예제 #1
0
  private void addBeanMapping(
      WSDDService service, Class<?> clazz, Collection<Class<?>> mappedClasses) {
    while (clazz != null) {
      while (clazz.isArray()) {
        clazz = clazz.getComponentType();
      }
      if (!needsMapping(clazz)) return;
      if (mappedClasses.contains(clazz)) return;
      mappedClasses.add(clazz);

      for (Method m : clazz.getDeclaredMethods()) {
        if (!m.isSynthetic()
            && m.getName().startsWith("get")
            && m.getParameterTypes().length == 0
            && (m.getModifiers() & Modifier.PUBLIC) != 0) {
          addBeanMapping(service, m.getReturnType(), mappedClasses);
        }
      }

      WSDDBeanMapping m = new WSDDBeanMapping();
      m.setLanguageSpecificType(clazz);
      Package p = clazz.getPackage();
      if (p == null) {
        // arrayちゃんと処理できてる?
        // System.out.println(clazz);
      }
      String packageName = p != null ? p.getName() : "";
      String simpleName = clazz.getSimpleName();
      boolean qnameSet = false;
      for (Pair<String, String> n : namespaceMappings) {
        if (packageName.startsWith(n.getFirst())) {
          String rest = packageName.substring(n.getFirst().length()).replace('.', '/');
          String nsPrefix = n.getSecond();
          if (rest.length() > 0) {
            rest = rest + "/";
            if (nsPrefix.endsWith("/") && rest.charAt(0) == '/') {
              rest = rest.substring(1);
            }
          }
          m.setQName(new QName(n.getSecond() + rest, simpleName));
          qnameSet = true;
          break;
        }
      }
      if (!qnameSet) {
        m.setQName(new QName("uri:" + packageName + "/", simpleName));
      }
      m.setSerializer(WSDDConstants.BEAN_SERIALIZER_FACTORY);
      m.setDeserializer(WSDDConstants.BEAN_DESERIALIZER_FACTORY);
      service.addTypeMapping(m);

      clazz = clazz.getSuperclass();
    }
  }
  @Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    Map<String, Object> httpHeaders = new Hashtable<String, Object>();
    List<RpcHeader> headers = new ArrayList<RpcHeader>();
    Pair<Endpoint, Long> r = preprocess(httpHeaders, headers);

    Endpoint endpoint = r.getFirst();
    long iid = r.getSecond();

    URL url = endpoint.getAddress().toURL();
    String key =
        url.getProtocol()
            + "://"
            + url.getAuthority()
            + url.getPath()
            + "##"
            + method.getName()
            + "("
            + JSON.encode(args)
            + ")";
    long s = System.currentTimeMillis();
    Object ret = cache.getIfPresent(key);
    if (ret != null) {
      postprocess(
          iid, System.currentTimeMillis() - s, new MimeHeaders(), new ArrayList<RpcHeader>(), null);
      return ret;
    } else {
      Object client = clientFactory.create(interfaceClass, endpoint.getAddress().toURL());
      RequestAttributes reqAttrs = (RequestAttributes) client;
      reqAttrs.setUserId(endpoint.getUserName());
      reqAttrs.setPassword(endpoint.getPassword());
      reqAttrs.addRequestMimeHeaders(httpHeaders);
      for (RpcHeader h : headers) {
        reqAttrs.addRequestRpcHeader(h.getNamespace(), h.getName(), h.getValue());
      }
      try {
        Object result = method.invoke(client, args);
        cache.put(key, result);
        return result;
      } finally {
        ResponseAttributes resAttrs = (ResponseAttributes) client;
        postprocess(
            iid,
            System.currentTimeMillis() - s,
            MimeHeadersUtil.fromStringObjectMap(resAttrs.getResponseMimeHeaders()),
            resAttrs.getResponseRpcHeaders(),
            resAttrs.getResponseRpcFault());
      }
    }
  }
예제 #3
0
 private void initNamespaceMappings(String mappings) {
   for (String m : mappings.split("\\n")) {
     String[] values = m.trim().split(", *");
     if (values.length < 2 || values[0].length() == 0) continue;
     namespaceMappings.add(Pair.create(values[0], values[1]));
   }
 }