/**
  * Here we are getting the target invocation method. The method get set as a property in the
  * message by the {@link org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor}
  *
  * @param message incoming message
  * @return
  */
 protected Method getTargetMethod(Message message) {
   BindingOperationInfo bop = message.getExchange().get(BindingOperationInfo.class);
   if (bop != null) {
     MethodDispatcher md =
         (MethodDispatcher)
             message.getExchange().get(Service.class).get(MethodDispatcher.class.getName());
     return md.getMethod(bop);
   }
   Method method = (Method) message.get("org.apache.cxf.resource.method");
   if (method != null) {
     return method;
   }
   log.error("The requested resource is not found. Please check the resource path etc..");
   throw new AccessDeniedException("Method is not available : Unauthorized");
 }
Пример #2
0
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

    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];
    }

    BindingOperationInfo oi = dispatcher.getBindingOperation(method, endpoint);
    if (oi == null) {
      // check for method on BindingProvider and Object
      if (method.getDeclaringClass().equals(BindingProvider.class)
          || method.getDeclaringClass().equals(Object.class)) {
        try {
          return method.invoke(this, params);
        } catch (InvocationTargetException e) {
          throw e.fillInStackTrace().getCause();
        }
      }

      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.fillInStackTrace();
    } catch (Exception ex) {
      for (Class<?> excls : method.getExceptionTypes()) {
        if (excls.isInstance(ex)) {
          throw ex.fillInStackTrace();
        }
      }

      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 result;
  }