@Override public void sendError(int sc) throws IOException { if (isCommitted()) { throw new IllegalStateException (sm.getString("coyoteResponse.sendError.ise")); } response.setAppCommitted(true); response.sendError(sc); }
String parseReasonPhrase(Response response) { String msg = response.getMessage(); if (msg != null) { return msg; } return statusReasons.getString("sc." + response.getStatus()); }
@Override public void sendRedirect(String location) throws IOException { if (isCommitted()) { throw new IllegalStateException (sm.getString("coyoteResponse.sendRedirect.ise")); } response.setAppCommitted(true); response.sendRedirect(location); }
protected void basicAuthError(Response response) throws IOException { response.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"" + context.getLoginConfig().getRealmName() + "\""); response.sendError(401); }
ErrorPage errorPage) { if (container.getLogger().isDebugEnabled()) { container.getLogger().debug("Processing " + errorPage); request.getContext().getServletContext(); RequestDispatcher rd = servletContext.getRequestDispatcher(errorPage.getLocation()); container.getLogger().error( sm.getString("standardHostValue.customStatusFailed", errorPage.getLocation())); return false; if (response.isCommitted()) { rd.include(request.getRequest(), response.getResponse()); } else { response.resetBuffer(true); response.setContentLength(-1); rd.forward(request.getRequest(), response.getResponse()); response.setSuspended(false);
MessageBytes requestPathMB = request.getRequestPathMB(); if ((requestPathMB.startsWithIgnoreCase("/META-INF/", 0)) || (requestPathMB.equalsIgnoreCase("/META-INF")) || (requestPathMB.startsWithIgnoreCase("/WEB-INF/", 0)) || (requestPathMB.equalsIgnoreCase("/WEB-INF"))) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; Wrapper wrapper = request.getWrapper(); if (wrapper == null || wrapper.isUnavailable()) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; response.sendAcknowledgement(); } catch (IOException ioe) { container.getLogger().error(sm.getString( "standardContextValve.acknowledgeException"), ioe); request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, ioe); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; request.setAsyncSupported(wrapper.getPipeline().isAsyncSupported()); wrapper.getPipeline().getFirst().invoke(request, response);
public Principal authenticateSSL(Request request, Response response) throws IOException { if (containerLog.isDebugEnabled()) { containerLog.debug(" Looking up certificates"); X509Certificate[] certs = (X509Certificate[]) request.getAttribute(Globals.CERTIFICATES_ATTR); request.getCoyoteRequest().action(ActionCode.ACTION_REQ_SSL_CERTIFICATE, null); } catch (IllegalStateException ise) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED, sm.getString("authenticator.certificates")); return null; certs = (X509Certificate[]) request.getAttribute(Globals.CERTIFICATES_ATTR); if (containerLog.isDebugEnabled()) { containerLog.debug(" No certificates included with this request"); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, sm.getString("authenticator.certificates")); return null; Principal principal = getContext().getRealm().authenticate(certs); containerLog.debug(" Realm.authenticate() returned false"); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, sm.getString("authenticator.unauthorized")); return null;
@Override public void invoke(Request request, Response response) throws IOException, ServletException { Context context = request.getContext(); if (context == null) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, sm.getString("standardHost.noContext")); return; } Thread.currentThread().setContextClassLoader(context.getLoader().getClassLoader()); boolean processed = false; try { if (ignorePattern == null || !ignorePattern.matcher(request.getRequestURI()).matches()) { processed = true; if (log.isTraceEnabled()) { log.trace("Will save to redis after request for [" + getQueryString(request) + "]"); } } else { if (log.isTraceEnabled()) { log.trace("Ignoring [" + getQueryString(request) + "]"); } } getNext().invoke(request, response); } finally { manager.afterRequest(processed); } }
@Override public AsyncContext startAsync(ServletRequest request, ServletResponse response) { if (!isAsyncSupported()) { IllegalStateException ise = new IllegalStateException(sm.getString("request.asyncNotSupported")); log.warn(sm.getString("coyoteRequest.noAsync", StringUtils.join(getNonAsyncClassNames())), ise); throw ise; } if (asyncContext == null) { asyncContext = new AsyncContextImpl(this); } asyncContext.setStarted(getContext(), request, response, request==getRequest() && response==getResponse().getResponse()); asyncContext.setTimeout(getConnector().getAsyncTimeout()); return asyncContext; }
if (isCommitted()) { throw new IllegalStateException(sm.getString("coyoteResponse.sendRedirect.ise")); resetBuffer(true); String locationUri; if (getRequest().getCoyoteRequest().getSupportsRelativeRedirects() && getContext().getUseRelativeRedirects()) { locationUri = location; } else { locationUri = toAbsolute(location); setStatus(status); setHeader("Location", locationUri); if (getContext().getSendRedirectBody()) { PrintWriter writer = getWriter(); writer.print(sm.getString("coyoteResponse.sendRedirect.note", Escape.htmlElementContent(locationUri))); flushBuffer(); log.warn(sm.getString("response.sendRedirectFail", location), e); setStatus(SC_NOT_FOUND); setSuspended(true);
/** * Select the appropriate child Host to process this request, * based on the requested server name. If no matching Host can * be found, return an appropriate HTTP error. * * @param request Request to be processed * @param response Response to be produced * * @exception IOException if an input/output error occurred * @exception ServletException if a servlet error occurred */ @Override public final void invoke(Request request, Response response) throws IOException, ServletException { // Select the Host to be used for this Request Host host = request.getHost(); if (host == null) { response.sendError (HttpServletResponse.SC_BAD_REQUEST, sm.getString("standardEngine.noHost", request.getServerName())); return; } if (request.isAsyncSupported()) { request.setAsyncSupported(host.getPipeline().isAsyncSupported()); } // Ask this Host to process this request host.getPipeline().getFirst().invoke(request, response); }
ErrorPage errorPage) { if (container.getLogger().isDebugEnabled()) container.getLogger().debug("Processing " + errorPage); request.setPathInfo(errorPage.getLocation()); response.resetBuffer(true); request.getContext().getServletContext(); RequestDispatcher rd = servletContext.getRequestDispatcher(errorPage.getLocation()); rd.forward(request.getRequest(), response.getResponse()); response.setSuspended(false); container.getLogger().error("Exception Processing " + errorPage, t); return (false);
try { if (requestResolver.isHttpPOSTBinding()) { if (request.getSession(false).getAttribute(Constants.SESSION_BEAN) != null) { String htmlPayload = manager.handleLogoutRequestForPOSTBinding(request); response.setContentType(Constants.CONTENT_TYPE_HTML); SSOUtils.sendCharacterData(response, htmlPayload); } else { containerLog.warn("Attempt to logout from an already logged out session"); response.sendRedirect(request.getContext().getPath()); response.sendRedirect(manager.handleLogoutRequestForRedirectBinding(request));
private JaspicState getJaspicState(AuthConfigProvider jaspicProvider, Request request, Response response, boolean authMandatory) throws IOException { JaspicState jaspicState = new JaspicState(); jaspicState.messageInfo = new MessageInfoImpl(request.getRequest(), response.getResponse(), authMandatory); try { CallbackHandler callbackHandler = createCallbackHandler(); ServerAuthConfig serverAuthConfig = jaspicProvider.getServerAuthConfig( "HttpServlet", jaspicAppContextID, callbackHandler); String authContextID = serverAuthConfig.getAuthContextID(jaspicState.messageInfo); jaspicState.serverAuthContext = serverAuthConfig.getAuthContext(authContextID, null, null); } catch (AuthException e) { log.warn(sm.getString("authenticator.jaspicServerAuthContextFail"), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return null; } return jaspicState; }
private boolean sendErrorPage(String location, Response response) { File file = new File(location); if (!file.isAbsolute()) { file = new File(getContainer().getCatalinaBase(), location); } if (!file.isFile() || !file.canRead()) { getContainer().getLogger().warn( sm.getString("errorReportValve.errorPageNotFound", location)); return false; } // Hard coded for now. Consider making this optional. At Valve level or // page level? response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); try (OutputStream os = response.getOutputStream(); InputStream is = new FileInputStream(file);){ IOTools.flow(is, os); } catch (IOException e) { getContainer().getLogger().warn( sm.getString("errorReportValve.errorPageIOException", location), e); return false; } return true; }
@Override public void invoke(final Request request, final Response response) throws IOException, ServletException { if (isAllowed(request.getRequest().getRemoteAddr())) { getNext().invoke(request, response); } else { response.sendError(HttpServletResponse.SC_FORBIDDEN); } }
@Override public void invoke(final Request request, final Response response) throws IOException, ServletException { if (request.getRequestURI().equals(current.endpoint)) { response.setHeader("Content-Type", "text/plain"); response.getWriter().write(current.challenge); return; } getNext().invoke(request, response); }
/** * Reject the request that was denied by this valve. * <p>If <code>invalidAuthenticationWhenDeny</code> is true * and the context has <code>preemptiveAuthentication</code> * set, set an invalid authorization header to trigger basic auth. * * @param request The servlet request to be processed * @param response The servlet response to be processed * @exception IOException if an input/output error occurs * @exception ServletException if a servlet error occurs */ protected void denyRequest(Request request, Response response) throws IOException, ServletException { if (invalidAuthenticationWhenDeny) { Context context = request.getContext(); if (context != null && context.getPreemptiveAuthentication()) { if (request.getCoyoteRequest().getMimeHeaders().getValue("authorization") == null) { request.getCoyoteRequest().getMimeHeaders().addValue("authorization").setString("invalid"); } getNext().invoke(request, response); return; } } response.sendError(denyStatus); }
/** * Special method for adding a session cookie as we should be overriding * any previous. * * @param cookie The new session cookie to add the response */ public void addSessionCookieInternal(final Cookie cookie) { if (isCommitted()) { return; } String name = cookie.getName(); final String headername = "Set-Cookie"; final String startsWith = name + "="; String header = generateCookieString(cookie); boolean set = false; MimeHeaders headers = getCoyoteResponse().getMimeHeaders(); int n = headers.size(); for (int i = 0; i < n; i++) { if (headers.getName(i).toString().equals(headername)) { if (headers.getValue(i).toString().startsWith(startsWith)) { headers.getValue(i).setString(header); set = true; } } } if (!set) { addHeader(headername, header); } }