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

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

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:gov.nih.nci.caxchange.messaging.SpecimenIntegrationTest.java

private void createSpecimenForUpdationOfInvalidQty() {
    try {/* w ww. j a va 2s.co  m*/
        final HttpPost httppost = new HttpPost(transcendCaxchangeServiceUrl);
        String xmlString = getInsertSpecimenXMLStr();
        xmlString = xmlString.replaceAll("102", "102_INV_QTY");
        final StringEntity reqentity = new StringEntity(xmlString);
        httppost.setEntity(reqentity);
        httppost.setHeader(HttpHeaders.CONTENT_TYPE, XMLTEXT);

        final HttpResponse response = httpclient.execute(httppost);
        final HttpEntity entity = response.getEntity();

        String createdXML = null;

        if (entity != null) {
            createdXML = EntityUtils.toString(entity);
            Assert.assertEquals(true, createdXML.contains("<responseStatus>SUCCESS</responseStatus>"));
        }
    } catch (ClientProtocolException e) {
        Assert.fail(e.getMessage());
    } catch (IllegalStateException e) {
        Assert.fail(e.getMessage());
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }
}

From source file:com.lenovo.h2000.services.LicenseServiceImpl.java

@Override
public String upload(byte[] fileBytes, Map<String, String> headers) throws Exception {
    Map<String, String> params = new HashMap<String, String>();

    CloseableHttpClient httpClient = HttpClients.createDefault();
    HttpPost httpPost = new HttpPost(
            HttpConfig.parseBaseUrl(headers) + "license/import" + "?" + TypeUtil.mapToString(params));

    String responseBody = "";
    DataInputStream in = null;//from   w  ww  .  java 2 s  .  c  o  m
    try {

        ByteArrayEntity requestEntity = new ByteArrayEntity(fileBytes);
        requestEntity.setContentEncoding("UTF-8");
        requestEntity.setContentType("application/octet-stream");
        httpPost.setEntity(requestEntity);
        HttpResponse response = httpClient.execute(httpPost);
        response.setHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8");
        HttpEntity responseEntity = response.getEntity();
        responseBody = EntityUtils.toString(responseEntity);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        _logger.error("throwing HttpClientUtil.doPost ClientProtocolException with " + e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        _logger.error("throwing HttpClientUtil.doPost IOException with " + e.getMessage());
    } finally {
        httpClient.close();
        if (in != null) {
            in.close();
        }
    }
    return responseBody;
}

From source file:com.liato.bankdroid.banking.banks.sebkort.SEBKortBase.java

@Override
public Urllib login() throws LoginException, BankException {
    try {/*w  w w  . j  ava 2s  .  c o  m*/
        LoginPackage lp = preLogin();
        urlopen.addHeader("Origin", String.format("https://%s", mApiBase));
        urlopen.addHeader("Referer",
                String.format("https://%s/nis/m/%s/external/t/login/index", mApiBase, mProviderPart));
        urlopen.addHeader("X-Requested-With", "XMLHttpRequest");
        List<NameValuePair> postData = lp.getPostData();
        postData.remove(mParamsTarget);
        postData.remove(mParamsErrorTarget);
        postData.add(
                new BasicNameValuePair("target", String.format("/nis/m/%s/login/loginSuccess", mProviderPart)));
        postData.add(new BasicNameValuePair("errorTarget",
                String.format("/nis/m/%s/external/login/loginError", mProviderPart)));

        LoginResponse r = mObjectMapper.readValue(urlopen.openStream(lp.getLoginTarget(), postData, true),
                LoginResponse.class);
        if ("Failure".equalsIgnoreCase(r.getReturnCode())) {
            throw new LoginException(
                    !TextUtils.isEmpty(r.getMessage()) ? Html.fromHtml(r.getMessage()).toString()
                            : res.getText(R.string.invalid_username_password).toString());
        }
    } catch (ClientProtocolException e) {
        throw new BankException(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        throw new BankException(e.getMessage());
    }
    return urlopen;
}

From source file:gov.nih.nci.caxchange.messaging.SpecimenIntegrationTest.java

/**
 * Testcase for Update Specimen when Available quantity is greater than Initial Quantity
 *///from w  w w .  j  av  a 2s .  c  om
@Test
public void updateSpecimensInvalidAvailableQtyXMLStr() {
    try {
        createSpecimenForUpdationOfInvalidQty();

        final HttpPost httppost = new HttpPost(transcendCaxchangeServiceUrl);
        final StringEntity reqentity = new StringEntity(getUpdateSpecimenInvalidAvailableQtyXMLStr());
        httppost.setEntity(reqentity);
        httppost.setHeader(HttpHeaders.CONTENT_TYPE, XMLTEXT);

        final HttpResponse response = httpclient.execute(httppost);
        final HttpEntity entity = response.getEntity();

        String updatedXML = null;

        if (entity != null) {
            updatedXML = EntityUtils.toString(entity);
            Assert.assertEquals(true, updatedXML.contains("FAILURE"));
        }
    } catch (ClientProtocolException e) {
        Assert.fail(e.getMessage());
    } catch (IllegalStateException e) {
        Assert.fail(e.getMessage());
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }
}

From source file:com.prasanna.android.http.SecureHttpHelper.java

public Bitmap getImage(final String absoluteUrl) {
    if (absoluteUrl != null) {
        try {//from w  w  w.j  a va2 s  .  c  om
            HttpResponse response = createSecureHttpClient().execute(getHttpGetObject(absoluteUrl));
            return getBitmap(response);
        } catch (ClientProtocolException e) {
            LogWrapper.e(TAG, e.getMessage());
        } catch (IOException e) {
            LogWrapper.e(TAG, e.getMessage());
        }

        throw new ClientException(ClientErrorCode.HTTP_REQ_ERROR);
    }

    return null;
}

From source file:gov.nih.nci.caxchange.messaging.SpecimenIntegrationTest.java

/**
 * Testcase for Update Specimen//www .j av  a2  s .  com
 */
@Test
public void updateSpecimen() {
    try {
        // Create the Specimen for which has to be updated.
        createSpecimenForUpdation();

        final HttpPost httppost = new HttpPost(transcendCaxchangeServiceUrl);
        final StringEntity reqentity = new StringEntity(getUpdateSpecimenXMLStr());
        httppost.setEntity(reqentity);
        httppost.setHeader(HttpHeaders.CONTENT_TYPE, XMLTEXT);

        final HttpResponse response = httpclient.execute(httppost);
        final HttpEntity entity = response.getEntity();

        String updatedXML = null;

        if (entity != null) {
            updatedXML = EntityUtils.toString(entity);
            Assert.assertEquals(true, updatedXML.contains("<responseStatus>SUCCESS</responseStatus>"));
        }
    } catch (ClientProtocolException e) {
        Assert.fail(e.getMessage());
    } catch (IllegalStateException e) {
        Assert.fail(e.getMessage());
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }
}

From source file:com.mnxfst.testing.activities.http.HTTPRequestActivity.java

/**
 * @see com.mnxfst.testing.activities.TSPlanActivity#execute(com.mnxfst.testing.plan.ctx.ITSPlanExecutionContext)
 *//*from w w  w. j  av  a2  s.c om*/
public TSPlanExecutionContext execute(TSPlanExecutionContext ctx) throws TSPlanActivityExecutionException {

    // receives the http response
    HttpResponse response = null;
    try {

        if (this.method.equalsIgnoreCase("get")) {
            response = sendGETRequest(header);
        } else {
            // TODO
            response = sendPOSTRequest(null, header);
        }
    } catch (ClientProtocolException e) {
        throw new TSPlanActivityExecutionException(
                "Failed to execute '" + this.method + "' request. Error: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new TSPlanActivityExecutionException(
                "Failed to execute '" + this.method + "' request. Error: " + e.getMessage(), e);
    }

    try {
        String content = EntityUtils.toString(response.getEntity());
        ctx.addContextValue(contextExportVariableResponseContent, content, ExecutionContextValueType.RUN);
    } catch (IOException e) {
        e.printStackTrace(); // TODO handle - we should log this instead of throwing an exception
    } finally {
        try {
            clientConnection.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return ctx;
}

From source file:eu.skillpro.ams.pscm.connector.amsservice.ui.UpdateRegisteredSEEsHandler.java

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    try {//from   www  .  j av a 2s .c o  m
        List<SEE> registeredSEEs = new ArrayList<>();
        for (SEE see : SkillproService.getSkillproProvider().getSEERepo()) {
            if (see.getMESNodeID() != null || !see.getMESNodeID().isEmpty()) {
                registeredSEEs.add(see);
            }
        }
        //can actually be done in the first for-loop, but let's just leave it like this for now
        for (SEE see : registeredSEEs) {
            updateSEE(see);
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        MessageDialog.open(MessageDialog.ERROR, HandlerUtil.getActiveShell(event), "Protocol exception",
                e.getMessage(), SWT.SHEET);
    } catch (IOException e) {
        e.printStackTrace();
        MessageDialog.open(MessageDialog.ERROR, HandlerUtil.getActiveShell(event), "IOException exception",
                e.getMessage(), SWT.SHEET);
    }
    return null;
}

From source file:org.jboss.arquillian.android.drone.impl.SelendroidHelper.java

/**
 * Waits for Selendroid start. After installation and execution of instrumentation command, we repeatedly send http request
 * to status page to get response code of 200 - server is up and running and we can proceed safely.
 *///www.  j  av a2  s  . c  o m
public void waitForServerHTTPStart() {
    HttpClient httpClient = new DefaultHttpClient();

    httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, SOCKET_TIME_OUT_SECONDS * 1000);
    httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
            CONNECTION_TIME_OUT_SECONDS * 1000);

    HttpGet httpGet = new HttpGet(getSelendroidStatusURI());

    boolean connectionSuccess = false;

    for (int i = NUM_CONNECTION_RETIRES; i > 0; i--) {
        try {
            HttpResponse response = httpClient.execute(httpGet);
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == 200) {
                connectionSuccess = true;
                break;
            }
            logger.log(Level.INFO,
                    "Response was not 200, response was: " + statusCode + ". Repeating " + i + " times.");
        } catch (ClientProtocolException e) {
            logger.log(Level.WARNING, e.getMessage());
        } catch (IOException e) {
            logger.log(Level.WARNING, e.getMessage());
        }
    }

    httpClient.getConnectionManager().shutdown();

    if (!connectionSuccess) {
        throw new AndroidExecutionException("Unable to get successful connection from Selendroid http server.");
    }
}