0

I have been looking to find a solution to alter/strip out the SOAP response from a proxy service before it hits to Woodstox's DeserializationException. Below is the exception I am getting. Before giving out straigt answers like CTRL-CHAR's are not valid for XML, creating a custom SOAP Message handler some facts:

  • This is a java desktop application, so no Tomcat

  • Have the wsdl and stubs are generated through JAX-WS RI 2.2.8

  • The Web Service Client configuration is as follow :

    <bean id="serviceProxy" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
        <property name="serviceInterface" value="local generated stub"/>
        <property name="wsdlDocumentUrl" value="--wsdl URL--"/>
        <property name="namespaceUri" value="urn:address"/>
        <property name="serviceName" value="proxyService"/>
        <property name="portName" value="Some_Wsi_HandlerPort"/>
        <property name="lookupServiceOnStartup" value="false" />
    </bean>
    

I tried the following configuration, but it didn't work :

<jaxws:client id="localService">
    <jaxws:properties>
       <entry key="javax.xml.stream.XMLOutputFactory">
            <ref bean="xmlOutputFactory"/>
        </entry>
     </jaxws:properties>       
</jaxws:client>

<bean id="invalidCharHandler"   class="com.ctc.wstx.api.InvalidCharHandler$ReplacingHandler">
    <constructor-arg value=" "/>
</bean>

<bean id="xmlOutputFactory" class="com.ctc.wstx.stax.WstxOutputFactory"/>

<beanclass="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject">
        <ref bean="xmlOutputFactory" />
    </property>
    <property name="targetMethod">
        <value>setProperty</value>
    </property>
    <property name="arguments">
        <list>
             <util:constant static-field="com.ctc.wstx.api.WstxOutputProperties.P_OUTPUT_INVALID_CHAR_HANDLER"/>
             <ref bean="invalidCharHandler" />
        </list>
    </property>
</bean>

I also tried creating custom SOAPHandler and LogicalHandler but they didn't help either.

I know there are methods to search and replace the unicode chars from the response body and consume it after manupulating the response body, but what I am looking for is a filter just like in the WstxOutputProperties.P_OUTPUT_INVALID_CHAR_HANDLER config above, which didn't work :( so without breaking the request and reponse to this proxy service, I just want the Woodstox or Spring or anything that I can inject customized to filter the invalid chars from the reponse before throwing an error and breaking the communication.

org.springframework.remoting.RemoteAccessException: Could not access remote service at [null]; nested exception is com.sun.xml.ws.encoding.soap.DeserializationException: Failed to read a response: javax.xml.bind.UnmarshalException - with linked exception: [com.ctc.wstx.exc.WstxUnexpectedCharException: Illegal character ((CTRL-CHAR, code 31)) at [row,col {unknown-source}]: [91,222]] at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.doInvoke(JaxWsPortClientInterceptor.java:565) at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.invoke(JaxWsPortClientInterceptor.java:541) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) at com.sun.proxy.$Proxy42.salesOrderInfo(Unknown Source)

UCJava
  • 307
  • 4
  • 19

1 Answers1

0

If you did control output side, the method you found (explained here) would work. But it sounds like something else is writing/adding invalid characters.

If so, I think you will need to implemented a java.io. FilterInputStream that just strips out such control characters: they are relatively easy to find, esp. if you only have trouble with 0x1F.

StaxMan
  • 113,358
  • 34
  • 211
  • 239
  • How can I inject the java.io.FilterInputStream implementation into the configuration then ? – UCJava Oct 28 '16 at 18:56
  • @UCJava unfortunately I don't know answer to that, if you do not control actual invocation (which sounds like you don't). So you may have to figure out how to get server give well-formed proper XML -- control characters are not allowed, so who-/whatever produces content it is not XML by definition. – StaxMan Oct 28 '16 at 19:44