Commits

Anonymous committed 2879fe3

url-quote buckets and keys in jiak-java

Comments (0)

Files changed (1)

client_lib/java/src/com/basho/riak/JiakClient.java

 import java.io.OutputStreamWriter;
 import java.net.URL;
 import java.net.URLConnection;
+import java.net.URLEncoder;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 		final HashMap<String, String> reqHeaders = new HashMap<String, String>();
 		reqHeaders.put("Content-Type", "application/json");
 		reqHeaders.put("Accept", "application/json");
-		final String reqURI = makeURI(object.getBucket() + "/"
-				+ object.getKey() + "?returnbody=true");
+		final String reqURI = makeURI(object.getBucket(),
+                                              object.getKey(),
+                                              "?returnbody=true");
 		final HttpURLConnection requestConn = doRequest("PUT", reqURI, object
 				.toJSONObject(), reqHeaders);
 		final JSONObject updated = expect(200, requestConn);
 		final HashMap<String, String> reqHeaders = new HashMap<String, String>();
 		reqHeaders.put("Content-Type", "application/json");
 		reqHeaders.put("Accept", "application/json");
-		final String reqURI = makeURI(bucket + "/" + key);
+		final String reqURI = makeURI(bucket, key);
 		final HttpURLConnection requestConn = doRequest("GET", reqURI, null,
 				reqHeaders);
 		if (requestConn.getResponseCode() == 404)
 	 *             If an error occurs during communication with the Riak server.
 	 * @throws JiakException
 	 *             If the Riak server returns an error or or an unexpected
-	 *             response code.
+	 *             response code.,
 	 */
 	public void delete(final String bucket, final String key)
 			throws IOException, JiakException {
-		final String reqURI = makeURI(bucket + "/" + key);
+		final String reqURI = makeURI(bucket, key);
 		final HashMap<String, String> reqHeaders = new HashMap<String, String>();
 		reqHeaders.put("Accept", "*/*");
 		final HttpURLConnection requestConn = doRequest("DELETE", reqURI, null,
 			final String key, final String walkSpec) throws IOException,
 			JSONException, JiakException {
 		final ArrayList<ArrayList<JiakObject>> results = new ArrayList<ArrayList<JiakObject>>();
-		final String reqURI = makeURI(bucket + "/" + key + "/" + walkSpec);
+		final String reqURI = makeURI(bucket, key, walkSpec);
 		final Map<String, String> reqHeaders = new HashMap<String, String>();
 		reqHeaders.put("Accept", "application/json");
 		final HttpURLConnection requestConn = doRequest("GET", reqURI, null,
 		throw new JiakException(connection.getResponseMessage());
 	}
 
-	protected String makeURI(final String path) {
-		return "http://" + ip + ":" + port + prefix + path;
+	protected String makeURI(final String bucket) {
+		return "http://" + ip + ":" + port + prefix + URLEncoder.encode(bucket);
+	}
+	protected String makeURI(final String bucket, final String key) {
+		return makeURI(bucket) + "/" + URLEncoder.encode(key);
+	}
+	protected String makeURI(final String bucket, final String key, final String extra) {
+		return makeURI(bucket, key) + "/" + extra;
 	}
 
 	protected static void writeRequestBody(final URLConnection connection,