问题
I am using Spring, CXF, Tomcat for developing web services.
I have a problem sending characters such as pipes(|) in the URL?
For example:
http://localhost:9080/address/v1/countries/\
|
throws a 500 error, is there a way to handle it and throw custom error code like 404 or even 400?
I tried setting the URIEncoding="UTF-8" on the connector object in server.xml in tomcat. But it did not fix it.
I also tried adding filter-mapping in the web.xml in my application like this:-
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Can someone point me in what way these kind of URI's can return a custom error code and message?
回答1:
please refer here for url encoding. Say suppose if you want to send Sachin|Tendulkar. You can send as Sachin%7CTendulkar.
回答2:
Yes. %7C is PIPE Character that needs to be used in URL. following is another example that I used successfully. In this neighborhood name is "ROOT|RESTFUL" which is represented as ROOT%7CRESTFUL
http://localhost:8080/BAE_4_3_API/rest/v1/user/rahul1/neighborhood/ROOT%7CRESTFUL/collaboration/1000/whiteboard
来源:https://stackoverflow.com/questions/21940826/how-to-handle-escape-characters-pipe-in-url-spring-rest-cxf