Illegal character - CTRL-CHAR
Thanks guys for you inputs. I am sharing solution might be helpful for others.
The requirement was not to wipe out CONTROL CHAR, it should remain as it is in DB also and one WS sends it across n/w client should able to get the CONTROL CHAR. So I implemented the code as follow:
- Encode strings using URLEncoder in Web-Service code.
- At client Side decode it using URLDecoder
Sharing sample code and output bellow.
Sample code:
System.out.println("NewSfn");
System.out.println(URLEncoder.encode("NewSfn", "UTF-8"));
System.out.println(URLDecoder.decode("NewSfn", "UTF-8"));
Output:
NewSfn
New%0FSfn
NewSfn
So client will recieve CONTROL CHARs.
EDIT: Stack Exchange is not showing CONTROL CHAR above. NewSfn
is like this New(CONTROL CHAR)Sfn
.
CXF - com.ctc.wstx.exc.WstxUnexpectedCharException: Illegal character ((CTRL-CHAR, code 5))
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 ;-)
Related Topics
How to Disable Spring Security for Particular Url
Gson Expected Begin_Array But Was String At Line 1 Column 62
Delete Not Working in Hibernate/Spring Data
Crudrepository and Hibernate: Save(List<S>) VS Save(Entity) in Transaction
Changing Scene When a Button Is Pressed Fxml
How to Change the Background Color of a Textfield Without Changing the Border in Javafx
How to Read All Classes from a Java Package in the Classpath
Server_Error: [Code] 1675030 [Message]: Error Performing Query
What Part of My Code Is Making My Performance Suffer (Codility'S Maxcounter)
Run Gradle Task With Spring Profiles (Integration Tests)
Java Program to Find Palindrome Numbers in Given Range
Cannot Find Element Using Selenium Webdriver
Use Only One Bufferedreader Object to Read Multiple Files in Java
Select the Letters After - in a String
Round Off a Double While Maintaining the Trailing Zero
Jpa Repository Query - Java.Lang.Object; Cannot Be Cast to Model