Example usage for org.springframework.web.client HttpStatusCodeException getMessage

List of usage examples for org.springframework.web.client HttpStatusCodeException getMessage

Introduction

In this page you can find the example usage for org.springframework.web.client HttpStatusCodeException getMessage.

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:access.controller.AccessController.java

/**
 * Deletes a Deployment Group from Piazza, and from the corresponding GeoServer.
 * /*from  ww  w  . ja  v a2 s  .c  o m*/
 * @param deploymentGroupId
 *            The Id of the deployment Group to delete.
 * @return Appropriate response
 */
@RequestMapping(value = "/deployment/group/{deploymentGroupId}", method = RequestMethod.DELETE, produces = "application/json")
public ResponseEntity<PiazzaResponse> deleteDeploymentGroup(
        @PathVariable(value = "deploymentGroupId") String deploymentGroupId) {
    try {
        if ((deploymentGroupId == null) || (deploymentGroupId.isEmpty())) {
            return new ResponseEntity<>(
                    new ErrorResponse("DeploymentGroup Id not specified.", ACCESS_COMPONENT_NAME),
                    HttpStatus.BAD_REQUEST);
        }
        // Delete the DeploymentGroup from GeoServer, and remove it from
        // the Piazza DB persistence
        DeploymentGroup deploymentGroup = accessor.getDeploymentGroupById(deploymentGroupId);
        if (deploymentGroup == null) {
            return new ResponseEntity<>(
                    new ErrorResponse("DeploymentGroup does not exist.", ACCESS_COMPONENT_NAME),
                    HttpStatus.NOT_FOUND);
        }
        groupDeployer.deleteDeploymentGroup(deploymentGroup);
        return new ResponseEntity<>(new SuccessResponse("Group Deleted.", ACCESS_COMPONENT_NAME),
                HttpStatus.OK);
    } catch (HttpStatusCodeException httpException) {
        // Return the HTTP Error code from GeoServer
        String error = String.format(
                "Could not delete DeploymentGroup. Response from GeoServer returned code %s with reason %s",
                httpException.getStatusCode().toString(), httpException.getMessage());
        LOGGER.error(error, httpException);
        pzLogger.log(error, Severity.ERROR,
                new AuditElement(ACCESS, "errorDeletingDeploymentGroup", deploymentGroupId));
        return new ResponseEntity<>(new ErrorResponse(error, ACCESS_COMPONENT_NAME),
                httpException.getStatusCode());
    } catch (Exception exception) {
        // Return the 500 Internal error
        String error = String.format("Could not delete DeploymentGroup. An unexpected error occurred: %s",
                exception.getMessage());
        LOGGER.error(error, exception);
        pzLogger.log(error, Severity.ERROR,
                new AuditElement(ACCESS, "errorDeletingDeploymentGroup", deploymentGroupId));
        return new ResponseEntity<>(new ErrorResponse(error, ACCESS_COMPONENT_NAME),
                HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:com.auditbucket.client.AbRestClient.java

public String getErrorMessage(HttpStatusCodeException e) {

    if (e.getStatusCode() == HttpStatus.INTERNAL_SERVER_ERROR) {
        logger.error(e.getResponseBodyAsString());
        return e.getResponseBodyAsString();
    }/*  w w  w.j a  v a 2 s .c  om*/

    JsonNode n = null;
    try {
        n = mapper.readTree(e.getResponseBodyAsByteArray());
    } catch (IOException e1) {

        logger.error(String.valueOf(e1));
    }
    String message;
    if (n != null)
        message = String.valueOf(n.get("message"));
    else
        message = e.getMessage();

    return message;
}

From source file:edu.mayo.cts2.framework.plugin.service.bioportal.rest.BioportalRestService.java

/**
 * Call bioportal./*from  ww w. j a  v  a  2  s .co  m*/
 *
 * @param url the url
 * @return the string
 */
protected String callBioportal(String url) {
    log.info("Calling Bioportal REST: " + url);
    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", "application/xml");

    ResponseEntity<String> response;

    try {
        response = this.restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<Void>(headers), String.class);
    } catch (HttpStatusCodeException e) {
        if (e.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
            throw e;
        } else {
            log.error("Error calling BioPortal REST Service", e);
            throw ExceptionFactory.createUnknownException("Error calling NCBO BioPortal: " + e.getMessage());
        }
    }

    return response.getBody();
}

From source file:org.alfresco.integrations.google.docs.service.GoogleDocsServiceImpl.java

/**
 * Delete Google Drive Folder/*from w  w  w. j ava  2 s.c o m*/
 * 
 * @param folderId
 * @throws GoogleDocsAuthenticationException
 * @throws GoogleDocsRefreshTokenException
 * @throws GoogleDocsServiceException
 */
private void deleteFolder(String folderId)
        throws GoogleDocsAuthenticationException, GoogleDocsRefreshTokenException, GoogleDocsServiceException {
    DriveOperations driveOperations = getDriveOperations(getConnection());

    try {
        driveOperations.delete(folderId);
    } catch (HttpStatusCodeException hsce) {
        throw new GoogleDocsServiceException(hsce.getMessage(), hsce, hsce.getStatusCode().value());
    }
}

From source file:org.alfresco.integrations.google.docs.service.GoogleDocsServiceImpl.java

public DriveFile getDriveFile(String resourceID)
        throws GoogleDocsServiceException, GoogleDocsAuthenticationException, GoogleDocsRefreshTokenException {
    log.debug("Get Document list entry for resource " + resourceID);
    DriveOperations driveOperations = getDriveOperations(getConnection());

    DriveFile driveFile = null;/*from  w ww .jav  a  2 s . c  o m*/

    try {
        driveFile = driveOperations.getFile(resourceID.substring(resourceID.lastIndexOf(':') + 1));
    } catch (HttpStatusCodeException hsce) {
        throw new GoogleDocsServiceException(hsce.getMessage(), hsce.getStatusCode().value());
    }

    return driveFile;
}

From source file:org.alfresco.integrations.google.docs.service.GoogleDocsServiceImpl.java

public GoogleUserProfile getGoogleUserProfile()
        throws GoogleDocsAuthenticationException, GoogleDocsRefreshTokenException, GoogleDocsServiceException {
    log.debug("Get Google Docs user metadata");
    UserInfoOperations userInfoOperations = getConnection().getApi().userOperations();

    GoogleUserProfile googleUserProfile = null;

    try {//from   w w w . jav a  2s .co  m
        googleUserProfile = userInfoOperations.getUserProfile();
    } catch (HttpStatusCodeException hsce) {
        throw new GoogleDocsServiceException(hsce.getMessage(), hsce.getStatusCode().value());
    }

    return googleUserProfile;
}

From source file:org.alfresco.integrations.google.docs.service.GoogleDocsServiceImpl.java

/**
 * Create new folder in Google Drive/* ww  w . j av a2  s.  c  o  m*/
 * 
 * @param parentId
 * @param folderName
 * @return
 * @throws GoogleDocsServiceException
 * @throws GoogleDocsAuthenticationException
 * @throws GoogleDocsRefreshTokenException
 */
private DriveFile createFolder(String parentId, String folderName)
        throws GoogleDocsServiceException, GoogleDocsAuthenticationException, GoogleDocsRefreshTokenException {
    DriveFile driveFile = null;
    DriveOperations driveOperations = getDriveOperations(getConnection());

    try {
        driveFile = driveOperations.createFolder(parentId, folderName);
        driveFile = driveOperations.hide(driveFile.getId());
    } catch (HttpStatusCodeException hsce) {
        throw new GoogleDocsServiceException(hsce.getMessage(), hsce, hsce.getStatusCode().value());
    }

    return driveFile;
}

From source file:org.alfresco.integrations.google.docs.service.GoogleDocsServiceImpl.java

public FileRevision getLatestRevision(DriveFile driveFile)
        throws GoogleDocsAuthenticationException, GoogleDocsRefreshTokenException, GoogleDocsServiceException {
    FileRevision fileRevision = null;// w  w  w .  j av  a2 s.  co m

    DriveOperations driveOperations = getDriveOperations(getConnection());

    List<FileRevision> fileRevisions = driveOperations.getRevisions(driveFile.getId());

    try {
        if (fileRevisions != null) {
            Collections.sort(fileRevisions, new FileRevisionComparator());

            fileRevision = fileRevisions.get(fileRevisions.size() - 1);
        }
    } catch (HttpStatusCodeException hsce) {
        throw new GoogleDocsServiceException(hsce.getMessage(), hsce.getStatusCode().value());
    }

    return fileRevision;
}

From source file:org.alfresco.integrations.google.docs.service.GoogleDocsServiceImpl.java

public boolean deleteContent(NodeRef nodeRef, DriveFile driveFile)
        throws GoogleDocsAuthenticationException, GoogleDocsServiceException, GoogleDocsRefreshTokenException {
    log.debug("Delete Google Doc for " + nodeRef);
    boolean deleted = false;

    DriveOperations driveOperations = getDriveOperations(getConnection());

    try {/*from  w  ww .  j  av  a2  s.c  o  m*/
        driveOperations.delete(driveFile.getId());

        // Delete the Working directory in Google Drive (if it exists....this should handle any migration issues)
        deleteWorkingDirectory(nodeRef);

        unDecorateNode(nodeRef);
        deleted = true;
    } catch (HttpStatusCodeException hsce) {
        throw new GoogleDocsServiceException(hsce.getMessage(), hsce.getStatusCode().value());
    }

    log.debug("Deleted: " + deleted);
    return deleted;
}