Search in sources :

Example 1 with WebDeploymentBuilder

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

the class EndpointPublisherImpl method startWebApp.

private static WebDeploymentController startWebApp(WebHost host, DeploymentUnit unit) throws Exception {
    WebDeploymentBuilder deployment = new WebDeploymentBuilder();
    WebDeploymentController handle;
    try {
        JBossWebMetaData jbwebMD = unit.getAttachment(WSAttachmentKeys.JBOSSWEB_METADATA_KEY);
        deployment.setContextRoot(jbwebMD.getContextRoot());
        ServerConfigService config = (ServerConfigService) unit.getServiceRegistry().getService(WSServices.CONFIG_SERVICE).getService();
        File docBase = new File(config.getValue().getServerTempDir(), jbwebMD.getContextRoot());
        if (!docBase.exists()) {
            docBase.mkdirs();
        }
        deployment.setDocumentRoot(docBase);
        deployment.setClassLoader(unit.getAttachment(WSAttachmentKeys.CLASSLOADER_KEY));
        deployment.addAllowedRequestPredicate(new AllowWSRequestPredicate());
        addServlets(jbwebMD, deployment);
        handle = host.addWebDeployment(deployment);
        handle.create();
    } catch (Exception e) {
        throw WSLogger.ROOT_LOGGER.createContextPhaseFailed(e);
    }
    try {
        handle.start();
    } catch (Exception e) {
        throw WSLogger.ROOT_LOGGER.startContextPhaseFailed(e);
    }
    return handle;
}
Also used : JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) ServerConfigService(org.jboss.as.webservices.service.ServerConfigService) AllowWSRequestPredicate(org.jboss.as.webservices.deployers.AllowWSRequestPredicate) WebDeploymentBuilder(org.jboss.as.web.host.WebDeploymentBuilder) WebDeploymentController(org.jboss.as.web.host.WebDeploymentController) File(java.io.File)

Example 2 with WebDeploymentBuilder

use of org.jboss.as.web.host.WebDeploymentBuilder 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)

Aggregations

File (java.io.File)2 WebDeploymentBuilder (org.jboss.as.web.host.WebDeploymentBuilder)2 WebDeploymentController (org.jboss.as.web.host.WebDeploymentController)2 ServletBuilder (org.jboss.as.web.host.ServletBuilder)1 AllowWSRequestPredicate (org.jboss.as.webservices.deployers.AllowWSRequestPredicate)1 ServerConfigService (org.jboss.as.webservices.service.ServerConfigService)1 JBossWebMetaData (org.jboss.metadata.web.jboss.JBossWebMetaData)1 StartException (org.jboss.msc.service.StartException)1