List of usage examples for org.apache.commons.httpclient HttpStatus SC_FORBIDDEN
int SC_FORBIDDEN
To view the source code for org.apache.commons.httpclient HttpStatus SC_FORBIDDEN.
Click Source Link
From source file:com.discogs.api.webservice.impl.HttpClientWebService.java
@Override public Resp doGet(String url) throws WebServiceException { HttpMethod method = new GZipCapableGetMethod(url); method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); method.setDoAuthentication(true);//ww w .ja v a 2 s .co m try { // execute the method int statusCode = this.httpClient.executeMethod(method); if (logger.isDebugEnabled()) { logger.debug(method.getResponseBodyAsString()); } switch (statusCode) { case HttpStatus.SC_OK: return createResp(method.getResponseBodyAsStream()); case HttpStatus.SC_NOT_FOUND: throw new ResourceNotFoundException("Resource not found.", method.getResponseBodyAsString()); case HttpStatus.SC_BAD_REQUEST: throw new RequestException(method.getResponseBodyAsString()); case HttpStatus.SC_FORBIDDEN: throw new AuthorizationException(method.getResponseBodyAsString()); case HttpStatus.SC_UNAUTHORIZED: throw new AuthorizationException(method.getResponseBodyAsString()); default: String em = "web service returned unknown status '" + statusCode + "', response was: " + method.getResponseBodyAsString(); logger.error(em); throw new WebServiceException(em); } } catch (HttpException e) { logger.error("Fatal protocol violation: " + e.getMessage()); throw new WebServiceException(e.getMessage(), e); } catch (IOException e) { logger.error("Fatal transport error: " + e.getMessage()); throw new WebServiceException(e.getMessage(), e); } finally { method.releaseConnection(); } }
From source file:edu.unc.lib.dl.ui.controller.DjatokaContentController.java
/** * Handles requests for jp2 metadata//ww w .j av a 2 s . co m * * @param model * @param request * @param response */ @RequestMapping("/jp2Metadata/{id}/{datastream}") public void getMetadata(@PathVariable("id") String id, @PathVariable("datastream") String datastream, HttpServletResponse response) { // Check if the user is allowed to view this object if (this.hasAccess(id, datastream)) { try { djatokaContentService.getMetadata(id, datastream, response.getOutputStream(), response); } catch (IOException e) { LOG.error("Error retrieving JP2 metadata content for " + id, e); } } else { LOG.debug("Access was forbidden to " + id + " for user " + GroupsThreadStore.getUsername()); response.setStatus(HttpStatus.SC_FORBIDDEN); } }
From source file:com.owncloud.android.operations.RemoveRemoteEncryptedFileOperation.java
/** * Performs the remove operation./*from w w w.jav a 2 s . c o m*/ */ @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result; DeleteMethod delete = null; String token = null; DecryptedFolderMetadata metadata; String privateKey = arbitraryDataProvider.getValue(account.name, EncryptionUtils.PRIVATE_KEY); // unlock try { // Lock folder LockFileOperation lockFileOperation = new LockFileOperation(parentId); RemoteOperationResult lockFileOperationResult = lockFileOperation.execute(client, true); if (lockFileOperationResult.isSuccess()) { token = (String) lockFileOperationResult.getData().get(0); } else if (lockFileOperationResult.getHttpCode() == HttpStatus.SC_FORBIDDEN) { throw new RemoteOperationFailedException("Forbidden! Please try again later.)"); } else { throw new RemoteOperationFailedException("Unknown error!"); } // refresh metadata GetMetadataOperation getMetadataOperation = new GetMetadataOperation(parentId); RemoteOperationResult getMetadataOperationResult = getMetadataOperation.execute(client, true); if (getMetadataOperationResult.isSuccess()) { // decrypt metadata String serializedEncryptedMetadata = (String) getMetadataOperationResult.getData().get(0); EncryptedFolderMetadata encryptedFolderMetadata = EncryptionUtils .deserializeJSON(serializedEncryptedMetadata, new TypeToken<EncryptedFolderMetadata>() { }); metadata = EncryptionUtils.decryptFolderMetaData(encryptedFolderMetadata, privateKey); } else { throw new RemoteOperationFailedException("No Metadata found!"); } // delete file remote delete = new DeleteMethod(client.getWebdavUri() + WebdavUtils.encodePath(remotePath)); int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT); delete.getResponseBodyAsString(); // exhaust the response, although not interesting result = new RemoteOperationResult(delete.succeeded() || status == HttpStatus.SC_NOT_FOUND, delete); Log_OC.i(TAG, "Remove " + remotePath + ": " + result.getLogMessage()); // remove file from metadata metadata.getFiles().remove(fileName); EncryptedFolderMetadata encryptedFolderMetadata = EncryptionUtils.encryptFolderMetadata(metadata, privateKey); String serializedFolderMetadata = EncryptionUtils.serializeJSON(encryptedFolderMetadata); // upload metadata UpdateMetadataOperation storeMetadataOperation = new UpdateMetadataOperation(parentId, serializedFolderMetadata, token); RemoteOperationResult uploadMetadataOperationResult = storeMetadataOperation.execute(client, true); if (!uploadMetadataOperationResult.isSuccess()) { throw new RemoteOperationFailedException("Metadata not uploaded!"); } // return success return result; } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Remove " + remotePath + ": " + result.getLogMessage(), e); } finally { if (delete != null) { delete.releaseConnection(); } // unlock file if (token != null) { UnlockFileOperation unlockFileOperation = new UnlockFileOperation(parentId, token); RemoteOperationResult unlockFileOperationResult = unlockFileOperation.execute(client, true); if (!unlockFileOperationResult.isSuccess()) { Log_OC.e(TAG, "Failed to unlock " + parentId); } } } return result; }
From source file:com.kagilum.intellij.icescrum.IceScrumRepository.java
private void checkServerStatus(int code) throws IOException { switch (code) { case HttpStatus.SC_SERVICE_UNAVAILABLE: throw new IOException("Web services aren't activated on your project..."); case HttpStatus.SC_UNAUTHORIZED: throw new IOException("Wrong login/pass..."); case HttpStatus.SC_FORBIDDEN: throw new IOException("You haven't access to this project..."); case HttpStatus.SC_NOT_FOUND: throw new IOException("No project or iceScrum server found..."); default://from www . j a v a 2 s . c om throw new IOException("Server error (" + HttpStatus.getStatusText(code) + ")"); } }
From source file:edu.unc.lib.dl.ui.controller.DjatokaContentController.java
/** * Handles requests for individual region tiles. * //from w ww . ja va 2 s .co m * @param model * @param request * @param response */ @RequestMapping("/jp2Region/{id}/{datastream}") public void getRegion(@PathVariable("id") String id, @PathVariable("datastream") String datastream, @RequestParam("svc.region") String region, @RequestParam("svc.level") String scale, @RequestParam("svc.rotate") String rotate, HttpServletResponse response) { // Check if the user is allowed to view this object if (this.hasAccess(id, datastream)) { try { djatokaContentService.streamJP2(id, region, scale, rotate, datastream, response.getOutputStream(), response); } catch (IOException e) { LOG.error("Error retrieving streaming JP2 content for " + id, e); } } else { LOG.debug("Access was forbidden to " + id + " for user " + GroupsThreadStore.getUsername()); response.setStatus(HttpStatus.SC_FORBIDDEN); } }
From source file:com.eucalyptus.blockstorage.StorageReplyQueue.java
public void handle(ExceptionMessage muleMsg) { try {// w w w. ja v a 2 s .com Object requestMsg = muleMsg.getPayload(); String requestString = requestMsg.toString(); BaseMessage msg = (BaseMessage) BindingManager.getDefaultBinding().fromOM(requestString); Throwable ex = muleMsg.getException().getCause(); StorageErrorMessageType errMsg = null; if (ex instanceof NoSuchVolumeException) { errMsg = new StorageErrorMessageType("NoSuchVolume", "Volume not found", HttpStatus.SC_NOT_FOUND, msg.getCorrelationId()); errMsg.setCorrelationId(msg.getCorrelationId()); } else if (ex instanceof VolumeInUseException) { errMsg = new StorageErrorMessageType("VolumeInUse", "Volume in use", HttpStatus.SC_FORBIDDEN, msg.getCorrelationId()); errMsg.setCorrelationId(msg.getCorrelationId()); } else if (ex instanceof NoSuchSnapshotException) { errMsg = new StorageErrorMessageType("NoSuchSnapshot", "Snapshot not found", HttpStatus.SC_NOT_FOUND, msg.getCorrelationId()); errMsg.setCorrelationId(msg.getCorrelationId()); } else if (ex instanceof VolumeAlreadyExistsException) { errMsg = new StorageErrorMessageType("VolumeAlreadyExists", "Volume already exists", HttpStatus.SC_CONFLICT, msg.getCorrelationId()); errMsg.setCorrelationId(msg.getCorrelationId()); } else if (ex instanceof VolumeNotReadyException) { errMsg = new StorageErrorMessageType("VolumeNotReady", "Volume not ready yet", HttpStatus.SC_CONFLICT, msg.getCorrelationId()); errMsg.setCorrelationId(msg.getCorrelationId()); } else if (ex instanceof SnapshotInUseException) { errMsg = new StorageErrorMessageType("SnapshotInUse", "Snapshot in use", HttpStatus.SC_CONFLICT, msg.getCorrelationId()); errMsg.setCorrelationId(msg.getCorrelationId()); } else { replies.putMessage( new EucalyptusErrorMessageType(muleMsg.getComponentName(), msg, ex.getMessage())); } if (errMsg != null) { replies.putMessage(errMsg); } } catch (Exception e) { LOG.error(e); } }
From source file:edu.ucsb.eucalyptus.ic.StorageReplyQueue.java
public void handle(ExceptionMessage muleMsg) { try {//from ww w .ja v a 2 s . com Object requestMsg = muleMsg.getPayload(); String requestString = requestMsg.toString(); BaseMessage msg = (BaseMessage) BindingManager.getBinding("msgs_eucalyptus_com").fromOM(requestString); Throwable ex = muleMsg.getException().getCause(); StorageErrorMessageType errMsg = null; if (ex instanceof NoSuchVolumeException) { errMsg = new StorageErrorMessageType("NoSuchVolume", "Volume not found", HttpStatus.SC_NOT_FOUND, msg.getCorrelationId()); errMsg.setCorrelationId(msg.getCorrelationId()); } else if (ex instanceof VolumeInUseException) { errMsg = new StorageErrorMessageType("VolumeInUse", "Volume in use", HttpStatus.SC_FORBIDDEN, msg.getCorrelationId()); errMsg.setCorrelationId(msg.getCorrelationId()); } else if (ex instanceof NoSuchSnapshotException) { errMsg = new StorageErrorMessageType("NoSuchSnapshot", "Snapshot not found", HttpStatus.SC_NOT_FOUND, msg.getCorrelationId()); errMsg.setCorrelationId(msg.getCorrelationId()); } else if (ex instanceof VolumeAlreadyExistsException) { errMsg = new StorageErrorMessageType("VolumeAlreadyExists", "Volume already exists", HttpStatus.SC_CONFLICT, msg.getCorrelationId()); errMsg.setCorrelationId(msg.getCorrelationId()); } else if (ex instanceof VolumeNotReadyException) { errMsg = new StorageErrorMessageType("VolumeNotReady", "Volume not ready yet", HttpStatus.SC_CONFLICT, msg.getCorrelationId()); errMsg.setCorrelationId(msg.getCorrelationId()); } else if (ex instanceof SnapshotInUseException) { errMsg = new StorageErrorMessageType("SnapshotInUse", "Snapshot in use", HttpStatus.SC_CONFLICT, msg.getCorrelationId()); errMsg.setCorrelationId(msg.getCorrelationId()); } else { replies.putMessage( new EucalyptusErrorMessageType(muleMsg.getComponentName(), msg, ex.getMessage())); } if (errMsg != null) { replies.putMessage(errMsg); } } catch (Exception e) { LOG.error(e); } }
From source file:com.cerema.cloud2.lib.common.operations.RemoteOperationResult.java
private RemoteOperationResult(boolean success, int httpCode) { mSuccess = success;//w w w.j a v a2 s .c o m mHttpCode = httpCode; if (success) { mCode = ResultCode.OK; } else if (httpCode > 0) { switch (httpCode) { case HttpStatus.SC_UNAUTHORIZED: mCode = ResultCode.UNAUTHORIZED; break; case HttpStatus.SC_NOT_FOUND: mCode = ResultCode.FILE_NOT_FOUND; break; case HttpStatus.SC_INTERNAL_SERVER_ERROR: mCode = ResultCode.INSTANCE_NOT_CONFIGURED; break; case HttpStatus.SC_CONFLICT: mCode = ResultCode.CONFLICT; break; case HttpStatus.SC_INSUFFICIENT_STORAGE: mCode = ResultCode.QUOTA_EXCEEDED; break; case HttpStatus.SC_FORBIDDEN: mCode = ResultCode.FORBIDDEN; break; default: mCode = ResultCode.UNHANDLED_HTTP_CODE; Log_OC.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + httpCode); } } }
From source file:ch.ksfx.web.services.spidering.http.HttpClientHelper.java
private HttpMethod executeMethod(HttpMethod httpMethod) { for (Header header : this.headers.getHeaders()) { httpMethod.setRequestHeader(header); }/*from ww w . ja v a 2 s. c om*/ httpMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new KsfxHttpRetryHandler(retryCount, retryDelay)); try { int tryCount = 0; int statusCode; do { if (tryCount > 1) { httpMethod = createNewHttpMethod(httpMethod); try { if (retryDelay == 0) { retryDelay = DEFAULT_RETRY_DELAY; } Thread.sleep(retryDelay); } catch (InterruptedException e) { logger.severe("InterruptedException"); } } //PROXY Configuration /* if (torify) { String proxyHost = ""; Integer proxyPort = 0; try { proxyHost = SpiderConfiguration.getConfiguration().getString("torifyHost"); proxyPort = SpiderConfiguration.getConfiguration().getInt("torifyPort"); } catch (Exception e) { logger.severe("Cannot get Proxy information"); } this.httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort); } */ statusCode = this.httpClient.executeMethod(httpMethod); tryCount++; } while (!(statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_FORBIDDEN || statusCode == HttpStatus.SC_NOT_FOUND) && tryCount < retryCount); if (statusCode != HttpStatus.SC_OK) { System.out.println("HTTP method failed: " + httpMethod.getStatusLine() + " - " + httpMethod.getURI().toString()); } } catch (HttpException e) { e.printStackTrace(); httpMethod.abort(); try { logger.log(Level.SEVERE, "Redirrex " + e.getClass(), e); if (e.getClass().equals(RedirectException.class)) { logger.log(Level.SEVERE, "Is real redirect exception", e); throw new RuntimeException("HttpRedirectException"); } logger.log(Level.SEVERE, "HTTP protocol error for URL: " + httpMethod.getURI().toString(), e); } catch (URIException e1) { e.printStackTrace(); logger.log(Level.SEVERE, "URI exception", e); } throw new RuntimeException("HttpException"); } catch (IOException e) { try { e.printStackTrace(); logger.log(Level.SEVERE, "HTTP transport error for URL: " + httpMethod.getURI().toString(), e); } catch (URIException e1) { e.printStackTrace(); logger.log(Level.SEVERE, "URI exception", e); } throw new RuntimeException("IOException"); } return httpMethod; }
From source file:com.kagilum.plugins.icescrum.IceScrumSession.java
private void checkServerStatus(int code) throws IOException { switch (code) { case HttpStatus.SC_SERVICE_UNAVAILABLE: throw new IOException(Messages.IceScrumSession_icescrum_http_unavailable()); case HttpStatus.SC_UNAUTHORIZED: throw new IOException(Messages.IceScrumSession_icescrum_http_unauthorized()); case HttpStatus.SC_FORBIDDEN: throw new IOException(Messages.IceScrumSession_icescrum_http_forbidden()); case HttpStatus.SC_NOT_FOUND: throw new IOException(Messages.IceScrumSession_icescrum_http_notfound()); default:/*from ww w . ja va 2 s. c o m*/ throw new IOException( Messages.IceScrumSession_icescrum_http_error() + " (" + HttpStatus.getStatusText(code) + ")"); } }