Example usage for java.io UnsupportedEncodingException getMessage

List of usage examples for java.io UnsupportedEncodingException getMessage

Introduction

In this page you can find the example usage for java.io UnsupportedEncodingException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.nimbits.user.GoogleAuthentication.java

private Cookie getAuthCookie(final String gaeAppBaseUrl, final String gaeAppLoginUrl, final String authToken)
        throws NimbitsException {
    final DefaultHttpClient httpClient = new DefaultHttpClient();
    Cookie retObj = null;//from   w ww.j  av a2s. c  o m
    final String cookieUrl;
    try {
        cookieUrl = gaeAppLoginUrl + "?continue=" + URLEncoder.encode(gaeAppBaseUrl, Const.CONST_ENCODING)
                + "&auth=" + URLEncoder.encode(authToken, Const.CONST_ENCODING);

        //
        //      String cookieUrl = gaeAppLoginUrl + "?continue="
        //      + URLEncoder.encode(gaeAppBaseUrl,Const.CONST_ENCODING) + "&auth=" + authToken;
        //httpClient.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false);
        final HttpGet httpget = new HttpGet(cookieUrl);
        final HttpResponse response = httpClient.execute(httpget);

        if (response.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_OK
                || response.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_NO_CONTENT) {

            for (final Cookie cookie : httpClient.getCookieStore().getCookies()) {
                if (cookie.getName().equals(Parameters.acsid.getText())) {
                    retObj = cookie;
                    break;
                }

            }
        } else if (response.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_INTERNAL_ERROR) {
            throw new NimbitsException("invalid token");

        } else {
            throw new NimbitsException(
                    "Error getting cookie: status code:" + response.getStatusLine().getStatusCode());
        }

        httpClient.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true);
    } catch (UnsupportedEncodingException e) {
        throw new NimbitsException(e.getMessage());
    } catch (ClientProtocolException e) {
        throw new NimbitsException(e.getMessage());
    } catch (IOException e) {
        throw new NimbitsException(e.getMessage());
    }

    return retObj;

}

From source file:com.sahana.geosmser.view.ReverseGeocoderView.java

public GeoPoint getGeoByAddress(String searchAddress) {
    GeoPoint mGeoPoint = null;//from   ww  w  . j a v a2  s  . c  o m
    StringBuilder responseBuilder = new StringBuilder();

    try {
        URL url = new URL("http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q="
                + URLEncoder.encode(searchAddress, "UTF-8"));
        // + "&key=ABQIAAAAi0Qn28OD_1M-BbLsxPRwYBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSdXKLoXxi1NXTY1EpEtAahu1gPgg");
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String inputLine;
        while ((inputLine = in.readLine()) != null) {
            responseBuilder.append(inputLine);
        }
        in.close();
    } catch (MalformedURLException me) {
        // me.printStackTrace();
        Toast.makeText(mContext, me.getMessage(), Toast.LENGTH_SHORT).show();
    } catch (UnsupportedEncodingException ue) {
        // ue.printStackTrace();
        Toast.makeText(mContext, ue.getMessage(), Toast.LENGTH_SHORT).show();
    } catch (IOException ie) {
        // ie.printStackTrace();
        Toast.makeText(mContext, ie.getMessage(), Toast.LENGTH_SHORT).show();
    }
    try {
        // JSONObject json = new JSONObject(responseBuilder.toString());
        JSONObject json = (JSONObject) new JSONTokener(responseBuilder.toString()).nextValue();
        JSONObject responseData = json.getJSONObject("responseData");
        JSONObject viewport = responseData.getJSONObject("viewport");
        JSONObject center = viewport.getJSONObject("center");
        Log.d(WhereToMeet.TAG, "" + viewport.toString());
        mGeoPoint = new GeoPoint((int) center.getDouble("lat"), (int) center.getDouble("lng"));
    } catch (JSONException e) {
        Log.d(WhereToMeet.TAG, "" + e.getMessage());
    }

    return mGeoPoint;

}

From source file:com.github.lpezet.antiope.dao.DefaultHttpRequestFactory.java

/**
 * Utility function for creating a new StringEntity and wrapping any errors
 * as an TSGClientException.//from w w  w  .  j ava2  s.  co  m
 * 
 * @param s
 *            The string contents of the returned HTTP entity.
 * @return A new StringEntity with the specified contents.
 */
private HttpEntity newStringEntity(String s) {
    try {
        return new StringEntity(s);
    } catch (UnsupportedEncodingException e) {
        throw new APIClientException("Unable to create HTTP entity: " + e.getMessage(), e);
    }
}

From source file:org.commonjava.couch.io.CouchHttpClient.java

public HttpResponse executeHttpWithResponse(final HttpRequestBase request, final Integer expectedStatus,
        final Object failureMessage) throws CouchDBException {
    final String url = request.getURI().toString();

    boolean failed = false;
    try {//from   ww  w.java  2 s  . com
        final HttpResponse response = client.execute(request);
        final StatusLine statusLine = response.getStatusLine();
        if (expectedStatus != null && statusLine.getStatusCode() != expectedStatus) {
            final HttpEntity entity = response.getEntity();
            final CouchError error = serializer.toError(entity);
            throw new CouchDBException("%s: %s.\nHTTP Response: %s\nError: %s", failureMessage, url, statusLine,
                    error);
        }

        return response;
    } catch (final UnsupportedEncodingException e) {
        failed = true;
        throw new CouchDBException("%s: %s.\nReason: %s", e, failureMessage, url, e.getMessage());
    } catch (final ClientProtocolException e) {
        failed = true;
        throw new CouchDBException("%s: %s.\nReason: %s", e, failureMessage, url, e.getMessage());
    } catch (final IOException e) {
        failed = true;
        throw new CouchDBException("%s: %s.\nReason: %s", e, failureMessage, url, e.getMessage());
    } finally {
        if (failed) {
            cleanup(request);
        }
    }
}

From source file:org.whispercomm.c2dm4j.impl.C2dmHttpPost.java

private void initPostEntity(Message message) {
    List<NameValuePair> params = new ArrayList<NameValuePair>();

    addParam(params, REGISTRATION_ID, message.getRegistrationId());
    addParam(params, COLLAPSE_ID, message.getCollapseKey());
    if (message.delayWhileIdle())
        addParam(params, DELAY_WHILE_IDLE);

    Map<String, String> data = message.getData();
    for (String key : data.keySet()) {
        addParam(params, DATA_KEY_PREFIX + key, data.get(key));
    }/*w  ww.j  a v  a2s. c o m*/

    try {
        this.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        /*
         * This should not be a checked exception. Good testing will catch
         * if an unsupported encoding is requested.
         */
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:net.formio.upload.MultipartRequestPreprocessor.java

private void addItemValue(List<String> list, FileItem item) {
    try {/* w  w  w . ja va  2  s.  c o  m*/
        list.add(item.getString(defaultEncoding));
    } catch (UnsupportedEncodingException ex) {
        throw new EncodingException(ex.getMessage(), ex);
    }
}

From source file:org.eclipse.californium.proxy.resources.ProxyHttpClientResource.java

@Override
public Response forwardRequest(Request request) {
    final Request incomingCoapRequest = request;

    // check the invariant: the request must have the proxy-uri set
    if (!incomingCoapRequest.getOptions().hasProxyUri()) {
        LOGGER.warning("Proxy-uri option not set.");
        return new Response(ResponseCode.BAD_OPTION);
    }/*from  w  w w .  jav  a 2s. c om*/

    // remove the fake uri-path // TODO: why? still necessary in new Cf?
    incomingCoapRequest.getOptions().clearUriPath();
    ; // HACK

    // get the proxy-uri set in the incoming coap request
    URI proxyUri;
    try {
        String proxyUriString = URLDecoder.decode(incomingCoapRequest.getOptions().getProxyUri(), "UTF-8");
        proxyUri = new URI(proxyUriString);
    } catch (UnsupportedEncodingException e) {
        LOGGER.warning("Proxy-uri option malformed: " + e.getMessage());
        return new Response(CoapTranslator.STATUS_FIELD_MALFORMED);
    } catch (URISyntaxException e) {
        LOGGER.warning("Proxy-uri option malformed: " + e.getMessage());
        return new Response(CoapTranslator.STATUS_FIELD_MALFORMED);
    }

    // get the requested host, if the port is not specified, the constructor
    // sets it to -1
    HttpHost httpHost = new HttpHost(proxyUri.getHost(), proxyUri.getPort(), proxyUri.getScheme());

    HttpRequest httpRequest = null;
    try {
        // get the mapping to http for the incoming coap request
        httpRequest = HttpTranslator.getHttpRequest(incomingCoapRequest);
        LOGGER.finer("Outgoing http request: " + httpRequest.getRequestLine());
    } catch (InvalidFieldException e) {
        LOGGER.warning("Problems during the http/coap translation: " + e.getMessage());
        return new Response(CoapTranslator.STATUS_FIELD_MALFORMED);
    } catch (TranslationException e) {
        LOGGER.warning("Problems during the http/coap translation: " + e.getMessage());
        return new Response(CoapTranslator.STATUS_TRANSLATION_ERROR);
    }

    ResponseHandler<Response> httpResponseHandler = new ResponseHandler<Response>() {
        @Override
        public Response handleResponse(HttpResponse httpResponse) throws ClientProtocolException, IOException {
            long timestamp = System.nanoTime();
            LOGGER.finer("Incoming http response: " + httpResponse.getStatusLine());
            // the entity of the response, if non repeatable, could be
            // consumed only one time, so do not debug it!
            // System.out.println(EntityUtils.toString(httpResponse.getEntity()));

            // translate the received http response in a coap response
            try {
                Response coapResponse = HttpTranslator.getCoapResponse(httpResponse, incomingCoapRequest);
                coapResponse.setTimestamp(timestamp);
                return coapResponse;
            } catch (InvalidFieldException e) {
                LOGGER.warning("Problems during the http/coap translation: " + e.getMessage());
                return new Response(CoapTranslator.STATUS_FIELD_MALFORMED);
            } catch (TranslationException e) {
                LOGGER.warning("Problems during the http/coap translation: " + e.getMessage());
                return new Response(CoapTranslator.STATUS_TRANSLATION_ERROR);
            }
        }
    };

    // accept the request sending a separate response to avoid the timeout
    // in the requesting client
    LOGGER.finer("Acknowledge message sent");

    Response coapResponse = null;
    try {
        // execute the request
        coapResponse = HTTP_CLIENT.execute(httpHost, httpRequest, httpResponseHandler, null);
    } catch (IOException e) {
        LOGGER.warning("Failed to get the http response: " + e.getMessage());
        return new Response(ResponseCode.INTERNAL_SERVER_ERROR);
    }

    return coapResponse;
}

From source file:fr.paris.lutece.portal.business.user.AdminUserFilter.java

/**
 * Build url attributes//  w  ww  .ja  v a 2s.c  o  m
 * @param url The url item
 */
public void setUrlAttributes(UrlItem url) {
    url.addParameter(PARAMETER_SEARCH_IS_SEARCH, Boolean.TRUE.toString());
    url.addParameter(PARAMETER_SEARCH_USER_LEVEL, _nUserLevel);
    url.addParameter(PARAMETER_SEARCH_STATUS, _nStatus);

    try {
        url.addParameter(PARAMETER_SEARCH_ACCESS_CODE,
                URLEncoder.encode(_strAccessCode, AppPropertiesService.getProperty(PROPERTY_ENCODING_URL)));
        url.addParameter(PARAMETER_SEARCH_LAST_NAME,
                URLEncoder.encode(_strLastName, AppPropertiesService.getProperty(PROPERTY_ENCODING_URL)));
        url.addParameter(PARAMETER_SEARCH_FIRST_NAME,
                URLEncoder.encode(_strFirstName, AppPropertiesService.getProperty(PROPERTY_ENCODING_URL)));
        url.addParameter(PARAMETER_SEARCH_EMAIL,
                URLEncoder.encode(_strEmail, AppPropertiesService.getProperty(PROPERTY_ENCODING_URL)));
    } catch (UnsupportedEncodingException e) {
        AppLogService.error(e.getMessage(), e);
    }
}

From source file:fr.paris.lutece.portal.business.user.AdminUserFilter.java

/**
 * Build url attributes/*from  ww w .j a  v  a  2s .c om*/
 * @return the url attributes
 */
public String getUrlAttributes() {
    StringBuilder sbUrlAttributes = new StringBuilder();
    sbUrlAttributes.append(PARAMETER_SEARCH_IS_SEARCH + CONSTANT_EQUAL + Boolean.TRUE);
    sbUrlAttributes.append(CONSTANT_AMPERSAND + PARAMETER_SEARCH_USER_LEVEL + CONSTANT_EQUAL + _nUserLevel);
    sbUrlAttributes.append(CONSTANT_AMPERSAND + PARAMETER_SEARCH_STATUS + CONSTANT_EQUAL + _nStatus);

    try {
        sbUrlAttributes.append(CONSTANT_AMPERSAND + PARAMETER_SEARCH_ACCESS_CODE + CONSTANT_EQUAL
                + URLEncoder.encode(_strAccessCode, AppPropertiesService.getProperty(PROPERTY_ENCODING_URL)));
        sbUrlAttributes.append(CONSTANT_AMPERSAND + PARAMETER_SEARCH_LAST_NAME + CONSTANT_EQUAL
                + URLEncoder.encode(_strLastName, AppPropertiesService.getProperty(PROPERTY_ENCODING_URL)));
        sbUrlAttributes.append(CONSTANT_AMPERSAND + PARAMETER_SEARCH_FIRST_NAME + CONSTANT_EQUAL
                + URLEncoder.encode(_strFirstName, AppPropertiesService.getProperty(PROPERTY_ENCODING_URL)));
        sbUrlAttributes.append(CONSTANT_AMPERSAND + PARAMETER_SEARCH_EMAIL + CONSTANT_EQUAL
                + URLEncoder.encode(_strEmail, AppPropertiesService.getProperty(PROPERTY_ENCODING_URL)));
    } catch (UnsupportedEncodingException e) {
        AppLogService.error(e.getMessage(), e);
    }

    return sbUrlAttributes.toString();
}

From source file:com.jana.android.net.HttpPostConnection.java

private void updateParams(HttpPost httpPost) {

    if (mParamsMap != null && mParamsMap.size() > 0) {

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(mParamsMap.values());

        try {/*from w ww  .j  av a2s .  c om*/

            httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));

        } catch (UnsupportedEncodingException e) {

            Logger.w("Failure while establishing url connection as unsupported encoding error > "
                    + e.getMessage());

            e.printStackTrace();
        }
    }
}