在Java中修改SOAP请求内容类型

时间:2019-03-23 00:58:04

标签: java soap

是否可以修改传入的SOAP请求的内容类型?我正在尝试将内容类型从text / xml更改为application / soap + xml。

我的过滤器类

public class SOAPFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
            throws IOException, ServletException {

        SOAPRequestWrapper requestWrapper = new SOAPRequestWrapper((HttpServletRequest) request);
        filterChain.doFilter(requestWrapper, response);
    }

    @Override
    public void destroy() {
    }

    @Override
    public void init(FilterConfig arg0) throws ServletException {
    }
}

我的请求包装器

public class SOAPRequestWrapper extends HttpServletRequestWrapper {

    private ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    private Map headerMap;

    public SOAPRequestWrapper(HttpServletRequest request) {
        super(request);
        System.out.println("In Wrapper");
    }

    @Override
    public Enumeration<String> getHeaders(String name) {
        System.out.println("In method");
        List<String> headerVals = Collections.list(super.getHeaders(name));
        int index = 0;
        for (String value : headerVals) {
            headerVals.set(index, value.replaceAll("text/xml", "application/soap+xml"));
            index++;
        }
        return Collections.enumeration(headerVals);
    }

    @Override
    public String getHeader(String name) {
        System.out.println("In method1");
        String headerValue = super.getHeader(name);
        if ("Content-Type".equalsIgnoreCase(name)) {
            return headerValue.replaceAll("text/xml", "application/soap+xml");
        }
        return headerValue;
    }

}

除包装器构造函数中的语句外,没有任何语句在我的日志中打印。我在这里想念什么吗?

0 个答案:

没有答案