开发者

Servlet filter for ColdFusion SOAP web service works for WSDL, but fails on SOAP requests

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, cal开发者_StackOverflowling 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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜