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:org.cloudsimulator.controller.BusinessConfigurationController.java

public void sendXmlRdfOfBusinessConfigurationToKB() {
    ResponseMessageString responseMessage;
    hideSendForm();/*from  ww w. j a va 2s . c  om*/
    try {
        responseMessage = KBDAO.sendXMLToKB("PUT", this.ipOfKB, "businessConfiguration",
                this.businessConfiguration.getLocalUri(), this.createdXmlRdfBusinessConfiguration);

        if (responseMessage != null) {
            if (responseMessage.getResponseCode() < 400) {
                this.sendDone = "done";
            } else {
                this.sendDone = "error";
            }

            if (responseMessage.getResponseBody() != null) {
                this.alertMessage = "<strong>Response Code </strong>: " + responseMessage.getResponseCode()
                        + " <strong>Reason</strong>: " + responseMessage.getReason() + "<br />"
                        + responseMessage.getResponseBody().replace("\n", "<br />");
            } else {
                this.alertMessage = "<strong>Response Code </strong>: " + responseMessage.getResponseCode()
                        + " <strong>Reason</strong>: " + responseMessage.getReason() + "<br />";
            }
        }
    } catch (ClientProtocolException e) {
        LOGGER.error(e.getMessage(), e);
        this.sendDone = "exception";
        this.alertMessage = e.toString();
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
        this.sendDone = "exception";
        this.alertMessage = e.toString();
    }
}

From source file:com.liato.bankdroid.banking.banks.TestBank.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());
    }/*from   w w w . j a  va2 s  .  c  o m*/
    urlopen = login();
    String response = null;
    Matcher matcher;
    try {

        response = urlopen.open("http://www.nullbyte.eu/bankdroid/tests/testbank/accounts.htm");
        matcher = reAccounts.matcher(response);
        while (matcher.find()) {
            /*
             * Capture groups:
             * GROUP                EXAMPLE DATA
             * 1: Name              Sparkonto
             * 2: Amount            83553,70
             * 3: ID                1
             * 4: Type              trans|fund
             *  
             */
            Account acc = new Account(Html.fromHtml(matcher.group(1)).toString().trim(),
                    Helpers.parseBalance(matcher.group(2)),
                    ("fund".equals(matcher.group(4)) ? "f:" : "") + matcher.group(3).trim());
            if ("fund".equals(matcher.group(4))) {
                acc.setType(Account.FUNDS);
            } else {
                balance = balance.add(Helpers.parseBalance(matcher.group(3)));
            }
            accounts.add(acc);
        }

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

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

@Override
public Urllib login() throws LoginException, BankException {
    try {//from   www.j  a v a2  s  . c om
        LoginPackage lp = preLogin();
        response = urlopen.open(lp.getLoginTarget(), lp.getPostData());
        if (!response.contains("passwordLoginOK")) {
            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.RequestUtilsTest.java

@Test
public void testPostRequestClientProtocolException() throws Exception {
    JsonObject payload = new JsonObject();
    payload.addProperty("foo", "bar/baz");

    Exception e = new ClientProtocolException("catch me");

    Capture<HttpUriRequest> requestCapture = newCapture();
    Capture<ResponseHandler<JsonObject>> handlerCapture = newCapture();
    expect(httpClient.execute(capture(requestCapture), capture(handlerCapture))).andThrow(e);
    httpClient.close();/*ww w . j  av a 2s  .com*/

    replayAll();

    RequestUtils requestUtils = createRequestUtilsPartialMock();
    try {
        requestUtils.post("pathFoo", payload);
        failBecauseExceptionWasNotThrown(ClientProtocolException.class);
    } catch (ClientProtocolException actual) {
        assertThat(actual.getMessage()).contains("catch me");
    }

    verifyAll();

    verifyPostRequest(requestCapture);
    verifyHandler(handlerCapture);
}

From source file:com.liato.bankdroid.banking.banks.BrummerKF.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());
    }/*from  w  w  w.j a  v  a2  s  . c om*/

    urlopen = login();
    Matcher matcher;
    try {
        response = urlopen.open("https://www.brummer.se/sv/online/privat/");
        matcher = reAccounts.matcher(response);

        while (matcher.find()) {
            /*
             * 1: Kontonamn
             * 2: Kontonummer
             * 3: Avkastning under ret
             * 4: Genomsnittlig rlig avkastning sedan start
             * 5: Avkastning sedan start
             * 6: Marknadsvrde (kronor)
             */

            accounts.add(new Account(Html.fromHtml(matcher.group(1)).toString().trim(),
                    Helpers.parseBalance(matcher.group(6).trim()), matcher.group(2)));

            balance = balance.add(Helpers.parseBalance(matcher.group(6)));
        }
        if (accounts.isEmpty()) {
            throw new BankException(res.getText(R.string.no_accounts_found).toString());
        }
    } catch (ClientProtocolException e) {
        throw new BankException(e.getMessage());
    } catch (IOException e) {
        throw new BankException(e.getMessage());
    }
}

From source file:com.liato.bankdroid.banking.banks.Zidisha.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());
    }//from   www .j a  v a 2 s  . com

    urlopen = login();
    Matcher matcher;
    try {
        response = urlopen.open("https://www.zidisha.org/index.php?p=19");
        matcher = reAccounts.matcher(response);

        while (matcher.find()) {
            /*
             * 1: Funds uploaded
             * 2: Available for withdrawal
             * 3: Lent by me
             * 4: Total Impact
             */
            Account insattningar = new Account("Insttningar", Helpers.parseBalance(matcher.group(1)),
                    "insattningar");
            Account tillgangligt = new Account("Tillgngligt", Helpers.parseBalance(matcher.group(2)),
                    "tillgangligt");
            Account utlanat = new Account("Utlnat", Helpers.parseBalance(matcher.group(3)), "utlanat");
            Account balans = new Account("Pverkan", Helpers.parseBalance(matcher.group(4)), "impact");

            insattningar.setCurrency("USD");
            tillgangligt.setCurrency("USD");
            utlanat.setCurrency("USD");
            balans.setCurrency("USD");

            accounts.add(insattningar);
            accounts.add(tillgangligt);
            accounts.add(utlanat);
            accounts.add(balans);

            balance = balance.add(Helpers.parseBalance(matcher.group(4)));
        }
        if (accounts.isEmpty()) {
            throw new BankException(res.getText(R.string.no_accounts_found).toString());
        }
    } catch (ClientProtocolException e) {
        throw new BankException(e.getMessage());
    } catch (IOException e) {
        throw new BankException(e.getMessage());
    }
}

From source file:es.pentalo.apps.RBPiCameraControl.API.RBPiCamera.java

synchronized public String startStreaming(List<Command> commands) {
    try {//  ww  w  . ja  va2 s .  co m
        HttpEntity entity = getEntityPost(mBaseUrl + "api/video/streaming/", commands);
        if (entity == null)
            return null;

        String str = EntityUtils.toString(entity);

        Log.d(TAG, str);
        return getStreamingURL(str);

    } catch (ClientProtocolException e) {
        Log.e(TAG, e.getMessage());
        return null;

    } catch (IOException e) {
        Log.e(TAG, e.getMessage());
        return null;

    }
}

From source file:com.adam.aslfms.service.NPNotifier.java

/**
 * Connects to Last.fm servers and requests a Now Playing notification of
 * <code>track</code>. If an error occurs, exceptions are thrown.
 * // w ww .  j  a v a 2  s.c  o  m
 * @param track
 *            the track to send as notification
 * @throws BadSessionException
 *             means that a new handshake is needed
 * @throws TemporaryFailureException
 * @throws UnknownResponseException
 *             {@link UnknownResponseException}
 * 
 */
public void notifyNowPlaying(Track track, HandshakeResult hInfo)
        throws BadSessionException, TemporaryFailureException {
    Log.d(TAG, "Notifying now playing: " + getNetApp().getName());

    Log.d(TAG, getNetApp().getName() + ": " + track.toString());

    DefaultHttpClient http = new DefaultHttpClient();
    HttpPost request = new HttpPost(hInfo.nowPlayingUri);

    List<BasicNameValuePair> data = new LinkedList<BasicNameValuePair>();

    data.add(new BasicNameValuePair("s", hInfo.sessionId));
    data.add(new BasicNameValuePair("a", track.getArtist()));
    data.add(new BasicNameValuePair("b", track.getAlbum()));
    data.add(new BasicNameValuePair("t", track.getTrack()));
    data.add(new BasicNameValuePair("l", Integer.toString(track.getDuration())));
    data.add(new BasicNameValuePair("n", track.getTrackNr()));
    data.add(new BasicNameValuePair("m", track.getMbid()));

    try {
        request.setEntity(new UrlEncodedFormEntity(data, "UTF-8"));
        ResponseHandler<String> handler = new BasicResponseHandler();
        String response = http.execute(request, handler);
        if (response.startsWith("OK")) {
            Log.i(TAG, "Nowplaying success: " + getNetApp().getName());
        } else if (response.startsWith("BADSESSION")) {
            throw new BadSessionException("Nowplaying failed because of badsession");
        } else {
            throw new TemporaryFailureException("NowPlaying failed weirdly: " + response);
        }

    } catch (ClientProtocolException e) {
        throw new TemporaryFailureException(TAG + ": " + e.getMessage());
    } catch (IOException e) {
        throw new TemporaryFailureException(TAG + ": " + e.getMessage());
    } finally {
        http.getConnectionManager().shutdown();
    }
}

From source file:com.normalexception.app.rx8club.task.AdminTask.java

@Override
protected Void doInBackground(Void... params) {
    try {/*from  w ww  .j  a  va 2  s . co m*/
        Log.d(TAG, progressText.get(doType));

        if (this.doType == DELETE_THREAD) {
            HtmlFormUtils.adminTypePost(doType, token, thread, deleteResponse);
        } else
            HtmlFormUtils.adminTypePost(doType, token, thread, null);

        if (this.doType == MOVE_THREAD) {
            String response = HtmlFormUtils.getResponseUrl();
            Log.d(TAG, "Response: " + response);

            Document doc = Jsoup.parse(HtmlFormUtils.getResponseContent());

            threadTitle = HtmlFormUtils.getInputElementValueByName(doc, "title");
            Log.d(TAG, "Thread Title: " + threadTitle);

            Elements selects = doc.select("select[name=destforumid] > option");
            for (Element select : selects) {
                selectOptions.put(select.text(), Integer.parseInt(select.attr("value")));
            }

            Log.d(TAG, "Parsed " + selectOptions.keySet().size() + " options");
        }
    } catch (ClientProtocolException e) {
        Log.e(TAG, e.getMessage(), e);
    } catch (IOException e) {
        Log.e(TAG, e.getMessage(), e);
    }
    return null;
}

From source file:pro.jariz.reisplanner.api.NSTask.java

protected String doReq(String... uri) {
    HttpClient httpclient = new DefaultHttpClient();
    HttpResponse response;/*from  w ww  .j a v  a 2  s.  c  o  m*/
    String responseString = null;
    try {
        HttpGet get = new HttpGet(uri[0]);
        get.setHeader("Authorization",
                "Basic " + Base64.encodeToString((username + ":" + password).getBytes(), Base64.NO_WRAP));
        response = httpclient.execute(get);
        StatusLine statusLine = response.getStatusLine();
        if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            response.getEntity().writeTo(out);
            out.close();
            responseString = out.toString();
        } else {
            //Closes the connection.
            response.getEntity().getContent().close();
            throw new IOException(statusLine.getReasonPhrase());
        }
    } catch (ClientProtocolException e) {
        NSTask.LastExceptionMessage = e.getMessage();
        NSAPI.Error(e);
        return null;
    } catch (IOException e) {
        NSTask.LastExceptionMessage = e.getMessage();
        NSAPI.Error(e);
        return null;
    }
    return responseString;
}