Exemplo n.º 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();
    }
  }
Exemplo n.º 2
0
  private void loadServicesFromServicesPath(WSDDDeployment deployment, ServiceLoader loader)
      throws IOException {
    for (String name : loader.listServiceNames()) {
      if (deployment.getWSDDService(new QName(name)) != null) continue;

      ServiceFactory factory = null;
      try {
        factory = loader.loadServiceFactory(Thread.currentThread().getContextClassLoader(), name);
      } catch (RuntimeException e) {
        if (e.getClass().getName().equals("BeanCreationException")) {
          logger.log(
              Level.WARNING,
              "ignore service \"" + name + "\" because interface class not determined.",
              e);
          continue;
        }
        throw e;
      }
      Set<Class<?>> interfaceClasses = factory.getInterfaces();
      if (interfaceClasses.isEmpty()) {
        logger.warning("ignore service \"" + name + "\" because interface class not determined.");
        continue;
      }

      WSDDService s = new WSDDService();
      s.setName(name);
      s.getServiceDesc().setName(name);
      s.setProviderQName(new QName("http://xml.apache.org/axis/wsdd/providers/java", "SGRPC"));
      s.setParameter("className", interfaceClasses.iterator().next().getName());
      s.setParameter(
          "x_sg_interfaces",
          StringUtil.join(
              interfaceClasses.toArray(new Class<?>[] {}), new ClassToClassNameTransformer(), ","));
      s.setParameter("x_sg_managed", "true");
      for (Class<?> c : interfaceClasses) {
        addBeanMapping(s, c.getName());
      }
      deployment.deployService(s);
    }
  }
Exemplo n.º 3
0
  protected static Mapping getMapping(MessageContext context, String mappingProperty) {
    long startTime = System.currentTimeMillis();

    // determine the mapping location, starting with a default based on the property
    String mappingLocation =
        mappingProperty.equals(CASTOR_MARSHALLER_PROPERTY)
            ? DEFAULT_MARSHALLER_MAPPING
            : DEFAULT_UNMARSHALLER_MAPPING;
    if (context != null) {
      String prop = (String) context.getProperty(mappingProperty);
      if (prop != null && !prop.trim().equals("")) {
        // the property exists in the message context, use the property value
        mappingLocation = prop;
        LOG.debug("Loading castor mapping from message context property[" + mappingProperty + "]");
      } else {
        try {
          // attempt to find the property in the wsdd global configuration
          prop =
              (String) context.getAxisEngine().getConfig().getGlobalOptions().get(mappingProperty);
        } catch (Exception e) {
          LOG.warn("Error reading global configuration:" + e.getMessage(), e);
        }
        if (prop != null && !prop.trim().equals("")) {
          mappingLocation = prop;
          LOG.debug(
              "Loading castor mapping from globalConfiguration property[" + mappingProperty + "]");
        } else {
          // walk through the WSDD config and find the property in service config options
          EngineConfiguration config = context.getAxisEngine().getConfig();
          if (config instanceof WSDDEngineConfiguration) {
            WSDDDeployment wsdd = ((WSDDEngineConfiguration) config).getDeployment();
            WSDDService[] services = wsdd.getServices();
            for (WSDDService service : services) {
              prop = service.getParameter(mappingProperty);
              if (prop != null && !prop.trim().equals("")) {
                // found it!
                mappingLocation = prop;
                LOG.debug(
                    "Loading castor mapping from service "
                        + service.getQName()
                        + " property ["
                        + prop
                        + "]");
                break;
              }
            }
          }
          if (!(prop != null && !prop.trim().equals(""))) {
            LOG.warn(
                "Unable to locate castor mapping property["
                    + mappingProperty
                    + "], using default mapping location:"
                    + mappingLocation);
          }
        }
      }
    } else {
      LOG.debug(
          "Unable to determine message context, using default mapping location:" + mappingLocation);
    }

    // locate the bytes of the mapping file
    String mappingDocument = null;
    try {
      mappingDocument = loadResource(mappingLocation);
    } catch (IOException ex) {
      LOG.error("Error loading mapping file [" + mappingLocation + "] : " + ex.getMessage(), ex);
    }

    Mapping mapping = loadMappingFromString(mappingLocation, mappingDocument, getDtdResolver());

    long duration = System.currentTimeMillis() - startTime;
    LOG.debug("Time to load mapping file:" + duration + " ms.");

    return mapping;
  }