The Java SDK for APT from Yahoo! API makes it easy to build Search Marketing tools to access and manage APT accounts. Without any pre-knowledge of Axis or SOAP, you can access the APT Web Services as easy as normal Java classes.
To use the Java client library, extract ysm-apt-jsdk jar (i.e. ysm-apt-jsdk-vx.x.x.jar) from the source or binary zip file (i.e. ysm-apt-jsdk-vx.x.x-src.zip or ysm-apt-jsdk-vx.x.x-bin.zip). Put the jar file in your classpath. Create the config and logging folder structure. Create the property files with required values. You don't need to put any other additional libraries in your classpath or do any pre-compiling. You don't need to worry about accessing the WSDL for the web services; the Axis generated stub classes in the client library do it for you.
The SDK comprises of a Factory class, a Constants class, a Log Helper class and a Data Structure for encapsulating the credentials besides Axis client side stubs generated by Axis' WSDL2Java tool. Users can configure the settings using a properties file and programmatically access the APT Web Services API using the ServiceFactory.java class and Axis client stubs.
Default Settings
Custom Settings
System Property name | Sample Property value |
================== | ================== |
YAHOO_PROPERTIES_FILE | "ConfigDir" + File.separatorChar +"YSM.propperties" |
YAHOO_LOG_CONFIG_FILE | "ConfigDir" + File.separatorChar +"log4j.propperties" |
## Create a ServiceFactory object, loading the configuration files from system property import com.yahoo.marketing.apt.client.ServiceFactory; ServiceFactory factory = new ServiceFactory(); //Get a SiteService object from the ServiceFactory SiteService siteService = factory.getService("SiteService"); // Get a Site object through SiteService long siteID = 123456; Site site = siteService.getSite(siteID);If the above system properties are not found the SDK will use the default settings specified earlier. For settings that are not found in the custom properties file, the default settings will be used.
## Create a ServiceFactory object, loading the configuration files directly import com.yahoo.marketing.apt.client.ServiceFactory; String configFile = "/myConf/myConfig.properties"; String logConfigFile = "/myConf/myAPTClientLogConfig.properties"; ServiceFactory factory = new ServiceFactory(configFile, logConfigFile); //Get a SiteService object from the ServiceFactory SiteService siteService = factory.getService("SiteService"); // Get a Site object through SiteService long siteID = 123456;
Credential credential = new Credential("username", "password", "apt-api-license-key", "123465789"); String configFile = "/myConf/myConfig.properties"; String logConfigFile = "/myConf/myLogConfig.properties"; ServiceFactory factory = new ServiceFactory(credential, configFile, logConfigFile); //Get a SiteService object from the ServiceFactory SiteService siteService = factory.getService(SiteService.class); // Get a Site object through SiteService long siteID = 123456; Site site = siteService.getSite(siteID);
In the properties file "myConfig.properties":
## Location Cache Filename and expiration settings Location.Cache.Filepath.Prefix=YahooAPT_LocCache_ Location.Cache.Expiration.Millis=86400000 # 24hrs - 86400000 ; 1min - 60000 ; 5min - 300000 ## APT Endpoint and Location settings APT.Version=V1 APT.Endpoint=https://sandbox.apt.yahooapis.com/ ## APT Credentials APT.Username=username APT.Password=password APT.License=apt-api-license-key APT.AccountID=123456789In the class main method:
String configFile = "/myConf/myConfig.properties"; String logConfigFile = "/myConf/myLogConfig.properties"; ServiceFactory factory = new ServiceFactory(credential, configFile, logConfigFile); //Get a SiteService object from the ServiceFactory SiteService siteService = factory.getService(SiteService.class); // Get a Site object through SiteService long siteID = 123456; Site site = siteService.getSite(siteID);
################################# ###APT Log Properties ### ################################# APT.Log.EnableLog=true APT.Log.LogSOAPMessages=false ################################## ### Commons-logging Properties ### ################################## # Directly selects log4j logging implementation class. org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.Log4jFactory # Maps to a Log4J category (uses log4j.properties) # note: org.apache.log4j.Category is deprecated in favor of org.apache.log4j.Logger # and requests for a Category object will return a Logger object. org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JCategoryLog ######################## ### Log4J Properties ### ######################## # Set root category priority to INFO and its appender to CONSOLE and LOGFILE log4j.rootCategory=FATAL, CONSOLE, LOGFILE # Set the APT service logger category to INFO log4j.logger.com.yahoo.marketing.apt=INFO # CONSOLE is set to be a ConsoleAppender using a PatternLayout. log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.Threshold=DEBUG log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=%d{HH:mm:ss} %-5p %x %c %m%n #log4j.appender.CONSOLE.layout.ConversionPattern=%d{HH:mm:ss} - %m%n #log4j.appender.CONSOLE.layout.ConversionPattern=%d %-4r [%t] %-5p %c %x - %m%n # LOGFILE is set to be a File appender using a PatternLayout. Change log4j.appender.LOGFILE.File to your log filename log4j.appender.LOGFILE=org.apache.log4j.RollingFileAppender log4j.appender.LOGFILE.File=logs/YahooSM.log log4j.appender.LOGFILE.Append=true log4j.appender.LOGFILE.File.MaxFileSize=1MB log4j.appender.LOGFILE.File.MaxBackupIndex=30 log4j.appender.LOGFILE.Threshold=INFO log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout log4j.appender.LOGFILE.layout.ConversionPattern=%d{HH:mm:ss} %-5p %c %m%nTo log SOAP request and response XML messages, set APT.Log.LogSOAPMessages into true. Then in the class main method:
String configFile = "/myConf/myConfig.properties"; String logConfigFile = "/myConf/myLogConfig.properties"; ServiceFactory factory = new ServiceFactory(credential, configFile, logConfigFile); LogHelper log = factory.getLogHelper(); try { // Get a SiteService object from the ServiceFactory SiteService siteService = factory.getService(SiteService.class); // Get a Site object through SiteService long siteID = 123456; Site site = siteService.getSite(siteID); // Log the success message together with the SOAP request and response message. log.info((Stub)siteService, "getSite() has been called successfully."); } catch(ApiFault fault) { // Log the failure message together with the SOAP request and response message. log.error((Stub)siteService, "getSite() has failed"); }
Javadoc
API documentation generated with javadoc.
License
The terms of the license used for the SDK.
APT from Yahoo! Home
Home of APT from Yahoo!
APT from Yahoo! Application Help
Application Help of APT from Yahoo!.