Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with deserialization of String sent over wire with XStream
    primarykey
    data
    text
    <p>I am trying to create a simple webservice which takes a String as input and returns string as output. I am using Ecelipse Helios and Axis 2.15.</p> <ol> <li>I am writing simple WSDL for the same.</li> <li>I am generating the stubs using code generator. <blockquote> <p>New ->code generator -> java class from wsdl-> give WSDL and generates the java skeletons.</li> <li>And in the skelton I am just print the value what is coming as parameter. and returning the same value.</li> <li>I have written client code to invoke the method of the webservice. which takes a String.</li> <li>but when I am trying to invoke the method I am getting following exception and it's not hitting the webservice.</li> </ol> <p>Infact I am using XStream along with Client/WebService.</p> </blockquote></p> <p>Code goes like this for the webservice skeleton:</p> <pre><code>public com.url.pkg.ShowInputResponse showInput( com.url.pkg.ShowInput showInput) { // TODO : fill this with the necessary business logic String inputString = showInput.getInputString(); System.out.println("INput String is :\n" + inputString); XStream xStream = new XStream(); System.out.println("After XStream Declaration..."); SOVO vo = null; try { vo = (SOVO) xStream.fromXML(inputString); } catch (Throwable e) { System.out.println(e); e.printStackTrace(); } System.out.println("After SOVO casting from XML"); System.out.println(vo.getName()); System.out.println(vo.getParams()); // TODO: business logic ShowInputResponse response = new ShowInputResponse(); response.set_return(inputString); return response; } </code></pre> <p>My client code goes like this :</p> <pre><code>public static void main(String[] args) throws Exception { BasicServiceStub stub = new BasicServiceStub(); ShowInput request = new ShowInput(); SOVO sovo = new SOVO(); sovo.setName("I am the post for SO"); Map params = new HashMap(); params.put("key1", "val1"); params.put("key2", "val2"); sovo.setParams(params); XStream xStream = new XStream(); String soVoString = xStream.toXML(sovo); // System.out.println(soVoString); request.setInputString(soVoString); ShowInputResponse response = stub.showInput(request); System.out.println("...................................."); System.out.println("response = " + response.get_return()); } </code></pre> <p>SOVO is a simple POJO which is present at both client and webservice side.</p> <pre><code>public class SOVO { private String name; private Map params; public String getName() { return name; } public void setName(String name) { this.name = name; } public Map getParams() { return params; } public void setParams(Map params) { this.params = params; } } </code></pre> <p>And last but most important WSDL is here:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://pkg.url.com" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://pkg.url.com"&gt; &lt;wsdl:types&gt; &lt;xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://pkg.url.com"&gt; &lt;xs:element name="showInput"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element minOccurs="0" name="inputString" nillable="true" type="xs:string"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:element name="showInputResponse"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;/xs:schema&gt; &lt;/wsdl:types&gt; &lt;wsdl:message name="showInputRequest"&gt; &lt;wsdl:part name="parameters" element="ns:showInput"/&gt; &lt;/wsdl:message&gt; &lt;wsdl:message name="showInputResponse"&gt; &lt;wsdl:part name="parameters" element="ns:showInputResponse"/&gt; &lt;/wsdl:message&gt; &lt;wsdl:portType name="BasicServicePortType"&gt; &lt;wsdl:operation name="showInput"&gt; &lt;wsdl:input message="ns:showInputRequest" wsaw:Action="urn:showInput"/&gt; &lt;wsdl:output message="ns:showInputResponse" wsaw:Action="urn:showInputResponse"/&gt; &lt;/wsdl:operation&gt; &lt;/wsdl:portType&gt; &lt;wsdl:binding name="BasicServiceSoap11Binding" type="ns:BasicServicePortType"&gt; &lt;soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/&gt; &lt;wsdl:operation name="showInput"&gt; &lt;soap:operation soapAction="urn:showInput" style="document"/&gt; &lt;wsdl:input&gt; &lt;soap:body use="literal"/&gt; &lt;/wsdl:input&gt; &lt;wsdl:output&gt; &lt;soap:body use="literal"/&gt; &lt;/wsdl:output&gt; &lt;/wsdl:operation&gt; &lt;/wsdl:binding&gt; &lt;wsdl:binding name="BasicServiceSoap12Binding" type="ns:BasicServicePortType"&gt; &lt;soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/&gt; &lt;wsdl:operation name="showInput"&gt; &lt;soap12:operation soapAction="urn:showInput" style="document"/&gt; &lt;wsdl:input&gt; &lt;soap12:body use="literal"/&gt; &lt;/wsdl:input&gt; &lt;wsdl:output&gt; &lt;soap12:body use="literal"/&gt; &lt;/wsdl:output&gt; &lt;/wsdl:operation&gt; &lt;/wsdl:binding&gt; &lt;wsdl:binding name="BasicServiceHttpBinding" type="ns:BasicServicePortType"&gt; &lt;http:binding verb="POST"/&gt; &lt;wsdl:operation name="showInput"&gt; &lt;http:operation location="BasicService/showInput"/&gt; &lt;wsdl:input&gt; &lt;mime:content type="text/xml" part="showInput"/&gt; &lt;/wsdl:input&gt; &lt;wsdl:output&gt; &lt;mime:content type="text/xml" part="showInput"/&gt; &lt;/wsdl:output&gt; &lt;/wsdl:operation&gt; &lt;/wsdl:binding&gt; &lt;wsdl:service name="BasicService"&gt; &lt;wsdl:port name="BasicServiceHttpSoap11Endpoint" binding="ns:BasicServiceSoap11Binding"&gt; &lt;soap:address location="http://localhost:8080/axis2/services/BasicService"/&gt; &lt;/wsdl:port&gt; &lt;wsdl:port name="BasicServiceHttpSoap12Endpoint" binding="ns:BasicServiceSoap12Binding"&gt; &lt;soap12:address location="http://localhost:8080/axis2/services/BasicService"/&gt; &lt;/wsdl:port&gt; &lt;wsdl:port name="BasicServiceHttpEndpoint" binding="ns:BasicServiceHttpBinding"&gt; &lt;http:address location="http://localhost:8080/axis2/services/BasicService"/&gt; &lt;/wsdl:port&gt; &lt;/wsdl:service&gt; &lt;/wsdl:definitions&gt; </code></pre> <p>And the Stack trace for the exception I must modify :</p> <p>I am not very sure if its hitting the webservice layer.</p> <pre><code>Caused by: org.apache.axis2.AxisFault: string at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:446) at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:371) at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:417) at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229) at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165) at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165) at com.url.pkg.BasicServiceStub.showInput(BasicServiceStub.java:184) at com.url.pkg.Client.main(Client.java:30) </code></pre> <p>It looks like more its some problem with XStream desirialization. Even though SOVO is in the classpath why its happening? Am I missing something?</p> <p>When I try sending XXXXX as string it tells:</p> <blockquote> <p>only whitespace content allowed before start tag and not X (position: START_DOCUMENT seen X... @1:1) </p> </blockquote> <p>When i try sending "some value" it says:</p> <blockquote> <p>only whitespace content allowed before start tag and not s (position: START_DOCUMENT seen s... @1:1) </p> </blockquote> <p>I am not sure what's wrong.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload