protected ServerContainer getContainer(HttpServletRequest request) { ServletContext servletContext = request.getServletContext(); String attrName = "javax.websocket.server.ServerContainer"; ServerContainer container = (ServerContainer) servletContext.getAttribute(attrName); Assert.notNull(container, "No 'javax.websocket.server.ServerContainer' ServletContext attribute. " + "Are you running in a Servlet container that supports JSR-356?"); return container; }
@Override public ServletContext getServletContext() { return b.request.getServletContext(); }
private WsServerContainer getContainer(HttpServletRequest request) { if (this.serverContainer == null) { Object container = request.getServletContext().getAttribute(SERVER_CONTAINER_ATTR); Assert.state(container instanceof WsServerContainer, "ServletContext attribute 'javax.websocket.server.ServerContainer' not found."); this.serverContainer = (WsServerContainer) container; initServerContainer(this.serverContainer); } return this.serverContainer; }
private void startLazily(HttpServletRequest request) { if (this.servletContext != null) { return; } synchronized (this.lifecycleMonitor) { if (this.servletContext == null) { this.servletContext = request.getServletContext(); start(); } } }
public Object getSubject(HttpServletRequest request) { try { ServletContext servletContext = request.getServletContext(); Object securityContext = this.securityContextMethod.invoke(servletContext); Object subject = this.currentUserMethod.invoke(null, securityContext, request); if (subject == null) { Object securityProvider = this.providerMethod.invoke(null); subject = this.anonymousSubjectMethod.invoke(securityProvider); } return subject; } catch (Exception ex) { throw new HandshakeFailureException("Failed to obtain SubjectHandle", ex); } } }
/** * Look for the WebApplicationContext associated with the DispatcherServlet * that has initiated request processing, and for the global context if none * was found associated with the current request. The global context will * be found via the ServletContext or via ContextLoader's current context. * <p>NOTE: This variant requires Servlet 3.0+ and is generally recommended * for forward-looking custom user code. * @param request current HTTP request * @return the request-specific WebApplicationContext, or the global one * if no request-specific context has been found, or {@code null} if none * @since 4.2.1 * @see #findWebApplicationContext(HttpServletRequest, ServletContext) * @see ServletRequest#getServletContext() * @see ContextLoader#getCurrentWebApplicationContext() */ @Nullable public static WebApplicationContext findWebApplicationContext(HttpServletRequest request) { return findWebApplicationContext(request, request.getServletContext()); }
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.getServletContext().getRequestDispatcher("/foo").forward(req, resp); } }
/** * Returns non-<code>null</code> attribute value. Scopes are examined in the * following order: request, session, application. */ public static Object attribute(final HttpServletRequest request, final String name) { Object value = request.getAttribute(name); if (value != null) { return value; } value = request.getSession().getAttribute(name); if (value != null) { return value; } return request.getServletContext().getAttribute(name); }
/** * Include named resource. */ public static boolean includeNamed(final HttpServletRequest request, final ServletResponse response, final String resource) throws IOException, ServletException { return includeNamed(request.getServletContext(), request, response, resource); }
/** * Forward to page path relative to the root of the ServletContext. */ public static boolean forwardAbsolute(final HttpServletRequest request, final ServletResponse response, final String page) throws IOException, ServletException { return forwardAbsolute(request.getServletContext(), request, response, page); }
/** * Forward to named resource. */ public static boolean forwardNamed(final HttpServletRequest request, final ServletResponse response, final String resource) throws IOException, ServletException { return forwardNamed(request.getServletContext(), request, response, resource); }
/** * Include page which path relative to the root of the ServletContext. */ public static boolean includeAbsolute(final HttpServletRequest request, final HttpServletResponse response, final String page) throws IOException, ServletException { return includeAbsolute(request.getServletContext(), request, response, page); }
private void forwardToMessagePage(final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse, final String message) throws Exception { httpServletRequest.setAttribute("title", OIDC_ERROR_TITLE); httpServletRequest.setAttribute("messages", message); final ServletContext uiContext = httpServletRequest.getServletContext().getContext("/nifi"); uiContext.getRequestDispatcher("/WEB-INF/pages/message-page.jsp").forward(httpServletRequest, httpServletResponse); }
@SuppressWarnings("unchecked") private Supplier<C> createContext(HttpServletRequest request) { WebApplicationContext context = WebApplicationContextUtils .getRequiredWebApplicationContext(request.getServletContext()); if (this.contextClass.isInstance(context)) { return () -> (C) context; } return () -> context.getBean(this.contextClass); }
@Override public void inject(final ActionRequest actionRequest, final Targets targets) { final HttpServletRequest servletRequest = actionRequest.getHttpServletRequest(); inject(servletRequest.getServletContext(), targets); }
@Override protected void handleSuccess(HttpServletRequest request, HttpServletResponse response, UpgradeInfo upgradeInfo, TyrusUpgradeResponse upgradeResponse) throws IOException, ServletException { response.setStatus(upgradeResponse.getStatus()); upgradeResponse.getHeaders().forEach((key, value) -> response.addHeader(key, Utils.getHeaderFromList(value))); AsyncContext asyncContext = request.startAsync(); asyncContext.setTimeout(-1L); Object nativeRequest = getNativeRequest(request); BeanWrapper beanWrapper = new BeanWrapperImpl(nativeRequest); Object httpSocket = beanWrapper.getPropertyValue("connection.connectionHandler.rawConnection"); Object webSocket = webSocketHelper.newInstance(request, httpSocket); webSocketHelper.upgrade(webSocket, httpSocket, request.getServletContext()); response.flushBuffer(); boolean isProtected = request.getUserPrincipal() != null; Writer servletWriter = servletWriterHelper.newInstance(webSocket, isProtected); Connection connection = upgradeInfo.createConnection(servletWriter, noOpCloseListener); new BeanWrapperImpl(webSocket).setPropertyValue("connection", connection); new BeanWrapperImpl(servletWriter).setPropertyValue("connection", connection); webSocketHelper.registerForReadEvent(webSocket); }
/** * Returns <code>true</code> if target exists. */ protected boolean targetExists(final ActionRequest actionRequest, final String target) { if (log.isDebugEnabled()) { log.debug("target check: " + target); } final ServletContext servletContext = actionRequest.getHttpServletRequest().getServletContext(); try { return servletContext.getResource(target) != null; } catch (MalformedURLException ignore) { return false; } }
@Override public void outject(final ActionRequest actionRequest, final Targets targets) { final ServletContext context = actionRequest.getHttpServletRequest().getServletContext(); targets.forEachTargetAndOut(this, (target, out) -> { final Object value = target.readValue(out); context.setAttribute(out.name(), value); }); }
@Override public void doFilter(HttpServletRequest wrappedRequest) { ServletContext context = wrappedRequest.getSession().getServletContext(); assertThat(context).isSameAs(wrappedRequest.getServletContext()); } });
/** * Performs injection. */ protected void inject(final ActionRequest actionRequest) { final Targets targets = actionRequest.getTargets(); final ServletContext servletContext = actionRequest.getHttpServletRequest().getServletContext(); scopeResolver.forEachScope(madvocScope -> madvocScope.inject(servletContext, targets)); scopeResolver.forEachScope(madvocScope -> madvocScope.inject(actionRequest, targets)); }