Thursday, June 30, 2011

Apache Axis Java Client

package com;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;

/**
 *
 * @author Vinaykumar.guntaka
 * jaxrpc.jar
 * commons-discover-0.2.jar
 * wsdl4j-1.5.1.jar
 * axis.jar
 */
public class Demo {
    public static String endpoint =   "http://localhost:8080/ProjectName/services/ProjectActions";
    public static void main(String[] args) {
        invokeMethod();
        invokeParamMethod();
     
    }
 
    public static void invokeMethod(){
        try {
            Service service = new Service();
            QName Qname = new QName(endpoint,"HelloWorld");
            Call call = (Call) service.createCall(Qname);
            call.setTargetEndpointAddress(new java.net.URL(endpoint));
              call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true));
                call.setProperty(Call.SOAPACTION_URI_PROPERTY,"http://localhost:8080/ProjectName/services/ProjectActions/HelloWorld");
                call.setOperationName(new QName("http://com","HelloWorld"));
             
                String ret = (String) call.invoke("HelloWorld", new Object[]{});
               
                System.out.println("Sent 'Hello!', got '" + ret + "'");
        } catch (Exception e) {
            // TODO: handle exception
        }
    }
    public static void invokeParamMethod(){
        try {
            Service service = new Service();
            QName Qname = new QName(endpoint,"getMessage");
            Call call = (Call) service.createCall(Qname);
            call.setTargetEndpointAddress(new java.net.URL(endpoint));
            call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true));
            call.setProperty(Call.SOAPACTION_URI_PROPERTY,"http://localhost:8080/ProjectName/services/ProjectActions/getMessage");
            call.setOperationName(new QName("http://com","getMessage"));
         
            call.addParameter("str", XMLType.XSD_STRING, ParameterMode.IN);
            call.addParameter("str1", XMLType.XSD_STRING, ParameterMode.IN);
            call.setReturnType(XMLType.XSD_STRING);
            String ret = (String) call.invoke( new Object[] { "Vinay!","Guntaka" } );
               
            System.out.println("got '" + ret + "'");
        } catch (Exception e) {
            // TODO: handle exception
        }
     
    }
 
    }

/*******************
 Web service actions

*/
 
    public String getMessage(String str,String str1){
        return str+"Vinay Guntaka"+str1;
     
    }
    public String HelloWorld(){
        return "HelloWorld Vinay Guntaka";
     
    }

No comments:

Post a Comment

Java 1.7 New Features Over 1.6

Automatic Resource Management Description: A proposal to support scoping of resource usage in a block with automatic resource cleanup. T...