APT from Yahoo! Java SDK

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.

Introduction

The Java SDK for APT from Yahoo! API makes it easy to build Search Marketing tools with Java to programmatically access and manage APT accounts. The aim of the SDK is to encapsulate all APT Web Service logic such that the usage of the APT Web Services becomes as easy as normal Java classes, without any pre-knowledge of Axis or SOAP. The client library is provided in a single jar file that contains all the pre-compiled Axis stub classes and a service factory class to be used to write Java clients accessing the APT Web Services.

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.

Build Instructions

  1. Download and install ant if you don't already have it installed
  2. Set ANT_HOME to in your system's environment variables
  3. Set PATH to \bin in your system's environment variables
  4. Ensure JAVA_HOME is set in the system environment variables
  5. Ensure 'tools.jar' is in the classpath entry in the system environment variables
  6. Unzip source zip file, i.e. ysm-apt-jsdk-src-vx.x.x.zip
  7. Open command prompt in project folder
  8. Key 'ant' at command prompt and hit enter
  9. Pick up jar file from build folder and use it as ysm sdk library in client applications following the Usage Instructions
  10. Pick up zip file from the dist directory as needed to distribute project.

Usage Instructions

SDK Configuration

Put ysm-apt-jsdk jar file in the lib folder and reference in your classpath.

Default Settings

Custom Settings

Authentication

To access APT from Yahoo! Web Service API, a set of credential information must be provided. There are two ways to pass the credentials to the SDK.

Logging

The APT SDK uses ServiceLog class to implement logging throughout the code. To enable the logging, put the logging configurations in log config file and set APT.Log.EnableLog into true.
#################################
###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%n	
To 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");
}

Property File

The default property file name is "YahooMarketing.properties" The properties defined in this file are:
ServiceFactory configuration properties: Logging Configuration properties: NOTE: By default the logging configuration is specified in the YahooMarketing.properties file. However one can use a separate logging configuration file and pass in the file name directly or as a system property as detailed in the Custom Settings under the
SDK Configuration section above.

Documentation

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!.

Sample Code

Please refer the sample code in the example folder of the SDK for usage and best practices for coding using the SDK.