Remove invalid characters from soap response in JAX-WS
<p>I am trying to get the lists present on a sharepoint site using SP webservice.</p>

<pre><code>Lists listsSevice = new Lists(new URL(spSiteURL + "/_vti_bin/Lists.asmx?wsdl"));
listsSevice.setHandlerResolver(new SPHandlerResolver());
spListsServiceIfx = listsSevice.getListsSoap();
// Calling the List Web Service
GetListItemsResponse.GetListItemsResult result = spListsServiceIfx .getListItems(listName, viewName, query, viewFields, rowLimit, queryOptions, webID);
</code></pre>

<p>However, I get this error because of some invalid character present in soap response.</p>

<pre><code>com.sun.xml.ws.encoding.soap.DeserializationException: Failed to read a response: javax.xml.bind.UnmarshalException
- with linked exception:
[com.ctc.wstx.exc.WstxParsingException: Illegal character entity: expansion character (code 0x15 at [row,col {unknown-source}]: [1125,122]]
</code></pre>

<p>I tried to modify the SOAPMessage to remove invalid characters from response.</p>

<pre><code>public class SOAPMessageHandler implements SOAPHandler&lt;SOAPMessageContext&gt; {

public boolean handleMessage(SOAPMessageContext smc) {
    System.out.println("in handleMessage");
    Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    System.out.println("outboundProperty: " + outboundProperty);

    try {
        if (outboundProperty.booleanValue()) {
            System.out.println(" SOAP Request ");
        } else {
            System.out.println(" SOAP Response ");
            SOAPMessage message = smc.getMessage();
            message.writeTo(System.out);
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            message.writeTo(out);
            String messageAsString = new String(out.toByteArray());
            /*smc.setMessage(new SOAPMessage( 
            stripNonValidXMLCharacters(message.getSOAPPart().toString())));*/
        }

    } catch (SOAPException e) {         
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        System.out.println("in soap msg handler..." + e.getMessage());
        e.printStackTrace();
    }
    System.out.println(""); 

    return true;
}
</code></pre>

<p>But I get an exception at</p>

<pre><code> SOAPMessage message = smc.getMessage();
</code></pre>

<p>The stack trace is:</p>

<pre><code>javax.xml.ws.WebServiceException: javax.xml.soap.SOAPException: org.xml.sax.SAXParseException; lineNumber: 1125; columnNumber: 122; Illegal character entity: expansion character (code 0x15
at [row,col {unknown-source}]: [1125,122]
at com.sun.xml.ws.handler.SOAPMessageContextImpl.getMessage(SOAPMessageContextImpl.java:86)
at com.cah.ecm.sharepoint.migrator.util.SOAPMessageHandler.handleMessage(SOAPMessageHandler.java:25)
at com.cah.ecm.sharepoint.migrator.util.SOAPMessageHandler.handleMessage(SOAPMessageHandler.java:1)
at com.sun.xml.ws.handler.HandlerProcessor.callHandleMessageReverse(HandlerProcessor.java:341)
at com.sun.xml.ws.handler.HandlerProcessor.callHandlersResponse(HandlerProcessor.java:214)
at com.sun.xml.ws.handler.ClientSOAPHandlerTube.callHandlersOnResponse(ClientSOAPHandlerTube.java:163)
at com.sun.xml.ws.handler.HandlerTube.processResponse(HandlerTube.java:164)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:651)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:600)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:585)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:482)
at com.sun.xml.ws.client.Stub.process(Stub.java:323)
at com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:161)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:113)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:93)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:144)
at com.sun.proxy.$Proxy28.getListItems(Unknown Source)
at com.cah.ecm.sharepoint.migrator.sharepoint.client.SharepointClient.getListItemNodes(SharepointClient.java:292)
at com.cah.ecm.sharepoint.migrator.sharepoint.client.SharepointClient.getListItems(SharepointClient.java:389)
at com.cah.ecm.sp.jde.main.TestIterateAllSPFiles.main(TestIterateAllSPFiles.java:35)
</code></pre>

<p>Please help me with where I am wrong and if there is an alternate way to remove invalid characters from SOAP response.</p>

<p>Thanks!</p>