Java Code Examples for javax.servlet.http.HttpServletResponse#SC_TEMPORARY_REDIRECT
The following examples show how to use
javax.servlet.http.HttpServletResponse#SC_TEMPORARY_REDIRECT .
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: EntityHttpServletResponse.java From sakai with Educational Community License v2.0 | 6 votes |
/** * @return the URL this response was forwarded or redirected to OR null if not redirected */ public String getRedirectedUrl() { String url = this.redirectedUrl; if (url == null) { if ( isRedirected() ) { url = this.getForwardedUrl(); if (url == null) { url = this.getIncludedUrl(); } if (this.getStatus() == HttpServletResponse.SC_MOVED_PERMANENTLY || this.getStatus() == HttpServletResponse.SC_SEE_OTHER || this.getStatus() == HttpServletResponse.SC_TEMPORARY_REDIRECT) { // get the location String newLocation = this.getHeader("Location"); if (newLocation == null) { newLocation = this.getHeader("location"); } if (newLocation != null) { url = newLocation; } } } } return url; }
Example 2
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 3
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 4
Source File: EntityHttpServletResponse.java From sakai with Educational Community License v2.0 | 6 votes |
/** * @return the URL this response was forwarded or redirected to OR null if not redirected */ public String getRedirectedUrl() { String url = this.redirectedUrl; if (url == null) { if ( isRedirected() ) { url = this.getForwardedUrl(); if (url == null) { url = this.getIncludedUrl(); } if (this.getStatus() == HttpServletResponse.SC_MOVED_PERMANENTLY || this.getStatus() == HttpServletResponse.SC_SEE_OTHER || this.getStatus() == HttpServletResponse.SC_TEMPORARY_REDIRECT) { // get the location String newLocation = this.getHeader("Location"); if (newLocation == null) { newLocation = this.getHeader("location"); } if (newLocation != null) { url = newLocation; } } } } return url; }
Example 5
Source File: TestRMFailover.java From hadoop with Apache License 2.0 | 5 votes |
static String getRedirectURL(String url) { String redirectUrl = null; try { HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); // do not automatically follow the redirection // otherwise we get too many redirections exception conn.setInstanceFollowRedirects(false); if(conn.getResponseCode() == HttpServletResponse.SC_TEMPORARY_REDIRECT) redirectUrl = conn.getHeaderField("Location"); } catch (Exception e) { // throw new RuntimeException(e); } return redirectUrl; }
Example 6
Source File: TestRMFailover.java From big-c with Apache License 2.0 | 5 votes |
static String getRedirectURL(String url) { String redirectUrl = null; try { HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); // do not automatically follow the redirection // otherwise we get too many redirections exception conn.setInstanceFollowRedirects(false); if(conn.getResponseCode() == HttpServletResponse.SC_TEMPORARY_REDIRECT) redirectUrl = conn.getHeaderField("Location"); } catch (Exception e) { // throw new RuntimeException(e); } return redirectUrl; }
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: EntityHttpServletResponse.java From sakai with Educational Community License v2.0 | 5 votes |
/** * @return true if this response was redirected */ public boolean isRedirected() { boolean redirected = false; if (this.getForwardedUrl() != null || this.getStatus() == HttpServletResponse.SC_FOUND || this.getStatus() == HttpServletResponse.SC_MOVED_PERMANENTLY || this.getStatus() == HttpServletResponse.SC_SEE_OTHER || this.getStatus() == HttpServletResponse.SC_TEMPORARY_REDIRECT) { redirected = true; } return redirected; }
Example 9
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 10
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 11
Source File: EntityHttpServletResponse.java From sakai with Educational Community License v2.0 | 5 votes |
/** * @return true if this response was redirected */ public boolean isRedirected() { boolean redirected = false; if (this.getForwardedUrl() != null || this.getStatus() == HttpServletResponse.SC_FOUND || this.getStatus() == HttpServletResponse.SC_MOVED_PERMANENTLY || this.getStatus() == HttpServletResponse.SC_SEE_OTHER || this.getStatus() == HttpServletResponse.SC_TEMPORARY_REDIRECT) { redirected = true; } return redirected; }