Search code examples
jquerysoapjqgrid

jqGrid soap error - Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '_' (code 95) in prolog; expected '<'


I implemented simple SOAP web services. The request and response XML are successfully transferred with soapUI.

== Request XML

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:aaa="http://www.aaa.com">
   <soapenv:Header/>
   <soapenv:Body>
      <aaa:getMember/>
   </soapenv:Body>
</soapenv:Envelope>

== Response XML

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/>
   <soap:Body>
      <ns2:getMemberResponse xmlns:ns2="http://www.aaa.com">
         <return>
            <user>
               <id>aupres</id>
               <passwd>aaa</passwd>
               <age>45</age>
               <name>husband</name>
            </user>
            <user>
               <id>hwa5383</id>
               <passwd>bbb</passwd>
               <age>40</age>
               <name>wife</name>
            </user>
            <user>
               <id>julian</id>
               <passwd>ccc</passwd>
               <age>15</age>
               <name>son</name>
            </user>
         </return>
      </ns2:getMemberResponse>
   </soap:Body>
</soap:Envelope>

I try to call the response soap XML with jqGrid script like belows

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery SOAP test</title>
<link rel="stylesheet" type="text/css" media="screen" href="jquery-ui.css"/>
<link rel="stylesheet" type="text/css" media="screen" href="ui.jqgrid.css"/>
<script type="text/javascript" src="jquery-2.2.0.min.js"></script>
<script type="text/javascript" src="jquery.jqGrid.min.js"></script>
<script type="text/javascript" src="grid.locale-kr.js"></script>
</head>
<body>
<table id="grid"></table>
<div id="pager"></div>
<script>
$(document).ready(function(){
   var soapMessage = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " + 
            "xmlns:aaa=\"http://www.aaa.com\"> " +
            "<soapenv:Header/> " +
            "<soapenv:Body> " +
            "<aaa:getMember/> " +
            "</soapenv:Body> " +
            "</soapenv:Envelope>"

   var $Grid = $("#grid");
   $Grid.jqGrid({
      mtype: "post",
      url: "CallMemberBean",
      datatype: "xml",
      datastr: soapMessage,
      processData: false,

      xmlReader : {
         root : "return" 
      },
     colNames : [
        'id',
        'password',
        'age',
        'name'
     ],
     colModel : [
        { name : 'id',        width:40,  align:'center', xmlmap:'id'},
        { name : 'passwd',    width:80,  align:'left',  xmlmap:'passwd'},
        { name : 'age',       width:80,  align:'left',  xmlmap:'age'},
        { name : 'name',      width:80,  align:'right', xmlmap:'name' }
     ],
     pager : '#pager',
     rowNum : '10',

     loadComplete : onloadComplete,

     loadError : onloadError,

     gridComplete : ongridComplete
      });

      function onloadComplete(data) {
     console.log(data)
      }

      function onloadError(jqXHR, textStatus, errorThrown) {
     console.log(jqXHR)
     console.log(errorThrown)
         console.log(textStatus)
          }
    });

This jqGrid client codes throw the following error

20:45:52,568 WARNING [org.apache.cxf.phase.PhaseInterceptorChain] (default task-45) Interceptor for {http://www.aaa.com}CallMemberBeanService has thrown exception, unwinding now: org.apache.cxf.binding.soap.SoapFault: Error reading XMLStreamReader.
    at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:259)
    at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:65)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:241)
    at org.jboss.wsf.stack.cxf.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:97)
    at org.jboss.wsf.stack.cxf.transport.ServletHelper.callRequestHandler(ServletHelper.java:131)
    at org.jboss.wsf.stack.cxf.CXFServletExt.invoke(CXFServletExt.java:88)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:286)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:206)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
    at org.jboss.wsf.stack.cxf.CXFServletExt.service(CXFServletExt.java:136)
    at org.jboss.wsf.spi.deployment.WSFServlet.service(WSFServlet.java:140) [jbossws-spi-2.3.1.Final.jar:2.3.1.Final]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:248) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:77) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:167) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:761) [undertow-core-1.1.8.Final.jar:1.1.8.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.8.0_65]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.8.0_65]
    at java.lang.Thread.run(Unknown Source) [rt.jar:1.8.0_65]
Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '_' (code 95) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]
    at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:639)
    at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2052)
    at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1134)
    at com.ctc.wstx.sr.BasicStreamReader.nextTag(BasicStreamReader.java:1157)
    at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:161)
    ... 39 more

Solution

  • The error message, which you posted looks like server side error. You use datatype: "xml" and the data will be loaded from url: "CallMemberBean". To use datastr: soapMessage as the input data of the grid instead of making request to url you need to use datatype: "xmlstring".

    If the soapMessage contains the Request XML, then you should use postData parameter instead of datastr parameter:

    postData: soapMessage
    

    If the type of postData parameter is the string, like in your case, then the value of postData replace the standard parameter, which send jqGrid typically. You should probably add ajaxGridOptions: { contentType: "text/xml; charset=utf-8" } option additionally.

    One more way to send custom formatted data to the server is the usage of serializeGridData callback function. The data, which returns the callback, will be used as the data used by underlying jQuery.ajax request. It allows you to build SOAP request which contains some dynamic options (the current page number, the page size and so on):

    serializeGridData: function (postdata) {
        return soapMessage; // can be build from postdata dynamically
    }