コード例 #1
0
ファイル: ResourceUtils.java プロジェクト: jboss/cxf
 private static OperationResourceInfo createOperationInfo(
     Method m, Method annotatedMethod, ClassResourceInfo cri, Path path, String httpMethod) {
   OperationResourceInfo ori = new OperationResourceInfo(m, annotatedMethod, cri);
   URITemplate t = URITemplate.createTemplate(path);
   ori.setURITemplate(t);
   ori.setHttpMethod(httpMethod);
   return ori;
 }
コード例 #2
0
ファイル: AbstractClient.java プロジェクト: Lxzw/cxf
 protected MultivaluedMap<String, String> getTemplateParametersMap(
     URITemplate template, List<Object> values) {
   if (values != null && values.size() != 0) {
     List<String> vars = template.getVariables();
     MultivaluedMap<String, String> templatesMap = new MetadataMap<String, String>(vars.size());
     for (int i = 0; i < vars.size(); i++) {
       if (i < values.size()) {
         templatesMap.add(vars.get(i), values.get(i).toString());
       }
     }
     return templatesMap;
   }
   return null;
 }
コード例 #3
0
 public List<String> getMatchedURIs(boolean decode) {
   if (stack != null) {
     List<String> objects = new ArrayList<String>();
     List<String> uris = new LinkedList<String>();
     String sum = "";
     for (MethodInvocationInfo invocation : stack) {
       OperationResourceInfo ori = invocation.getMethodInfo();
       URITemplate[] paths = {ori.getClassResourceInfo().getURITemplate(), ori.getURITemplate()};
       for (URITemplate t : paths) {
         if (t != null) {
           String v = t.getValue();
           sum += "/" + (decode ? HttpUtils.pathDecode(v) : v);
         }
       }
       UriBuilder ub = UriBuilder.fromPath(sum);
       objects.addAll(invocation.getTemplateValues());
       uris.add(0, ub.build(objects.toArray()).normalize().getPath());
     }
     return uris;
   }
   LOG.fine("No resource stack information, returning empty list");
   return Collections.emptyList();
 }
コード例 #4
0
ファイル: ResourceUtils.java プロジェクト: jboss/cxf
  public static ClassResourceInfo createClassResourceInfo(
      final Class<?> rClass,
      final Class<?> sClass,
      ClassResourceInfo parent,
      boolean root,
      boolean enableStatic,
      Bus bus) {
    ClassResourceInfo cri = new ClassResourceInfo(rClass, sClass, root, enableStatic, bus);
    cri.setParent(parent);

    if (root) {
      URITemplate t = URITemplate.createTemplate(cri.getPath());
      cri.setURITemplate(t);
    }

    evaluateResourceClass(cri, enableStatic);
    return checkMethodDispatcher(cri) ? cri : null;
  }
コード例 #5
0
ファイル: ResourceUtils.java プロジェクト: jboss/cxf
  public static ClassResourceInfo createServiceClassResourceInfo(
      Map<String, UserResource> resources,
      UserResource model,
      Class<?> sClass,
      boolean isRoot,
      boolean enableStatic,
      Bus bus) {
    if (model == null) {
      throw new RuntimeException("Resource class " + sClass.getName() + " has no model info");
    }
    ClassResourceInfo cri =
        new ClassResourceInfo(
            sClass,
            sClass,
            isRoot,
            enableStatic,
            true,
            model.getConsumes(),
            model.getProduces(),
            bus);
    URITemplate t = URITemplate.createTemplate(model.getPath());
    cri.setURITemplate(t);

    MethodDispatcher md = new MethodDispatcher();
    Map<String, UserOperation> ops = model.getOperationsAsMap();

    Method defaultMethod = null;
    Map<String, Method> methodNames = new HashMap<String, Method>();
    for (Method m : cri.getServiceClass().getMethods()) {
      if (m.getAnnotation(DefaultMethod.class) != null) {
        // if needed we can also support multiple default methods
        defaultMethod = m;
      }
      methodNames.put(m.getName(), m);
    }

    for (Map.Entry<String, UserOperation> entry : ops.entrySet()) {
      UserOperation op = entry.getValue();
      Method actualMethod = methodNames.get(op.getName());
      if (actualMethod == null) {
        actualMethod = defaultMethod;
      }
      if (actualMethod == null) {
        continue;
      }
      OperationResourceInfo ori =
          new OperationResourceInfo(
              actualMethod,
              cri,
              URITemplate.createTemplate(op.getPath()),
              op.getVerb(),
              op.getConsumes(),
              op.getProduces(),
              op.getParameters(),
              op.isOneway());
      String rClassName = actualMethod.getReturnType().getName();
      if (op.getVerb() == null) {
        if (resources.containsKey(rClassName)) {
          ClassResourceInfo subCri =
              rClassName.equals(model.getName())
                  ? cri
                  : createServiceClassResourceInfo(
                      resources,
                      resources.get(rClassName),
                      actualMethod.getReturnType(),
                      false,
                      enableStatic,
                      bus);
          if (subCri != null) {
            cri.addSubClassResourceInfo(subCri);
            md.bind(ori, actualMethod);
          }
        }
      } else {
        md.bind(ori, actualMethod);
      }
    }

    cri.setMethodDispatcher(md);
    return checkMethodDispatcher(cri) ? cri : null;
  }