Java Code Examples for org.apache.http.HttpStatus#SC_SEE_OTHER

The following examples show how to use org.apache.http.HttpStatus#SC_SEE_OTHER . 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: MyRedirectHandler.java    From Mobike with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isRedirectRequested(
        final HttpResponse response,
        final HttpContext context) {
    if (!enableRedirects) {
        return false;
    }
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    int statusCode = response.getStatusLine().getStatusCode();
    switch (statusCode) {
        case HttpStatus.SC_MOVED_TEMPORARILY:
        case HttpStatus.SC_MOVED_PERMANENTLY:
        case HttpStatus.SC_SEE_OTHER:
        case HttpStatus.SC_TEMPORARY_REDIRECT:
            return true;
        default:
            return false;
    } //end of switch
}
 
Example 2
Source File: MyRedirectHandler.java    From AndroidWear-OpenWear with MIT License 6 votes vote down vote up
@Override
public boolean isRedirectRequested(
        final HttpResponse response,
        final HttpContext context) {
    if (!enableRedirects) {
        return false;
    }
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    int statusCode = response.getStatusLine().getStatusCode();
    switch (statusCode) {
        case HttpStatus.SC_MOVED_TEMPORARILY:
        case HttpStatus.SC_MOVED_PERMANENTLY:
        case HttpStatus.SC_SEE_OTHER:
        case HttpStatus.SC_TEMPORARY_REDIRECT:
            return true;
        default:
            return false;
    } //end of switch
}
 
Example 3
Source File: MyRedirectHandler.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isRedirectRequested(
        final HttpResponse response,
        final HttpContext context) {
    if (!enableRedirects) {
        return false;
    }
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    int statusCode = response.getStatusLine().getStatusCode();
    switch (statusCode) {
        case HttpStatus.SC_MOVED_TEMPORARILY:
        case HttpStatus.SC_MOVED_PERMANENTLY:
        case HttpStatus.SC_SEE_OTHER:
        case HttpStatus.SC_TEMPORARY_REDIRECT:
            return true;
        default:
            return false;
    } //end of switch
}
 
Example 4
Source File: MyRedirectHandler.java    From Android-Basics-Codes with Artistic License 2.0 6 votes vote down vote up
@Override
public boolean isRedirectRequested(
        final HttpResponse response,
        final HttpContext context) {
    if (!enableRedirects) {
        return false;
    }
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    int statusCode = response.getStatusLine().getStatusCode();
    switch (statusCode) {
        case HttpStatus.SC_MOVED_TEMPORARILY:
        case HttpStatus.SC_MOVED_PERMANENTLY:
        case HttpStatus.SC_SEE_OTHER:
        case HttpStatus.SC_TEMPORARY_REDIRECT:
            return true;
        default:
            return false;
    } //end of switch
}
 
Example 5
Source File: MyRedirectHandler.java    From Android-Basics-Codes with Artistic License 2.0 6 votes vote down vote up
@Override
public boolean isRedirectRequested(
        final HttpResponse response,
        final HttpContext context) {
    if (!enableRedirects) {
        return false;
    }
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    int statusCode = response.getStatusLine().getStatusCode();
    switch (statusCode) {
        case HttpStatus.SC_MOVED_TEMPORARILY:
        case HttpStatus.SC_MOVED_PERMANENTLY:
        case HttpStatus.SC_SEE_OTHER:
        case HttpStatus.SC_TEMPORARY_REDIRECT:
            return true;
        default:
            return false;
    } //end of switch
}
 
Example 6
Source File: MyRedirectHandler.java    From Android-Basics-Codes with Artistic License 2.0 6 votes vote down vote up
@Override
public boolean isRedirectRequested(
        final HttpResponse response,
        final HttpContext context) {
    if (!enableRedirects) {
        return false;
    }
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    int statusCode = response.getStatusLine().getStatusCode();
    switch (statusCode) {
        case HttpStatus.SC_MOVED_TEMPORARILY:
        case HttpStatus.SC_MOVED_PERMANENTLY:
        case HttpStatus.SC_SEE_OTHER:
        case HttpStatus.SC_TEMPORARY_REDIRECT:
            return true;
        default:
            return false;
    } //end of switch
}
 
Example 7
Source File: SimpleRedirectStrategy.java    From gerbil with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public boolean isRedirected(final HttpRequest request, final HttpResponse response, final HttpContext context)
        throws ProtocolException {
    Args.notNull(request, "HTTP request");
    Args.notNull(response, "HTTP response");

    final int statusCode = response.getStatusLine().getStatusCode();
    final String method = request.getRequestLine().getMethod();
    final Header locationHeader = response.getFirstHeader("location");
    switch (statusCode) {
    case HttpStatus.SC_MOVED_TEMPORARILY:
        return isRedirectable(method) && locationHeader != null;
    case HttpStatus.SC_MOVED_PERMANENTLY:
    case HttpStatus.SC_TEMPORARY_REDIRECT:
    case 308: // Ensure that HTTP 308 is redirected as well
        return isRedirectable(method);
    case HttpStatus.SC_SEE_OTHER:
        return true;
    default:
        return false;
    } // end of switch
}
 
Example 8
Source File: DcResponse.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * Engineとして許容しないレスポンスコードかどうかを判定する.
 * @param oStatus レスポンスコード(Number型)
 * @return true:Engineとして許容しないレスポンスコードである false:Engineとして許容できるレスポンスコードである
 */
private static boolean isInvalidResCode(Number oStatus) {
    // 以下のレスポンスコードは許容しない
    // ・3桁ではない
    // ・0番台
    // ・100番台(クライアントの挙動が不安定になるため)
    if (!String.valueOf(Context.toString(oStatus)).matches("^[2-9]\\d{2}$")) {
        return true;
    }
    // 301、303、307はサーブレットコンテナでエラーになるため許容しない
    if (oStatus.intValue() == HttpStatus.SC_MOVED_PERMANENTLY
            || oStatus.intValue() == HttpStatus.SC_SEE_OTHER
            || oStatus.intValue() == HttpStatus.SC_TEMPORARY_REDIRECT) {
        return true;
    }
    return false;
}
 
Example 9
Source File: HttpClientAdapter.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check if status is a redirect (various 30x values).
 *
 * @param status Http status
 * @return true if status is a redirect
 */
public static boolean isRedirect(int status) {
    return status == HttpStatus.SC_MOVED_PERMANENTLY
            || status == HttpStatus.SC_MOVED_TEMPORARILY
            || status == HttpStatus.SC_SEE_OTHER
            || status == HttpStatus.SC_TEMPORARY_REDIRECT;
}
 
Example 10
Source File: MCRDNBURNRestClient.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Updates all URLS to a given URN.
 * <br><br>
 * 204 No Content: URN was updated successfully<br>
 * 301 Moved Permanently: URN has a newer version<br>
 * 303 See other: URL is registered for another URN<br>
 *
 * @return the status code of the request
 */

private Optional<Date> update(MCRPIRegistrationInfo urn) {
    MCREpicurLite elp = epicurProvider.apply(urn);
    String elpXML = elp.asXMLString();
    String updateURL = getUpdateURL(urn);
    CloseableHttpResponse response = MCRHttpsClient.post(updateURL, APPLICATION_XML.toString(), elpXML);
    StatusLine statusLine = response.getStatusLine();

    if (statusLine == null) {
        LOGGER.warn("POST request for {} returns no status line.", updateURL);
        return Optional.empty();
    }

    int postStatus = statusLine.getStatusCode();

    String identifier = urn.getIdentifier();
    switch (postStatus) {
        case HttpStatus.SC_NO_CONTENT:
            LOGGER.info("URN {} updated to {}.", identifier, elp.getUrl());
            return Optional.ofNullable(response.getFirstHeader("Last-Modified"))
                .map(Header::getValue)
                .map(DateTimeFormatter.RFC_1123_DATE_TIME::parse)
                .map(Instant::from)
                .map(Date::from);
        case HttpStatus.SC_MOVED_PERMANENTLY:
            LOGGER.warn("URN {} has a newer version.", identifier);
            break;
        case HttpStatus.SC_SEE_OTHER:
            LOGGER.warn("URL {} is registered for another URN.", elp.getUrl());
            break;
        default:
            LOGGER.warn("URN {} could not be updated. Status {}.", identifier, postStatus);
            break;
    }

    return Optional.empty();
}
 
Example 11
Source File: HttpClientTools.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
private static boolean isRedirectStatus(int statusCode) {
  switch (statusCode) {
    case HttpStatus.SC_MOVED_PERMANENTLY:
    case HttpStatus.SC_MOVED_TEMPORARILY:
    case HttpStatus.SC_SEE_OTHER:
    case HttpStatus.SC_TEMPORARY_REDIRECT:
      return true;
    default:
      return false;
  }
}
 
Example 12
Source File: CustomRedirectStrategy.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean isRedirected(
        final HttpRequest request,
        final HttpResponse response,
        final HttpContext context) throws ProtocolException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }

    int statusCode = response.getStatusLine().getStatusCode();
    String method = request.getRequestLine().getMethod();
    Header locationHeader = response.getFirstHeader("location");
    switch (statusCode) {
    case HttpStatus.SC_MOVED_TEMPORARILY:
        return isRedirectable(method) && locationHeader != null;
    case HttpStatus.SC_MOVED_PERMANENTLY:
    case HttpStatus.SC_TEMPORARY_REDIRECT:
        return isRedirectable(method);
    case HttpStatus.SC_SEE_OTHER:
        return true;
    default:
        return false;
    } //end of switch
}
 
Example 13
Source File: MCRDNBURNRestClient.java    From mycore with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Registers a new URN.
 * <br><br>
 * 201 Created: URN-Record is successfully created.<br>
 * 303 See other: At least one of the given URLs is already registered under another URN,
 * which means you should use this existing URN instead of assigning a new one<br>
 * 409 Conflict: URN-Record already exists and can not be created again.<br>
 *
 * @return the status code of the request
 */
private Optional<Date> registerNew(MCRPIRegistrationInfo urn) {
    MCREpicurLite elp = epicurProvider.apply(urn);
    String elpXML = elp.asXMLString();
    String baseServiceURL = getBaseServiceURL(urn);
    CloseableHttpResponse response = MCRHttpsClient.put(baseServiceURL, APPLICATION_XML.toString(), elpXML);

    StatusLine statusLine = response.getStatusLine();

    if (statusLine == null) {
        LOGGER.warn("PUT request for {} returns no status line.", baseServiceURL);
        return Optional.empty();
    }

    int putStatus = statusLine.getStatusCode();

    String identifier = urn.getIdentifier();
    URL url = elp.getUrl();
    switch (putStatus) {
        case HttpStatus.SC_CREATED:
            LOGGER.info("URN {} registered to {}", identifier, url);
            return Optional.ofNullable(response.getFirstHeader("Last-Modified"))
                .map(Header::getValue)
                .map(DateTimeFormatter.RFC_1123_DATE_TIME::parse)
                .map(Instant::from)
                .map(Date::from);
        case HttpStatus.SC_SEE_OTHER:
            LOGGER.warn("At least one of the given URLs is already registered under another URN, "
                + "which means you should use this existing URN instead of assigning a new one.");
            LOGGER.warn("URN {} could NOT registered to {}.", identifier, url);
            break;
        case HttpStatus.SC_CONFLICT:
            LOGGER.warn("URN-Record already exists and can not be created again.");
            LOGGER.warn("URN {} could NOT registered to {}.", identifier, url);
            break;
        default:
            LOGGER.warn("Could not handle urnInfo request: status={}, urn={}, url={}.", putStatus, identifier, url);
            LOGGER.warn("Epicur Lite:");
            LOGGER.warn(elpXML);
            break;
    }

    return Optional.empty();
}
 
Example 14
Source File: ExceptionUtils.java    From flink-crawler with Apache License 2.0 4 votes vote down vote up
public static FetchStatus mapHttpStatusToFetchStatus(int httpStatus) {
    switch (httpStatus) {
        case HttpStatus.SC_OK:
            return FetchStatus.FETCHED;

        case HttpStatus.SC_FORBIDDEN:
            return FetchStatus.HTTP_FORBIDDEN;

        case HttpStatus.SC_UNAUTHORIZED:
        case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
            return FetchStatus.HTTP_UNAUTHORIZED;

        case HttpStatus.SC_NOT_FOUND:
            return FetchStatus.HTTP_NOT_FOUND;

        case HttpStatus.SC_GONE:
            return FetchStatus.HTTP_GONE;

        case HttpStatus.SC_TEMPORARY_REDIRECT:
        case HttpStatus.SC_MOVED_TEMPORARILY:
        case HttpStatus.SC_SEE_OTHER:
            return FetchStatus.HTTP_TOO_MANY_REDIRECTS;

        case HttpStatus.SC_MOVED_PERMANENTLY:
            return FetchStatus.HTTP_MOVED_PERMANENTLY;

        default:
            if (httpStatus < 300) {
                LOGGER.warn("Invalid HTTP status for exception: " + httpStatus);
                return FetchStatus.HTTP_SERVER_ERROR;
            } else if (httpStatus < 400) {
                return FetchStatus.HTTP_REDIRECTION_ERROR;
            } else if (httpStatus < 500) {
                return FetchStatus.HTTP_CLIENT_ERROR;
            } else if (httpStatus < 600) {
                return FetchStatus.HTTP_SERVER_ERROR;
            } else {
                LOGGER.warn("Unknown status: " + httpStatus);
                return FetchStatus.HTTP_SERVER_ERROR;
            }
    }
}
 
Example 15
Source File: HttpRequestHandler.java    From Asqatasun with GNU Affero General Public License v3.0 4 votes vote down vote up
private int computeStatus(int status) {
    switch (status) { 
        case HttpStatus.SC_FORBIDDEN:
        case HttpStatus.SC_METHOD_NOT_ALLOWED:
        case HttpStatus.SC_BAD_REQUEST:
        case HttpStatus.SC_UNAUTHORIZED:
        case HttpStatus.SC_PAYMENT_REQUIRED:
        case HttpStatus.SC_NOT_FOUND:
        case HttpStatus.SC_NOT_ACCEPTABLE:
        case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
        case HttpStatus.SC_REQUEST_TIMEOUT:
        case HttpStatus.SC_CONFLICT:
        case HttpStatus.SC_GONE:
        case HttpStatus.SC_LENGTH_REQUIRED:
        case HttpStatus.SC_PRECONDITION_FAILED:
        case HttpStatus.SC_REQUEST_TOO_LONG:
        case HttpStatus.SC_REQUEST_URI_TOO_LONG:
        case HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE:
        case HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE:
        case HttpStatus.SC_EXPECTATION_FAILED:
        case HttpStatus.SC_INSUFFICIENT_SPACE_ON_RESOURCE:
        case HttpStatus.SC_METHOD_FAILURE:
        case HttpStatus.SC_UNPROCESSABLE_ENTITY:
        case HttpStatus.SC_LOCKED:
        case HttpStatus.SC_FAILED_DEPENDENCY:
        case HttpStatus.SC_INTERNAL_SERVER_ERROR:
        case HttpStatus.SC_NOT_IMPLEMENTED:
        case HttpStatus.SC_BAD_GATEWAY:
        case HttpStatus.SC_SERVICE_UNAVAILABLE:
        case HttpStatus.SC_GATEWAY_TIMEOUT:
        case HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED:
        case HttpStatus.SC_INSUFFICIENT_STORAGE:
            return 0;
        case HttpStatus.SC_CONTINUE:
        case HttpStatus.SC_SWITCHING_PROTOCOLS:
        case HttpStatus.SC_PROCESSING:
        case HttpStatus.SC_OK:
        case HttpStatus.SC_CREATED:
        case HttpStatus.SC_ACCEPTED:
        case HttpStatus.SC_NON_AUTHORITATIVE_INFORMATION:
        case HttpStatus.SC_NO_CONTENT:
        case HttpStatus.SC_RESET_CONTENT:
        case HttpStatus.SC_PARTIAL_CONTENT:
        case HttpStatus.SC_MULTI_STATUS:
        case HttpStatus.SC_MULTIPLE_CHOICES:
        case HttpStatus.SC_MOVED_PERMANENTLY:
        case HttpStatus.SC_MOVED_TEMPORARILY:
        case HttpStatus.SC_SEE_OTHER:
        case HttpStatus.SC_NOT_MODIFIED:
        case HttpStatus.SC_USE_PROXY:
        case HttpStatus.SC_TEMPORARY_REDIRECT:
            return 1;
        default : 
            return 1;
    }
}