users@glassfish.java.net

glassfish doesn't understand KSoap2-msgs

From: Stefan Schilling <mail.suse_at_gmx.de>
Date: Wed, 20 Feb 2008 16:43:29 +0100

Hello again!

Using:
glassfish-v2ur1-b09d
kloap2-2.1.2
JavaME CLDC 1.1, WTK-2.5.2

I just tried to solve my problem described in http://sourceforge.net/forum/forum.php?thread_id=1945385&forum_id=532039 by writing a simple HelloWorld application. I can send the data and the server actually starts the requested Stateless/WebService-Bean.
But it then crashes, because the parameter could not be read / created from the KSoap2-created XML-document.

I don't know, whats going wrong here, so I just give you some details (we call it: 'code' :) ). WSDL, Server, Client, in that order.

Please write, if you need any other information.

Thanks!

Stefan

####################### wsdl #######################

<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.2_01-hudson-189-. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.2_01-hudson-189-. --><definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://middleware.test/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://middleware.test/" name="HelloWorld">
<wsp:UsingPolicy></wsp:UsingPolicy>
<wsp:Policy wsu:Id="HelloWorldPortBinding_sayHello_WSAT_Policy">
<wsp:ExactlyOne>
<wsp:All>
<ns1:ATAlwaysCapability xmlns:ns1="http://schemas.xmlsoap.org/ws/2004/10/wsat" wsp:Optional="false"></ns1:ATAlwaysCapability>
<ns2:ATAssertion xmlns:ns3="http://schemas.xmlsoap.org/ws/2002/12/policy" xmlns:ns2="http://schemas.xmlsoap.org/ws/2004/10/wsat" ns3:Optional="true" wsp:Optional="true"></ns2:ATAssertion>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
<types>
<xsd:schema>
<xsd:import namespace="http://middleware.test/" schemaLocation="http://172.16.1.1:8080/HelloWorld/HelloWorld?xsd=1"></xsd:import>
</xsd:schema>
</types>
<message name="sayHello">
<part name="parameters" element="tns:sayHello"></part>
</message>
<message name="sayHelloResponse">
<part name="parameters" element="tns:sayHelloResponse"></part>
</message>
<portType name="HelloWorld">
<operation name="sayHello">
<input message="tns:sayHello"></input>
<output message="tns:sayHelloResponse"></output>
</operation>
</portType>
<binding name="HelloWorldPortBinding" type="tns:HelloWorld">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
<operation name="sayHello">
<wsp:PolicyReference URI="#HelloWorldPortBinding_sayHello_WSAT_Policy"></wsp:PolicyReference>
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal"></soap:body>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
</operation>
</binding>
<service name="HelloWorld">
<port name="HelloWorldPort" binding="tns:HelloWorldPortBinding">
<soap:address location="http://172.16.1.1:8080/HelloWorld/HelloWorld"></soap:address>
</port>
</service>
</definitions>

####################### /wsdl #######################

####################### server-Beanclass #######################

package test.middleware;

import java.util.logging.Logger;
import javax.ejb.Stateless;
import javax.jws.WebService;

@WebService(serviceName="HelloWorld", portName="HelloWorldPort")
@Stateless
public class HelloWorld implements HelloClientIF {

        private Logger logger = Logger.getLogger(this.getClass().getName());

        public Hello sayHello( Hello partner ){
                logger.info("Starting sayHello");
                String helloString = "Hello ".concat(partner.getFirstName()).concat(" ").concat(partner.getName())
                                                                .concat(". How are you doing?")
                Hello returnMe = new Hello();
                returnMe.setReturnedString(helloString);
                return returnMe;
        }
}

####################### /server-Beanclass #######################

####################### server-Hello.class #######################

package test.middleware;

import java.io.Serializable;

public class Hello implements Serializable {

        private static final long serialVersionUID = 4054913498292705816L;
        private String firstName;
        private String name;
        private String returnedString;
        
        
        public String setReturnedString() {
                return returnedString;
        }
        public void setReturnedString(String returnString) {
                this.returnedString = returnString;
        }
        public String getFirstName() {
                return firstName;
        }
        public void setFirstName(String firstName) {
                this.firstName = firstName;
        }
        public String getName() {
                return name;
        }
        public void setName(String name) {
                this.name = name;
        }
}

####################### /server-Hello.class #######################

...of course, I cannot use the java.io.Serializable class in CLDC. So, the client has its own HelloClient.class:

####################### client-HelloClient.class #######################

package testClient;

import java.util.Hashtable;

import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapSerializationEnvelope;

public class HelloClient implements KvmSerializable {

        private String firstName;
        private String name;
        private String returnedString = "autsch";
        
        
        public String getFirstName() {
                return firstName;
        }

        public void setFirstName(String foreName) {
                this.firstName = foreName;
        }

        public String getName() {
                return name;
        }

        public void setName(String name) {
                this.name = name;
        }

        public String getReturnedString() {
                return returnedString;
        }

        public void setReturnedString(String returnedString) {
                this.returnedString = returnedString;
        }

        public Object getProperty(int index) {

                if ( index == 0 ) {
                        return getFirstName();
                } else if ( index == 1 ) {
                        return getName();
                } else if ( index == 2 ) {
                        return getReturnedString();
                } else {
                        return null;
                }
        }

        public int getPropertyCount() {
                
                return 3;
        }

        public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info) {
                
                info.type = PropertyInfo.STRING_CLASS;
                if(index == 0) {
                        info.name = "firstName";
                } else if (index == 1) {
                        info.name = "name";
                } else if (index == 2) {
                        info.name = "returnedString";
                } else {
                }
                
        }

        public void setProperty(int index, Object obj) {
                if ( index == 0 ) {
                        setFirstName( (String) obj );
                } else if ( index == 1 ) {
                        setName( (String) obj );
                } else if ( index == 2 ) {
                        setReturnedString((String) obj );
                } else {
                
                }
        }

        public void register(SoapSerializationEnvelope envelope) {
                envelope.addMapping("http://172.16.1.1/middleware", "HelloClient", this.getClass());
                
        }
}

####################### /client-HelloClient.class #######################

and here comes the Client Midlet class:

####################### client-Run.class #######################

package testClient;

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

import net.sf.microlog.Logger;
import net.sf.microlog.util.Properties;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransport;

public class Run extends MIDlet {
        
        private Properties loggerProps = new Properties(this);
        private Logger logger = Logger.getLogger();
    
        public Run() {
        }

        protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
        }

        protected void pauseApp() {
        }

        protected void startApp() throws MIDletStateChangeException {
                
                logger.configure(loggerProps);
                
                try {
                        HelloClient helloClient = new HelloClient();
                        helloClient.setFirstName("Stefan");
                        helloClient.setName("Schilling");
                        
                        Class outgoing = helloClient.getClass();
                        PropertyInfo pi = new PropertyInfo();
                        pi.name = "hello";
                        pi.type = outgoing;
                        SoapObject template = new SoapObject("urn:xmethods:hello", "persDataResponse");
                        
                        SoapObject client = new SoapObject("http://middleware.test/", "sayHello");
        
                        client.addProperty("hello", helloClient);
                        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                        envelope.setOutputSoapObject(client);
                        helloClient.register(envelope);
                        HttpTransport ht = new HttpTransport("http://172.16.1.1:8080/HelloWorld/HelloWorld");
                        ht.call("", envelope);
                        
                        
                        template.addProperty(pi, "irrelevant");
                        envelope.addTemplate(template);
                        envelope.bodyOut = helloClient;
                } catch ( Exception e ){
                        logger.error("Caught Exception: \n" + e);
                }
        }
}


####################### /client-Run.class #######################


As a result, the following document is sent to glassfish app server:

####################### sent XML-Document #######################


T 172.16.1.6:2978 -> 172.16.1.1:8080 [AP]
POST /HelloWorld/HelloWorld
HTTP/1.1..
SOAPAction: ..
Content-Type: text/xml.
.Content-Length: 559..
User-Agent: kSOAP/2.0..
Host: 172.16.1.1:8080....

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:d="http://www.w3.org/2001/XMLSchema"
            xmlns:c="http://schemas.xmlsoap.org/soap/encoding/"
            xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
     <v:Header />
     <v:Body>
          <n0:sayHello id="o0" c:root="1" xmlns:n0="http://middleware.test/">
               <hello i:type="n1:HelloClient" xmlns:n1="http://172.16.1.1/middleware">
                    <firstName i:type="d:string">Stefan</firstName>
                    <name i:type="d:string">Schilling</name>
                    <returnedString i:type="d:string">autsch</returnedString>
               </hello>
          </n0:sayHello>
     </v:Body>
</v:Envelope>..

####################### /sent XML-Document #######################

But the server responds with the following Exception:

####################### Glassfish-Exception #######################

[#|2008-02-20T16:01:32.134+0100|INFO|sun-appserver9.1|test.middleware.HelloWorld|_ThreadID=24;_ThreadName=httpSSLWorkerThread-8080-0;|Starting sayHello|#]

[#|2008-02-20T16:01:32.134+0100|SEVERE|sun-appserver9.1|com.sun.xml.ws.server.sei.EndpointMethodHandler|_ThreadID=24;_ThreadName=httpSSLWorkerThread-8080-0;_RequestID=d6f0f66b-791e-4f6c-a75b-0acc946fd98b;|The log message is null.
javax.ejb.EJBException
        at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:3869)
        at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:3769)
        at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:3571)
        at com.sun.ejb.containers.WebServiceInvocationHandler.invoke(WebServiceInvocationHandler.java:200)
        at $Proxy186.sayHello(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.enterprise.webservice.InvokerImpl.invoke(InvokerImpl.java:81)
        at com.sun.enterprise.webservice.EjbInvokerImpl.invoke(EjbInvokerImpl.java:82)
        at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:146)
        at com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:257)
        at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:93)
        at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
        at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
        at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
        at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
        at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:106)
        at com.sun.enterprise.webservice.MonitoringPipe.process(MonitoringPipe.java:147)
        at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:115)
        at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
        at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
        at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
        at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
        at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:106)
        at com.sun.xml.ws.tx.service.TxServerPipe.process(TxServerPipe.java:317)
        at com.sun.enterprise.webservice.CommonServerSecurityPipe.processRequest(CommonServerSecurityPipe.java:218)
        at com.sun.enterprise.webservice.CommonServerSecurityPipe.process(CommonServerSecurityPipe.java:129)
        at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:115)
        at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
        at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
        at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
        at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
        at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:243)
        at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:444)
        at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
        at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135)
        at com.sun.enterprise.webservice.Ejb3MessageDispatcher.handlePost(Ejb3MessageDispatcher.java:113)
        at com.sun.enterprise.webservice.Ejb3MessageDispatcher.invoke(Ejb3MessageDispatcher.java:87)
        at com.sun.enterprise.webservice.EjbWebServiceServlet.dispatchToEjbEndpoint(EjbWebServiceServlet.java:200)
        at com.sun.enterprise.webservice.EjbWebServiceServlet.service(EjbWebServiceServlet.java:129)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
        at com.sun.enterprise.web.AdHocContextValve.invoke(AdHocContextValve.java:114)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:87)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
        at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
        at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380)
        at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
        at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
Caused by: java.lang.NullPointerException
        at test.middleware.HelloWorld.sayHello(HelloWorld.java:19)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1067)
        at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:176)
        at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2895)
        at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:3986)
        at com.sun.ejb.containers.WebServiceInvocationHandler.invoke(WebServiceInvocationHandler.java:189)
        ... 64 more
|#]


####################### /Glassfish-Exception #######################
-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger