List of usage examples for org.apache.commons.codec.net URLCodec encode
public Object encode(Object pObject) throws EncoderException
From source file:corner.orm.tapestry.utils.ComponentResponseUtils.java
private static String processFileName(String fileName, String agent) throws IOException { String codedfilename = fileName; if (null != agent && -1 != agent.indexOf("MSIE")) {// IE //apachecodeC?: //http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6437829 URLCodec codec = new URLCodec("UTF-8"); try {/*from w ww.j a v a 2s . c om*/ codedfilename = codec.encode(fileName); } catch (EncoderException e) { log.warn(e); } } else if (null != agent && -1 != agent.indexOf("Mozilla")) { // Mozilla // firefox codedfilename = String.format(MOZILLA_DOWNLOAD_FILE_NAME, new String(Base64.encodeBase64(fileName.getBytes("UTF-8")))); } return codedfilename; }
From source file:ch.iterate.openstack.swift.model.Region.java
private static String encode(String object, boolean preserveslashes) { URLCodec codec = new URLCodec(); try {/* w w w. j a va 2 s. c o m*/ final String encoded = codec.encode(object).replaceAll("\\+", "%20"); if (preserveslashes) { return encoded.replaceAll("%2F", "/"); } return encoded; } catch (EncoderException ee) { return object; } }
From source file:com.intel.cosbench.client.http.HttpClientUtil.java
public static String encodeURL(String str) { URLCodec codec = new URLCodec(); try {//from ww w .j a v a2 s . c om return codec.encode(str).replaceAll("\\+", "%20"); } catch (EncoderException ee) { return str; } }
From source file:edu.jhu.pha.vospace.storage.SwiftKeystoneStorageManager.java
public static String sanitizeForURI(String str) { URLCodec codec = new URLCodec(); try {/*from ww w. j ava2 s . c o m*/ return codec.encode(str).replaceAll("\\+", "%20"); } catch (EncoderException ee) { return str; } }
From source file:NetUsage.java
public void start() throws EncoderException, DecoderException { String urlData1 = "This#is^a&String with reserved @/characters"; URLCodec encoder = new URLCodec(); String result = encoder.encode(urlData1); System.err.println("URL Encoding result: " + result); System.err.println("URL Decoding result: " + encoder.decode(result)); }
From source file:jp.dip.komusubi.botter.util.TrimUrlUtil.java
@Override public String shorten(String url) { String responseLine = null;//from ww w.jav a 2s . co m try { URLCodec codec = new URLCodec(); String requestUrl = SHORTEN_SERVICE_URL + "?url=" + codec.encode(url); responseLine = UrlAccessDelegate.readFirstLine(requestUrl); if (responseLine == null) logger.warn("tr.im response is null, URL is :{}", requestUrl); } catch (EncoderException e) { throw new BotterException(e); } return responseLine; }
From source file:de.schneider.dev.poi.service.OpenStreetMapGeoService.java
public void getGeoCoordinate(String location) throws EncoderException { LOG.info("Start GeoCoordination OpenStreetMap"); // create default HttpClient HttpClient httpClient = new DefaultHttpClient(); // get data from URI URLCodec urlCodec = new URLCodec("UTF-8"); HttpGet httpGet = new HttpGet(URI_String + urlCodec.encode(location) + "&format=json"); LOG.info("HttpGet: " + httpGet); LOG.debug(httpGet.toString());/* w w w . j av a2s. com*/ LOG.debug("HttpGetURI: " + httpGet.getURI()); // get response try { HttpResponse httpResponse = httpClient.execute(httpGet); LOG.info("HttpResponse: " + httpResponse); LOG.info("Status Code: " + httpResponse.getStatusLine().getStatusCode()); LOG.info("Status Phrase: " + httpResponse.getStatusLine().getReasonPhrase()); HttpEntity httpEntity = httpResponse.getEntity(); LOG.info("HttpEntity: " + httpEntity); LOG.info("HttpEntity Streaming: " + httpEntity.isStreaming()); if (httpEntity.isStreaming()) { InputStream inputStream = httpEntity.getContent(); String content = EntityUtils.toString(httpEntity); LOG.info(content); inputStream.close(); } } catch (ClientProtocolException cpe) { LOG.error(cpe.getMessage()); } catch (IOException ioe) { LOG.error(ioe.getMessage()); } }
From source file:de.schneider.dev.poi.service.GoogleMapGeoService.java
public void getGeoCoordinate(String location) throws EncoderException { LOG.info("Start GeoCoordination Google Map"); // create default HttpClient HttpClient httpClient = new DefaultHttpClient(); // get data from URI URLCodec urlCodec = new URLCodec("UTF-8"); HttpGet httpGet = new HttpGet(DEFAULT_JSON_URI + urlCodec.encode(location) + "&sensor=false"); LOG.info("HttpGet: " + httpGet); // get response try {// w w w . j a v a2 s . c o m HttpResponse httpResponse = httpClient.execute(httpGet); LOG.info("HttpResponse: " + httpResponse); LOG.info("Status Code: " + httpResponse.getStatusLine().getStatusCode()); LOG.info("Status Phrase: " + httpResponse.getStatusLine().getReasonPhrase()); HttpEntity httpEntity = httpResponse.getEntity(); LOG.info("HttpEntity: " + httpEntity); LOG.info("HttpEntity Streaming: " + httpEntity.isStreaming()); if (httpEntity.isStreaming()) { InputStream inputStream = httpEntity.getContent(); String content = EntityUtils.toString(httpEntity); LOG.info(content); inputStream.close(); } } catch (ClientProtocolException cpe) { LOG.error(cpe.toString()); } catch (IOException ioe) { LOG.error(ioe.toString()); } }
From source file:com.softlayer.objectstorage.ObjectFile.java
/** * Utility method for getting data from REST api to populate this object * //ww w .ja va 2s .co m * @throws EncoderException * @throws IOException */ private void loadFileData() throws EncoderException, IOException { Hashtable<String, String> params = super.createAuthParams(); URLCodec ucode = new URLCodec(); String uName = ucode.encode(this.containerName).replaceAll("\\+", "%20"); String fName = ucode.encode(this.name).replaceAll("\\+", "%20"); ClientResource client = super.get(params, super.storageurl + "/" + uName + "/" + fName); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); client.get().write(outputStream); this.bytes = outputStream.toByteArray(); this.headers = client.getResponseAttributes(); }
From source file:eu.seaclouds.platform.planner.core.HttpHelper.java
private String prepareRequestURL(String restPath, List<NameValuePair> params) { StringBuilder operationBuilder = new StringBuilder(); operationBuilder.append(serviceURL); operationBuilder.append(restPath);//from w w w . j a v a2s.c om if (params.size() > 0) { operationBuilder.append("?"); URLCodec coded = new URLCodec(); try { for (NameValuePair p : params) operationBuilder.append(p.getName() + "=" + coded.encode(p.getValue())); } catch (EncoderException e) { e.printStackTrace(); return null; } } return operationBuilder.toString(); }