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);
}
}
}
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;
}
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);
}
Aggregations