Featured Post

JAX-WS webservice analysis

Friends,

     I have spent tremendous amount of time on JAX-ws webservice implementation and here are my observations . I would like to explain things in detail.

I have created class LinuxTest as shown below 

LinuxTest.java
-----------------
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.seo.testlinux;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

/**
 *
 * @author vpilaka
 */
@WebService(name = "TestLINUX", portName = "LinuxPort", serviceName = "LinuxService", targetNamespace = "com.seo.testlinux")
public class LinuxTest {

    /**
     * Web service operation
     */
    @WebMethod(operationName = "execute")
    public String execute(@WebParam(name = "command") String command, @WebParam(name = "param1") String param1, @WebParam(name = "param2") String param2) {
        return command;
    }

}


as per my observations TestLINUX is interface that get generated when we run wsimport
LinuxPort will be port class and Linux Service will be class that extends Service 

here is class output
****************

TestLINUX.java
--------------------

package testlinux.seo.com;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.Action;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;


/**
 * This class was generated by the JAX-WS RI.
 * JAX-WS RI 2.2.9-b130926.1035
 * Generated source version: 2.2
 * 
 */
@WebService(name = "TestLINUX", targetNamespace = "com.seo.testlinux")
@XmlSeeAlso({
    ObjectFactory.class
})
public interface TestLINUX {


    /**
     * 
     * @param command
     * @param param1
     * @param param2
     * @return
     *     returns java.lang.String
     */
    @WebMethod
    @WebResult(targetNamespace = "")
    @RequestWrapper(localName = "execute", targetNamespace = "com.seo.testlinux", className = "testlinux.seo.com.Execute")
    @ResponseWrapper(localName = "executeResponse", targetNamespace = "com.seo.testlinux", className = "testlinux.seo.com.ExecuteResponse")
    @Action(input = "com.seo.testlinux/TestLINUX/executeRequest", output = "com.seo.testlinux/TestLINUX/executeResponse")
    public String execute(
        @WebParam(name = "command", targetNamespace = "")
        String command,
        @WebParam(name = "param1", targetNamespace = "")
        String param1,
        @WebParam(name = "param2", targetNamespace = "")
        String param2);

}


LinuxService.java
---------------------

package testlinux.seo.com;

import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;


/**
 * This class was generated by the JAX-WS RI.
 * JAX-WS RI 2.2.9-b130926.1035
 * Generated source version: 2.2
 * 
 */
@WebServiceClient(name = "LinuxService", targetNamespace = "com.seo.testlinux", wsdlLocation = "http://localhost:8080/TestLinux/LinuxService?wsdl")
public class LinuxService
    extends Service
{

    private final static URL LINUXSERVICE_WSDL_LOCATION;
    private final static WebServiceException LINUXSERVICE_EXCEPTION;
    private final static QName LINUXSERVICE_QNAME = new QName("com.seo.testlinux", "LinuxService");

    static {
        URL url = null;
        WebServiceException e = null;
        try {
            url = new URL("http://localhost:8080/TestLinux/LinuxService?wsdl");
        } catch (MalformedURLException ex) {
            e = new WebServiceException(ex);
        }
        LINUXSERVICE_WSDL_LOCATION = url;
        LINUXSERVICE_EXCEPTION = e;
    }

    public LinuxService() {
        super(__getWsdlLocation(), LINUXSERVICE_QNAME);
    }

    public LinuxService(WebServiceFeature... features) {
        super(__getWsdlLocation(), LINUXSERVICE_QNAME, features);
    }

    public LinuxService(URL wsdlLocation) {
        super(wsdlLocation, LINUXSERVICE_QNAME);
    }

    public LinuxService(URL wsdlLocation, WebServiceFeature... features) {
        super(wsdlLocation, LINUXSERVICE_QNAME, features);
    }

    public LinuxService(URL wsdlLocation, QName serviceName) {
        super(wsdlLocation, serviceName);
    }

    public LinuxService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
        super(wsdlLocation, serviceName, features);
    }

    /**
     * 
     * @return
     *     returns TestLINUX
     */
    @WebEndpoint(name = "LinuxPort")
    public TestLINUX getLinuxPort() {
        return super.getPort(new QName("com.seo.testlinux", "LinuxPort"), TestLINUX.class);
    }

    /**
     * 
     * @param features
     *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the features parameter will have their default values.
     * @return
     *     returns TestLINUX
     */
    @WebEndpoint(name = "LinuxPort")
    public TestLINUX getLinuxPort(WebServiceFeature... features) {
        return super.getPort(new QName("com.seo.testlinux", "LinuxPort"), TestLINUX.class, features);
    }

    private static URL __getWsdlLocation() {
        if (LINUXSERVICE_EXCEPTION!= null) {
            throw LINUXSERVICE_EXCEPTION;
        }
        return LINUXSERVICE_WSDL_LOCATION;
    }

}

execute method implementation as Execute.java

Execute.java
---------------

package testlinux.seo.com;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;


/**
 * Java class for execute complex type.
 * 
 * The following schema fragment specifies the expected content contained within this class.
 * 
 *

 * <complexType name="execute">
 *   <complexContent>
 *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       <sequence>
 *         <element name="command" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *         <element name="param1" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *         <element name="param2" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *       </sequence>
 *     </restriction>
 *   </complexContent>
 * </complexType>
 *
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "execute", propOrder = {
    "command",
    "param1",
    "param2"
})
public class Execute {

    protected String command;
    protected String param1;
    protected String param2;

    /**
     * Gets the value of the command property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getCommand() {
        return command;
    }

    /**
     * Sets the value of the command property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setCommand(String value) {
        this.command = value;
    }

    /**
     * Gets the value of the param1 property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getParam1() {
        return param1;
    }

    /**
     * Sets the value of the param1 property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setParam1(String value) {
        this.param1 = value;
    }

    /**
     * Gets the value of the param2 property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getParam2() {
        return param2;
    }

    /**
     * Sets the value of the param2 property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setParam2(String value) {
        this.param2 = value;
    }

}

ExecuteResponse.java
---------------------------

package testlinux.seo.com;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;


/**
 * Java class for executeResponse complex type.
 * 
 * The following schema fragment specifies the expected content contained within this class.
 * 
 *

 * <complexType name="executeResponse">
 *   <complexContent>
 *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       <sequence>
 *         <element name="return" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *       </sequence>
 *     </restriction>
 *   </complexContent>
 * </complexType>
 *
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "executeResponse", propOrder = {
    "_return"
})
public class ExecuteResponse {

    @XmlElement(name = "return")
    protected String _return;

    /**
     * Gets the value of the return property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getReturn() {
        return _return;
    }

    /**
     * Sets the value of the return property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setReturn(String value) {
        this._return = value;
    }

}


ObjectFactory.java : as Factory class to support implemented interfaces and objects
------------------------------------------------------------------------------------------------------

package testlinux.seo.com;

import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;


/**
 * This object contains factory methods for each 
 * Java content interface and Java element interface 
 * generated in the testlinux.seo.com package. 
 * An ObjectFactory allows you to programatically 
 * construct new instances of the Java representation 
 * for XML content. The Java representation of XML 
 * content can consist of schema derived interfaces 
 * and classes representing the binding of schema 
 * type definitions, element declarations and model 
 * groups.  Factory methods for each of these are 
 * provided in this class.
 * 
 */
@XmlRegistry
public class ObjectFactory {

    private final static QName _Execute_QNAME = new QName("com.seo.testlinux", "execute");
    private final static QName _ExecuteResponse_QNAME = new QName("com.seo.testlinux", "executeResponse");

    /**
     * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: testlinux.seo.com
     * 
     */
    public ObjectFactory() {
    }

    /**
     * Create an instance of {@link ExecuteResponse }
     * 
     */
    public ExecuteResponse createExecuteResponse() {
        return new ExecuteResponse();
    }

    /**
     * Create an instance of {@link Execute }
     * 
     */
    public Execute createExecute() {
        return new Execute();
    }

    /**
     * Create an instance of {@link JAXBElement }{@code <}{@link Execute }{@code >}}
     * 
     */
    @XmlElementDecl(namespace = "com.seo.testlinux", name = "execute")
    public JAXBElement createExecute(Execute value) {
        return new JAXBElement(_Execute_QNAME, Execute.class, null, value);
    }

    /**
     * Create an instance of {@link JAXBElement }{@code <}{@link ExecuteResponse }{@code >}}
     * 
     */
    @XmlElementDecl(namespace = "com.seo.testlinux", name = "executeResponse")
    public JAXBElement createExecuteResponse(ExecuteResponse value) {
        return new JAXBElement(_ExecuteResponse_QNAME, ExecuteResponse.class, null, value);
    }

}

MyServiceTest.java 
-----------------------
this is client code which makes call to hosted webservice 

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.seo;

import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import testlinux.seo.com.LinuxService;

/**
 *
 * @author vpilaka
 */
public class MyServiceTest {
    
    public static void main(String[] args) throws MalformedURLException {
       
        LinuxService ls=new LinuxService(new URL("http://localhost:8080/TestLinux/LinuxService?wsdl"),new QName("com.seo.testlinux","LinuxService"));
        System.out.println(ls.getLinuxPort().execute("ls", "-lrt", ""));
//        AdsenseService as=new AdsenseService();
//        AdService as1=as.getAdsensePort();
        BindingProvider bindingProvider = (BindingProvider) ls.getLinuxPort();
        bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,"http://www.test-domain.com/TestLinux/LinuxService?wsdl");
        System.out.println("A:--->"+ls.getLinuxPort().execute("ls","-lrt",""));
    }
    
}















generated wsdl
------------------
This XML file does not appear to have any style information associated with it. The document tree is shown below.
 xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy"xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="com.seo.testlinux" xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="com.seo.testlinux" name="LinuxService">



 namespace="com.seo.testlinux" schemaLocation="http://localhost:8080/TestLinux/LinuxService?xsd=1"/>



 name="execute">

 name="parameters" element="tns:execute"/>


 name="executeResponse">

 name="parameters" element="tns:executeResponse"/>


 name="TestLINUX">

 name="execute">

 wsam:Action="com.seo.testlinux/TestLINUX/executeRequest" message="tns:execute"/>

 wsam:Action="com.seo.testlinux/TestLINUX/executeResponse" message="tns:executeResponse"/>



 name="LinuxPortBinding" type="tns:TestLINUX">

 transport="http://schemas.xmlsoap.org/soap/http" style="document"/>

 name="execute">

 soapAction=""/>


 use="literal"/>



 use="literal"/>




 name="LinuxService">

 name="LinuxPort" binding="tns:LinuxPortBinding">

 location="http://localhost:8080/TestLinux/LinuxService"/>



Comments

Popular posts from this blog

[Inside AdSense] Understanding your eCPM (effective cost per thousand impress...