Source:
<code>protected void register(Class<?> applicationClass, Set<Class<?>> providers, Set<Class<?>> resources, ServletContext servletContext) { ApplicationPath path = applicationClass.getAnnotation(ApplicationPath.class); ServletRegistration.Dynamic reg; String mapping; String prefix; if (path == null) { if (servletContext.getServletRegistration(applicationClass.getName()) == null) { return; } reg = servletContext.addServlet(applicationClass.getName(), HttpServlet30Dispatcher.class); Collection<String> mappings = reg.getMappings(); if (mappings == null || mappings.isEmpty()) { return; } <START> mapping = mappings.iterator().next(); <END> prefix = mapping; while (!prefix.equals("/") && (prefix.endsWith("/") || prefix.endsWith("*"))) { prefix = prefix.substring(0, prefix.length() - 1); } } else { mapping = path.value(); if (!mapping.startsWith("/")) mapping = "/" + mapping; prefix = mapping; if (!prefix.equals("/") && prefix.endsWith("/")) prefix = prefix.substring(0, prefix.length() - 1); if (!mapping.endsWith("/*")) { if (mapping.endsWith("/")) mapping += "*"; else mapping += "/*"; } reg = servletContext.addServlet(applicationClass.getName(), HttpServlet30Dispatcher.class); reg.setLoadOnStartup(1); reg.setAsyncSupported(true); reg.addMapping(mapping); } reg.setInitParameter("javax.ws.rs.Application", applicationClass.getName()); reg.setInitParameter("resteasy.servlet.mapping.prefix", prefix); if (resources.size() > 0) { StringBuilder builder = new StringBuilder(); boolean first = true; for (Class<?> resource : resources) { if (first) first = false; else builder.append(","); builder.append(resource.getName()); } reg.setInitParameter(ResteasyContextParameters.RESTEASY_SCANNED_RESOURCES, builder.toString()); } if (providers.size() > 0) { StringBuilder builder = new StringBuilder(); boolean first = true; for (Class<?> provider : providers) { if (first) { first = false; } else { builder.append(","); } builder.append(provider.getName()); } reg.setInitParameter(ResteasyContextParameters.RESTEASY_SCANNED_PROVIDERS, builder.toString()); } }</code><technical_language>Related question RESTEASY-2650, Application paths, want add a servlet for path? wrong track here</technical_language>

Target:
protected void register(Class<?> applicationClass, Set<Class<?>> providers, Set<Class<?>> resources, ServletContext servletContext) { Set<ServletRegistration> servletsForApp = getServletsForApplication(applicationClass, servletContext); if (!servletsForApp.isEmpty()) { for (ServletRegistration servletReg : servletsForApp) { String servletClassName = servletReg.getClassName(); if (servletClassName == null) servletContext.addServlet(servletReg.getName(), HttpServlet30Dispatcher.class); String prefix = servletReg.getMappings().iterator().next(); if (prefix.endsWith("*")) prefix = prefix.substring(0, prefix.length() - 1); if (prefix.length() > 1 && prefix.endsWith("/")) prefix = prefix.substring(0, prefix.length() - 1); registerResourcesAndProviders(servletReg, providers, resources, applicationClass, prefix); } return; } ApplicationPath path = applicationClass.getAnnotation(ApplicationPath.class); if (path == null) { return; } ServletRegistration.Dynamic reg; String mapping = path.value(); String prefix; if (!mapping.startsWith("/")) mapping = "/" + mapping; prefix = mapping; if (!prefix.equals("/") && prefix.endsWith("/")) prefix = prefix.substring(0, prefix.length() - 1); if (!mapping.endsWith("/*")) { if (mapping.endsWith("/")) mapping += "*"; else mapping += "/*"; } reg = servletContext.addServlet(applicationClass.getName(), HttpServlet30Dispatcher.class); reg.setLoadOnStartup(1); reg.setAsyncSupported(true); reg.addMapping(mapping); registerResourcesAndProviders(reg, providers, resources, applicationClass, prefix); }