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:com.seleritycorp.context.RequestResponseHandlerTest.java

@Test
public void testHandleResponseClientErrorNonJson() throws Exception {
    HttpResponse response = mockResponse(400, "nonJsonContentFoo");
    RequestResponseHandler handler = createRequestResponseHandler();

    replayAll();//ww  w  .  j av a  2 s  . c  o m

    try {
        handler.handleResponse(response);
        failBecauseExceptionWasNotThrown(ClientProtocolException.class);
    } catch (ClientProtocolException e) {
        assertThat(e.getMessage()).contains("400");
        assertThat(e.getMessage()).contains("reasonFoo");
        assertThat(e.getMessage()).doesNotContain("nonJsonContentFoo");
    }

    verifyAll();
}

From source file:com.seleritycorp.context.RequestResponseHandlerTest.java

@Test
public void testHandleResponsePartialNonJson() throws Exception {
    HttpResponse response = mockResponse(206, "nonJsonContentFoo");
    RequestResponseHandler handler = createRequestResponseHandler();

    replayAll();/*from   w w w .  j  ava 2  s .c om*/

    try {
        handler.handleResponse(response);
        failBecauseExceptionWasNotThrown(ClientProtocolException.class);
    } catch (ClientProtocolException e) {
        assertThat(e.getMessage()).contains("206");
        assertThat(e.getMessage()).contains("reasonFoo");
        assertThat(e.getMessage()).doesNotContain("nonJsonContentFoo");
    }

    verifyAll();
}

From source file:com.seleritycorp.context.RequestResponseHandlerTest.java

@Test
public void testHandleResponseRedirectNonJson() throws Exception {
    HttpResponse response = mockResponse(302, "nonJsonContentFoo");
    RequestResponseHandler handler = createRequestResponseHandler();

    replayAll();//  w  w  w  . j a  v a  2  s. c  o  m

    try {
        handler.handleResponse(response);
        failBecauseExceptionWasNotThrown(ClientProtocolException.class);
    } catch (ClientProtocolException e) {
        assertThat(e.getMessage()).contains("302");
        assertThat(e.getMessage()).contains("reasonFoo");
        assertThat(e.getMessage()).doesNotContain("nonJsonContentFoo");
    }

    verifyAll();
}

From source file:com.seleritycorp.context.RequestResponseHandlerTest.java

@Test
public void testHandleResponseServerErrorNonJson() throws Exception {
    HttpResponse response = mockResponse(500, "nonJsonContentFoo");
    RequestResponseHandler handler = createRequestResponseHandler();

    replayAll();// w  w  w  .  ja  v  a 2 s  . co  m

    try {
        handler.handleResponse(response);
        failBecauseExceptionWasNotThrown(ClientProtocolException.class);
    } catch (ClientProtocolException e) {
        assertThat(e.getMessage()).contains("500");
        assertThat(e.getMessage()).contains("reasonFoo");
        assertThat(e.getMessage()).doesNotContain("nonJsonContentFoo");
    }

    verifyAll();
}

From source file:com.seleritycorp.context.RequestResponseHandlerTest.java

@Test
public void testHandleResponseClientErrorJsonErrorMessage() throws Exception {
    HttpResponse response = mockResponse(400, "{\"errorMessage\":\"bar\"}");
    RequestResponseHandler handler = createRequestResponseHandler();

    replayAll();//  ww  w . ja v  a 2  s. c  om

    try {
        handler.handleResponse(response);
        failBecauseExceptionWasNotThrown(ClientProtocolException.class);
    } catch (ClientProtocolException e) {
        assertThat(e.getMessage()).contains("400");
        assertThat(e.getMessage()).contains("reasonFoo");
        assertThat(e.getMessage()).contains("bar");
    }

    verifyAll();
}

From source file:org.apache.james.transport.mailets.SerialiseToHTTP.java

private String httpPost(NameValuePair[] data) {

    RequestBuilder requestBuilder = RequestBuilder.post(url);

    if (data.length > 1 && data[1] != null) {
        requestBuilder.addParameter(data[1].getName(), data[1].getValue());
        log(data[1].getName() + "::" + data[1].getValue());
    }//from  ww  w .  j  ava  2 s .  com

    CloseableHttpClient client = HttpClientBuilder.create().build();
    CloseableHttpResponse clientResponse = null;
    try {
        clientResponse = client.execute(requestBuilder.build());

        if (clientResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            log("POST failed: " + clientResponse.getStatusLine());
            return clientResponse.getStatusLine().toString();
        }
        return null;
    } catch (ClientProtocolException e) {
        log("Fatal protocol violation: " + e.getMessage());
        return "Fatal protocol violation: " + e.getMessage();
    } catch (IOException e) {
        log("Fatal transport error: " + e.getMessage());
        return "Fatal transport error: " + e.getMessage();
    } finally {
        IOUtils.closeQuietly(clientResponse);
        IOUtils.closeQuietly(client);
    }
}

From source file:com.liato.bankdroid.banking.banks.Nordea.java

@Override
public Urllib login() throws LoginException, BankException {
    urlopen = new Urllib();
    String response = null;//w  w  w.j av  a 2  s  .c  om
    try {
        LoginPackage lp = preLogin();
        Log.d("BankNordea", "Posting to https://mobil.nordea.se/banking-nordea/nordea-c3/login.html");
        response = urlopen.open(lp.getLoginTarget(), lp.getPostData());
        Log.d("BankNordea", "Url after post: " + urlopen.getCurrentURI());

        if (response.contains("felaktiga uppgifter")) {
            throw new LoginException(res.getText(R.string.invalid_username_password).toString());
        }

    } catch (ClientProtocolException e) {
        throw new BankException(e.getMessage());
    } catch (IOException e) {
        throw new BankException(e.getMessage());
    }
    return urlopen;
}

From source file:com.seleritycorp.context.RequestResponseHandlerTest.java

@Test
public void testHandleResponseClientErrorJsonMarkerless() throws Exception {
    HttpResponse response = mockResponse(400, "{\"bar\":42}");
    RequestResponseHandler handler = createRequestResponseHandler();

    replayAll();//from  w w w  .ja va  2 s. c o  m

    try {
        handler.handleResponse(response);
        failBecauseExceptionWasNotThrown(ClientProtocolException.class);
    } catch (ClientProtocolException e) {
        assertThat(e.getMessage()).contains("400");
        assertThat(e.getMessage()).contains("reasonFoo");
        assertThat(e.getMessage()).doesNotContain("bar");
        assertThat(e.getMessage()).doesNotContain("42");
    }

    verifyAll();
}

From source file:com.seleritycorp.context.RequestResponseHandlerTest.java

@Test
public void testHandleResponseClientErrorJsonErrorObject() throws Exception {
    HttpResponse response = mockResponse(400, "{\"errorCode\":\"bar\", \"foo\":42}");
    RequestResponseHandler handler = createRequestResponseHandler();

    replayAll();/*from   w  ww .  j  av a 2  s. c  o m*/

    try {
        handler.handleResponse(response);
        failBecauseExceptionWasNotThrown(ClientProtocolException.class);
    } catch (ClientProtocolException e) {
        assertThat(e.getMessage()).contains("400");
        assertThat(e.getMessage()).contains("reasonFoo");
        assertThat(e.getMessage()).contains("errorCode");
        assertThat(e.getMessage()).contains("bar");
        assertThat(e.getMessage()).contains("foo");
        assertThat(e.getMessage()).contains("42");
    }

    verifyAll();
}

From source file:com.liato.bankdroid.banking.banks.AbsIkanoPartner.java

@Override
public void update() throws BankException, LoginException, BankChoiceException {
    super.update();
    if (username == null || password == null || username.length() == 0 || password.length() == 0) {
        throw new LoginException(res.getText(R.string.invalid_username_password).toString());
    }// w  ww . jav a2s  . c om

    urlopen = login();
    Document d = Jsoup.parse(response);
    Element element = d.select("#primary-nav > li:eq(1) > a").first();
    if (element != null && element.attr("href") != null) {
        String myAccountUrl = element.attr("href");
        try {
            response = urlopen.open("https://partner.ikanobank.se/" + myAccountUrl);
            d = Jsoup.parse(response);
            Elements es = d.select("#CustomerAccountInformationSpan > span > span");
            int accId = 0;
            for (Element el : es) {
                Element name = el.select("> span > span:eq(0)").first();
                Element balance = el.select("> span:eq(1)").first();
                Element currency = el.select("> span:eq(2)").first();
                if (name != null && balance != null && currency != null) {
                    Account account = new Account(name.text().trim(), Helpers.parseBalance(balance.text()),
                            Integer.toString(accId));
                    account.setCurrency(Helpers.parseCurrency(currency.text(), "SEK"));
                    if (accId > 0) {
                        account.setAliasfor("0");
                    }
                    accounts.add(account);
                    accId++;
                }
            }
            if (accounts.isEmpty()) {
                throw new BankException(res.getText(R.string.no_accounts_found).toString());
            }
            // Use the amount from "Kvar att handla fr" which should be the
            // last account in the list.
            this.balance = accounts.get(accounts.size() - 1).getBalance();
            ArrayList<Transaction> transactions = new ArrayList<Transaction>();
            es = d.select("#ShowCustomerTransactionPurchasesInformationDiv table tr:has(td)");
            for (Element el : es) {
                if (el.childNodeSize() == 6) {
                    Transaction transaction = new Transaction(el.child(0).text().trim(),
                            el.child(1).text().trim(), Helpers.parseBalance(el.child(2).text()));
                    transaction.setCurrency(Helpers.parseCurrency(el.child(3).text().trim(), "SEK"));
                    transactions.add(transaction);
                }
            }
            accounts.get(0).setTransactions(transactions);
        }

        catch (ClientProtocolException e) {
            throw new BankException(e.getMessage());
        } catch (IOException e) {
            throw new BankException(e.getMessage());
        }
    }
    if (accounts.isEmpty()) {
        throw new BankException(res.getText(R.string.no_accounts_found).toString());
    }
    super.updateComplete();
}