Search in sources :

Example 1 with Scope

use of javax.xml.ws.handler.MessageContext.Scope in project cxf by apache.

the class JaxWsClientProxy method invoke.

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if (client == null) {
        throw new IllegalStateException("The client has been closed.");
    }
    Endpoint endpoint = getClient().getEndpoint();
    String address = endpoint.getEndpointInfo().getAddress();
    MethodDispatcher dispatcher = (MethodDispatcher) endpoint.getService().get(MethodDispatcher.class.getName());
    Object[] params = args;
    if (null == params) {
        params = new Object[0];
    }
    try {
        if (method.getDeclaringClass().equals(BindingProvider.class) || method.getDeclaringClass().equals(Object.class) || method.getDeclaringClass().equals(Closeable.class) || method.getDeclaringClass().equals(AutoCloseable.class)) {
            return method.invoke(this, params);
        } else if (method.getDeclaringClass().isInstance(client)) {
            return method.invoke(client, params);
        }
    } catch (InvocationTargetException e) {
        throw e.getCause();
    }
    BindingOperationInfo oi = dispatcher.getBindingOperation(method, endpoint);
    if (oi == null) {
        Message msg = new Message("NO_BINDING_OPERATION_INFO", LOG, method.getName());
        throw new WebServiceException(msg.toString());
    }
    client.getRequestContext().put(Method.class.getName(), method);
    boolean isAsync = isAsync(method);
    Object result = null;
    try {
        if (isAsync) {
            result = invokeAsync(method, oi, params);
        } else {
            result = invokeSync(method, oi, params);
        }
    } catch (WebServiceException wex) {
        throw wex;
    } catch (Exception ex) {
        for (Class<?> excls : method.getExceptionTypes()) {
            if (excls.isInstance(ex)) {
                throw ex;
            }
        }
        if (ex instanceof Fault && ex.getCause() instanceof IOException) {
            throw new WebServiceException(ex.getMessage(), ex.getCause());
        }
        if (getBinding() instanceof HTTPBinding) {
            HTTPException exception = new HTTPException(HttpURLConnection.HTTP_INTERNAL_ERROR);
            exception.initCause(ex);
            throw exception;
        } else if (getBinding() instanceof SOAPBinding) {
            SOAPFault soapFault = createSoapFault((SOAPBinding) getBinding(), ex);
            if (soapFault == null) {
                throw new WebServiceException(ex);
            }
            SOAPFaultException exception = new SOAPFaultException(soapFault);
            if (ex instanceof Fault && ex.getCause() != null) {
                exception.initCause(ex.getCause());
            } else {
                exception.initCause(ex);
            }
            throw exception;
        } else {
            throw new WebServiceException(ex);
        }
    } finally {
        if (addressChanged(address)) {
            setupEndpointAddressContext(getClient().getEndpoint());
        }
    }
    Map<String, Object> respContext = client.getResponseContext();
    Map<String, Scope> scopes = CastUtils.cast((Map<?, ?>) respContext.get(WrappedMessageContext.SCOPES));
    if (scopes != null) {
        for (Map.Entry<String, Scope> scope : scopes.entrySet()) {
            if (scope.getValue() == Scope.HANDLER) {
                respContext.remove(scope.getKey());
            }
        }
    }
    return adjustObject(result);
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) HTTPException(javax.xml.ws.http.HTTPException) Message(org.apache.cxf.common.i18n.Message) Fault(org.apache.cxf.interceptor.Fault) SOAPFault(javax.xml.soap.SOAPFault) SoapFault(org.apache.cxf.binding.soap.SoapFault) Endpoint(org.apache.cxf.endpoint.Endpoint) MethodDispatcher(org.apache.cxf.service.invoker.MethodDispatcher) HTTPBinding(javax.xml.ws.http.HTTPBinding) WebServiceException(javax.xml.ws.WebServiceException) SOAPBinding(javax.xml.ws.soap.SOAPBinding) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) BindingProvider(javax.xml.ws.BindingProvider) Method(java.lang.reflect.Method) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HTTPException(javax.xml.ws.http.HTTPException) SOAPException(javax.xml.soap.SOAPException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebServiceException(javax.xml.ws.WebServiceException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Scope(javax.xml.ws.handler.MessageContext.Scope) SOAPFault(javax.xml.soap.SOAPFault) Map(java.util.Map)

Aggregations

IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Map (java.util.Map)1 SOAPException (javax.xml.soap.SOAPException)1 SOAPFault (javax.xml.soap.SOAPFault)1 BindingProvider (javax.xml.ws.BindingProvider)1 WebServiceException (javax.xml.ws.WebServiceException)1 Scope (javax.xml.ws.handler.MessageContext.Scope)1 HTTPBinding (javax.xml.ws.http.HTTPBinding)1 HTTPException (javax.xml.ws.http.HTTPException)1 SOAPBinding (javax.xml.ws.soap.SOAPBinding)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 SoapFault (org.apache.cxf.binding.soap.SoapFault)1 Message (org.apache.cxf.common.i18n.Message)1 Endpoint (org.apache.cxf.endpoint.Endpoint)1 Fault (org.apache.cxf.interceptor.Fault)1 MethodDispatcher (org.apache.cxf.service.invoker.MethodDispatcher)1 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)1