Handle SLO Redirect profile request.

@param response the response
@param request  the request
@throws Exception the exception
548254
@GetMapping(path = SamlIdPConstants.ENDPOINT_SAML2_SLO_PROFILE_REDIRECT)
    protected void handleSaml2ProfileSLOPostRequest(final HttpServletResponse response,
                                                    final HttpServletRequest request) throws Exception {
        val decoder = getSamlProfileHandlerConfigurationContext().getSamlMessageDecoders().getInstance(HttpMethod.GET);
        handleSloProfileRequest(response, request, decoder);
    }
1355616
protected CommonProfile getAuthenticatedProfile(final HttpServletRequest request, final HttpServletResponse response) {
        val context = new J2EContext(request, response, getConfigurationContext().getSessionStore());
        val manager = new ProfileManager<>(context, context.getSessionStore());
        val profile = manager.get(true);

        if (profile.isEmpty()) {
            throw new IllegalArgumentException("Unable to determine the user profile from the context");
        }
        return profile.get();
    }
1059223
public void doPost(HttpServletRequest request,
                       HttpServletResponse response) 
        throws ServletException, IOException
    {
        HttpSession session = request.getSession(false);
        String action = request.getParameter("Action");
        String name =  request.getParameter("Name");
        String value =  request.getParameter("Value");
        String age =  request.getParameter("MaxAge");

        String nextUrl = getURI(request)+"?R="+redirectCount++;
        if (action.equals("New Session"))
        {   
            session = request.getSession(true);
        }
        else 
        if (session!=null)
        {
            if (action.equals("Invalidate"))
                session.invalidate();
            else if (action.equals("Set"))
            {   
                session.setAttribute(name,value);
                try
                {
                    int m = Integer.parseInt(age);
                    session.setMaxInactiveInterval(m);
                }
                catch(Exception e)
                {
                    LogSupport.ignore(log,e);
                }
            }
            else if (action.equals("Remove"))
                session.removeAttribute(name);
        }

        String encodedUrl=response.encodeRedirectURL(nextUrl);
        response.sendRedirect(encodedUrl);
        
    }
1063880
protected void handleExceptionIfNeeded(HttpResponse response) throws GloboDnsException, IOException {
		int statusCode = response.getStatusCode();
		if (statusCode/100 == 2) {
			// 200 family code
			// Successful return, do nothing
			return;
		} else if (statusCode/100 == 4 || statusCode/100 == 5) {
			// 400 and 500 family codes
			// Something was wrong, produce an error result
			String responseAsString = response.parseAsString();
			if (responseAsString == null || !responseAsString.startsWith("{")) {
				// Response not well formed!
				throw new GloboDnsHttpException("Unknown error in GloboDNS: " + responseAsString, statusCode);
			}
			
			GloboDnsRoot<ErrorMessage> responseObj = this.parse(responseAsString, ErrorMessage.class);
			ErrorMessage errorMsg = responseObj.getFirstObject();
			if (errorMsg != null && errorMsg.getMsg() != null) {
				throw new GloboDnsHttpException(errorMsg.getMsg(), statusCode);
			} else {
				throw new GloboDnsHttpException(responseAsString, statusCode);
			}
		} else {
			// Unknown error code, return generic exception with description
			throw new GloboDnsHttpException(response.parseAsString(), statusCode);
		}
	}
844070
public void handle(ServerHttpRequest request, ServerHttpResponse response)
			throws IOException {
		try {
			Assert.state(request.getHeaders().getContentLength() > 0, "No content");
			ObjectInputStream objectInputStream = new ObjectInputStream(
					request.getBody());
			ClassLoaderFiles files = (ClassLoaderFiles) objectInputStream.readObject();
			objectInputStream.close();
			this.server.updateAndRestart(files);
			response.setStatusCode(HttpStatus.OK);
		}
		catch (Exception ex) {
			logger.warn("Unable to handler restart server HTTP request", ex);
			response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
		}
	}
1318430
@RequestMapping(
            headers = {"org.apereo.portal.url.UrlType=ACTION"},
            method = RequestMethod.POST)
    public void actionRequest(HttpServletRequest request, HttpServletResponse response)
            throws IOException {

        final IPortalRequestInfo portalRequestInfo =
                this.urlSyntaxProvider.getPortalRequestInfo(request);
        final IPortletRequestInfo portletRequestInfo =
                portalRequestInfo.getTargetedPortletRequestInfo();

        final IPortalUrlBuilder actionRedirectUrl;
        if (portletRequestInfo != null) {
            final IPortletWindowId targetWindowId = portletRequestInfo.getPortletWindowId();
            actionRedirectUrl =
                    this.portalUrlProvider.getPortalUrlBuilderByPortletWindow(
                            request, targetWindowId, UrlType.RENDER);
        } else {
            final String targetedLayoutNodeId = portalRequestInfo.getTargetedLayoutNodeId();

            if (targetedLayoutNodeId != null) {
                actionRedirectUrl =
                        this.portalUrlProvider.getPortalUrlBuilderByLayoutNode(
                                request, targetedLayoutNodeId, UrlType.RENDER);
            } else {
                actionRedirectUrl = this.portalUrlProvider.getDefaultUrl(request);
            }
        }

        // Stuff the action-redirect URL builder into the request so other code can use it during
        // request processing
        this.portalUrlProvider.convertToPortalActionUrlBuilder(request, actionRedirectUrl);

        if (portletRequestInfo != null) {
            final IPortletWindowId targetWindowId = portletRequestInfo.getPortletWindowId();

            try {
                this.portletExecutionManager.doPortletAction(targetWindowId, request, response);
            } catch (RuntimeException e) {
                this.logger.error(
                        "Exception thrown while executing portlet action for: "
                                + portletRequestInfo,
                        e);

                // TODO this should be a constant right?
                actionRedirectUrl.setParameter("portletActionError", targetWindowId.toString());
            }
        }

        sendRedirect(actionRedirectUrl, response);
    }
1002461
public function onException(GetResponseForExceptionEvent $event) {
    $exception = $event->getException();
    if (!($exception instanceof RouteException) || PHP_SAPI === 'cli') {
      return;
    }

    $handler = \Drupal::service('acm_exception.route_exception_handler');
    $redirect = $handler->getRedirect($exception);
    $event->setResponse(RedirectResponse::create($redirect, 302));
  }
1210967
public static void redirect(HttpServletRequest request, HttpServletResponse response,
                               String url) throws IOException {
        String redirectUrl;

        if (url.startsWith("/")) {
            redirectUrl = request.getContextPath() + url;
        } else {
            redirectUrl = url;
        }

        logger.debug("Redirecting to URL: {}", redirectUrl);

        response.sendRedirect(redirectUrl);
    }
1299500
public void handle(String pathInContext,
                       String pathParams,
                       HttpRequest request,
                       HttpResponse response)
        throws HttpException, IOException
    {
        Resource resource = getResource(pathInContext);
        if (resource==null)
            return;

        // Is the method allowed?
        if (!isMethodAllowed(request.getMethod()))
        {
            if(log.isDebugEnabled())log.debug("Method not allowed: "+request.getMethod());
            if (resource.exists())
            {
                setAllowHeader(response);
                response.sendError(HttpResponse.__405_Method_Not_Allowed);
            }
            return;
        }

        // Handle the request
        try
        {
            if(log.isDebugEnabled())log.debug("PATH="+pathInContext+" RESOURCE="+resource);
            
            // check filename
            String method=request.getMethod();
            if (method.equals(HttpRequest.__GET) ||
                method.equals(HttpRequest.__POST) ||
                method.equals(HttpRequest.__HEAD))
                handleGet(request, response, pathInContext, pathParams, resource);  
            else if (method.equals(HttpRequest.__PUT))
                handlePut(request, response, pathInContext, resource);
            else if (method.equals(HttpRequest.__DELETE))
                handleDelete(request, response, pathInContext, resource);
            else if (method.equals(HttpRequest.__OPTIONS))
                handleOptions(response, pathInContext);
            else if (method.equals(HttpRequest.__MOVE))
                handleMove(request, response, pathInContext, resource);
            else if (method.equals(HttpRequest.__TRACE))
                handleTrace(request, response);
            else
            {
                if(log.isDebugEnabled())log.debug("Unknown action:"+method);
                // anything else...
                try{
                    if (resource.exists())
                        response.sendError(HttpResponse.__501_Not_Implemented);
                }
                catch(Exception e) {LogSupport.ignore(log,e);}
            }
        }
        catch(IllegalArgumentException e)
        {
            LogSupport.ignore(log,e);
        }
        finally
        {
            if (resource!=null && !(resource instanceof CachedResource))
                resource.release();
        }
    }
243558
public T handle(final HttpRequest request, final HttpResponse response)
        throws IOException
    {
        // Find the response stream - the error stream may be valid in cases
        // where the input stream is not.
        InputStream is = null;
        try {
            final HttpEntity httpEntity = response.getEntity();
            if (httpEntity != null) {
                is = httpEntity.getContent();
                    }
        }
        catch (IOException e) {
            log.warn("Could not locate response body stream", e);
            // normal for 401, 403 and 404 responses, for example...
        }

        if (is == null) {
            // Fall back to zero length response.
            is = new NullInputStream(0);
        }

        final Header header = response.getFirstHeader("Content-Encoding");
        if (header != null) {
            final String encoding = StringUtils.trimToEmpty(header.getValue());

            if (StringUtils.equalsIgnoreCase(encoding, "gzip") || StringUtils.equalsIgnoreCase(encoding, "x-gzip")) {
                log.debug("Found GZIP stream");
                is = new GZIPInputStream(is);
            }
            else if (StringUtils.equalsIgnoreCase(encoding, "deflate")) {
                log.debug("Found deflate stream");
                final Inflater inflater = new Inflater(true);
                is = new InflaterInputStream(is, inflater);
            }
        }
        return contentConverter.convert(request, response, is);
    }
392875
protected void handleRedirectResponse(HttpServerExchange exchange, Response response) {
        exchange.setStatusCode(StatusCodes.FOUND);
        
        Server.headers()
            .entrySet()
            .stream()
            .filter(entry -> StringUtils.isNotBlank(entry.getValue()))
            .forEach(entry -> exchange.getResponseHeaders().add(entry.getKey().toHttpString(), entry.getValue()));

        exchange.getResponseHeaders().put(Header.LOCATION.toHttpString(), response.getRedirectTo());
        response.getHeaders().forEach((key, value) -> exchange.getResponseHeaders().add(key, value));
        exchange.endExchange();
    }
1192485
public void doBrowse(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException
    {
        if (!common.checkGet(request, response)) return;
        User user = common.getLoggedInUser(request);
        if (user == null) {
            common.pageSoftError(response, "Can't do /browse.  Nobody is logged in.");
            return;
        }

        DbxClientV2 dbxClient = requireDbxClient(request, response, user);
        if (dbxClient == null) return;

        String path = request.getParameter("path");
        if (path == null || path.length() == 0) {
            renderFolder(response, user, dbxClient, "");
        } else {
            String pathError = DbxPathV2.findError(path);
            if (pathError != null) {
                response.sendError(400, "Invalid path: " + jq(path) + ": " + pathError);
                return;
            }
            Metadata metadata;
            try {
                metadata = dbxClient.files()
                    .getMetadata(path);
            }
            catch (GetMetadataErrorException ex) {
                if (ex.errorValue.isPath()) {
                    LookupError le = ex.errorValue.getPathValue();
                    if (le.isNotFound()) {
                        response.sendError(400, "Path doesn't exist on Dropbox: " + jq(path));
                        return;
                    }
                }
                common.handleException(response, ex, "getMetadata(" + jq(path) + ")");
                return;
            }
            catch (DbxException ex) {
                common.handleDbxException(response, user, ex, "getMetadata(" + jq(path) + ")");
                return;
            }

            path = DbxPathV2.getParent(path) + "/" + metadata.getName();
            if (metadata instanceof FolderMetadata) {
                renderFolder(response, user, dbxClient, path);
            }
            else {
                renderFile(response, path, (FileMetadata) metadata);
            }
        }
    }
846226
public void handlePut(HttpServletRequest request, HttpServletResponse response, String pathInContext, Resource resource) throws ServletException, IOException
    {
        boolean exists = resource != null && resource.exists();
        if (exists && !passConditionalHeaders(request, response, resource))
            return;

        if (pathInContext.endsWith("/"))
        {
            if (!exists)
            {
                if (!resource.getFile().mkdirs())
                    response.sendError(HttpResponse.__403_Forbidden, "Directories could not be created");
                else
                {
                    response.setStatus(HttpResponse.__201_Created);
                    response.flushBuffer();
                }
            }
            else
            {
                response.setStatus(HttpResponse.__200_OK);
                response.flushBuffer();
            }
        }
        else
        {
            try
            {
                int toRead = request.getContentLength();
                InputStream in = request.getInputStream();
                OutputStream out = resource.getOutputStream();
                if (toRead >= 0)
                    IO.copy(in, out, toRead);
                else
                    IO.copy(in, out);
                out.close();

                response.setStatus(exists ? HttpResponse.__200_OK : HttpResponse.__201_Created);
                response.flushBuffer();
            }
            catch (Exception ex)
            {
                log.warn(LogSupport.EXCEPTION, ex);
                response.sendError(HttpResponse.__403_Forbidden, ex.getMessage());
            }
        }
    }
177014
public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		String requestedPath = (StringUtils.isEmpty(mapping)) ? helper
				.getPathWithinApplication(request) : helper
				.getPathWithinServletMapping(request);

		if (StringUtils.isNotEmpty(controllerMapping)) {
			requestedPath = requestedPath.substring(controllerMapping.length());
		}

		requestHandler.processRequest(requestedPath, request, response);
		return null;
	}
240767
def handle_response(response)
        case response.code.to_i
          when 301,302
            raise(Redirection.new(response))
          when 200...400
            response
          when 400
            raise(BadRequest.new(response))
          when 401
            raise(UnauthorizedAccess.new(response))
          when 403
            raise(ForbiddenAccess.new(response))
          when 404
            raise(ResourceNotFound.new(response))
          when 405
            raise(MethodNotAllowed.new(response))
          when 409
            raise(ResourceConflict.new(response))
          when 422
            raise(ResourceInvalid.new(response))
          when 401...500
            raise(ClientError.new(response))
          when 500...600
            raise(ServerError.new(response))
          else
            raise(ConnectionError.new(response, "Unknown response code: #{response.code}"))
        end
      end
1218920
public void doLogout(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        if (!common.checkPost(request, response)) return;
        request.getSession().removeAttribute("logged-in-username");
        response.sendRedirect("/");
    }
1063849
protected void handle(Authentication authentication) throws IOException, ServletException {
        HttpServletRequest request = http.getCurrentRequest();
        HttpServletResponse response = http.getCurrentResponse();
        String targetUrl = determineTargetUrl(request, response);

        if (response.isCommitted()) {
            logger.debug("Response has already been committed. Unable to redirect to " + targetUrl);
            return;
        } else {
            logger.debug("Redirecting to " + targetUrl);
        }

        redirectStrategy.sendRedirect(targetUrl);
    }