List of usage examples for org.springframework.web.client HttpStatusCodeException getStatusCode
public HttpStatus getStatusCode()
From source file:org.alfresco.integrations.google.docs.service.GoogleDocsServiceImpl.java
/** * Get the Document from the users Google Drive account. The Document and its working directory will be removed from their * Google Drive account. The editingInGoogle aspect will be removed. * //from www . jav a 2 s . c o m * @param nodeRef * @param resourceID * @throws GoogleDocsAuthenticationException * @throws GoogleDocsServiceException * @throws GoogleDocsRefreshTokenException */ private void getPresentation(NodeRef nodeRef, String resourceID, boolean removeFromDrive) throws GoogleDocsAuthenticationException, GoogleDocsServiceException, GoogleDocsRefreshTokenException, IOException { log.debug("Get Google Presentation for node: " + nodeRef); DriveOperations driveOperations = getDriveOperations(getConnection()); try { String mimetype = null; mimetype = validateMimeType(fileFolderService.getFileInfo(nodeRef).getContentData().getMimetype()); log.debug("Current mimetype: " + fileFolderService.getFileInfo(nodeRef).getContentData().getMimetype() + "; Mimetype of Google Doc: " + mimetype); log.debug("Export format: " + mimetype); DriveFile driveFile = driveOperations.getFile(resourceID.substring(resourceID.lastIndexOf(':') + 1)); InputStream inputStream = getFileInputStream(driveFile, mimetype); ContentWriter writer = fileFolderService.getWriter(nodeRef); writer.setMimetype(mimetype); writer.putContent(inputStream); renameNode(nodeRef, driveFile.getTitle()); saveSharedInfo(nodeRef, resourceID); if (removeFromDrive) { deleteContent(nodeRef, driveFile); } else { nodeService.setProperty(nodeRef, GoogleDocsModel.PROP_REVISION_ID, getLatestRevision(driveFile).getId()); } postActivity(nodeRef); if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TEMPORARY) && removeFromDrive) { nodeService.removeAspect(nodeRef, ContentModel.ASPECT_TEMPORARY); log.debug("Temporary Aspect Removed"); } } catch (IOException ioe) { throw ioe; } catch (HttpStatusCodeException hsce) { throw new GoogleDocsServiceException(hsce.getMessage(), hsce.getStatusCode().value()); } catch (JSONException jsonException) { throw new GoogleDocsAuthenticationException( "Unable to create activity entry: " + jsonException.getMessage(), jsonException); } }
From source file:org.alfresco.integrations.google.docs.service.GoogleDocsServiceImpl.java
public boolean hasConcurrentEditors(NodeRef nodeRef) throws GoogleDocsAuthenticationException, GoogleDocsRefreshTokenException, GoogleDocsServiceException { log.debug(//from w ww .j a v a2 s .co m "Check for Concurrent Editors (Edits that have occured in the last " + idleThreshold + " seconds)"); DriveOperations driveOperations = getDriveOperations(getConnection()); String resourceID = nodeService.getProperty(nodeRef, GoogleDocsModel.PROP_RESOURCE_ID).toString(); boolean concurrentChange = false; try { List<FileRevision> fileRevisionList = driveOperations .getRevisions(resourceID.substring(resourceID.lastIndexOf(':') + 1)); if (fileRevisionList.size() > 1) { log.debug("Revisions Found"); Collections.sort(fileRevisionList, Collections.reverseOrder(new FileRevisionComparator())); // Find any revisions occurring within the last 'idleThreshold' // seconds List<FileRevision> workingList = new ArrayList<FileRevision>(); Calendar bufferTime = Calendar.getInstance(); bufferTime.add(Calendar.SECOND, -idleThreshold); for (FileRevision entry : fileRevisionList) { if (entry.getModifiedDate().after(new Date(bufferTime.getTimeInMillis()))) { workingList.add(entry); } else { // once we past 'idleThreshold' seconds get out of here break; } } // If there any revisions that occurred within the last // 'idleThreshold' seconds of time.... if (workingList.size() > 0) { log.debug("Revisions within threshhold found"); // Filter the current user from the list for (int i = workingList.size() - 1; i >= 0; i--) { FileRevision fileRevision = workingList.get(i); String name = getGoogleUserProfile().getName(); // if there is no author -- the entry is the initial // creation if (fileRevision.getLastModifyingUserName() != null) { if (fileRevision.getLastModifyingUserName().equals(name)) { workingList.remove(i); } } else { workingList.remove(i); } } } // Are there are changes by other users within the last // 'idleThreshold' seconds if (workingList.size() > 0) { log.debug("Revisions not made by current user found."); concurrentChange = true; } } else { String name = getGoogleUserProfile().getName(); // if the authors list is empty -- the author was the original // creator and it is the initial copy if (fileRevisionList.get(0).getLastModifyingUserName() != null) { if (!fileRevisionList.get(0).getLastModifyingUserName().equals(name)) { Calendar bufferTime = Calendar.getInstance(); bufferTime.add(Calendar.SECOND, -idleThreshold); if (fileRevisionList.get(0).getModifiedDate() .before(new Date(bufferTime.getTimeInMillis()))) { log.debug("Revisions not made by current user found."); concurrentChange = true; } } } } } catch (HttpStatusCodeException hsce) { throw new GoogleDocsServiceException(hsce.getMessage(), hsce.getStatusCode().value()); } log.debug("Concurrent Edits: " + concurrentChange); return concurrentChange; }
From source file:org.kaaproject.kaa.server.common.admin.TestMessage.java
public String getMessage(KaaRestTemplate kaaRestTemplate, TestHttpMethods httpMethods) { String result;//from ww w . j a va 2s . c o m try { switch (httpMethods) { case GET: { String httpResult = kaaRestTemplate.getForObject("http://localhost:8080/kaaTest", String.class); result = "Message SUCCESS result: " + httpResult; break; } case PUT: { String putText = "putText"; kaaRestTemplate.put("http://localhost:8080/kaaTest/put", putText); result = "Result SUCCESS" + putText; break; } case DELETE: { kaaRestTemplate.delete("http://localhost:8080/kaaTest/delete"); result = "Result SUCCESS"; break; } case POST: { String httpResult = kaaRestTemplate.postForObject("http://localhost:8080/kaaTest/post", new String("postText"), String.class); result = "Message SUCCESS result: " + httpResult; break; } default: { result = "ERROR"; } } } catch (HttpStatusCodeException e) { result = "Get FAILED with HttpStatusCode: " + e.getStatusCode() + "|" + e.getStatusText(); } catch (RuntimeException e) { result = "Get FAILED\n" + ExceptionUtils.getFullStackTrace(e); } return result; }
From source file:org.kaaproject.kaa.server.control.AbstractTestControlServer.java
protected void checkRestErrorStatusCode(TestRestCall restCall, HttpStatus expectedStatus) throws Exception { HttpStatus errorStatus = null;//from www. j ava 2 s .c om try { restCall.executeRestCall(); } catch (HttpStatusCodeException e) { errorStatus = e.getStatusCode(); } Assert.assertNotNull(errorStatus); Assert.assertEquals(expectedStatus, errorStatus); }
From source file:org.mskcc.cbio.portal.util.SessionServiceUtil.java
/** * Return cohort object if there is success response from * session-service API, else it would return null * @param virtualStudyId//from ww w.java 2 s . c o m * @return cohort object */ public VirtualStudy getVirtualStudyData(String virtualStudyId) { if (!GlobalProperties.getSessionServiceUrl().equals("")) { try { RestTemplate restTemplate = new RestTemplate(); HttpEntity<String> headers = new HttpEntity<String>(getHttpHeaders()); ResponseEntity<VirtualStudy> responseEntity = restTemplate.exchange( GlobalProperties.getSessionServiceUrl() + "virtual_study/" + virtualStudyId, HttpMethod.GET, headers, VirtualStudy.class); return responseEntity.getBody(); } catch (HttpStatusCodeException exception) { LOG.warn("SessionServiceUtil.getVirtualCohortData(): HttpStatusCodeException = '" + exception.getStatusCode() + "'"); } catch (Exception exception) { LOG.warn("SessionServiceUtil.getVirtualCohortData(): Exception = '" + exception.getMessage() + "'"); } } return null; }
From source file:org.springframework.vault.authentication.AuthenticationStepsExecutor.java
@Override @SuppressWarnings("unchecked") public VaultToken login() throws VaultException { Object state = null;/*from w ww . ja va2 s . c om*/ for (Node<?> o : chain.steps) { if (logger.isDebugEnabled()) { logger.debug(String.format("Executing %s with current state %s", o, state)); } try { if (o instanceof HttpRequestNode) { state = doHttpRequest((HttpRequestNode<Object>) o, state); } if (o instanceof AuthenticationSteps.MapStep) { state = doMapStep((MapStep<Object, Object>) o, state); } if (o instanceof OnNextStep) { state = doOnNext((OnNextStep<Object>) o, state); } if (o instanceof AuthenticationSteps.SupplierStep<?>) { state = doSupplierStep((SupplierStep<Object>) o); } if (logger.isDebugEnabled()) { logger.debug(String.format("Executed %s with current state %s", o, state)); } } catch (HttpStatusCodeException e) { throw new VaultException( String.format("HTTP request %s in state %s failed with Status %s and body %s", o, state, e.getStatusCode(), VaultResponses.getError(e.getResponseBodyAsString()))); } catch (RuntimeException e) { throw new VaultException(String.format("Authentication execution failed in %s", o), e); } } if (state instanceof VaultToken) { return (VaultToken) state; } if (state instanceof VaultResponse) { VaultResponse response = (VaultResponse) state; Assert.state(response.getAuth() != null, "Auth field must not be null"); return LoginTokenUtil.from(response.getAuth()); } throw new IllegalStateException( String.format("Cannot retrieve VaultToken from authentication chain. Got instead %s", state)); }
From source file:sample.test.service.RemoteVehicleDetailsService.java
@Override public VehicleDetails getVehicleDetails(VehicleIdentificationNumber vin) throws VehicleIdentificationNumberNotFoundException { Assert.notNull(vin, "VIN must not be null"); logger.debug("Retrieving vehicle data for: " + vin); try {//from ww w . j a v a 2 s . co m return this.restTemplate.getForObject("/vehicle/{vin}/details", VehicleDetails.class, vin); } catch (HttpStatusCodeException ex) { if (HttpStatus.NOT_FOUND.equals(ex.getStatusCode())) { throw new VehicleIdentificationNumberNotFoundException(vin, ex); } throw ex; } }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestUtils.java
private static void handleHttpStatusCodeException(RestClientExceptionHandlerEnvironment environment) { HttpStatusCodeException httpStatusCodeException = (HttpStatusCodeException) environment .getRestClientException();// w w w . j a v a 2 s.c o m switch (httpStatusCodeException.getStatusCode()) { case NOT_FOUND: throw new OwncloudResourceNotFoundException(environment.getRequestURI(), environment.getUsername()); case INSUFFICIENT_STORAGE: throw new OwncloudQuotaExceededException(environment.getRequestURI(), environment.getUsername()); default: break; } }