Ejemplo n.º 1
0
  @Override
  public void customize(Object beanInstance) {
    if (beanInstance instanceof EndpointImpl) {
      configureEndpoint((EndpointImpl) beanInstance);
    }
    if (beanInstance instanceof ServerFactoryBean) {
      ServerFactoryBean factory = (ServerFactoryBean) beanInstance;

      if (factory.getInvoker() instanceof JBossWSInvoker) {
        ((JBossWSInvoker) factory.getInvoker()).setTargetBean(factory.getServiceBean());
      }
      List<Endpoint> depEndpoints = dep.getService().getEndpoints();
      if (depEndpoints != null) {
        final String targetBeanName = factory.getServiceBean().getClass().getName();
        for (Endpoint depEndpoint : depEndpoints) {
          if (depEndpoint.getTargetBeanClass().getName().equals(targetBeanName)) {
            depEndpoint.addAttachment(Object.class, factory.getServiceBean());
          }
        }
      }
    }
    if (beanInstance instanceof ServiceImpl) {
      ServiceImpl service = (ServiceImpl) beanInstance;
      List<Endpoint> depEndpoints = dep.getService().getEndpoints();
      if (depEndpoints != null) {
        final Collection<org.apache.cxf.endpoint.Endpoint> eps = service.getEndpoints().values();
        for (Endpoint depEp : depEndpoints) {
          for (org.apache.cxf.endpoint.Endpoint ep : eps) {
            if (ep.getService().getName().equals(depEp.getProperty(Message.WSDL_SERVICE))
                && ep.getEndpointInfo().getName().equals(depEp.getProperty(Message.WSDL_PORT))) {
              depEp.addAttachment(org.apache.cxf.endpoint.Endpoint.class, ep);
            }
          }
        }
      }
    }
    if (beanInstance instanceof HTTPTransportFactory) {
      HTTPTransportFactory factory = (HTTPTransportFactory) beanInstance;
      DestinationRegistry oldRegistry = factory.getRegistry();
      if (!(oldRegistry instanceof JBossWSDestinationRegistryImpl)) {
        factory.setRegistry(new JBossWSDestinationRegistryImpl());
      }
    }
    super.customize(beanInstance);
  }
  private void propagateAttachments(final DeploymentUnit unit, final ArchiveDeployment dep) {
    dep.addAttachment(DeploymentUnit.class, unit);
    unit.putAttachment(DEPLOYMENT_KEY, dep);

    final JBossWebMetaData webMD = getJBossWebMetaData(unit);
    dep.addAttachment(JBossWebMetaData.class, webMD);

    final WebservicesMetaData webservicesMD = getOptionalAttachment(unit, WEBSERVICES_METADATA_KEY);
    dep.addAttachment(WebservicesMetaData.class, webservicesMD);

    final JBossWebservicesMetaData jbossWebservicesMD =
        getOptionalAttachment(unit, JBOSS_WEBSERVICES_METADATA_KEY);
    dep.addAttachment(JBossWebservicesMetaData.class, jbossWebservicesMD);

    final JAXWSDeployment jaxwsDeployment = getOptionalAttachment(unit, JAXWS_ENDPOINTS_KEY);
    dep.addAttachment(JAXWSDeployment.class, jaxwsDeployment);

    final EjbJarMetaData ejbJarMD =
        getOptionalAttachment(unit, EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
    dep.addAttachment(EjbJarMetaData.class, ejbJarMD);
  }
  /**
   * Creates new Web Service deployment.
   *
   * @param unit deployment unit
   * @return archive deployment
   */
  private ArchiveDeployment newDeployment(final DeploymentUnit unit) {
    ROOT_LOGGER.creatingUnifiedWebservicesDeploymentModel(unit);
    final ResourceRoot deploymentRoot = unit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    final VirtualFile root = deploymentRoot != null ? deploymentRoot.getRoot() : null;
    final ClassLoader classLoader;
    final Module module = unit.getAttachment(Attachments.MODULE);
    if (module == null) {
      classLoader = unit.getAttachment(CLASSLOADER_KEY);
      if (classLoader == null) {
        throw MESSAGES.classLoaderResolutionFailed(unit);
      }
    } else {
      classLoader = module.getClassLoader();
    }
    final ArchiveDeployment dep = this.newDeployment(unit.getName(), classLoader);

    if (unit.getParent() != null) {
      final String parentDeploymentName = unit.getParent().getName();
      final Module parentModule = unit.getParent().getAttachment(Attachments.MODULE);
      if (parentModule == null) {
        throw MESSAGES.classLoaderResolutionFailed(deploymentRoot);
      }
      final ClassLoader parentClassLoader = parentModule.getClassLoader();

      ROOT_LOGGER.creatingUnifiedWebservicesDeploymentModel(unit.getParent());
      final ArchiveDeployment parentDep =
          this.newDeployment(parentDeploymentName, parentClassLoader);
      dep.setParent(parentDep);
    }

    if (root != null) {
      dep.setRootFile(new VirtualFileAdaptor(root));
    } else {
      dep.setRootFile(new ResourceLoaderAdapter(classLoader));
    }
    dep.setRuntimeClassLoader(classLoader);
    dep.setType(deploymentType);

    return dep;
  }
Ejemplo n.º 4
0
  protected void configureEndpoint(EndpointImpl endpoint) {
    // Configure wsdl file publisher
    if (wsdlPublisher != null) {
      endpoint.setWsdlPublisher(wsdlPublisher);
    }
    // Configure according to the specified jaxws endpoint configuration
    if (!endpoint.isPublished()) // before publishing, we set the jaxws conf
    {
      final Object implementor = endpoint.getImplementor();

      // setup our invoker for http endpoints if invoker is not configured in jbossws-cxf.xml DD
      boolean isHttpEndpoint =
          endpoint.getAddress() != null
              && endpoint
                  .getAddress()
                  .substring(0, 5)
                  .toLowerCase(Locale.ENGLISH)
                  .startsWith("http");
      if ((endpoint.getInvoker() == null) && isHttpEndpoint) {
        final AnnotationsInfo ai = dep.getAttachment(AnnotationsInfo.class);
        endpoint.setInvoker(
            new JBossWSInvoker(ai.hasAnnotatedClasses(UseAsyncMethod.class.getName())));
      }

      // ** Endpoint configuration setup **
      final String endpointClassName = implementor.getClass().getName();
      final List<Endpoint> depEndpoints = dep.getService().getEndpoints();
      for (Endpoint depEndpoint : depEndpoints) {
        if (endpointClassName.equals(depEndpoint.getTargetBeanName())) {
          org.jboss.wsf.spi.metadata.config.EndpointConfig config = depEndpoint.getEndpointConfig();
          if (config == null) {
            // the ASIL did not set the endpoint configuration, perhaps because we're processing an
            // Endpoint.publish() API started endpoint or because we're on WildFly 8.0.0.Final or
            // previous version. We compute the config here then (clearly no container injection
            // will be performed on optional handlers attached to the config)
            BasicConfigResolver bcr = new BasicConfigResolver(dep, implementor.getClass());
            config = bcr.resolveEndpointConfig();
            depEndpoint.setEndpointConfig(config);
          }
          if (config != null) {
            endpoint.setEndpointConfig(config);
          }

          // also save Service QName and Port QName in the endpoint for later matches
          depEndpoint.setProperty(Message.WSDL_PORT, endpoint.getEndpointName());
          depEndpoint.setProperty(Message.WSDL_SERVICE, endpoint.getServiceName());
        }
      }

      // JASPI
      final JASPIAuthenticationProvider jaspiProvider =
          (JASPIAuthenticationProvider)
              ServiceLoader.loadService(
                  JASPIAuthenticationProvider.class.getName(),
                  null,
                  ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader());
      if (jaspiProvider == null) {
        Loggers.DEPLOYMENT_LOGGER.cannotFindJaspiClasses();
      } else {
        if (jaspiProvider.enableServerAuthentication(endpoint, depEndpoints.get(0))) {
          endpoint.getInInterceptors().add(new AuthenticationMgrSubjectCreatingInterceptor());
        }
      }
    }
  }