如何在CXF的READ阶段从SoapMessage中提取请求的操作名称?

时间:2014-08-16 06:01:23

标签: java cxf

我有一个以下拦截器来记录请求的操作名称。

public class ServiceLogPreInterceptor extends AbstractSoapInterceptor {

    public static Logger logger = LoggerFactory
        .getLogger(ServiceLogPreInterceptor.class);

    public ServiceLogPreInterceptor() {
            super(Phase.READ);
            addAfter(StartBodyInterceptor.class.getName());
            addAfter(ReadHeadersInterceptor.class.getName());
            addAfter(EndpointSelectionInterceptor.class.getName());
     }

    @Override
    public void handleMessage(SoapMessage message) throws Fault {
        // I need Requested Operation name here!!
        String opName = getOperationName(message);

        logger.debug(opName);
    }

    private String getOperationName(String msg) {
         return "??????";
    }

}

这是我的拦截链

ServiceLogPreInterceptor(READ) - > AuthenticationInterceptor(SAAJInterceptor) - > authorizationInterceptor(PRE_INVOKE) - >和实际的方法调用

bindingoperationinfos在我的authorizationInterceptor中可用但是 我的ServiceLogPreInterceptor中没有可用的绑定操作,我不知道如何以合理的方式从SoapMessage中提取操作名称:)。

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。这是我的解决方案。

public BindingOperationInfo extractBindingOperationInfo(Message message) {
    DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
    DataReader<XMLStreamReader> dr = getDataReader(message);
    boolean client = isRequestor(message);
    Exchange exchange = message.getExchange();
    BindingOperationInfo bop = null;

    Service service = ServiceModelUtil.getService(message.getExchange());

    try {

        Endpoint ep = exchange.get(Endpoint.class);
        ServiceInfo si = ep.getEndpointInfo().getService();
        Collection<OperationInfo> operations = null;
        operations = new ArrayList<OperationInfo>();
        operations.addAll(si.getInterface().getOperations());

        if (xmlReader == null || !StaxUtils.toNextElement(xmlReader)) {
            // empty input
            bop = getBindingOperationForEmptyBody(operations, ep, exchange);
            return bop;
        }

        setDataReaderValidation(service, message, dr);


        QName elName = xmlReader.getName();
        bop = findMessagePart(exchange, operations, elName, client,
                 message);

    } catch (Fault f) {
        if (!isRequestor(message)) {
            f.setFaultCode(Fault.FAULT_CODE_CLIENT);
        }
        throw f;
    }

    return bop;
}

然后从bindigOperationInfo中提取方法。