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:alpine.servlets.FileSystemResourceServlet.java

@Override
protected StaticResource getStaticResource(HttpServletRequest request) throws IllegalArgumentException {
    final String pathInfo = request.getPathInfo();

    if (pathInfo == null || pathInfo.isEmpty() || "/".equals(pathInfo)) {
        throw new IllegalArgumentException();
    }/*from   w ww .ja v a  2 s .c  o  m*/

    String name = "";
    try {
        name = URLDecoder.decode(pathInfo.substring(1), StandardCharsets.UTF_8.name());
    } catch (UnsupportedEncodingException e) {
        LOGGER.error(e.getMessage());
    }

    final ServletContext context = request.getServletContext();
    final File file = (absolute) ? new File(directory, name)
            : new File(context.getRealPath("/"), name).getAbsoluteFile();

    return !file.exists() ? null : new StaticResource() {
        @Override
        public long getLastModified() {
            return file.lastModified();
        }

        @Override
        public InputStream getInputStream() throws IOException {
            return new FileInputStream(file);
        }

        @Override
        public String getFileName() {
            return file.getName();
        }

        @Override
        public long getContentLength() {
            return file.length();
        }
    };
}

From source file:com.facetime.cloud.server.support.UTF8HttpMessageConverter.java

@Override
protected Long getContentLength(String s, MediaType contentType) {
    if (contentType != null && contentType.getCharSet() != null) {
        Charset charset = contentType.getCharSet();
        try {//from w  w  w . jav  a2s. co  m
            return (long) s.getBytes(charset.name()).length;
        } catch (UnsupportedEncodingException ex) {
            // should not occur
            throw new InternalError(ex.getMessage());
        }
    } else {
        return null;
    }
}

From source file:net.gcolin.httpquery.HttpHandlerImpl.java

@Override
public Request put(String uri, String str) {
    HttpPut put = new HttpPut(uri);
    try {//from   w w  w.j  ava2s .  com
        put.setEntity(new StringEntity(str));
    } catch (UnsupportedEncodingException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, e.getMessage(), e);
    }
    return new RequestImpl(put);
}

From source file:net.gcolin.httpquery.HttpHandlerImpl.java

@Override
public Request post(String uri, String str) {
    HttpPost post = new HttpPost(uri);
    try {/*from   w ww.j a va  2 s  .  c  o  m*/
        post.setEntity(new StringEntity(str));
    } catch (UnsupportedEncodingException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, e.getMessage(), e);
    }
    return new RequestImpl(post);
}

From source file:net.yoomai.virgo.spider.Emulator.java

/**
 * /*w w w  .  j  a v  a 2 s  .  c  om*/
 *
 * @param params
 * @param url
 */
public String login(Map<String, String> params, String url) {
    String cookie = "";

    CloseableHttpClient httpClient = HttpClients.createDefault();
    HttpPost httpPost = new HttpPost(url);

    List<NameValuePair> nvps = generateURLParams(params);
    try {
        httpPost.setEntity(new UrlEncodedFormEntity(nvps));
    } catch (UnsupportedEncodingException e) {
        log.error(e.getMessage() + " : " + e.getCause());
    }

    CloseableHttpResponse response = null;

    try {
        response = httpClient.execute(httpPost);
    } catch (IOException e) {
        log.error(e.getMessage() + " : " + e.getCause());
    }

    if (response != null) {
        StatusLine statusLine = response.getStatusLine();
        log.info(statusLine);
        if (statusLine.getStatusCode() == 200 || statusLine.getStatusCode() == 302) {
            Header[] headers = response.getHeaders("Set-Cookie");
            for (Header header : headers) {
                cookie += header.getValue() + ";";
            }
        }
    }

    return cookie;
}

From source file:net.shopxx.plugin.ccbPayment.CcbPaymentPlugin.java

private boolean verifySign(Map<String, ?> parameterMap, String sign) {
    try {//from w ww . j av  a2 s .  com
        PluginConfig pluginConfig = getPluginConfig();
        PublicKey publicKey = RSAUtils.generatePublicKey(toBytes(pluginConfig.getAttribute("key")));
        return RSAUtils.verify("MD5withRSA", publicKey, toBytes(sign),
                joinKeyValue(new LinkedHashMap<String, Object>(parameterMap), null, null, "&", false, "SIGN")
                        .getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:at.sti2.spark.handler.SupportHandler.java

private void sendToREST(String url, String content) {

    //HTTP Post//from   w  ww . ja v  a2  s . co  m
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(url);

    try {
        StringEntity postStringEntity = new StringEntity(content);
        postStringEntity.setContentType("text/xml");

        httpPost.addHeader("Accept", "*/*");
        httpPost.setEntity(postStringEntity);
        HttpResponse response = httpclient.execute(httpPost);

        logger.info("[POSTING Event] Status code " + response.getStatusLine());

        //First invocation succeeded
        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {

            HttpEntity entityResponse = response.getEntity();

            //Something has been returned, let's see what is in it
            if (entityResponse != null) {
                String stringResponse = EntityUtils.toString(entityResponse);
                logger.debug("Response " + stringResponse);
            }
        }
    } catch (UnsupportedEncodingException e) {
        logger.error(e.getMessage());
    } catch (ClientProtocolException e) {
        logger.error(e.getMessage());
    } catch (IOException e) {
        logger.error(e.getMessage());
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:com.aliyun.android.oss.task.DeleteMultipleObjectTask.java

@Override
protected HttpUriRequest generateHttpRequest() {
    String requestUri = this.getOSSEndPoint() + httpTool.generateCanonicalizedResource("/?delete");

    HttpPost httpPost = new HttpPost(requestUri);

    String md5 = "";
    try {//from  w  w w .jav  a 2 s .  c o  m
        String entity = generateHttpEntityStr();
        byte[] mds = MD5Util.getMD5(entity.getBytes("UTF-8"));
        md5 = Base64.encode(mds);
        httpPost.setHeader("Content-MD5", md5);
        httpPost.setEntity(new StringEntity(entity, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        Log.e("exception occurs when deleting mutiple object", e.getMessage());
    }

    String resource = httpTool.generateCanonicalizedResource("/" + bucketName + "/?delete");
    String dateStr = Helper.getGMTDate();
    String authorization = OSSHttpTool.generateAuthorization(accessId, accessKey, httpMethod.toString(), md5,
            "text/plain; charsert=UTF-8", dateStr, "", resource);

    httpPost.setHeader(CONTENT_TYPE, "text/plain; charsert=UTF-8");
    httpPost.setHeader(AUTHORIZATION, authorization);
    httpPost.setHeader(DATE, dateStr);

    return httpPost;
}

From source file:id.pazpo.agent.utils.OAuthHeaderBuilder.java

/**
 * Construct a &-separated list of the given values, percentEncoded.
 *//*  www  .j  a v  a 2  s.  c o m*/
public String percentEncode(String s) {
    if (s == null) {
        return "";
    }
    try {
        return URLEncoder.encode(s, ENCODING)
                // OAuth encodes some characters differently:
                .replace("+", "%20").replace("*", "%2A").replace("%7E", "~");
        // This could be done faster with more hand-crafted code.
    } catch (UnsupportedEncodingException wow) {
        throw new RuntimeException(wow.getMessage(), wow);
    }
}

From source file:de.hybris.platform.impex.jalo.ImpExImporterTest.java

@Test
public void testFullImport() {
    try {/*ww  w  .  j a  v a  2  s. co  m*/
        final InputStream inputStream = ImpExManager.class
                .getResourceAsStream("/impex/testfiles/productFull.impex");
        assertNotNull("Can not read from jar file 'productFull.impex'", inputStream);
        final CSVReader reader = new CSVReader(inputStream, windows1252.getCode());
        final Importer importer = new Importer(reader);
        final Product product = (Product) importer.importNext();
        assertNotNull("Imported product was null", product);
        importer.close();
        assertEquals("Dump file is at " + importer.getDumpHandler().getDumpAsFile().getAbsolutePath(), 0,
                importer.getDumpedLineCountPerPass());
    } catch (final UnsupportedEncodingException e) {
        fail(e.getMessage());
    } catch (final ImpExException e) {
        fail(e.getMessage());
    }
}