List of usage examples for org.apache.commons.codec.net URLCodec URLCodec
public URLCodec()
From source file:com.fujitsu.dc.client.DcContext.java
/** * TODO This is not a feature of the original JAVA DAO. There is a need to move to a different class. * @param str String decoded//ww w. j a v a 2 s.c o m * @return Dedoded URI * @throws UnsupportedEncodingException exception * @throws DecoderException exception */ public final String decodeURI(final String str) throws UnsupportedEncodingException, DecoderException { URLCodec codec = new URLCodec(); return codec.decode(str, "utf-8"); }
From source file:com.ge.research.semtk.sparqlX.SparqlEndpointInterface.java
/** * Execute query using GET (use should be rare - in cases where POST is not supported) * @return a JSONObject wrapping the results. in the event the results were tabular, they can be obtained in the JsonArray "@Table". if the results were a graph, use "@Graph" for json-ld * @throws Exception// www. ja v a 2s . co m */ public JSONObject executeQueryGet(String query, SparqlResultTypes resultsType) throws Exception { if (resultsType == null) { resultsType = getDefaultResultType(); } // encode the query and build a real URL URLCodec encoder = new URLCodec(); String cleanURL = getGetURL() + encoder.encode(query); URL url = new URL(null, cleanURL, handler); System.out.println("URL: " + url); // create an http GET connection and make the request HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // set the type of output desired. this might not work.... String resultsFormat = this.getContentType(resultsType); conn.setRequestProperty("Accept", resultsFormat); conn.setRequestMethod("GET"); // read the results BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String results = ""; // get everythign from reader String line; while ((line = rd.readLine()) != null) { results += line; } try { this.response = (JSONObject) new JSONParser().parse(results); } catch (Exception e) { throw new Exception("Cannot parse query result into JSON: " + results); } JSONObject interimObj = new JSONObject(this.response); rd.close(); // close the reader if (this.response == null) { System.err.println("the response could not be transformed into json"); return null; } else { JSONObject procResp = getResultsFromResponse(interimObj, resultsType); return procResp; } }
From source file:edu.jhu.pha.vospace.storage.SwiftKeystoneStorageManager.java
public static String sanitizeForURI(String str) { URLCodec codec = new URLCodec(); try {/*from w w w .j av a2 s . co m*/ return codec.encode(str).replaceAll("\\+", "%20"); } catch (EncoderException ee) { return str; } }
From source file:com.eucalyptus.ws.util.HmacUtils.java
public static String urlEncode(String s) { try {//from w ww.j av a 2 s .c o m return new URLCodec().encode(s, "UTF-8"); } catch (UnsupportedEncodingException e) { return s; } }
From source file:com.bugclipse.fogbugz.api.client.FogBugzClient.java
private static String encode(String str) { try {/*w w w.j av a 2s .com*/ return new URLCodec().encode(str); } catch (EncoderException e) { e.printStackTrace(); return str; } }
From source file:com.wwpass.connection.WWPassConnection.java
private InputStream makeRequest(String method, String command, Map<String, ?> parameters) throws IOException, WWPassProtocolException { String commandUrl = SpfeURL + command + ".xml"; //String command_url = SpfeURL + command + ".json"; StringBuilder sb = new StringBuilder(); URLCodec codec = new URLCodec(); @SuppressWarnings("unchecked") Map<String, Object> localParams = (Map<String, Object>) parameters; for (Map.Entry<String, Object> entry : localParams.entrySet()) { sb.append(URLEncoder.encode(entry.getKey(), "UTF-8")); sb.append("="); if (entry.getValue() instanceof String) { sb.append(URLEncoder.encode((String) entry.getValue(), "UTF-8")); } else {//from w ww . j a v a2 s .c o m sb.append(new String(codec.encode((byte[]) entry.getValue()))); } sb.append("&"); } String paramsString = sb.toString(); sb = null; if ("GET".equalsIgnoreCase(method)) { commandUrl += "?" + paramsString; } else if ("POST".equalsIgnoreCase(method)) { } else { throw new IllegalArgumentException("Method " + method + " not supported."); } HttpsURLConnection conn = null; try { URL url = new URL(commandUrl); conn = (HttpsURLConnection) url.openConnection(); conn.setReadTimeout(timeoutMs); conn.setSSLSocketFactory(SPFEContext.getSocketFactory()); if ("POST".equalsIgnoreCase(method)) { conn.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream()); writer.write(paramsString); writer.flush(); } InputStream in = conn.getInputStream(); return getReplyData(in); } catch (MalformedURLException e) { throw new IllegalArgumentException("Command-parameters combination is invalid: " + e.getMessage()); } finally { if (conn != null) { conn.disconnect(); } } }
From source file:ch.iterate.openstack.swift.Client.java
private static String encode(String object) { URLCodec codec = new URLCodec(); try {/*from w w w.j a va 2 s . c om*/ return codec.encode(object).replaceAll("\\+", "%20"); } catch (EncoderException ee) { return object; } }
From source file:edu.jhuapl.openessence.controller.ReportController.java
private String appendUrlParameter(String url, String param, String value) { StringBuilder sb = new StringBuilder(url); if (url.contains("?")) { sb.append('&'); } else {/* w ww .j a v a 2 s .c o m*/ sb.append('?'); } URLCodec codec = new URLCodec(); try { sb.append(codec.encode(param)); } catch (EncoderException e) { log.error("Exception encoding URL param " + param, e); } try { sb.append('=').append(codec.encode(value)); } catch (EncoderException e) { log.error("Exception encoding URL value " + value, e); } return sb.toString(); }
From source file:com.rackspacecloud.client.cloudfiles.FilesClient.java
/** * URI/*from w w w . j a v a2 s . c o m*/ * @param str * * @return URI */ public static String sanitizeForURI(String str) { URLCodec codec = new URLCodec(); try { return codec.encode(str).replaceAll("\\+", "%20"); } catch (EncoderException ee) { logger.warn("Error trying to encode string for URI", ee); return str; } }
From source file:com.rackspacecloud.client.cloudfiles.FilesClient.java
/** * URI/// www .j ava 2s. com * @param str * * @return URI */ public static String sanitizeAndPreserveSlashes(String str) { URLCodec codec = new URLCodec(); try { return codec.encode(str).replaceAll("\\+", "%20").replaceAll("%2F", "/"); } catch (EncoderException ee) { logger.warn("Error trying to encode string for URI", ee); return str; } }