Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2014, Red Hat, Inc., and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.jboss.as.webservices.publish;
 
 import static org.jboss.as.webservices.WSMessages.MESSAGES;
 
 import java.io.File;
 import java.util.List;
 import java.util.Map;
 
 import  org.jboss.metadata.javaee.spec.ParamValueMetaData;
 import  org.jboss.metadata.web.jboss.JBossServletMetaData;
 import  org.jboss.metadata.web.jboss.JBossWebMetaData;
 import  org.jboss.metadata.web.spec.ServletMappingMetaData;
WS endpoint publisher, allows for publishing a WS endpoint on AS 7

Author(s):
alessio.soldano@jboss.com
Since:
12-Jul-2011
 
 public final class EndpointPublisherImpl implements EndpointPublisher {
 
     private final WebHost host;
     private final boolean runningInService;
     private static List<DeploymentAspectpublisherDepAspects = null;
     private static List<DeploymentAspectdepAspects = null;
 
     protected EndpointPublisherImpl(WebHost host) {
         this(hostfalse);
     }
 
     protected EndpointPublisherImpl(WebHost hostboolean runningInService) {
         this. = host;
         this. = runningInService;
     }
 
     protected EndpointPublisherImpl(boolean runningInService) {
         this(nullrunningInService);
     }
 
     @Override
     public Context publish(String contextClassLoader loaderMap<StringStringurlPatternToClassNameMapthrows Exception {
         return publish(getBaseTarget(), contextloaderurlPatternToClassNameMapnullnullnull);
     }
 
    @Override
    public Context publish(String contextClassLoader loaderMap<StringStringurlPatternToClassNameMapWebservicesMetaData metadatathrows Exception {
        return publish(getBaseTarget(), contextloaderurlPatternToClassNameMapnullmetadatanull);
    }
    @Override
    public Context publish(String contextClassLoader loaderMap<StringStringurlPatternToClassNameMap,
            WebservicesMetaData metadataJBossWebservicesMetaData jbwsMetadatathrows Exception {
        return publish(getBaseTarget(), contextloaderurlPatternToClassNameMapnullmetadatajbwsMetadata);
    }
    protected Context publish(ServiceTarget targetString contextClassLoader loader,
            Map<StringStringurlPatternToClassNameMap, JBossWebMetaData jbwmdWebservicesMetaData metadataJBossWebservicesMetaData jbwsMetadata)
            throws Exception {
        DeploymentUnit unit = doPrepare(contextloaderurlPatternToClassNameMapjbwmdmetadatajbwsMetadata);
        doDeploy(targetunit);
        return doPublish(targetunit);
    }
    private static ServiceTarget getBaseTarget() {
    }

    
Prepare the ws Deployment and return a DeploymentUnit containing it

Parameters:
context
loader
urlPatternToClassNameMap
jbwmd
metadata
jbwsMetadata
Returns:
    protected DeploymentUnit doPrepare(String contextClassLoader loader,
            Map<StringStringurlPatternToClassNameMap, JBossWebMetaData jbwmdWebservicesMetaData metadataJBossWebservicesMetaData jbwsMetadata) {
        ClassLoader origClassLoader = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
        WSEndpointDeploymentUnit unit = new WSEndpointDeploymentUnit(loadercontexturlPatternToClassNameMapjbwmdmetadatajbwsMetadata);
        try {
            WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader());
            WSDeploymentBuilder.getInstance().build(unit);
            return unit;
        } finally {
            WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(origClassLoader);
        }
    }

    
Triggers the WS deployment aspects, which process the deployment and install the endpoint services.

Parameters:
target
unit
    protected void doDeploy(ServiceTarget targetDeploymentUnit unit) {
        List<DeploymentAspectaspects = getDeploymentAspects();
        ClassLoader origClassLoader = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
        Deployment dep = null;
        try {
            WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader());
            dep = unit.getAttachment(.);
            dep.addAttachment(ServiceTarget.classtarget);
            DeploymentAspectManager dam = new DeploymentAspectManagerImpl();
            dam.setDeploymentAspects(aspects);
            dam.deploy(dep);
        } finally {
            if (dep != null) {
                dep.removeAttachment(ServiceTarget.class);
            }
            WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(origClassLoader);
        }
    }

    
Publish the webapp for the WS deployment unit

Parameters:
target
unit
Returns:
Throws:
Exception
    protected Context doPublish(ServiceTarget targetDeploymentUnit unitthrows Exception {
        Deployment deployment = unit.getAttachment(.);
        List<Endpointendpoints = deployment.getService().getEndpoints();
        //If we're running in a Service, that will already have proper dependencies set on the installed endpoint services,
        //otherwise we need to explicitly wait for the endpoint services to be started before creating the webapp.
        if (!) {
            final ServiceRegistry registry = unit.getServiceRegistry();
            for (Endpoint ep : endpoints) {
                final ServiceName serviceName = EndpointService.getServiceName(unitep.getShortName());
                registry.getRequiredService(serviceName).awaitValue();
            }
        }
        deployment.addAttachment(WebDeploymentController.classstartWebApp(unit)); //TODO simplify and use findChild later in destroy()/stopWebApp()
        return new Context(unit.getAttachment(.).getContextRoot(), endpoints);
    }
    private static WebDeploymentController startWebApp(WebHost hostDeploymentUnit unitthrows Exception {
        WebDeploymentBuilder deployment = new WebDeploymentBuilder();
        WebDeploymentController handle;
        try {
            JBossWebMetaData jbwebMD = unit.getAttachment(.);
            deployment.setContextRoot(jbwebMD.getContextRoot());
            File docBase = new File(config.getValue().getServerTempDir(), jbwebMD.getContextRoot());
            if (!docBase.exists()) {
                docBase.mkdirs();
            }
            deployment.setDocumentRoot(docBase);
            deployment.setClassLoader(unit.getAttachment(.));
            addServlets(jbwebMDdeployment);
            handle = host.addWebDeployment(deployment);
            handle.create();
        } catch (Exception e) {
            throw .createContextPhaseFailed(e);
        }
        try {
            handle.start();
        } catch (Exception e) {
            throw .startContextPhaseFailed(e);
        }
        return handle;
    }
    private static void addServlets(JBossWebMetaData jbwebMDWebDeploymentBuilder deployment) {
        for (JBossServletMetaData smd : jbwebMD.getServlets()) {
            final String sc = smd.getServletClass();
            if (sc.equals(WSFServlet.class.getName())) {
                ServletBuilder servletBuilder = new ServletBuilder();
                final String servletName = smd.getServletName();
                List<ParamValueMetaData> params = smd.getInitParam();
                List<StringurlPatterns = null;
                for (ServletMappingMetaData smmd : jbwebMD.getServletMappings()) {
                    if (smmd.getServletName().equals(servletName)) {
                        urlPatterns = smmd.getUrlPatterns();
                        servletBuilder.addUrlMappings(urlPatterns);
                        break;
                    }
                }
                WSFServlet wsfs = new WSFServlet();
                servletBuilder.setServletName(servletName);
                servletBuilder.setServlet(wsfs);
                servletBuilder.setServletClass(WSFServlet.class);
                for (ParamValueMetaData param : params) {
                    servletBuilder.addInitParam(param.getParamName(), param.getParamValue());
                }
                deployment.addServlet(servletBuilder);
            }
        }
    }
    @Override
    public void destroy(Context contextthrows Exception {
        List<Endpointeps = context.getEndpoints();
        if (eps == null || eps.isEmpty()) {
            return;
        }
        Deployment dep = eps.get(0).getService().getDeployment();
        try {
            stopWebApp(dep);
        } finally {
            undeploy(dep);
        }
    }

    
Triggers the WS deployment aspects, which process the deployment unit and stop the endpoint services.

Parameters:
context
Throws:
Exception
    protected void undeploy(DeploymentUnit unitthrows Exception {
    }
    protected void undeploy(Deployment deploymentthrows Exception {
        List<DeploymentAspectaspects = getDeploymentAspects();
        ClassLoader origClassLoader = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
        try {
            WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader());
            DeploymentAspectManager dam = new DeploymentAspectManagerImpl();
            dam.setDeploymentAspects(aspects);
            dam.undeploy(deployment);
        } finally {
            WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(origClassLoader);
        }
    }

    
Stops the webapp serving the provided ws deployment

Parameters:
deployment
Throws:
Exception
    protected void stopWebApp(Deployment deploymentthrows Exception {
        WebDeploymentController context;
        try {
            context = deployment.getAttachment(WebDeploymentController.class);
            context.stop();
        } catch (Exception e) {
            throw .stopContextPhaseFailed(e);
        }
        try {
            context.destroy();
        } catch (Exception e) {
            throw .destroyContextPhaseFailed(e);
        }
    }
    }
    private static synchronized List<DeploymentAspectgetReplacedDeploymentAspects() {
        if ( == null) {
             = new LinkedList<DeploymentAspect>();
            List<DeploymentAspectserverAspects = DeploymentAspectsProvider.getSortedDeploymentAspects();
            for (DeploymentAspect aspect : serverAspects) {
                if(aspect instanceof EndpointHandlerDeploymentAspect) {
                    .add(aspect);
                    //add another aspect to set InvocationHandlerJAXWS to each endpoint
                    ForceJAXWSInvocationHandlerDeploymentAspect handlerAspect = new ForceJAXWSInvocationHandlerDeploymentAspect();
                    .add(handlerAspect);
                } else {
                    .add(aspect);
                }
            }
        }
        return ;
    }
    private static synchronized List<DeploymentAspectgetPublisherDeploymentAspects() {
        if ( == null) {
             = new LinkedList<DeploymentAspect>();
            // copy to replace the EndpointServiceDeploymentAspect
            List<DeploymentAspectserverAspects = DeploymentAspectsProvider.getSortedDeploymentAspects();
            for (DeploymentAspect aspect : serverAspects) {
                if (aspect instanceof EndpointServiceDeploymentAspect) {
                    final EndpointServiceDeploymentAspect a = (EndpointServiceDeploymentAspectaspect;
                    EndpointServiceDeploymentAspect clone = (EndpointServiceDeploymentAspect) (a.clone());
                    clone.setStopServices(true);
                    .add(clone);
                } else if(aspect instanceof EndpointHandlerDeploymentAspect) {
                    .add(aspect);
                    //add another aspect to set InvocationHandlerJAXWS to each endpoint
                    ForceJAXWSInvocationHandlerDeploymentAspect handlerAspect = new ForceJAXWSInvocationHandlerDeploymentAspect();
                    .add(handlerAspect);
                } else {
                    .add(aspect);
                }
            }
        }
        return ;
    }
        }
        @Override
        public void start(final Deployment dep) {
            for (final Endpoint ep : dep.getService().getEndpoints()) {
                ep.setInvocationHandler(new InvocationHandlerJAXWS());
            }
        }
    }
    private static ServiceContainer currentServiceContainer() {
        if(System.getSecurityManager() == null) {
            return CurrentServiceContainer.getServiceContainer();
        }
        return AccessController.doPrivileged(.);
    }
New to GrepCode? Check out our FAQ X