5 Replies Latest reply: Nov 6, 2012 12:22 PM by 972510 RSS

    Getting issue while invoking a webservice.

    972510
      Hi All

      when i invoke a webservice which is located remotley using httpclient post method. I am getting the following error

      <faultcode>soapenv:Server.userException</faultcode>
      <faultstring>org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.</faultstring>

      Can anyone please help me out how to get out this exception. tried googling on this exception, but there is no luck.




      import java.io.File;
      import java.io.FileInputStream;

      import org.apache.commons.httpclient.HttpClient;
      import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
      import org.apache.commons.httpclient.methods.PostMethod;


      public class PostXML {

      public static void main(String[] args) throws Exception {

      // Get target URL
      String strURL = "http://localhost/services/CmdLineInterface?wsdl";

      // Get file to be posted
      String strXMLFilename = "C:\\post.xml";
      File input = new File(strXMLFilename);

      // Prepare HTTP post
      PostMethod post = new PostMethod(strURL);

      // Request content will be retrieved directly
      // from the input stream
      // Per default, the request content needs to be buffered
      // in order to determine its length.
      // Request body buffering can be avoided when
      // content length is explicitly specified
      post.setRequestEntity(new InputStreamRequestEntity(
      new FileInputStream(input), input.length()));

      // Specify content type and encoding
      // If content encoding is not explicitly specified
      // ISO-8859-1 is assumed
      post.setRequestHeader(
      "Content-type", "text/xml; charset=ISO-8859-1");
      // post.set
      post.setRequestHeader("SOAPAction", "");

      // Get HTTP client
      HttpClient httpclient = new HttpClient();

      // Execute request
      try {

      int result = httpclient.executeMethod(post);


      // Display status code
      System.out.println("Response status code: " + result);

      // Display response
      System.out.println("Response body: ");
      System.out.println(post.getResponseBodyAsString());



      }catch(Exception e)
      {
           e.printStackTrace();
      }finally {
      // Release current connection to the connection pool
      // once you are done
      post.releaseConnection();
      }
      }
      }

      the above is the code i am using for calling the webservice.

      Anyone can you please help me on this.

      Regards
      Rakesh
        • 1. Re: Getting issue while invoking a webservice.
          jtahlborn
          it means your xml doesn't match what the server is expecting. without knowing what the server is expecting and what you are sending, it's hard to give much in the way of further guidance.
          • 2. Re: Getting issue while invoking a webservice.
            972510
            Hi


            Thank you very much for replying , i had modified the XML part which had worked.

            where as i ma getting an out put

            with html encodings

            &lt and &gt.


            Here is my input i had given to the code which i had posted earlier.

            <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:test">
            <soapenv:Header/>
            <soapenv:Body>
            <processCmdLineRequest xmlns="urn:prrq"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
            <test>
                    <requestInfo>
                            <headerInfo>
                                    <interface>CLI</interface>
                                    <requestType>userinfo</requestType>
                                    <actionName>myhome</actionName>
                            </headerInfo>
                            <queueName>beta-testing</queueName>
                            <lookIn>thisqimpact</lookIn>
                           <user>amesh</user>               
                    </requestInfo>
            </test>]]></processCmdLineRequest>
            </soapenv:Body>
            </soapenv:Envelope>


            and i get the output as follows.
            <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><processCmdLineRequestReturn xmlns="urn:prrq">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
            &lt;responseInfo&gt;
                 &lt;messageCode&gt;SUC-124&lt;/messageCode&gt;
                 &lt;messageDescription&gt;The requested information is as follows..&lt;/messageDescription&gt;
                 &lt;OpenRequests&gt;
                 &lt;review&gt;
                 &lt;Product&gt;&lt;/Product&gt;


            But i should get the output in standard xml tags

            without sopad envlope.. can you please help me on this.
            Regards
            Rakesh
            • 3. Re: Getting issue while invoking a webservice.
              EJP
              Please post your WSDL so we can know what your server is expecting. Hard to see how you think we can proceed without it, but we can't.
              • 4. Re: Getting issue while invoking a webservice.
                jtahlborn
                user8395058 wrote:
                and i get the output as follows.
                <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><processCmdLineRequestReturn xmlns="urn:prrq">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
                &lt;responseInfo&gt;
                     &lt;messageCode&gt;SUC-124&lt;/messageCode&gt;
                     &lt;messageDescription&gt;The requested information is as follows..&lt;/messageDescription&gt;
                     &lt;OpenRequests&gt;
                     &lt;review&gt;
                     &lt;Product&gt;&lt;/Product&gt;


                But i should get the output in standard xml tags

                without sopad envlope.. can you please help me on this.
                why would you expect soap response to not have a soap envelope? that's how soap works...
                • 5. Re: Getting issue while invoking a webservice.
                  972510
                  Hi

                  Thank you very much for replying back..

                  Here is my WSDL file i am using


                  This XML file does not appear to have any style information associated with it. The document tree is shown below.
                  <wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="urn:test" xmlns:intf="urn:test" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:test">
                  <!--
                  WSDL created by Apache Axis version: 1.4 Built on Apr 22, 2006 (06:55:48 PDT)
                  -->
                  <wsdl:types>
                  <schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="urn:test">
                  <element name="in0" type="xsd:string"/>
                  <element name="processCmdLineRequestReturn" type="xsd:string"/>
                  </schema>
                  </wsdl:types>
                  <wsdl:message name="processCmdLineRequestResponse">
                  <wsdl:part element="intf:processCmdLineRequestReturn" name="processCmdLineRequestReturn"/>
                  </wsdl:message>
                  <wsdl:message name="processCmdLineRequestRequest">
                  <wsdl:part element="intf:in0" name="in0"/>
                  </wsdl:message>
                  <wsdl:portType name="CmdLineInterface">
                  <wsdl:operation name="processCmdLineRequest" parameterOrder="in0">
                  <wsdl:input message="intf:processCmdLineRequestRequest" name="processCmdLineRequestRequest"/>
                  <wsdl:output message="intf:processCmdLineRequestResponse" name="processCmdLineRequestResponse"/>
                  </wsdl:operation>
                  </wsdl:portType>
                  <wsdl:binding name="CmdLineInterfaceSoapBinding" type="intf:CmdLineInterface">
                  <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
                  <wsdl:operation name="processCmdLineRequest">
                  <wsdlsoap:operation soapAction=""/>
                  <wsdl:input name="processCmdLineRequestRequest">
                  <wsdlsoap:body use="literal"/>
                  </wsdl:input>
                  <wsdl:output name="processCmdLineRequestResponse">
                  <wsdlsoap:body use="literal"/>
                  </wsdl:output>
                  </wsdl:operation>
                  </wsdl:binding>
                  <wsdl:service name="CmdLineInterfaceService">
                  <wsdl:port binding="intf:CmdLineInterfaceSoapBinding" name="CmdLineInterface">
                  <wsdlsoap:address location="http://localhost:8080/test/services/CmdLineInterface"/>
                  </wsdl:port>
                  </wsdl:service>
                  </wsdl:definitions>

                  Regards
                  Rakesh