org.eclipse.jetty.servlet.ServletMapping Java Examples

The following examples show how to use org.eclipse.jetty.servlet.ServletMapping. 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: HttpServer2.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Add an internal servlet in the server, with initialization parameters.
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled.
 *
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param params init parameters
 */
public void addInternalServlet(String name, String pathSpec,
                               Class<? extends HttpServlet> clazz, Map<String, String> params) {
  // Jetty doesn't like the same path spec mapping to different servlets, so
  // if there's already a mapping for this pathSpec, remove it and assume that
  // the newest one is the one we want
  final ServletHolder sh = new ServletHolder(clazz);
  sh.setName(name);
  sh.setInitParameters(params);
  final ServletMapping[] servletMappings =
      webAppContext.getServletHandler().getServletMappings();
  for (int i = 0; i < servletMappings.length; i++) {
    if (servletMappings[i].containsPathSpec(pathSpec)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Found existing {} servlet at path {}; will replace mapping with {} servlet"
            , servletMappings[i].getServletName(), pathSpec, sh.getName());
      }
      ServletMapping[] newServletMappings =
          ArrayUtil.removeFromArray(servletMappings, servletMappings[i]);
      webAppContext.getServletHandler()
          .setServletMappings(newServletMappings);
      break;
    }
  }
  webAppContext.addServlet(sh, pathSpec);
}
 
Example #2
Source File: JettyServer.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void start() throws ServerException {
    logger.info("start server, host: {}, port: {}", host, port);
    try {
        if (logger.isDebugEnabled()) {
            if (servletContextHandler.getServletHandler() != null && servletContextHandler.getServletHandler()
                                                                                          .getServletMappings() != null) {
                for (ServletMapping servletMapping : servletContextHandler.getServletHandler()
                                                                          .getServletMappings()) {
                    logger.debug("jetty servlet mappings: {} register by {}", servletMapping.getPathSpecs(), servletMapping
                        .getServletName());
                }
            }
        }

        server.start();
    } catch (Exception e) {
        throw new JettyServerException(e.getMessage(), e);
    }
}
 
Example #3
Source File: HttpServer2.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
/**
 * Add an internal servlet in the server, with initialization parameters.
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled.
 *
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param params init parameters
 */
public void addInternalServlet(String name, String pathSpec,
    Class<? extends HttpServlet> clazz, Map<String, String> params) {
  // Jetty doesn't like the same path spec mapping to different servlets, so
  // if there's already a mapping for this pathSpec, remove it and assume that
  // the newest one is the one we want
  final ServletHolder sh = new ServletHolder(clazz);
  sh.setName(name);
  sh.setInitParameters(params);
  final ServletMapping[] servletMappings =
      webAppContext.getServletHandler().getServletMappings();
  for (int i = 0; i < servletMappings.length; i++) {
    if (servletMappings[i].containsPathSpec(pathSpec)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Found existing " + servletMappings[i].getServletName() +
            " servlet at path " + pathSpec + "; will replace mapping" +
            " with " + sh.getName() + " servlet");
      }
      ServletMapping[] newServletMappings =
          ArrayUtil.removeFromArray(servletMappings, servletMappings[i]);
      webAppContext.getServletHandler()
          .setServletMappings(newServletMappings);
      break;
    }
  }
  webAppContext.addServlet(sh, pathSpec);
}
 
Example #4
Source File: WebServer.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
private Holder(@NotNull String pathSpec, @NotNull Servlet servlet) {
  path = pathSpec;
  holder = new ServletHolder(servlet);
  mapping = new ServletMapping();
  mapping.setServletName(holder.getName());
  mapping.setPathSpec(pathSpec);
}
 
Example #5
Source File: WebServer.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
private void updateServlets() {
  if (handler != null) {
    final Holder[] snapshot = servlets.toArray(new Holder[0]);
    final ServletHolder[] holders = new ServletHolder[snapshot.length];
    final ServletMapping[] mappings = new ServletMapping[snapshot.length];
    for (int i = 0; i < snapshot.length; ++i) {
      holders[i] = snapshot[i].holder;
      mappings[i] = snapshot[i].mapping;
    }
    handler.setServlets(holders);
    handler.setServletMappings(mappings);
  }
}
 
Example #6
Source File: WebMappingsRenderer.java    From dropwizard-guicey with MIT License 5 votes vote down vote up
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_INFERRED")
private void renderServlet(final ServletMapping mapping,
                           final ServletHolder holder,
                           final Multimap<String, FilterReference> servletFilters,
                           final TreeNode root) throws Exception {
    final List<String> markers = new ArrayList<>();
    boolean first = true;
    for (String path : mapping.getPathSpecs()) {
        markers.clear();
        if (first && !holder.isEnabled()) {
            markers.add("DISABLED");
        }
        // indicate multiple mappings of the same servlet
        String type = IDEM;
        String async = "";
        String stopped = "";
        String name = "";
        if (first) {
            type = RenderUtils.renderClassLine(Class.forName(holder.getClassName()), markers);
            if (holder.isStopped()) {
                stopped = STOPPED;
            }
            if (holder.isAsyncSupported()) {
                async = ASYNC;
            }
            name = mapping.getServletName();
        }
        final TreeNode servlet = root.child("servlet    %-20s %-7s %-70s %-10s    %-15s %s",
                // blank placeholder to match with filters output
                path, async, type, stopped, "", name);
        if (first) {
            for (FilterReference filter : servletFilters.get(mapping.getServletName())) {
                renderFilter(filter.getMapping(), filter.getHolder(), servlet);
            }
        }
        first = false;
    }
}
 
Example #7
Source File: WebMappingsRenderer.java    From dropwizard-guicey with MIT License 5 votes vote down vote up
private void renderContext(final MappingsConfig config,
                           final MutableServletContextHandler handler,
                           final String name,
                           final StringBuilder res) {
    final TreeNode root = new TreeNode("%s %s", name, handler.getContextPath());
    try {
        final Multimap<String, FilterReference> servletFilters = renderContextFilters(config, handler, root);

        // may be null if server not started and no servlets were registered (Guice Filter is always registered)
        if (handler.getServletHandler().getServletMappings() != null) {
            for (ServletMapping mapping : handler.getServletHandler().getServletMappings()) {
                final ServletHolder servlet = handler.getServletHandler().getServlet(mapping.getServletName());
                if (isAllowed(servlet.getClassName(), config)) {
                    renderServlet(mapping,
                            servlet,
                            servletFilters,
                            root);
                }
            }
        }
    } catch (Exception ex) {
        Throwables.throwIfUnchecked(ex);
        throw new IllegalStateException(ex);
    }
    if (root.hasChildren()) {
        res.append(NEWLINE).append(NEWLINE);
        root.render(res);
    }
}
 
Example #8
Source File: HttpServer2.java    From knox with Apache License 2.0 5 votes vote down vote up
/**
 * Add an internal servlet in the server, with initialization parameters.
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled.
 *
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param params init parameters
 */
public void addInternalServlet(String name, String pathSpec,
                               Class<? extends HttpServlet> clazz, Map<String, String> params) {
  // Jetty doesn't like the same path spec mapping to different servlets, so
  // if there's already a mapping for this pathSpec, remove it and assume that
  // the newest one is the one we want
  final ServletHolder sh = new ServletHolder(clazz);
  sh.setName(name);
  sh.setInitParameters(params);
  final ServletMapping[] servletMappings =
      webAppContext.getServletHandler().getServletMappings();
  for (ServletMapping servletMapping : servletMappings) {
    if (servletMapping.containsPathSpec(pathSpec)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Found existing " + servletMapping.getServletName() +
                      " servlet at path " + pathSpec + "; will replace mapping" +
                      " with " + sh.getName() + " servlet");
      }
      ServletMapping[] newServletMappings =
          ArrayUtil.removeFromArray(servletMappings, servletMapping);
      webAppContext.getServletHandler()
          .setServletMappings(newServletMappings);
      break;
    }
  }
  webAppContext.addServlet(sh, pathSpec);
}
 
Example #9
Source File: HttpServer2.java    From knox with Apache License 2.0 5 votes vote down vote up
/**
 * Add an internal servlet in the server, specifying whether or not to
 * protect with Kerberos authentication.
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled.
 *
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param requireAuth Require Kerberos authenticate to access servlet
 */
public void addInternalServlet(String name, String pathSpec,
                               Class<? extends HttpServlet> clazz, boolean requireAuth) {
  ServletHolder holder = new ServletHolder(clazz);
  if (name != null) {
    holder.setName(name);
  }
  // Jetty doesn't like the same path spec mapping to different servlets, so
  // if there's already a mapping for this pathSpec, remove it and assume that
  // the newest one is the one we want
  final ServletMapping[] servletMappings =
      webAppContext.getServletHandler().getServletMappings();
  for (ServletMapping servletMapping : servletMappings) {
    if (servletMapping.containsPathSpec(pathSpec)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Found existing " + servletMapping.getServletName() +
                      " servlet at path " + pathSpec + "; will replace mapping" +
                      " with " + holder.getName() + " servlet");
      }
      ServletMapping[] newServletMappings =
          ArrayUtil.removeFromArray(servletMappings, servletMapping);
      webAppContext.getServletHandler()
          .setServletMappings(newServletMappings);
      break;
    }
  }
  webAppContext.addServlet(holder, pathSpec);

  if(requireAuth && UserGroupInformation.isSecurityEnabled()) {
    LOG.info("Adding Kerberos (SPNEGO) filter to " + name);
    ServletHandler handler = webAppContext.getServletHandler();
    FilterMapping fmap = new FilterMapping();
    fmap.setPathSpec(pathSpec);
    fmap.setFilterName(SPNEGO_FILTER);
    fmap.setDispatches(FilterMapping.ALL);
    handler.addFilterMapping(fmap);
  }
}
 
Example #10
Source File: HttpServer2.java    From knox with Apache License 2.0 5 votes vote down vote up
/**
 * Add an internal servlet in the server, with initialization parameters.
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled.
 *
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param params init parameters
 */
public void addInternalServlet(String name, String pathSpec,
                               Class<? extends HttpServlet> clazz, Map<String, String> params) {
  // Jetty doesn't like the same path spec mapping to different servlets, so
  // if there's already a mapping for this pathSpec, remove it and assume that
  // the newest one is the one we want
  final ServletHolder sh = new ServletHolder(clazz);
  sh.setName(name);
  sh.setInitParameters(params);
  final ServletMapping[] servletMappings =
      webAppContext.getServletHandler().getServletMappings();
  for (ServletMapping servletMapping : servletMappings) {
    if (servletMapping.containsPathSpec(pathSpec)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Found existing " + servletMapping.getServletName() +
                      " servlet at path " + pathSpec + "; will replace mapping" +
                      " with " + sh.getName() + " servlet");
      }
      ServletMapping[] newServletMappings =
          ArrayUtil.removeFromArray(servletMappings, servletMapping);
      webAppContext.getServletHandler()
          .setServletMappings(newServletMappings);
      break;
    }
  }
  webAppContext.addServlet(sh, pathSpec);
}
 
Example #11
Source File: HttpServer2.java    From knox with Apache License 2.0 5 votes vote down vote up
/**
 * Add an internal servlet in the server, specifying whether or not to
 * protect with Kerberos authentication.
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled.
 *
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param requireAuth Require Kerberos authenticate to access servlet
 */
public void addInternalServlet(String name, String pathSpec,
                               Class<? extends HttpServlet> clazz, boolean requireAuth) {
  ServletHolder holder = new ServletHolder(clazz);
  if (name != null) {
    holder.setName(name);
  }
  // Jetty doesn't like the same path spec mapping to different servlets, so
  // if there's already a mapping for this pathSpec, remove it and assume that
  // the newest one is the one we want
  final ServletMapping[] servletMappings =
      webAppContext.getServletHandler().getServletMappings();
  for (ServletMapping servletMapping : servletMappings) {
    if (servletMapping.containsPathSpec(pathSpec)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Found existing " + servletMapping.getServletName() +
                      " servlet at path " + pathSpec + "; will replace mapping" +
                      " with " + holder.getName() + " servlet");
      }
      ServletMapping[] newServletMappings =
          ArrayUtil.removeFromArray(servletMappings, servletMapping);
      webAppContext.getServletHandler()
          .setServletMappings(newServletMappings);
      break;
    }
  }
  webAppContext.addServlet(holder, pathSpec);

  if(requireAuth && UserGroupInformation.isSecurityEnabled()) {
    LOG.info("Adding Kerberos (SPNEGO) filter to " + name);
    ServletHandler handler = webAppContext.getServletHandler();
    FilterMapping fmap = new FilterMapping();
    fmap.setPathSpec(pathSpec);
    fmap.setFilterName(SPNEGO_FILTER);
    fmap.setDispatches(FilterMapping.ALL);
    handler.addFilterMapping(fmap);
  }
}
 
Example #12
Source File: HttpServer.java    From sensorhub with Mozilla Public License 2.0 5 votes vote down vote up
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 #13
Source File: HttpServer.java    From sensorhub with Mozilla Public License 2.0 5 votes vote down vote up
public synchronized void deployServlet(HttpServlet servlet, Map<String, String> initParams, String... paths)
{
    ServletHolder holder = new ServletHolder(servlet);
    if (initParams != null)
        holder.setInitParameters(initParams);
    
    ServletMapping mapping = new ServletMapping();
    mapping.setServletName(holder.getName());
    mapping.setPathSpecs(paths);
    
    servletHandler.getServletHandler().addServlet(holder);
    servletHandler.getServletHandler().addServletMapping(mapping);
    log.debug("Servlet deployed " + mapping.toString());
}
 
Example #14
Source File: HttpConductorImpl.java    From sql-layer with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 #15
Source File: HttpServer2.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Add an internal servlet in the server, specifying whether or not to
 * protect with Kerberos authentication.
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled.
 *
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param requireAuth Require Kerberos authenticate to access servlet
 */
public void addInternalServlet(String name, String pathSpec,
                               Class<? extends HttpServlet> clazz, boolean requireAuth) {
  ServletHolder holder = new ServletHolder(clazz);
  if (name != null) {
    holder.setName(name);
  }
  // Jetty doesn't like the same path spec mapping to different servlets, so
  // if there's already a mapping for this pathSpec, remove it and assume that
  // the newest one is the one we want
  final ServletMapping[] servletMappings =
      webAppContext.getServletHandler().getServletMappings();
  for (int i = 0; i < servletMappings.length; i++) {
    if (servletMappings[i].containsPathSpec(pathSpec)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Found existing {} servlet at path {}; will replace mapping with {} servlet"
            , servletMappings[i].getServletName()
            , pathSpec
            , holder.getName());
      }
      ServletMapping[] newServletMappings =
          ArrayUtil.removeFromArray(servletMappings, servletMappings[i]);
      webAppContext.getServletHandler()
          .setServletMappings(newServletMappings);
      break;
    }
  }
  webAppContext.addServlet(holder, pathSpec);

  if(requireAuth && UserGroupInformation.isSecurityEnabled()) {
    LOG.info("Adding Kerberos (SPNEGO) filter to {}", name);
    ServletHandler handler = webAppContext.getServletHandler();
    FilterMapping fmap = new FilterMapping();
    fmap.setPathSpec(pathSpec);
    fmap.setFilterName(SPNEGO_FILTER);
    fmap.setDispatches(FilterMapping.ALL);
    handler.addFilterMapping(fmap);
  }
}
 
Example #16
Source File: AssetServlet.java    From onedev with MIT License 5 votes vote down vote up
@Override
public final Resource getResource(String pathInContext) {
	ServletContextHandler.Context context = (ServletContextHandler.Context) getServletContext();
	ServletContextHandler contextHandler = (ServletContextHandler) context.getContextHandler();
	
	for (ServletMapping mapping: contextHandler.getServletHandler().getServletMappings()) {
		if (mapping.getServletName().equals(getServletName())) {
			for (String pathSpec: mapping.getPathSpecs()) {
				String relativePath = null;
				if (pathSpec.endsWith("/*")) {
					pathSpec = StringUtils.substringBeforeLast(pathSpec, "/*");
					if (pathInContext.startsWith(pathSpec + "/")) 
						relativePath = pathInContext.substring(pathSpec.length());
				} else if (pathSpec.startsWith("*.")) {
					pathSpec = StringUtils.stripStart(pathSpec, "*");
					if (pathInContext.endsWith(pathSpec))
						relativePath = pathInContext;
				} else if (pathSpec.equals(pathInContext)) {
					relativePath = pathInContext;
				}
				if (relativePath != null) {
					relativePath = StringUtils.stripStart(relativePath, "/");
					Resource resource = Resource.newResource(loadResource(relativePath));
					if (resource != null && resource.exists())
						return resource;
				}
			}
		}
	}
	
	return null;
}
 
Example #17
Source File: HttpServer2.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
/**
 * Add an internal servlet in the server, specifying whether or not to
 * protect with Kerberos authentication.
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled.
 *
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param requireAuth Require Kerberos authenticate to access servlet
 */
public void addInternalServlet(String name, String pathSpec,
    Class<? extends HttpServlet> clazz, boolean requireAuth) {
  ServletHolder holder = new ServletHolder(clazz);
  if (name != null) {
    holder.setName(name);
  }
  // Jetty doesn't like the same path spec mapping to different servlets, so
  // if there's already a mapping for this pathSpec, remove it and assume that
  // the newest one is the one we want
  final ServletMapping[] servletMappings =
      webAppContext.getServletHandler().getServletMappings();
  for (int i = 0; i < servletMappings.length; i++) {
    if (servletMappings[i].containsPathSpec(pathSpec)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Found existing " + servletMappings[i].getServletName() +
            " servlet at path " + pathSpec + "; will replace mapping" +
            " with " + holder.getName() + " servlet");
      }
      ServletMapping[] newServletMappings =
          ArrayUtil.removeFromArray(servletMappings, servletMappings[i]);
      webAppContext.getServletHandler()
          .setServletMappings(newServletMappings);
      break;
    }
  }
  webAppContext.addServlet(holder, pathSpec);

  if (requireAuth && UserGroupInformation.isSecurityEnabled()) {
    LOG.info("Adding Kerberos (SPNEGO) filter to {}", name);
    ServletHandler handler = webAppContext.getServletHandler();
    FilterMapping fmap = new FilterMapping();
    fmap.setPathSpec(pathSpec);
    fmap.setFilterName(SPNEGO_FILTER);
    fmap.setDispatches(FilterMapping.ALL);
    handler.addFilterMapping(fmap);
  }
}
 
Example #18
Source File: JettyAppServer.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@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);
    }
}