ColdFusion SOAP Web 服务的 Servlet 过滤器适用于 WSDL,但在处理 SOAP 请求时失败
我正在尝试为 可怕的 ColdFusion bug 创建一个解决方法导致我的 SOAP Web 服务返回不一致的结果。我想要做的是在对 CFC 的任何调用的输出中将“remote_api.tafkan”替换为“remote_api”。
我创建了一个 Java servlet 过滤器来执行此操作,当我调用 WSDL 时它可以工作,但当我对服务的其中一个方法进行 SOAP 调用时它会中断。
下面是我的过滤器的代码:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public final class PFAPICorrector implements Filter {
private FilterConfig filterConfig = null;
public void init(FilterConfig filterConfig)
throws ServletException {
this.filterConfig = filterConfig;
}
public void destroy() {
this.filterConfig = null;
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
CharResponseWrapper wrapper = new CharResponseWrapper((HttpServletResponse)response);
chain.doFilter(request, wrapper);
System.out.println("ORIGINAL (" + wrapper.toString().length() + "): " + wrapper.toString());
String correctedResponse = wrapper.toString().replace("remote_api.tafkan", "remote_api");
response.setContentLength(correctedResponse.length());
System.out.println("CORRECTED (" + correctedResponse.length() + "): " + correctedResponse);
PrintWriter out = response.getWriter();
out.write(correctedResponse);
out.close();
}
}
正如我所提到的,调用在其 wsdl:documentation 中包含有问题的“remote_api.tafkan”字符串的 WSDL 会导致正确过滤的输出,并且原始和更正的调试语句会打印出预期的内容。
但是,当我向 WSDL 描述的方法之一发出 SOAP 请求(使用 SoapUI)时,过滤不起作用(字符串未替换),并且我在 CF 日志中收到以下内容
ORIGINAL (0):
CORRECTED (0):
08/05 11:00:11 error
java.lang.IllegalStateException
at jrun.servlet.JRunResponse.getWriter(JRunResponse.java:198)
at PFAPICorrector.doFilter(PFAPICorrector.java:51)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
at jrun.servlet.FilterChain.service(FilterChain.java:101)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:249)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
:我之前的过滤器正在输出 SOAP 响应并终止过滤器链,因此我的过滤器永远看不到响应,因此我的调试输出中缺少原始数据。 (我可能遇到此问题,但修补程序没有更改任何内容。)
如果无法看到 ColdFusion 的 servlet 和过滤器内部发生了什么,我如何修改 SOAP 响应?
I'm trying to create a workaround for a terrible ColdFusion bug that results in my SOAP web service returning inconsistent results. What I want to do is replace "remote_api.tafkan" with "remote_api" in the output of any call to a CFC.
I've created a Java servlet filter to do this, and it works when I call the WSDL, but it breaks when I make a SOAP call to one of the service's methods.
Here's the code for my filter:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public final class PFAPICorrector implements Filter {
private FilterConfig filterConfig = null;
public void init(FilterConfig filterConfig)
throws ServletException {
this.filterConfig = filterConfig;
}
public void destroy() {
this.filterConfig = null;
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
CharResponseWrapper wrapper = new CharResponseWrapper((HttpServletResponse)response);
chain.doFilter(request, wrapper);
System.out.println("ORIGINAL (" + wrapper.toString().length() + "): " + wrapper.toString());
String correctedResponse = wrapper.toString().replace("remote_api.tafkan", "remote_api");
response.setContentLength(correctedResponse.length());
System.out.println("CORRECTED (" + correctedResponse.length() + "): " + correctedResponse);
PrintWriter out = response.getWriter();
out.write(correctedResponse);
out.close();
}
}
As I mentioned, calling the WSDL that includes the offending "remote_api.tafkan" string in its wsdl:documentation results in properly filtered output, and the ORIGINAL and CORRECTED debug statements print out the expected content.
However, when I make a SOAP request (using SoapUI) to one of the methods described by the WSDL, the filtering doesn't work (the string is not replaced), and I get the following in my CF log:
ORIGINAL (0):
CORRECTED (0):
08/05 11:00:11 error
java.lang.IllegalStateException
at jrun.servlet.JRunResponse.getWriter(JRunResponse.java:198)
at PFAPICorrector.doFilter(PFAPICorrector.java:51)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
at jrun.servlet.FilterChain.service(FilterChain.java:101)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:249)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
It seems like one of the filters prior to mine is outputting the SOAP response and terminating the filter chain, so my filter never sees the response, hence the lack of data in ORIGINAL in my debug output. (I may be running into this issue, but the hotfix there didn't change anything.)
Without being able to see what's going on inside ColdFusion's servlets and filters, how can I modify the SOAP response?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论