更新时间:2023-01-31 19:09:36
Spring WS servlet 前面的 servlet 过滤器如何检查 url 和 params?
How about a servlet filter in front of the Spring WS servlet that checks the url and the params?
如果匹配,则返回 WSDL,否则就让请求通过,就好像什么都没发生一样.
In case of a match, you return the WSDL, otherwise you let the request through as if nothing happened.
这应该很容易实现并且可以满足您的需求,如果您绝对必须将 WS + ?WSDL 的 url 附加到它.
This should be trivial to implement and will fill your need, if you absolutely must have the url of the WS + ?WSDL appended to it.
代码如下:
public class WsdlQueryCompatibilityFilter implements Filter {
@Override
public void init(final FilterConfig filterConfig) throws ServletException {
// do nothing
}
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
throws IOException, ServletException {
final HttpServletRequest httpServletRequest = (HttpServletRequest) request;
if ("GET".equals(httpServletRequest.getMethod())
&& "wsdl".equalsIgnoreCase(httpServletRequest.getQueryString())) {
httpServletRequest.getSession().getServletContext().getRequestDispatcher("/ws.wsdl")
.forward(request, response);
} else {
chain.doFilter(request, response);
}
}
@Override
public void destroy() {
// do nothing
}
}