1

我正在为 Web 服务编写客户端,我想使用拦截器做两件事 - 1)记录传出的 XML 消息和 2)读取 HTTP 响应,而不是 SOAP 响应。

服务端只有一个 void 方法,他们只是通过 HTTP 响应代码确认收到我的消息。

这就是他们的反应:

HTTP/1.1 202 Accepted
Date: Wed, 10 Jul 2013 23:06:36 GMT
Server: Oracle-Application-Server-11g
Content-Length: 0
X-ORACLE-DMS-ECID: 004sJ1KLm7yB_6RjMX^QsA0002X30001U5
X-Powered-By: Servlet/2.5 JSP/2.1
Content-Type: 
Content-Language: en
X-F5-ServerSSL-Profile: serverssl_sys_soaorexafun
X-F5-ForwardProxy-Host: 64.181.184.15%819 443

我需要“HTTP/1.1 202 Accepted”响应。

我的拦截器代码是:

package com.cambiahealth.orservice.client;

import org.apache.cxf.binding.soap.interceptor.EndpointSelectionInterceptor;
import org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import org.apache.log4j.Logger;

public class CoverOregonServiceInterceptor extends AbstractPhaseInterceptor<Message> {

    static Logger logger = Logger.getLogger(CoverOregonServiceInterceptor.class.getName());
    private static Integer responseCode = 0;

    public CoverOregonServiceInterceptor() {
        super(Phase.POST_INVOKE);
        addAfter(ReadHeadersInterceptor.class.getName());
        addAfter(EndpointSelectionInterceptor.class.getName());
    }

    @Override
    public void handleMessage(Message message) throws Fault {
        try{
            responseCode = (Integer) message.get(Message.RESPONSE_CODE);
            logger.info("Response Code is " + responseCode);
        } catch (Exception e){
            logger.error("Failed to read the response code from Soap message", e);
        }        
    }

    public Integer getResponseCode(){
        return responseCode;
    }

}

我客户端中的代码是:

String wsdlUrl = coverOregonServiceUrl + "?wsdl";
CoverOregonServiceInterceptor interceptor = new CoverOregonServiceInterceptor();
CoverOregonServiceInterceptor outInterceptor = new CoverOregonServiceInterceptor();
InboundEnrollmentManagementClient client = new InboundEnrollmentManagementClient(
                    new URL(wsdlUrl));
InboundEnrollManagementPortType port = client.getInboundEnrollManagementPort();
Client cxfClient = ClientProxy.getClient(port);
cxfClient.getInInterceptors().add(interceptor); 
cxfClient.getOutFaultInterceptors().add(outInterceptor);
port.statusupdate(request);

但是,我的拦截器根本没有被调用/触发。我尝试了各种不同的阶段 - READ、RECEIVE、PRE_INVOKE、POST_INVOKE、INVOKE、POST_STREAM、SEND。但他们都没有工作。在发送请求之前,我尝试了一个类似的拦截器来记录 XML 消息。而且它在那里也不起作用。有什么建议么?

4

1 回答 1

0

弄清楚了。我正在调用的服务没有返回,因此我无法使用入站拦截器链。

cxfClient.getInInterceptors().add(interceptor);

我在出站链中使用它并且它有效。

cxfClient.getOutInterceptors().add(outInterceptor);
于 2013-07-16T19:29:24.263 回答