用于添加标头的自定义拦截器,不会使用更新的标头发送消息

时间:2016-12-14 20:34:46

标签: soap http-headers client cxf interceptor

我这样做

    org.apache.cxf.endpoint.Client client = ClientProxy.getClient(port);
            client.getInInterceptors().add(new HeaderHandler());

            try {
                port.[my method](inputs);
}

我的处理程序看起来像

public class HeaderHandler extends LoggingInInterceptor {

    public HeaderHandler() {
        super(Phase.PRE_STREAM);
    }

    @SuppressWarnings("unchecked")
    @Override
    public void handleMessage(Message message) throws org.apache.cxf.interceptor.Fault {
        Map<String, List<String>> headers = CastUtils.cast((Map<String, List<String>>) message.get(Message.PROTOCOL_HEADERS));
        List<String> clientid = new ArrayList<String>();
        clientid.add("");
        headers.put("clientid", clientid);

        List<String> authorization = new ArrayList<String>();
        authorization.add("Basic @#$%#$%^#$^");
        headers.put("Authorization", authorization);

        message.put(Message.PROTOCOL_HEADERS, headers);
        System.out.println("called");
    }
}

总是调用句柄消息方法并通过调试我可以在方法结束之前找到我在保存的消息中创建的标题,但是当端口方法解析时,我只有在soap请求中再次发送的默认标题

Headers: {Accept=[*/*], cache-control=[no-cache], connection=[keep-alive], Content-Length=[494], content-type=[application/soap+xml; action="urn:[my method]"; charset=UTF-8], host=[localhost:8080], pragma=[no-cache], user-agent=[Apache-CXF/3.1.8]}

是什么给出了?

1 个答案:

答案 0 :(得分:1)

请查看CXF常见问题:How can I add soap headers to the request/response?,我建议使用CXF方式

cout << theSource << endl;