use of io.undertow.servlet.handlers.ServletHandler in project undertow by undertow-io.
the class ServletContextImpl method addServlet.
@Override
public ServletRegistration.Dynamic addServlet(final String servletName, final String className) {
ensureNotProgramaticListener();
ensureNotInitialized();
try {
if (deploymentInfo.getServlets().containsKey(servletName)) {
return null;
}
Class<? extends Servlet> servletClass = (Class<? extends Servlet>) deploymentInfo.getClassLoader().loadClass(className);
ServletInfo servlet = new ServletInfo(servletName, servletClass, deploymentInfo.getClassIntrospecter().createInstanceFactory(servletClass));
readServletAnnotations(servlet);
deploymentInfo.addServlet(servlet);
ServletHandler handler = deployment.getServlets().addServlet(servlet);
return new ServletRegistrationImpl(servlet, handler.getManagedServlet(), deployment);
} catch (ClassNotFoundException e) {
throw UndertowServletMessages.MESSAGES.cannotLoadClass(className, e);
} catch (NoSuchMethodException e) {
throw UndertowServletMessages.MESSAGES.couldNotCreateFactory(className, e);
}
}
use of io.undertow.servlet.handlers.ServletHandler in project undertow by undertow-io.
the class ManagedServlets method addServlet.
public ServletHandler addServlet(final ServletInfo servletInfo) {
ManagedServlet managedServlet = new ManagedServlet(servletInfo, deployment.getServletContext());
ServletHandler servletHandler = new ServletHandler(managedServlet);
managedServletMap.put(servletInfo.getName(), servletHandler);
deployment.addLifecycleObjects(managedServlet);
this.servletPaths.invalidate();
return servletHandler;
}
use of io.undertow.servlet.handlers.ServletHandler in project undertow by undertow-io.
the class DeploymentManagerImpl method start.
@Override
public HttpHandler start() throws ServletException {
try {
return deployment.createThreadSetupAction(new ThreadSetupHandler.Action<HttpHandler, Object>() {
@Override
public HttpHandler call(HttpServerExchange exchange, Object ignore) throws ServletException {
deployment.getSessionManager().start();
//we need to copy before iterating
//because listeners can add other listeners
ArrayList<Lifecycle> lifecycles = new ArrayList<>(deployment.getLifecycleObjects());
for (Lifecycle object : lifecycles) {
object.start();
}
HttpHandler root = deployment.getHandler();
final TreeMap<Integer, List<ManagedServlet>> loadOnStartup = new TreeMap<>();
for (Map.Entry<String, ServletHandler> entry : deployment.getServlets().getServletHandlers().entrySet()) {
ManagedServlet servlet = entry.getValue().getManagedServlet();
Integer loadOnStartupNumber = servlet.getServletInfo().getLoadOnStartup();
if (loadOnStartupNumber != null) {
if (loadOnStartupNumber < 0) {
continue;
}
List<ManagedServlet> list = loadOnStartup.get(loadOnStartupNumber);
if (list == null) {
loadOnStartup.put(loadOnStartupNumber, list = new ArrayList<>());
}
list.add(servlet);
}
}
for (Map.Entry<Integer, List<ManagedServlet>> load : loadOnStartup.entrySet()) {
for (ManagedServlet servlet : load.getValue()) {
servlet.createServlet();
}
}
if (deployment.getDeploymentInfo().isEagerFilterInit()) {
for (ManagedFilter filter : deployment.getFilters().getFilters().values()) {
filter.createFilter();
}
}
state = State.STARTED;
return root;
}
}).call(null, null);
} catch (ServletException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of io.undertow.servlet.handlers.ServletHandler in project undertow by undertow-io.
the class ServletContextImpl method addServlet.
@Override
public ServletRegistration.Dynamic addServlet(final String servletName, final Servlet servlet) {
ensureNotProgramaticListener();
ensureNotInitialized();
if (deploymentInfo.getServlets().containsKey(servletName)) {
return null;
}
ServletInfo s = new ServletInfo(servletName, servlet.getClass(), new ImmediateInstanceFactory<>(servlet));
readServletAnnotations(s);
deploymentInfo.addServlet(s);
ServletHandler handler = deployment.getServlets().addServlet(s);
return new ServletRegistrationImpl(s, handler.getManagedServlet(), deployment);
}
use of io.undertow.servlet.handlers.ServletHandler in project undertow by undertow-io.
the class ServletContextImpl method addServlet.
@Override
public ServletRegistration.Dynamic addServlet(final String servletName, final Class<? extends Servlet> servletClass) {
ensureNotProgramaticListener();
ensureNotInitialized();
if (deploymentInfo.getServlets().containsKey(servletName)) {
return null;
}
try {
ServletInfo servlet = new ServletInfo(servletName, servletClass, deploymentInfo.getClassIntrospecter().createInstanceFactory(servletClass));
readServletAnnotations(servlet);
deploymentInfo.addServlet(servlet);
ServletHandler handler = deployment.getServlets().addServlet(servlet);
return new ServletRegistrationImpl(servlet, handler.getManagedServlet(), deployment);
} catch (NoSuchMethodException e) {
throw UndertowServletMessages.MESSAGES.couldNotCreateFactory(servletClass.getName(), e);
}
}
Aggregations