Monday, August 10, 2015

Axis2 web service client sample for getting values using web service stub,[you need to pass authentication only if secured the WS]

/* Say this CxLastBill class constructor creates object with Status and Cusomner's lastBillMin */
private Long lastBillMin = null;//getter & setter in code
private String status = null;//getter & setter in code

 public CxLastBill(HashMap hm, String cxRef) {//hm map has authentication and EP,cxRef is the request parameter 
 //Http Authentication 
HttpTransportProperties.Authenticator basicAuthentication = new HttpTransportProperties.Authenticator(); basicAuthentication.setPassword(hm.get("RBMPD")); basicAuthentication.setUsername(hm.get("RBMUS")); 

//Call End point Runtime and set some properties for request
    ECAAccountStub proxy;
    try {
        proxy = new ECAAccountStub(hm.get("RBMEP"));//Endpoint
        proxy._getServiceClient()
                .getOptions()
                .setProperty(
                        org.apache.axis2.transport.http.HTTPConstants.CHUNKED,
                        Boolean.FALSE);
        proxy._getServiceClient()
                .getOptions()
                .setProperty(
                        org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE,
                        basicAuthentication);

       
        /*
       
        Code implementation
        ie, Set inputs and get Outputs for client requirement
       
        cxRef is used for query the data
       
        Ex:  QueryAccountInput
             queryAccountOutput  
       
        */

        setLastBillMin(queryAccountOutputObject.getLastBillMny());//get last Bill money from response value
        setStatus("OK");
    } catch (Exception e) {
        // TODO: handle exception
        setStatus("ERROR: " + e.getMessage());
    }

        Ref :
        http://wiki.servicenow.com/index.php?title=Java_Apache_Axis2_Web_Services_Client_Examples#gsc.tab=0

No comments:

This site providing you to JAVA Language easy way. I think if you are beginner to JAVA refer this to implements you knowledge using only with very simplest codes.