This document contains conceptual and procedural information on connecting your development environment or other systems to the ExactTarget SOAP web service API using
Java via the
Axis 1.4 SOAP client.
Why Connect to the Web Service API using
Java and Axis 1.4
You can use the connection to the SOAP 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 Axis 1.4
Download Apache
Axis 1.4 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 SOAP web service API servers.
Code
The sample code below demonstrates how to connect and interact with the SOAP web service API.
Authenticating with Apache
Axis 1.4
This sample code demonstrates how to use
Java and Axis 1.4 to authenticate with the SOAP web service API.
Password Callback Handler
Place this sample code in the Class-path.file to define PasswordTokenHandler and what type of Password method the service is using. In this case, the service uses the
PasswordText method.
view plaincopy
to clipboardprint?
- public class PasswordTokenHandler implements CallbackHandler {
- public void handle(Callback[] callbacks) throws IOException,
- UnsupportedCallbackException {
- for (int i = 0; i < callbacks.length; i++) {
- if (callbacks[i] instanceof WSPasswordCallback) {
- WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
- pc.setPassword("ET Password");
- } else {
- throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
- }
- }
- }
- }
public class PasswordTokenHandler implements CallbackHandler { public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (int i = 0; i < callbacks.length; i++) { if (callbacks[i] instanceof WSPasswordCallback) { WSPasswordCallback pc = (WSPasswordCallback) callbacks[i]; pc.setPassword("ET Password"); } else { throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback"); } } }}
The sample code below demonstrates how to define a callback handler.
view plaincopy
to clipboardprint?
- <deployment
- name="commonsHTTPConfig"
- xmlns="http://xml.apache.org/axis/wsdd/"
- xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
- <!-- <transport name="http" pivot="java:org.apache.axis.transport.http.HTTPSender"/> -->
- <globalConfiguration>
- <requestFlow>
- <handler type="java:org.apache.ws.axis.security.WSDoAllSender">
- <parameter name="action" value="UsernameToken"/>
- <parameter name="passwordCallbackClass" value="com.et.util.PasswordTokenHandler"/>
- <parameter name="passwordType" value="PasswordText"/>
- </handler>
- </requestFlow>
- </globalConfiguration>
- <transport name="http" pivot="java:org.apache.axis.transport.http.CommonsHTTPSender"></transport>
-
- <!-- <transport name="http" pivot="java:org.apache.axis.transport.http.CommonsHTTPSender"/>
- <transport name="local" pivot="java:org.apache.axis.transport.local.LocalSender"/>
- <transport name="java" pivot="java:org.apache.axis.transport.java.JavaSender"/>-->
- </deployment>
<deployment name="commonsHTTPConfig" xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <!-- <transport name="http" pivot="java:org.apache.axis.transport.http.HTTPSender"/> --> <globalConfiguration> <requestFlow> <handler type="java:org.apache.ws.axis.security.WSDoAllSender"> <parameter name="action" value="UsernameToken"/> <parameter name="passwordCallbackClass" value="com.et.util.PasswordTokenHandler"/> <parameter name="passwordType" value="PasswordText"/> </handler> </requestFlow> </globalConfiguration> <transport name="http" pivot="java:org.apache.axis.transport.http.CommonsHTTPSender"></transport> <!-- <transport name="http" pivot="java:org.apache.axis.transport.http.CommonsHTTPSender"/> <transport name="local" pivot="java:org.apache.axis.transport.local.LocalSender"/> <transport name="java" pivot="java:org.apache.axis.transport.java.JavaSender"/>--></deployment>
The sample code below accesses the SOAP client and assigns the username and password in the request.
view plaincopy
to clipboardprint?
- public Soap_PortType init() {
- Soap_PortType stub = null;
- try {
- InputStream inConfig = BaseTestCase.class.getClassLoader().getResourceAsStream("axis_client_config.xml");
- EngineConfiguration config = new FileProvider(inConfig);
- PartnerAPILocator locator = new PartnerAPILocator(config);
- inConfig.close();
-
- stub = locator.getSoap();
-
- Stub axisPort = (Stub) stub;
- axisPort._setProperty(UsernameToken.PASSWORD_TYPE, WSConstants.PASSWORD_TEXT);
- axisPort._setProperty(WSHandlerConstants.USER, "ET USERNAME");
- axisPort._setProperty(WSHandlerConstants.PW_CALLBACK_REF, new PasswordTokenHandler());
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- return stub;
- }
public Soap_PortType init() { Soap_PortType stub = null; try { InputStream inConfig = BaseTestCase.class.getClassLoader().getResourceAsStream("axis_client_config.xml"); EngineConfiguration config = new FileProvider(inConfig); PartnerAPILocator locator = new PartnerAPILocator(config); inConfig.close(); stub = locator.getSoap(); Stub axisPort = (Stub) stub; axisPort._setProperty(UsernameToken.PASSWORD_TYPE, WSConstants.PASSWORD_TEXT); axisPort._setProperty(WSHandlerConstants.USER, "ET USERNAME"); axisPort._setProperty(WSHandlerConstants.PW_CALLBACK_REF, new PasswordTokenHandler()); } catch (Exception e) { e.printStackTrace(); } return stub;}
Content of
Axis Client config.xml Fileview plaincopy
to clipboardprint?
- <deployment
- name="commonsHTTPConfig"
- xmlns="http://xml.apache.org/axis/wsdd/"
- xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
- <globalConfiguration>
- <requestFlow>
- <handler type="java:org.apache.ws.axis.security.WSDoAllSender">
- <parameter name="action" value="UsernameToken"/>
- <parameter name="passwordCallbackClass" value="com.et.util.PasswordTokenHandler"/>
- <parameter name="passwordType" value="PasswordText"/>
- </handler>
- </requestFlow>
- </globalConfiguration>
- <transport name="http" pivot="java:org.apache.axis.transport.http.CommonsHTTPSender"></transport>
- </deployment>
<deployment name="commonsHTTPConfig" xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <globalConfiguration> <requestFlow> <handler type="java:org.apache.ws.axis.security.WSDoAllSender"> <parameter name="action" value="UsernameToken"/> <parameter name="passwordCallbackClass" value="com.et.util.PasswordTokenHandler"/> <parameter name="passwordType" value="PasswordText"/> </handler> </requestFlow> </globalConfiguration> <transport name="http" pivot="java:org.apache.axis.transport.http.CommonsHTTPSender"></transport> </deployment>
Additional Data
Passing credentials using WS-Security headersby Adobe
There are no ratings yet. Be the first to rate this article.Modified
15 October 2007
Share
on FacebookShare
on TwitterShare
on LinkedInPrintLiveCyclesecurityweb services