Example usage for org.apache.http.client HttpResponseException getMessage

List of usage examples for org.apache.http.client HttpResponseException getMessage

Introduction

In this page you can find the example usage for org.apache.http.client HttpResponseException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:tds.tdsadmin.web.backingbean.DefaultBacking.java

private ProcedureResult executeProcedure(TestOpportunity testOpp) {
    ProcedureResult result = null;/*w w  w.j  av a  2  s  . c om*/
    try {
        switch (this.procedure) {
        case "changeperm":
            result = controller.setOpportunitySegmentPerm(response, testOpp.getOppKey(), this.getRequestor(),
                    testOpp.getSegmentName(), testOpp.getSegmentPosition(), testOpp.getRestoreOn(),
                    testOpp.getIspermeable(), this.getReason());
            break;
        case "alter":
            result = controller.alterOpportunityExpiration(response, testOpp.getOppKey(), this.getRequestor(),
                    testOpp.getDayIncrement(), this.getReason());
            break;
        case "extend":
            result = controller.extendingOppGracePeriod(response, testOpp.getOppKey(), this.getRequestor(),
                    testOpp.getSelectedSitting(), testOpp.getDoUpdate(), this.getReason());
            break;
        case "reopen":
            result = controller.reopenOpportunity(response, testOpp.getOppKey(), this.getRequestor(),
                    this.getReason());
            break;
        case "reset":
            result = controller.resetOpportunity(response, testOpp.getOppKey(), this.getRequestor(),
                    this.getReason());
            break;
        case "invalidate":
            result = controller.invalidateTestOpportunity(response, testOpp.getOppKey(), this.getRequestor(),
                    this.getReason());
            break;
        case "restore":

            result = controller.restoreTestOpportunity(response, testOpp.getOppKey(), this.getRequestor(),
                    this.getReason());

            break;
        }
        _logger.info(String.format("DefaultBacking: Success for procedure=%s, oppkey=%s", procedure,
                testOpp.getOppKey()));
    } catch (HttpResponseException e) {
        _logger.error("DefaultBacking: " + e.getMessage(), e);
    }
    return result;
}

From source file:org.musicmount.io.server.dav.DAVResourceProvider.java

@Override
protected boolean exists(ServerPath path) throws IOException {
    if (path.isDirectory()) {
        try {/*from   ww w . j  a v  a 2  s  .  co m*/
            return getFileAttributes(path).isDirectory();
        } catch (HttpResponseException e) {
            if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
                return false;
            } else {
                throw new IOException(e.getMessage() + " (" + e.getStatusCode() + ")", e);
            }
        }
    } else { // HEAD, doesn't work for directories
        return getSardine().exists(path.toUri().toString());
    }
}

From source file:fr.lissi.belilif.om2m.oao.ApplicationManager.java

/**
 * Exist./*  w  w  w .  ja  va 2  s .  c  om*/
 * 
 * @param obj
 *            the obj
 * @return true, if successful
 */
@Override
public boolean exist(Application obj) {
    HttpGetSimpleResp resp;
    try {
        resp = WebServiceActions.doGet(this.OM2MUrlBase + "applications/" + obj.getAppId(), headers);
        if (resp.getStatusCode() == 200)
            return true;
    } catch (HttpResponseException e) {
        // LOGGER.warn("HttpResponseException - " + e.getStatusCode() + " / " + e.getMessage());
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        LOGGER.error(e.getMessage());
    } catch (ConnectException e) {
        LOGGER.error(
                e.getMessage() + ". \nThe server '" + this.OM2MUrlBase.substring(7, 21) + "' is unreachable.");
    } catch (IOException e) {
        LOGGER.error(e.getMessage());
    }
    return false;
}

From source file:eu.over9000.skadi.service.ImportFollowedService.java

@Override
protected Task<Set<String>> createTask() {
    return new Task<Set<String>>() {

        @Override/*from w  w  w .ja va 2  s. co m*/
        protected Set<String> call() throws Exception {

            this.updateMessage("importing channels for " + ImportFollowedService.this.user);
            try {
                final Set<String> channels = new TreeSet<>();

                int limit = 0;
                int offset = 0;

                String url = "https://api.twitch.tv/kraken/users/" + ImportFollowedService.this.user
                        + "/follows/channels";
                String response = HttpUtil.getAPIResponse(url);
                JsonObject responseObject = ImportFollowedService.this.parser.parse(response).getAsJsonObject();

                String parameters = responseObject.getAsJsonObject("_links").get("self").getAsString()
                        .split("\\?")[1];
                String[] split = parameters.split("&");

                for (final String string : split) {
                    if (string.startsWith("limit")) {
                        limit = Integer.valueOf(string.split("=")[1]);
                    } else if (string.startsWith("offset")) {
                        offset = Integer.valueOf(string.split("=")[1]);
                    }
                }

                final int count = responseObject.get("_total").getAsInt();
                LOGGER.debug("total channels followed: " + count);

                this.updateProgress(count, channels.size());
                this.updateMessage("Loaded " + channels.size() + " of " + count + " channels");

                while (offset < count) {

                    ImportFollowedService.this.parseAndAddChannelsToSet(channels, responseObject);

                    url = "https://api.twitch.tv/kraken/users/" + ImportFollowedService.this.user
                            + "/follows/channels?limit=" + limit + "&offset=" + (offset + limit);
                    response = HttpUtil.getAPIResponse(url);
                    responseObject = ImportFollowedService.this.parser.parse(response).getAsJsonObject();

                    parameters = responseObject.getAsJsonObject("_links").get("self").getAsString()
                            .split("\\?")[1];
                    split = parameters.split("&");
                    for (final String string : split) {
                        if (string.startsWith("limit")) {
                            limit = Integer.valueOf(string.split("=")[1]);
                        } else if (string.startsWith("offset")) {
                            offset = Integer.valueOf(string.split("=")[1]);
                        }
                    }

                    LOGGER.debug("limit=" + limit + " offset=" + offset + " channelsize=" + channels.size());

                    this.updateProgress(count, channels.size());
                    this.updateMessage("Loaded " + channels.size() + " of " + count + " channels");
                }

                return channels;

            } catch (final HttpResponseException e) {
                if (e.getStatusCode() == 404) {
                    this.updateMessage("The given user does not exist");
                    return null;
                }

                this.updateMessage("Error: " + e.getMessage());
                LOGGER.error("Error", e);
                return null;
            } catch (final Exception e) {
                this.updateMessage("Error: " + e.getMessage());
                LOGGER.error("Error", e);
                return null;
            }
        }
    };
}

From source file:org.obm.locator.LocatorClientImpl.java

@Override
public String getServiceLocation(String serviceSlashProperty, String loginAtDomain)
        throws LocatorClientException {
    try {/*from  w  w  w.  ja v a2s  .c  o  m*/
        String responseBody = Request.Get(buildFullServiceUrl(serviceSlashProperty, loginAtDomain))
                .connectTimeout(timeoutInMS).socketTimeout(timeoutInMS).execute().returnContent().asString();
        return Iterables.get(Splitter.on(RESPONSE_SEPARATOR).split(responseBody), 0);
    } catch (HttpResponseException e) {
        if (e.getStatusCode() == HTTP_CODE_NOT_FOUND) {
            throw new ServiceNotFoundException(
                    String.format("Service %s for %s not found", serviceSlashProperty, loginAtDomain));
        } else {
            throw new LocatorClientException(
                    String.format("HTTP error %d: %s", e.getStatusCode(), e.getMessage()), e);
        }
    } catch (MalformedURLException e) {
        throw new LocatorClientException(e.getMessage(), e);
    } catch (SocketTimeoutException e) {
        throw new LocatorClientException(e.getMessage(), e);
    } catch (IOException e) {
        throw new LocatorClientException(e.getMessage(), e);
    }
}

From source file:com.puppetlabs.geppetto.forge.impl.ForgeServiceImpl.java

@Override
public void publish(File moduleArchive, boolean dryRun, Diagnostic result) throws IOException {
    if (releaseService == null)
        throw new UnsupportedOperationException(
                "Unable to publish since no release service is configured. Was a serviceURL provided in the preferences?");

    Metadata metadata = forgeUtil.getMetadataFromPackage(moduleArchive);
    if (metadata == null)
        throw new ForgeException("No \"metadata.json\" found in archive: " + moduleArchive.getAbsolutePath());

    if (metadata.getName() == null)
        throw new ForgeException(
                "The \"metadata.json\" found in archive: " + moduleArchive.getAbsolutePath() + " has no name");

    if (metadata.getVersion() == null)
        throw new ForgeException("The \"metadata.json\" found in archive: " + moduleArchive.getAbsolutePath()
                + " has no version");

    try {/*from   www  .j  a  v a2  s  . c  om*/
        if (metadataRepo.resolve(metadata.getName(), metadata.getVersion()) != null)
            throw new AlreadyPublishedException("Module " + metadata.getName() + ':' + metadata.getVersion()
                    + " has already been published");
    } catch (HttpResponseException e) {
        // A SC_NOT_FOUND can be expected and is OK.
        if (e.getStatusCode() != HttpStatus.SC_NOT_FOUND)
            throw new ForgeException("Unable to check module existence on the forge: " + e.getMessage());
    }

    if (dryRun) {
        result.addChild(new Diagnostic(INFO, PUBLISHER, "Module file " + moduleArchive.getName()
                + " would have been uploaded (but wasn't since this is a dry run)"));
        return;
    }

    InputStream gzInput = new FileInputStream(moduleArchive);
    try {
        ModuleName name = metadata.getName();
        releaseService.create(name.getOwner(), name.getName(), "Published using GitHub trigger", gzInput,
                moduleArchive.length());
        result.addChild(new Diagnostic(INFO, PUBLISHER,
                "Module file " + moduleArchive.getName() + " has been uploaded"));
    } finally {
        StreamUtil.close(gzInput);
    }
}

From source file:fr.lissi.belilif.om2m.oao.ContainerManager.java

/**
 * Exist./*w w w . j  a v a2s .c  o  m*/
 *
 * @param obj
 *            the obj
 * @return true, if successful
 */
@Override
public boolean exist(Container obj) {
    if (obj.getApplication() == null || obj.getApplication().getAppId() == null) {
        LOGGER.error("you must specify the parent resource (parent Application) to manage containers.");
        return false;
    }

    HttpGetSimpleResp resp;
    try {
        resp = WebServiceActions.doGet(this.OM2MUrlBase + "applications/" + obj.getApplication().getAppId()
                + "/containers/" + obj.getId(), headers);
        if (resp.getStatusCode() == 200)
            return true;
    } catch (HttpResponseException e) {
        // LOGGER.warn("HttpResponseException - " + e.getStatusCode() + " / " + e.getMessage());
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        LOGGER.error(e.getMessage());
    } catch (ConnectException e) {
        LOGGER.error(
                e.getMessage() + ". \nThe server '" + this.OM2MUrlBase.substring(7, 21) + "' is unreachable.");
    } catch (IOException e) {
        LOGGER.error(e.getMessage());
    }
    return false;
}

From source file:org.ofbiz.testtools.seleniumxml.RemoteRequest.java

public void runTest() {

    ClientConnectionManager ccm = new ThreadSafeClientConnManager(defaultParameters, supportedSchemes);
    //  new SingleClientConnManager(getParams(), supportedSchemes);

    DefaultHttpClient client = new DefaultHttpClient(ccm, defaultParameters);
    client.setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy());

    ////from  ww  w. j a v  a  2s. c  o m
    // We first try to login with the loginAs to set the session.
    // Then we call the remote service.
    //
    HttpEntity entity = null;
    ResponseHandler<String> responseHandler = null;
    try {
        BasicHttpContext localContext = new BasicHttpContext();
        // Create a local instance of cookie store
        CookieStore cookieStore = new BasicCookieStore();
        localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

        Header sessionHeader = null;

        if (this.loginAsUrl != null) {

            String loginAsUri = this.host + this.loginAsUrl;
            String loginAsParamString = "?" + this.loginAsUserParam + "&" + this.loginAsPasswordParam;

            HttpGet req2 = new HttpGet(loginAsUri + loginAsParamString);
            System.out.println("loginAsUrl:" + loginAsUri + loginAsParamString);

            req2.setHeader("Connection", "Keep-Alive");
            HttpResponse rsp = client.execute(req2, localContext);

            Header[] headers = rsp.getAllHeaders();
            for (int i = 0; i < headers.length; i++) {
                Header hdr = headers[i];
                String headerValue = hdr.getValue();
                if (headerValue.startsWith("JSESSIONID")) {
                    sessionHeader = hdr;
                }
                System.out.println("login: " + hdr.getName() + " : " + hdr.getValue());
            }
            List<Cookie> cookies = cookieStore.getCookies();
            System.out.println("cookies.size(): " + cookies.size());
            for (int i = 0; i < cookies.size(); i++) {
                System.out.println("Local cookie(0): " + cookies.get(i));
            }
        }
        //String paramString2 = "USERNAME=" + this.parent.getUserName()
        //                   + "&PASSWORD=" + this.parent.getPassword();
        //String thisUri2 = this.host + "/eng/control/login?" + paramString2;
        //HttpGet req2 = new HttpGet ( thisUri2 );
        //req2.setHeader("Connection","Keep-Alive");
        //HttpResponse rsp = client.execute(req2, localContext);

        //Header sessionHeader = null;
        //Header[] headers = rsp.getAllHeaders();
        //for (int i=0; i<headers.length; i++) {
        //    Header hdr = headers[i];
        //    String headerValue = hdr.getValue();
        //    if (headerValue.startsWith("JSESSIONID")) {
        //        sessionHeader = hdr;
        //    }
        //    System.out.println(headers[i]);
        //    System.out.println(hdr.getName() + " : " + hdr.getValue());
        //}

        //List<Cookie> cookies = cookieStore.getCookies();
        //System.out.println("cookies.size(): " + cookies.size());
        //for (int i = 0; i < cookies.size(); i++) {
        //    System.out.println("Local cookie(0): " + cookies.get(i));
        //}
        if (HttpHandleMode.equals(this.responseHandlerMode)) {

        } else {
            responseHandler = new JsonResponseHandler(this);
        }

        String paramString = urlEncodeArgs(this.inMap, false);

        String thisUri = null;
        if (sessionHeader != null) {
            String sessionHeaderValue = sessionHeader.getValue();
            int pos1 = sessionHeaderValue.indexOf("=");
            int pos2 = sessionHeaderValue.indexOf(";");
            String sessionId = sessionHeaderValue.substring(pos1 + 1, pos2);
            thisUri = this.host + this.requestUrl + ";jsessionid=" + sessionId + "?" + paramString;
        } else {
            thisUri = this.host + this.requestUrl + "?" + paramString;
        }
        //String sessionHeaderValue = sessionHeader.getValue();
        //int pos1 = sessionHeaderValue.indexOf("=");
        //int pos2 = sessionHeaderValue.indexOf(";");
        //String sessionId = sessionHeaderValue.substring(pos1 + 1, pos2);
        //System.out.println("sessionId: " + sessionId);
        //String thisUri = this.host + this.requestUrl + ";jsessionid=" + sessionId + "?"  + paramString;
        //String thisUri = this.host + this.requestUrl + "?"  + paramString;
        System.out.println("thisUri: " + thisUri);

        HttpGet req = new HttpGet(thisUri);
        if (sessionHeader != null) {
            req.setHeader(sessionHeader);
        }

        String responseBody = client.execute(req, responseHandler, localContext);
        /*
        entity = rsp.getEntity();
                
        System.out.println("----------------------------------------");
        System.out.println(rsp.getStatusLine());
        Header[] headers = rsp.getAllHeaders();
        for (int i=0; i<headers.length; i++) {
        System.out.println(headers[i]);
        }
        System.out.println("----------------------------------------");
                
        if (entity != null) {
        System.out.println(EntityUtils.toString(rsp.getEntity()));
        }
        */
    } catch (HttpResponseException e) {
        System.out.println(e.getMessage());
    } catch (IOException e) {
        System.out.println(e.getMessage());
    } finally {
        // If we could be sure that the stream of the entity has been
        // closed, we wouldn't need this code to release the connection.
        // However, EntityUtils.toString(...) can throw an exception.

        // if there is no entity, the connection is already released
        try {
            if (entity != null)
                entity.consumeContent(); // release connection gracefully
        } catch (IOException e) {
            System.out.println("in 'finally'  " + e.getMessage());
        }

    }
    return;
}

From source file:com.streamsets.stage.destination.waveanalytics.WaveAnalyticsTarget.java

private void runDataflow(String dataflowId) throws IOException {
    try {//  w ww  .ja va2s . co m
        HttpResponse res = Request.Put(restEndpoint + String.format(startDataflow, dataflowId))
                .addHeader("Authorization", "OAuth " + connection.getConfig().getSessionId()).execute()
                .returnResponse();

        int statusCode = res.getStatusLine().getStatusCode();
        String content = EntityUtils.toString(res.getEntity());

        LOG.info("PUT dataflow with result {} content {}", statusCode, content);
    } catch (HttpResponseException e) {
        LOG.error("PUT dataflow with result {} {}", e.getStatusCode(), e.getMessage());
        throw e;
    }
}

From source file:com.streamsets.stage.destination.waveanalytics.WaveAnalyticsTarget.java

private void putDataflowJson(String dataflowId, String payload) throws IOException {
    try {//  w  w w .  j ava2  s  . c  o m
        HttpResponse res = Request.Patch(restEndpoint + String.format(dataflowJson, dataflowId))
                .addHeader("Authorization", "OAuth " + connection.getConfig().getSessionId())
                .bodyString(payload, ContentType.APPLICATION_JSON).execute().returnResponse();

        int statusCode = res.getStatusLine().getStatusCode();
        String content = EntityUtils.toString(res.getEntity());

        LOG.info("PATCH dataflow with result {} content {}", statusCode, content);
    } catch (HttpResponseException e) {
        LOG.error("PATCH dataflow with result {} {}", e.getStatusCode(), e.getMessage());
        throw e;
    }
}