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

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

10-01 08:29