private void initializeServlet(Context context, String name) { Container child = context.findChild(name); if (child instanceof StandardWrapper) { try { StandardWrapper wrapper = (StandardWrapper) child; wrapper.deallocate(wrapper.allocate()); } catch (ServletException ex) { // Continue } } }
/** * Gets the application servlet. * * @param context the context * @param servletName the servlet name * @return the application servlet */ public static ServletInfo getApplicationServlet(Context context, String servletName) { Container container = context.findChild(servletName); if (container instanceof Wrapper) { Wrapper wrapper = (Wrapper) container; return getServletInfo(wrapper, context.getName()); } return null; }
@Override protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { String jspName = ServletRequestUtils.getStringParameter(request, "source", null); ServletContext sctx = context.getServletContext(); ServletConfig scfg = (ServletConfig) context.findChild("jsp"); Options opt = new EmbeddedServletOptions(scfg, sctx); String encoding = opt.getJavaEncoding(); String content = null; if (jspName != null) { String servletName = getContainerWrapper().getTomcatContainer().getServletFileNameForJsp(context, jspName); if (servletName != null) { File servletFile = new File(servletName); if (servletFile.exists()) { try (InputStream fis = Files.newInputStream(servletFile.toPath())) { content = Utils.highlightStream(jspName, fis, "java", encoding); } } } } return new ModelAndView(getViewName(), "content", content); }
@Override public String getServletFileNameForJsp(Context context, String jspName) { String servletName = null; ServletConfig servletConfig = (ServletConfig) context.findChild("jsp"); if (servletConfig != null) { ServletContext sctx = context.getServletContext(); Options opt = new EmbeddedServletOptions(servletConfig, sctx); JspRuntimeContext jrctx = new JspRuntimeContext(sctx, opt); JspCompilationContext jcctx = createJspCompilationContext(jspName, opt, sctx, jrctx, null); servletName = jcctx.getServletJavaFileName(); } else { logger.error(NO_JSP_SERVLET, context.getName()); } return servletName; }
@Override public void listContextJsps(Context context, Summary summary, boolean compile) { ServletConfig servletConfig = (ServletConfig) context.findChild("jsp"); if (servletConfig != null) { synchronized (servletConfig) {
ServletConfig scfg = (ServletConfig) context.findChild("jsp"); Options opt = new EmbeddedServletOptions(scfg, sctx); String descriptorPageEncoding =
@Override public void recompileJsps(Context context, Summary summary, List<String> names) { ServletConfig servletConfig = (ServletConfig) context.findChild("jsp"); if (servletConfig != null) { if (summary != null) {
/** * Gets the application servlet maps. * * @param context the context * @return the application servlet maps */ public static List<ServletMapping> getApplicationServletMaps(Context context) { String[] sms = context.findServletMappings(); List<ServletMapping> servletMaps = new ArrayList<>(sms.length); for (String servletMapping : sms) { if (servletMapping != null) { String sn = context.findServletMapping(servletMapping); if (sn != null) { ServletMapping sm = new ServletMapping(); sm.setApplicationName(context.getName().length() > 0 ? context.getName() : "/"); sm.setUrl(servletMapping); sm.setServletName(sn); Container container = context.findChild(sn); if (container instanceof Wrapper) { Wrapper wrapper = (Wrapper) container; sm.setServletClass(wrapper.getServletClass()); sm.setAvailable(!wrapper.isUnavailable()); } servletMaps.add(sm); } } } return servletMaps; }
@Bean public EmbeddedServletContainerCustomizer customizer() { return new EmbeddedServletContainerCustomizer() { @Override public void customize(ConfigurableEmbeddedServletContainer container) { if (container instanceof TomcatEmbeddedServletContainerFactory) { customizeTomcat((TomcatEmbeddedServletContainerFactory) container); } } private void customizeTomcat( TomcatEmbeddedServletContainerFactory tomcat) { tomcat.addContextCustomizers(new TomcatContextCustomizer() { @Override public void customize(Context context) { Wrapper jsp = (Wrapper) context.findChild("jsp"); jsp.addInitParameter("development", development); } }); } }; }
private void addAddedJAXWsServices() { final WebAppInfo webAppInfo = info.get(); final AppInfo appInfo = info.app(); if (webAppInfo == null || appInfo == null || "false".equalsIgnoreCase(appInfo.properties.getProperty("openejb.jaxws.add-missing-servlets", "true"))) { return; } try { // if no jaxws classes are here don't try anything OpenEJBContextConfig.class.getClassLoader().loadClass("org.apache.openejb.server.webservices.WsServlet"); } catch (final ClassNotFoundException | NoClassDefFoundError e) { return; } for (final ServletInfo servlet : webAppInfo.servlets) { if (!servlet.mappings.iterator().hasNext()) { // no need to do anything continue; } for (final ParamValueInfo pv : servlet.initParams) { if ("openejb-internal".equals(pv.name) && "true".equals(pv.value)) { if (context.findChild(servlet.servletName) == null) { final Wrapper wrapper = context.createWrapper(); wrapper.setName(servlet.servletName); wrapper.setServletClass("org.apache.openejb.server.webservices.WsServlet"); // add servlet to context context.addChild(wrapper); context.addServletMappingDecoded(servlet.mappings.iterator().next(), wrapper.getName()); } break; } } } }
@Override public Set<String> addMapping(String... urlPatterns) { if (urlPatterns == null) { return Collections.emptySet(); } Set<String> conflicts = new HashSet<>(); for (String urlPattern : urlPatterns) { String wrapperName = context.findServletMapping(urlPattern); if (wrapperName != null) { Wrapper wrapper = (Wrapper) context.findChild(wrapperName); if (wrapper.isOverridable()) { // Some Wrappers (from global and host web.xml) may be // overridden rather than generating a conflict context.removeServletMapping(urlPattern); } else { conflicts.add(urlPattern); } } } if (!conflicts.isEmpty()) { return conflicts; } for (String urlPattern : urlPatterns) { context.addServletMapping(urlPattern, wrapper.getName()); } return Collections.emptySet(); }
private void convertJsps(WebXml webXml) { Map<String,String> jspInitParams; ServletDef jspServlet = webXml.getServlets().get("jsp"); if (jspServlet == null) { jspInitParams = new HashMap<String,String>(); Wrapper w = (Wrapper) context.findChild("jsp"); if (w != null) { String[] params = w.findInitParameters(); for (String param : params) { jspInitParams.put(param, w.findInitParameter(param)); } } } else { jspInitParams = jspServlet.getParameterMap(); } for (ServletDef servletDef: webXml.getServlets().values()) { if (servletDef.getJspFile() != null) { convertJsp(servletDef, jspInitParams); } } }
private void convertJsps(WebXml webXml) { Map<String,String> jspInitParams; ServletDef jspServlet = webXml.getServlets().get("jsp"); if (jspServlet == null) { jspInitParams = new HashMap<>(); Wrapper w = (Wrapper) context.findChild("jsp"); if (w != null) { String[] params = w.findInitParameters(); for (String param : params) { jspInitParams.put(param, w.findInitParameter(param)); } } } else { jspInitParams = jspServlet.getParameterMap(); } for (ServletDef servletDef: webXml.getServlets().values()) { if (servletDef.getJspFile() != null) { convertJsp(servletDef, jspInitParams); } } }
private void convertJsps(WebXml webXml) { Map<String,String> jspInitParams; ServletDef jspServlet = webXml.getServlets().get("jsp"); if (jspServlet == null) { jspInitParams = new HashMap<String,String>(); Wrapper w = (Wrapper) context.findChild("jsp"); if (w != null) { String[] params = w.findInitParameters(); for (String param : params) { jspInitParams.put(param, w.findInitParameter(param)); } } } else { jspInitParams = jspServlet.getParameterMap(); } for (ServletDef servletDef: webXml.getServlets().values()) { if (servletDef.getJspFile() != null) { convertJsp(servletDef, jspInitParams); } } }
private void convertJsps(WebXml webXml) { Map<String,String> jspInitParams; ServletDef jspServlet = webXml.getServlets().get("jsp"); if (jspServlet == null) { jspInitParams = new HashMap<>(); Wrapper w = (Wrapper) context.findChild("jsp"); if (w != null) { String[] params = w.findInitParameters(); for (String param : params) { jspInitParams.put(param, w.findInitParameter(param)); } } } else { jspInitParams = jspServlet.getParameterMap(); } for (ServletDef servletDef: webXml.getServlets().values()) { if (servletDef.getJspFile() != null) { convertJsp(servletDef, jspInitParams); } } }
private void convertJsps(WebXml webXml) { Map<String,String> jspInitParams; ServletDef jspServlet = webXml.getServlets().get("jsp"); if (jspServlet == null) { jspInitParams = new HashMap<>(); Wrapper w = (Wrapper) context.findChild("jsp"); if (w != null) { String[] params = w.findInitParameters(); for (String param : params) { jspInitParams.put(param, w.findInitParameter(param)); } } } else { jspInitParams = jspServlet.getParameterMap(); } for (ServletDef servletDef: webXml.getServlets().values()) { if (servletDef.getJspFile() != null) { convertJsp(servletDef, jspInitParams); } } }
public List<String> setWsContainer(String virtualHost, String contextRoot, String servletName, HttpListener wsContainer) throws Exception { if (virtualHost == null) virtualHost = engine.getDefaultHost(); Container host = engine.findChild(virtualHost); if (host == null) { throw new IllegalArgumentException("Invalid virtual host '" + virtualHost + "'. Do you have a matchiing Host entry in the server.xml?"); } Context context = (Context) host.findChild("/" + contextRoot); if (context == null) { throw new IllegalArgumentException("Could not find web application context " + contextRoot + " in host " + host.getName()); } Wrapper wrapper = (Wrapper) context.findChild(servletName); if (wrapper == null) { throw new IllegalArgumentException("Could not find servlet " + contextRoot + " in web application context " + context.getName()); } setWsContainer(context, wrapper, wsContainer); // add service locations List<String> addresses = new ArrayList<String>(); for (Connector connector : connectors) { for (String mapping : wrapper.findMappings()) { URI address = new URI(connector.getScheme(), null, host.getName(), connector.getPort(), "/" + contextRoot + mapping, null, null); addresses.add(address.toString()); } } return addresses; }
public void clearWsContainer(String virtualHost, String contextRoot, String servletName) { if (virtualHost == null) virtualHost = engine.getDefaultHost(); Container host = engine.findChild(virtualHost); if (host == null) { throw new IllegalArgumentException("Invalid virtual host '" + virtualHost + "'. Do you have a matchiing Host entry in the server.xml?"); } Context context = (Context) host.findChild("/" + contextRoot); if (context == null) { throw new IllegalArgumentException("Could not find web application context " + contextRoot + " in host " + host.getName()); } Wrapper wrapper = (Wrapper) context.findChild(servletName); if (wrapper == null) { throw new IllegalArgumentException("Could not find servlet " + contextRoot + " in web application context " + context.getName()); } // clear the webservice ref in the servlet context String webServicecontainerId = wrapper.findInitParameter(WsServlet.WEBSERVICE_CONTAINER); if (webServicecontainerId != null) { context.getServletContext().removeAttribute(webServicecontainerId); wrapper.removeInitParameter(WsServlet.WEBSERVICE_CONTAINER); } }
public void clearWsContainer(String virtualHost, String contextRoot, String servletName) { if (virtualHost == null) virtualHost = engine.getDefaultHost(); Container host = engine.findChild(virtualHost); if (host == null) { throw new IllegalArgumentException("Invalid virtual host '" + virtualHost + "'. Do you have a matchiing Host entry in the server.xml?"); } Context context = (Context) host.findChild("/" + contextRoot); if (context == null) { throw new IllegalArgumentException("Could not find web application context " + contextRoot + " in host " + host.getName()); } Wrapper wrapper = (Wrapper) context.findChild(servletName); if (wrapper == null) { throw new IllegalArgumentException("Could not find servlet " + servletName + " in web application context " + context.getName()); } // clear the webservice ref in the servlet context String webServicecontainerId = wrapper.findInitParameter(WsServlet.WEBSERVICE_CONTAINER); if (webServicecontainerId != null) { context.getServletContext().removeAttribute(webServicecontainerId); wrapper.removeInitParameter(WsServlet.WEBSERVICE_CONTAINER); } }
@Override public void addServlet(ServletDescriptor descriptor) { String name = descriptor.getName(); Context context = getContextForPath(descriptor.getContext()); // remove existing servlet, to allow overrides (usually to change init params) Container previous = context.findChild(name); if (previous != null) { context.removeChild(previous); } Wrapper servlet = Tomcat.addServlet(context, name, descriptor.getClazz().getName()); Map<String, String> initParams = descriptor.getInitParams(); if (initParams != null) { for (Entry<String, String> es : initParams.entrySet()) { servlet.addInitParameter(es.getKey(), es.getValue()); } } for (String urlPattern : descriptor.getUrlPatterns()) { context.addServletMappingDecoded(urlPattern, name); } }