Java Code Examples for javax.servlet.http.HttpServletResponse#SC_MOVED_PERMANENTLY
The following examples show how to use
javax.servlet.http.HttpServletResponse#SC_MOVED_PERMANENTLY .
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: 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 3
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 4
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 5
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 6
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 7
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 8
Source File: BrowserRedirectException.java From archiva with Apache License 2.0 | 4 votes |
public BrowserRedirectException( String location ) { super( HttpServletResponse.SC_MOVED_PERMANENTLY ); this.location = location; }
Example 9
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 10
Source File: WebUtils.java From ymate-platform-v2 with Apache License 2.0 | 2 votes |
/** * @param response HttpServletResponse对象 * @param url 目标URL地址 * @return 通过设置Header的Location属性执行页面跳转 */ public static String doRedirectHeaderLocation(HttpServletResponse response, String url) { response.setHeader("Location", url); return "http:" + HttpServletResponse.SC_MOVED_PERMANENTLY; }