You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by wi...@apache.org on 2014/10/31 11:16:49 UTC

[2/3] git commit: swtiched to URIBuilder to build POST requests

swtiched to URIBuilder to build POST requests


Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/50955473
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/50955473
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/50955473

Branch: refs/heads/develop
Commit: 509554733eb23e0c32b1d0d1f59c429dd4b31266
Parents: 0ed4572
Author: Sergio Fernández <wi...@apache.org>
Authored: Fri Oct 31 10:59:04 2014 +0100
Committer: Sergio Fernández <wi...@apache.org>
Committed: Fri Oct 31 10:59:11 2014 +0100

----------------------------------------------------------------------
 .../java/org/apache/marmotta/client/util/HTTPUtil.java   | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/50955473/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/util/HTTPUtil.java
----------------------------------------------------------------------
diff --git a/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/util/HTTPUtil.java b/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/util/HTTPUtil.java
index ba8232f..3382657 100644
--- a/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/util/HTTPUtil.java
+++ b/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/util/HTTPUtil.java
@@ -25,6 +25,7 @@ import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpHead;
 import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.utils.URIBuilder;
 import org.apache.http.config.Registry;
 import org.apache.http.config.RegistryBuilder;
 import org.apache.http.conn.socket.ConnectionSocketFactory;
@@ -35,6 +36,7 @@ import org.apache.http.protocol.HttpContext;
 import org.apache.marmotta.client.ClientConfiguration;
 
 import java.io.IOException;
+import java.net.URISyntaxException;
 
 /**
  * HTTP Utilities
@@ -81,15 +83,14 @@ public class HTTPUtil {
         return httpClientBuilder.build();
     }
 
-    public static HttpPost createPost(String path, ClientConfiguration config) {
-        String serviceUrl = config.getMarmottaUri() + path;
+    public static HttpPost createPost(String path, ClientConfiguration config) throws URISyntaxException {
+        final URIBuilder uriBuilder = new URIBuilder(config.getMarmottaUri()).setPath(path);
 
-        //FIXME: switch to a more elegant way, such as Jersey's UriBuilder
         if (StringUtils.isNotBlank(config.getMarmottaContext())) {
-            serviceUrl += "?" + CONTEXT + "=" + config.getMarmottaContext();
+            uriBuilder.addParameter(CONTEXT, config.getMarmottaContext());
         }
 
-        return new HttpPost(serviceUrl);
+        return new HttpPost(uriBuilder.build());
     }