Java Code Examples for org.eclipse.jetty.servlet.ServletHandler#getServlets()
The following examples show how to use
org.eclipse.jetty.servlet.ServletHandler#getServlets() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpConductorImpl.java From sql-layer with GNU Affero General Public License v3.0 | 5 votes |
@Override public void unregisterHandler(ServletHolder servlet) { synchronized(lock) { ServletHandler servletHandler = rootContextHandler.getServletHandler(); ServletHolder[] curServlets = servletHandler.getServlets(); List<ServletHolder> newServlets = new ArrayList<>(); newServlets.addAll(Arrays.asList(curServlets)); if(!newServlets.remove(servlet)) { throw new IllegalArgumentException("Servlet not registered"); } List<ServletMapping> newMappings = new ArrayList<>(); newMappings.addAll(Arrays.asList(servletHandler.getServletMappings())); for(Iterator<ServletMapping> it = newMappings.iterator(); it.hasNext(); ) { ServletMapping m = it.next(); if(servlet.getName().equals(m.getServletName())) { for(String path : m.getPathSpecs()) { registeredPaths.remove(path); } it.remove(); break; } } servletHandler.setServlets(newServlets.toArray(new ServletHolder[newServlets.size()])); servletHandler.setServletMappings(newMappings.toArray(new ServletMapping[newMappings.size()])); if(!servlet.isStopped()) { try { servlet.stop(); } catch(Exception e) { throw new HttpConductorException(e); } } } }
Example 2
Source File: HttpServer.java From sensorhub with Mozilla Public License 2.0 | 5 votes |
public synchronized void undeployServlet(HttpServlet servlet) { try { // there is no removeServlet method so we need to do it manually ServletHandler handler = servletHandler.getServletHandler(); // first collect servlets we want to keep List<ServletHolder> servlets = new ArrayList<ServletHolder>(); String nameToRemove = null; for( ServletHolder holder : handler.getServlets() ) { if (holder.getServlet() != servlet) servlets.add(holder); else nameToRemove = holder.getName(); } if (nameToRemove == null) return; // also update servlet path mappings List<ServletMapping> mappings = new ArrayList<ServletMapping>(); for (ServletMapping mapping : handler.getServletMappings()) { if (!nameToRemove.contains(mapping.getServletName())) mappings.add(mapping); } // set the new configuration handler.setServletMappings( mappings.toArray(new ServletMapping[0]) ); handler.setServlets( servlets.toArray(new ServletHolder[0]) ); } catch (ServletException e) { log.error("Error while undeploying servlet", e); } }
Example 3
Source File: JettyAppServer.java From keycloak with Apache License 2.0 | 4 votes |
@Override public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException { log.info("Deploying archive " + archive.getName()); if (!(archive instanceof WebArchive)) { throw new IllegalArgumentException("JettyContainer only supports WebArchives."); } WebArchive webArchive = (WebArchive) archive; try { KeycloakAdapterApp app = appProvider.createApp(webArchive); WebAppContext webAppContext = (WebAppContext) app.getContextHandler(); addAdditionalConfigurations(webAppContext); setContextRoot(webArchive, app, webAppContext); if (app.usesOIDCAuthenticator()) { addOIDCAuthenticator(webAppContext); } if (app.usesSAMLAuthenticator()) { addSAMLAuthenticator(webAppContext); } if (app.usesJaxrs()) { addRestEasyServlet(webArchive, webAppContext); } setEmbeddedClassloaderForDeployment(webAppContext); deployer.addApp(app); deployer.requestAppGoal(app, AppLifeCycle.STARTED); deployedApps.put(archive.getId(), app); HTTPContext httpContext = new HTTPContext(configuration.getBindAddress(), configuration.getBindHttpPort()); ServletHandler servletHandler = webAppContext.getServletHandler(); for (ServletHolder servlet : servletHandler.getServlets()) { log.debugf("Servlet context mapping: %s => %s", servlet.getName(), servlet.getContextPath()); httpContext.add(new Servlet(servlet.getName(), servlet.getContextPath())); } if (log.isInfoEnabled()) { for (ServletMapping mapping : server.getChildHandlerByClass(ServletHandler.class).getServletMappings()) { log.debugf("Servlet mapping: %s => %s", mapping.getServletName(), Arrays.toString(mapping.getPathSpecs())); } } return new ProtocolMetaData().addContext(httpContext); } catch (Exception e) { throw new DeploymentException("Unable to deploy archive", e); } }