Connecting to the API using Java and Axis2

This document contains conceptual and procedural information on connecting your development environment or other systems to the ExactTarget web service API using Java via the Axis2 SOAP client. Axis2 is a SOAP client preferred by many Java users.

Why Connect to the Web Service API using Java and Axis2

You can use the connection to the web service API to test your calls and perform various tasks, such as sending email and retrieving tracking information.

How To Connect to the Web Service API using Java and Axis2

Download Apache Axis2 at http://ws.apache.org/axis2 and follow the appropriate instructions at that site to install the service on your computer. You can use the sample code below to authenticate your installation and exchange information with the web service API servers.

Code

The sample code below demonstrates how to connect and interact with the web service API.

Authenticating with Apache Axis2

This sample code demonstrates how to use Java and Axis2 to authenticate with the web service API.

Password Callback Handler

public class PWCBHandler implements CallbackHandler {
	public static String user = ClientTest.getProperties().getProperty("user");
	public static String password = ClientTest.getProperties().getProperty("password");
	
    public void handle(Callback[] callbacks) throws IOException,
            UnsupportedCallbackException {
        for (int i = 0; i < callbacks.length; i++) {
            WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i];
            String id = pwcb.getIdentifer();
            if(user.equals(id)) {            	
            	pwcb.setPassword(password);
            }
        }
    } //end method handle
} //end class PWCBHandler

Client Code

String endpoint = properties.getProperty( "endpoint" );

//Create reference to ExactTarget Web Service API.
EndpointReference endPointReference = new EndpointReference( endpoint );

//Create Axis2 ConfigurationContext; an Axis2 ConfigurationContext is like an in-memory database that holds static 
//and dynamic data. Note that at the client side we have no services, so the concept of a repository is not that useful.
ConfigurationContext configurationContext = 
	ConfigurationContextFactory.createConfigurationContextFromFileSystem( repositoryLocation, configurationFileLocation );

//Create PartnerAPIStub with ExactTarget Web Service API endpoint and Axis2 ConfigurationContext.
PartnerAPIStub stub = new PartnerAPIStub( configurationContext, endpoint );

//Create Axis2 ServiceClient from PartnerAPIStub. An Axis2 ServiceClient provides an easy way to invoke services.
ServiceClient serviceClient = stub._getServiceClient();

//Create security options. Remaining security setup is within axis2-client.xml; while there exist programmatic
//methods of setting up Rampart and OutflowSecurity, the XML methods are preferred.
Options options = new Options();
options.setTo( endPointReference );
serviceClient.setOptions( options );

Example axis2-client.xml Snippet

<axisconfig name="AxisJava2.0">
    
    <module ref="rampart" />

    <parameter name="OutflowSecurity">
        <action>
            <items>UsernameToken</items>
            <user>et_documentation</user>
            <passwordCallbackClass>com.exacttarget.samples.Axis2v12.client.PWCBHandler</passwordCallbackClass>
            <passwordType>PasswordText</passwordType>
        </action>
    </parameter>
....  </axisconfig>

Additional Data

Use the information below to round out your knowledge of using Java with the web service API.

Passing credentials using WS-Security headers

Examples for C# and Java
http://www.adobe.com/devnet/livecycle/articles/passing_credentials.html

Troubleshooting

  1. The password is always being passed as Digest format. What do I do?
    1. In Axis2.xml passwordType node value,  should be defined as "PasswordText"
    2. Ensure the classpaths contain only one Axis configuration
    3. Ensure the most recent Axis2 library is installed on the the machine.




 

 


Enter the digits 11515 backwards:
   
 

 

Tag page

Files 1

FileSizeDateAttached by 
 AxisSampleProject.zip
No description
9.81 MB18:17, 20 Apr 2010AdminActions
You must login to post a comment.