List of usage examples for org.apache.commons.httpclient HttpStatus SC_ACCEPTED
int SC_ACCEPTED
To view the source code for org.apache.commons.httpclient HttpStatus SC_ACCEPTED.
Click Source Link
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 w w w. jav a2s .co m return 1; } }
From source file:org.purl.sword.client.Client.java
/** * Post a file to the server. The different elements of the post are encoded * in the specified message.//from w w w . ja v a 2 s . c om * * @param message * The message that contains the post information. * * @throws SWORDClientException * if there is an error during the post operation. */ public DepositResponse postFile(PostMessage message) throws SWORDClientException { if (message == null) { throw new SWORDClientException("Message cannot be null."); } PostMethod httppost = new PostMethod(message.getDestination()); if (doAuthentication) { setBasicCredentials(username, password); httppost.setDoAuthentication(true); } DepositResponse response = null; String messageBody = ""; try { if (message.isUseMD5()) { String md5 = ChecksumUtils.generateMD5(message.getFilepath()); if (message.getChecksumError()) { md5 = "1234567890"; } log.debug("checksum error is: " + md5); if (md5 != null) { httppost.addRequestHeader(new Header(HttpHeaders.CONTENT_MD5, md5)); } } String filename = message.getFilename(); if (!"".equals(filename)) { httppost.addRequestHeader(new Header(HttpHeaders.CONTENT_DISPOSITION, " filename=" + filename)); } if (containsValue(message.getSlug())) { httppost.addRequestHeader(new Header(HttpHeaders.SLUG, message.getSlug())); } if (message.getCorruptRequest()) { // insert a header with an invalid boolean value httppost.addRequestHeader(new Header(HttpHeaders.X_NO_OP, "Wibble")); } else { httppost.addRequestHeader(new Header(HttpHeaders.X_NO_OP, Boolean.toString(message.isNoOp()))); } httppost.addRequestHeader(new Header(HttpHeaders.X_VERBOSE, Boolean.toString(message.isVerbose()))); String packaging = message.getPackaging(); if (packaging != null && packaging.length() > 0) { httppost.addRequestHeader(new Header(HttpHeaders.X_PACKAGING, packaging)); } String onBehalfOf = message.getOnBehalfOf(); if (containsValue(onBehalfOf)) { httppost.addRequestHeader(new Header(HttpHeaders.X_ON_BEHALF_OF, onBehalfOf)); } String userAgent = message.getUserAgent(); if (containsValue(userAgent)) { httppost.addRequestHeader(new Header(HttpHeaders.USER_AGENT, userAgent)); } FileRequestEntity requestEntity = new FileRequestEntity(new File(message.getFilepath()), message.getFiletype()); httppost.setRequestEntity(requestEntity); client.executeMethod(httppost); status = new Status(httppost.getStatusCode(), httppost.getStatusText()); log.info("Checking the status code: " + status.getCode()); if (status.getCode() == HttpStatus.SC_ACCEPTED || status.getCode() == HttpStatus.SC_CREATED) { messageBody = readResponse(httppost.getResponseBodyAsStream()); response = new DepositResponse(status.getCode()); response.setLocation(httppost.getResponseHeader("Location").getValue()); // added call for the status code. lastUnmarshallInfo = response.unmarshall(messageBody, new Properties()); } else { messageBody = readResponse(httppost.getResponseBodyAsStream()); response = new DepositResponse(status.getCode()); response.unmarshallErrorDocument(messageBody); } return response; } catch (NoSuchAlgorithmException nex) { throw new SWORDClientException("Unable to use MD5. " + nex.getMessage(), nex); } catch (HttpException ex) { throw new SWORDClientException(ex.getMessage(), ex); } catch (IOException ioex) { throw new SWORDClientException(ioex.getMessage(), ioex); } catch (UnmarshallException uex) { throw new SWORDClientException(uex.getMessage() + "(<pre>" + messageBody + "</pre>)", uex); } finally { httppost.releaseConnection(); } }
From source file:org.sonatype.nexus.proxy.storage.remote.commonshttpclient.CommonsHttpClientRemoteStorage.java
@Override public void storeItem(ProxyRepository repository, StorageItem item) throws UnsupportedStorageOperationException, RemoteStorageException { if (!(item instanceof StorageFileItem)) { throw new UnsupportedStorageOperationException("Storing of non-files remotely is not supported!"); }//www .j a v a2 s . c o m StorageFileItem fItem = (StorageFileItem) item; ResourceStoreRequest request = new ResourceStoreRequest(item); URL remoteURL = getAbsoluteUrlFromBase(repository, request); PutMethod method = new PutMethod(remoteURL.toString()); try { method.setRequestEntity( new InputStreamRequestEntity(fItem.getInputStream(), fItem.getLength(), fItem.getMimeType())); int response = executeMethod(repository, request, method, remoteURL); if (response != HttpStatus.SC_OK && response != HttpStatus.SC_CREATED && response != HttpStatus.SC_NO_CONTENT && response != HttpStatus.SC_ACCEPTED) { throw new RemoteStorageException("Unexpected response code while executing " + method.getName() + " method [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\"" + remoteURL.toString() + "\"]. Expected: \"any success (2xx)\". Received: " + response + " : " + HttpStatus.getStatusText(response)); } } catch (IOException e) { throw new RemoteStorageException( e.getMessage() + " [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\"" + remoteURL.toString() + "\"]", e); } finally { method.releaseConnection(); } }
From source file:org.sonatype.nexus.proxy.storage.remote.commonshttpclient.CommonsHttpClientRemoteStorage.java
@Override public void deleteItem(ProxyRepository repository, ResourceStoreRequest request) throws ItemNotFoundException, UnsupportedStorageOperationException, RemoteStorageException { URL remoteURL = getAbsoluteUrlFromBase(repository, request); DeleteMethod method = new DeleteMethod(remoteURL.toString()); try {//from w w w.j a v a 2 s.c o m int response = executeMethod(repository, request, method, remoteURL); if (response != HttpStatus.SC_OK && response != HttpStatus.SC_NO_CONTENT && response != HttpStatus.SC_ACCEPTED) { throw new RemoteStorageException("The response to HTTP " + method.getName() + " was unexpected HTTP Code " + response + " : " + HttpStatus.getStatusText(response) + " [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\"" + remoteURL.toString() + "\"]"); } } finally { method.releaseConnection(); } }
From source file:org.wso2.carbon.appfactory.s4.integration.StratosRestClient.java
public void deployApplication(String applicationId) throws AppFactoryException { ServerResponse response = MutualAuthHttpClient.sendPostRequest("", stratosManagerURL + APPLICATIONS_REST_END_POINT + "/" + applicationId + "/deploy/" + SINGLE_TENANT_APPLICATION_POLICY_ID, username);//from w w w . j a v a 2 s .co m if (response.getStatusCode() == HttpStatus.SC_ACCEPTED) { if (log.isDebugEnabled()) { log.debug(" Stratos application deployed for appId : " + applicationId); } } else { String errorMsg = "Error occured while deploying stratos appliction for ID : " + applicationId + "HTTP Status code : " + response.getStatusCode() + " server response : " + response.getResponse(); handleException(errorMsg); } }
From source file:org.wso2.carbon.appfactory.s4.integration.StratosRestClient.java
public void undeployApplication(String applicationId) throws AppFactoryException { ServerResponse response = MutualAuthHttpClient.sendPostRequest("", this.stratosManagerURL + APPLICATIONS_REST_END_POINT + "/" + applicationId + "/undeploy/", username);// w ww. jav a 2s . co m if (response.getStatusCode() == HttpStatus.SC_ACCEPTED) { if (log.isDebugEnabled()) { log.debug("Stratos undeployment started successfully for appId : " + applicationId); } } else { String errorMsg = "Error occured while undeploying stratos appliction for ID : " + applicationId + "HTTP Status code : " + response.getStatusCode() + " server response : " + response.getResponse(); handleException(errorMsg); } }
From source file:org.wso2.carbon.dataservices.google.tokengen.servlet.TokenEndpoint.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) { AuthCode authCode = CodeHolder.getInstance().getAuthCodeForSession(request.getSession().getId()); String responseMsg = ""; JSONObject resJson = new JSONObject(); int responseStatus; if (authCode != null) { if (log.isDebugEnabled()) { log.debug("Request received for retrieve access token from session - " + request.getSession().getId()); }/*w w w.ja v a 2 s . com*/ StringBuffer jb = new StringBuffer(); JSONObject jsonObject; String line = null; try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { jb.append(line); } jsonObject = new JSONObject(new JSONTokener(jb.toString())); String clientId = jsonObject.getString(DBConstants.GSpread.CLIENT_ID); String clientSecret = jsonObject.getString(DBConstants.GSpread.CLIENT_SECRET); String redirectURIs = jsonObject.getString(DBConstants.GSpread.REDIRECT_URIS); if (clientId == null || clientId.isEmpty()) { responseStatus = HttpStatus.SC_BAD_REQUEST; responseMsg = "ClientID is null or empty"; } else if (clientSecret == null || clientSecret.isEmpty()) { responseStatus = HttpStatus.SC_BAD_REQUEST; responseMsg = "Client Secret is null or empty"; } else if (redirectURIs == null || redirectURIs.isEmpty()) { responseStatus = HttpStatus.SC_BAD_REQUEST; responseMsg = "Redirect URIs is null or empty"; } else { HttpTransport httpTransport = new NetHttpTransport(); JacksonFactory jsonFactory = new JacksonFactory(); // Step 2: Exchange auth code for tokens GoogleTokenResponse googleTokenResponse = new GoogleAuthorizationCodeTokenRequest(httpTransport, jsonFactory, "https://www.googleapis.com/oauth2/v3/token", clientId, clientSecret, authCode.getAuthCode(), redirectURIs).execute(); resJson.append(DBConstants.GSpread.ACCESS_TOKEN, googleTokenResponse.getAccessToken()); resJson.append(DBConstants.GSpread.REFRESH_TOKEN, googleTokenResponse.getRefreshToken()); responseMsg = resJson.toString(); responseStatus = HttpStatus.SC_OK; if (log.isDebugEnabled()) { log.debug("Access token request successfully served for client id " + clientId); } } } catch (JSONException e) { responseStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; responseMsg = "Error in Processing accessTokenRequest Error - " + e.getMessage(); log.error(responseMsg, e); } catch (IOException e) { responseStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; responseMsg = "Error in Processing accessTokenRequest Error - " + e.getMessage(); log.error(responseMsg, e); } catch (Exception e) { responseStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; responseMsg = "Error in Processing accessTokenRequest Error - " + e.getMessage(); log.error(responseMsg, e); } } else { responseStatus = HttpStatus.SC_ACCEPTED; responseMsg = resJson.toString(); } try { PrintWriter out = response.getWriter(); out.println(responseMsg); response.setStatus(responseStatus); } catch (IOException e) { log.error("Error Getting print writer to write http response Error - " + e.getMessage(), e); response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); } }
From source file:org.wso2.carbon.device.mgt.iot.services.DeviceControllerService.java
@Path("/pushdata/{owner}/{type}/{id}/{time}/{key}/{value}") @POST//from ww w . ja v a2 s. c o m // @Produces("application/xml") public static String pushData(@PathParam("owner") String owner, @PathParam("type") String deviceType, @PathParam("id") String deviceId, @PathParam("time") Long time, @PathParam("key") String key, @PathParam("value") String value, @HeaderParam("description") String description, @Context HttpServletResponse response) { HashMap<String, String> deviceDataMap = new HashMap<String, String>(); deviceDataMap.put("owner", owner); deviceDataMap.put("deviceType", deviceType); deviceDataMap.put("deviceId", deviceId); deviceDataMap.put("time", "" + time); deviceDataMap.put("key", key); deviceDataMap.put("value", value); deviceDataMap.put("description", description); //DeviceValidator deviceChecker = new DeviceValidator(); //DeviceIdentifier dId = new DeviceIdentifier(); //dId.setId(deviceId); //dId.setType(deviceType); // try { // boolean exists = deviceChecker.isExist(owner, dId); String result = null; // if (exists) { try { iotDataStore.publishIoTData(deviceDataMap); response.setStatus(HttpStatus.SC_ACCEPTED); result = "Data Published Succesfully..."; } catch (DeviceControllerServiceException e) { response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); result = "Failed to push " + description + " data to dataStore at " + dataStoreConfig.getEndPoint() + ":" + dataStoreConfig.getPort(); } // // } // return result; // // } catch (InstantiationException e) { // response.setStatus(500); // return null; // } catch (IllegalAccessException e) { // response.setStatus(500); // return null; // } catch (ConfigurationException e) { // response.setStatus(500); // return null; // } catch (DeviceCloudException e) { // response.setStatus(500); // return null; // } }
From source file:org.wso2.carbon.device.mgt.iot.services.DeviceControllerService.java
@Path("/setcontrol/{owner}/{type}/{id}/{key}/{value}") @POST//from w w w . j a v a 2 s .com public static String setControl(@PathParam("owner") String owner, @PathParam("type") String deviceType, @PathParam("id") String deviceId, @PathParam("key") String key, @PathParam("value") String value, @Context HttpServletResponse response) { HashMap<String, String> deviceControlsMap = new HashMap<String, String>(); deviceControlsMap.put("owner", owner); deviceControlsMap.put("deviceType", deviceType); deviceControlsMap.put("deviceId", deviceId); deviceControlsMap.put("key", key); deviceControlsMap.put("value", value); String result = null; try { iotControlQueue.enqueueControls(deviceControlsMap); response.setStatus(HttpStatus.SC_ACCEPTED); result = "Controls added to queue succesfully.."; } catch (DeviceControllerServiceException e) { response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); result = "Failed to enqueue data to queue at " + controlQueueConfig.getEndPoint() + ":" + controlQueueConfig.getPort(); } return result; }
From source file:org.wso2.carbon.device.mgt.iot.services.firealarm.FireAlarmControllerService.java
@Path("/readcontrols/{owner}/{deviceId}") @GET/*from ww w.j av a 2 s . c o m*/ public String readControls(@PathParam("owner") String owner, @PathParam("deviceId") String deviceId, @Context HttpServletResponse response) { String result = null; LinkedList<String> deviceControlList = internalControlsQueue.get(deviceId); if (deviceControlList == null) { result = "No controls have been set for device " + deviceId + " of owner " + owner; response.setStatus(HttpStatus.SC_NO_CONTENT); } else { try { result = deviceControlList.remove(); response.setStatus(HttpStatus.SC_ACCEPTED); response.addHeader("Control", result); } catch (NoSuchElementException ex) { result = "There are no more controls for device " + deviceId + " of owner " + owner; response.setStatus(HttpStatus.SC_NO_CONTENT); } } log.info(result); return result; }