Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring CXF-com.ctc.wstx.exc.WstxUnexpectedCharException:非法字符((CTRL-CHAR,代码5))_Spring_Cxf_Illegal Characters - Fatal编程技术网

Spring CXF-com.ctc.wstx.exc.WstxUnexpectedCharException:非法字符((CTRL-CHAR,代码5))

Spring CXF-com.ctc.wstx.exc.WstxUnexpectedCharException:非法字符((CTRL-CHAR,代码5)),spring,cxf,illegal-characters,Spring,Cxf,Illegal Characters,我在互联网上发现,问题是soap请求包含unicode字符,表示“、ctrl+v”,这在Xml中是非法字符。我不知道如何将其转换为字符串,但我希望简单地在服务器端将其删除 有人能告诉我如何解决这个问题吗? 我发现了这个片段: XMLOutputFactory f = new WstxOutputFactory(); f.setProperty(WstxOutputProperties.P_OUTPUT_INVALID_CHAR_HANDLER, new InvalidCharHa

我在互联网上发现,问题是soap请求包含unicode字符,表示“、ctrl+v”,这在Xml中是非法字符。我不知道如何将其转换为字符串,但我希望简单地在服务器端将其删除

有人能告诉我如何解决这个问题吗? 我发现了这个片段:

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

有人能告诉我如何配置Spring以使用此处理程序构建WstxOutputFactory吗?-InvalidCharHandler.ReplacingHandler(“”)。感谢您的建议。

解决方案非常简单:

    <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>

设定属性
此配置片段从soap消息中删除非法字符,然后应用程序运行;-)