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);
}
Aggregations