Search in sources :

Example 1 with ServletBuilder

use of org.jboss.as.web.host.ServletBuilder in project wildfly by wildfly.

the class EndpointPublisherImpl method addServlets.

private static void addServlets(JBossWebMetaData jbwebMD, WebDeploymentBuilder 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<String> urlPatterns = 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);
        }
    }
}
Also used : ParamValueMetaData(org.jboss.metadata.javaee.spec.ParamValueMetaData) ServletMappingMetaData(org.jboss.metadata.web.spec.ServletMappingMetaData) JBossServletMetaData(org.jboss.metadata.web.jboss.JBossServletMetaData) ServletBuilder(org.jboss.as.web.host.ServletBuilder) WSFServlet(org.jboss.wsf.spi.deployment.WSFServlet)

Example 2 with ServletBuilder

use of org.jboss.as.web.host.ServletBuilder in project wildfly by wildfly.

the class WebAppController method startWebApp.

private WebDeploymentController startWebApp(WebHost host) throws Exception {
    WebDeploymentBuilder builder = new WebDeploymentBuilder();
    WebDeploymentController deployment;
    try {
        builder.setContextRoot(contextRoot);
        File docBase = new File(serverTempDir, contextRoot);
        if (!docBase.exists()) {
            docBase.mkdirs();
        }
        builder.setDocumentRoot(docBase);
        builder.setClassLoader(classloader);
        final int j = servletClass.indexOf(".");
        final String servletName = j < 0 ? servletClass : servletClass.substring(j + 1);
        final Class<?> clazz = classloader.loadClass(servletClass);
        ServletBuilder servlet = new ServletBuilder();
        servlet.setServletName(servletName);
        servlet.setServlet((Servlet) clazz.newInstance());
        servlet.setServletClass(clazz);
        servlet.addUrlMapping(urlPattern);
        builder.addServlet(servlet);
        deployment = host.addWebDeployment(builder);
        deployment.create();
    } catch (Exception e) {
        throw WSLogger.ROOT_LOGGER.createContextPhaseFailed(e);
    }
    try {
        deployment.start();
    } catch (Exception e) {
        throw WSLogger.ROOT_LOGGER.startContextPhaseFailed(e);
    }
    return deployment;
}
Also used : ServletBuilder(org.jboss.as.web.host.ServletBuilder) WebDeploymentBuilder(org.jboss.as.web.host.WebDeploymentBuilder) WebDeploymentController(org.jboss.as.web.host.WebDeploymentController) File(java.io.File) StartException(org.jboss.msc.service.StartException)

Example 3 with ServletBuilder

use of org.jboss.as.web.host.ServletBuilder in project wildfly by wildfly.

the class WebHostService method addWebDeployment.

@Override
public WebDeploymentController addWebDeployment(final WebDeploymentBuilder webDeploymentBuilder) {
    DeploymentInfo d = new DeploymentInfo();
    d.setDeploymentName(webDeploymentBuilder.getContextRoot());
    d.setContextPath(webDeploymentBuilder.getContextRoot());
    d.setClassLoader(webDeploymentBuilder.getClassLoader());
    d.setResourceManager(new PathResourceManager(webDeploymentBuilder.getDocumentRoot().toPath().toAbsolutePath(), 1024L * 1024L));
    d.setIgnoreFlush(false);
    for (ServletBuilder servlet : webDeploymentBuilder.getServlets()) {
        ServletInfo s;
        if (servlet.getServlet() == null) {
            s = new ServletInfo(servlet.getServletName(), (Class<? extends Servlet>) servlet.getServletClass());
        } else {
            s = new ServletInfo(servlet.getServletName(), (Class<? extends Servlet>) servlet.getServletClass(), new ImmediateInstanceFactory<>(servlet.getServlet()));
        }
        if (servlet.isForceInit()) {
            s.setLoadOnStartup(1);
        }
        s.addMappings(servlet.getUrlMappings());
        for (Map.Entry<String, String> param : servlet.getInitParams().entrySet()) {
            s.addInitParam(param.getKey(), param.getValue());
        }
        d.addServlet(s);
    }
    if (controlPoint != null) {
        d.addOuterHandlerChainWrapper(GlobalRequestControllerHandler.wrapper(controlPoint, webDeploymentBuilder.getAllowRequestPredicates()));
    }
    return new WebDeploymentControllerImpl(d);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) ServletBuilder(org.jboss.as.web.host.ServletBuilder) Servlet(javax.servlet.Servlet) ImmediateInstanceFactory(io.undertow.servlet.util.ImmediateInstanceFactory) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) Map(java.util.Map) PathResourceManager(io.undertow.server.handlers.resource.PathResourceManager)

Aggregations

ServletBuilder (org.jboss.as.web.host.ServletBuilder)3 PathResourceManager (io.undertow.server.handlers.resource.PathResourceManager)1 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 ServletInfo (io.undertow.servlet.api.ServletInfo)1 ImmediateInstanceFactory (io.undertow.servlet.util.ImmediateInstanceFactory)1 File (java.io.File)1 Map (java.util.Map)1 Servlet (javax.servlet.Servlet)1 WebDeploymentBuilder (org.jboss.as.web.host.WebDeploymentBuilder)1 WebDeploymentController (org.jboss.as.web.host.WebDeploymentController)1 ParamValueMetaData (org.jboss.metadata.javaee.spec.ParamValueMetaData)1 JBossServletMetaData (org.jboss.metadata.web.jboss.JBossServletMetaData)1 ServletMappingMetaData (org.jboss.metadata.web.spec.ServletMappingMetaData)1 StartException (org.jboss.msc.service.StartException)1 WSFServlet (org.jboss.wsf.spi.deployment.WSFServlet)1