CXF - com.ctc.wstx.exc.WstxUnexpectedCharException: Illegal character ((CTRL-CHAR, code 5))

两盒软妹~` 提交于 2019-12-06 05:19:31

问题


I found on internet that problem is that soap request contain unicode char for ,,ctrl + v", which is illegal character in Xml. I dont know how this get into String, but I want simple to remove it on server side.

Can plase someone give me the point how to solve this issue? I found this snippet :

  XMLOutputFactory f = new WstxOutputFactory();
  f.setProperty(WstxOutputProperties.P_OUTPUT_INVALID_CHAR_HANDLER,
    new InvalidCharHandler.ReplacingHandler(' '));
  XMLStreamWriter sw = f.createXMLStreamWriter(...);

Can someone tell me how to configure Spring for construction of WstxOutputFactory with this handler? - InvalidCharHandler.ReplacingHandler(' '). Thanks for advice.


回答1:


The solution is pretty simple :

    <jaxws:endpoint id="kservice"  
                    implementor="#kostrounService"
                    address="/call_kostroun" >
                    <jaxws:properties>
                           <entry key="javax.xml.stream.XMLOutputFactory"            valueref="xmlOutputFactory" />
                     </jaxws:properties>       
    </jaxws:endpoint> 
 <bean id="invalidCharHandler"   class="com.ctc.wstx.api.InvalidCharHandler$ReplacingHandler">
         <constructor-arg value=" "/>
   </bean>

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

   <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetObject">
            <ref local="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>

This snippet of configuration remove illegal characters from soap message, and app then run ;-)



来源:https://stackoverflow.com/questions/12061766/cxf-com-ctc-wstx-exc-wstxunexpectedcharexception-illegal-character-ctrl-cha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!