Example usage for org.springframework.web.client HttpServerErrorException getStatusText

List of usage examples for org.springframework.web.client HttpServerErrorException getStatusText

Introduction

In this page you can find the example usage for org.springframework.web.client HttpServerErrorException getStatusText.

Prototype

public String getStatusText() 

Source Link

Document

Return the HTTP status text.

Usage

From source file:info.raack.appliancelabeler.service.OAuthRequestProcessor.java

public <T, S> S processRequest(String uri, OAuthSecurityContext context, ResponseHandler<T, S> handler)
        throws OAuthUnauthorizedException {
    logger.debug("Attempting to request " + uri);

    String responseString = null;
    InputStream xmlInputStream = null;
    try {//from  w  w w  .j  a  v a2 s  . c om
        if (context != null) {
            // set the current authentication context
            OAuthSecurityContextHolder.setContext(context);
        }

        // use the normal request processor for the currently logged in user
        byte[] bytes = oAuthRestTemplate.getForObject(URI.create(uri), byte[].class);

        responseString = new String(bytes);
        //logger.debug(new String(bytes));
        xmlInputStream = new ByteArrayInputStream(bytes);

        //logger.debug("response: " + new String(bytes));
        synchronized (this) {
            try {
                T item = (T) ((JAXBElement) u1.unmarshal(xmlInputStream)).getValue();
                return handler.extractValue(item);
            } catch (Exception e) {
                // don't do anything if we can't unmarshall with the teds.xsd - try the other one
                try {
                    xmlInputStream.close();
                } catch (Exception e2) {

                }

                xmlInputStream = new ByteArrayInputStream(bytes);
            }
            T item = (T) ((JAXBElement) u2.unmarshal(xmlInputStream)).getValue();
            return handler.extractValue(item);
        }

    } catch (HttpClientErrorException e2) {
        // if unauthorized - our credentials are bad or have been revoked - throw exception up the stack
        if (e2.getStatusCode() == HttpStatus.UNAUTHORIZED) {
            throw new OAuthUnauthorizedException();
        } else {
            throw new RuntimeException(
                    "Unknown remote server error " + e2.getStatusCode() + " (" + e2.getStatusText()
                            + ") returned when requesting " + uri + "; " + e2.getResponseBodyAsString());
        }
    } catch (HttpServerErrorException e3) {
        throw new RuntimeException(
                "Unknown remote server error " + e3.getStatusCode() + " (" + e3.getStatusText()
                        + ") returned when requesting " + uri + "; " + e3.getResponseBodyAsString());
    } catch (Exception e) {
        throw new RuntimeException(
                "Could not request " + uri + (responseString != null ? " response was " + responseString : ""),
                e);
    } finally {
        try {
            if (xmlInputStream != null) {
                xmlInputStream.close();
            }
        } catch (Exception e) {
        }
    }
}

From source file:com.wavemaker.tools.deployment.cloudfoundry.CloudFoundryDeploymentTarget.java

private String doDeploy(ApplicationArchive applicationArchive, DeploymentInfo deploymentInfo,
        boolean checkExist) throws DeploymentStatusException {
    try {//from  w  ww  . j a v  a  2  s  .c  o  m
        CloudFoundryClient client = getClient(deploymentInfo);
        String url = createApplication(client, deploymentInfo, checkExist);
        log.info("Preparing: " + url);
        setupServices(client, deploymentInfo);
        uploadAppliation(client, deploymentInfo.getApplicationName(), applicationArchive);
        try {
            CloudApplication application = client.getApplication(deploymentInfo.getApplicationName());
            if (application.getState().equals(CloudApplication.AppState.STARTED)) {
                doRestart(deploymentInfo, client);
            } else {
                doStart(deploymentInfo, client);
            }
        } catch (CloudFoundryException ex) {
            throw new DeploymentStatusException("ERROR: Could not start application. " + ex.getDescription(),
                    ex);
        }
        if (!url.startsWith("http://")) {
            url = "http://" + url;
        }
        return url;
    } catch (HttpServerErrorException e) {
        throw new DeploymentStatusException("ERROR: Clould not deploy application due to remote exception\n"
                + e.getMessage() + "\n\n" + e.getStatusText());
    }
}

From source file:org.springframework.web.client.RestTemplateIntegrationTests.java

@Test
public void serverError() {
    try {//from  w  w w  .j  ava 2  s .c om
        template.execute(baseUrl + "/status/server", HttpMethod.GET, null, null);
        fail("HttpServerErrorException expected");
    } catch (HttpServerErrorException ex) {
        assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, ex.getStatusCode());
        assertNotNull(ex.getStatusText());
        assertNotNull(ex.getResponseBodyAsString());
    }
}