September 29, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

How to Write Axis2 Web Service Clients for the Cloud

  • May 13, 2009
  • By Deepal Jayasinghe
  • Send Email »
  • More Articles »

What are those options?

Now we are going to discuss some of the options we use when we generate the code,

  • -uri :- as the name implies the "uri" option is to specify the location of the WSDL document, it can either be a remote URL or path to a local file.
  • -o :- This parameter is used to specify the output location of the code, so that the Axis2 tools generates the code into it.
  • -u :- The idea of "u" option is to unpack the code, it will generate the data binding code and service invocation code into separate classes.

Now we have generated the client side stub for our Amazon EC2. Our next step is to write the code to use the stub. In fact there is not such a big difference from writing a client to the other Web service and EC2, so if you know how to use a stub then it will be easy for you to use the generated stub to do the work you want.

Invoking the stub

As we discussed before there is no difference using the previously generated stub for EC2 and a normal stub with one exception. The exception being, in the case of Amazon EC2 we have to use security so we need to setup security requirement for EC2. Basically we need to configure the public key and the certificate. In addition to that due to some of the missing features in Axis2 security implementation we need to write some additional code. But we are not going to discuss that here since it will complicate the article, you can find the required library in the resource section. Download that and add it into the classpath, then you can use those utilities for the client.

Writing the security handler

As we discussed before to use Amazon EC2 we need to use the WS- Security, to use WS-Security in Axis2 we need to write a special handler to provide and handle the user-name and password. And writing that is so simple, we just need use the following code as the security handler:
  import org.apache.ws.security.WSPasswordCallback;
  
  import javax.security.auth.callback.Callback;
  import javax.security.auth.callback.UnsupportedCallbackException;
  import javax.security.auth.callback.CallbackHandler;
  import java.io.IOException;
  
  public class SecurityHandler implements CallbackHandler {
      public static String password;
  
          public void handle(Callback[] callbacks) throws IOException,
                  UnsupportedCallbackException {
              for (Callback callback : callbacks) {
                  WSPasswordCallback pwcb = (WSPasswordCallback) callback;
                  pwcb.setPassword(password);
              }
          }
  
  }

Having written the security handler and other security related code we are now ready to write the code to invoke the stub.





Page 2 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel