try { filter = filterConfig.getFilter(); filter.doFilter(request, response, this); } catch (IOException e) { throw e; throw e; } catch (Throwable e) { throw new ServletException("Throwable", e); servlet.service(request, response); } else { RequestDispatcher rd = configImpl.getServletContext().getNamedDispatcher("default"); if (rd == null) { throw new ServletException("No Servlet Found"); throw e; } catch (Throwable e) { throw new ServletException("Throwable", e);
@Override public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException { if (bean instanceof Servlet) { ((Servlet) bean).destroy(); } }
@Override public void dispatch(final ServletContext context, final String path) { final ServletRequest servletRequest = getRequest(); if (!HttpServletRequest.class.isInstance(servletRequest)) { throw new IllegalStateException("Not a http request: " + servletRequest); } final HttpServletRequest request = HttpServletRequest.class.cast(servletRequest); if (request.getAttribute(ASYNC_REQUEST_URI) == null) { request.setAttribute(ASYNC_REQUEST_URI, request.getRequestURI()); request.setAttribute(ASYNC_CONTEXT_PATH, request.getContextPath()); request.setAttribute(ASYNC_SERVLET_PATH, request.getServletPath()); request.setAttribute(ASYNC_PATH_INFO, request.getPathInfo()); request.setAttribute(ASYNC_QUERY_STRING, request.getQueryString()); } try { servlet.getInstance().service(request, response); } catch (final ServletException | IOException ioe) { onError(ioe); } }
public void forward(String relativePath) throws ServletException, IOException { ServletContext context = servlet.getServletConfig().getServletContext(); String baseURI; String requestURI = request.getRequestURI(); if(relativePath.startsWith("/")){ baseURI = requestURI.substring(0, request.getContextPath().length()); }else{ baseURI = requestURI.substring(0, requestURI.lastIndexOf("/")); } context.getRequestDispatcher(baseURI+relativePath).forward(request, response); }
public void init(final ServletConfig servletConfig) throws ServletException { final String targetBean = servletConfig.getInitParameter("targetBean"); final ApplicationContext ctx = getContext(servletConfig.getServletContext()); if (targetBean == null || !ctx.containsBean(targetBean)) { throw new ServletException("targetBean '" + targetBean + "' not found in context."); } this.delegate = (Servlet) ctx.getBean(targetBean, Servlet.class); this.delegate.init(servletConfig); }
public Object getAttribute(String key, Object value, int scope){ switch (scope) { case HttpScriptContext.ENGINE_SCOPE: return request.getAttribute(key); case HttpScriptContext.SESSION_SCOPE: if (useSession()) { return request.getSession().getAttribute(key); } else { return null; } case HttpScriptContext.APPLICATION_SCOPE: return servlet.getServletConfig().getServletContext().getAttribute(key); default: return null; } }
public HttpSession getSession() { HttpSession session = request.getSession(); if (session != null) { return dispatchTargets.peek().getContextController().getSessionAdaptor( session, dispatchTargets.peek().getServletRegistration().getT().getServletConfig().getServletContext()); } return null; }
public void init(ServletConfig config) throws ServletException { synchronized(this) { if(_stack.size()==0) { try { Servlet s = newInstance(); s.init(config); _stack.push(s); } catch (ServletException e) { throw e; } catch (Exception e) { throw new ServletException(e); } } } }
private void serviceViaPlugin(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { // requestPath is the full path minus the JAX-RS prefix (/plugins) final String requestPath = req.getServletPath() + req.getPathInfo(); final Servlet pluginServlet = getPluginServlet(requestPath); if (pluginServlet != null) { initializeServletIfNeeded(req, pluginServlet); final OSGIServletRequestWrapper requestWrapper = new OSGIServletRequestWrapper(req, servletRouter.getPluginPrefixForPath(requestPath)); pluginServlet.service(requestWrapper, resp); } else { resp.sendError(404); } }
public void init(ServletConfig config) throws ServletException { next.init(config); try { managedService.init(new InstanceContext(config.getServletContext())); } catch (ServiceException e) { throw new ServletException("Unable to initialize ServiceEndpoint", e); } }
public void init(ServletConfig sc) throws ServletException { if(delegate == null) throw new ServletException("Invalid Servlet Delegate"); delegate.init(sc); }
@Override protected void doPortalInit() throws Exception { ServletContext servletContext = servletConfig.getServletContext(); ClassLoader classLoader = (ClassLoader)servletContext.getAttribute( PluginContextListener.PLUGIN_CLASS_LOADER); String servletClass = servletConfig.getInitParameter("servlet-class"); servlet = (Servlet)InstanceFactory.newInstance( classLoader, servletClass); servlet.init(servletConfig); }
@Override protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { req.setAttribute(ADMIN_PROPERTY, true); restServlet.service(req, resp); } }
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String pathInfo = request.getPathInfo(); if (pathInfo != null && pathInfo.startsWith("/WEB-INF/")) { //$NON-NLS-1$ response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } ClassLoader original = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(jspLoader); jspServlet.service(request, response); } finally { Thread.currentThread().setContextClassLoader(original); } }
/** * Create a ServletContextConfiguration using the context of * the specified servlet. * * @param servlet the servlet */ public ServletContextConfiguration(final Servlet servlet) { this.context = servlet.getServletConfig().getServletContext(); }
@Override public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; if (!httpContext.handleSecurity(httpRequest, httpResponse)) return; Object u = httpRequest.getAttribute(HttpContext.REMOTE_USER); String remoteUser = u instanceof String ? (String) u : null; Object a = httpRequest.getAttribute(HttpContext.AUTHENTICATION_TYPE); String authType = a instanceof String ? (String) a : null; if (remoteUser != null || authType != null) { request = new SecurityRequestWrapper(remoteUser, authType, httpRequest); } } delegate.service(request, response); } }
private void initializeServletIfNeeded(final HttpServletRequest req, final Servlet pluginServlet) throws ServletException { if (!initializedServlets.contains(pluginServlet)) { synchronized (servletsMonitor) { if (!initializedServlets.contains(pluginServlet)) { final ServletConfig servletConfig = (ServletConfig) req.getAttribute("killbill.osgi.servletConfig"); if (servletConfig != null) { // TODO PIERRE The servlet will never be destroyed! pluginServlet.init(servletConfig); initializedServlets.add(pluginServlet); } } } } }
public void handle(final ServletRequest req, final ServletResponse res) throws ServletException, IOException { final Servlet local = this.servlet; if ( local != null ) { local.service(req, res); } else { throw new ServletException("Servlet has been unregistered"); } }
public Servlet unregisterMapping(String path) throws ServletException { Servlet servlet = servlets.remove(path); if (servlet == null) { throw new ServletException("Servlet not registered: " + path); } servlet.destroy(); return servlet; }