Search in sources :

Example 1 with WSClientException

use of com.alibaba.csb.ws.sdk.WSClientException in project csb-sdk by aliyun.

the class BindingInterceptor method before.

/* packaged */
List<Handler> before(Object proxy) throws JAXBException {
    // 拦截器BindingInterceptor方法调用:before()!");
    if (!(proxy instanceof BindingProvider)) {
        throw new WSClientException("proxy is not a legal soap client, can not do the interceptor");
    }
    // put security info into http request headers for over-proxy invocation
    setSecrectHeaders((BindingProvider) proxy, wsparams);
    // skip this soap header logic
    if (HEADERS_INSOAP) {
        shh = new SOAPHeaderHandler(wsparams);
        BindingProvider bp = (BindingProvider) proxy;
        handlers = bp.getBinding().getHandlerChain();
        List<Handler> newHandlers = new ArrayList<Handler>();
        if (handlers != null) {
            newHandlers.addAll(handlers);
        }
        newHandlers.add(shh);
        // tip, must set the handleList again, or the handler will not
        // run!!!
        bp.getBinding().setHandlerChain(newHandlers);
    }
    return handlers;
}
Also used : ArrayList(java.util.ArrayList) Handler(javax.xml.ws.handler.Handler) BindingProvider(javax.xml.ws.BindingProvider) WSClientException(com.alibaba.csb.ws.sdk.WSClientException)

Example 2 with WSClientException

use of com.alibaba.csb.ws.sdk.WSClientException in project csb-sdk by aliyun.

the class BindingInterceptor method after.

/* packaged */
public void after(Object proxy) {
    // 拦截器BindingInterceptor方法调用:after()!");
    if (!(proxy instanceof BindingProvider)) {
        throw new WSClientException("proxy is not a legal soap client, can not do the interceptor");
    }
    // TODO: this is not work, can not clear the new-added handler!
    if (shh != null) {
        BindingProvider bp = (BindingProvider) proxy;
        bp.getBinding().getHandlerChain().remove(shh);
        bp.getBinding().setHandlerChain(handlers);
    }
}
Also used : BindingProvider(javax.xml.ws.BindingProvider) WSClientException(com.alibaba.csb.ws.sdk.WSClientException)

Example 3 with WSClientException

use of com.alibaba.csb.ws.sdk.WSClientException in project csb-sdk by aliyun.

the class SOAPHeaderHandler method handleMessage.

@Override
public boolean handleMessage(SOAPMessageContext context) {
    try {
        Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
        if (outboundProperty.booleanValue()) {
            SOAPEnvelope envelope = context.getMessage().getSOAPPart().getEnvelope();
            SOAPHeader header = envelope.getHeader();
            if (header == null)
                header = envelope.addHeader();
            if (wsParams.getAk() != null) {
                Map<String, String> headers = SignUtil.newParamsMap(null, wsParams.getApi(), wsParams.getVersion(), wsParams.getAk(), wsParams.getSk(), wsParams.isTimestamp(), wsParams.isNonce(), WSClientSDK.genExtHeader(wsParams.getFingerPrinter()));
                for (Entry<String, String> kv : headers.entrySet()) {
                    header.addHeaderElement(new QName(HEADER_NS, kv.getKey())).setTextContent(kv.getValue());
                    dumpHeaders(kv.getKey(), kv.getValue());
                }
            }
            if (wsParams.isMockRequest()) {
                header.addHeaderElement(new QName(HEADER_NS, HEADER_MOCK));
                dumpHeaders(HEADER_MOCK, "");
            }
        } else {
        // remove the unnecessary response headers
        // SOAPEnvelope envelope =
        // context.getMessage().getSOAPPart().getEnvelope();
        }
    } catch (Exception e) {
        throw new WSClientException("failed to add soap header", e);
    }
    return true;
}
Also used : QName(javax.xml.namespace.QName) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) WSClientException(com.alibaba.csb.ws.sdk.WSClientException) SOAPHeader(javax.xml.soap.SOAPHeader) WSClientException(com.alibaba.csb.ws.sdk.WSClientException)

Aggregations

WSClientException (com.alibaba.csb.ws.sdk.WSClientException)3 BindingProvider (javax.xml.ws.BindingProvider)2 ArrayList (java.util.ArrayList)1 QName (javax.xml.namespace.QName)1 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)1 SOAPHeader (javax.xml.soap.SOAPHeader)1 Handler (javax.xml.ws.handler.Handler)1