Axis2 connecting to the Web Service API using Java and axis 1.4

Source: Internet
Author: User
Tags soap client

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
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 calland perform varous 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
PasswordtextMethod.

View plaincopy
To clipboardprint?
  1. Public class passwordtokenhandler implements callbackhandler {
  2. Public void handle (callback [] callbacks) throws ioexception,
  3. Unsupportedcallbackexception {
  4. For (INT I = 0; I <Callbacks. length; I ++ ){
  5. If (callbacks [I] instanceof wspasswordcallback ){
  6. Wspasswordcallback Pc = (wspasswordcallback) callbacks [I];
  7. PC. setpassword ("et password ");
  8. } Else {
  9. Throw new unsupportedcallbackexception (callbacks [I], "Unrecognized callback ");
  10. }
  11. }
  12. }
  13. }
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?
  1. <Deployment
  2. Name = "commonshttpconfig"
  3. Xmlns = "http://xml.apache.org/axis/wsdd"
  4. Xmlns: Java = "http://xml.apache.org/axis/wsdd/providers/java">
  5. <! -- <Transport name = "HTTP" protocol = "Java: org. Apache. axis. Transport. http. httpsender"/> -->
  6. <Globalconfiguration>
  7. <Requestflow>
  8. <Handler type = "Java: org. Apache. ws. axis. Security. wsdoallsender">
  9. <Parameter name = "action" value = "userNameToken"/>
  10. <Parameter name = "passwordcallbackclass" value = "com. Et. util. passwordtokenhandler"/>
  11. <Parameter name = "passwordtype" value = "passwordtext"/>
  12. </Handler>
  13. </Requestflow>
  14. </Globalconfiguration>
  15. <Transport name = "HTTP" protocol = "Java: org. Apache. axis. Transport. http. commonshttpsender"> </Transport>
  16. <! -- <Transport name = "HTTP" protocol = "Java: org. Apache. axis. Transport. http. commonshttpsender"/>
  17. <Transport name = "local" plugin = "Java: org. Apache. axis. Transport. Local. localsender"/>
  18. <Transport name = "Java" plugin = "Java: org. Apache. axis. Transport. java. javasender"/> -->
  19. </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>            

The sample code below accesses the soap client and assigns the username and password in the request.

View plaincopy
To clipboardprint?
  1. Public soap_porttype Init (){
  2. Soap_porttype stub = NULL;
  3. Try {
  4. Inputstream inconfig = basetestcase. Class. getclassloader (). getresourceasstream ("axis_client_config.xml ");
  5. Engineconfiguration Config = new fileprovider (inconfig );
  6. Partnerapilocator locator = new partnerapilocator (config );
  7. Inconfig. Close ();
  8. Stub = locator. getsoap ();
  9. Stub axisport = (stub) Stub;
  10. Axisport. _ setproperty (userNameToken. password_type, wsconstants. password_text );
  11. Axisport. _ setproperty (wshandlerconstants. User, "et username ");
  12. Axisport. _ setproperty (wshandlerconstants. pw_callback_ref, new passwordtokenhandler ());
  13. }
  14. Catch (exception e ){
  15. E. printstacktrace ();
  16. }
  17. Return stub;
  18. }
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
Axis client config. xml FileView plaincopy
To clipboardprint?
  1. <Deployment
  2. Name = "commonshttpconfig"
  3. Xmlns = "http://xml.apache.org/axis/wsdd"
  4. Xmlns: Java = "http://xml.apache.org/axis/wsdd/providers/java">
  5. <Globalconfiguration>
  6. <Requestflow>
  7. <Handler type = "Java: org. Apache. ws. axis. Security. wsdoallsender">
  8. <Parameter name = "action" value = "userNameToken"/>
  9. <Parameter name = "passwordcallbackclass" value = "com. Et. util. passwordtokenhandler"/>
  10. <Parameter name = "passwordtype" value = "passwordtext"/>
  11. </Handler>
  12. </Requestflow>
  13. </Globalconfiguration>
  14. <Transport name = "HTTP" protocol = "Java: org. Apache. axis. Transport. http. commonshttpsender"> </Transport>
  15. </Deployment>
<deployment        name="commonsHTTPConfig"        xmlns="http://xml.apache.org/axis/wsdd/"        xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">    <globalConfiguration>        <requestFlow>            

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

    • Comments
      (2)
    Page tools
    Share
    On facebookshare
    On twittershare
    On linkedinprintlivecyclesecurityweb services
    Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.