-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Unconsistentbehaviorbetweendirectpostandurl-encodedpost…
…forUpdateinCorese-Server#191' into development
- Loading branch information
Showing
7 changed files
with
549 additions
and
372 deletions.
There are no files selected for viewing
388 changes: 185 additions & 203 deletions
388
corese-server/src/main/java/fr/inria/corese/server/webservice/SPARQLRestAPI.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
corese-server/src/test/java/fr/inria/corese/server/webservice/HTTPConnectionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package fr.inria.corese.server.webservice; | ||
|
||
import java.io.IOException; | ||
import java.net.HttpURLConnection; | ||
import java.net.MalformedURLException; | ||
import java.net.ProtocolException; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class HTTPConnectionUtils { | ||
|
||
/** | ||
* Get a connection to a server. | ||
* | ||
* @param url server URL | ||
* @param headers HTTP headers | ||
* @return | ||
* @throws MalformedURLException | ||
* @throws IOException | ||
* @throws ProtocolException | ||
*/ | ||
|
||
public static HttpURLConnection methodConnection(String method, String url, List<List<String>> headers) | ||
throws IOException { | ||
URL u = new URL(url); | ||
HttpURLConnection con = (HttpURLConnection) u.openConnection(); | ||
con.setRequestMethod(method); | ||
con.setConnectTimeout(5000); | ||
con.setReadTimeout(5000); | ||
con.setInstanceFollowRedirects(true); | ||
for (List<String> header : headers) { | ||
con.setRequestProperty(header.get(0), header.get(1)); | ||
} | ||
return con; | ||
} | ||
|
||
public static HttpURLConnection getConnection(String url, List<List<String>> headers) | ||
throws IOException { | ||
return methodConnection("GET", url, headers); | ||
} | ||
|
||
public static HttpURLConnection postConnection(String url, List<List<String>> headers, String body) | ||
throws IOException { | ||
HttpURLConnection con = methodConnection("POST", url, headers); | ||
con.setDoOutput(true); | ||
con.getOutputStream().write(body.getBytes()); | ||
return con; | ||
} | ||
|
||
public static HttpURLConnection postUrlencodedConnection(String url, List<List<String>> headers, String body) | ||
throws IOException { | ||
List<List<String>> newHeaders = new ArrayList<>(headers); | ||
List<String> contentTypeHeader = new ArrayList<>(); | ||
contentTypeHeader.add("Content-Type"); | ||
contentTypeHeader.add("application/x-www-form-urlencoded"); | ||
newHeaders.add(contentTypeHeader); | ||
return postConnection(url, newHeaders, body); | ||
} | ||
|
||
public static HttpURLConnection putConnection(String url, List<List<String>> headers, String body) | ||
throws IOException { | ||
HttpURLConnection con = methodConnection("PUT", url, headers); | ||
con.setDoOutput(true); | ||
con.getOutputStream().write(body.getBytes()); | ||
return con; | ||
} | ||
|
||
public static HttpURLConnection deleteConnection(String url, List<List<String>> headers) | ||
throws IOException { | ||
return methodConnection("DELETE", url, headers); | ||
} | ||
|
||
public static HttpURLConnection deleteConnection(String url) | ||
throws IOException { | ||
return deleteConnection( url, new ArrayList<>()); | ||
} | ||
|
||
public static HttpURLConnection headConnection(String url, List<List<String>> headers) | ||
throws IOException { | ||
return methodConnection("HEAD", url, headers); | ||
} | ||
|
||
public static HttpURLConnection headConnection(String url) | ||
throws IOException { | ||
return headConnection(url, new ArrayList<>()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.