繁体   English   中英

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

[英]How to Extract Requested Operation name from SoapMessage in READ phase of 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中没有可用的bindingoperationinfos,而且我不知道如何以明智的方式从SoapMessage中提取操作名称:)。

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

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中提取该方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM