Java Code Examples for javax.servlet.http.HttpServletResponse#SC_MOVED_TEMPORARILY
The following examples show how to use
javax.servlet.http.HttpServletResponse#SC_MOVED_TEMPORARILY .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedirectRequestHandler.java From onedev with MIT License | 6 votes |
/** {@inheritDoc} */ public void respond(final IRequestCycle requestCycle) { String location = requestCycle.getUrlRenderer().renderRelativeUrl(Url.parse(getRedirectUrl())); WebResponse response = (WebResponse)requestCycle.getResponse(); if (status == HttpServletResponse.SC_MOVED_TEMPORARILY) { response.sendRedirect(location); } else { response.setStatus(status); if (((WebRequest)requestCycle.getRequest()).isAjax()) { response.setHeader("Ajax-Location", location); } else { response.setHeader("Location", location); } } }
Example 2
Source File: RedirectServlet.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public void init(ServletConfig config) throws ServletException { super.init(config); destination = config.getInitParameter("destination"); if(destination==null) { throw new ServletException("RedirectServlet missing destination configuration"); } if( "false".equals(config.getInitParameter("permanent") )) { code = HttpServletResponse.SC_MOVED_TEMPORARILY; } // Replace the context key if(destination.startsWith(CONTEXT_KEY)) { destination = config.getServletContext().getContextPath() +destination.substring(CONTEXT_KEY.length()); } }
Example 3
Source File: AtlasApiHaDispatch.java From knox with Apache License 2.0 | 6 votes |
@Override protected void executeRequest(HttpUriRequest outboundRequest, HttpServletRequest inboundRequest, HttpServletResponse outboundResponse) throws IOException { HttpResponse inboundResponse = null; try { inboundResponse = executeOutboundRequest(outboundRequest); int statusCode = inboundResponse.getStatusLine().getStatusCode(); Header originalLocationHeader = inboundResponse.getFirstHeader("Location"); if ((statusCode == HttpServletResponse.SC_MOVED_TEMPORARILY || statusCode == HttpServletResponse.SC_TEMPORARY_REDIRECT) && originalLocationHeader != null) { inboundResponse.removeHeaders("Location"); failoverRequest(outboundRequest, inboundRequest, outboundResponse, inboundResponse, new Exception("Atlas HA redirection")); } writeOutboundResponse(outboundRequest, inboundRequest, outboundResponse, inboundResponse); } catch (IOException e) { LOG.errorConnectingToServer(outboundRequest.getURI().toString(), e); failoverRequest(outboundRequest, inboundRequest, outboundResponse, inboundResponse, e); } }
Example 4
Source File: AtlasApiTrustedProxyHaDispatch.java From knox with Apache License 2.0 | 6 votes |
@Override protected void executeRequest(HttpUriRequest outboundRequest, HttpServletRequest inboundRequest, HttpServletResponse outboundResponse) throws IOException { HttpResponse inboundResponse = null; try { inboundResponse = executeOutboundRequest(outboundRequest); int statusCode = inboundResponse.getStatusLine().getStatusCode(); Header originalLocationHeader = inboundResponse.getFirstHeader("Location"); if ((statusCode == HttpServletResponse.SC_MOVED_TEMPORARILY || statusCode == HttpServletResponse.SC_TEMPORARY_REDIRECT) && originalLocationHeader != null) { inboundResponse.removeHeaders("Location"); failoverRequest(outboundRequest, inboundRequest, outboundResponse, inboundResponse, new Exception("Atlas HA redirection")); } writeOutboundResponse(outboundRequest, inboundRequest, outboundResponse, inboundResponse); } catch (IOException e) { LOG.errorConnectingToServer(outboundRequest.getURI().toString(), e); failoverRequest(outboundRequest, inboundRequest, outboundResponse, inboundResponse, e); } }
Example 5
Source File: SlackNotificationTestServer.java From tcSlackBuildNotifier with MIT License | 6 votes |
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/plain"); response.setStatus(this.response); switch (this.response) { case HttpServletResponse.SC_OK: //response.getWriter().println("<h1>Hello SimpleServlet</h1>"); this.printParams(request, response); break; case HttpServletResponse.SC_MOVED_TEMPORARILY: response.sendRedirect("/200"); break; default: response.getWriter().println("<h1>Hello from defaultt</h1>"); break; } System.out.println("Handling Web request for " + ((Request) request).getUri().toString()); }
Example 6
Source File: RedirectRequestHandler.java From onedev with MIT License | 5 votes |
/** * @param redirectUrl * URL to redirect to. * @param status * 301 (Moved permanently) or 302 (Moved temporarily) */ public RedirectRequestHandler(final String redirectUrl, final int status) { if ((status != HttpServletResponse.SC_MOVED_PERMANENTLY) && (status != HttpServletResponse.SC_MOVED_TEMPORARILY) && (status != HttpServletResponse.SC_SEE_OTHER)) { throw new IllegalStateException("Status must be either 301, 302 or 303, but was: " + status); } this.redirectUrl = Args.notEmpty(redirectUrl, "redirectUrl"); this.status = status; }
Example 7
Source File: AppEngineHttpFetcher.java From openid4java with Apache License 2.0 | 5 votes |
private static boolean isRedirect(int responseCode) { switch (responseCode) { case HttpServletResponse.SC_MOVED_PERMANENTLY: case HttpServletResponse.SC_MOVED_TEMPORARILY: case HttpServletResponse.SC_SEE_OTHER: case HttpServletResponse.SC_TEMPORARY_REDIRECT: return true; default: return false; } }
Example 8
Source File: AtlasHaDispatch.java From knox with Apache License 2.0 | 5 votes |
@Override protected void executeRequest(HttpUriRequest outboundRequest, HttpServletRequest inboundRequest, HttpServletResponse outboundResponse) throws IOException { HttpResponse inboundResponse = null; try { inboundResponse = executeOutboundRequest(outboundRequest); int sc = inboundResponse.getStatusLine().getStatusCode(); if(sc == HttpServletResponse.SC_MOVED_TEMPORARILY || sc == HttpServletResponse.SC_TEMPORARY_REDIRECT) { if(!isLoginRedirect(inboundResponse.getFirstHeader("Location"))) { inboundResponse.removeHeaders("Location"); failoverRequest(outboundRequest, inboundRequest, outboundResponse, inboundResponse, new Exception("Atlas HA redirection")); } } writeOutboundResponse(outboundRequest, inboundRequest, outboundResponse, inboundResponse); } catch (IOException e) { LOG.errorConnectingToServer(outboundRequest.getURI().toString(), e); failoverRequest(outboundRequest, inboundRequest, outboundResponse, inboundResponse, e); } }
Example 9
Source File: AtlasTrustedProxyHaDispatch.java From knox with Apache License 2.0 | 5 votes |
@Override protected void executeRequest(HttpUriRequest outboundRequest, HttpServletRequest inboundRequest, HttpServletResponse outboundResponse) throws IOException { HttpResponse inboundResponse = null; try { inboundResponse = executeOutboundRequest(outboundRequest); int sc = inboundResponse.getStatusLine().getStatusCode(); if (sc == HttpServletResponse.SC_MOVED_TEMPORARILY || sc == HttpServletResponse.SC_TEMPORARY_REDIRECT) { if (!isLoginRedirect(inboundResponse.getFirstHeader("Location"))) { inboundResponse.removeHeaders("Location"); failoverRequest(outboundRequest, inboundRequest, outboundResponse, inboundResponse, new Exception("Atlas HA redirection")); } } writeOutboundResponse(outboundRequest, inboundRequest, outboundResponse, inboundResponse); } catch (IOException e) { LOG.errorConnectingToServer(outboundRequest.getURI().toString(), e); failoverRequest(outboundRequest, inboundRequest, outboundResponse, inboundResponse, e); } }
Example 10
Source File: BrowserRedirectException.java From archiva with Apache License 2.0 | 5 votes |
/** * * @param location * @param relocationType see {@link RelocationException.RelocationType} * @since 2.0.0 */ public BrowserRedirectException( String location, RelocationException.RelocationType relocationType ) { super( relocationType == RelocationException.RelocationType.TEMPORARY ? HttpServletResponse.SC_MOVED_TEMPORARILY : HttpServletResponse.SC_MOVED_PERMANENTLY ); this.location = location; }
Example 11
Source File: RedirectRequestHandler.java From onedev with MIT License | 4 votes |
/** * @param redirectUrl * URL to redirect to. */ public RedirectRequestHandler(final String redirectUrl) { this(redirectUrl, HttpServletResponse.SC_MOVED_TEMPORARILY); }
Example 12
Source File: GenericResponseWrapper.java From ymate-platform-v2 with Apache License 2.0 | 4 votes |
@Override public void sendRedirect(String string) throws IOException { statusCode = HttpServletResponse.SC_MOVED_TEMPORARILY; super.sendRedirect(string); }
Example 13
Source File: AbstractRepositoryServletTestCase.java From archiva with Apache License 2.0 | 4 votes |
protected WebResponse getWebResponse( WebRequest webRequest ) //, boolean followRedirect ) throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.setRequestURI( webRequest.getUrl().getPath() ); request.addHeader( "User-Agent", "Apache Archiva unit test" ); request.setMethod( webRequest.getHttpMethod().name() ); if ( webRequest.getHttpMethod() == HttpMethod.PUT ) { PutMethodWebRequest putRequest = PutMethodWebRequest.class.cast( webRequest ); request.setContentType( putRequest.contentType ); request.setContent( IOUtils.toByteArray( putRequest.inputStream ) ); } if ( webRequest instanceof MkColMethodWebRequest ) { request.setMethod( "MKCOL" ); } final MockHttpServletResponse response = execute( request ); if ( response.getStatus() == HttpServletResponse.SC_MOVED_PERMANENTLY || response.getStatus() == HttpServletResponse.SC_MOVED_TEMPORARILY ) { String location = response.getHeader( "Location" ); log.debug( "follow redirect to {}", location ); return getWebResponse( new GetMethodWebRequest( location ) ); } return new WebResponse( null, null, 1 ) { @Override public String getContentAsString() { try { return response.getContentAsString(); } catch ( UnsupportedEncodingException e ) { throw new RuntimeException( e.getMessage(), e ); } } @Override public int getStatusCode() { return response.getStatus(); } @Override public String getResponseHeaderValue( String headerName ) { return response.getHeader( headerName ); } }; }
Example 14
Source File: ResponseBuilder.java From jerseyoauth2 with MIT License | 4 votes |
@Override public IOAuth2Response buildAuthorizationRequestErrorResponse(OAuth2ProtocolException ex, URI redirectUrl) throws ResponseBuilderException { return new AuthRequestErrorResponse(HttpServletResponse.SC_MOVED_TEMPORARILY, redirectUrl, ex); }
Example 15
Source File: ResponseBuilder.java From jerseyoauth2 with MIT License | 4 votes |
@Override public IOAuth2Response buildAuthorizationCodeResponse(String code, URI redirectUrl, String state) throws ResponseBuilderException { return new AuthCodeResponse(HttpServletResponse.SC_MOVED_TEMPORARILY, code, redirectUrl, state); }
Example 16
Source File: ResponseBuilder.java From jerseyoauth2 with MIT License | 4 votes |
@Override public IOAuth2Response buildImplicitGrantAccessTokenResponse(IAccessTokenInfo accessToken, URI redirectUrl, String state) throws ResponseBuilderException { return new AccessTokenRedirectResponse( HttpServletResponse.SC_MOVED_TEMPORARILY, accessToken, redirectUrl, state); }