コード例 #1
0
ファイル: ResourceUtils.java プロジェクト: jboss/cxf
 private static boolean checkMethodDispatcher(ClassResourceInfo cr) {
   if (cr.getMethodDispatcher().getOperationResourceInfos().isEmpty()) {
     LOG.warning(
         new org.apache.cxf.common.i18n.Message(
                 "NO_RESOURCE_OP_EXC", BUNDLE, cr.getServiceClass().getName())
             .toString());
     return false;
   }
   return true;
 }
コード例 #2
0
ファイル: ResourceUtils.java プロジェクト: jboss/cxf
  private static void getAllTypesForResource(
      ClassResourceInfo resource,
      ResourceTypes types,
      boolean jaxbOnly,
      MessageBodyWriter<?> jaxbWriter) {
    for (OperationResourceInfo ori : resource.getMethodDispatcher().getOperationResourceInfos()) {
      Method method = ori.getMethodToInvoke();
      Class<?> realReturnType = method.getReturnType();
      Class<?> cls = realReturnType;
      if (cls == Response.class) {
        cls = getActualJaxbType(cls, method, false);
      }
      Type type = method.getGenericReturnType();
      if (jaxbOnly) {
        checkJaxbType(
            resource.getServiceClass(),
            cls,
            realReturnType == Response.class ? cls : type,
            types,
            method.getAnnotations(),
            jaxbWriter);
      } else {
        types.getAllTypes().put(cls, type);
      }

      for (Parameter pm : ori.getParameters()) {
        if (pm.getType() == ParameterType.REQUEST_BODY) {
          Class<?> inType = method.getParameterTypes()[pm.getIndex()];
          Type paramType = method.getGenericParameterTypes()[pm.getIndex()];
          if (jaxbOnly) {
            checkJaxbType(
                resource.getServiceClass(),
                inType,
                paramType,
                types,
                method.getParameterAnnotations()[pm.getIndex()],
                jaxbWriter);
          } else {
            types.getAllTypes().put(inType, paramType);
          }
        }
      }
    }

    for (ClassResourceInfo sub : resource.getSubResources()) {
      if (!isRecursiveSubResource(resource, sub)) {
        getAllTypesForResource(sub, types, jaxbOnly, jaxbWriter);
      }
    }
  }
コード例 #3
0
ファイル: ClientProxyImpl.java プロジェクト: eonezhang/cxf
  /**
   * Updates the current state if Client method is invoked, otherwise does the remote invocation or
   * returns a new proxy if subresource method is invoked. Can throw an expected exception if
   * ResponseExceptionMapper is registered
   */
  public Object invoke(Object o, Method m, Object[] params) throws Throwable {

    Class<?> declaringClass = m.getDeclaringClass();
    if (Client.class == declaringClass
        || InvocationHandlerAware.class == declaringClass
        || Object.class == declaringClass) {
      return m.invoke(this, params);
    }
    resetResponse();
    OperationResourceInfo ori = cri.getMethodDispatcher().getOperationResourceInfo(m);
    if (ori == null) {
      reportInvalidResourceMethod(m, "INVALID_RESOURCE_METHOD");
    }

    MultivaluedMap<ParameterType, Parameter> types = getParametersInfo(m, params, ori);
    List<Parameter> beanParamsList = getParameters(types, ParameterType.BEAN);

    int bodyIndex = getBodyIndex(types, ori);

    List<Object> pathParams = getPathParamValues(m, params, types, beanParamsList, ori, bodyIndex);

    UriBuilder builder = getCurrentBuilder().clone();
    if (isRoot) {
      addNonEmptyPath(builder, ori.getClassResourceInfo().getURITemplate().getValue());
    }
    addNonEmptyPath(builder, ori.getURITemplate().getValue());

    handleMatrixes(m, params, types, beanParamsList, builder);
    handleQueries(m, params, types, beanParamsList, builder);

    URI uri = builder.buildFromEncoded(pathParams.toArray()).normalize();

    MultivaluedMap<String, String> headers = getHeaders();
    MultivaluedMap<String, String> paramHeaders = new MetadataMap<String, String>();
    handleHeaders(m, params, paramHeaders, beanParamsList, types);
    handleCookies(m, params, paramHeaders, beanParamsList, types);

    if (ori.isSubResourceLocator()) {
      ClassResourceInfo subCri = cri.getSubResource(m.getReturnType(), m.getReturnType());
      if (subCri == null) {
        reportInvalidResourceMethod(m, "INVALID_SUBRESOURCE");
      }

      MultivaluedMap<String, String> subHeaders = paramHeaders;
      if (inheritHeaders) {
        subHeaders.putAll(headers);
      }

      ClientState newState =
          getState()
              .newState(
                  uri, subHeaders, getTemplateParametersMap(ori.getURITemplate(), pathParams));
      ClientProxyImpl proxyImpl =
          new ClientProxyImpl(newState, proxyLoader, subCri, false, inheritHeaders);
      proxyImpl.setConfiguration(getConfiguration());
      return JAXRSClientFactory.createProxy(m.getReturnType(), proxyLoader, proxyImpl);
    }
    headers.putAll(paramHeaders);

    getState().setTemplates(getTemplateParametersMap(ori.getURITemplate(), pathParams));

    Object body = null;
    if (bodyIndex != -1) {
      body = params[bodyIndex];
      if (body == null) {
        bodyIndex = -1;
      }
    } else if (types.containsKey(ParameterType.FORM)) {
      body = handleForm(m, params, types, beanParamsList);
    } else if (types.containsKey(ParameterType.REQUEST_BODY)) {
      body = handleMultipart(types, ori, params);
    }

    setRequestHeaders(
        headers,
        ori,
        types.containsKey(ParameterType.FORM),
        body == null ? null : body.getClass(),
        m.getReturnType());

    return doChainedInvocation(uri, headers, ori, body, bodyIndex, null, null);
  }