List of usage examples for org.apache.commons.httpclient HttpStatus SC_MULTIPLE_CHOICES
int SC_MULTIPLE_CHOICES
To view the source code for org.apache.commons.httpclient HttpStatus SC_MULTIPLE_CHOICES.
Click Source Link
From source file:ch.cyberduck.core.dav.DAVResource.java
/** * Check if the http status code passed as argument is a success * * @param statusCode/* w w w . jav a 2s.c om*/ * @return true if code represents a HTTP success */ private boolean isHttpSuccess(int statusCode) { return (statusCode >= HttpStatus.SC_OK && statusCode < HttpStatus.SC_MULTIPLE_CHOICES); }
From source file:edu.psu.iam.cpr.core.util.Utility.java
/** * This method is used to convert an CPR status code to an analogous HTTP status code. * * @param statusCode contains the CPR status code. * @return will return the HTTP status code. *///w w w .j av a2 s. c o m public static int convertCprReturnToHttpStatus(final int statusCode) { final ReturnType returnType = ReturnType.get(statusCode); int httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; switch (returnType) { case SUCCESS: httpStatus = HttpStatus.SC_OK; break; case ADD_FAILED_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case ALREADY_DELETED_EXCEPTION: httpStatus = HttpStatus.SC_BAD_REQUEST; break; case RECORD_NOT_FOUND_EXCEPTION: httpStatus = HttpStatus.SC_NOT_FOUND; break; case ARCHIVE_FAILED_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case NOT_SPECIFIED_EXCEPTION: httpStatus = HttpStatus.SC_BAD_REQUEST; break; case TYPE_NOT_FOUND_EXCEPTION: httpStatus = HttpStatus.SC_BAD_REQUEST; break; case INVALID_PARAMETERS_EXCEPTION: httpStatus = HttpStatus.SC_BAD_REQUEST; break; case YN_PARAMETERS_EXCEPTION: httpStatus = HttpStatus.SC_BAD_REQUEST; break; case GENERAL_EXCEPTION: httpStatus = HttpStatus.SC_BAD_REQUEST; break; case PARAMETER_LENGTH_EXCEPTION: httpStatus = HttpStatus.SC_BAD_REQUEST; break; case MESSAGE_CREATION_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case MESSAGE_INITIALIZATION_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case MESSAGE_SEND_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case NOT_AUTHORIZED_EXCEPTION: httpStatus = HttpStatus.SC_UNAUTHORIZED; break; case PERSON_NOT_ACTIVE_EXCEPTION: httpStatus = HttpStatus.SC_BAD_REQUEST; break; case PERSON_NOT_FOUND_EXCEPTION: httpStatus = HttpStatus.SC_NOT_FOUND; break; case PSUID_NOT_FOUND_EXCEPTION: httpStatus = HttpStatus.SC_NOT_FOUND; break; case SERVICE_AUTHENTICATION_EXCEPTION: httpStatus = HttpStatus.SC_UNAUTHORIZED; break; case SET_PRIMARY_FAILED_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case UPDATE_FAILED_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case WEB_SERVICE_NOT_FOUND_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case GI_FAILURE: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case DB_CONNECTION_FAILURE: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case GENERAL_DATABASE_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case UNARCHIVE_FAILED_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case DATA_CHANGE_EXCEPTION: httpStatus = HttpStatus.SC_UNAUTHORIZED; break; case SECURITY_OPERATION_EXCEPTION: httpStatus = HttpStatus.SC_UNAUTHORIZED; break; case AFFILIATION_USE_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case IAP_USE_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case RECORD_ALREADY_EXISTS: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case EXACT_MATCH_EXCEPTION: httpStatus = HttpStatus.SC_MULTIPLE_CHOICES; break; case NEAR_MATCH_EXCEPTION: httpStatus = HttpStatus.SC_MULTIPLE_CHOICES; break; case MESSAGE_RECEIVE_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case DIRECTORY_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case JSON_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case JMS_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case NOT_IMPLEMENTED_EXCEPTION: httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; default: break; } return httpStatus; }
From source file:org.opens.tanaguru.util.http.HttpRequestHandler.java
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:/*from ww w. j av a 2 s.c o m*/ return 1; } }
From source file:org.sonatype.nexus.proxy.storage.remote.commonshttpclient.CommonsHttpClientRemoteStorage.java
@Override protected boolean checkRemoteAvailability(long newerThen, ProxyRepository repository, ResourceStoreRequest request, boolean isStrict) throws RemoteStorageException { URL remoteURL = getAbsoluteUrlFromBase(repository, request); HttpMethodBase method = new HeadMethod(remoteURL.toString()); int response = HttpStatus.SC_BAD_REQUEST; // artifactory hack, it pukes on HEAD so we will try with GET if HEAD fails boolean doGet = false; try {//from w w w . j av a2 s . c om response = executeMethod(repository, request, method, remoteURL); } catch (RemoteStorageException e) { // If HEAD failed, attempt a GET. Some repos may not support HEAD method doGet = true; getLogger().debug("HEAD method failed, will attempt GET. Exception: " + e.getMessage(), e); } finally { method.releaseConnection(); // HEAD returned error, but not exception, try GET before failing if (!doGet && response != HttpStatus.SC_OK) { doGet = true; getLogger().debug("HEAD method failed, will attempt GET. Status: " + response); } } if (doGet) { // create a GET method = new GetMethod(remoteURL.toString()); try { // execute it response = executeMethod(repository, request, method, remoteURL); } finally { // and release it immediately method.releaseConnection(); } } // if we are not strict and remote is S3 if (!isStrict && isRemotePeerAmazonS3Storage(repository)) { // if we are relaxed, we will accept any HTTP response code below 500. This means anyway the HTTP // transaction succeeded. This method was never really detecting that the remoteUrl really denotes a root of // repository (how could we do that?) // this "relaxed" check will help us to "pass" S3 remote storage. return response >= HttpStatus.SC_OK && response <= HttpStatus.SC_INTERNAL_SERVER_ERROR; } else { // non relaxed check is strict, and will select only the OK response if (response == HttpStatus.SC_OK) { // we have it // we have newer if this below is true return makeDateFromHeader(method.getResponseHeader("last-modified")) > newerThen; } else if ((response >= HttpStatus.SC_MULTIPLE_CHOICES && response < HttpStatus.SC_BAD_REQUEST) || response == HttpStatus.SC_NOT_FOUND) { return false; } else { throw new RemoteStorageException("Unexpected response code while executing " + method.getName() + " method [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\"" + remoteURL.toString() + "\"]. Expected: \"SUCCESS (200)\". Received: " + response + " : " + HttpStatus.getStatusText(response)); } } }
From source file:org.wso2.appfactory.dynamicslave.JenkinsClient.java
public String get(String path, Map<String, String> query) { GetMethod getMethod = createGetMethod(path, getNameValuePairFromMap(query)); int statusCode; String response = null;//from w w w. ja v a 2s . co m try { httpClient.executeMethod(getMethod); } catch (IOException e) { LOGGER.info("Invocation failed for " + getMethod.getPath()); return null; } finally { getMethod.releaseConnection(); } try { statusCode = getMethod.getStatusCode(); if (statusCode < HttpStatus.SC_OK || statusCode >= HttpStatus.SC_MULTIPLE_CHOICES) { LOGGER.info("Invocation returned " + statusCode + " for " + getMethod.getPath()); } else { response = getMethod.getResponseBodyAsString(); LOGGER.info("Sent get successfully " + getMethod.getPath()); } } catch (IOException e) { LOGGER.info("Error while getting the response " + getMethod.getPath()); return null; } return response; }
From source file:org.wso2.appfactory.dynamicslave.JenkinsClient.java
public String post(String path) { PostMethod postMethod = createPost(path, null, null, null); int statusCode = 0; String response = null;/*from w ww .j a va 2s. c om*/ try { statusCode = httpClient.executeMethod(postMethod); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Error while calling the backed for " + postMethod.getPath(), e); return null; } try { if (statusCode != HttpStatus.SC_MOVED_TEMPORARILY && (statusCode < HttpStatus.SC_OK || statusCode >= HttpStatus.SC_MULTIPLE_CHOICES)) { LOGGER.info("Invocation returned " + statusCode + " for " + postMethod.getPath()); return null; } else { response = postMethod.getResponseBodyAsString(); LOGGER.info("Sent post successfully " + postMethod.getPath()); } } catch (IOException e) { LOGGER.log(Level.SEVERE, "Error while getting the response for " + postMethod.getPath(), e); return null; } finally { postMethod.releaseConnection(); } return response; }
From source file:org.wso2.appfactory.dynamicslave.JenkinsClient.java
public String post_xml(String path, String xml, Map<String, String> params) { PostMethod postMethod = null;/* w w w . j a v a2 s.c o m*/ int statusCode = 0; String response = null; NameValuePair[] nameValuePairs = getNameValuePairFromMap(params); StringRequestEntity stringRequestEntity = null; try { stringRequestEntity = xml != null ? new StringRequestEntity(xml, "text/xml", "utf-8") : null; } catch (UnsupportedEncodingException e) { LOGGER.log(Level.SEVERE, "Error while getting the request parameters for " + postMethod.getPath(), e); return null; } postMethod = createPost(path, nameValuePairs, stringRequestEntity, null); try { statusCode = httpClient.executeMethod(postMethod); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Error while calling the backed for " + postMethod.getPath(), e); return null; } try { if (statusCode != HttpStatus.SC_MOVED_TEMPORARILY && (statusCode < HttpStatus.SC_OK || statusCode >= HttpStatus.SC_MULTIPLE_CHOICES)) { LOGGER.info("Invocation returned " + statusCode + " for " + postMethod.getPath()); return null; } else { response = postMethod.getResponseBodyAsString(); LOGGER.info("Sent post successfully " + postMethod.getPath()); } } catch (IOException e) { LOGGER.log(Level.SEVERE, "Error while getting the response for " + postMethod.getPath(), e); return null; } finally { postMethod.releaseConnection(); } return response; }
From source file:pl.nask.hsn2.service.task.WebClientObjectTreeNode.java
private void processSingleResource(EmbeddedResource resource) { boolean requestFailed = resource.isRequestFailed(); if (!requestFailed) { String failureReason = resource.getFailureMessage(); String url = resource.getAbsoluteUrl(); WebResponse webResponse = null;//from w ww .j a v a 2s . com try { Page page = webClientWorker.getInsecurePage(url); webResponse = page.getWebResponse(); int serverRespStatus = webResponse.getStatusCode(); int resourceRedirLimit = contextHeight(); while (resourceRedirLimit++ < params.getRedirectDepthLimit() && serverRespStatus >= HttpStatus.SC_MULTIPLE_CHOICES && serverRespStatus < HttpStatus.SC_BAD_REQUEST) { String redirect = webResponse.getResponseHeaderValue("Location"); String newUrl = UrlUtils.resolveUrl(url, redirect); LOGGER.debug("Resource '{}' redirected to: {}", url, newUrl); page = webClientWorker.getInsecurePage(newUrl); webResponse = page.getWebResponse(); serverRespStatus = webResponse.getStatusCode(); } // Status message can be used as a failure message. failureReason = webResponse.getStatusMessage(); } catch (ConnectTimeoutException e) { // Set proper message and log it. failureReason = getReasonAndLogWarn(e, "Connection timeout for URL: " + url); requestFailed = true; } catch (SocketTimeoutException e) { // Set proper message and log it. failureReason = getReasonAndLogWarn(e, "Socket timeout for URL: " + url); requestFailed = true; } catch (UnknownHostException e) { // Set proper message and log it. failureReason = getReasonAndLogWarn(e, "Unknown host for URL: url"); requestFailed = true; } catch (ClientProtocolException e) { // Set proper message and log it. failureReason = getReasonAndLogError(e, "Unsupported protocol. Probably not a resource: " + url); requestFailed = true; } catch (IOException e) { // Set proper message and log it. failureReason = getReasonAndLogError(e, "IOException for URL: " + url); requestFailed = true; } catch (Exception e) { // Set proper message and log it. failureReason = getReasonAndLogError(e, "Exception for URL: " + url); requestFailed = true; } finally { webClientWorker.closeAllWindows(); LOGGER.debug("Trying to close all windows for url: {}", url); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Updating resource:{},[{},{},{}]", new Object[] { resource.getAbsoluteUrl(), webResponse != null ? webResponse.getContentType() : "no response", failureReason, requestFailed }); } resource.update(webResponse, failureReason, requestFailed); } }
From source file:pl.nask.hsn2.service.urlfollower.ProcessedPage.java
private void checkServerSideRedirect() { if (responseCode >= HttpStatus.SC_MULTIPLE_CHOICES && responseCode <= HttpStatus.SC_TEMPORARY_REDIRECT && responseCode != HttpStatus.SC_NOT_MODIFIED) { // At this point response code is 300, 301, 302, 303, 305, 306 or 307 (but no 304). serverSideRedirectLocation = page.getWebResponse().getResponseHeaderValue("Location"); // Server side redirection could be relative, so we have to make sure it is set correctly. URL requestUrl = page.getUrl(); if (serverSideRedirectLocation == null || serverSideRedirectLocation.isEmpty()) { // It could happen location header is empty. This is not valid redirect. serverSideRedirectLocation = null; } else if (!(serverSideRedirectLocation.startsWith("http://") && serverSideRedirectLocation.startsWith("https://"))) { // It could happen location header is relative. This is not valid redirect but web // browsers seem to follow it, so WebClient do. serverSideRedirectLocation = UrlUtils.resolveUrl(requestUrl, serverSideRedirectLocation); }/*from w w w.ja v a 2s . co m*/ } }
From source file:pl.nask.hsn2.service.urlfollower.WebWindowListenerImpl.java
private boolean isServerRedirect(Page page) { int responseCode = page.getWebResponse().getStatusCode(); // returns 300, 301, 302, 303, 305, 306 or 307 (but no 304). return responseCode >= HttpStatus.SC_MULTIPLE_CHOICES && responseCode <= HttpStatus.SC_TEMPORARY_REDIRECT && responseCode != HttpStatus.SC_NOT_MODIFIED; }