Exemplo n.º 1
0
 private void loadHandlers(Binding binding, EndpointConfiguration config) {
   List<Handler> handlers = config.getHandlers();
   if (handlers == null) {
     return;
   }
   binding.setHandlerChain(handlers);
 }
Exemplo n.º 2
0
 /**
  * Unregisters a service endpoint.
  *
  * @param path the endpoint path
  */
 public synchronized void unregisterService(String path) {
   if (delegate == null) {
     // case where the endpoint is undeployed before it has been activated
     for (Iterator<EndpointConfiguration> it = configurations.iterator(); it.hasNext(); ) {
       EndpointConfiguration configuration = it.next();
       if (configuration.getServicePath().equals(path)) {
         it.remove();
         return;
       }
     }
     return;
   }
   ServletAdapter adapter = delegate.unregisterServletAdapter(path);
   if (adapter != null) {
     container.removeEndpoint(adapter);
   }
 }
  /**
   * Sets properties on endpoint configuration using method reflection.
   *
   * @param endpointConfiguration
   * @param parameters
   * @param context
   */
  protected void enrichEndpointConfiguration(
      EndpointConfiguration endpointConfiguration,
      Map<String, String> parameters,
      TestContext context) {
    for (Map.Entry<String, String> parameterEntry : parameters.entrySet()) {
      Field field =
          ReflectionUtils.findField(endpointConfiguration.getClass(), parameterEntry.getKey());

      if (field == null) {
        throw new CitrusRuntimeException(
            String.format(
                "Unable to find parameter field on endpoint configuration '%s'",
                parameterEntry.getKey()));
      }

      Method setter =
          ReflectionUtils.findMethod(
              endpointConfiguration.getClass(),
              "set"
                  + parameterEntry.getKey().substring(0, 1).toUpperCase()
                  + parameterEntry.getKey().substring(1),
              field.getType());

      if (setter == null) {
        throw new CitrusRuntimeException(
            String.format(
                "Unable to find parameter setter on endpoint configuration '%s'",
                "set"
                    + parameterEntry.getKey().substring(0, 1).toUpperCase()
                    + parameterEntry.getKey().substring(1)));
      }

      ReflectionUtils.invokeMethod(
          setter,
          endpointConfiguration,
          TypeConversionUtils.convertStringToType(
              parameterEntry.getValue(), field.getType(), context));
    }
  }
Exemplo n.º 4
0
  public synchronized void registerService(EndpointConfiguration configuration) {
    if (delegate == null) {
      // servlet has not be initialized, delay service registration
      configurations.add(configuration);
      return;
    }
    Class<?> seiClass = configuration.getSeiClass();
    ClassLoader classLoader = seiClass.getClassLoader();
    ClassLoader old = Thread.currentThread().getContextClassLoader();
    try {
      Thread.currentThread().setContextClassLoader(classLoader);
      URL wsdlLocation = configuration.getWsdlLocation();
      SDDocumentSource primaryWsdl = null;
      if (wsdlLocation != null) {
        // WSDL may not be defined for a Java-based endpoint, in which case it will be introspected
        // from the SEI class
        primaryWsdl = SDDocumentSource.create(wsdlLocation);
      }
      WSBinding binding = BindingImpl.create(BindingID.SOAP11_HTTP);
      Container endpointContainer = container;
      List<SDDocumentSource> metadata = null;
      URL generatedWsdl = configuration.getGeneratedWsdl();
      if (generatedWsdl != null) {
        // create a container wrapper used by Metro to resolve the WSIT configuration
        endpointContainer = new WsitConfigurationContainer(container, generatedWsdl);
        // Compile the list of imported schemas so they can be resolved using ?xsd GET requests.
        // Metro will re-write the WSDL import
        // so clients can dereference the imports when they obtain the WSDL.
        metadata = new ArrayList<>();
        List<URL> schemas = configuration.getGeneratedSchemas();
        if (schemas != null) {
          for (URL schema : schemas) {
            metadata.add(SDDocumentSource.create(schema));
          }
        }
      }
      String servicePath = configuration.getServicePath();
      Invoker invoker = configuration.getInvoker();
      QName serviceName = configuration.getServiceName();
      QName portName = configuration.getPortName();

      // Fetch the handlers
      loadHandlers(binding, configuration);

      WSEndpoint<?> wsEndpoint;
      try {
        wsEndpoint =
            WSEndpoint.create(
                seiClass,
                false,
                invoker,
                serviceName,
                portName,
                endpointContainer,
                binding,
                primaryWsdl,
                metadata,
                null,
                true);
      } catch (WebServiceException e) {
        if (e.getMessage().contains("Not a primary WSDL")) {
          // workaround for WSDLs without service declarations
          wsEndpoint =
              WSEndpoint.create(
                  seiClass,
                  false,
                  invoker,
                  serviceName,
                  portName,
                  endpointContainer,
                  binding,
                  null,
                  metadata,
                  null,
                  true);
        } else {
          throw e;
        }
      }
      wsEndpoint.setExecutor(executorService);

      ServletAdapter adapter =
          servletAdapterFactory.createAdapter(servicePath, servicePath, wsEndpoint);
      delegate.registerServletAdapter(adapter, F3Provider.class.getClassLoader());

      String mexPath = servicePath + MEX_SUFFIX;
      ServletAdapter mexAdapter =
          servletAdapterFactory.createAdapter(mexPath, mexPath, mexEndpoint);
      delegate.registerServletAdapter(mexAdapter, F3Provider.class.getClassLoader());
    } finally {
      Thread.currentThread().setContextClassLoader(old);
    }
  }