From 237212978b96216a615e1f2f39a12d5aace17637 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Peters Date: Mon, 20 Jun 2016 10:32:58 +0200 Subject: [PATCH 0001/1769] junit 4.11 -> 4.12 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 829398f93..437b60779 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ If you would like to run tests, also add the following dependency along with the junit junit - 4.11 + 4.12 test From 3945305568b5b7d92a34b626532b5a6a9ea1e39c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 2 Mar 2018 13:07:03 -0600 Subject: [PATCH 0002/1769] change ownership to community closes #3 --- pom.xml | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 764152684..9bb9eec36 100644 --- a/pom.xml +++ b/pom.xml @@ -1,10 +1,10 @@ 4.0.0 - com.mashape.unirest + org.openunirest.unirest unirest-java jar - 1.4.10-SNAPSHOT + 2.0.00-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://unirest.io/ @@ -24,19 +24,17 @@ - https://github.com/Mashape/unirest-java - scm:git:git@github.com:Mashape/unirest-java.git - scm:git:git@github.com:Mashape/unirest-java.git + https://github.com/OpenUnirest/unirest-java + scm:git:git@github.com:OpenUnirest/unirest-java.git + scm:git:git@github.com:OpenUnirest/unirest-java.git - mashape - Mashape - opensource@mashape.com - https://github.com/Mashape - Mashape - https://www.mashape.com + Ryber + Ryan Bergman + https://github.com/OpenUnirest + OpenUnirest From b8fb76c714371377b6dc7f71df4d73181dba87f6 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 2 Mar 2018 13:09:57 -0600 Subject: [PATCH 0003/1769] java 8 all the way closes #1 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 9bb9eec36..f916750f6 100644 --- a/pom.xml +++ b/pom.xml @@ -54,8 +54,8 @@ true 128m 512m - 1.5 - 1.5 + 1.8 + 1.8 UTF-8 From 6ced767c273e3af91fbc4a4930e40a372c6c5a7c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 2 Mar 2018 13:28:16 -0600 Subject: [PATCH 0004/1769] fix the tests so that they work locally. closes #2 --- pom.xml | 6 + .../mashape/unirest/test/http/MockServer.java | 105 ++++++++++++++++++ .../unirest/test/http/UnirestTest.java | 45 ++++++-- 3 files changed, 145 insertions(+), 11 deletions(-) create mode 100644 src/test/java/com/mashape/unirest/test/http/MockServer.java diff --git a/pom.xml b/pom.xml index f916750f6..44cb7398a 100644 --- a/pom.xml +++ b/pom.xml @@ -137,5 +137,11 @@ ${jackson.version} test + + com.sparkjava + spark-core + 2.6.0 + test + diff --git a/src/test/java/com/mashape/unirest/test/http/MockServer.java b/src/test/java/com/mashape/unirest/test/http/MockServer.java new file mode 100644 index 000000000..aa914b5ff --- /dev/null +++ b/src/test/java/com/mashape/unirest/test/http/MockServer.java @@ -0,0 +1,105 @@ +/* +The MIT License + +Copyright (c) 2013 OpenUnirest (http://github.com/OpenUnirest) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +package com.mashape.unirest.test.http; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.http.entity.ContentType; +import spark.Request; +import spark.Response; +import spark.Route; +import spark.Spark; + +import javax.servlet.MultipartConfigElement; +import javax.servlet.http.Part; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +import static java.lang.System.getProperty; +import static spark.Spark.*; + +public class MockServer { + private static final ObjectMapper om = new ObjectMapper(); + public static int PORT = 4567; + public static String HOST = "http://localhost:" + PORT; + + public static void start() { + port(PORT); + post("/post", ContentType.MULTIPART_FORM_DATA.getMimeType(), multipost); + get("/get", new Route() { + public Object handle(Request request, Response response) throws Exception { + return "Hi Momn"; + } + }); + } + + private static Route multipost = new Route() { + public Object handle(Request req, Response res) throws Exception { + req.raw().setAttribute("org.eclipse.jetty.multipartConfig", new MultipartConfigElement(getProperty("java.io.tmpdir"))); + + ResponseBody body = new ResponseBody(); + for (Part p : req.raw().getParts()) { + if (p.getContentType().equals(ContentType.APPLICATION_OCTET_STREAM.getMimeType())) { + buildFilePart(p, body); + } else { + buildFormPart(p, body); + } + } + + return om.writeValueAsString(body); + } + }; + + private static void buildFormPart(Part p, ResponseBody body) throws IOException { + java.util.Scanner s = new Scanner(p.getInputStream()).useDelimiter("\\A"); + String value = s.hasNext() ? s.next() : ""; + body.form.put(p.getName(), value); + } + + public static void buildFilePart(Part part, ResponseBody body){ + body.files = new File(); + body.files.fileName = part.getSubmittedFileName(); + body.files.type = part.getContentType(); + body.files.inputName = part.getName(); + } + + public static void shutdown() { + Spark.stop(); + } + + public static class ResponseBody { + public File files; + public Map form = new HashMap(); + } + + public static class File { + public String fileName; + public String type; + public String inputName; + } +} diff --git a/src/test/java/com/mashape/unirest/test/http/UnirestTest.java b/src/test/java/com/mashape/unirest/test/http/UnirestTest.java index e7145a705..22d24ce0a 100644 --- a/src/test/java/com/mashape/unirest/test/http/UnirestTest.java +++ b/src/test/java/com/mashape/unirest/test/http/UnirestTest.java @@ -1,7 +1,8 @@ /* The MIT License -Copyright (c) 2013 Mashape (http://mashape.com) +Copyright for portions of project Foo are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for project OpenUnirest/unirest-java are held by OpenUnirest (c) 2017. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -31,6 +32,7 @@ a copy of this software and associated documentation files (the import com.mashape.unirest.http.options.Options; import com.mashape.unirest.request.GetRequest; import com.mashape.unirest.request.HttpRequest; +import com.mashape.unirest.request.body.MultipartBody; import com.mashape.unirest.test.helper.GetResponse; import com.mashape.unirest.test.helper.JacksonObjectMapper; @@ -41,8 +43,7 @@ a copy of this software and associated documentation files (the import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.junit.Before; -import org.junit.Test; +import org.junit.*; import java.io.*; import java.net.InetAddress; @@ -52,6 +53,7 @@ a copy of this software and associated documentation files (the import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; +import static com.mashape.unirest.test.http.MockServer.HOST; import static org.junit.Assert.*; public class UnirestTest { @@ -59,6 +61,16 @@ public class UnirestTest { private CountDownLatch lock; private boolean status; + @BeforeClass + public static void suiteSetUp(){ + MockServer.start(); + } + + @AfterClass + public static void suiteTearDown(){ + MockServer.shutdown(); + } + @Before public void setUp() { lock = new CountDownLatch(1); @@ -297,7 +309,14 @@ public void testMultipartContentType() throws JSONException, InterruptedExceptio @Test public void testMultipartInputStreamContentType() throws JSONException, InterruptedException, ExecutionException, URISyntaxException, UnirestException, FileNotFoundException { - HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post").field("name", "Mark").field("file", new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())), ContentType.APPLICATION_OCTET_STREAM, "image.jpg").asJson(); + FileInputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())); + MultipartBody request = Unirest.post(HOST + "/post") + .field("name", "Mark") + .field("file", stream, ContentType.APPLICATION_OCTET_STREAM, "image.jpg"); + + HttpResponse jsonResponse = request + .asJson(); + assertTrue(jsonResponse.getHeaders().size() > 0); assertTrue(jsonResponse.getBody().toString().length() > 0); assertFalse(jsonResponse.getRawBody() == null); @@ -305,13 +324,14 @@ public void testMultipartInputStreamContentType() throws JSONException, Interrup JsonNode json = jsonResponse.getBody(); assertFalse(json.isArray()); - assertNotNull(json.getObject()); + JSONObject object = json.getObject(); + assertNotNull(object); assertNotNull(json.getArray()); assertEquals(1, json.getArray().length()); assertNotNull(json.getArray().get(0)); - assertNotNull(json.getObject().getJSONObject("files")); + assertNotNull(object.getJSONObject("files")); - assertTrue(json.getObject().getJSONObject("files").getString("file").contains("data:application/octet-stream")); + assertTrue(json.getObject().getJSONObject("files").getString("type").contains("application/octet-stream")); assertEquals("Mark", json.getObject().getJSONObject("form").getString("name")); } @@ -592,7 +612,7 @@ private void makeParallelRequests() throws InterruptedException { newFixedThreadPool.execute(new Runnable() { public void run() { try { - Unirest.get("http://httpbin.org/get").queryString("index", counter.incrementAndGet()).asJson(); + Unirest.get(HOST + "/get").queryString("index", counter.incrementAndGet()).asString(); } catch (UnirestException e) { throw new RuntimeException(e); } @@ -733,9 +753,6 @@ public void testCaseInsensitiveHeaders() throws UnirestException { assertEquals("John", request.getHeaders().get("NAme").get(1)); assertEquals("Marco", request.getHeaders().get("Name").get(0)); assertEquals("John", request.getHeaders().get("Name").get(1)); - - headers = request.asJson().getBody().getObject().getJSONObject("headers"); - assertEquals("Marco,John", headers.get("Name")); } @Test @@ -815,4 +832,10 @@ public void testHeaderNamesCaseSensitive() { assertEquals("Only header \"Content-Type\" should exist", null, headers.getFirst("content-type")); assertEquals("Only header \"Content-Type\" should exist", "application/json", headers.getFirst("Content-Type")); } + + private static void debugApache() { + System.setProperty("org.apache.commons.logging.Log","org.apache.commons.logging.impl.SimpleLog"); + System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); + System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "DEBUG"); + } } From cdef62af2d3444b6c11888abd97c5d515c6131da Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 2 Mar 2018 13:29:28 -0600 Subject: [PATCH 0005/1769] travis doesnt care about java 6 or 7. Part of #1 --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8b5c5222b..47dd1f502 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,6 @@ language: java jdk: - - openjdk6 - - openjdk7 - - oraclejdk7 - oraclejdk8 os: From ca08a56da8be4d9ffed8573b96873213d939c1e1 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 2 Mar 2018 13:32:36 -0600 Subject: [PATCH 0006/1769] patch up apache for security issues. Closes #4 --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 44cb7398a..d7aedcb53 100644 --- a/pom.xml +++ b/pom.xml @@ -102,17 +102,17 @@ org.apache.httpcomponents httpclient - 4.5.2 + 4.5.5 org.apache.httpcomponents httpasyncclient - 4.1.1 + 4.1.3 org.apache.httpcomponents httpmime - 4.5.2 + 4.5.5 org.json From 0f8fdaa88957a41e39fbc676d9975872502101b7 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 2 Mar 2018 13:36:01 -0600 Subject: [PATCH 0007/1769] Unirest exception should not be checked. Fixes #5 --- .../com/mashape/unirest/http/exceptions/UnirestException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/mashape/unirest/http/exceptions/UnirestException.java b/src/main/java/com/mashape/unirest/http/exceptions/UnirestException.java index 50b13957c..94e4fc85f 100644 --- a/src/main/java/com/mashape/unirest/http/exceptions/UnirestException.java +++ b/src/main/java/com/mashape/unirest/http/exceptions/UnirestException.java @@ -1,6 +1,6 @@ package com.mashape.unirest.http.exceptions; -public class UnirestException extends Exception { +public class UnirestException extends RuntimeException { private static final long serialVersionUID = -3714840499934575734L; From c55b6d9d4d0312b10890779d57607497ba194275 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 2 Mar 2018 13:43:49 -0600 Subject: [PATCH 0008/1769] clean up test code --- .../mashape/unirest/test/http/MockServer.java | 36 ++++------- .../unirest/test/http/UnirestTest.java | 64 +++++++++---------- 2 files changed, 45 insertions(+), 55 deletions(-) diff --git a/src/test/java/com/mashape/unirest/test/http/MockServer.java b/src/test/java/com/mashape/unirest/test/http/MockServer.java index aa914b5ff..481ee9813 100644 --- a/src/test/java/com/mashape/unirest/test/http/MockServer.java +++ b/src/test/java/com/mashape/unirest/test/http/MockServer.java @@ -28,8 +28,6 @@ a copy of this software and associated documentation files (the import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.http.entity.ContentType; -import spark.Request; -import spark.Response; import spark.Route; import spark.Spark; @@ -51,29 +49,23 @@ public class MockServer { public static void start() { port(PORT); post("/post", ContentType.MULTIPART_FORM_DATA.getMimeType(), multipost); - get("/get", new Route() { - public Object handle(Request request, Response response) throws Exception { - return "Hi Momn"; - } - }); + get("/get", (request, response) -> "Hi Momn"); } - private static Route multipost = new Route() { - public Object handle(Request req, Response res) throws Exception { - req.raw().setAttribute("org.eclipse.jetty.multipartConfig", new MultipartConfigElement(getProperty("java.io.tmpdir"))); + private static Route multipost = (req, res) -> { + req.raw().setAttribute("org.eclipse.jetty.multipartConfig", new MultipartConfigElement(getProperty("java.io.tmpdir"))); - ResponseBody body = new ResponseBody(); - for (Part p : req.raw().getParts()) { - if (p.getContentType().equals(ContentType.APPLICATION_OCTET_STREAM.getMimeType())) { - buildFilePart(p, body); - } else { - buildFormPart(p, body); - } - } + ResponseBody body = new ResponseBody(); + for (Part p : req.raw().getParts()) { + if (p.getContentType().equals(ContentType.APPLICATION_OCTET_STREAM.getMimeType())) { + buildFilePart(p, body); + } else { + buildFormPart(p, body); + } + } - return om.writeValueAsString(body); - } - }; + return om.writeValueAsString(body); + }; private static void buildFormPart(Part p, ResponseBody body) throws IOException { java.util.Scanner s = new Scanner(p.getInputStream()).useDelimiter("\\A"); @@ -94,7 +86,7 @@ public static void shutdown() { public static class ResponseBody { public File files; - public Map form = new HashMap(); + public Map form = new HashMap<>(); } public static class File { diff --git a/src/test/java/com/mashape/unirest/test/http/UnirestTest.java b/src/test/java/com/mashape/unirest/test/http/UnirestTest.java index 22d24ce0a..b18ddac8f 100644 --- a/src/test/java/com/mashape/unirest/test/http/UnirestTest.java +++ b/src/test/java/com/mashape/unirest/test/http/UnirestTest.java @@ -77,7 +77,7 @@ public void setUp() { status = false; } - private String findAvailableIpAddress() throws UnknownHostException, IOException { + private String findAvailableIpAddress() throws IOException { for (int i = 100; i <= 255; i++) { String ip = "192.168.1." + i; if (!InetAddress.getByName(ip).isReachable(1000)) { @@ -115,21 +115,21 @@ public void testGet() throws JSONException, UnirestException { } @Test - public void testGetUTF8() throws UnirestException { + public void testGetUTF8() { HttpResponse response = Unirest.get("http://httpbin.org/get").queryString("param3", "こんにちは").asJson(); assertEquals(response.getBody().getObject().getJSONObject("args").getString("param3"), "こんにちは"); } @Test - public void testPostUTF8() throws UnirestException { + public void testPostUTF8() { HttpResponse response = Unirest.post("http://httpbin.org/post").field("param3", "こんにちは").asJson(); assertEquals(response.getBody().getObject().getJSONObject("form").getString("param3"), "こんにちは"); } @Test - public void testPostBinaryUTF8() throws UnirestException, URISyntaxException { + public void testPostBinaryUTF8() throws URISyntaxException { HttpResponse response = Unirest.post("http://httpbin.org/post").field("param3", "こんにちは").field("file", new File(getClass().getResource("/test").toURI())).asJson(); assertEquals("This is a test file", response.getBody().getObject().getJSONObject("files").getString("file")); @@ -137,7 +137,7 @@ public void testPostBinaryUTF8() throws UnirestException, URISyntaxException { } @Test - public void testPostRawBody() throws UnirestException, URISyntaxException, IOException { + public void testPostRawBody() { String sourceString = "'\"@こんにちは-test-123-" + Math.random(); byte[] sentBytes = sourceString.getBytes(); @@ -231,7 +231,7 @@ public void testAsync() throws JSONException, InterruptedException, ExecutionExc } @Test - public void testAsyncCallback() throws JSONException, InterruptedException, ExecutionException { + public void testAsyncCallback() throws JSONException, InterruptedException { Unirest.post("http://httpbin.org/post").header("accept", "application/json").field("param1", "value1").field("param2", "bye").asJsonAsync(new Callback() { public void failed(UnirestException e) { @@ -268,7 +268,7 @@ public void cancelled() { } @Test - public void testMultipart() throws JSONException, InterruptedException, ExecutionException, URISyntaxException, UnirestException { + public void testMultipart() throws JSONException, URISyntaxException, UnirestException { HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post").field("name", "Mark").field("file", new File(getClass().getResource("/test").toURI())).asJson(); assertTrue(jsonResponse.getHeaders().size() > 0); assertTrue(jsonResponse.getBody().toString().length() > 0); @@ -288,7 +288,7 @@ public void testMultipart() throws JSONException, InterruptedException, Executio } @Test - public void testMultipartContentType() throws JSONException, InterruptedException, ExecutionException, URISyntaxException, UnirestException { + public void testMultipartContentType() throws JSONException, URISyntaxException, UnirestException { HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post").field("name", "Mark").field("file", new File(getClass().getResource("/image.jpg").toURI()), "image/jpeg").asJson(); assertTrue(jsonResponse.getHeaders().size() > 0); assertTrue(jsonResponse.getBody().toString().length() > 0); @@ -308,7 +308,7 @@ public void testMultipartContentType() throws JSONException, InterruptedExceptio } @Test - public void testMultipartInputStreamContentType() throws JSONException, InterruptedException, ExecutionException, URISyntaxException, UnirestException, FileNotFoundException { + public void testMultipartInputStreamContentType() throws JSONException, URISyntaxException, FileNotFoundException { FileInputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())); MultipartBody request = Unirest.post(HOST + "/post") .field("name", "Mark") @@ -336,7 +336,7 @@ public void testMultipartInputStreamContentType() throws JSONException, Interrup } @Test - public void testMultipartInputStreamContentTypeAsync() throws JSONException, InterruptedException, ExecutionException, URISyntaxException, UnirestException, FileNotFoundException { + public void testMultipartInputStreamContentTypeAsync() throws JSONException, InterruptedException, URISyntaxException, FileNotFoundException { Unirest.post("http://httpbin.org/post").field("name", "Mark").field("file", new FileInputStream(new File(getClass().getResource("/test").toURI())), ContentType.APPLICATION_OCTET_STREAM, "test").asJsonAsync(new Callback() { public void failed(UnirestException e) { @@ -374,7 +374,7 @@ public void cancelled() { } @Test - public void testMultipartByteContentType() throws JSONException, InterruptedException, ExecutionException, URISyntaxException, UnirestException, IOException { + public void testMultipartByteContentType() throws JSONException, InterruptedException, ExecutionException, URISyntaxException, IOException { final InputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())); final byte[] bytes = new byte[stream.available()]; stream.read(bytes); @@ -398,7 +398,7 @@ public void testMultipartByteContentType() throws JSONException, InterruptedExce } @Test - public void testMultipartByteContentTypeAsync() throws JSONException, InterruptedException, ExecutionException, URISyntaxException, UnirestException, IOException { + public void testMultipartByteContentTypeAsync() throws JSONException, InterruptedException, ExecutionException, URISyntaxException, IOException { final InputStream stream = new FileInputStream(new File(getClass().getResource("/test").toURI())); final byte[] bytes = new byte[stream.available()]; stream.read(bytes); @@ -478,7 +478,7 @@ public void cancelled() { } @Test - public void testGzip() throws UnirestException, JSONException { + public void testGzip() throws JSONException { HttpResponse jsonResponse = Unirest.get("http://httpbin.org/gzip").asJson(); assertTrue(jsonResponse.getHeaders().size() > 0); assertTrue(jsonResponse.getBody().toString().length() > 0); @@ -491,7 +491,7 @@ public void testGzip() throws UnirestException, JSONException { } @Test - public void testGzipAsync() throws UnirestException, JSONException, InterruptedException, ExecutionException { + public void testGzipAsync() throws JSONException, InterruptedException, ExecutionException { HttpResponse jsonResponse = Unirest.get("http://httpbin.org/gzip").asJsonAsync().get(); assertTrue(jsonResponse.getHeaders().size() > 0); assertTrue(jsonResponse.getBody().toString().length() > 0); @@ -504,7 +504,7 @@ public void testGzipAsync() throws UnirestException, JSONException, InterruptedE } @Test - public void testDefaultHeaders() throws UnirestException, JSONException { + public void testDefaultHeaders() throws JSONException { Unirest.setDefaultHeader("X-Custom-Header", "hello"); Unirest.setDefaultHeader("user-agent", "foobar"); @@ -532,7 +532,7 @@ public void testDefaultHeaders() throws UnirestException, JSONException { } @Test - public void testSetTimeouts() throws UnknownHostException, IOException { + public void testSetTimeouts() throws IOException { String address = "http://" + findAvailableIpAddress() + "/"; long start = System.currentTimeMillis(); try { @@ -554,7 +554,7 @@ public void testSetTimeouts() throws UnknownHostException, IOException { } @Test - public void testPathParameters() throws UnirestException { + public void testPathParameters() { HttpResponse jsonResponse = Unirest.get("http://httpbin.org/{method}").routeParam("method", "get").queryString("name", "Mark").asJson(); assertEquals(200, jsonResponse.getStatus()); @@ -562,7 +562,7 @@ public void testPathParameters() throws UnirestException { } @Test - public void testQueryAndBodyParameters() throws UnirestException { + public void testQueryAndBodyParameters() { HttpResponse jsonResponse = Unirest.post("http://httpbin.org/{method}").routeParam("method", "post").queryString("name", "Mark").field("wot", "wat").asJson(); assertEquals(200, jsonResponse.getStatus()); @@ -571,7 +571,7 @@ public void testQueryAndBodyParameters() throws UnirestException { } @Test - public void testPathParameters2() throws UnirestException { + public void testPathParameters2() { HttpResponse jsonResponse = Unirest.patch("http://httpbin.org/{method}").routeParam("method", "patch").field("name", "Mark").asJson(); assertEquals(200, jsonResponse.getStatus()); @@ -580,7 +580,7 @@ public void testPathParameters2() throws UnirestException { } @Test - public void testMissingPathParameter() throws UnirestException { + public void testMissingPathParameter() { try { Unirest.get("http://httpbin.org/{method}").routeParam("method222", "get").queryString("name", "Mark").asJson(); fail(); @@ -609,15 +609,13 @@ private void makeParallelRequests() throws InterruptedException { ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(10); final AtomicInteger counter = new AtomicInteger(0); for (int i = 0; i < 200; i++) { - newFixedThreadPool.execute(new Runnable() { - public void run() { - try { - Unirest.get(HOST + "/get").queryString("index", counter.incrementAndGet()).asString(); - } catch (UnirestException e) { - throw new RuntimeException(e); - } - } - }); + newFixedThreadPool.execute(() -> { + try { + Unirest.get(HOST + "/get").queryString("index", counter.incrementAndGet()).asString(); + } catch (UnirestException e) { + throw new RuntimeException(e); + } + }); } newFixedThreadPool.shutdown(); @@ -690,7 +688,7 @@ public void testGetQuerystringArray() throws JSONException, UnirestException { } @Test - public void testPostMultipleFiles() throws JSONException, UnirestException, URISyntaxException { + public void testPostMultipleFiles() throws JSONException, URISyntaxException { HttpResponse response = Unirest.post("http://httpbin.org/post").field("param3", "wot").field("file1", new File(getClass().getResource("/test").toURI())).field("file2", new File(getClass().getResource("/test").toURI())).asJson(); JSONObject names = response.getBody().getObject().getJSONObject("files"); @@ -736,7 +734,7 @@ public void testPostCollection() throws JSONException, UnirestException { } @Test - public void testCaseInsensitiveHeaders() throws UnirestException { + public void testCaseInsensitiveHeaders() { GetRequest request = Unirest.get("http://httpbin.org/headers").header("Name", "Marco"); assertEquals(1, request.getHeaders().size()); assertEquals("Marco", request.getHeaders().get("name").get(0)); @@ -787,7 +785,7 @@ public void setTimeoutsAndCustomClient() { } @Test - public void testObjectMapperRead() throws UnirestException, IOException { + public void testObjectMapperRead() { Unirest.setObjectMapper(new JacksonObjectMapper()); GetResponse getResponseMock = new GetResponse(); @@ -800,7 +798,7 @@ public void testObjectMapperRead() throws UnirestException, IOException { } @Test - public void testObjectMapperWrite() throws UnirestException, IOException { + public void testObjectMapperWrite() { Unirest.setObjectMapper(new JacksonObjectMapper()); GetResponse postResponseMock = new GetResponse(); From af52721f53260425bdade56b4a6640483f62664f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 2 Mar 2018 14:02:19 -0600 Subject: [PATCH 0009/1769] update readme --- README.md | 81 +------------------------------------------------------ 1 file changed, 1 insertion(+), 80 deletions(-) diff --git a/README.md b/README.md index 829398f93..06d8ee986 100644 --- a/README.md +++ b/README.md @@ -38,65 +38,8 @@ Is easy as pie. Kidding. It's about as easy as doing these little steps: ### With Maven -You can use Maven by including the library: - -```xml - - com.mashape.unirest - unirest-java - 1.4.9 - -``` - -There are dependencies for Unirest-Java, these should be already installed, and they are as follows: - -```xml - - org.apache.httpcomponents - httpclient - 4.3.6 - - - org.apache.httpcomponents - httpasyncclient - 4.0.2 - - - org.apache.httpcomponents - httpmime - 4.3.6 - - - org.json - json - 20140107 - -``` - -If you would like to run tests, also add the following dependency along with the others: - -```xml - - junit - junit - 4.11 - test - - - commons-io - commons-io - 2.4 - test - -``` +We are working on getting this new fork into Maven Central. Hold tight -### Without Maven - -Alternatively if you don't use Maven, you can directly include the JAR file in the classpath: http://oss.sonatype.org/content/repositories/releases/com/mashape/unirest/unirest-java/1.4.9/unirest-java-1.4.9.jar - -Don't forget to also install the dependencies ([`org.json`](http://www.json.org/java/), [`httpclient 4.3.6`](http://hc.apache.org/downloads.cgi), [`httpmime 4.3.6`](http://hc.apache.org/downloads.cgi), [`httpasyncclient 4.0.2`](http://hc.apache.org/downloads.cgi)) in the classpath too. - -There is also a way to generate a Unirest-Java JAR file that already includes the required dependencies, but you will need Maven to generate it. Follow the instructions at http://blog.mashape.com/post/69117323931/installing-unirest-java-with-the-maven-assembly-plugin ## Creating Request So you're probably wondering how using Unirest makes creating requests in Java easier, here is a basic POST request that will explain everything: @@ -341,25 +284,3 @@ Unirest starts a background event loop and your Java application won't be able t ```java Unirest.shutdown(); ``` - ----- - -Made with ♥ from the [Mashape](https://www.mashape.com/) team - -[unirest-logo]: http://cl.ly/image/2P373Y090s2O/Image%202015-10-12%20at%209.48.06%20PM.png - - -[license-url]: https://github.com/Mashape/unirest-java/blob/master/LICENSE -[license-image]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat - -[gitter-url]: https://gitter.im/Mashape/unirest-java -[gitter-image]: https://img.shields.io/badge/Gitter-Join%20Chat-blue.svg?style=flat - -[travis-url]: https://travis-ci.org/Mashape/unirest-java -[travis-image]: https://img.shields.io/travis/Mashape/unirest-java.svg?style=flat - -[maven-url]: http://search.maven.org/#browse%7C1262490619 -[maven-version]: https://img.shields.io/maven-central/v/com.mashape.unirest/unirest-java.svg?style=flat - -[versioneye-url]: https://www.versioneye.com/user/projects/54b83a12050646ca5c0001fc -[versioneye-image]: https://www.versioneye.com/user/projects/54b83a12050646ca5c0001fc/badge.svg?style=flat From 7d87aa517b87cb6100caf28bb2e8f2d7294e9617 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 2 Mar 2018 18:30:39 -0600 Subject: [PATCH 0010/1769] change all the namespaces closes #7 --- .../openunirest}/http/Headers.java | 4 +-- .../openunirest}/http/HttpClientHelper.java | 16 +++++----- .../openunirest}/http/HttpDeleteWithBody.java | 2 +- .../openunirest}/http/HttpMethod.java | 2 +- .../openunirest}/http/HttpPatchWithBody.java | 2 +- .../openunirest}/http/HttpResponse.java | 10 +++--- .../openunirest}/http/JsonNode.java | 2 +- .../openunirest}/http/ObjectMapper.java | 2 +- .../openunirest}/http/Unirest.java | 22 ++++++------- .../openunirest}/http/async/Callback.java | 6 ++-- .../http/async/RequestThread.java | 10 +++--- .../AsyncIdleConnectionMonitorThread.java | 4 +-- .../http/exceptions/UnirestException.java | 2 +- .../openunirest}/http/options/Option.java | 2 +- .../openunirest}/http/options/Options.java | 14 ++++++--- .../openunirest}/http/utils/Base64Coder.java | 26 ++++++++-------- .../http/utils/ClientFactory.java | 6 ++-- .../openunirest}/http/utils/MapUtil.java | 2 +- .../http/utils/ResponseUtils.java | 4 +-- .../SyncIdleConnectionMonitorThread.java | 4 +-- .../http/utils/URLParamEncoder.java | 4 +-- .../openunirest}/request/BaseRequest.java | 12 +++---- .../openunirest}/request/GetRequest.java | 4 +-- .../openunirest}/request/HttpRequest.java | 10 +++--- .../request/HttpRequestWithBody.java | 20 ++++++------ .../openunirest}/request/body/Body.java | 2 +- .../request/body/MultipartBody.java | 9 +++--- .../openunirest}/request/body/RawBody.java | 6 ++-- .../request/body/RequestBodyEntity.java | 8 ++--- .../openunirest}/test/helper/GetResponse.java | 2 +- .../test/helper/JacksonObjectMapper.java | 4 +-- .../openunirest}/test/http/MockServer.java | 2 +- .../openunirest}/test/http/UnirestTest.java | 31 ++++++++++--------- 33 files changed, 130 insertions(+), 126 deletions(-) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/Headers.java (90%) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/HttpClientHelper.java (95%) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/HttpDeleteWithBody.java (97%) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/HttpMethod.java (97%) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/HttpPatchWithBody.java (97%) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/HttpResponse.java (95%) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/JsonNode.java (98%) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/ObjectMapper.java (78%) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/Unirest.java (93%) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/async/Callback.java (89%) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/async/RequestThread.java (87%) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/async/utils/AsyncIdleConnectionMonitorThread.java (94%) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/exceptions/UnirestException.java (84%) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/options/Option.java (81%) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/options/Options.java (92%) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/utils/Base64Coder.java (98%) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/utils/ClientFactory.java (74%) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/utils/MapUtil.java (97%) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/utils/ResponseUtils.java (97%) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/utils/SyncIdleConnectionMonitorThread.java (95%) rename src/main/java/{com/mashape/unirest => org/openunirest}/http/utils/URLParamEncoder.java (97%) rename src/main/java/{com/mashape/unirest => org/openunirest}/request/BaseRequest.java (92%) rename src/main/java/{com/mashape/unirest => org/openunirest}/request/GetRequest.java (95%) rename src/main/java/{com/mashape/unirest => org/openunirest}/request/HttpRequest.java (94%) rename src/main/java/{com/mashape/unirest => org/openunirest}/request/HttpRequestWithBody.java (92%) rename src/main/java/{com/mashape/unirest => org/openunirest}/request/body/Body.java (96%) rename src/main/java/{com/mashape/unirest => org/openunirest}/request/body/MultipartBody.java (96%) rename src/main/java/{com/mashape/unirest => org/openunirest}/request/body/RawBody.java (91%) rename src/main/java/{com/mashape/unirest => org/openunirest}/request/body/RequestBodyEntity.java (90%) rename src/test/java/{com/mashape/unirest => org/openunirest}/test/helper/GetResponse.java (89%) rename src/test/java/{com/mashape/unirest => org/openunirest}/test/helper/JacksonObjectMapper.java (88%) rename src/test/java/{com/mashape/unirest => org/openunirest}/test/http/MockServer.java (98%) rename src/test/java/{com/mashape/unirest => org/openunirest}/test/http/UnirestTest.java (97%) diff --git a/src/main/java/com/mashape/unirest/http/Headers.java b/src/main/java/org/openunirest/http/Headers.java similarity index 90% rename from src/main/java/com/mashape/unirest/http/Headers.java rename to src/main/java/org/openunirest/http/Headers.java index 662485020..e05ec69aa 100644 --- a/src/main/java/com/mashape/unirest/http/Headers.java +++ b/src/main/java/org/openunirest/http/Headers.java @@ -1,4 +1,4 @@ -package com.mashape.unirest.http; +package org.openunirest.http; import java.util.HashMap; import java.util.List; @@ -14,5 +14,5 @@ public String getFirst(Object key) { } return null; } - + } diff --git a/src/main/java/com/mashape/unirest/http/HttpClientHelper.java b/src/main/java/org/openunirest/http/HttpClientHelper.java similarity index 95% rename from src/main/java/com/mashape/unirest/http/HttpClientHelper.java rename to src/main/java/org/openunirest/http/HttpClientHelper.java index bc84b9ab7..69dc150ca 100644 --- a/src/main/java/com/mashape/unirest/http/HttpClientHelper.java +++ b/src/main/java/org/openunirest/http/HttpClientHelper.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.mashape.unirest.http; +package org.openunirest.http; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -53,13 +53,13 @@ a copy of this software and associated documentation files (the import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.apache.http.nio.entity.NByteArrayEntity; -import com.mashape.unirest.http.async.Callback; -import com.mashape.unirest.http.async.utils.AsyncIdleConnectionMonitorThread; -import com.mashape.unirest.http.exceptions.UnirestException; -import com.mashape.unirest.http.options.Option; -import com.mashape.unirest.http.options.Options; -import com.mashape.unirest.http.utils.ClientFactory; -import com.mashape.unirest.request.HttpRequest; +import org.openunirest.http.async.Callback; +import org.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; +import org.openunirest.http.exceptions.UnirestException; +import org.openunirest.http.options.Option; +import org.openunirest.http.options.Options; +import org.openunirest.http.utils.ClientFactory; +import org.openunirest.request.HttpRequest; public class HttpClientHelper { diff --git a/src/main/java/com/mashape/unirest/http/HttpDeleteWithBody.java b/src/main/java/org/openunirest/http/HttpDeleteWithBody.java similarity index 97% rename from src/main/java/com/mashape/unirest/http/HttpDeleteWithBody.java rename to src/main/java/org/openunirest/http/HttpDeleteWithBody.java index e5e3a5886..1b024886f 100644 --- a/src/main/java/com/mashape/unirest/http/HttpDeleteWithBody.java +++ b/src/main/java/org/openunirest/http/HttpDeleteWithBody.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.mashape.unirest.http; +package org.openunirest.http; import java.net.URI; diff --git a/src/main/java/com/mashape/unirest/http/HttpMethod.java b/src/main/java/org/openunirest/http/HttpMethod.java similarity index 97% rename from src/main/java/com/mashape/unirest/http/HttpMethod.java rename to src/main/java/org/openunirest/http/HttpMethod.java index b6e201055..7d7ae0938 100644 --- a/src/main/java/com/mashape/unirest/http/HttpMethod.java +++ b/src/main/java/org/openunirest/http/HttpMethod.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.mashape.unirest.http; +package org.openunirest.http; public enum HttpMethod { GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS; diff --git a/src/main/java/com/mashape/unirest/http/HttpPatchWithBody.java b/src/main/java/org/openunirest/http/HttpPatchWithBody.java similarity index 97% rename from src/main/java/com/mashape/unirest/http/HttpPatchWithBody.java rename to src/main/java/org/openunirest/http/HttpPatchWithBody.java index 0dad5d372..256cafceb 100644 --- a/src/main/java/com/mashape/unirest/http/HttpPatchWithBody.java +++ b/src/main/java/org/openunirest/http/HttpPatchWithBody.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.mashape.unirest.http; +package org.openunirest.http; import java.net.URI; diff --git a/src/main/java/com/mashape/unirest/http/HttpResponse.java b/src/main/java/org/openunirest/http/HttpResponse.java similarity index 95% rename from src/main/java/com/mashape/unirest/http/HttpResponse.java rename to src/main/java/org/openunirest/http/HttpResponse.java index e0800d227..bdc4977a5 100644 --- a/src/main/java/com/mashape/unirest/http/HttpResponse.java +++ b/src/main/java/org/openunirest/http/HttpResponse.java @@ -23,11 +23,11 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.mashape.unirest.http; +package org.openunirest.http; -import com.mashape.unirest.http.options.Option; -import com.mashape.unirest.http.options.Options; -import com.mashape.unirest.http.utils.ResponseUtils; +import org.openunirest.http.options.Option; +import org.openunirest.http.options.Options; +import org.openunirest.http.utils.ResponseUtils; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.StatusLine; @@ -106,7 +106,7 @@ public HttpResponse(org.apache.http.HttpResponse response, Class responseClas throw new RuntimeException(e); } } - + EntityUtils.consumeQuietly(responseEntity); } diff --git a/src/main/java/com/mashape/unirest/http/JsonNode.java b/src/main/java/org/openunirest/http/JsonNode.java similarity index 98% rename from src/main/java/com/mashape/unirest/http/JsonNode.java rename to src/main/java/org/openunirest/http/JsonNode.java index b5669b58c..1a73f470b 100644 --- a/src/main/java/com/mashape/unirest/http/JsonNode.java +++ b/src/main/java/org/openunirest/http/JsonNode.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.mashape.unirest.http; +package org.openunirest.http; import org.json.JSONArray; import org.json.JSONException; diff --git a/src/main/java/com/mashape/unirest/http/ObjectMapper.java b/src/main/java/org/openunirest/http/ObjectMapper.java similarity index 78% rename from src/main/java/com/mashape/unirest/http/ObjectMapper.java rename to src/main/java/org/openunirest/http/ObjectMapper.java index a3b1eb36f..742deeb8b 100644 --- a/src/main/java/com/mashape/unirest/http/ObjectMapper.java +++ b/src/main/java/org/openunirest/http/ObjectMapper.java @@ -1,4 +1,4 @@ -package com.mashape.unirest.http; +package org.openunirest.http; public interface ObjectMapper { diff --git a/src/main/java/com/mashape/unirest/http/Unirest.java b/src/main/java/org/openunirest/http/Unirest.java similarity index 93% rename from src/main/java/com/mashape/unirest/http/Unirest.java rename to src/main/java/org/openunirest/http/Unirest.java index 6aba57782..ff20fd1f6 100644 --- a/src/main/java/com/mashape/unirest/http/Unirest.java +++ b/src/main/java/org/openunirest/http/Unirest.java @@ -23,14 +23,14 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.mashape.unirest.http; - -import com.mashape.unirest.http.async.utils.AsyncIdleConnectionMonitorThread; -import com.mashape.unirest.http.options.Option; -import com.mashape.unirest.http.options.Options; -import com.mashape.unirest.http.utils.SyncIdleConnectionMonitorThread; -import com.mashape.unirest.request.GetRequest; -import com.mashape.unirest.request.HttpRequestWithBody; +package org.openunirest.http; + +import org.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; +import org.openunirest.http.options.Option; +import org.openunirest.http.options.Options; +import org.openunirest.http.utils.SyncIdleConnectionMonitorThread; +import org.openunirest.request.GetRequest; +import org.openunirest.request.HttpRequestWithBody; import org.apache.http.HttpHost; import org.apache.http.client.HttpClient; import org.apache.http.impl.client.CloseableHttpClient; @@ -70,7 +70,7 @@ public static void setProxy(HttpHost proxy) { /** * Set the ObjectMapper implementation to use for Response to Object binding - * + * * @param objectMapper Custom implementation of ObjectMapper interface */ public static void setObjectMapper(ObjectMapper objectMapper) { @@ -82,7 +82,7 @@ public static void setObjectMapper(ObjectMapper objectMapper) { /** * Set the connection timeout and socket timeout - * + * * @param connectionTimeout The timeout until a connection with the server is established (in milliseconds). Default is 10000. Set to zero to disable the timeout. * @param socketTimeout The timeout to receive data (in milliseconds). Default is 60000. Set to zero to disable the timeout. */ @@ -96,7 +96,7 @@ public static void setTimeouts(long connectionTimeout, long socketTimeout) { /** * Set the concurrency levels - * + * * @param maxTotal Defines the overall connection limit for a connection pool. Default is 200. * @param maxPerRoute Defines a connection limit per one HTTP route (this can be considered a per target host limit). Default is 20. */ diff --git a/src/main/java/com/mashape/unirest/http/async/Callback.java b/src/main/java/org/openunirest/http/async/Callback.java similarity index 89% rename from src/main/java/com/mashape/unirest/http/async/Callback.java rename to src/main/java/org/openunirest/http/async/Callback.java index 597135b67..eedd4575e 100644 --- a/src/main/java/com/mashape/unirest/http/async/Callback.java +++ b/src/main/java/org/openunirest/http/async/Callback.java @@ -23,10 +23,10 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.mashape.unirest.http.async; +package org.openunirest.http.async; -import com.mashape.unirest.http.HttpResponse; -import com.mashape.unirest.http.exceptions.UnirestException; +import org.openunirest.http.HttpResponse; +import org.openunirest.http.exceptions.UnirestException; public interface Callback { diff --git a/src/main/java/com/mashape/unirest/http/async/RequestThread.java b/src/main/java/org/openunirest/http/async/RequestThread.java similarity index 87% rename from src/main/java/com/mashape/unirest/http/async/RequestThread.java rename to src/main/java/org/openunirest/http/async/RequestThread.java index 2e6e96569..598a53aec 100644 --- a/src/main/java/com/mashape/unirest/http/async/RequestThread.java +++ b/src/main/java/org/openunirest/http/async/RequestThread.java @@ -23,12 +23,12 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.mashape.unirest.http.async; +package org.openunirest.http.async; -import com.mashape.unirest.http.HttpClientHelper; -import com.mashape.unirest.http.HttpResponse; -import com.mashape.unirest.http.exceptions.UnirestException; -import com.mashape.unirest.request.HttpRequest; +import org.openunirest.http.HttpClientHelper; +import org.openunirest.http.HttpResponse; +import org.openunirest.http.exceptions.UnirestException; +import org.openunirest.request.HttpRequest; public class RequestThread extends Thread { diff --git a/src/main/java/com/mashape/unirest/http/async/utils/AsyncIdleConnectionMonitorThread.java b/src/main/java/org/openunirest/http/async/utils/AsyncIdleConnectionMonitorThread.java similarity index 94% rename from src/main/java/com/mashape/unirest/http/async/utils/AsyncIdleConnectionMonitorThread.java rename to src/main/java/org/openunirest/http/async/utils/AsyncIdleConnectionMonitorThread.java index 3f899c017..1f2093f15 100644 --- a/src/main/java/com/mashape/unirest/http/async/utils/AsyncIdleConnectionMonitorThread.java +++ b/src/main/java/org/openunirest/http/async/utils/AsyncIdleConnectionMonitorThread.java @@ -1,4 +1,4 @@ -package com.mashape.unirest.http.async.utils; +package org.openunirest.http.async.utils; import java.util.concurrent.TimeUnit; @@ -32,4 +32,4 @@ public void run() { } } -} \ No newline at end of file +} diff --git a/src/main/java/com/mashape/unirest/http/exceptions/UnirestException.java b/src/main/java/org/openunirest/http/exceptions/UnirestException.java similarity index 84% rename from src/main/java/com/mashape/unirest/http/exceptions/UnirestException.java rename to src/main/java/org/openunirest/http/exceptions/UnirestException.java index 94e4fc85f..16d0f763c 100644 --- a/src/main/java/com/mashape/unirest/http/exceptions/UnirestException.java +++ b/src/main/java/org/openunirest/http/exceptions/UnirestException.java @@ -1,4 +1,4 @@ -package com.mashape.unirest.http.exceptions; +package org.openunirest.http.exceptions; public class UnirestException extends RuntimeException { diff --git a/src/main/java/com/mashape/unirest/http/options/Option.java b/src/main/java/org/openunirest/http/options/Option.java similarity index 81% rename from src/main/java/com/mashape/unirest/http/options/Option.java rename to src/main/java/org/openunirest/http/options/Option.java index a146ce2b1..649dd97ea 100644 --- a/src/main/java/com/mashape/unirest/http/options/Option.java +++ b/src/main/java/org/openunirest/http/options/Option.java @@ -1,4 +1,4 @@ -package com.mashape.unirest.http.options; +package org.openunirest.http.options; public enum Option { HTTPCLIENT, ASYNCHTTPCLIENT, CONNECTION_TIMEOUT, SOCKET_TIMEOUT, DEFAULT_HEADERS, SYNC_MONITOR, ASYNC_MONITOR, MAX_TOTAL, MAX_PER_ROUTE, PROXY, OBJECT_MAPPER diff --git a/src/main/java/com/mashape/unirest/http/options/Options.java b/src/main/java/org/openunirest/http/options/Options.java similarity index 92% rename from src/main/java/com/mashape/unirest/http/options/Options.java rename to src/main/java/org/openunirest/http/options/Options.java index 8c73de19e..4dd51df62 100644 --- a/src/main/java/com/mashape/unirest/http/options/Options.java +++ b/src/main/java/org/openunirest/http/options/Options.java @@ -1,4 +1,4 @@ -package com.mashape.unirest.http.options; +package org.openunirest.http.options; import java.util.HashMap; import java.util.Map; @@ -13,8 +13,8 @@ import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor; import org.apache.http.nio.reactor.IOReactorException; -import com.mashape.unirest.http.async.utils.AsyncIdleConnectionMonitorThread; -import com.mashape.unirest.http.utils.SyncIdleConnectionMonitorThread; +import org.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; +import org.openunirest.http.utils.SyncIdleConnectionMonitorThread; public class Options { @@ -23,7 +23,7 @@ public class Options { public static final int MAX_TOTAL = 200; public static final int MAX_PER_ROUTE = 20; - private static Map options = new HashMap(); + private static Map options = new HashMap<>(); private static boolean customClientSet = false; @@ -32,10 +32,14 @@ public static void customClientSet() { } public static void setOption(Option option, Object value) { + validateOption(option); + options.put(option, value); + } + + private static void validateOption(Option option) { if ((option == Option.CONNECTION_TIMEOUT || option == Option.SOCKET_TIMEOUT) && customClientSet) { throw new RuntimeException("You can't set custom timeouts when providing custom client implementations. Set the timeouts directly in your custom client configuration instead."); } - options.put(option, value); } public static Object getOption(Option option) { diff --git a/src/main/java/com/mashape/unirest/http/utils/Base64Coder.java b/src/main/java/org/openunirest/http/utils/Base64Coder.java similarity index 98% rename from src/main/java/com/mashape/unirest/http/utils/Base64Coder.java rename to src/main/java/org/openunirest/http/utils/Base64Coder.java index ad8378d6e..6e87a9c4f 100644 --- a/src/main/java/com/mashape/unirest/http/utils/Base64Coder.java +++ b/src/main/java/org/openunirest/http/utils/Base64Coder.java @@ -1,4 +1,4 @@ -package com.mashape.unirest.http.utils; +package org.openunirest.http.utils; //Copyright 2003-2010 Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland //www.source-code.biz, www.inventec.ch/chdh @@ -57,7 +57,7 @@ public class Base64Coder { /** * Encodes a string into Base64 format. No blanks or line breaks are inserted. - * + * * @param s A String to be encoded. * @return A String containing the Base64 encoded data. */ @@ -68,7 +68,7 @@ public static String encodeString(String s) { /** * Encodes a byte array into Base 64 format and breaks the output into lines of 76 characters. This method is compatible with * sun.misc.BASE64Encoder.encodeBuffer(byte[]). - * + * * @param in An array containing the data bytes to be encoded. * @return A String containing the Base64 encoded data, broken into lines. */ @@ -78,7 +78,7 @@ public static String encodeLines(byte[] in) { /** * Encodes a byte array into Base 64 format and breaks the output into lines. - * + * * @param in An array containing the data bytes to be encoded. * @param iOff Offset of the first byte in in to be processed. * @param iLen Number of bytes to be processed in in, starting at iOff. @@ -105,7 +105,7 @@ public static String encodeLines(byte[] in, int iOff, int iLen, int lineLen, Str /** * Encodes a byte array into Base64 format. No blanks or line breaks are inserted in the output. - * + * * @param in An array containing the data bytes to be encoded. * @return A character array containing the Base64 encoded data. */ @@ -115,7 +115,7 @@ public static char[] encode(byte[] in) { /** * Encodes a byte array into Base64 format. No blanks or line breaks are inserted in the output. - * + * * @param in An array containing the data bytes to be encoded. * @param iLen Number of bytes to process in in. * @return A character array containing the Base64 encoded data. @@ -126,7 +126,7 @@ public static char[] encode(byte[] in, int iLen) { /** * Encodes a byte array into Base64 format. No blanks or line breaks are inserted in the output. - * + * * @param in An array containing the data bytes to be encoded. * @param iOff Offset of the first byte in in to be processed. * @param iLen Number of bytes to process in in, starting at iOff. @@ -159,7 +159,7 @@ public static char[] encode(byte[] in, int iOff, int iLen) { /** * Decodes a string from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data. - * + * * @param s A Base64 String to be decoded. * @return A String containing the decoded data. * @throws IllegalArgumentException If the input is not valid Base64 encoded data. @@ -171,7 +171,7 @@ public static String decodeString(String s) { /** * Decodes a byte array from Base64 format and ignores line separators, tabs and blanks. CR, LF, Tab and Space characters are ignored in the input data. This method is * compatible with sun.misc.BASE64Decoder.decodeBuffer(String). - * + * * @param s A Base64 String to be decoded. * @return An array containing the decoded data bytes. * @throws IllegalArgumentException If the input is not valid Base64 encoded data. @@ -189,7 +189,7 @@ public static byte[] decodeLines(String s) { /** * Decodes a byte array from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data. - * + * * @param s A Base64 String to be decoded. * @return An array containing the decoded data bytes. * @throws IllegalArgumentException If the input is not valid Base64 encoded data. @@ -200,7 +200,7 @@ public static byte[] decode(String s) { /** * Decodes a byte array from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data. - * + * * @param in A character array containing the Base64 encoded data. * @return An array containing the decoded data bytes. * @throws IllegalArgumentException If the input is not valid Base64 encoded data. @@ -211,7 +211,7 @@ public static byte[] decode(char[] in) { /** * Decodes a byte array from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data. - * + * * @param in A character array containing the Base64 encoded data. * @param iOff Offset of the first character in in to be processed. * @param iLen Number of characters to process in in, starting at iOff. @@ -257,4 +257,4 @@ public static byte[] decode(char[] in, int iOff, int iLen) { private Base64Coder() { } -} // end class Base64Coder \ No newline at end of file +} // end class Base64Coder diff --git a/src/main/java/com/mashape/unirest/http/utils/ClientFactory.java b/src/main/java/org/openunirest/http/utils/ClientFactory.java similarity index 74% rename from src/main/java/com/mashape/unirest/http/utils/ClientFactory.java rename to src/main/java/org/openunirest/http/utils/ClientFactory.java index a4167a89a..72f333d16 100644 --- a/src/main/java/com/mashape/unirest/http/utils/ClientFactory.java +++ b/src/main/java/org/openunirest/http/utils/ClientFactory.java @@ -1,10 +1,10 @@ -package com.mashape.unirest.http.utils; +package org.openunirest.http.utils; import org.apache.http.client.HttpClient; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; -import com.mashape.unirest.http.options.Option; -import com.mashape.unirest.http.options.Options; +import org.openunirest.http.options.Option; +import org.openunirest.http.options.Options; public class ClientFactory { diff --git a/src/main/java/com/mashape/unirest/http/utils/MapUtil.java b/src/main/java/org/openunirest/http/utils/MapUtil.java similarity index 97% rename from src/main/java/com/mashape/unirest/http/utils/MapUtil.java rename to src/main/java/org/openunirest/http/utils/MapUtil.java index 37edd7783..3efcfe502 100644 --- a/src/main/java/com/mashape/unirest/http/utils/MapUtil.java +++ b/src/main/java/org/openunirest/http/utils/MapUtil.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.mashape.unirest.http.utils; +package org.openunirest.http.utils; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/com/mashape/unirest/http/utils/ResponseUtils.java b/src/main/java/org/openunirest/http/utils/ResponseUtils.java similarity index 97% rename from src/main/java/com/mashape/unirest/http/utils/ResponseUtils.java rename to src/main/java/org/openunirest/http/utils/ResponseUtils.java index 7fb7d0891..89196f312 100644 --- a/src/main/java/com/mashape/unirest/http/utils/ResponseUtils.java +++ b/src/main/java/org/openunirest/http/utils/ResponseUtils.java @@ -1,4 +1,4 @@ -package com.mashape.unirest.http.utils; +package org.openunirest.http.utils; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -15,7 +15,7 @@ public class ResponseUtils { /** * Parse out a charset from a content type header. - * + * * @param contentType e.g. "text/html; charset=EUC-JP" * @return "EUC-JP", or null if not found. Charset is trimmed and uppercased. */ diff --git a/src/main/java/com/mashape/unirest/http/utils/SyncIdleConnectionMonitorThread.java b/src/main/java/org/openunirest/http/utils/SyncIdleConnectionMonitorThread.java similarity index 95% rename from src/main/java/com/mashape/unirest/http/utils/SyncIdleConnectionMonitorThread.java rename to src/main/java/org/openunirest/http/utils/SyncIdleConnectionMonitorThread.java index 05ffc7b86..5adceba1a 100644 --- a/src/main/java/com/mashape/unirest/http/utils/SyncIdleConnectionMonitorThread.java +++ b/src/main/java/org/openunirest/http/utils/SyncIdleConnectionMonitorThread.java @@ -1,4 +1,4 @@ -package com.mashape.unirest.http.utils; +package org.openunirest.http.utils; import java.util.concurrent.TimeUnit; @@ -32,4 +32,4 @@ public void run() { } } -} \ No newline at end of file +} diff --git a/src/main/java/com/mashape/unirest/http/utils/URLParamEncoder.java b/src/main/java/org/openunirest/http/utils/URLParamEncoder.java similarity index 97% rename from src/main/java/com/mashape/unirest/http/utils/URLParamEncoder.java rename to src/main/java/org/openunirest/http/utils/URLParamEncoder.java index c636644b6..2d60f883c 100644 --- a/src/main/java/com/mashape/unirest/http/utils/URLParamEncoder.java +++ b/src/main/java/org/openunirest/http/utils/URLParamEncoder.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.mashape.unirest.http.utils; +package org.openunirest.http.utils; public class URLParamEncoder { @@ -51,4 +51,4 @@ private static boolean isUnsafe(char ch) { return " %$&+,/:;=?@<>#%".indexOf(ch) >= 0; } -} \ No newline at end of file +} diff --git a/src/main/java/com/mashape/unirest/request/BaseRequest.java b/src/main/java/org/openunirest/request/BaseRequest.java similarity index 92% rename from src/main/java/com/mashape/unirest/request/BaseRequest.java rename to src/main/java/org/openunirest/request/BaseRequest.java index a19af21e7..dc55bb13e 100644 --- a/src/main/java/com/mashape/unirest/request/BaseRequest.java +++ b/src/main/java/org/openunirest/request/BaseRequest.java @@ -23,13 +23,13 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.mashape.unirest.request; +package org.openunirest.request; -import com.mashape.unirest.http.HttpClientHelper; -import com.mashape.unirest.http.HttpResponse; -import com.mashape.unirest.http.JsonNode; -import com.mashape.unirest.http.async.Callback; -import com.mashape.unirest.http.exceptions.UnirestException; +import org.openunirest.http.HttpClientHelper; +import org.openunirest.http.HttpResponse; +import org.openunirest.http.JsonNode; +import org.openunirest.http.async.Callback; +import org.openunirest.http.exceptions.UnirestException; import java.io.InputStream; import java.util.concurrent.Future; diff --git a/src/main/java/com/mashape/unirest/request/GetRequest.java b/src/main/java/org/openunirest/request/GetRequest.java similarity index 95% rename from src/main/java/com/mashape/unirest/request/GetRequest.java rename to src/main/java/org/openunirest/request/GetRequest.java index 1e1471f87..2e1a144cd 100644 --- a/src/main/java/com/mashape/unirest/request/GetRequest.java +++ b/src/main/java/org/openunirest/request/GetRequest.java @@ -23,11 +23,11 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.mashape.unirest.request; +package org.openunirest.request; import java.util.Map; -import com.mashape.unirest.http.HttpMethod; +import org.openunirest.http.HttpMethod; public class GetRequest extends HttpRequest { diff --git a/src/main/java/com/mashape/unirest/request/HttpRequest.java b/src/main/java/org/openunirest/request/HttpRequest.java similarity index 94% rename from src/main/java/com/mashape/unirest/request/HttpRequest.java rename to src/main/java/org/openunirest/request/HttpRequest.java index e0bc52f1b..1ed0ab404 100644 --- a/src/main/java/com/mashape/unirest/request/HttpRequest.java +++ b/src/main/java/org/openunirest/request/HttpRequest.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.mashape.unirest.request; +package org.openunirest.request; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -37,10 +37,10 @@ a copy of this software and associated documentation files (the import java.util.regex.Matcher; import java.util.regex.Pattern; -import com.mashape.unirest.http.HttpMethod; -import com.mashape.unirest.http.utils.Base64Coder; -import com.mashape.unirest.http.utils.URLParamEncoder; -import com.mashape.unirest.request.body.Body; +import org.openunirest.http.HttpMethod; +import org.openunirest.http.utils.Base64Coder; +import org.openunirest.http.utils.URLParamEncoder; +import org.openunirest.request.body.Body; public class HttpRequest extends BaseRequest { diff --git a/src/main/java/com/mashape/unirest/request/HttpRequestWithBody.java b/src/main/java/org/openunirest/request/HttpRequestWithBody.java similarity index 92% rename from src/main/java/com/mashape/unirest/request/HttpRequestWithBody.java rename to src/main/java/org/openunirest/request/HttpRequestWithBody.java index e3e641434..b91cfea9d 100644 --- a/src/main/java/com/mashape/unirest/request/HttpRequestWithBody.java +++ b/src/main/java/org/openunirest/request/HttpRequestWithBody.java @@ -23,19 +23,19 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.mashape.unirest.request; +package org.openunirest.request; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.content.InputStreamBody; -import com.mashape.unirest.http.HttpMethod; -import com.mashape.unirest.http.JsonNode; -import com.mashape.unirest.http.ObjectMapper; -import com.mashape.unirest.http.options.Option; -import com.mashape.unirest.http.options.Options; -import com.mashape.unirest.request.body.MultipartBody; -import com.mashape.unirest.request.body.RawBody; -import com.mashape.unirest.request.body.RequestBodyEntity; +import org.openunirest.http.HttpMethod; +import org.openunirest.http.JsonNode; +import org.openunirest.http.ObjectMapper; +import org.openunirest.http.options.Option; +import org.openunirest.http.options.Options; +import org.openunirest.request.body.MultipartBody; +import org.openunirest.request.body.RawBody; +import org.openunirest.request.body.RequestBodyEntity; import org.json.JSONArray; import org.json.JSONObject; @@ -183,4 +183,4 @@ public RequestBodyEntity body(JSONObject body) { public RequestBodyEntity body(JSONArray body) { return body(body.toString()); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mashape/unirest/request/body/Body.java b/src/main/java/org/openunirest/request/body/Body.java similarity index 96% rename from src/main/java/com/mashape/unirest/request/body/Body.java rename to src/main/java/org/openunirest/request/body/Body.java index 104d2dd44..5d1dd0468 100644 --- a/src/main/java/com/mashape/unirest/request/body/Body.java +++ b/src/main/java/org/openunirest/request/body/Body.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.mashape.unirest.request.body; +package org.openunirest.request.body; import org.apache.http.HttpEntity; diff --git a/src/main/java/com/mashape/unirest/request/body/MultipartBody.java b/src/main/java/org/openunirest/request/body/MultipartBody.java similarity index 96% rename from src/main/java/com/mashape/unirest/request/body/MultipartBody.java rename to src/main/java/org/openunirest/request/body/MultipartBody.java index 4d88df1f4..9b657ce78 100644 --- a/src/main/java/com/mashape/unirest/request/body/MultipartBody.java +++ b/src/main/java/org/openunirest/request/body/MultipartBody.java @@ -23,12 +23,11 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.mashape.unirest.request.body; +package org.openunirest.request.body; import java.io.File; import java.io.InputStream; import java.io.UnsupportedEncodingException; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.LinkedList; @@ -47,9 +46,9 @@ a copy of this software and associated documentation files (the import org.apache.http.entity.mime.content.InputStreamBody; import org.apache.http.entity.mime.content.StringBody; -import com.mashape.unirest.http.utils.MapUtil; -import com.mashape.unirest.request.BaseRequest; -import com.mashape.unirest.request.HttpRequest; +import org.openunirest.http.utils.MapUtil; +import org.openunirest.request.BaseRequest; +import org.openunirest.request.HttpRequest; public class MultipartBody extends BaseRequest implements Body { private Map> parameters = new LinkedHashMap>(); diff --git a/src/main/java/com/mashape/unirest/request/body/RawBody.java b/src/main/java/org/openunirest/request/body/RawBody.java similarity index 91% rename from src/main/java/com/mashape/unirest/request/body/RawBody.java rename to src/main/java/org/openunirest/request/body/RawBody.java index 02dd6d5fe..4922a9249 100644 --- a/src/main/java/com/mashape/unirest/request/body/RawBody.java +++ b/src/main/java/org/openunirest/request/body/RawBody.java @@ -23,10 +23,10 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.mashape.unirest.request.body; +package org.openunirest.request.body; -import com.mashape.unirest.request.BaseRequest; -import com.mashape.unirest.request.HttpRequest; +import org.openunirest.request.BaseRequest; +import org.openunirest.request.HttpRequest; import org.apache.http.HttpEntity; import org.apache.http.entity.ByteArrayEntity; diff --git a/src/main/java/com/mashape/unirest/request/body/RequestBodyEntity.java b/src/main/java/org/openunirest/request/body/RequestBodyEntity.java similarity index 90% rename from src/main/java/com/mashape/unirest/request/body/RequestBodyEntity.java rename to src/main/java/org/openunirest/request/body/RequestBodyEntity.java index 08377c95c..9598a7447 100644 --- a/src/main/java/com/mashape/unirest/request/body/RequestBodyEntity.java +++ b/src/main/java/org/openunirest/request/body/RequestBodyEntity.java @@ -23,14 +23,14 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.mashape.unirest.request.body; +package org.openunirest.request.body; import org.apache.http.HttpEntity; import org.apache.http.entity.StringEntity; -import com.mashape.unirest.http.JsonNode; -import com.mashape.unirest.request.BaseRequest; -import com.mashape.unirest.request.HttpRequest; +import org.openunirest.http.JsonNode; +import org.openunirest.request.BaseRequest; +import org.openunirest.request.HttpRequest; public class RequestBodyEntity extends BaseRequest implements Body { diff --git a/src/test/java/com/mashape/unirest/test/helper/GetResponse.java b/src/test/java/org/openunirest/test/helper/GetResponse.java similarity index 89% rename from src/test/java/com/mashape/unirest/test/helper/GetResponse.java rename to src/test/java/org/openunirest/test/helper/GetResponse.java index 9005beee6..7a861dcf1 100644 --- a/src/test/java/com/mashape/unirest/test/helper/GetResponse.java +++ b/src/test/java/org/openunirest/test/helper/GetResponse.java @@ -1,4 +1,4 @@ -package com.mashape.unirest.test.helper; +package org.openunirest.test.helper; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/test/java/com/mashape/unirest/test/helper/JacksonObjectMapper.java b/src/test/java/org/openunirest/test/helper/JacksonObjectMapper.java similarity index 88% rename from src/test/java/com/mashape/unirest/test/helper/JacksonObjectMapper.java rename to src/test/java/org/openunirest/test/helper/JacksonObjectMapper.java index 0ff398f71..38210a679 100644 --- a/src/test/java/com/mashape/unirest/test/helper/JacksonObjectMapper.java +++ b/src/test/java/org/openunirest/test/helper/JacksonObjectMapper.java @@ -1,7 +1,7 @@ -package com.mashape.unirest.test.helper; +package org.openunirest.test.helper; import com.fasterxml.jackson.core.JsonProcessingException; -import com.mashape.unirest.http.ObjectMapper; +import org.openunirest.http.ObjectMapper; import java.io.IOException; diff --git a/src/test/java/com/mashape/unirest/test/http/MockServer.java b/src/test/java/org/openunirest/test/http/MockServer.java similarity index 98% rename from src/test/java/com/mashape/unirest/test/http/MockServer.java rename to src/test/java/org/openunirest/test/http/MockServer.java index 481ee9813..50e46c589 100644 --- a/src/test/java/com/mashape/unirest/test/http/MockServer.java +++ b/src/test/java/org/openunirest/test/http/MockServer.java @@ -24,7 +24,7 @@ a copy of this software and associated documentation files (the */ -package com.mashape.unirest.test.http; +package org.openunirest.test.http; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.http.entity.ContentType; diff --git a/src/test/java/com/mashape/unirest/test/http/UnirestTest.java b/src/test/java/org/openunirest/test/http/UnirestTest.java similarity index 97% rename from src/test/java/com/mashape/unirest/test/http/UnirestTest.java rename to src/test/java/org/openunirest/test/http/UnirestTest.java index b18ddac8f..4dc83039a 100644 --- a/src/test/java/com/mashape/unirest/test/http/UnirestTest.java +++ b/src/test/java/org/openunirest/test/http/UnirestTest.java @@ -24,17 +24,16 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.mashape.unirest.test.http; - -import com.mashape.unirest.http.*; -import com.mashape.unirest.http.async.Callback; -import com.mashape.unirest.http.exceptions.UnirestException; -import com.mashape.unirest.http.options.Options; -import com.mashape.unirest.request.GetRequest; -import com.mashape.unirest.request.HttpRequest; -import com.mashape.unirest.request.body.MultipartBody; -import com.mashape.unirest.test.helper.GetResponse; -import com.mashape.unirest.test.helper.JacksonObjectMapper; +package org.openunirest.test.http; + +import org.openunirest.http.async.Callback; +import org.openunirest.http.exceptions.UnirestException; +import org.openunirest.http.options.Options; +import org.openunirest.request.GetRequest; +import org.openunirest.request.HttpRequest; +import org.openunirest.request.body.MultipartBody; +import org.openunirest.test.helper.GetResponse; +import org.openunirest.test.helper.JacksonObjectMapper; import org.apache.commons.io.IOUtils; import org.apache.http.entity.ContentType; @@ -44,16 +43,18 @@ a copy of this software and associated documentation files (the import org.json.JSONException; import org.json.JSONObject; import org.junit.*; +import org.openunirest.http.Headers; +import org.openunirest.http.HttpResponse; +import org.openunirest.http.JsonNode; +import org.openunirest.http.Unirest; import java.io.*; import java.net.InetAddress; import java.net.URISyntaxException; -import java.net.UnknownHostException; import java.util.Arrays; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; -import static com.mashape.unirest.test.http.MockServer.HOST; import static org.junit.Assert.*; public class UnirestTest { @@ -310,7 +311,7 @@ public void testMultipartContentType() throws JSONException, URISyntaxException, @Test public void testMultipartInputStreamContentType() throws JSONException, URISyntaxException, FileNotFoundException { FileInputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())); - MultipartBody request = Unirest.post(HOST + "/post") + MultipartBody request = Unirest.post(MockServer.HOST + "/post") .field("name", "Mark") .field("file", stream, ContentType.APPLICATION_OCTET_STREAM, "image.jpg"); @@ -611,7 +612,7 @@ private void makeParallelRequests() throws InterruptedException { for (int i = 0; i < 200; i++) { newFixedThreadPool.execute(() -> { try { - Unirest.get(HOST + "/get").queryString("index", counter.incrementAndGet()).asString(); + Unirest.get(MockServer.HOST + "/get").queryString("index", counter.incrementAndGet()).asString(); } catch (UnirestException e) { throw new RuntimeException(e); } From e128d778e660f986a98aad4e256dbe9acbef92af Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 2 Mar 2018 18:34:30 -0600 Subject: [PATCH 0011/1769] change all the copyright to include new open initiative --- LICENSE | 3 ++- src/main/java/org/openunirest/http/HttpClientHelper.java | 2 +- src/main/java/org/openunirest/http/HttpDeleteWithBody.java | 2 +- src/main/java/org/openunirest/http/HttpMethod.java | 2 +- src/main/java/org/openunirest/http/HttpPatchWithBody.java | 2 +- src/main/java/org/openunirest/http/HttpResponse.java | 2 +- src/main/java/org/openunirest/http/JsonNode.java | 2 +- src/main/java/org/openunirest/http/Unirest.java | 2 +- src/main/java/org/openunirest/http/async/Callback.java | 2 +- src/main/java/org/openunirest/http/async/RequestThread.java | 2 +- src/main/java/org/openunirest/http/utils/MapUtil.java | 2 +- src/main/java/org/openunirest/http/utils/URLParamEncoder.java | 2 +- src/main/java/org/openunirest/request/BaseRequest.java | 2 +- src/main/java/org/openunirest/request/GetRequest.java | 2 +- src/main/java/org/openunirest/request/HttpRequest.java | 2 +- .../java/org/openunirest/request/HttpRequestWithBody.java | 2 +- src/main/java/org/openunirest/request/body/Body.java | 2 +- src/main/java/org/openunirest/request/body/MultipartBody.java | 2 +- src/main/java/org/openunirest/request/body/RawBody.java | 2 +- .../java/org/openunirest/request/body/RequestBodyEntity.java | 2 +- src/test/java/org/openunirest/test/http/UnirestTest.java | 4 ++-- 21 files changed, 23 insertions(+), 22 deletions(-) diff --git a/LICENSE b/LICENSE index 78fe11e6c..8b23035b1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ The MIT License -Copyright (c) 2013-2015 Mashape (https://www.mashape.com) +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/org/openunirest/http/HttpClientHelper.java b/src/main/java/org/openunirest/http/HttpClientHelper.java index 69dc150ca..fa1865267 100644 --- a/src/main/java/org/openunirest/http/HttpClientHelper.java +++ b/src/main/java/org/openunirest/http/HttpClientHelper.java @@ -1,7 +1,7 @@ /* The MIT License -Copyright (c) 2013 Mashape (http://mashape.com) +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/org/openunirest/http/HttpDeleteWithBody.java b/src/main/java/org/openunirest/http/HttpDeleteWithBody.java index 1b024886f..de824bf34 100644 --- a/src/main/java/org/openunirest/http/HttpDeleteWithBody.java +++ b/src/main/java/org/openunirest/http/HttpDeleteWithBody.java @@ -1,7 +1,7 @@ /* The MIT License -Copyright (c) 2013 Mashape (http://mashape.com) +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/org/openunirest/http/HttpMethod.java b/src/main/java/org/openunirest/http/HttpMethod.java index 7d7ae0938..f6385f7b7 100644 --- a/src/main/java/org/openunirest/http/HttpMethod.java +++ b/src/main/java/org/openunirest/http/HttpMethod.java @@ -1,7 +1,7 @@ /* The MIT License -Copyright (c) 2013 Mashape (http://mashape.com) +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/org/openunirest/http/HttpPatchWithBody.java b/src/main/java/org/openunirest/http/HttpPatchWithBody.java index 256cafceb..1214ba7e4 100644 --- a/src/main/java/org/openunirest/http/HttpPatchWithBody.java +++ b/src/main/java/org/openunirest/http/HttpPatchWithBody.java @@ -1,7 +1,7 @@ /* The MIT License -Copyright (c) 2013 Mashape (http://mashape.com) +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/org/openunirest/http/HttpResponse.java b/src/main/java/org/openunirest/http/HttpResponse.java index bdc4977a5..331fcb528 100644 --- a/src/main/java/org/openunirest/http/HttpResponse.java +++ b/src/main/java/org/openunirest/http/HttpResponse.java @@ -1,7 +1,7 @@ /* The MIT License -Copyright (c) 2013 Mashape (http://mashape.com) +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/org/openunirest/http/JsonNode.java b/src/main/java/org/openunirest/http/JsonNode.java index 1a73f470b..69fb71910 100644 --- a/src/main/java/org/openunirest/http/JsonNode.java +++ b/src/main/java/org/openunirest/http/JsonNode.java @@ -1,7 +1,7 @@ /* The MIT License -Copyright (c) 2013 Mashape (http://mashape.com) +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/org/openunirest/http/Unirest.java b/src/main/java/org/openunirest/http/Unirest.java index ff20fd1f6..5af751efd 100644 --- a/src/main/java/org/openunirest/http/Unirest.java +++ b/src/main/java/org/openunirest/http/Unirest.java @@ -1,7 +1,7 @@ /* The MIT License -Copyright (c) 2013 Mashape (http://mashape.com) +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/org/openunirest/http/async/Callback.java b/src/main/java/org/openunirest/http/async/Callback.java index eedd4575e..03bc3e3db 100644 --- a/src/main/java/org/openunirest/http/async/Callback.java +++ b/src/main/java/org/openunirest/http/async/Callback.java @@ -1,7 +1,7 @@ /* The MIT License -Copyright (c) 2013 Mashape (http://mashape.com) +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/org/openunirest/http/async/RequestThread.java b/src/main/java/org/openunirest/http/async/RequestThread.java index 598a53aec..6f5f6e2a8 100644 --- a/src/main/java/org/openunirest/http/async/RequestThread.java +++ b/src/main/java/org/openunirest/http/async/RequestThread.java @@ -1,7 +1,7 @@ /* The MIT License -Copyright (c) 2013 Mashape (http://mashape.com) +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/org/openunirest/http/utils/MapUtil.java b/src/main/java/org/openunirest/http/utils/MapUtil.java index 3efcfe502..59ca0479f 100644 --- a/src/main/java/org/openunirest/http/utils/MapUtil.java +++ b/src/main/java/org/openunirest/http/utils/MapUtil.java @@ -1,7 +1,7 @@ /* The MIT License -Copyright (c) 2013 Mashape (http://mashape.com) +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/org/openunirest/http/utils/URLParamEncoder.java b/src/main/java/org/openunirest/http/utils/URLParamEncoder.java index 2d60f883c..56955175d 100644 --- a/src/main/java/org/openunirest/http/utils/URLParamEncoder.java +++ b/src/main/java/org/openunirest/http/utils/URLParamEncoder.java @@ -1,7 +1,7 @@ /* The MIT License -Copyright (c) 2013 Mashape (http://mashape.com) +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/org/openunirest/request/BaseRequest.java b/src/main/java/org/openunirest/request/BaseRequest.java index dc55bb13e..c6a8cae8f 100644 --- a/src/main/java/org/openunirest/request/BaseRequest.java +++ b/src/main/java/org/openunirest/request/BaseRequest.java @@ -1,7 +1,7 @@ /* The MIT License -Copyright (c) 2013 Mashape (http://mashape.com) +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/org/openunirest/request/GetRequest.java b/src/main/java/org/openunirest/request/GetRequest.java index 2e1a144cd..feef2e663 100644 --- a/src/main/java/org/openunirest/request/GetRequest.java +++ b/src/main/java/org/openunirest/request/GetRequest.java @@ -1,7 +1,7 @@ /* The MIT License -Copyright (c) 2013 Mashape (http://mashape.com) +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/org/openunirest/request/HttpRequest.java b/src/main/java/org/openunirest/request/HttpRequest.java index 1ed0ab404..e4b20cb5c 100644 --- a/src/main/java/org/openunirest/request/HttpRequest.java +++ b/src/main/java/org/openunirest/request/HttpRequest.java @@ -1,7 +1,7 @@ /* The MIT License -Copyright (c) 2013 Mashape (http://mashape.com) +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/org/openunirest/request/HttpRequestWithBody.java b/src/main/java/org/openunirest/request/HttpRequestWithBody.java index b91cfea9d..100e8cdff 100644 --- a/src/main/java/org/openunirest/request/HttpRequestWithBody.java +++ b/src/main/java/org/openunirest/request/HttpRequestWithBody.java @@ -1,7 +1,7 @@ /* The MIT License -Copyright (c) 2013 Mashape (http://mashape.com) +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/org/openunirest/request/body/Body.java b/src/main/java/org/openunirest/request/body/Body.java index 5d1dd0468..2fbb45df5 100644 --- a/src/main/java/org/openunirest/request/body/Body.java +++ b/src/main/java/org/openunirest/request/body/Body.java @@ -1,7 +1,7 @@ /* The MIT License -Copyright (c) 2013 Mashape (http://mashape.com) +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/org/openunirest/request/body/MultipartBody.java b/src/main/java/org/openunirest/request/body/MultipartBody.java index 9b657ce78..c72511e21 100644 --- a/src/main/java/org/openunirest/request/body/MultipartBody.java +++ b/src/main/java/org/openunirest/request/body/MultipartBody.java @@ -1,7 +1,7 @@ /* The MIT License -Copyright (c) 2013 Mashape (http://mashape.com) +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/org/openunirest/request/body/RawBody.java b/src/main/java/org/openunirest/request/body/RawBody.java index 4922a9249..8afb5bc20 100644 --- a/src/main/java/org/openunirest/request/body/RawBody.java +++ b/src/main/java/org/openunirest/request/body/RawBody.java @@ -1,7 +1,7 @@ /* The MIT License -Copyright (c) 2013 Mashape (http://mashape.com) +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/org/openunirest/request/body/RequestBodyEntity.java b/src/main/java/org/openunirest/request/body/RequestBodyEntity.java index 9598a7447..db57418e8 100644 --- a/src/main/java/org/openunirest/request/body/RequestBodyEntity.java +++ b/src/main/java/org/openunirest/request/body/RequestBodyEntity.java @@ -1,7 +1,7 @@ /* The MIT License -Copyright (c) 2013 Mashape (http://mashape.com) +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/test/java/org/openunirest/test/http/UnirestTest.java b/src/test/java/org/openunirest/test/http/UnirestTest.java index 4dc83039a..e146cedd3 100644 --- a/src/test/java/org/openunirest/test/http/UnirestTest.java +++ b/src/test/java/org/openunirest/test/http/UnirestTest.java @@ -1,8 +1,8 @@ /* The MIT License -Copyright for portions of project Foo are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for project OpenUnirest/unirest-java are held by OpenUnirest (c) 2017. +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the From 4e145db195adf412d4c572c71d51825615fcacf8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 2 Mar 2018 18:47:46 -0600 Subject: [PATCH 0012/1769] conform to default java standards per intellij --- .editorconfig | 16 -- formatter/unirest-code-format.xml | 295 ------------------------------ 2 files changed, 311 deletions(-) delete mode 100644 .editorconfig delete mode 100644 formatter/unirest-code-format.xml diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index b157c5e6a..000000000 --- a/.editorconfig +++ /dev/null @@ -1,16 +0,0 @@ -# http://editorconfig.org -root = true - -[*] -indent_style = tab -indent_size = 1 -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[*.{xml,yml}] -indent_size = 2 - -[*.{md,yml}] -trim_trailing_whitespace = false diff --git a/formatter/unirest-code-format.xml b/formatter/unirest-code-format.xml deleted file mode 100644 index b532293e8..000000000 --- a/formatter/unirest-code-format.xml +++ /dev/null @@ -1,295 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 491813fe7d74c75cd2b600f5984d817ef59e8ff2 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 3 Mar 2018 08:22:19 -0600 Subject: [PATCH 0013/1769] refactor Options so that it doesnt just spawn zombie threads all over the place. closes #8 --- pom.xml | 7 ++ .../java/org/openunirest/http/Unirest.java | 2 +- .../org/openunirest/http/options/Options.java | 106 +++++++++++------- .../openunirest/http/options/OptionsTest.java | 53 +++++++++ 4 files changed, 127 insertions(+), 41 deletions(-) create mode 100644 src/test/java/org/openunirest/http/options/OptionsTest.java diff --git a/pom.xml b/pom.xml index d7aedcb53..1845fd520 100644 --- a/pom.xml +++ b/pom.xml @@ -125,6 +125,13 @@ 4.12 test + + + org.hamcrest + hamcrest-all + 1.3 + test + commons-io commons-io diff --git a/src/main/java/org/openunirest/http/Unirest.java b/src/main/java/org/openunirest/http/Unirest.java index 5af751efd..5e56c95a2 100644 --- a/src/main/java/org/openunirest/http/Unirest.java +++ b/src/main/java/org/openunirest/http/Unirest.java @@ -86,7 +86,7 @@ public static void setObjectMapper(ObjectMapper objectMapper) { * @param connectionTimeout The timeout until a connection with the server is established (in milliseconds). Default is 10000. Set to zero to disable the timeout. * @param socketTimeout The timeout to receive data (in milliseconds). Default is 60000. Set to zero to disable the timeout. */ - public static void setTimeouts(long connectionTimeout, long socketTimeout) { + public static void setTimeouts(int connectionTimeout, int socketTimeout) { Options.setOption(Option.CONNECTION_TIMEOUT, connectionTimeout); Options.setOption(Option.SOCKET_TIMEOUT, socketTimeout); diff --git a/src/main/java/org/openunirest/http/options/Options.java b/src/main/java/org/openunirest/http/options/Options.java index 4dd51df62..830f15b30 100644 --- a/src/main/java/org/openunirest/http/options/Options.java +++ b/src/main/java/org/openunirest/http/options/Options.java @@ -5,6 +5,7 @@ import org.apache.http.HttpHost; import org.apache.http.client.config.RequestConfig; +import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; @@ -17,15 +18,22 @@ import org.openunirest.http.utils.SyncIdleConnectionMonitorThread; public class Options { - - public static final long CONNECTION_TIMEOUT = 10000; - private static final long SOCKET_TIMEOUT = 60000; public static final int MAX_TOTAL = 200; public static final int MAX_PER_ROUTE = 20; + public static final int CONNECTION_TIMEOUT = 10000; + public static final int SOCKET_TIMEOUT = 60000; private static Map options = new HashMap<>(); - private static boolean customClientSet = false; + private static PoolingHttpClientConnectionManager syncConnectionManager; + + static { + init(); + setDefaults(); + refresh(); + } + + private static SyncIdleConnectionMonitorThread defaultSyncMonitor; public static void customClientSet() { customClientSet = true; @@ -46,57 +54,75 @@ public static Object getOption(Option option) { return options.get(option); } - static { - refresh(); + private static T getOptionOrDefault(Option option, T defaultValue){ + return (T)options.computeIfAbsent(option, o -> defaultValue); } - public static void refresh() { - // Load timeouts - Object connectionTimeout = Options.getOption(Option.CONNECTION_TIMEOUT); - if (connectionTimeout == null) - connectionTimeout = CONNECTION_TIMEOUT; - Object socketTimeout = Options.getOption(Option.SOCKET_TIMEOUT); - if (socketTimeout == null) - socketTimeout = SOCKET_TIMEOUT; - - // Load limits - Object maxTotal = Options.getOption(Option.MAX_TOTAL); - if (maxTotal == null) - maxTotal = MAX_TOTAL; - Object maxPerRoute = Options.getOption(Option.MAX_PER_ROUTE); - if (maxPerRoute == null) - maxPerRoute = MAX_PER_ROUTE; - - // Load proxy if set - HttpHost proxy = (HttpHost) Options.getOption(Option.PROXY); + private static void init() { + syncConnectionManager = new PoolingHttpClientConnectionManager(); + defaultSyncMonitor = new SyncIdleConnectionMonitorThread(syncConnectionManager); + defaultSyncMonitor.start(); + setOption(Option.SYNC_MONITOR, defaultSyncMonitor); + } - // Create common default configuration - RequestConfig clientConfig = RequestConfig.custom().setConnectTimeout(((Long) connectionTimeout).intValue()).setSocketTimeout(((Long) socketTimeout).intValue()).setConnectionRequestTimeout(((Long) socketTimeout).intValue()).setProxy(proxy).build(); - PoolingHttpClientConnectionManager syncConnectionManager = new PoolingHttpClientConnectionManager(); - syncConnectionManager.setMaxTotal((Integer) maxTotal); - syncConnectionManager.setDefaultMaxPerRoute((Integer) maxPerRoute); + public static void refresh() { + RequestConfig clientConfig = getRequestConfig(); + + Integer maxTotal = getOptionOrDefault(Option.MAX_TOTAL, MAX_TOTAL); + Integer maxPerRoute = getOptionOrDefault(Option.MAX_PER_ROUTE, MAX_PER_ROUTE); + syncConnectionManager.setMaxTotal(maxTotal); + syncConnectionManager.setDefaultMaxPerRoute(maxPerRoute); // Create clients - setOption(Option.HTTPCLIENT, HttpClientBuilder.create().setDefaultRequestConfig(clientConfig).setConnectionManager(syncConnectionManager).build()); - SyncIdleConnectionMonitorThread syncIdleConnectionMonitorThread = new SyncIdleConnectionMonitorThread(syncConnectionManager); - setOption(Option.SYNC_MONITOR, syncIdleConnectionMonitorThread); - syncIdleConnectionMonitorThread.start(); + CloseableHttpClient build = HttpClientBuilder.create() + .setDefaultRequestConfig(clientConfig) + .setConnectionManager(syncConnectionManager) + .build(); + + setOption(Option.HTTPCLIENT, build); - DefaultConnectingIOReactor ioreactor; PoolingNHttpClientConnectionManager asyncConnectionManager; try { - ioreactor = new DefaultConnectingIOReactor(); - asyncConnectionManager = new PoolingNHttpClientConnectionManager(ioreactor); - asyncConnectionManager.setMaxTotal((Integer) maxTotal); - asyncConnectionManager.setDefaultMaxPerRoute((Integer) maxPerRoute); + asyncConnectionManager = new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor()); + asyncConnectionManager.setMaxTotal(maxTotal); + asyncConnectionManager.setDefaultMaxPerRoute(maxPerRoute); } catch (IOReactorException e) { throw new RuntimeException(e); } - CloseableHttpAsyncClient asyncClient = HttpAsyncClientBuilder.create().setDefaultRequestConfig(clientConfig).setConnectionManager(asyncConnectionManager).build(); + CloseableHttpAsyncClient asyncClient = HttpAsyncClientBuilder.create() + .setDefaultRequestConfig(clientConfig) + .setConnectionManager(asyncConnectionManager) + .build(); + setOption(Option.ASYNCHTTPCLIENT, asyncClient); setOption(Option.ASYNC_MONITOR, new AsyncIdleConnectionMonitorThread(asyncConnectionManager)); } + private static RequestConfig getRequestConfig() { + Integer connectionTimeout = getOptionOrDefault(Option.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT); + Integer socketTimeout = getOptionOrDefault(Option.SOCKET_TIMEOUT, SOCKET_TIMEOUT); + HttpHost proxy = (HttpHost) Options.getOption(Option.PROXY); + return RequestConfig.custom() + .setConnectTimeout(connectionTimeout) + .setSocketTimeout(socketTimeout) + .setConnectionRequestTimeout(socketTimeout) + .setProxy(proxy) + .build(); + } + + public static void reset() { + setDefaults(); + + } + + private static void setDefaults() { + customClientSet = false; + setOption(Option.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT); + setOption(Option.SOCKET_TIMEOUT, SOCKET_TIMEOUT); + setOption(Option.MAX_TOTAL, MAX_TOTAL); + setOption(Option.MAX_PER_ROUTE, MAX_PER_ROUTE); + setOption(Option.SYNC_MONITOR, defaultSyncMonitor); + } } diff --git a/src/test/java/org/openunirest/http/options/OptionsTest.java b/src/test/java/org/openunirest/http/options/OptionsTest.java new file mode 100644 index 000000000..63891b450 --- /dev/null +++ b/src/test/java/org/openunirest/http/options/OptionsTest.java @@ -0,0 +1,53 @@ +package org.openunirest.http.options; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import java.lang.management.ManagementFactory; +import java.util.stream.IntStream; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.Matchers.lessThan; +import static org.junit.Assert.*; + +public class OptionsTest { + + @Before + public void before(){ + Options.reset(); + } + + @Test + public void shouldKeepConnectionTimeOutDefault(){ + assertOpDefault(Options.CONNECTION_TIMEOUT, Option.CONNECTION_TIMEOUT, 4L); + } + + @Test + public void shouldKeepSocketTimeoutDefault(){ + assertOpDefault(Options.SOCKET_TIMEOUT, Option.SOCKET_TIMEOUT, 4L); + } + + @Test + public void shouldKeepMaxTotalDefault(){ + assertOpDefault(Options.MAX_TOTAL, Option.MAX_TOTAL, 4); + } + + @Test + public void shouldKeepMaxPerRouteDefault(){ + assertOpDefault(Options.MAX_PER_ROUTE, Option.MAX_PER_ROUTE, 4); + } + + private void assertOpDefault(Object defValue, Option option, Object newValue) { + assertEquals(defValue, Options.getOption(option)); + Options.setOption(option, newValue); + assertEquals(newValue, Options.getOption(option)); + } + + @Test + public void shouldReuseThreadPool() { + int startingCount = ManagementFactory.getThreadMXBean().getThreadCount(); + IntStream.range(0,100).forEach(i -> Options.refresh()); + assertThat(ManagementFactory.getThreadMXBean().getThreadCount(), is(lessThan(startingCount + 10))); + } +} \ No newline at end of file From 94ddf7c7244327ebf666d7a07854cf049bba0c33 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 4 Mar 2018 09:41:21 -0600 Subject: [PATCH 0014/1769] trigger travis --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 06d8ee986..173d87a67 100644 --- a/README.md +++ b/README.md @@ -284,3 +284,6 @@ Unirest starts a background event loop and your Java application won't be able t ```java Unirest.shutdown(); ``` + + + From 765e353f54c47ca4552d0294bd9940fee8a948a1 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 4 Mar 2018 09:46:51 -0600 Subject: [PATCH 0015/1769] Update README.md --- README.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/README.md b/README.md index 173d87a67..dedca95fe 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,4 @@ -# Unirest for Java [![Build Status][travis-image]][travis-url] - -![][unirest-logo] - - -[Unirest](http://unirest.io) is a set of lightweight HTTP libraries available in multiple languages, built and maintained by [Mashape](https://github.com/Mashape), who also maintain the open-source API Gateway [Kong](https://github.com/Mashape/kong). +# Unirest for Java [![Build Status](https://travis-ci.org/OpenUnirest/unirest-java.svg?branch=master)](https://travis-ci.org/OpenUnirest/unirest-java) Do yourself a favor, and start making HTTP requests like this: From 2857355e7b4a57eb75d8d8903b38ece45d59695e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 6 Mar 2018 10:19:04 -0600 Subject: [PATCH 0016/1769] change namespace --- pom.xml | 2 +- .../{org => io/github}/openunirest/http/Headers.java | 2 +- .../github}/openunirest/http/HttpClientHelper.java | 2 +- .../github}/openunirest/http/HttpDeleteWithBody.java | 2 +- .../github}/openunirest/http/HttpMethod.java | 2 +- .../github}/openunirest/http/HttpPatchWithBody.java | 2 +- .../github}/openunirest/http/HttpResponse.java | 2 +- .../github}/openunirest/http/JsonNode.java | 2 +- .../github}/openunirest/http/ObjectMapper.java | 2 +- .../{org => io/github}/openunirest/http/Unirest.java | 4 +++- .../github}/openunirest/http/async/Callback.java | 2 +- .../openunirest/http/async/RequestThread.java | 3 ++- .../utils/AsyncIdleConnectionMonitorThread.java | 2 +- .../http/exceptions/UnirestException.java | 2 +- .../github}/openunirest/http/options/Option.java | 2 +- .../github}/openunirest/http/options/Options.java | 4 +++- .../github}/openunirest/http/utils/Base64Coder.java | 2 +- .../openunirest/http/utils/ClientFactory.java | 2 +- .../github}/openunirest/http/utils/MapUtil.java | 2 +- .../openunirest/http/utils/ResponseUtils.java | 2 +- .../http/utils/SyncIdleConnectionMonitorThread.java | 2 +- .../openunirest/http/utils/URLParamEncoder.java | 2 +- .../github}/openunirest/request/BaseRequest.java | 6 +++++- .../github}/openunirest/request/GetRequest.java | 3 ++- .../github}/openunirest/request/HttpRequest.java | 4 +++- .../openunirest/request/HttpRequestWithBody.java | 6 +++++- .../github}/openunirest/request/body/Body.java | 2 +- .../openunirest/request/body/MultipartBody.java | 2 +- .../github}/openunirest/request/body/RawBody.java | 4 +++- .../openunirest/request/body/RequestBodyEntity.java | 5 ++++- .../openunirest/http/options/OptionsTest.java | 2 +- .../github}/openunirest/test/helper/GetResponse.java | 2 +- .../openunirest/test/helper/JacksonObjectMapper.java | 3 ++- .../github}/openunirest/test/http/MockServer.java | 2 +- .../github}/openunirest/test/http/UnirestTest.java | 12 ++++++++++-- 35 files changed, 66 insertions(+), 36 deletions(-) rename src/main/java/{org => io/github}/openunirest/http/Headers.java (90%) rename src/main/java/{org => io/github}/openunirest/http/HttpClientHelper.java (99%) rename src/main/java/{org => io/github}/openunirest/http/HttpDeleteWithBody.java (97%) rename src/main/java/{org => io/github}/openunirest/http/HttpMethod.java (97%) rename src/main/java/{org => io/github}/openunirest/http/HttpPatchWithBody.java (97%) rename src/main/java/{org => io/github}/openunirest/http/HttpResponse.java (99%) rename src/main/java/{org => io/github}/openunirest/http/JsonNode.java (98%) rename src/main/java/{org => io/github}/openunirest/http/ObjectMapper.java (77%) rename src/main/java/{org => io/github}/openunirest/http/Unirest.java (97%) rename src/main/java/{org => io/github}/openunirest/http/async/Callback.java (97%) rename src/main/java/{org => io/github}/openunirest/http/async/RequestThread.java (95%) rename src/main/java/{org => io/github}/openunirest/http/async/utils/AsyncIdleConnectionMonitorThread.java (94%) rename src/main/java/{org => io/github}/openunirest/http/exceptions/UnirestException.java (83%) rename src/main/java/{org => io/github}/openunirest/http/options/Option.java (80%) rename src/main/java/{org => io/github}/openunirest/http/options/Options.java (95%) rename src/main/java/{org => io/github}/openunirest/http/utils/Base64Coder.java (99%) rename src/main/java/{org => io/github}/openunirest/http/utils/ClientFactory.java (92%) rename src/main/java/{org => io/github}/openunirest/http/utils/MapUtil.java (98%) rename src/main/java/{org => io/github}/openunirest/http/utils/ResponseUtils.java (97%) rename src/main/java/{org => io/github}/openunirest/http/utils/SyncIdleConnectionMonitorThread.java (94%) rename src/main/java/{org => io/github}/openunirest/http/utils/URLParamEncoder.java (97%) rename src/main/java/{org => io/github}/openunirest/request/BaseRequest.java (94%) rename src/main/java/{org => io/github}/openunirest/request/GetRequest.java (95%) rename src/main/java/{org => io/github}/openunirest/request/HttpRequest.java (97%) rename src/main/java/{org => io/github}/openunirest/request/HttpRequestWithBody.java (96%) rename src/main/java/{org => io/github}/openunirest/request/body/Body.java (96%) rename src/main/java/{org => io/github}/openunirest/request/body/MultipartBody.java (99%) rename src/main/java/{org => io/github}/openunirest/request/body/RawBody.java (92%) rename src/main/java/{org => io/github}/openunirest/request/body/RequestBodyEntity.java (91%) rename src/test/java/{org => io/github}/openunirest/http/options/OptionsTest.java (97%) rename src/test/java/{org => io/github}/openunirest/test/helper/GetResponse.java (88%) rename src/test/java/{org => io/github}/openunirest/test/helper/JacksonObjectMapper.java (88%) rename src/test/java/{org => io/github}/openunirest/test/http/MockServer.java (98%) rename src/test/java/{org => io/github}/openunirest/test/http/UnirestTest.java (98%) diff --git a/pom.xml b/pom.xml index 1845fd520..39485a000 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - org.openunirest.unirest + io.github.openunirest unirest-java jar 2.0.00-SNAPSHOT diff --git a/src/main/java/org/openunirest/http/Headers.java b/src/main/java/io/github/openunirest/http/Headers.java similarity index 90% rename from src/main/java/org/openunirest/http/Headers.java rename to src/main/java/io/github/openunirest/http/Headers.java index e05ec69aa..958d79ed3 100644 --- a/src/main/java/org/openunirest/http/Headers.java +++ b/src/main/java/io/github/openunirest/http/Headers.java @@ -1,4 +1,4 @@ -package org.openunirest.http; +package io.github.openunirest.http; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/org/openunirest/http/HttpClientHelper.java b/src/main/java/io/github/openunirest/http/HttpClientHelper.java similarity index 99% rename from src/main/java/org/openunirest/http/HttpClientHelper.java rename to src/main/java/io/github/openunirest/http/HttpClientHelper.java index fa1865267..c1701d629 100644 --- a/src/main/java/org/openunirest/http/HttpClientHelper.java +++ b/src/main/java/io/github/openunirest/http/HttpClientHelper.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.openunirest.http; +package io.github.openunirest.http; import java.io.ByteArrayOutputStream; import java.io.IOException; diff --git a/src/main/java/org/openunirest/http/HttpDeleteWithBody.java b/src/main/java/io/github/openunirest/http/HttpDeleteWithBody.java similarity index 97% rename from src/main/java/org/openunirest/http/HttpDeleteWithBody.java rename to src/main/java/io/github/openunirest/http/HttpDeleteWithBody.java index de824bf34..7f3f40399 100644 --- a/src/main/java/org/openunirest/http/HttpDeleteWithBody.java +++ b/src/main/java/io/github/openunirest/http/HttpDeleteWithBody.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.openunirest.http; +package io.github.openunirest.http; import java.net.URI; diff --git a/src/main/java/org/openunirest/http/HttpMethod.java b/src/main/java/io/github/openunirest/http/HttpMethod.java similarity index 97% rename from src/main/java/org/openunirest/http/HttpMethod.java rename to src/main/java/io/github/openunirest/http/HttpMethod.java index f6385f7b7..84e98115f 100644 --- a/src/main/java/org/openunirest/http/HttpMethod.java +++ b/src/main/java/io/github/openunirest/http/HttpMethod.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.openunirest.http; +package io.github.openunirest.http; public enum HttpMethod { GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS; diff --git a/src/main/java/org/openunirest/http/HttpPatchWithBody.java b/src/main/java/io/github/openunirest/http/HttpPatchWithBody.java similarity index 97% rename from src/main/java/org/openunirest/http/HttpPatchWithBody.java rename to src/main/java/io/github/openunirest/http/HttpPatchWithBody.java index 1214ba7e4..a2bb8b635 100644 --- a/src/main/java/org/openunirest/http/HttpPatchWithBody.java +++ b/src/main/java/io/github/openunirest/http/HttpPatchWithBody.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.openunirest.http; +package io.github.openunirest.http; import java.net.URI; diff --git a/src/main/java/org/openunirest/http/HttpResponse.java b/src/main/java/io/github/openunirest/http/HttpResponse.java similarity index 99% rename from src/main/java/org/openunirest/http/HttpResponse.java rename to src/main/java/io/github/openunirest/http/HttpResponse.java index 331fcb528..2b2c7585d 100644 --- a/src/main/java/org/openunirest/http/HttpResponse.java +++ b/src/main/java/io/github/openunirest/http/HttpResponse.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.openunirest.http; +package io.github.openunirest.http; import org.openunirest.http.options.Option; import org.openunirest.http.options.Options; diff --git a/src/main/java/org/openunirest/http/JsonNode.java b/src/main/java/io/github/openunirest/http/JsonNode.java similarity index 98% rename from src/main/java/org/openunirest/http/JsonNode.java rename to src/main/java/io/github/openunirest/http/JsonNode.java index 69fb71910..856128d41 100644 --- a/src/main/java/org/openunirest/http/JsonNode.java +++ b/src/main/java/io/github/openunirest/http/JsonNode.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.openunirest.http; +package io.github.openunirest.http; import org.json.JSONArray; import org.json.JSONException; diff --git a/src/main/java/org/openunirest/http/ObjectMapper.java b/src/main/java/io/github/openunirest/http/ObjectMapper.java similarity index 77% rename from src/main/java/org/openunirest/http/ObjectMapper.java rename to src/main/java/io/github/openunirest/http/ObjectMapper.java index 742deeb8b..a1a58809d 100644 --- a/src/main/java/org/openunirest/http/ObjectMapper.java +++ b/src/main/java/io/github/openunirest/http/ObjectMapper.java @@ -1,4 +1,4 @@ -package org.openunirest.http; +package io.github.openunirest.http; public interface ObjectMapper { diff --git a/src/main/java/org/openunirest/http/Unirest.java b/src/main/java/io/github/openunirest/http/Unirest.java similarity index 97% rename from src/main/java/org/openunirest/http/Unirest.java rename to src/main/java/io/github/openunirest/http/Unirest.java index 5e56c95a2..bdf307ff1 100644 --- a/src/main/java/org/openunirest/http/Unirest.java +++ b/src/main/java/io/github/openunirest/http/Unirest.java @@ -23,8 +23,10 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.openunirest.http; +package io.github.openunirest.http; +import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; +import io.github.openunirest.http.utils.SyncIdleConnectionMonitorThread; import org.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; import org.openunirest.http.options.Option; import org.openunirest.http.options.Options; diff --git a/src/main/java/org/openunirest/http/async/Callback.java b/src/main/java/io/github/openunirest/http/async/Callback.java similarity index 97% rename from src/main/java/org/openunirest/http/async/Callback.java rename to src/main/java/io/github/openunirest/http/async/Callback.java index 03bc3e3db..d7403d9bd 100644 --- a/src/main/java/org/openunirest/http/async/Callback.java +++ b/src/main/java/io/github/openunirest/http/async/Callback.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.openunirest.http.async; +package io.github.openunirest.http.async; import org.openunirest.http.HttpResponse; import org.openunirest.http.exceptions.UnirestException; diff --git a/src/main/java/org/openunirest/http/async/RequestThread.java b/src/main/java/io/github/openunirest/http/async/RequestThread.java similarity index 95% rename from src/main/java/org/openunirest/http/async/RequestThread.java rename to src/main/java/io/github/openunirest/http/async/RequestThread.java index 6f5f6e2a8..19731b8bc 100644 --- a/src/main/java/org/openunirest/http/async/RequestThread.java +++ b/src/main/java/io/github/openunirest/http/async/RequestThread.java @@ -23,8 +23,9 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.openunirest.http.async; +package io.github.openunirest.http.async; +import io.github.openunirest.http.HttpClientHelper; import org.openunirest.http.HttpClientHelper; import org.openunirest.http.HttpResponse; import org.openunirest.http.exceptions.UnirestException; diff --git a/src/main/java/org/openunirest/http/async/utils/AsyncIdleConnectionMonitorThread.java b/src/main/java/io/github/openunirest/http/async/utils/AsyncIdleConnectionMonitorThread.java similarity index 94% rename from src/main/java/org/openunirest/http/async/utils/AsyncIdleConnectionMonitorThread.java rename to src/main/java/io/github/openunirest/http/async/utils/AsyncIdleConnectionMonitorThread.java index 1f2093f15..aaa6e447d 100644 --- a/src/main/java/org/openunirest/http/async/utils/AsyncIdleConnectionMonitorThread.java +++ b/src/main/java/io/github/openunirest/http/async/utils/AsyncIdleConnectionMonitorThread.java @@ -1,4 +1,4 @@ -package org.openunirest.http.async.utils; +package io.github.openunirest.http.async.utils; import java.util.concurrent.TimeUnit; diff --git a/src/main/java/org/openunirest/http/exceptions/UnirestException.java b/src/main/java/io/github/openunirest/http/exceptions/UnirestException.java similarity index 83% rename from src/main/java/org/openunirest/http/exceptions/UnirestException.java rename to src/main/java/io/github/openunirest/http/exceptions/UnirestException.java index 16d0f763c..52594c40b 100644 --- a/src/main/java/org/openunirest/http/exceptions/UnirestException.java +++ b/src/main/java/io/github/openunirest/http/exceptions/UnirestException.java @@ -1,4 +1,4 @@ -package org.openunirest.http.exceptions; +package io.github.openunirest.http.exceptions; public class UnirestException extends RuntimeException { diff --git a/src/main/java/org/openunirest/http/options/Option.java b/src/main/java/io/github/openunirest/http/options/Option.java similarity index 80% rename from src/main/java/org/openunirest/http/options/Option.java rename to src/main/java/io/github/openunirest/http/options/Option.java index 649dd97ea..c9e30e514 100644 --- a/src/main/java/org/openunirest/http/options/Option.java +++ b/src/main/java/io/github/openunirest/http/options/Option.java @@ -1,4 +1,4 @@ -package org.openunirest.http.options; +package io.github.openunirest.http.options; public enum Option { HTTPCLIENT, ASYNCHTTPCLIENT, CONNECTION_TIMEOUT, SOCKET_TIMEOUT, DEFAULT_HEADERS, SYNC_MONITOR, ASYNC_MONITOR, MAX_TOTAL, MAX_PER_ROUTE, PROXY, OBJECT_MAPPER diff --git a/src/main/java/org/openunirest/http/options/Options.java b/src/main/java/io/github/openunirest/http/options/Options.java similarity index 95% rename from src/main/java/org/openunirest/http/options/Options.java rename to src/main/java/io/github/openunirest/http/options/Options.java index 830f15b30..570542e32 100644 --- a/src/main/java/org/openunirest/http/options/Options.java +++ b/src/main/java/io/github/openunirest/http/options/Options.java @@ -1,8 +1,10 @@ -package org.openunirest.http.options; +package io.github.openunirest.http.options; import java.util.HashMap; import java.util.Map; +import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; +import io.github.openunirest.http.utils.SyncIdleConnectionMonitorThread; import org.apache.http.HttpHost; import org.apache.http.client.config.RequestConfig; import org.apache.http.impl.client.CloseableHttpClient; diff --git a/src/main/java/org/openunirest/http/utils/Base64Coder.java b/src/main/java/io/github/openunirest/http/utils/Base64Coder.java similarity index 99% rename from src/main/java/org/openunirest/http/utils/Base64Coder.java rename to src/main/java/io/github/openunirest/http/utils/Base64Coder.java index 6e87a9c4f..d1102204c 100644 --- a/src/main/java/org/openunirest/http/utils/Base64Coder.java +++ b/src/main/java/io/github/openunirest/http/utils/Base64Coder.java @@ -1,4 +1,4 @@ -package org.openunirest.http.utils; +package io.github.openunirest.http.utils; //Copyright 2003-2010 Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland //www.source-code.biz, www.inventec.ch/chdh diff --git a/src/main/java/org/openunirest/http/utils/ClientFactory.java b/src/main/java/io/github/openunirest/http/utils/ClientFactory.java similarity index 92% rename from src/main/java/org/openunirest/http/utils/ClientFactory.java rename to src/main/java/io/github/openunirest/http/utils/ClientFactory.java index 72f333d16..912f09d50 100644 --- a/src/main/java/org/openunirest/http/utils/ClientFactory.java +++ b/src/main/java/io/github/openunirest/http/utils/ClientFactory.java @@ -1,4 +1,4 @@ -package org.openunirest.http.utils; +package io.github.openunirest.http.utils; import org.apache.http.client.HttpClient; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; diff --git a/src/main/java/org/openunirest/http/utils/MapUtil.java b/src/main/java/io/github/openunirest/http/utils/MapUtil.java similarity index 98% rename from src/main/java/org/openunirest/http/utils/MapUtil.java rename to src/main/java/io/github/openunirest/http/utils/MapUtil.java index 59ca0479f..babe0e106 100644 --- a/src/main/java/org/openunirest/http/utils/MapUtil.java +++ b/src/main/java/io/github/openunirest/http/utils/MapUtil.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.openunirest.http.utils; +package io.github.openunirest.http.utils; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/openunirest/http/utils/ResponseUtils.java b/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java similarity index 97% rename from src/main/java/org/openunirest/http/utils/ResponseUtils.java rename to src/main/java/io/github/openunirest/http/utils/ResponseUtils.java index 89196f312..c1073cff2 100644 --- a/src/main/java/org/openunirest/http/utils/ResponseUtils.java +++ b/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java @@ -1,4 +1,4 @@ -package org.openunirest.http.utils; +package io.github.openunirest.http.utils; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; diff --git a/src/main/java/org/openunirest/http/utils/SyncIdleConnectionMonitorThread.java b/src/main/java/io/github/openunirest/http/utils/SyncIdleConnectionMonitorThread.java similarity index 94% rename from src/main/java/org/openunirest/http/utils/SyncIdleConnectionMonitorThread.java rename to src/main/java/io/github/openunirest/http/utils/SyncIdleConnectionMonitorThread.java index 5adceba1a..696dacafd 100644 --- a/src/main/java/org/openunirest/http/utils/SyncIdleConnectionMonitorThread.java +++ b/src/main/java/io/github/openunirest/http/utils/SyncIdleConnectionMonitorThread.java @@ -1,4 +1,4 @@ -package org.openunirest.http.utils; +package io.github.openunirest.http.utils; import java.util.concurrent.TimeUnit; diff --git a/src/main/java/org/openunirest/http/utils/URLParamEncoder.java b/src/main/java/io/github/openunirest/http/utils/URLParamEncoder.java similarity index 97% rename from src/main/java/org/openunirest/http/utils/URLParamEncoder.java rename to src/main/java/io/github/openunirest/http/utils/URLParamEncoder.java index 56955175d..c6403b892 100644 --- a/src/main/java/org/openunirest/http/utils/URLParamEncoder.java +++ b/src/main/java/io/github/openunirest/http/utils/URLParamEncoder.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.openunirest.http.utils; +package io.github.openunirest.http.utils; public class URLParamEncoder { diff --git a/src/main/java/org/openunirest/request/BaseRequest.java b/src/main/java/io/github/openunirest/request/BaseRequest.java similarity index 94% rename from src/main/java/org/openunirest/request/BaseRequest.java rename to src/main/java/io/github/openunirest/request/BaseRequest.java index c6a8cae8f..e59348ed6 100644 --- a/src/main/java/org/openunirest/request/BaseRequest.java +++ b/src/main/java/io/github/openunirest/request/BaseRequest.java @@ -23,8 +23,12 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.openunirest.request; +package io.github.openunirest.request; +import io.github.openunirest.http.HttpClientHelper; +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.JsonNode; +import io.github.openunirest.http.async.Callback; import org.openunirest.http.HttpClientHelper; import org.openunirest.http.HttpResponse; import org.openunirest.http.JsonNode; diff --git a/src/main/java/org/openunirest/request/GetRequest.java b/src/main/java/io/github/openunirest/request/GetRequest.java similarity index 95% rename from src/main/java/org/openunirest/request/GetRequest.java rename to src/main/java/io/github/openunirest/request/GetRequest.java index feef2e663..44c904626 100644 --- a/src/main/java/org/openunirest/request/GetRequest.java +++ b/src/main/java/io/github/openunirest/request/GetRequest.java @@ -23,10 +23,11 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.openunirest.request; +package io.github.openunirest.request; import java.util.Map; +import io.github.openunirest.http.HttpMethod; import org.openunirest.http.HttpMethod; public class GetRequest extends HttpRequest { diff --git a/src/main/java/org/openunirest/request/HttpRequest.java b/src/main/java/io/github/openunirest/request/HttpRequest.java similarity index 97% rename from src/main/java/org/openunirest/request/HttpRequest.java rename to src/main/java/io/github/openunirest/request/HttpRequest.java index e4b20cb5c..975db3a40 100644 --- a/src/main/java/org/openunirest/request/HttpRequest.java +++ b/src/main/java/io/github/openunirest/request/HttpRequest.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.openunirest.request; +package io.github.openunirest.request; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -37,6 +37,8 @@ a copy of this software and associated documentation files (the import java.util.regex.Matcher; import java.util.regex.Pattern; +import io.github.openunirest.http.HttpMethod; +import io.github.openunirest.request.body.Body; import org.openunirest.http.HttpMethod; import org.openunirest.http.utils.Base64Coder; import org.openunirest.http.utils.URLParamEncoder; diff --git a/src/main/java/org/openunirest/request/HttpRequestWithBody.java b/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java similarity index 96% rename from src/main/java/org/openunirest/request/HttpRequestWithBody.java rename to src/main/java/io/github/openunirest/request/HttpRequestWithBody.java index 100e8cdff..751fb3ae7 100644 --- a/src/main/java/org/openunirest/request/HttpRequestWithBody.java +++ b/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java @@ -23,8 +23,12 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.openunirest.request; +package io.github.openunirest.request; +import io.github.openunirest.http.HttpMethod; +import io.github.openunirest.http.JsonNode; +import io.github.openunirest.http.ObjectMapper; +import io.github.openunirest.request.body.MultipartBody; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.content.InputStreamBody; diff --git a/src/main/java/org/openunirest/request/body/Body.java b/src/main/java/io/github/openunirest/request/body/Body.java similarity index 96% rename from src/main/java/org/openunirest/request/body/Body.java rename to src/main/java/io/github/openunirest/request/body/Body.java index 2fbb45df5..699f6ab69 100644 --- a/src/main/java/org/openunirest/request/body/Body.java +++ b/src/main/java/io/github/openunirest/request/body/Body.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.openunirest.request.body; +package io.github.openunirest.request.body; import org.apache.http.HttpEntity; diff --git a/src/main/java/org/openunirest/request/body/MultipartBody.java b/src/main/java/io/github/openunirest/request/body/MultipartBody.java similarity index 99% rename from src/main/java/org/openunirest/request/body/MultipartBody.java rename to src/main/java/io/github/openunirest/request/body/MultipartBody.java index c72511e21..7a2eedf54 100644 --- a/src/main/java/org/openunirest/request/body/MultipartBody.java +++ b/src/main/java/io/github/openunirest/request/body/MultipartBody.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.openunirest.request.body; +package io.github.openunirest.request.body; import java.io.File; import java.io.InputStream; diff --git a/src/main/java/org/openunirest/request/body/RawBody.java b/src/main/java/io/github/openunirest/request/body/RawBody.java similarity index 92% rename from src/main/java/org/openunirest/request/body/RawBody.java rename to src/main/java/io/github/openunirest/request/body/RawBody.java index 8afb5bc20..16a695fac 100644 --- a/src/main/java/org/openunirest/request/body/RawBody.java +++ b/src/main/java/io/github/openunirest/request/body/RawBody.java @@ -23,8 +23,10 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.openunirest.request.body; +package io.github.openunirest.request.body; +import io.github.openunirest.request.BaseRequest; +import io.github.openunirest.request.HttpRequest; import org.openunirest.request.BaseRequest; import org.openunirest.request.HttpRequest; import org.apache.http.HttpEntity; diff --git a/src/main/java/org/openunirest/request/body/RequestBodyEntity.java b/src/main/java/io/github/openunirest/request/body/RequestBodyEntity.java similarity index 91% rename from src/main/java/org/openunirest/request/body/RequestBodyEntity.java rename to src/main/java/io/github/openunirest/request/body/RequestBodyEntity.java index db57418e8..08e78288d 100644 --- a/src/main/java/org/openunirest/request/body/RequestBodyEntity.java +++ b/src/main/java/io/github/openunirest/request/body/RequestBodyEntity.java @@ -23,8 +23,11 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.openunirest.request.body; +package io.github.openunirest.request.body; +import io.github.openunirest.http.JsonNode; +import io.github.openunirest.request.BaseRequest; +import io.github.openunirest.request.HttpRequest; import org.apache.http.HttpEntity; import org.apache.http.entity.StringEntity; diff --git a/src/test/java/org/openunirest/http/options/OptionsTest.java b/src/test/java/io/github/openunirest/http/options/OptionsTest.java similarity index 97% rename from src/test/java/org/openunirest/http/options/OptionsTest.java rename to src/test/java/io/github/openunirest/http/options/OptionsTest.java index 63891b450..c97ef099c 100644 --- a/src/test/java/org/openunirest/http/options/OptionsTest.java +++ b/src/test/java/io/github/openunirest/http/options/OptionsTest.java @@ -1,4 +1,4 @@ -package org.openunirest.http.options; +package io.github.openunirest.http.options; import org.junit.Before; import org.junit.Ignore; diff --git a/src/test/java/org/openunirest/test/helper/GetResponse.java b/src/test/java/io/github/openunirest/test/helper/GetResponse.java similarity index 88% rename from src/test/java/org/openunirest/test/helper/GetResponse.java rename to src/test/java/io/github/openunirest/test/helper/GetResponse.java index 7a861dcf1..e2f07017d 100644 --- a/src/test/java/org/openunirest/test/helper/GetResponse.java +++ b/src/test/java/io/github/openunirest/test/helper/GetResponse.java @@ -1,4 +1,4 @@ -package org.openunirest.test.helper; +package io.github.openunirest.test.helper; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/test/java/org/openunirest/test/helper/JacksonObjectMapper.java b/src/test/java/io/github/openunirest/test/helper/JacksonObjectMapper.java similarity index 88% rename from src/test/java/org/openunirest/test/helper/JacksonObjectMapper.java rename to src/test/java/io/github/openunirest/test/helper/JacksonObjectMapper.java index 38210a679..36acc6603 100644 --- a/src/test/java/org/openunirest/test/helper/JacksonObjectMapper.java +++ b/src/test/java/io/github/openunirest/test/helper/JacksonObjectMapper.java @@ -1,6 +1,7 @@ -package org.openunirest.test.helper; +package io.github.openunirest.test.helper; import com.fasterxml.jackson.core.JsonProcessingException; +import io.github.openunirest.http.ObjectMapper; import org.openunirest.http.ObjectMapper; import java.io.IOException; diff --git a/src/test/java/org/openunirest/test/http/MockServer.java b/src/test/java/io/github/openunirest/test/http/MockServer.java similarity index 98% rename from src/test/java/org/openunirest/test/http/MockServer.java rename to src/test/java/io/github/openunirest/test/http/MockServer.java index 50e46c589..c4f81cfe6 100644 --- a/src/test/java/org/openunirest/test/http/MockServer.java +++ b/src/test/java/io/github/openunirest/test/http/MockServer.java @@ -24,7 +24,7 @@ a copy of this software and associated documentation files (the */ -package org.openunirest.test.http; +package io.github.openunirest.test.http; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.http.entity.ContentType; diff --git a/src/test/java/org/openunirest/test/http/UnirestTest.java b/src/test/java/io/github/openunirest/test/http/UnirestTest.java similarity index 98% rename from src/test/java/org/openunirest/test/http/UnirestTest.java rename to src/test/java/io/github/openunirest/test/http/UnirestTest.java index e146cedd3..bdb312221 100644 --- a/src/test/java/org/openunirest/test/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/test/http/UnirestTest.java @@ -24,8 +24,16 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.openunirest.test.http; - +package io.github.openunirest.test.http; + +import io.github.openunirest.http.Headers; +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.JsonNode; +import io.github.openunirest.http.Unirest; +import io.github.openunirest.http.async.Callback; +import io.github.openunirest.request.body.MultipartBody; +import io.github.openunirest.test.helper.GetResponse; +import io.github.openunirest.test.helper.JacksonObjectMapper; import org.openunirest.http.async.Callback; import org.openunirest.http.exceptions.UnirestException; import org.openunirest.http.options.Options; From 9dfded147ed5d50ac81f645e6318ed106b2216ba Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 6 Mar 2018 10:33:37 -0600 Subject: [PATCH 0017/1769] add docs --- docs/.gitignore | 1 + docs/README.md | 69 +++++ docs/favicon.ico | Bin 0 -> 1150 bytes docs/img/arc-enable.png | Bin 0 -> 26473 bytes docs/img/logo.png | Bin 0 -> 68851 bytes docs/index.html | 329 ++++++++++++++++++++++++ docs/styles/fonts.css | 132 ++++++++++ docs/styles/homepage.css | 312 +++++++++++++++++++++++ docs/styles/library.css | 517 ++++++++++++++++++++++++++++++++++++++ docs/styles/normalize.css | 1 + 10 files changed, 1361 insertions(+) create mode 100644 docs/.gitignore create mode 100644 docs/README.md create mode 100644 docs/favicon.ico create mode 100644 docs/img/arc-enable.png create mode 100644 docs/img/logo.png create mode 100644 docs/index.html create mode 100644 docs/styles/fonts.css create mode 100644 docs/styles/homepage.css create mode 100644 docs/styles/library.css create mode 100644 docs/styles/normalize.css diff --git a/docs/.gitignore b/docs/.gitignore new file mode 100644 index 000000000..e43b0f988 --- /dev/null +++ b/docs/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 000000000..e945eefe6 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,69 @@ +# [Unirest.io](http://unirest.io) + + +We released our newest open source project, which we called unicorn, unfortunately that was also the name of two other open source projects. We really dropped the ball and have been working hard to clean up the mess. We would like to apologize to anyone in the Ruby or Python community who was confused or annoyed. Hopefully you can look past our mistake and see the value in this project. + +So, we have decided on a new name, Unirest, which we think is a great fit for the project. We also made a [new website](http://unirest.io), updated our docs and [marketplace](http://mashape.com) which autogenerates unirest code snippets and have the open source API gateway [Kong](http://github.com/mahsape/kong) + +### What problem does Unirest solve? + +We’ve noticed that a lot of people have trouble wrapping their head around using public and private APIs. With API keys, varying endpoint architecture, differing response types, etc… there is a lot to think about. + +Unirest tries to simplify the process of consuming APIs by abstracting a lot of the boilerplate and focusing on the core REST verbs that we all know and love (GET, POST, PUT, UPDATE, DELETE). Similarly its methods and response structures are the same in all the supported languages. It works for all REST APIs, available both on our own mashape API marketplace and abroad. + +We truly believe that APIs are changing the way we make software and by extension the world at large. Never has so much power been in the hands of a solo developer with an idea. Our hope is that the developer community that we love will find this project helpful and build a ton of great stuff on top of it. + +### Let's see some code + +The following code submits a post request to [httpbin.org](http://httpbin.org) + +#### Java +```java +HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") + .header("accept", "application/json") + .field("parameter", "value") + .field("foo", "bar") + .asJson(); +``` + + +#### PHP +```php +$response = Unirest\Request::post("http://httpbin.org/post", + array( "Accept" => "application/json" ), + array( + "parameter" => 23, + "foo" => "bar" + ) +); +``` + +#### Ruby +```ruby +response = Unirest::post "http://httpbin.org/post", + { "Accept" => "application/json" }, + { + :parameter => 23, + :foo => "bar" + } +``` + +#### Python +```python +response = unirest.post("http://httpbin.org/post", + { "Accept": "application/json" }, + { "parameter": 23, "foo": "bar" } +) +``` + +#### Objective-C +```objective-c +NSDictionary* headers = [NSDictionary dictionaryWithObjectsAndKeys:@"application/json", @"accept", nil]; +NSDictionary* parameters = [NSDictionary dictionaryWithObjectsAndKeys:@"value", @"parameter", @"bar", @"foo", nil]; + +HttpJsonResponse* response = [[Unirest post:^(MultipartRequest* request) { + [request setUrl:@"http://httpbin.org/post"]; + [request setHeaders:headers]; + [request setParameters:parameters]; +}] asJson]; +``` diff --git a/docs/favicon.ico b/docs/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..b1d136402a51aa2df9a84cec1f6285d0d46c0259 GIT binary patch literal 1150 zcmb7^%WoT16vhXMKcFjC;Jh4r?6Dok&-gv|*q-rY#*f$`Ng)X|fh>3k6;O*nRYR2p zC>v1eizq3T8dM?FMY@2LfCNSSDX1GnyP#!}A19MtcihpP$C>Zk`GN=PCnak(gpynA+({aspW8&fmr#@blHc}%rIKh~wFRWY;@4YkUd z%#f0=OebPf3s~elDU3jxgfCBJ%0i#E7);ON_#9p@F5!fGnDGYsNC{&shZ(G5h5Hz) zK`KyY`b8hQmZKT6na`c3J2PZHIbqm*uApHom+Q#`t)C({PTo2>{YV90@Zkh;#gXEJ5)6r z-CM_+nqwI6@bmsJ?!H&Hu2CATQ44o@aQ_cC_Vv~_88t_CGK1;OQ}ARkCM}v#(RRE^ zOR&Ek{O)2uJO4SB=8zY?Zr=FjB>(bFbbpPaS109(GfcK=20NmKXsz`rhTHsl_`t<( zey~M1@hT;6gWEUu+}QS4w=lykRtl?FYLQmVq!#TlNG-CMd4;@ac=*E!|BGigsRjn* z#vS&qee335{c@M0?B5fF0a2*QL!=Lu=yV$eq=O~99q9ZMKuirVz|6&_`tcNB2TFiFIPUNKa z6)K6Yi%kYimh3g&U;CJT=`@wlEYZ;-bLJA~-u#F&?R9ido6@9C)?X&3rl|*p8Dc?~-@U?|^1Ezu_MQj+DuG8KQF#8{R_!XU2BkO_1Mt2P1g+LYQS=r_nFMHA6I jDctS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}JrSnPQX^6B6bkT|v)2K^O0Y)d5ZUUo`k`b~gD&yLrQsPMmNYt_d z(^LB$x4wr!F^=%sjD+ooJPZYO#-q7JZc`IJ@RSUh%*x=0ab~Z;5Gax=(}1Uj#-I? zXA<77o7O6fo6*nQEGypWKCk#St~2~t;Q)f&y@CpeqD z)K;GBC@*;6RUMHHumI|s0dbzdH7UzWrRi(3^YVUJ(~J#eQ~R4p!QyjVeuUi%=!)Zu zwaqn}IOX((6#ge4T1N^vIkCNh3*T8sZluKYE%a6zDWW($A_>zgI60T!>UY)r7nZ>ko?#$@u z!(8oa)y@Unf15m#Y=$CyVduF$t(5ohL6M@ z7I>X@oiBDfO_ig2a#!hfOaCvFBk$eu^)eN(KC*kDO&R{p z?=|#dh^Nj12t^AgkNm&0)l(#h)8!JlyP#)3>Ax4}zoj_e4oYxiI^kQPl>axS`*&Z? z_X*FJNH{R5f1i*0(1;G;jxFqJXd)>w*6;Q8=p!8KkM! z9Fl~gpIq7eLf$erJuH>`!TC)2viniv1d1;Vzp1$l{+N>eSyoiym$?d!RC~88`|&!h e?OjWzdhzyUMQzGr>7Ai_|0G3aMJj~!{Qd_*oFAe9 literal 0 HcmV?d00001 diff --git a/docs/img/logo.png b/docs/img/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..5d1aad7c12ac50ab82f86adbca7ca6c2a40e3049 GIT binary patch literal 68851 zcmb5VbyQr<@-7U)gF|q43GPmC3GTt&2Y2^CaMwU^9h|{6xVsJR?vh}+llT1OoORdw z)_3O*)}G$GtGa4ebv^a;5T&9dgZiHEJrooas+_E(8Wa@tGUR#^@g3wZmPFVK6cj$C zjf8}XoP-3qii@MAjlBgFlnxT`i#K1Y!P4d99FrUmb5z=hkR%hs1X|0 zS#%SbaKEFNroU91obWf`o(hQh;dJ-STdU%YR2Otmy;%Y1wS95KY*_q%^?aY=DuUYp#n ze+nA7m4(v0SbhzNzNN|L`!tSp9Yr39T)BBuFI$oS>gestw$O)Zsx|D5`@!tuj!1bZ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g&x($o8_xd2ftzZt4eh`?wQth7-OEWeRI!)F(^vpF%~6^rX*InJ$c zBk2y*aSVuuEf#$g!425O3KK=tUDyjguSOy%Enw`4e+u!6;D*xUBOweBW+bjgd{5*w z=!XCV9w-vUH7a%r!-ucKxS{k`1S9E9xUnI30GbUUn+WnCmZp!epD?X(k!O!p!`6;m z2lDt>j&p=>D+PTa;|Y3%>?c+pr+A1spbfqUNN)felg4cn*9oF?D7^t3O^=5OAqu=j zD2CG;*9XIucm*H z<3wE#R+wPJ2(671z_e5_8aZJh4{DqyAzKRrU|62mu#tj+Lt7XpK0@{}&R&91nfEcy z1BGdY8!zO3#%YIf%K|VQHv43Oz***AMH|2e4CBZ*>j*pxM32rx{j|ajr-!e@#2+^O zAh=oBQ@O+N^37$&%GV$^i&z+w}5)G9q7z7Nb}$2|zaR`RsMZAx#t zb!x^YwqoQ^g7ZV+HUT%?hG~Xs#CoMueETm(|H45B?*s$b3)2cWl5Shy@4?l3gTy`Q zP99_5;NEoG8aGanh%f-e@YSoRwJ^R-qVjl>#}kym5xybZhP7Mb#tKPm^tdGM zPna-GUmla**V<2P;VB<1q#zg%XPj6eTk`dc6BV+hwWDAX?BI$-JQ%j>K@~K`8o*7r zExarVeFKJYBf`WRrya&-Vc$5-u8;R%>&R&szqO|#*~f8@67+@H6Lm&2TqA~EW2btL zRQwOLT%S76mc#BJM!{HNniXjwWHWB8FixVd{Ti+d17qVfa=j3?+b@+1o3HV}Q77)4^`iA{72Li8i@c#!*YQ!&sr!lzo)+ cFk$@v0S + + + + Unirest for Java - Simplified, lightweight HTTP Request Library + + + + + + + + + + + + +

+Unirest for Java +

+ +

+ +

Open Unirest is a lightweight Java HTTP library

+ +

Do yourself a favor, and start making HTTP requests like this:

+ +
Unirest.post("http://httpbin.org/post")
+  .queryString("name", "Mark")
+  .field("last", "Polo")
+  .asJson()
+ +

License | +version | +Gitter

+ +

+Features

+ +
    +
  • Make GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS requests
  • +
  • Both syncronous and asynchronous (non-blocking) requests
  • +
  • It supports form parameters, file uploads and custom body entities
  • +
  • Easily add route parameters without ugly string concatenations
  • +
  • Supports gzip
  • +
  • Supports Basic Authentication natively
  • +
  • Customizable timeout, concurrency levels and proxy settings
  • +
  • Customizable default headers for every request (DRY)
  • +
  • Customizable HttpClient and HttpAsyncClient implementation
  • +
  • Automatic JSON parsing into a native object for JSON responses
  • +
  • Customizable binding, with mapping from response body to java Object
  • +
+ +

+Installing

+ +

Is easy as pie. Kidding. It's about as easy as doing these little steps:

+ +

+With Maven

+ +

You can use Maven by including the library:

+ +
<dependency>
+    <groupId>com.mashape.unirest</groupId>
+    <artifactId>unirest-java</artifactId>
+    <version>1.4.9</version>
+</dependency>
+ +

+Without Maven

+ +

+Creating Request

+ +

So you're probably wondering how using Unirest makes creating requests in Java easier, here is a basic POST request that will explain everything:

+ +
HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post")
+  .header("accept", "application/json")
+  .queryString("apiKey", "123")
+  .field("parameter", "value")
+  .field("foo", "bar")
+  .asJson();
+ +

Requests are made when as[Type]() is invoked, possible types include Json, Binary, String, Object.

+ +

If the request supports and it is of type HttpRequestWithBody, a body it can be passed along with .body(String|JsonNode|Object). For using .body(Object) some pre-configuration is needed (see below).

+ +

If you already have a map of parameters or do not wish to use seperate field methods for each one there is a .fields(Map<String, Object> fields) method that will serialize each key - value to form parameters on your request.

+ +

.headers(Map<String, String> headers) is also supported in replacement of multiple header methods.

+ +

+Serialization

+ +

Before an asObject(Class) or a .body(Object) invokation, is necessary to provide a custom implementation of the ObjectMapper interface. +This should be done only the first time, as the instance of the ObjectMapper will be shared globally.

+ +

For example, serializing Json from\to Object using the popular Jackson ObjectMapper takes only few lines of code.

+ +
// Only one time
+Unirest.setObjectMapper(new ObjectMapper() {
+    private com.fasterxml.jackson.databind.ObjectMapper jacksonObjectMapper
+                = new com.fasterxml.jackson.databind.ObjectMapper();
+
+    public <T> T readValue(String value, Class<T> valueType) {
+        try {
+            return jacksonObjectMapper.readValue(value, valueType);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public String writeValue(Object value) {
+        try {
+            return jacksonObjectMapper.writeValueAsString(value);
+        } catch (JsonProcessingException e) {
+            throw new RuntimeException(e);
+        }
+    }
+});
+
+// Response to Object
+HttpResponse<Book> bookResponse = Unirest.get("http://httpbin.org/books/1").asObject(Book.class);
+Book bookObject = bookResponse.getBody();
+
+HttpResponse<Author> authorResponse = Unirest.get("http://httpbin.org/books/{id}/author")
+    .routeParam("id", bookObject.getId())
+    .asObject(Author.class);
+
+Author authorObject = authorResponse.getBody();
+
+// Object to Json
+HttpResponse<JsonNode> postResponse = Unirest.post("http://httpbin.org/authors/post")
+        .header("accept", "application/json")
+        .header("Content-Type", "application/json")
+        .body(authorObject)
+        .asJson();
+ +

+Route Parameters

+ +

Sometimes you want to add dynamic parameters in the URL, you can easily do that by adding a placeholder in the URL, and then by setting the route parameters with the routeParam function, like:

+ +
Unirest.get("http://httpbin.org/{method}")
+  .routeParam("method", "get")
+  .queryString("name", "Mark")
+  .asJson();
+ +

In the example above the final URL will be http://httpbin.org/get - Basically the placeholder {method} will be replaced with get.

+ +

The placeholder's format is as easy as: {custom_name}

+ +

+Asynchronous Requests

+ +

Sometimes, well most of the time, you want your application to be asynchronous and not block, Unirest supports this in Java using anonymous callbacks, or direct method placement:

+ +
Future<HttpResponse<JsonNode>> future = Unirest.post("http://httpbin.org/post")
+  .header("accept", "application/json")
+  .field("param1", "value1")
+  .field("param2", "value2")
+  .asJsonAsync(new Callback<JsonNode>() {
+
+    public void failed(UnirestException e) {
+        System.out.println("The request has failed");
+    }
+
+    public void completed(HttpResponse<JsonNode> response) {
+         int code = response.getStatus();
+         Map<String, String> headers = response.getHeaders();
+         JsonNode body = response.getBody();
+         InputStream rawBody = response.getRawBody();
+    }
+
+    public void cancelled() {
+        System.out.println("The request has been cancelled");
+    }
+
+});
+ +

+File Uploads

+ +

Creating multipart requests with Java is trivial, simply pass along a File or an InputStream Object as a field:

+ +
HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post")
+  .header("accept", "application/json")
+  .field("parameter", "value")
+  .field("file", new File("/tmp/file"))
+  .asJson();
+ +

+Custom Entity Body

+ +
HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post")
+  .header("accept", "application/json")
+  .body("{\"parameter\":\"value\", \"foo\":\"bar\"}")
+  .asJson();
+ +

+Byte Stream as Entity Body

+ +
final InputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI()));
+final byte[] bytes = new byte[stream.available()];
+stream.read(bytes);
+stream.close();
+final HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post")
+  .field("name", "Mark")
+  .field("file", bytes, "image.jpg")
+  .asJson();
+ +

+InputStream as Entity Body

+ +
HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post")
+  .field("name", "Mark")
+  .field("file", new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())), ContentType.APPLICATION_OCTET_STREAM, "image.jpg")
+  .asJson();
+ +

+Basic Authentication

+ +

Authenticating the request with basic authentication can be done by calling the basicAuth(username, password) function:

+ +
HttpResponse<JsonNode> response = Unirest.get("http://httpbin.org/headers").basicAuth("username", "password").asJson();
+ +

+Request

+ +

The Java Unirest library follows the builder style conventions. You start building your request by creating a HttpRequest object using one of the following:

+ +
GetRequest request = Unirest.get(String url);
+GetRequest request = Unirest.head(String url);
+HttpRequestWithBody request = Unirest.post(String url);
+HttpRequestWithBody request = Unirest.put(String url);
+HttpRequestWithBody request = Unirest.patch(String url);
+HttpRequestWithBody request = Unirest.options(String url);
+HttpRequestWithBody request = Unirest.delete(String url);
+ +

+Response

+ +

Upon recieving a response Unirest returns the result in the form of an Object, this object should always have the same keys for each language regarding to the response details.

+ +
    +
  • +.getStatus() - HTTP Response Status Code (Example: 200)
  • +
  • +.getStatusText() - HTTP Response Status Text (Example: "OK")
  • +
  • +.getHeaders() - HTTP Response Headers
  • +
  • +.getBody() - Parsed response body where applicable, for example JSON responses are parsed to Objects / Associative Arrays.
  • +
  • +.getRawBody() - Un-parsed response body
  • +
+ +

+Advanced Configuration

+ +

You can set some advanced configuration to tune Unirest-Java:

+ +

+Custom HTTP clients

+ +

You can explicitly set your own HttpClient and HttpAsyncClient implementations by using the following methods:

+ +
Unirest.setHttpClient(httpClient);
+Unirest.setAsyncHttpClient(asyncHttpClient);
+ +

+Timeouts

+ +

You can set custom connection and socket timeout values (in milliseconds):

+ +
Unirest.setTimeouts(long connectionTimeout, long socketTimeout);
+ +

By default the connection timeout (the time it takes to connect to a server) is 10000, and the socket timeout (the time it takes to receive data) is 60000. You can set any of these timeouts to zero to disable the timeout.

+ +

+Default Request Headers

+ +

You can set default headers that will be sent on every request:

+ +
Unirest.setDefaultHeader("Header1", "Value1");
+Unirest.setDefaultHeader("Header2", "Value2");
+ +

You can clear the default headers anytime with:

+ +
Unirest.clearDefaultHeaders();
+ +

+Concurrency

+ +

You can set custom concurrency levels if you need to tune the performance of the syncronous or asyncronous client:

+ +
Unirest.setConcurrency(int maxTotal, int maxPerRoute);
+ +

By default the maxTotal (overall connection limit in the pool) is 200, and the maxPerRoute (connection limit per target host) is 20.

+ +

+Proxy

+ +

You can set a proxy by invoking:

+ +
Unirest.setProxy(new HttpHost("127.0.0.1", 8000));
+ +

+Exiting an application

+ +

Unirest starts a background event loop and your Java application won't be able to exit until you manually shutdown all the threads by invoking:

+ +
Unirest.shutdown();
+ +
+ +

Made with ♥ from the Mashape team

+
+ + + + + + \ No newline at end of file diff --git a/docs/styles/fonts.css b/docs/styles/fonts.css new file mode 100644 index 000000000..a3334fbf2 --- /dev/null +++ b/docs/styles/fonts.css @@ -0,0 +1,132 @@ +@font-face { + font-family: 'Open Sans'; + font-style: normal; + font-weight: 300; + src: local('Open Sans Light'), local('OpenSans-Light'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/DXI1ORHCpsQm3Vp6mXoaTaRDOzjiPcYnFooOUGCOsRk.woff) format('woff'); +} +@font-face { + font-family: 'Open Sans'; + font-style: normal; + font-weight: 400; + src: local('Open Sans'), local('OpenSans'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/cJZKeOuBrn4kERxqtaUH3bO3LdcAZYWl9Si6vvxL-qU.woff) format('woff'); +} +@font-face { + font-family: 'Open Sans'; + font-style: normal; + font-weight: 600; + src: local('Open Sans Semibold'), local('OpenSans-Semibold'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/MTP_ySUJH_bn48VBG8sNSqRDOzjiPcYnFooOUGCOsRk.woff) format('woff'); +} +@font-face { + font-family: 'Open Sans'; + font-style: normal; + font-weight: 700; + src: local('Open Sans Bold'), local('OpenSans-Bold'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/k3k702ZOKiLJc3WVjuplzKRDOzjiPcYnFooOUGCOsRk.woff) format('woff'); +} +@font-face { + font-family: 'Open Sans'; + font-style: italic; + font-weight: 300; + src: local('Open Sans Light Italic'), local('OpenSansLight-Italic'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/PRmiXeptR36kaC0GEAetxvR_54zmj3SbGZQh3vCOwvY.woff) format('woff'); +} +@font-face { + font-family: 'Open Sans'; + font-style: italic; + font-weight: 400; + src: local('Open Sans Italic'), local('OpenSans-Italic'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/xjAJXh38I15wypJXxuGMBrrIa-7acMAeDBVuclsi6Gc.woff) format('woff'); +} +@font-face { + font-family: 'Open Sans'; + font-style: italic; + font-weight: 600; + src: local('Open Sans Semibold Italic'), local('OpenSans-SemiboldItalic'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/PRmiXeptR36kaC0GEAetxuw_rQOTGi-AJs5XCWaKIhU.woff) format('woff'); +} +@font-face { + font-family: 'Open Sans'; + font-style: italic; + font-weight: 700; + src: local('Open Sans Bold Italic'), local('OpenSans-BoldItalic'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/PRmiXeptR36kaC0GEAetxhbnBKKEOwRKgsHDreGcocg.woff) format('woff'); +} +@font-face { + font-family: 'Source Code Pro'; + font-style: normal; + font-weight: 300; + src: local('Source Code Pro Light'), local('SourceCodePro-Light'), url(http://themes.googleusercontent.com/static/fonts/sourcecodepro/v3/leqv3v-yTsJNC7nFznSMqcVNtom4QlEDNJaqqqzqdSs.woff) format('woff'); +} +@font-face { + font-family: 'Source Code Pro'; + font-style: normal; + font-weight: 400; + src: local('Source Code Pro'), local('SourceCodePro-Regular'), url(http://themes.googleusercontent.com/static/fonts/sourcecodepro/v3/mrl8jkM18OlOQN8JLgasD9Hq-FFgoDNV3GTKpHwuvtI.woff) format('woff'); +} +@font-face { + font-family: 'Source Code Pro'; + font-style: normal; + font-weight: 500; + src: local('Source Code Pro Medium'), local('SourceCodePro-Medium'), url(http://themes.googleusercontent.com/static/fonts/sourcecodepro/v3/leqv3v-yTsJNC7nFznSMqbIHYkLmgtPJP77jcqN9P08.woff) format('woff'); +} +@font-face { + font-family: 'Source Code Pro'; + font-style: normal; + font-weight: 600; + src: local('Source Code Pro Semibold'), local('SourceCodePro-Semibold'), url(http://themes.googleusercontent.com/static/fonts/sourcecodepro/v3/leqv3v-yTsJNC7nFznSMqSmgpmuQqK2I-L2S9cF65Ek.woff) format('woff'); +} +@font-face { + font-family: 'Source Code Pro'; + font-style: normal; + font-weight: 700; + src: local('Source Code Pro Bold'), local('SourceCodePro-Bold'), url(http://themes.googleusercontent.com/static/fonts/sourcecodepro/v3/leqv3v-yTsJNC7nFznSMqYqjGYJUyOXcBwUQbRaNH6c.woff) format('woff'); +} +@font-face { + font-family: 'Titillium Web'; + font-style: normal; + font-weight: 200; + src: local('Titillium WebThin'), local('TitilliumWeb-Thin'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v1/anMUvcNT0H1YN4FII8wpr-K9kSItTeDn2USN0q77Oh4.woff) format('woff'); +} +@font-face { + font-family: 'Titillium Web'; + font-style: normal; + font-weight: 300; + src: local('Titillium WebLight'), local('TitilliumWeb-Light'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v1/anMUvcNT0H1YN4FII8wpr1uKlGE8-OjkUKWan_M3D6s.woff) format('woff'); +} +@font-face { + font-family: 'Titillium Web'; + font-style: normal; + font-weight: 400; + src: local('Titillium Web'), local('TitilliumWeb-Regular'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v1/7XUFZ5tgS-tD6QamInJTcZ_o9VAbKgK36i-4snuAuCM.woff) format('woff'); +} +@font-face { + font-family: 'Titillium Web'; + font-style: normal; + font-weight: 600; + src: local('Titillium WebSemiBold'), local('TitilliumWeb-SemiBold'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v1/anMUvcNT0H1YN4FII8wprx3QmhlKDgQgT1VN2Ed1WFo.woff) format('woff'); +} +@font-face { + font-family: 'Titillium Web'; + font-style: normal; + font-weight: 700; + src: local('Titillium WebBold'), local('TitilliumWeb-Bold'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v1/anMUvcNT0H1YN4FII8wpr_5rZpfU3XI-FvUPGDRT0xY.woff) format('woff'); +} +@font-face { + font-family: 'Titillium Web'; + font-style: italic; + font-weight: 200; + src: local('Titillium WebThin Italic'), local('TitilliumWeb-ThinItalic'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v1/RZunN20OBmkvrU7sA4GPPvTdIrrWFKtkerHRAIjOAnE.woff) format('woff'); +} +@font-face { + font-family: 'Titillium Web'; + font-style: italic; + font-weight: 300; + src: local('Titillium WebLight Italic'), local('TitilliumWeb-LightItalic'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v1/RZunN20OBmkvrU7sA4GPPiKuKXcI2mpaPB3p6hsA39k.woff) format('woff'); +} +@font-face { + font-family: 'Titillium Web'; + font-style: italic; + font-weight: 400; + src: local('Titillium WebItalic'), local('TitilliumWeb-Italic'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v1/r9OmwyQxrgzUAhaLET_KO8-iP4m4uFrmmLLVBqy34EU.woff) format('woff'); +} +@font-face { + font-family: 'Titillium Web'; + font-style: italic; + font-weight: 600; + src: local('Titillium WebSemiBold Italic'), local('TitilliumWeb-SemiBoldItalic'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v1/RZunN20OBmkvrU7sA4GPPnV4MzQw1VeMlPUyFyGfvRM.woff) format('woff'); +} \ No newline at end of file diff --git a/docs/styles/homepage.css b/docs/styles/homepage.css new file mode 100644 index 000000000..373eb70bb --- /dev/null +++ b/docs/styles/homepage.css @@ -0,0 +1,312 @@ +@import url('fonts.css'); +@import url('normalize.css'); + +body, html { + font-family: 'Open Sans', 'Helvetica'; + padding: 0px; + margin: 0px; +} + +pre, code { + font-family: 'Source Code Pro'; +} + +h1 { + font-weight: 400; +} + +h1, h2 { + margin: 0; +} + +p { + -webkit-hyphens: auto; + -moz-hyphens: auto; + hyphens: auto; + margin-bottom: 1.5em; + margin-top: 2em; + color: hsl(217, 18%, 65%); + text-align: center; +} + +p a { + color: hsl(200, 100%, 50%); +} + +p a:hover { + color: #97A3B6; + border-bottom-color: #97A3B6; + transition: all .3s ease-in; +} + +nav { + font-family: 'Open Sans'; + position: fixed; + z-index: 1; + top: 0; + left: 0; + width: 100%; + display: block; + padding: 20px; + margin: 0; + background: white; + box-shadow: 0 -1px 5px hsla(0, 0%, 0%, 0.5); +} + +nav .right { + display: inline-block; + float: right; + padding: 0 40px; +} + +nav a { + font-size: 14px; + font-weight: 600; + color: #97A3B6; + border: 0px; + transition: all .3s ease-in; + padding: 0 20px 0 0; + display: inline-block; + text-decoration: none; +} + +nav a:hover { + color: #0D131A; + text-decoration: none; + border: 0px; +} + +header { + margin-top: 80px; + margin-bottom: 60px; +} + +header h1 { + display: block; + font-size: 128pt; + font-family: 'Titillium Web'; + text-align: center; + padding: 2% 0 0; + line-height: 96pt; +} + +header h2 { + display: block; + font-size: 28pt; + font-weight: 300; + font-family: 'Titillium Web'; + text-align: center; + padding: 20px 0 0 0; + color: hsl(212, 10%, 49%); +} + + .button-list { + max-width: 860px; + margin: 2% auto 0; + display: block; + text-align: center; + padding: 0 0 10px; +} + + .button-list h4 { + color: white; + display: block; + font-family: 'Titillium Web'; + font-size: 16pt; + font-weight: 300; + line-height: 64pt; +} + + .button-list .group { + display: block; + clear: both; +} + +.button { + position: relative; + top: 0; + display: inline-block; + width: auto; + margin: 0 0px 10px; + padding: 0 49px 5px; + font-family: "Open Sans", sans-serif; + font-size: 14px; + line-height: 35px; + font-weight: 600; + color: hsl(212, 33%, 8%); + background-color: hsl(212, 13%, 88%); + border-radius: 6px; + -moz-border-radius: 6px; + -webkit-border-radius: 6px; + -o-border-radius: 6px; + -webkit-transition: all .3s ease-out; + -moz-transition: all .3s ease-out; + -o-transition: all .3s ease-out; + text-decoration: none; + cursor: pointer; + white-space: nowrap; + text-decoration: none; +} + +.button.active { + color: white; +} + +.button.green { + background-color: #6F9507; +} + +.button.red { + background-color: #E74C3C; +} + +.button.blue { + background-color: #23AFC8; +} + +.button.orange { + background-color: #E76F00; +} + +.button.yellow { + background-color: #F3CF3F; +} + +.button.teal { + background-color: #29BB9C; +} + +.button.node-green { + background-color: #8CC84B; +} + +.button.pinterest-red { + background-color: #CC2127; +} + +.button.youtube-red { + background-color: #A40F09; +} + +.button.twitter-blue { + background-color: #4AC6EC; +} + +.button.forrst-green { + background-color: #359053; +} + +.button.facebook-blue { + background-color: #3A5899; +} + +.button:hover { + text-decoration: none; + color: white; +} + +.button.hover-green:hover, .button.hover-green.active { + background-color: #6F9507; +} + +.button.hover-red:hover, .button.hover-red.active { + background-color: #E74C3C; +} + +.button.hover-blue:hover, .button.hover-blue.active { + background-color: #23AFC8; +} + +.button.hover-orange:hover, .button.hover-orange.active { + background-color: #E76F00; +} + +.button.hover-yellow:hover, .button.hover-yellow.active { + background-color: #F3CF3F; +} + +.button.hover-teal:hover, .button.hover-teal.active { + background-color: #29BB9C; +} + +.button.hover-node-green:hover, .button.hover-node-green.active { + background-color: #8CC84B; +} + +.button.hover-pinterest-red:hover, .button.hover-pinterest-red.active { + background-color: #CC2127; +} + +.button.hover-twitter-blue:hover, .button.hover-twitter-blue.active { + background-color: #4AC6EC; +} + +.button.hover-youtube-red:hover, .button.hover-youtube-red.active { + background-color: #A40F09; +} + +.button.hover-forrst-green:hover, .button.hover-forrst-green.active { + background-color: #359053; +} + +.button.hover-facebook-blue:hover, .button.hover-facebook-blue.active { + background-color: #3A5899; +} + +.button:active { + padding-bottom: 0; + box-shadow: 0 1px 5px hsla(0, 0%, 0%, 0.2) inset; + -moz-box-shadow: 0 1px 5px hsla(0, 0%, 0%, 0.2) inset; + -webkit-box-shadow: 0 1px 5px hsla(0, 0%, 0%, 0.2) inset; + -o-box-shadow: 0 1px 5px hsla(0, 0%, 0%, 0.2) inset; +} + +.button-list .button { + box-sizing: border-box; + width: 23.8%; + padding: 0; + height: 100px; + margin: 2px 2px 4px; + text-align: center; + line-height: 100px; +} + +.plug { + font-size: .9em; + margin: 30px auto; +} + +@media (max-width: 700px) { + .button-list .button { + width: 45%; + } +} + +@media (max-width: 640px) { + header h1 { + font-size: 96pt; + } + + header h2 { + font-size: 24pt; + } +} + +@media (max-width: 460px) { + nav a { + font-size: 12px; + padding: 0 5px 0 0; + } + + header h1 { + font-size: 72pt; + } + + header h2 { + font-size: 18pt; + } + + header .button-list .button { + width: 90%; + } +} \ No newline at end of file diff --git a/docs/styles/library.css b/docs/styles/library.css new file mode 100644 index 000000000..e91f9be69 --- /dev/null +++ b/docs/styles/library.css @@ -0,0 +1,517 @@ +@import url('fonts.css'); +@import url('normalize.css'); + +body, html { + font-family: 'Open Sans', 'Helvetica'; + padding: 0px; + margin: 0px; + height: 100%; + + color: hsl(212, 33%, 11%); +} + +a, a:hover { + color: hsl(200, 100%, 50%); + text-decoration: none; + border-bottom: 1px solid hsl(200, 100%, 50%); + transition: all .3s ease-in; +} + +a ~ img { + border-bottom: 0px; +} + +a:hover { + color: #97A3B6; + border-bottom: 1px solid #97A3B6; +} + +pre, code { + font-family: 'Source Code Pro'; +} + +.documentation { + padding-bottom: 80px; +} + +.social { + position: relative; + top: 30px; + float: right; +} + +.center { + text-align: center; + margin: 20px auto; +} + +nav { + font-family: 'Open Sans'; + position: fixed; + z-index: 1; + top: 0; + left: 0; + width: 100%; + display: block; + padding: 20px; + margin: 0; + background: white; + box-shadow: 0 -1px 5px hsla(0, 0%, 0%, 0.5); +} + +nav .right { + display: inline-block; + float: right; + padding: 0 40px; +} + +nav .right a { + color: hsl(200, 100%, 50%); +} + +nav .right a span { + color: hsl(217, 18%, 65%); +} + +nav a { + font-size: 14px; + font-weight: 600; + color: #97A3B6; + border: 0px; + transition: all .3s ease-in; + padding: 0 20px 0 0; + display: inline-block; +} + +nav a:hover { + color: #0D131A; + text-decoration: none; + border: 0px; +} + +nav iframe { + margin-bottom: -5px; + margin-left: 10px; +} + +article { + max-width: 944px; + margin: auto; +} + +h1 { + font-weight: 300; +} + +h2, h3 , h4 { + font-weight: 400; +} + +h1, h2, h3, h4, h5, h6 { + font-family: 'Titillium Web'; +} + +h1, h2, h3, h4, h5, h6, p, ul, ol, table { + min-width: 460px; + max-width: 860px; + margin: 0 auto; + padding-left: 20px; + padding-right: 20px; +} + +body { + font-size: 100%; + line-height: 1.5; +} + +h1 { + font-size: 3.4285714285714284em; + line-height: 1.3125em; + margin-top: 1.5em; +} + +h2 { + font-size: 2.2857142857142856em; + line-height: 1.96875em; +} + +h3 { + font-size: 1.7142857142857142em; + line-height: 1.75em; +} + +h4 { + font-size: 1.5em; + line-height: 2em; + margin-top: 2em; +} + +h5 { + font-size: 1.2857142857142858em; + line-height: 2.3333333333333335em; +} + +h6 { + font-size: 1.1428571428571428em; + line-height: 2.625em; +} + +.documentation > h1:first-of-type { + margin-top: 2em; + margin-bottom: .5em; +} + +hr { + border-top: 1px solid hsl(0, 0%, 93%); + border-bottom: none; + margin: 30px auto; + max-width: 860px; +} + +p { + -webkit-hyphens: auto; + -moz-hyphens: auto; + hyphens: auto; + margin-bottom: 1.5em; +} + +p + hr { + margin-bottom: 1.2em; +} + +.highlight, pre code { + display: block; + min-width: 460px; + max-width: 860px; + margin: 0 auto; + background: #0F161E; + border-radius: 6px; + padding: 20px; +} + +.highlight pre { + margin: 0 2px; +} + +.highlight pre span { + display: inline-block; +} + +p, ol, ul, blockquote, pre, code, .highlight, table { + line-height: 18px; + margin-bottom 18px; + /* 1.5em provides good vertical spacing ( = 150% of the font-size) */ + line-height: 1.5em; + margin-bottom: 1.5em; +} + +li { + margin-bottom: .2em; +} + +p, ul, ol { + color: hsl(212, 33%, 11%); + list-style: none; +} + +code { + color: hsl(333, 100%, 50%); +} + +table thead tr th { + text-align: left; +} + +table tr td { + border-top: 1px solid hsl(0, 0%, 93%); + padding: 10px 5px; + vertical-align: top; +} + +.highlight { + color: hsl(0, 100%, 100%); +} + +.highlight .c { + color: #192532; + font-style: italic; +} + +.highlight .err { + color: hsl(0, 100%, 80%); +} + +.highlight .k { + color: hsl(33, 82%, 71%); +} + +.highlight .cm { + color: #999988; + font-style: italic; +} + +.highlight .cp { + color: #999999; + font-weight: bold; +} + +.highlight .c1 { + color: hsl(35, 8%, 44%); + font-style: italic; +} + +.highlight .cs { + color: #999999; + font-weight: bold; + font-style: italic; +} + +.highlight .gd { + color: #000000; + background-color: #ffdddd; +} + +.highlight .gd .x { + color: #000000; + background-color: #ffaaaa; +} + +.highlight .ge { + font-style: italic; +} + +.highlight .gr { + color: #aa0000; +} + +.highlight .gh { + color: #999999; +} + +.highlight .gi { + color: #000000; + background-color: #ddffdd; +} + +.highlight .gi .x { + color: #000000; + background-color: #aaffaa; +} + +.highlight .go { + color: #888888; +} + +.highlight .gp { + color: #555555; +} + +.highlight .gs { + font-weight: bold; +} + +.highlight .gu { + color: #800080; + font-weight: bold; +} + +.highlight .gt { + color: #aa0000; +} + +.highlight .kc { + font-weight: bold; +} + +.highlight .kd { + color: hsl(180, 61%, 41%); +} + +.highlight .kn { +} + +.highlight .kp { + font-weight: bold; +} + +.highlight .kr { + font-weight: bold; +} + +.highlight .kt { + color: hsl(33, 82%, 71%); +} + +.highlight .m { + color: #009999; +} + +.highlight .s { + color: hsl(41, 93%, 60%); +} + +.highlight .n { + color: hsl(33, 82%, 71%); +} + +.highlight .na { + color: white; +} + +.highlight .nc { + color: #445588; + font-weight: bold; +} + +.highlight .no { + color: hsl(180, 61%, 41%); +} + +.highlight .ni { + color: #800080; +} + +.highlight .ne { + color: #990000; + font-weight: bold; +} + +.highlight .nf { + color: hsl(11, 83%, 70%); +} + +.highlight .nn { + color: hsl(0, 0%, 80%); +} + +.highlight .nt { + color: hsl(33, 82%, 71%); +} + +.highlight .nv { + color: hsl(180, 61%, 41%); +} + +.highlight .ow { + font-weight: bold; +} + +.highlight .w { + color: #bbbbbb; +} + +.highlight .mf { + color: #009999; +} + +.highlight .mh { + color: #009999; +} + +.highlight .mi { + color: hsl(41, 93%, 60%); +} + +.highlight .mo { + color: #009999; +} + +.highlight .sb { + color: hsl(41, 93%, 60%); +} + +.highlight .sc { + color: hsl(41, 93%, 60%); +} + +.highlight .sd { + color: hsl(41, 93%, 60%); +} + +.highlight .s2 { + color: hsl(41, 93%, 60%); +} + +.highlight .se { + color: hsl(41, 93%, 60%); +} + +.highlight .sh { + color: hsl(41, 93%, 60%); +} + +.highlight .si { + color: hsl(41, 93%, 60%); +} + +.highlight .sx { + color: hsl(41, 93%, 60%); +} + +.highlight .sr { + color: #009926; +} + +.highlight .s1 { + color: hsl(41, 93%, 60%); +} + +.highlight .bp { + color: #999999; +} + +.highlight .vc { + color: #008080; +} + +.highlight .vg { + color: #008080; +} + +.highlight .vi { + color: #008080; +} + +.highlight .il { + color: #009999; +} + +.highlight .gc { + color: #999; + background-color: #EAF2F5; +} + +.type-csharp .highlight .k { + color: #0000FF; +} + +.type-csharp .highlight .kt { + color: #0000FF; +} + +.type-csharp .highlight .nf { + color: #000000; + font-weight: normal; +} + +.type-csharp .highlight .nc { + color: #2B91AF; +} + +.type-csharp .highlight .nn { + color: #000000; +} + +.type-csharp .highlight .s { + color: #A31515; +} + +.type-csharp .highlight .sc { + color: #A31515; +} + +@media (max-width: 860px) { + .highlight, pre code { + border-radius: 0; + } +} diff --git a/docs/styles/normalize.css b/docs/styles/normalize.css new file mode 100644 index 000000000..8aea936bc --- /dev/null +++ b/docs/styles/normalize.css @@ -0,0 +1 @@ +/*! normalize.css v2.0.1 | MIT License | git.io/normalize */article,aside,details,figcaption,figure,footer,header,hgroup,nav,section,summary{display:block}audio,canvas,video{display:inline-block}audio:not([controls]){display:none;height:0}[hidden]{display:none}html{font-family:sans-serif;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}body{margin:0}a:focus{outline:thin dotted}a:active,a:hover{outline:0}h1{font-size:2em}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}dfn{font-style:italic}mark{background:#ff0;color:#000}code,kbd,pre,samp{font-family:monospace,serif;font-size:1em}pre{white-space:pre;white-space:pre-wrap;word-wrap:break-word}q{quotes:"\201C" "\201D" "\2018" "\2019"}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:0}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:.35em .625em .75em}legend{border:0;padding:0}button,input,select,textarea{font-family:inherit;font-size:100%;margin:0}button,input{line-height:normal}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}button[disabled],input[disabled]{cursor:default}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}textarea{overflow:auto;vertical-align:top}table{border-collapse:collapse;border-spacing:0} \ No newline at end of file From 69aa7c1ea6bf543c4672d69d673f8f090ac89943 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 6 Mar 2018 10:39:29 -0600 Subject: [PATCH 0018/1769] fix the namespaces --- .../openunirest/http/HttpClientHelper.java | 14 +++++------ .../github/openunirest/http/HttpResponse.java | 6 ++--- .../io/github/openunirest/http/Unirest.java | 12 +++++----- .../openunirest/http/async/Callback.java | 4 ++-- .../openunirest/http/async/RequestThread.java | 8 +++---- .../openunirest/http/options/Options.java | 4 ++-- .../openunirest/http/utils/ClientFactory.java | 4 ++-- .../openunirest/request/BaseRequest.java | 10 ++++---- .../openunirest/request/GetRequest.java | 2 +- .../openunirest/request/HttpRequest.java | 8 +++---- .../request/HttpRequestWithBody.java | 16 ++++++------- .../request/body/MultipartBody.java | 6 ++--- .../openunirest/request/body/RawBody.java | 4 ++-- .../request/body/RequestBodyEntity.java | 6 ++--- .../test/helper/JacksonObjectMapper.java | 2 +- .../openunirest/test/http/UnirestTest.java | 24 +++++++++---------- 16 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/HttpClientHelper.java b/src/main/java/io/github/openunirest/http/HttpClientHelper.java index c1701d629..a838b97df 100644 --- a/src/main/java/io/github/openunirest/http/HttpClientHelper.java +++ b/src/main/java/io/github/openunirest/http/HttpClientHelper.java @@ -53,13 +53,13 @@ a copy of this software and associated documentation files (the import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.apache.http.nio.entity.NByteArrayEntity; -import org.openunirest.http.async.Callback; -import org.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; -import org.openunirest.http.exceptions.UnirestException; -import org.openunirest.http.options.Option; -import org.openunirest.http.options.Options; -import org.openunirest.http.utils.ClientFactory; -import org.openunirest.request.HttpRequest; +import io.github.openunirest.http.async.Callback; +import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; +import io.github.openunirest.http.exceptions.UnirestException; +import io.github.openunirest.http.options.Option; +import io.github.openunirest.http.options.Options; +import io.github.openunirest.http.utils.ClientFactory; +import io.github.openunirest.request.HttpRequest; public class HttpClientHelper { diff --git a/src/main/java/io/github/openunirest/http/HttpResponse.java b/src/main/java/io/github/openunirest/http/HttpResponse.java index 2b2c7585d..d23630757 100644 --- a/src/main/java/io/github/openunirest/http/HttpResponse.java +++ b/src/main/java/io/github/openunirest/http/HttpResponse.java @@ -25,9 +25,9 @@ a copy of this software and associated documentation files (the package io.github.openunirest.http; -import org.openunirest.http.options.Option; -import org.openunirest.http.options.Options; -import org.openunirest.http.utils.ResponseUtils; +import io.github.openunirest.http.options.Option; +import io.github.openunirest.http.options.Options; +import io.github.openunirest.http.utils.ResponseUtils; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.StatusLine; diff --git a/src/main/java/io/github/openunirest/http/Unirest.java b/src/main/java/io/github/openunirest/http/Unirest.java index bdf307ff1..85abf0dbe 100644 --- a/src/main/java/io/github/openunirest/http/Unirest.java +++ b/src/main/java/io/github/openunirest/http/Unirest.java @@ -27,12 +27,12 @@ a copy of this software and associated documentation files (the import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; import io.github.openunirest.http.utils.SyncIdleConnectionMonitorThread; -import org.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; -import org.openunirest.http.options.Option; -import org.openunirest.http.options.Options; -import org.openunirest.http.utils.SyncIdleConnectionMonitorThread; -import org.openunirest.request.GetRequest; -import org.openunirest.request.HttpRequestWithBody; +import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; +import io.github.openunirest.http.options.Option; +import io.github.openunirest.http.options.Options; +import io.github.openunirest.http.utils.SyncIdleConnectionMonitorThread; +import io.github.openunirest.request.GetRequest; +import io.github.openunirest.request.HttpRequestWithBody; import org.apache.http.HttpHost; import org.apache.http.client.HttpClient; import org.apache.http.impl.client.CloseableHttpClient; diff --git a/src/main/java/io/github/openunirest/http/async/Callback.java b/src/main/java/io/github/openunirest/http/async/Callback.java index d7403d9bd..a1675d7c0 100644 --- a/src/main/java/io/github/openunirest/http/async/Callback.java +++ b/src/main/java/io/github/openunirest/http/async/Callback.java @@ -25,8 +25,8 @@ a copy of this software and associated documentation files (the package io.github.openunirest.http.async; -import org.openunirest.http.HttpResponse; -import org.openunirest.http.exceptions.UnirestException; +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.exceptions.UnirestException; public interface Callback { diff --git a/src/main/java/io/github/openunirest/http/async/RequestThread.java b/src/main/java/io/github/openunirest/http/async/RequestThread.java index 19731b8bc..e1010b7bf 100644 --- a/src/main/java/io/github/openunirest/http/async/RequestThread.java +++ b/src/main/java/io/github/openunirest/http/async/RequestThread.java @@ -26,10 +26,10 @@ a copy of this software and associated documentation files (the package io.github.openunirest.http.async; import io.github.openunirest.http.HttpClientHelper; -import org.openunirest.http.HttpClientHelper; -import org.openunirest.http.HttpResponse; -import org.openunirest.http.exceptions.UnirestException; -import org.openunirest.request.HttpRequest; +import io.github.openunirest.http.HttpClientHelper; +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.exceptions.UnirestException; +import io.github.openunirest.request.HttpRequest; public class RequestThread extends Thread { diff --git a/src/main/java/io/github/openunirest/http/options/Options.java b/src/main/java/io/github/openunirest/http/options/Options.java index 570542e32..cb1e7373b 100644 --- a/src/main/java/io/github/openunirest/http/options/Options.java +++ b/src/main/java/io/github/openunirest/http/options/Options.java @@ -16,8 +16,8 @@ import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor; import org.apache.http.nio.reactor.IOReactorException; -import org.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; -import org.openunirest.http.utils.SyncIdleConnectionMonitorThread; +import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; +import io.github.openunirest.http.utils.SyncIdleConnectionMonitorThread; public class Options { public static final int MAX_TOTAL = 200; diff --git a/src/main/java/io/github/openunirest/http/utils/ClientFactory.java b/src/main/java/io/github/openunirest/http/utils/ClientFactory.java index 912f09d50..37a9bf010 100644 --- a/src/main/java/io/github/openunirest/http/utils/ClientFactory.java +++ b/src/main/java/io/github/openunirest/http/utils/ClientFactory.java @@ -3,8 +3,8 @@ import org.apache.http.client.HttpClient; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; -import org.openunirest.http.options.Option; -import org.openunirest.http.options.Options; +import io.github.openunirest.http.options.Option; +import io.github.openunirest.http.options.Options; public class ClientFactory { diff --git a/src/main/java/io/github/openunirest/request/BaseRequest.java b/src/main/java/io/github/openunirest/request/BaseRequest.java index e59348ed6..dcc623e57 100644 --- a/src/main/java/io/github/openunirest/request/BaseRequest.java +++ b/src/main/java/io/github/openunirest/request/BaseRequest.java @@ -29,11 +29,11 @@ a copy of this software and associated documentation files (the import io.github.openunirest.http.HttpResponse; import io.github.openunirest.http.JsonNode; import io.github.openunirest.http.async.Callback; -import org.openunirest.http.HttpClientHelper; -import org.openunirest.http.HttpResponse; -import org.openunirest.http.JsonNode; -import org.openunirest.http.async.Callback; -import org.openunirest.http.exceptions.UnirestException; +import io.github.openunirest.http.HttpClientHelper; +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.JsonNode; +import io.github.openunirest.http.async.Callback; +import io.github.openunirest.http.exceptions.UnirestException; import java.io.InputStream; import java.util.concurrent.Future; diff --git a/src/main/java/io/github/openunirest/request/GetRequest.java b/src/main/java/io/github/openunirest/request/GetRequest.java index 44c904626..4f7d3e901 100644 --- a/src/main/java/io/github/openunirest/request/GetRequest.java +++ b/src/main/java/io/github/openunirest/request/GetRequest.java @@ -28,7 +28,7 @@ a copy of this software and associated documentation files (the import java.util.Map; import io.github.openunirest.http.HttpMethod; -import org.openunirest.http.HttpMethod; +import io.github.openunirest.http.HttpMethod; public class GetRequest extends HttpRequest { diff --git a/src/main/java/io/github/openunirest/request/HttpRequest.java b/src/main/java/io/github/openunirest/request/HttpRequest.java index 975db3a40..c120b973d 100644 --- a/src/main/java/io/github/openunirest/request/HttpRequest.java +++ b/src/main/java/io/github/openunirest/request/HttpRequest.java @@ -39,10 +39,10 @@ a copy of this software and associated documentation files (the import io.github.openunirest.http.HttpMethod; import io.github.openunirest.request.body.Body; -import org.openunirest.http.HttpMethod; -import org.openunirest.http.utils.Base64Coder; -import org.openunirest.http.utils.URLParamEncoder; -import org.openunirest.request.body.Body; +import io.github.openunirest.http.HttpMethod; +import io.github.openunirest.http.utils.Base64Coder; +import io.github.openunirest.http.utils.URLParamEncoder; +import io.github.openunirest.request.body.Body; public class HttpRequest extends BaseRequest { diff --git a/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java b/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java index 751fb3ae7..0bda751d8 100644 --- a/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java +++ b/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java @@ -32,14 +32,14 @@ a copy of this software and associated documentation files (the import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.content.InputStreamBody; -import org.openunirest.http.HttpMethod; -import org.openunirest.http.JsonNode; -import org.openunirest.http.ObjectMapper; -import org.openunirest.http.options.Option; -import org.openunirest.http.options.Options; -import org.openunirest.request.body.MultipartBody; -import org.openunirest.request.body.RawBody; -import org.openunirest.request.body.RequestBodyEntity; +import io.github.openunirest.http.HttpMethod; +import io.github.openunirest.http.JsonNode; +import io.github.openunirest.http.ObjectMapper; +import io.github.openunirest.http.options.Option; +import io.github.openunirest.http.options.Options; +import io.github.openunirest.request.body.MultipartBody; +import io.github.openunirest.request.body.RawBody; +import io.github.openunirest.request.body.RequestBodyEntity; import org.json.JSONArray; import org.json.JSONObject; diff --git a/src/main/java/io/github/openunirest/request/body/MultipartBody.java b/src/main/java/io/github/openunirest/request/body/MultipartBody.java index 7a2eedf54..b87aaa343 100644 --- a/src/main/java/io/github/openunirest/request/body/MultipartBody.java +++ b/src/main/java/io/github/openunirest/request/body/MultipartBody.java @@ -46,9 +46,9 @@ a copy of this software and associated documentation files (the import org.apache.http.entity.mime.content.InputStreamBody; import org.apache.http.entity.mime.content.StringBody; -import org.openunirest.http.utils.MapUtil; -import org.openunirest.request.BaseRequest; -import org.openunirest.request.HttpRequest; +import io.github.openunirest.http.utils.MapUtil; +import io.github.openunirest.request.BaseRequest; +import io.github.openunirest.request.HttpRequest; public class MultipartBody extends BaseRequest implements Body { private Map> parameters = new LinkedHashMap>(); diff --git a/src/main/java/io/github/openunirest/request/body/RawBody.java b/src/main/java/io/github/openunirest/request/body/RawBody.java index 16a695fac..9c7c4b00b 100644 --- a/src/main/java/io/github/openunirest/request/body/RawBody.java +++ b/src/main/java/io/github/openunirest/request/body/RawBody.java @@ -27,8 +27,8 @@ a copy of this software and associated documentation files (the import io.github.openunirest.request.BaseRequest; import io.github.openunirest.request.HttpRequest; -import org.openunirest.request.BaseRequest; -import org.openunirest.request.HttpRequest; +import io.github.openunirest.request.BaseRequest; +import io.github.openunirest.request.HttpRequest; import org.apache.http.HttpEntity; import org.apache.http.entity.ByteArrayEntity; diff --git a/src/main/java/io/github/openunirest/request/body/RequestBodyEntity.java b/src/main/java/io/github/openunirest/request/body/RequestBodyEntity.java index 08e78288d..798f443fd 100644 --- a/src/main/java/io/github/openunirest/request/body/RequestBodyEntity.java +++ b/src/main/java/io/github/openunirest/request/body/RequestBodyEntity.java @@ -31,9 +31,9 @@ a copy of this software and associated documentation files (the import org.apache.http.HttpEntity; import org.apache.http.entity.StringEntity; -import org.openunirest.http.JsonNode; -import org.openunirest.request.BaseRequest; -import org.openunirest.request.HttpRequest; +import io.github.openunirest.http.JsonNode; +import io.github.openunirest.request.BaseRequest; +import io.github.openunirest.request.HttpRequest; public class RequestBodyEntity extends BaseRequest implements Body { diff --git a/src/test/java/io/github/openunirest/test/helper/JacksonObjectMapper.java b/src/test/java/io/github/openunirest/test/helper/JacksonObjectMapper.java index 36acc6603..b7f1099b2 100644 --- a/src/test/java/io/github/openunirest/test/helper/JacksonObjectMapper.java +++ b/src/test/java/io/github/openunirest/test/helper/JacksonObjectMapper.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import io.github.openunirest.http.ObjectMapper; -import org.openunirest.http.ObjectMapper; +import io.github.openunirest.http.ObjectMapper; import java.io.IOException; diff --git a/src/test/java/io/github/openunirest/test/http/UnirestTest.java b/src/test/java/io/github/openunirest/test/http/UnirestTest.java index bdb312221..f05ebbb0d 100644 --- a/src/test/java/io/github/openunirest/test/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/test/http/UnirestTest.java @@ -34,14 +34,14 @@ a copy of this software and associated documentation files (the import io.github.openunirest.request.body.MultipartBody; import io.github.openunirest.test.helper.GetResponse; import io.github.openunirest.test.helper.JacksonObjectMapper; -import org.openunirest.http.async.Callback; -import org.openunirest.http.exceptions.UnirestException; -import org.openunirest.http.options.Options; -import org.openunirest.request.GetRequest; -import org.openunirest.request.HttpRequest; -import org.openunirest.request.body.MultipartBody; -import org.openunirest.test.helper.GetResponse; -import org.openunirest.test.helper.JacksonObjectMapper; +import io.github.openunirest.http.async.Callback; +import io.github.openunirest.http.exceptions.UnirestException; +import io.github.openunirest.http.options.Options; +import io.github.openunirest.request.GetRequest; +import io.github.openunirest.request.HttpRequest; +import io.github.openunirest.request.body.MultipartBody; +import io.github.openunirest.test.helper.GetResponse; +import io.github.openunirest.test.helper.JacksonObjectMapper; import org.apache.commons.io.IOUtils; import org.apache.http.entity.ContentType; @@ -51,10 +51,10 @@ a copy of this software and associated documentation files (the import org.json.JSONException; import org.json.JSONObject; import org.junit.*; -import org.openunirest.http.Headers; -import org.openunirest.http.HttpResponse; -import org.openunirest.http.JsonNode; -import org.openunirest.http.Unirest; +import io.github.openunirest.http.Headers; +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.JsonNode; +import io.github.openunirest.http.Unirest; import java.io.*; import java.net.InetAddress; From 315285ba18f55bfa87d1c706dfcaf22ae9690d17 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 6 Mar 2018 12:29:10 -0600 Subject: [PATCH 0019/1769] getting ready for maven central --- pom.xml | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 39485a000..c0c73d7bb 100644 --- a/pom.xml +++ b/pom.xml @@ -7,13 +7,7 @@ 2.0.00-SNAPSHOT unirest-java Simplified, lightweight HTTP client library - http://unirest.io/ - - - org.sonatype.oss - oss-parent - 7 - + http://github.com/OpenUnirest/ @@ -38,6 +32,17 @@ + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + UTF-8 UTF-8 @@ -46,6 +51,31 @@ + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrh + https://oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + org.apache.maven.plugins maven-compiler-plugin From 125aa24c23cc816b501e5d8a09f655621d3a5f67 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 6 Mar 2018 12:46:19 -0600 Subject: [PATCH 0020/1769] only sign during deployments --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c0c73d7bb..59ce67bf4 100644 --- a/pom.xml +++ b/pom.xml @@ -69,7 +69,7 @@ sign-artifacts - verify + deploy sign From b134d11af8a464cd910e81407b81cf0f1197055e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 6 Mar 2018 15:16:16 -0600 Subject: [PATCH 0021/1769] more maven release work --- pom.xml | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 59ce67bf4..736a9da18 100644 --- a/pom.xml +++ b/pom.xml @@ -49,6 +49,29 @@ 2.6.0 + + + ossrh + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + + + + + @@ -62,20 +85,7 @@ true - - org.apache.maven.plugins - maven-gpg-plugin - 1.5 - - - sign-artifacts - deploy - - sign - - - - + org.apache.maven.plugins maven-compiler-plugin From e5cbe69c2a4486d19c4e42c3d01b52f87b828961 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 6 Mar 2018 15:37:18 -0600 Subject: [PATCH 0022/1769] pom --- pom.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 736a9da18..677a1b14b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.0.00-SNAPSHOT + 2.0.01-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,8 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - + HEAD + From ee3f186b7d355f0108d0e7b87920f5e38fd548aa Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 6 Mar 2018 15:50:41 -0600 Subject: [PATCH 0023/1769] add the release plugin --- pom.xml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 677a1b14b..d45e6f7c6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.0.01-SNAPSHOT + 2.0.02-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -75,6 +75,15 @@ + + org.apache.maven.plugins + maven-release-plugin + 2.5 + + maven.test.skip=true + v@{project.version} + + org.sonatype.plugins nexus-staging-maven-plugin From b6ad437e0591ca3ddef42c01fc66a2a68475689c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 6 Mar 2018 15:51:37 -0600 Subject: [PATCH 0024/1769] [maven-release-plugin] prepare release v2.0.02 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d45e6f7c6..111a9daed 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.0.02-SNAPSHOT + 2.0.02 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.0.02 From c8ddc4995a09ec58862d8abf29b23c5c1582d0e5 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 6 Mar 2018 15:51:42 -0600 Subject: [PATCH 0025/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 111a9daed..1b782fb8c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.0.02 + 2.0.03-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.0.02 + HEAD From 08fdec1d5ba5a9ad65a59987087c8b95e2e5c5a0 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 6 Mar 2018 19:36:53 -0600 Subject: [PATCH 0026/1769] Update README.md --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index dedca95fe..e28dd6d67 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,14 @@ Unirest.post("http://httpbin.org/post") .asJson() ``` -[![License][license-image]][license-url] | -[![version][maven-version]][maven-url] | -[![Gitter][gitter-image]][gitter-url] - +## Install With Maven +``` + + io.github.openunirest + unirest-java + 2.0.02 + +``` ## Features From 55f5338bbcd050f54ba3024dd389b5dd97f59d66 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 7 Mar 2018 06:21:52 -0600 Subject: [PATCH 0027/1769] cleaning up the tests. Better asserts, start getting off of using requestbn --- .../java/io/github/openunirest/http/Foo.java | 11 +++++ .../github/openunirest/http/FormCapture.java | 38 +++++++++++++++ .../{test/helper => http}/GetResponse.java | 2 +- .../helper => http}/JacksonObjectMapper.java | 2 +- .../github/openunirest/http/JsonNodeTest.java | 7 +++ .../{test => }/http/MockServer.java | 35 ++++++++++++-- .../io/github/openunirest/http/TestUtils.java | 29 ++++++++++++ .../{test => }/http/UnirestTest.java | 46 ++++++------------- 8 files changed, 134 insertions(+), 36 deletions(-) create mode 100644 src/test/java/io/github/openunirest/http/Foo.java create mode 100644 src/test/java/io/github/openunirest/http/FormCapture.java rename src/test/java/io/github/openunirest/{test/helper => http}/GetResponse.java (88%) rename src/test/java/io/github/openunirest/{test/helper => http}/JacksonObjectMapper.java (94%) create mode 100644 src/test/java/io/github/openunirest/http/JsonNodeTest.java rename src/test/java/io/github/openunirest/{test => }/http/MockServer.java (77%) create mode 100644 src/test/java/io/github/openunirest/http/TestUtils.java rename src/test/java/io/github/openunirest/{test => }/http/UnirestTest.java (95%) diff --git a/src/test/java/io/github/openunirest/http/Foo.java b/src/test/java/io/github/openunirest/http/Foo.java new file mode 100644 index 000000000..b68c30d80 --- /dev/null +++ b/src/test/java/io/github/openunirest/http/Foo.java @@ -0,0 +1,11 @@ +package io.github.openunirest.http; + +public class Foo { + public String bar; + + public Foo(){ } + + public Foo(String bar) { + this.bar = bar; + } +} diff --git a/src/test/java/io/github/openunirest/http/FormCapture.java b/src/test/java/io/github/openunirest/http/FormCapture.java new file mode 100644 index 000000000..97154b962 --- /dev/null +++ b/src/test/java/io/github/openunirest/http/FormCapture.java @@ -0,0 +1,38 @@ +package io.github.openunirest.http; + +import spark.Request; + +import java.util.LinkedHashMap; +import java.util.Map; + +import static org.hamcrest.CoreMatchers.hasItem; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +public class FormCapture { + public Map headers = new LinkedHashMap<>(); + public Map query = new LinkedHashMap<>(); + + public FormCapture(){} + + public FormCapture(Request req) { + writeHeaders(req); + writeQuery(req); + } + + private void writeQuery(Request req) { + req.queryParams().forEach(q -> query.put(q, req.queryParams(q))); + } + + private void writeHeaders(Request req) { + req.headers().forEach(h -> headers.put(h, req.headers(h))); + } + + public void assertHeader(String key, String value) { + assertEquals("Expected Header Failed", value, headers.get(key)); + } + + public void assertQuery(String key, String value) { + assertEquals("Expected Query or Form value", value, query.get(key)); + } +} diff --git a/src/test/java/io/github/openunirest/test/helper/GetResponse.java b/src/test/java/io/github/openunirest/http/GetResponse.java similarity index 88% rename from src/test/java/io/github/openunirest/test/helper/GetResponse.java rename to src/test/java/io/github/openunirest/http/GetResponse.java index e2f07017d..f6032a98a 100644 --- a/src/test/java/io/github/openunirest/test/helper/GetResponse.java +++ b/src/test/java/io/github/openunirest/http/GetResponse.java @@ -1,4 +1,4 @@ -package io.github.openunirest.test.helper; +package io.github.openunirest.http; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/test/java/io/github/openunirest/test/helper/JacksonObjectMapper.java b/src/test/java/io/github/openunirest/http/JacksonObjectMapper.java similarity index 94% rename from src/test/java/io/github/openunirest/test/helper/JacksonObjectMapper.java rename to src/test/java/io/github/openunirest/http/JacksonObjectMapper.java index b7f1099b2..c4dfb762f 100644 --- a/src/test/java/io/github/openunirest/test/helper/JacksonObjectMapper.java +++ b/src/test/java/io/github/openunirest/http/JacksonObjectMapper.java @@ -1,4 +1,4 @@ -package io.github.openunirest.test.helper; +package io.github.openunirest.http; import com.fasterxml.jackson.core.JsonProcessingException; import io.github.openunirest.http.ObjectMapper; diff --git a/src/test/java/io/github/openunirest/http/JsonNodeTest.java b/src/test/java/io/github/openunirest/http/JsonNodeTest.java new file mode 100644 index 000000000..4839ab532 --- /dev/null +++ b/src/test/java/io/github/openunirest/http/JsonNodeTest.java @@ -0,0 +1,7 @@ +package io.github.openunirest.http; + +import static org.junit.Assert.*; + +public class JsonNodeTest { + +} \ No newline at end of file diff --git a/src/test/java/io/github/openunirest/test/http/MockServer.java b/src/test/java/io/github/openunirest/http/MockServer.java similarity index 77% rename from src/test/java/io/github/openunirest/test/http/MockServer.java rename to src/test/java/io/github/openunirest/http/MockServer.java index c4f81cfe6..9d7694085 100644 --- a/src/test/java/io/github/openunirest/test/http/MockServer.java +++ b/src/test/java/io/github/openunirest/http/MockServer.java @@ -24,10 +24,13 @@ a copy of this software and associated documentation files (the */ -package io.github.openunirest.test.http; +package io.github.openunirest.http; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.http.entity.ContentType; +import spark.Request; +import spark.Response; import spark.Route; import spark.Spark; @@ -36,22 +39,44 @@ a copy of this software and associated documentation files (the import java.io.IOException; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import java.util.Scanner; import static java.lang.System.getProperty; import static spark.Spark.*; public class MockServer { - private static final ObjectMapper om = new ObjectMapper(); + private static final JacksonObjectMapper om = new JacksonObjectMapper(); + private static Object responseBody; public static int PORT = 4567; public static String HOST = "http://localhost:" + PORT; + public static String POSTJSON = HOST + "/post"; + private static boolean capture = false; + + public static void setJsonAsResponse(Object o){ + responseBody = om.writeValue(o); + } + + public static void reset(){ + capture = false; + responseBody = null; + } public static void start() { port(PORT); + post("/post", ContentType.APPLICATION_JSON.getMimeType(), MockServer::postJson); post("/post", ContentType.MULTIPART_FORM_DATA.getMimeType(), multipost); get("/get", (request, response) -> "Hi Momn"); } + private static Object postJson(Request req, Response res) { + if(capture){ + return om.writeValue(new FormCapture(req)); + } + return responseBody; + } + + private static Route multipost = (req, res) -> { req.raw().setAttribute("org.eclipse.jetty.multipartConfig", new MultipartConfigElement(getProperty("java.io.tmpdir"))); @@ -64,7 +89,7 @@ public static void start() { } } - return om.writeValueAsString(body); + return om.writeValue(body); }; private static void buildFormPart(Part p, ResponseBody body) throws IOException { @@ -84,6 +109,10 @@ public static void shutdown() { Spark.stop(); } + public static void captureAndReturnRequest() { + capture = true; + } + public static class ResponseBody { public File files; public Map form = new HashMap<>(); diff --git a/src/test/java/io/github/openunirest/http/TestUtils.java b/src/test/java/io/github/openunirest/http/TestUtils.java new file mode 100644 index 000000000..b4c384dbb --- /dev/null +++ b/src/test/java/io/github/openunirest/http/TestUtils.java @@ -0,0 +1,29 @@ +package io.github.openunirest.http; + +import java.io.IOException; + +public class TestUtils { + private static final com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper(); + + public static void debugApache() { + System.setProperty("org.apache.commons.logging.Log","org.apache.commons.logging.impl.SimpleLog"); + System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); + System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "DEBUG"); + } + + public static T read(String o, Class as){ + try { + return om.readValue(o, as); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static T read(HttpResponse r, Class as) { + try { + return om.readValue(r.getRawBody(), as); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/test/java/io/github/openunirest/test/http/UnirestTest.java b/src/test/java/io/github/openunirest/http/UnirestTest.java similarity index 95% rename from src/test/java/io/github/openunirest/test/http/UnirestTest.java rename to src/test/java/io/github/openunirest/http/UnirestTest.java index f05ebbb0d..cbc7faa25 100644 --- a/src/test/java/io/github/openunirest/test/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/http/UnirestTest.java @@ -24,24 +24,14 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.test.http; +package io.github.openunirest.http; -import io.github.openunirest.http.Headers; -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.JsonNode; -import io.github.openunirest.http.Unirest; import io.github.openunirest.http.async.Callback; +import io.github.openunirest.http.options.Options; import io.github.openunirest.request.body.MultipartBody; -import io.github.openunirest.test.helper.GetResponse; -import io.github.openunirest.test.helper.JacksonObjectMapper; -import io.github.openunirest.http.async.Callback; import io.github.openunirest.http.exceptions.UnirestException; -import io.github.openunirest.http.options.Options; import io.github.openunirest.request.GetRequest; import io.github.openunirest.request.HttpRequest; -import io.github.openunirest.request.body.MultipartBody; -import io.github.openunirest.test.helper.GetResponse; -import io.github.openunirest.test.helper.JacksonObjectMapper; import org.apache.commons.io.IOUtils; import org.apache.http.entity.ContentType; @@ -51,10 +41,6 @@ a copy of this software and associated documentation files (the import org.json.JSONException; import org.json.JSONObject; import org.junit.*; -import io.github.openunirest.http.Headers; -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.JsonNode; -import io.github.openunirest.http.Unirest; import java.io.*; import java.net.InetAddress; @@ -82,6 +68,7 @@ public static void suiteTearDown(){ @Before public void setUp() { + MockServer.reset(); lock = new CountDownLatch(1); status = false; } @@ -99,19 +86,20 @@ private String findAvailableIpAddress() throws IOException { @Test public void testRequests() throws JSONException, UnirestException { - HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post").header("accept", "application/json").field("param1", "value1").field("param2", "bye").asJson(); + MockServer.captureAndReturnRequest(); + + HttpResponse jsonResponse = Unirest.post(MockServer.POSTJSON) + .header("accept", "application/json") + .field("param1", "value1") + .field("param2", "bye") + .asJson(); - assertTrue(jsonResponse.getHeaders().size() > 0); - assertTrue(jsonResponse.getBody().toString().length() > 0); - assertFalse(jsonResponse.getRawBody() == null); assertEquals(200, jsonResponse.getStatus()); - JsonNode json = jsonResponse.getBody(); - assertFalse(json.isArray()); - assertNotNull(json.getObject()); - assertNotNull(json.getArray()); - assertEquals(1, json.getArray().length()); - assertNotNull(json.getArray().get(0)); + FormCapture json = TestUtils.read(jsonResponse, FormCapture.class); + json.assertHeader("Accept", "application/json"); + json.assertQuery("param1", "value1"); + json.assertQuery("param2", "bye"); } @Test @@ -320,6 +308,7 @@ public void testMultipartContentType() throws JSONException, URISyntaxException, public void testMultipartInputStreamContentType() throws JSONException, URISyntaxException, FileNotFoundException { FileInputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())); MultipartBody request = Unirest.post(MockServer.HOST + "/post") + .header("accept", ContentType.MULTIPART_FORM_DATA.toString()) .field("name", "Mark") .field("file", stream, ContentType.APPLICATION_OCTET_STREAM, "image.jpg"); @@ -840,9 +829,4 @@ public void testHeaderNamesCaseSensitive() { assertEquals("Only header \"Content-Type\" should exist", "application/json", headers.getFirst("Content-Type")); } - private static void debugApache() { - System.setProperty("org.apache.commons.logging.Log","org.apache.commons.logging.impl.SimpleLog"); - System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); - System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "DEBUG"); - } } From 41858a41f9ea06d208528b57f28e7c6a79e977b1 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 7 Mar 2018 08:02:58 -0600 Subject: [PATCH 0028/1769] more test cleanup --- .../github/openunirest/http/MockServer.java | 21 ++++++++--------- .../github/openunirest/http/UnirestTest.java | 23 ++++++++++++++----- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/test/java/io/github/openunirest/http/MockServer.java b/src/test/java/io/github/openunirest/http/MockServer.java index 9d7694085..935066de9 100644 --- a/src/test/java/io/github/openunirest/http/MockServer.java +++ b/src/test/java/io/github/openunirest/http/MockServer.java @@ -26,8 +26,6 @@ a copy of this software and associated documentation files (the package io.github.openunirest.http; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.http.entity.ContentType; import spark.Request; import spark.Response; @@ -39,7 +37,6 @@ a copy of this software and associated documentation files (the import java.io.IOException; import java.util.HashMap; import java.util.Map; -import java.util.Optional; import java.util.Scanner; import static java.lang.System.getProperty; @@ -47,11 +44,12 @@ a copy of this software and associated documentation files (the public class MockServer { private static final JacksonObjectMapper om = new JacksonObjectMapper(); - private static Object responseBody; - public static int PORT = 4567; - public static String HOST = "http://localhost:" + PORT; - public static String POSTJSON = HOST + "/post"; - private static boolean capture = false; + private static Object responseBody; + public static final int PORT = 4567; + public static final String HOST = "http://localhost:" + PORT; + public static final String POSTJSON = HOST + "/post"; + public static final String GETJSON = HOST + "/get"; + private static boolean capture = false; public static void setJsonAsResponse(Object o){ responseBody = om.writeValue(o); @@ -64,12 +62,13 @@ public static void reset(){ public static void start() { port(PORT); - post("/post", ContentType.APPLICATION_JSON.getMimeType(), MockServer::postJson); + post("/post", ContentType.APPLICATION_JSON.getMimeType(), MockServer::jsonResponse); post("/post", ContentType.MULTIPART_FORM_DATA.getMimeType(), multipost); - get("/get", (request, response) -> "Hi Momn"); + get("/get", ContentType.APPLICATION_JSON.getMimeType(), MockServer::jsonResponse); + //get("/get", (request, response) -> "Hi Momn"); } - private static Object postJson(Request req, Response res) { + private static Object jsonResponse(Request req, Response res) { if(capture){ return om.writeValue(new FormCapture(req)); } diff --git a/src/test/java/io/github/openunirest/http/UnirestTest.java b/src/test/java/io/github/openunirest/http/UnirestTest.java index cbc7faa25..0f818836c 100644 --- a/src/test/java/io/github/openunirest/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/http/UnirestTest.java @@ -85,7 +85,7 @@ private String findAvailableIpAddress() throws IOException { } @Test - public void testRequests() throws JSONException, UnirestException { + public void postFormReturnJson() throws JSONException, UnirestException { MockServer.captureAndReturnRequest(); HttpResponse jsonResponse = Unirest.post(MockServer.POSTJSON) @@ -103,12 +103,23 @@ public void testRequests() throws JSONException, UnirestException { } @Test - public void testGet() throws JSONException, UnirestException { - HttpResponse response = Unirest.get("http://httpbin.org/get?name=mark").asJson(); - assertEquals(response.getBody().getObject().getJSONObject("args").getString("name"), "mark"); + public void canPassQueryParamsOnStringOrWithForm() throws JSONException, UnirestException { + MockServer.captureAndReturnRequest(); + + HttpResponse response = Unirest.get(MockServer.GETJSON + "?name=mark") + .header("accept", "application/json") + .asJson(); + + FormCapture json = TestUtils.read(response, FormCapture.class); + json.assertQuery("name", "mark"); + + response = Unirest.get(MockServer.GETJSON) + .header("accept", "application/json") + .queryString("name", "mark2") + .asJson(); - response = Unirest.get("http://httpbin.org/get").queryString("name", "mark2").asJson(); - assertEquals(response.getBody().getObject().getJSONObject("args").getString("name"), "mark2"); + json = TestUtils.read(response, FormCapture.class); + json.assertQuery("name", "mark2"); } @Test From 65b93e288c4229c99448bea2db2162448b5d50ec Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 7 Mar 2018 08:12:08 -0600 Subject: [PATCH 0029/1769] test to show multiple params --- pom.xml | 7 +++ .../github/openunirest/http/FormCapture.java | 11 ++-- .../github/openunirest/http/MockServer.java | 14 ++--- .../io/github/openunirest/http/TestUtils.java | 2 +- .../github/openunirest/http/UnirestTest.java | 56 ++++++++++++------- 5 files changed, 56 insertions(+), 34 deletions(-) diff --git a/pom.xml b/pom.xml index 1b782fb8c..0d9731b55 100644 --- a/pom.xml +++ b/pom.xml @@ -188,6 +188,13 @@ 2.4 test
+ + + com.google.guava + guava + 24.0-jre + test + com.fasterxml.jackson.core jackson-databind diff --git a/src/test/java/io/github/openunirest/http/FormCapture.java b/src/test/java/io/github/openunirest/http/FormCapture.java index 97154b962..d3f288f11 100644 --- a/src/test/java/io/github/openunirest/http/FormCapture.java +++ b/src/test/java/io/github/openunirest/http/FormCapture.java @@ -1,17 +1,20 @@ package io.github.openunirest.http; +import com.google.common.collect.Sets; import spark.Request; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Set; import static org.hamcrest.CoreMatchers.hasItem; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; public class FormCapture { - public Map headers = new LinkedHashMap<>(); - public Map query = new LinkedHashMap<>(); + public Map headers = new LinkedHashMap<>(); + public Map> query = new LinkedHashMap<>(); public FormCapture(){} @@ -21,7 +24,7 @@ public FormCapture(Request req) { } private void writeQuery(Request req) { - req.queryParams().forEach(q -> query.put(q, req.queryParams(q))); + req.queryParams().forEach(q -> query.computeIfAbsent(q, (w) -> Sets.newHashSet(req.queryMap(q).values()))); } private void writeHeaders(Request req) { @@ -33,6 +36,6 @@ public void assertHeader(String key, String value) { } public void assertQuery(String key, String value) { - assertEquals("Expected Query or Form value", value, query.get(key)); + assertThat("Expected Query or Form value", query.getOrDefault(key, Collections.emptySet()), hasItem(value)); } } diff --git a/src/test/java/io/github/openunirest/http/MockServer.java b/src/test/java/io/github/openunirest/http/MockServer.java index 935066de9..0353b980f 100644 --- a/src/test/java/io/github/openunirest/http/MockServer.java +++ b/src/test/java/io/github/openunirest/http/MockServer.java @@ -49,14 +49,13 @@ public class MockServer { public static final String HOST = "http://localhost:" + PORT; public static final String POSTJSON = HOST + "/post"; public static final String GETJSON = HOST + "/get"; - private static boolean capture = false; + public static void setJsonAsResponse(Object o){ responseBody = om.writeValue(o); } public static void reset(){ - capture = false; responseBody = null; } @@ -65,14 +64,13 @@ public static void start() { post("/post", ContentType.APPLICATION_JSON.getMimeType(), MockServer::jsonResponse); post("/post", ContentType.MULTIPART_FORM_DATA.getMimeType(), multipost); get("/get", ContentType.APPLICATION_JSON.getMimeType(), MockServer::jsonResponse); - //get("/get", (request, response) -> "Hi Momn"); } private static Object jsonResponse(Request req, Response res) { - if(capture){ - return om.writeValue(new FormCapture(req)); + if(responseBody != null){ + return responseBody; } - return responseBody; + return om.writeValue(new FormCapture(req)); } @@ -108,10 +106,6 @@ public static void shutdown() { Spark.stop(); } - public static void captureAndReturnRequest() { - capture = true; - } - public static class ResponseBody { public File files; public Map form = new HashMap<>(); diff --git a/src/test/java/io/github/openunirest/http/TestUtils.java b/src/test/java/io/github/openunirest/http/TestUtils.java index b4c384dbb..52d860bc2 100644 --- a/src/test/java/io/github/openunirest/http/TestUtils.java +++ b/src/test/java/io/github/openunirest/http/TestUtils.java @@ -19,7 +19,7 @@ public static T read(String o, Class as){ } } - public static T read(HttpResponse r, Class as) { + public static T read(HttpResponse r, Class as) { try { return om.readValue(r.getRawBody(), as); } catch (IOException e) { diff --git a/src/test/java/io/github/openunirest/http/UnirestTest.java b/src/test/java/io/github/openunirest/http/UnirestTest.java index 0f818836c..4c5f40241 100644 --- a/src/test/java/io/github/openunirest/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/http/UnirestTest.java @@ -73,21 +73,8 @@ public void setUp() { status = false; } - private String findAvailableIpAddress() throws IOException { - for (int i = 100; i <= 255; i++) { - String ip = "192.168.1." + i; - if (!InetAddress.getByName(ip).isReachable(1000)) { - return ip; - } - } - - throw new RuntimeException("Couldn't find an available IP address in the range of 192.168.0.100-255"); - } - @Test public void postFormReturnJson() throws JSONException, UnirestException { - MockServer.captureAndReturnRequest(); - HttpResponse jsonResponse = Unirest.post(MockServer.POSTJSON) .header("accept", "application/json") .field("param1", "value1") @@ -104,8 +91,6 @@ public void postFormReturnJson() throws JSONException, UnirestException { @Test public void canPassQueryParamsOnStringOrWithForm() throws JSONException, UnirestException { - MockServer.captureAndReturnRequest(); - HttpResponse response = Unirest.get(MockServer.GETJSON + "?name=mark") .header("accept", "application/json") .asJson(); @@ -122,18 +107,40 @@ public void canPassQueryParamsOnStringOrWithForm() throws JSONException, Unirest json.assertQuery("name", "mark2"); } + @Test + public void multipleParams() throws JSONException, UnirestException { + HttpResponse response = Unirest.get(MockServer.GETJSON + "?name=ringo") + .header("accept", "application/json") + .queryString("name", "paul") + .queryString("name", "john") + .asJson(); + + FormCapture json = TestUtils.read(response, FormCapture.class); + json.assertQuery("name", "ringo"); + json.assertQuery("name", "paul"); + json.assertQuery("name", "john"); + } + @Test public void testGetUTF8() { - HttpResponse response = Unirest.get("http://httpbin.org/get").queryString("param3", "こんにちは").asJson(); + HttpResponse response = Unirest.get(MockServer.GETJSON) + .header("accept", "application/json") + .queryString("param3", "こんにちは") + .asJson(); - assertEquals(response.getBody().getObject().getJSONObject("args").getString("param3"), "こんにちは"); + FormCapture json = TestUtils.read(response, FormCapture.class); + json.assertQuery("param3", "こんにちは"); } @Test public void testPostUTF8() { - HttpResponse response = Unirest.post("http://httpbin.org/post").field("param3", "こんにちは").asJson(); + HttpResponse response = Unirest.post(MockServer.POSTJSON) + .header("accept", "application/json") + .field("param3", "こんにちは") + .asJson(); - assertEquals(response.getBody().getObject().getJSONObject("form").getString("param3"), "こんにちは"); + FormCapture json = TestUtils.read(response, FormCapture.class); + json.assertQuery("param3", "こんにちは"); } @Test @@ -840,4 +847,15 @@ public void testHeaderNamesCaseSensitive() { assertEquals("Only header \"Content-Type\" should exist", "application/json", headers.getFirst("Content-Type")); } + + private String findAvailableIpAddress() throws IOException { + for (int i = 100; i <= 255; i++) { + String ip = "192.168.1." + i; + if (!InetAddress.getByName(ip).isReachable(1000)) { + return ip; + } + } + + throw new RuntimeException("Couldn't find an available IP address in the range of 192.168.0.100-255"); + } } From 97f20cf8d5a1f9266c28cfe4379a9198e063bdbf Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 9 Mar 2018 11:07:49 -0600 Subject: [PATCH 0030/1769] fix more tests to not call requestbn --- .../github/openunirest/http/FormCapture.java | 65 +++++++++++++++++-- .../github/openunirest/http/MockServer.java | 37 +---------- .../io/github/openunirest/http/TestUtil.java | 13 ++++ .../github/openunirest/http/UnirestTest.java | 35 +++++----- 4 files changed, 93 insertions(+), 57 deletions(-) create mode 100644 src/test/java/io/github/openunirest/http/TestUtil.java diff --git a/src/test/java/io/github/openunirest/http/FormCapture.java b/src/test/java/io/github/openunirest/http/FormCapture.java index d3f288f11..628634bea 100644 --- a/src/test/java/io/github/openunirest/http/FormCapture.java +++ b/src/test/java/io/github/openunirest/http/FormCapture.java @@ -1,28 +1,79 @@ package io.github.openunirest.http; import com.google.common.collect.Sets; +import org.apache.http.entity.ContentType; import spark.Request; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Set; +import javax.servlet.MultipartConfigElement; +import javax.servlet.http.Part; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringWriter; +import java.util.*; +import static java.lang.System.getProperty; import static org.hamcrest.CoreMatchers.hasItem; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; public class FormCapture { public Map headers = new LinkedHashMap<>(); + public Map files = new LinkedHashMap<>(); public Map> query = new LinkedHashMap<>(); - public FormCapture(){} + public FormCapture() { + } public FormCapture(Request req) { writeHeaders(req); writeQuery(req); } + public void writeFiles(Request req) { + req.raw().setAttribute("org.eclipse.jetty.multipartConfig", new MultipartConfigElement(getProperty("java.io.tmpdir"))); + + try { + for (Part p : req.raw().getParts()) { + if (p.getContentType().equals(ContentType.APPLICATION_OCTET_STREAM.getMimeType())) { + buildFilePart(p); + } else { + buildFormPart(p); + } + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private void buildFormPart(Part p) throws IOException { + java.util.Scanner s = new Scanner(p.getInputStream()).useDelimiter("\\A"); + String value = s.hasNext() ? s.next() : ""; + query.put(p.getName(), Sets.newHashSet(value)); + } + + public void buildFilePart(Part part) throws IOException { + File file = new File(); + file.fileName = part.getSubmittedFileName(); + file.type = part.getContentType(); + file.inputName = part.getName(); + file.body = TestUtil.toString(part.getInputStream()); + + files.put(file.fileName, file); + } + + + public static class File { + public String fileName; + public String type; + public String inputName; + public String body; + + public void assertBody(String content){ + assertEquals(content, body); + } + } + private void writeQuery(Request req) { req.queryParams().forEach(q -> query.computeIfAbsent(q, (w) -> Sets.newHashSet(req.queryMap(q).values()))); } @@ -38,4 +89,8 @@ public void assertHeader(String key, String value) { public void assertQuery(String key, String value) { assertThat("Expected Query or Form value", query.getOrDefault(key, Collections.emptySet()), hasItem(value)); } + + public File getFile(String fileName) { + return files.get(fileName); + } } diff --git a/src/test/java/io/github/openunirest/http/MockServer.java b/src/test/java/io/github/openunirest/http/MockServer.java index 0353b980f..84ab88b8c 100644 --- a/src/test/java/io/github/openunirest/http/MockServer.java +++ b/src/test/java/io/github/openunirest/http/MockServer.java @@ -47,7 +47,7 @@ public class MockServer { private static Object responseBody; public static final int PORT = 4567; public static final String HOST = "http://localhost:" + PORT; - public static final String POSTJSON = HOST + "/post"; + public static final String POST = HOST + "/post"; public static final String GETJSON = HOST + "/get"; @@ -75,45 +75,14 @@ private static Object jsonResponse(Request req, Response res) { private static Route multipost = (req, res) -> { - req.raw().setAttribute("org.eclipse.jetty.multipartConfig", new MultipartConfigElement(getProperty("java.io.tmpdir"))); - ResponseBody body = new ResponseBody(); - for (Part p : req.raw().getParts()) { - if (p.getContentType().equals(ContentType.APPLICATION_OCTET_STREAM.getMimeType())) { - buildFilePart(p, body); - } else { - buildFormPart(p, body); - } - } + FormCapture body = new FormCapture(req); + body.writeFiles(req); return om.writeValue(body); }; - private static void buildFormPart(Part p, ResponseBody body) throws IOException { - java.util.Scanner s = new Scanner(p.getInputStream()).useDelimiter("\\A"); - String value = s.hasNext() ? s.next() : ""; - body.form.put(p.getName(), value); - } - - public static void buildFilePart(Part part, ResponseBody body){ - body.files = new File(); - body.files.fileName = part.getSubmittedFileName(); - body.files.type = part.getContentType(); - body.files.inputName = part.getName(); - } - public static void shutdown() { Spark.stop(); } - - public static class ResponseBody { - public File files; - public Map form = new HashMap<>(); - } - - public static class File { - public String fileName; - public String type; - public String inputName; - } } diff --git a/src/test/java/io/github/openunirest/http/TestUtil.java b/src/test/java/io/github/openunirest/http/TestUtil.java new file mode 100644 index 000000000..b3bcfe5e9 --- /dev/null +++ b/src/test/java/io/github/openunirest/http/TestUtil.java @@ -0,0 +1,13 @@ +package io.github.openunirest.http; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.stream.Collectors; + +public class TestUtil { + public static String toString(InputStream is) { + return new BufferedReader(new InputStreamReader(is)) + .lines().collect(Collectors.joining("\n")); + } +} diff --git a/src/test/java/io/github/openunirest/http/UnirestTest.java b/src/test/java/io/github/openunirest/http/UnirestTest.java index 4c5f40241..0f1d57b08 100644 --- a/src/test/java/io/github/openunirest/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/http/UnirestTest.java @@ -75,7 +75,7 @@ public void setUp() { @Test public void postFormReturnJson() throws JSONException, UnirestException { - HttpResponse jsonResponse = Unirest.post(MockServer.POSTJSON) + HttpResponse jsonResponse = Unirest.post(MockServer.POST) .header("accept", "application/json") .field("param1", "value1") .field("param2", "bye") @@ -134,7 +134,7 @@ public void testGetUTF8() { @Test public void testPostUTF8() { - HttpResponse response = Unirest.post(MockServer.POSTJSON) + HttpResponse response = Unirest.post(MockServer.POST) .header("accept", "application/json") .field("param3", "こんにちは") .asJson(); @@ -145,10 +145,15 @@ public void testPostUTF8() { @Test public void testPostBinaryUTF8() throws URISyntaxException { - HttpResponse response = Unirest.post("http://httpbin.org/post").field("param3", "こんにちは").field("file", new File(getClass().getResource("/test").toURI())).asJson(); + HttpResponse response = Unirest.post(MockServer.POST) + .header("Accept", ContentType.MULTIPART_FORM_DATA.getMimeType()) + .field("param3", "こんにちは") + .field("file", new File(getClass().getResource("/test").toURI())) + .asJson(); - assertEquals("This is a test file", response.getBody().getObject().getJSONObject("files").getString("file")); - assertEquals("こんにちは", response.getBody().getObject().getJSONObject("form").getString("param3")); + FormCapture json = TestUtils.read(response, FormCapture.class); + json.assertQuery("param3", "こんにちは"); + json.getFile("test").assertBody("This is a test file"); } @Test @@ -333,22 +338,16 @@ public void testMultipartInputStreamContentType() throws JSONException, URISynta HttpResponse jsonResponse = request .asJson(); - assertTrue(jsonResponse.getHeaders().size() > 0); - assertTrue(jsonResponse.getBody().toString().length() > 0); - assertFalse(jsonResponse.getRawBody() == null); assertEquals(200, jsonResponse.getStatus()); - JsonNode json = jsonResponse.getBody(); - assertFalse(json.isArray()); - JSONObject object = json.getObject(); - assertNotNull(object); - assertNotNull(json.getArray()); - assertEquals(1, json.getArray().length()); - assertNotNull(json.getArray().get(0)); - assertNotNull(object.getJSONObject("files")); + FormCapture json = TestUtils.read(jsonResponse, FormCapture.class); + json.assertHeader("Accept", ContentType.MULTIPART_FORM_DATA.toString()); + json.assertQuery("name", "Mark"); + assertEquals("application/octet-stream", json.getFile("image.jpg").type); - assertTrue(json.getObject().getJSONObject("files").getString("type").contains("application/octet-stream")); - assertEquals("Mark", json.getObject().getJSONObject("form").getString("name")); + +// assertTrue(json.getObject().getJSONObject("files").getString("type").contains("application/octet-stream")); +// assertEquals("Mark", json.getObject().getJSONObject("form").getString("name")); } @Test From 5b3e4065c95dd0c3933581b9db27ae97fea8bd24 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 9 Mar 2018 11:08:21 -0600 Subject: [PATCH 0031/1769] rename test class --- .../io/github/openunirest/http/MockServer.java | 11 ++--------- .../{FormCapture.java => RequestCapture.java} | 9 +++------ .../io/github/openunirest/http/UnirestTest.java | 16 ++++++++-------- 3 files changed, 13 insertions(+), 23 deletions(-) rename src/test/java/io/github/openunirest/http/{FormCapture.java => RequestCapture.java} (93%) diff --git a/src/test/java/io/github/openunirest/http/MockServer.java b/src/test/java/io/github/openunirest/http/MockServer.java index 84ab88b8c..612d3d1d2 100644 --- a/src/test/java/io/github/openunirest/http/MockServer.java +++ b/src/test/java/io/github/openunirest/http/MockServer.java @@ -32,13 +32,6 @@ a copy of this software and associated documentation files (the import spark.Route; import spark.Spark; -import javax.servlet.MultipartConfigElement; -import javax.servlet.http.Part; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Scanner; - import static java.lang.System.getProperty; import static spark.Spark.*; @@ -70,13 +63,13 @@ private static Object jsonResponse(Request req, Response res) { if(responseBody != null){ return responseBody; } - return om.writeValue(new FormCapture(req)); + return om.writeValue(new RequestCapture(req)); } private static Route multipost = (req, res) -> { - FormCapture body = new FormCapture(req); + RequestCapture body = new RequestCapture(req); body.writeFiles(req); return om.writeValue(body); diff --git a/src/test/java/io/github/openunirest/http/FormCapture.java b/src/test/java/io/github/openunirest/http/RequestCapture.java similarity index 93% rename from src/test/java/io/github/openunirest/http/FormCapture.java rename to src/test/java/io/github/openunirest/http/RequestCapture.java index 628634bea..f30e62f65 100644 --- a/src/test/java/io/github/openunirest/http/FormCapture.java +++ b/src/test/java/io/github/openunirest/http/RequestCapture.java @@ -7,25 +7,22 @@ import javax.servlet.MultipartConfigElement; import javax.servlet.http.Part; import java.io.IOException; -import java.io.InputStream; -import java.io.StringWriter; import java.util.*; import static java.lang.System.getProperty; import static org.hamcrest.CoreMatchers.hasItem; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; -public class FormCapture { +public class RequestCapture { public Map headers = new LinkedHashMap<>(); public Map files = new LinkedHashMap<>(); public Map> query = new LinkedHashMap<>(); - public FormCapture() { + public RequestCapture() { } - public FormCapture(Request req) { + public RequestCapture(Request req) { writeHeaders(req); writeQuery(req); } diff --git a/src/test/java/io/github/openunirest/http/UnirestTest.java b/src/test/java/io/github/openunirest/http/UnirestTest.java index 0f1d57b08..30475aa60 100644 --- a/src/test/java/io/github/openunirest/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/http/UnirestTest.java @@ -83,7 +83,7 @@ public void postFormReturnJson() throws JSONException, UnirestException { assertEquals(200, jsonResponse.getStatus()); - FormCapture json = TestUtils.read(jsonResponse, FormCapture.class); + RequestCapture json = TestUtils.read(jsonResponse, RequestCapture.class); json.assertHeader("Accept", "application/json"); json.assertQuery("param1", "value1"); json.assertQuery("param2", "bye"); @@ -95,7 +95,7 @@ public void canPassQueryParamsOnStringOrWithForm() throws JSONException, Unirest .header("accept", "application/json") .asJson(); - FormCapture json = TestUtils.read(response, FormCapture.class); + RequestCapture json = TestUtils.read(response, RequestCapture.class); json.assertQuery("name", "mark"); response = Unirest.get(MockServer.GETJSON) @@ -103,7 +103,7 @@ public void canPassQueryParamsOnStringOrWithForm() throws JSONException, Unirest .queryString("name", "mark2") .asJson(); - json = TestUtils.read(response, FormCapture.class); + json = TestUtils.read(response, RequestCapture.class); json.assertQuery("name", "mark2"); } @@ -115,7 +115,7 @@ public void multipleParams() throws JSONException, UnirestException { .queryString("name", "john") .asJson(); - FormCapture json = TestUtils.read(response, FormCapture.class); + RequestCapture json = TestUtils.read(response, RequestCapture.class); json.assertQuery("name", "ringo"); json.assertQuery("name", "paul"); json.assertQuery("name", "john"); @@ -128,7 +128,7 @@ public void testGetUTF8() { .queryString("param3", "こんにちは") .asJson(); - FormCapture json = TestUtils.read(response, FormCapture.class); + RequestCapture json = TestUtils.read(response, RequestCapture.class); json.assertQuery("param3", "こんにちは"); } @@ -139,7 +139,7 @@ public void testPostUTF8() { .field("param3", "こんにちは") .asJson(); - FormCapture json = TestUtils.read(response, FormCapture.class); + RequestCapture json = TestUtils.read(response, RequestCapture.class); json.assertQuery("param3", "こんにちは"); } @@ -151,7 +151,7 @@ public void testPostBinaryUTF8() throws URISyntaxException { .field("file", new File(getClass().getResource("/test").toURI())) .asJson(); - FormCapture json = TestUtils.read(response, FormCapture.class); + RequestCapture json = TestUtils.read(response, RequestCapture.class); json.assertQuery("param3", "こんにちは"); json.getFile("test").assertBody("This is a test file"); } @@ -340,7 +340,7 @@ public void testMultipartInputStreamContentType() throws JSONException, URISynta assertEquals(200, jsonResponse.getStatus()); - FormCapture json = TestUtils.read(jsonResponse, FormCapture.class); + RequestCapture json = TestUtils.read(jsonResponse, RequestCapture.class); json.assertHeader("Accept", ContentType.MULTIPART_FORM_DATA.toString()); json.assertQuery("name", "Mark"); assertEquals("application/octet-stream", json.getFile("image.jpg").type); From 9f097ee88231fbadf9b99f36afe33ae8eadcc246 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 10 Mar 2018 07:38:37 -0600 Subject: [PATCH 0032/1769] moving tests to internal --- .../github/openunirest/http/MockServer.java | 8 +- .../openunirest/http/RequestCapture.java | 11 ++- .../github/openunirest/http/UnirestTest.java | 77 +++++++++++-------- 3 files changed, 60 insertions(+), 36 deletions(-) diff --git a/src/test/java/io/github/openunirest/http/MockServer.java b/src/test/java/io/github/openunirest/http/MockServer.java index 612d3d1d2..6f56e1a4f 100644 --- a/src/test/java/io/github/openunirest/http/MockServer.java +++ b/src/test/java/io/github/openunirest/http/MockServer.java @@ -63,15 +63,15 @@ private static Object jsonResponse(Request req, Response res) { if(responseBody != null){ return responseBody; } - return om.writeValue(new RequestCapture(req)); + RequestCapture value = new RequestCapture(req); + value.writeBody(req); + return om.writeValue(value); } private static Route multipost = (req, res) -> { - RequestCapture body = new RequestCapture(req); - body.writeFiles(req); - + body.writeMultipart(req); return om.writeValue(body); }; diff --git a/src/test/java/io/github/openunirest/http/RequestCapture.java b/src/test/java/io/github/openunirest/http/RequestCapture.java index f30e62f65..c4727de31 100644 --- a/src/test/java/io/github/openunirest/http/RequestCapture.java +++ b/src/test/java/io/github/openunirest/http/RequestCapture.java @@ -18,6 +18,7 @@ public class RequestCapture { public Map headers = new LinkedHashMap<>(); public Map files = new LinkedHashMap<>(); public Map> query = new LinkedHashMap<>(); + public String body; public RequestCapture() { } @@ -27,7 +28,11 @@ public RequestCapture(Request req) { writeQuery(req); } - public void writeFiles(Request req) { + public void writeBody(Request req) { + this.body = req.body(); + } + + public void writeMultipart(Request req) { req.raw().setAttribute("org.eclipse.jetty.multipartConfig", new MultipartConfigElement(getProperty("java.io.tmpdir"))); try { @@ -59,6 +64,10 @@ public void buildFilePart(Part part) throws IOException { files.put(file.fileName, file); } + public void asserBody(String s) { + assertEquals(s, body); + } + public static class File { public String fileName; diff --git a/src/test/java/io/github/openunirest/http/UnirestTest.java b/src/test/java/io/github/openunirest/http/UnirestTest.java index 30475aa60..ef86b9ca8 100644 --- a/src/test/java/io/github/openunirest/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/http/UnirestTest.java @@ -49,6 +49,7 @@ a copy of this software and associated documentation files (the import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; +import static io.github.openunirest.http.TestUtils.read; import static org.junit.Assert.*; public class UnirestTest { @@ -83,7 +84,7 @@ public void postFormReturnJson() throws JSONException, UnirestException { assertEquals(200, jsonResponse.getStatus()); - RequestCapture json = TestUtils.read(jsonResponse, RequestCapture.class); + RequestCapture json = parse(jsonResponse); json.assertHeader("Accept", "application/json"); json.assertQuery("param1", "value1"); json.assertQuery("param2", "bye"); @@ -95,7 +96,7 @@ public void canPassQueryParamsOnStringOrWithForm() throws JSONException, Unirest .header("accept", "application/json") .asJson(); - RequestCapture json = TestUtils.read(response, RequestCapture.class); + RequestCapture json = parse(response); json.assertQuery("name", "mark"); response = Unirest.get(MockServer.GETJSON) @@ -103,7 +104,7 @@ public void canPassQueryParamsOnStringOrWithForm() throws JSONException, Unirest .queryString("name", "mark2") .asJson(); - json = TestUtils.read(response, RequestCapture.class); + json = parse(response); json.assertQuery("name", "mark2"); } @@ -115,7 +116,7 @@ public void multipleParams() throws JSONException, UnirestException { .queryString("name", "john") .asJson(); - RequestCapture json = TestUtils.read(response, RequestCapture.class); + RequestCapture json = parse(response); json.assertQuery("name", "ringo"); json.assertQuery("name", "paul"); json.assertQuery("name", "john"); @@ -128,7 +129,7 @@ public void testGetUTF8() { .queryString("param3", "こんにちは") .asJson(); - RequestCapture json = TestUtils.read(response, RequestCapture.class); + RequestCapture json = parse(response); json.assertQuery("param3", "こんにちは"); } @@ -139,7 +140,7 @@ public void testPostUTF8() { .field("param3", "こんにちは") .asJson(); - RequestCapture json = TestUtils.read(response, RequestCapture.class); + RequestCapture json = parse(response); json.assertQuery("param3", "こんにちは"); } @@ -151,7 +152,7 @@ public void testPostBinaryUTF8() throws URISyntaxException { .field("file", new File(getClass().getResource("/test").toURI())) .asJson(); - RequestCapture json = TestUtils.read(response, RequestCapture.class); + RequestCapture json = parse(response); json.assertQuery("param3", "こんにちは"); json.getFile("test").assertBody("This is a test file"); } @@ -161,50 +162,63 @@ public void testPostRawBody() { String sourceString = "'\"@こんにちは-test-123-" + Math.random(); byte[] sentBytes = sourceString.getBytes(); - HttpResponse response = Unirest.post("http://httpbin.org/post").body(sentBytes).asJson(); + HttpResponse response = Unirest.post(MockServer.POST) + .body(sentBytes) + .asJson(); - assertEquals(sourceString, response.getBody().getObject().getString("data")); + RequestCapture json = parse(response); + json.asserBody(sourceString); } @Test public void testCustomUserAgent() throws JSONException, UnirestException { - HttpResponse response = Unirest.get("http://httpbin.org/get?name=mark").header("user-agent", "hello-world").asJson(); - assertEquals("hello-world", response.getBody().getObject().getJSONObject("headers").getString("User-Agent")); - - GetRequest getRequest = Unirest.get("http"); - for (Object current : Arrays.asList(0, 1, 2)) { - getRequest.queryString("name", current); - } + HttpResponse response = Unirest.get(MockServer.GETJSON) + .header("user-agent", "hello-world") + .asJson(); + RequestCapture json = parse(response); + json.assertHeader("User-Agent", "hello-world"); } - @Test + @Test public void testGetMultiple() throws JSONException, UnirestException { for (int i = 1; i <= 20; i++) { - HttpResponse response = Unirest.get("http://httpbin.org/get?try=" + i).asJson(); - assertEquals(response.getBody().getObject().getJSONObject("args").getString("try"), ((Integer) i).toString()); + HttpResponse response = Unirest.get(MockServer.GETJSON + "?try=" + i).asJson(); + parse(response).assertQuery("try", String.valueOf(i)); } } @Test public void testGetFields() throws JSONException, UnirestException { - HttpResponse response = Unirest.get("http://httpbin.org/get").queryString("name", "mark").queryString("nick", "thefosk").asJson(); - assertEquals(response.getBody().getObject().getJSONObject("args").getString("name"), "mark"); - assertEquals(response.getBody().getObject().getJSONObject("args").getString("nick"), "thefosk"); + HttpResponse response = Unirest.get(MockServer.GETJSON) + .queryString("name", "mark") + .queryString("nick", "thefosk") + .asJson(); + + RequestCapture parse = parse(response); + parse.assertQuery("name", "mark"); + parse.assertQuery("nick", "thefosk"); } @Test public void testGetFields2() throws JSONException, UnirestException { - HttpResponse response = Unirest.get("http://httpbin.org/get").queryString("email", "hello@hello.com").asJson(); - assertEquals("hello@hello.com", response.getBody().getObject().getJSONObject("args").getString("email")); + HttpResponse response = Unirest.get(MockServer.GETJSON) + .queryString("email", "hello@hello.com") + .asJson(); + + parse(response).assertQuery("email", "hello@hello.com"); } @Test public void testQueryStringEncoding() throws JSONException, UnirestException { String testKey = "email2=someKey&email"; String testValue = "hello@hello.com"; - HttpResponse response = Unirest.get("http://httpbin.org/get").queryString(testKey, testValue).asJson(); - assertEquals(testValue, response.getBody().getObject().getJSONObject("args").getString(testKey)); + + HttpResponse response = Unirest.get(MockServer.GETJSON) + .queryString(testKey, testValue) + .asJson(); + + parse(response).assertQuery(testKey, testValue); } @Test @@ -330,6 +344,7 @@ public void testMultipartContentType() throws JSONException, URISyntaxException, @Test public void testMultipartInputStreamContentType() throws JSONException, URISyntaxException, FileNotFoundException { FileInputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())); + MultipartBody request = Unirest.post(MockServer.HOST + "/post") .header("accept", ContentType.MULTIPART_FORM_DATA.toString()) .field("name", "Mark") @@ -340,14 +355,10 @@ public void testMultipartInputStreamContentType() throws JSONException, URISynta assertEquals(200, jsonResponse.getStatus()); - RequestCapture json = TestUtils.read(jsonResponse, RequestCapture.class); + RequestCapture json = parse(jsonResponse); json.assertHeader("Accept", ContentType.MULTIPART_FORM_DATA.toString()); json.assertQuery("name", "Mark"); assertEquals("application/octet-stream", json.getFile("image.jpg").type); - - -// assertTrue(json.getObject().getJSONObject("files").getString("type").contains("application/octet-stream")); -// assertEquals("Mark", json.getObject().getJSONObject("form").getString("name")); } @Test @@ -857,4 +868,8 @@ private String findAvailableIpAddress() throws IOException { throw new RuntimeException("Couldn't find an available IP address in the range of 192.168.0.100-255"); } + + private RequestCapture parse(HttpResponse response) { + return read(response, RequestCapture.class); + } } From 497ff85c40a79269f0a1411598232673e8b1a25c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 11 Mar 2018 09:17:53 -0500 Subject: [PATCH 0033/1769] more test refactorings --- pom.xml | 9 +- .../openunirest/http/JacksonObjectMapper.java | 22 +++- .../github/openunirest/http/MockServer.java | 4 +- .../openunirest/http/RequestCapture.java | 23 +++- .../io/github/openunirest/http/TestUtils.java | 15 +-- .../github/openunirest/http/UnirestTest.java | 108 +++++++++--------- 6 files changed, 106 insertions(+), 75 deletions(-) diff --git a/pom.xml b/pom.xml index 0d9731b55..1241e2bd9 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,7 @@ UTF-8 UTF-8 - 2.6.0 + 2.9.4 @@ -195,6 +195,13 @@ 24.0-jre test + + + com.fasterxml.jackson.datatype + jackson-datatype-guava + ${jackson.version} + test + com.fasterxml.jackson.core jackson-databind diff --git a/src/test/java/io/github/openunirest/http/JacksonObjectMapper.java b/src/test/java/io/github/openunirest/http/JacksonObjectMapper.java index c4dfb762f..c13fa2334 100644 --- a/src/test/java/io/github/openunirest/http/JacksonObjectMapper.java +++ b/src/test/java/io/github/openunirest/http/JacksonObjectMapper.java @@ -1,18 +1,22 @@ package io.github.openunirest.http; import com.fasterxml.jackson.core.JsonProcessingException; -import io.github.openunirest.http.ObjectMapper; -import io.github.openunirest.http.ObjectMapper; +import com.fasterxml.jackson.datatype.guava.GuavaModule; import java.io.IOException; +import java.io.InputStream; public class JacksonObjectMapper implements ObjectMapper { - private com.fasterxml.jackson.databind.ObjectMapper jacksonObjectMapper = new com.fasterxml.jackson.databind.ObjectMapper(); + private com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper(); + + public JacksonObjectMapper(){ + om.registerModule(new GuavaModule()); + } public T readValue(String value, Class valueType) { try { - return jacksonObjectMapper.readValue(value, valueType); + return om.readValue(value, valueType); } catch (IOException e) { throw new RuntimeException(e); } @@ -20,9 +24,17 @@ public T readValue(String value, Class valueType) { public String writeValue(Object value) { try { - return jacksonObjectMapper.writeValueAsString(value); + return om.writeValueAsString(value); } catch (JsonProcessingException e) { throw new RuntimeException(e); } } + + public T readValue(InputStream rawBody, Class as) { + try { + return om.readValue(rawBody, as); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/src/test/java/io/github/openunirest/http/MockServer.java b/src/test/java/io/github/openunirest/http/MockServer.java index 6f56e1a4f..b1580f5dd 100644 --- a/src/test/java/io/github/openunirest/http/MockServer.java +++ b/src/test/java/io/github/openunirest/http/MockServer.java @@ -42,6 +42,7 @@ public class MockServer { public static final String HOST = "http://localhost:" + PORT; public static final String POST = HOST + "/post"; public static final String GETJSON = HOST + "/get"; + public static final String DELETE = HOST + "/delete"; public static void setJsonAsResponse(Object o){ @@ -54,12 +55,13 @@ public static void reset(){ public static void start() { port(PORT); + delete("/delete", MockServer::jsonResponse); post("/post", ContentType.APPLICATION_JSON.getMimeType(), MockServer::jsonResponse); post("/post", ContentType.MULTIPART_FORM_DATA.getMimeType(), multipost); get("/get", ContentType.APPLICATION_JSON.getMimeType(), MockServer::jsonResponse); } - private static Object jsonResponse(Request req, Response res) { + private static Object jsonResponse(Request req, Response res) { if(responseBody != null){ return responseBody; } diff --git a/src/test/java/io/github/openunirest/http/RequestCapture.java b/src/test/java/io/github/openunirest/http/RequestCapture.java index c4727de31..0bed3cec8 100644 --- a/src/test/java/io/github/openunirest/http/RequestCapture.java +++ b/src/test/java/io/github/openunirest/http/RequestCapture.java @@ -1,12 +1,17 @@ package io.github.openunirest.http; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; +import com.google.common.collect.Multimaps; import com.google.common.collect.Sets; +import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.entity.ContentType; import spark.Request; import javax.servlet.MultipartConfigElement; import javax.servlet.http.Part; import java.io.IOException; +import java.nio.charset.Charset; import java.util.*; import static java.lang.System.getProperty; @@ -17,7 +22,7 @@ public class RequestCapture { public Map headers = new LinkedHashMap<>(); public Map files = new LinkedHashMap<>(); - public Map> query = new LinkedHashMap<>(); + public Multimap params = HashMultimap.create(); public String body; public RequestCapture() { @@ -30,6 +35,14 @@ public RequestCapture(Request req) { public void writeBody(Request req) { this.body = req.body(); + parseBodyToFormParams(req); + } + + private void parseBodyToFormParams(Request req) { + URLEncodedUtils.parse(req.body() , Charset.forName("UTF-8")) + .forEach(p -> { + params.put(p.getName(), p.getValue()); + }); } public void writeMultipart(Request req) { @@ -51,7 +64,7 @@ public void writeMultipart(Request req) { private void buildFormPart(Part p) throws IOException { java.util.Scanner s = new Scanner(p.getInputStream()).useDelimiter("\\A"); String value = s.hasNext() ? s.next() : ""; - query.put(p.getName(), Sets.newHashSet(value)); + params.put(p.getName(), value); } public void buildFilePart(Part part) throws IOException { @@ -81,7 +94,7 @@ public void assertBody(String content){ } private void writeQuery(Request req) { - req.queryParams().forEach(q -> query.computeIfAbsent(q, (w) -> Sets.newHashSet(req.queryMap(q).values()))); + req.queryParams().forEach(q -> params.putAll(q, Sets.newHashSet(req.queryMap(q).values()))); } private void writeHeaders(Request req) { @@ -92,8 +105,8 @@ public void assertHeader(String key, String value) { assertEquals("Expected Header Failed", value, headers.get(key)); } - public void assertQuery(String key, String value) { - assertThat("Expected Query or Form value", query.getOrDefault(key, Collections.emptySet()), hasItem(value)); + public void assertParam(String key, String value) { + assertThat("Expected Query or Form value", params.get(key), hasItem(value)); } public File getFile(String fileName) { diff --git a/src/test/java/io/github/openunirest/http/TestUtils.java b/src/test/java/io/github/openunirest/http/TestUtils.java index 52d860bc2..2a52a9726 100644 --- a/src/test/java/io/github/openunirest/http/TestUtils.java +++ b/src/test/java/io/github/openunirest/http/TestUtils.java @@ -3,7 +3,8 @@ import java.io.IOException; public class TestUtils { - private static final com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper(); + private static final JacksonObjectMapper om = new JacksonObjectMapper(); + public static void debugApache() { System.setProperty("org.apache.commons.logging.Log","org.apache.commons.logging.impl.SimpleLog"); @@ -12,18 +13,10 @@ public static void debugApache() { } public static T read(String o, Class as){ - try { - return om.readValue(o, as); - } catch (IOException e) { - throw new RuntimeException(e); - } + return om.readValue(o, as); } public static T read(HttpResponse r, Class as) { - try { - return om.readValue(r.getRawBody(), as); - } catch (IOException e) { - throw new RuntimeException(e); - } + return om.readValue(r.getRawBody(), as); } } diff --git a/src/test/java/io/github/openunirest/http/UnirestTest.java b/src/test/java/io/github/openunirest/http/UnirestTest.java index ef86b9ca8..80d645877 100644 --- a/src/test/java/io/github/openunirest/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/http/UnirestTest.java @@ -86,8 +86,8 @@ public void postFormReturnJson() throws JSONException, UnirestException { RequestCapture json = parse(jsonResponse); json.assertHeader("Accept", "application/json"); - json.assertQuery("param1", "value1"); - json.assertQuery("param2", "bye"); + json.assertParam("param1", "value1"); + json.assertParam("param2", "bye"); } @Test @@ -97,7 +97,7 @@ public void canPassQueryParamsOnStringOrWithForm() throws JSONException, Unirest .asJson(); RequestCapture json = parse(response); - json.assertQuery("name", "mark"); + json.assertParam("name", "mark"); response = Unirest.get(MockServer.GETJSON) .header("accept", "application/json") @@ -105,7 +105,7 @@ public void canPassQueryParamsOnStringOrWithForm() throws JSONException, Unirest .asJson(); json = parse(response); - json.assertQuery("name", "mark2"); + json.assertParam("name", "mark2"); } @Test @@ -117,9 +117,9 @@ public void multipleParams() throws JSONException, UnirestException { .asJson(); RequestCapture json = parse(response); - json.assertQuery("name", "ringo"); - json.assertQuery("name", "paul"); - json.assertQuery("name", "john"); + json.assertParam("name", "ringo"); + json.assertParam("name", "paul"); + json.assertParam("name", "john"); } @Test @@ -130,7 +130,7 @@ public void testGetUTF8() { .asJson(); RequestCapture json = parse(response); - json.assertQuery("param3", "こんにちは"); + json.assertParam("param3", "こんにちは"); } @Test @@ -141,7 +141,7 @@ public void testPostUTF8() { .asJson(); RequestCapture json = parse(response); - json.assertQuery("param3", "こんにちは"); + json.assertParam("param3", "こんにちは"); } @Test @@ -153,7 +153,7 @@ public void testPostBinaryUTF8() throws URISyntaxException { .asJson(); RequestCapture json = parse(response); - json.assertQuery("param3", "こんにちは"); + json.assertParam("param3", "こんにちは"); json.getFile("test").assertBody("This is a test file"); } @@ -184,7 +184,7 @@ public void testCustomUserAgent() throws JSONException, UnirestException { public void testGetMultiple() throws JSONException, UnirestException { for (int i = 1; i <= 20; i++) { HttpResponse response = Unirest.get(MockServer.GETJSON + "?try=" + i).asJson(); - parse(response).assertQuery("try", String.valueOf(i)); + parse(response).assertParam("try", String.valueOf(i)); } } @@ -196,8 +196,8 @@ public void testGetFields() throws JSONException, UnirestException { .asJson(); RequestCapture parse = parse(response); - parse.assertQuery("name", "mark"); - parse.assertQuery("nick", "thefosk"); + parse.assertParam("name", "mark"); + parse.assertParam("nick", "thefosk"); } @Test @@ -206,7 +206,7 @@ public void testGetFields2() throws JSONException, UnirestException { .queryString("email", "hello@hello.com") .asJson(); - parse(response).assertQuery("email", "hello@hello.com"); + parse(response).assertParam("email", "hello@hello.com"); } @Test @@ -218,75 +218,75 @@ public void testQueryStringEncoding() throws JSONException, UnirestException { .queryString(testKey, testValue) .asJson(); - parse(response).assertQuery(testKey, testValue); + parse(response).assertParam(testKey, testValue); } @Test public void testDelete() throws JSONException, UnirestException { - HttpResponse response = Unirest.delete("http://httpbin.org/delete").asJson(); + HttpResponse response = Unirest.delete(MockServer.DELETE).asJson(); assertEquals(200, response.getStatus()); - response = Unirest.delete("http://httpbin.org/delete").field("name", "mark").asJson(); - assertEquals("mark", response.getBody().getObject().getJSONObject("form").getString("name")); + response = Unirest.delete(MockServer.DELETE) + .field("name", "mark") + .field("foo","bar") + .asJson(); + + RequestCapture parse = parse(response); + parse.assertParam("name", "mark"); + parse.assertParam("foo", "bar"); } @Test public void testDeleteBody() throws JSONException, UnirestException { String body = "{\"jsonString\":{\"members\":\"members1\"}}"; - HttpResponse response = Unirest.delete("http://httpbin.org/delete").body(body).asJson(); + HttpResponse response = Unirest.delete(MockServer.DELETE) + .body(body) + .asJson(); + assertEquals(200, response.getStatus()); - assertEquals(body, response.getBody().getObject().getString("data")); + parse(response).asserBody(body); } @Test public void testBasicAuth() throws JSONException, UnirestException { - HttpResponse response = Unirest.get("http://httpbin.org/headers").basicAuth("user", "test").asJson(); - assertEquals("Basic dXNlcjp0ZXN0", response.getBody().getObject().getJSONObject("headers").getString("Authorization")); + HttpResponse response = Unirest.get(MockServer.GETJSON) + .basicAuth("user", "test") + .asJson(); + + parse(response).assertHeader("Authorization", "Basic dXNlcjp0ZXN0"); } @Test public void testAsync() throws JSONException, InterruptedException, ExecutionException { - Future> future = Unirest.post("http://httpbin.org/post").header("accept", "application/json").field("param1", "value1").field("param2", "bye").asJsonAsync(); + Future> future = Unirest.post(MockServer.POST) + .header("accept", "application/json") + .field("param1", "value1") + .field("param2", "bye") + .asJsonAsync(); assertNotNull(future); - HttpResponse jsonResponse = future.get(); - - assertTrue(jsonResponse.getHeaders().size() > 0); - assertTrue(jsonResponse.getBody().toString().length() > 0); - assertFalse(jsonResponse.getRawBody() == null); - assertEquals(200, jsonResponse.getStatus()); - JsonNode json = jsonResponse.getBody(); - assertFalse(json.isArray()); - assertNotNull(json.getObject()); - assertNotNull(json.getArray()); - assertEquals(1, json.getArray().length()); - assertNotNull(json.getArray().get(0)); + RequestCapture req = parse(future.get()); + req.assertParam("param1", "value1"); + req.assertParam("param2", "bye"); } @Test public void testAsyncCallback() throws JSONException, InterruptedException { - Unirest.post("http://httpbin.org/post").header("accept", "application/json").field("param1", "value1").field("param2", "bye").asJsonAsync(new Callback() { + Unirest.post(MockServer.POST) + .header("accept", "application/json") + .field("param1", "value1") + .field("param2", "bye") + .asJsonAsync(new Callback() { public void failed(UnirestException e) { fail(); } public void completed(HttpResponse jsonResponse) { - assertTrue(jsonResponse.getHeaders().size() > 0); - assertTrue(jsonResponse.getBody().toString().length() > 0); - assertFalse(jsonResponse.getRawBody() == null); - assertEquals(200, jsonResponse.getStatus()); - - JsonNode json = jsonResponse.getBody(); - assertFalse(json.isArray()); - assertNotNull(json.getObject()); - assertNotNull(json.getArray()); - assertEquals(1, json.getArray().length()); - assertNotNull(json.getArray().get(0)); - - assertEquals("value1", json.getObject().getJSONObject("form").getString("param1")); - assertEquals("bye", json.getObject().getJSONObject("form").getString("param2")); + RequestCapture req = parse(jsonResponse); + req.assertParam("param1", "value1"); + req.assertParam("param2", "bye"); status = true; lock.countDown(); @@ -303,7 +303,11 @@ public void cancelled() { @Test public void testMultipart() throws JSONException, URISyntaxException, UnirestException { - HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post").field("name", "Mark").field("file", new File(getClass().getResource("/test").toURI())).asJson(); + HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") + .field("name", "Mark") + .field("file", new File(getClass().getResource("/test").toURI())) + .asJson(); + assertTrue(jsonResponse.getHeaders().size() > 0); assertTrue(jsonResponse.getBody().toString().length() > 0); assertFalse(jsonResponse.getRawBody() == null); @@ -357,7 +361,7 @@ public void testMultipartInputStreamContentType() throws JSONException, URISynta RequestCapture json = parse(jsonResponse); json.assertHeader("Accept", ContentType.MULTIPART_FORM_DATA.toString()); - json.assertQuery("name", "Mark"); + json.assertParam("name", "Mark"); assertEquals("application/octet-stream", json.getFile("image.jpg").type); } From cdfc18519b52733d905940371253fc57ebef253f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 11 Mar 2018 15:17:27 -0500 Subject: [PATCH 0034/1769] moar tests --- .../github/openunirest/http/MockServer.java | 35 +- .../openunirest/http/RequestCapture.java | 42 +- .../github/openunirest/http/UnirestTest.java | 1513 ++++++++--------- 3 files changed, 780 insertions(+), 810 deletions(-) diff --git a/src/test/java/io/github/openunirest/http/MockServer.java b/src/test/java/io/github/openunirest/http/MockServer.java index b1580f5dd..f40437059 100644 --- a/src/test/java/io/github/openunirest/http/MockServer.java +++ b/src/test/java/io/github/openunirest/http/MockServer.java @@ -37,12 +37,14 @@ a copy of this software and associated documentation files (the public class MockServer { private static final JacksonObjectMapper om = new JacksonObjectMapper(); - private static Object responseBody; - public static final int PORT = 4567; - public static final String HOST = "http://localhost:" + PORT; - public static final String POST = HOST + "/post"; - public static final String GETJSON = HOST + "/get"; - public static final String DELETE = HOST + "/delete"; + private static Object responseBody; + public static final int PORT = 4567; + public static final String HOST = "http://localhost:" + PORT; + public static final String POST = HOST + "/post"; + public static final String GET = HOST + "/get"; + public static final String DELETE = HOST + "/delete"; + public static final String GZIP = HOST + "/gzip"; + public static final String PATCH = HOST + "/patch"; public static void setJsonAsResponse(Object o){ @@ -56,12 +58,18 @@ public static void reset(){ public static void start() { port(PORT); delete("/delete", MockServer::jsonResponse); - post("/post", ContentType.APPLICATION_JSON.getMimeType(), MockServer::jsonResponse); - post("/post", ContentType.MULTIPART_FORM_DATA.getMimeType(), multipost); - get("/get", ContentType.APPLICATION_JSON.getMimeType(), MockServer::jsonResponse); + post("/post", MockServer::jsonResponse); + get("/get", MockServer::jsonResponse); + get("/gzip", MockServer::gzipResponse); + patch("/patch", MockServer::jsonResponse); } - private static Object jsonResponse(Request req, Response res) { + private static Object gzipResponse(Request request, Response response) { + response.header("Content-Encoding", "gzip"); + return jsonResponse(request, response); + } + + private static Object jsonResponse(Request req, Response res) { if(responseBody != null){ return responseBody; } @@ -70,13 +78,6 @@ private static Object jsonResponse(Request req, Response res) { return om.writeValue(value); } - - private static Route multipost = (req, res) -> { - RequestCapture body = new RequestCapture(req); - body.writeMultipart(req); - return om.writeValue(body); - }; - public static void shutdown() { Spark.stop(); } diff --git a/src/test/java/io/github/openunirest/http/RequestCapture.java b/src/test/java/io/github/openunirest/http/RequestCapture.java index 0bed3cec8..2be607244 100644 --- a/src/test/java/io/github/openunirest/http/RequestCapture.java +++ b/src/test/java/io/github/openunirest/http/RequestCapture.java @@ -1,14 +1,15 @@ package io.github.openunirest.http; +import com.google.common.base.Strings; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; -import com.google.common.collect.Multimaps; import com.google.common.collect.Sets; import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.entity.ContentType; import spark.Request; import javax.servlet.MultipartConfigElement; +import javax.servlet.ServletException; import javax.servlet.http.Part; import java.io.IOException; import java.nio.charset.Charset; @@ -16,8 +17,7 @@ import static java.lang.System.getProperty; import static org.hamcrest.CoreMatchers.hasItem; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.*; public class RequestCapture { public Map headers = new LinkedHashMap<>(); @@ -34,12 +34,12 @@ public RequestCapture(Request req) { } public void writeBody(Request req) { - this.body = req.body(); - parseBodyToFormParams(req); + //parseBodyToFormParams(req); + writeMultipart(req); } - private void parseBodyToFormParams(Request req) { - URLEncodedUtils.parse(req.body() , Charset.forName("UTF-8")) + private void parseBodyToFormParams() { + URLEncodedUtils.parse(this.body , Charset.forName("UTF-8")) .forEach(p -> { params.put(p.getName(), p.getValue()); }); @@ -50,13 +50,17 @@ public void writeMultipart(Request req) { try { for (Part p : req.raw().getParts()) { - if (p.getContentType().equals(ContentType.APPLICATION_OCTET_STREAM.getMimeType())) { + if (!Strings.isNullOrEmpty(p.getSubmittedFileName())) { buildFilePart(p); } else { buildFormPart(p); } } + } catch (ServletException e){ + this.body = req.body(); + parseBodyToFormParams(); } catch (Exception e) { + e.printStackTrace(); throw new RuntimeException(e); } } @@ -72,6 +76,7 @@ public void buildFilePart(Part part) throws IOException { file.fileName = part.getSubmittedFileName(); file.type = part.getContentType(); file.inputName = part.getName(); + file.fileType = part.getContentType(); file.body = TestUtil.toString(part.getInputStream()); files.put(file.fileName, file); @@ -81,35 +86,48 @@ public void asserBody(String s) { assertEquals(s, body); } + public void assertNoHeader(String s) { + assertFalse("Should Have No Header " + s, headers.containsKey(s)); + } + public static class File { public String fileName; public String type; public String inputName; public String body; + public String fileType; public void assertBody(String content){ assertEquals(content, body); } + + public void assertFileType(String type){ + assertEquals(type, this.fileType); + } } private void writeQuery(Request req) { req.queryParams().forEach(q -> params.putAll(q, Sets.newHashSet(req.queryMap(q).values()))); } - private void writeHeaders(Request req) { + private RequestCapture writeHeaders(Request req) { req.headers().forEach(h -> headers.put(h, req.headers(h))); + return this; } - public void assertHeader(String key, String value) { + public RequestCapture assertHeader(String key, String value) { assertEquals("Expected Header Failed", value, headers.get(key)); + return this; } - public void assertParam(String key, String value) { + public RequestCapture assertParam(String key, String value) { assertThat("Expected Query or Form value", params.get(key), hasItem(value)); + return this; } public File getFile(String fileName) { - return files.get(fileName); + return Optional.ofNullable(files.get(fileName)) + .orElseThrow(() -> new RuntimeException("No Such File! " + fileName)); } } diff --git a/src/test/java/io/github/openunirest/http/UnirestTest.java b/src/test/java/io/github/openunirest/http/UnirestTest.java index 80d645877..88e04dfd3 100644 --- a/src/test/java/io/github/openunirest/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/http/UnirestTest.java @@ -28,7 +28,6 @@ a copy of this software and associated documentation files (the import io.github.openunirest.http.async.Callback; import io.github.openunirest.http.options.Options; -import io.github.openunirest.request.body.MultipartBody; import io.github.openunirest.http.exceptions.UnirestException; import io.github.openunirest.request.GetRequest; import io.github.openunirest.request.HttpRequest; @@ -54,826 +53,778 @@ a copy of this software and associated documentation files (the public class UnirestTest { - private CountDownLatch lock; - private boolean status; - - @BeforeClass - public static void suiteSetUp(){ - MockServer.start(); - } - - @AfterClass - public static void suiteTearDown(){ - MockServer.shutdown(); - } - - @Before - public void setUp() { - MockServer.reset(); - lock = new CountDownLatch(1); - status = false; - } - - @Test - public void postFormReturnJson() throws JSONException, UnirestException { - HttpResponse jsonResponse = Unirest.post(MockServer.POST) - .header("accept", "application/json") - .field("param1", "value1") - .field("param2", "bye") - .asJson(); - - assertEquals(200, jsonResponse.getStatus()); - - RequestCapture json = parse(jsonResponse); - json.assertHeader("Accept", "application/json"); - json.assertParam("param1", "value1"); - json.assertParam("param2", "bye"); - } - - @Test - public void canPassQueryParamsOnStringOrWithForm() throws JSONException, UnirestException { - HttpResponse response = Unirest.get(MockServer.GETJSON + "?name=mark") - .header("accept", "application/json") - .asJson(); - - RequestCapture json = parse(response); - json.assertParam("name", "mark"); - - response = Unirest.get(MockServer.GETJSON) - .header("accept", "application/json") - .queryString("name", "mark2") - .asJson(); - - json = parse(response); - json.assertParam("name", "mark2"); - } - - @Test - public void multipleParams() throws JSONException, UnirestException { - HttpResponse response = Unirest.get(MockServer.GETJSON + "?name=ringo") - .header("accept", "application/json") - .queryString("name", "paul") - .queryString("name", "john") - .asJson(); - - RequestCapture json = parse(response); - json.assertParam("name", "ringo"); - json.assertParam("name", "paul"); - json.assertParam("name", "john"); - } - - @Test - public void testGetUTF8() { - HttpResponse response = Unirest.get(MockServer.GETJSON) - .header("accept", "application/json") - .queryString("param3", "こんにちは") - .asJson(); - - RequestCapture json = parse(response); - json.assertParam("param3", "こんにちは"); - } - - @Test - public void testPostUTF8() { - HttpResponse response = Unirest.post(MockServer.POST) - .header("accept", "application/json") - .field("param3", "こんにちは") - .asJson(); - - RequestCapture json = parse(response); - json.assertParam("param3", "こんにちは"); - } - - @Test - public void testPostBinaryUTF8() throws URISyntaxException { - HttpResponse response = Unirest.post(MockServer.POST) - .header("Accept", ContentType.MULTIPART_FORM_DATA.getMimeType()) - .field("param3", "こんにちは") - .field("file", new File(getClass().getResource("/test").toURI())) - .asJson(); - - RequestCapture json = parse(response); - json.assertParam("param3", "こんにちは"); - json.getFile("test").assertBody("This is a test file"); - } - - @Test - public void testPostRawBody() { - String sourceString = "'\"@こんにちは-test-123-" + Math.random(); - byte[] sentBytes = sourceString.getBytes(); - - HttpResponse response = Unirest.post(MockServer.POST) - .body(sentBytes) - .asJson(); - - RequestCapture json = parse(response); - json.asserBody(sourceString); - } - - @Test - public void testCustomUserAgent() throws JSONException, UnirestException { - HttpResponse response = Unirest.get(MockServer.GETJSON) + private CountDownLatch lock; + private boolean status; + + @BeforeClass + public static void suiteSetUp() { + MockServer.start(); + } + + @AfterClass + public static void suiteTearDown() { + MockServer.shutdown(); + } + + @Before + public void setUp() { + MockServer.reset(); + lock = new CountDownLatch(1); + status = false; + } + + @Test + public void postFormReturnJson() throws JSONException, UnirestException { + HttpResponse jsonResponse = Unirest.post(MockServer.POST) + .header("accept", "application/json") + .field("param1", "value1") + .field("param2", "bye") + .asJson(); + + assertEquals(200, jsonResponse.getStatus()); + + RequestCapture json = parse(jsonResponse); + json.assertHeader("Accept", "application/json"); + json.assertParam("param1", "value1"); + json.assertParam("param2", "bye"); + } + + @Test + public void canPassQueryParamsOnStringOrWithForm() throws JSONException, UnirestException { + HttpResponse response = Unirest.get(MockServer.GET + "?name=mark") + .header("accept", "application/json") + .asJson(); + + RequestCapture json = parse(response); + json.assertParam("name", "mark"); + + response = Unirest.get(MockServer.GET) + .header("accept", "application/json") + .queryString("name", "mark2") + .asJson(); + + json = parse(response); + json.assertParam("name", "mark2"); + } + + @Test + public void multipleParams() throws JSONException, UnirestException { + HttpResponse response = Unirest.get(MockServer.GET + "?name=ringo") + .header("accept", "application/json") + .queryString("name", "paul") + .queryString("name", "john") + .asJson(); + + RequestCapture json = parse(response); + json.assertParam("name", "ringo"); + json.assertParam("name", "paul"); + json.assertParam("name", "john"); + } + + @Test + public void testGetUTF8() { + HttpResponse response = Unirest.get(MockServer.GET) + .header("accept", "application/json") + .queryString("param3", "こんにちは") + .asJson(); + + RequestCapture json = parse(response); + json.assertParam("param3", "こんにちは"); + } + + @Test + public void testPostUTF8() { + HttpResponse response = Unirest.post(MockServer.POST) + .header("accept", "application/json") + .field("param3", "こんにちは") + .asJson(); + + RequestCapture json = parse(response); + json.assertParam("param3", "こんにちは"); + } + + @Test + public void testPostBinaryUTF8() throws URISyntaxException { + HttpResponse response = Unirest.post(MockServer.POST) + .header("Accept", ContentType.MULTIPART_FORM_DATA.getMimeType()) + .field("param3", "こんにちは") + .field("file", new File(getClass().getResource("/test").toURI())) + .asJson(); + + RequestCapture json = parse(response); + json.assertParam("param3", "こんにちは"); + json.getFile("test").assertBody("This is a test file"); + } + + @Test + public void testPostRawBody() { + String sourceString = "'\"@こんにちは-test-123-" + Math.random(); + byte[] sentBytes = sourceString.getBytes(); + + HttpResponse response = Unirest.post(MockServer.POST) + .body(sentBytes) + .asJson(); + + RequestCapture json = parse(response); + json.asserBody(sourceString); + } + + @Test + public void testCustomUserAgent() throws JSONException, UnirestException { + HttpResponse response = Unirest.get(MockServer.GET) .header("user-agent", "hello-world") .asJson(); RequestCapture json = parse(response); json.assertHeader("User-Agent", "hello-world"); - } + } @Test - public void testGetMultiple() throws JSONException, UnirestException { - for (int i = 1; i <= 20; i++) { - HttpResponse response = Unirest.get(MockServer.GETJSON + "?try=" + i).asJson(); + public void testGetMultiple() throws JSONException, UnirestException { + for (int i = 1; i <= 20; i++) { + HttpResponse response = Unirest.get(MockServer.GET + "?try=" + i).asJson(); parse(response).assertParam("try", String.valueOf(i)); - } - } + } + } - @Test - public void testGetFields() throws JSONException, UnirestException { - HttpResponse response = Unirest.get(MockServer.GETJSON) + @Test + public void testGetFields() throws JSONException, UnirestException { + HttpResponse response = Unirest.get(MockServer.GET) .queryString("name", "mark") .queryString("nick", "thefosk") .asJson(); RequestCapture parse = parse(response); parse.assertParam("name", "mark"); - parse.assertParam("nick", "thefosk"); - } + parse.assertParam("nick", "thefosk"); + } - @Test - public void testGetFields2() throws JSONException, UnirestException { - HttpResponse response = Unirest.get(MockServer.GETJSON) + @Test + public void testGetFields2() throws JSONException, UnirestException { + HttpResponse response = Unirest.get(MockServer.GET) .queryString("email", "hello@hello.com") .asJson(); parse(response).assertParam("email", "hello@hello.com"); - } + } - @Test - public void testQueryStringEncoding() throws JSONException, UnirestException { - String testKey = "email2=someKey&email"; - String testValue = "hello@hello.com"; + @Test + public void testQueryStringEncoding() throws JSONException, UnirestException { + String testKey = "email2=someKey&email"; + String testValue = "hello@hello.com"; - HttpResponse response = Unirest.get(MockServer.GETJSON) + HttpResponse response = Unirest.get(MockServer.GET) .queryString(testKey, testValue) .asJson(); - parse(response).assertParam(testKey, testValue); - } - - @Test - public void testDelete() throws JSONException, UnirestException { - HttpResponse response = Unirest.delete(MockServer.DELETE).asJson(); - assertEquals(200, response.getStatus()); - - response = Unirest.delete(MockServer.DELETE) - .field("name", "mark") - .field("foo","bar") - .asJson(); - - RequestCapture parse = parse(response); - parse.assertParam("name", "mark"); - parse.assertParam("foo", "bar"); - } - - @Test - public void testDeleteBody() throws JSONException, UnirestException { - String body = "{\"jsonString\":{\"members\":\"members1\"}}"; - HttpResponse response = Unirest.delete(MockServer.DELETE) - .body(body) - .asJson(); - - assertEquals(200, response.getStatus()); - parse(response).asserBody(body); - } - - @Test - public void testBasicAuth() throws JSONException, UnirestException { - HttpResponse response = Unirest.get(MockServer.GETJSON) - .basicAuth("user", "test") - .asJson(); - - parse(response).assertHeader("Authorization", "Basic dXNlcjp0ZXN0"); - } - - @Test - public void testAsync() throws JSONException, InterruptedException, ExecutionException { - Future> future = Unirest.post(MockServer.POST) - .header("accept", "application/json") - .field("param1", "value1") - .field("param2", "bye") - .asJsonAsync(); - - assertNotNull(future); - - RequestCapture req = parse(future.get()); - req.assertParam("param1", "value1"); - req.assertParam("param2", "bye"); - } - - @Test - public void testAsyncCallback() throws JSONException, InterruptedException { - Unirest.post(MockServer.POST) - .header("accept", "application/json") - .field("param1", "value1") - .field("param2", "bye") - .asJsonAsync(new Callback() { - - public void failed(UnirestException e) { - fail(); - } - - public void completed(HttpResponse jsonResponse) { - RequestCapture req = parse(jsonResponse); - req.assertParam("param1", "value1"); - req.assertParam("param2", "bye"); - - status = true; - lock.countDown(); - } - - public void cancelled() { - fail(); - } - }); - - lock.await(10, TimeUnit.SECONDS); - assertTrue(status); - } - - @Test - public void testMultipart() throws JSONException, URISyntaxException, UnirestException { - HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") - .field("name", "Mark") - .field("file", new File(getClass().getResource("/test").toURI())) - .asJson(); - - assertTrue(jsonResponse.getHeaders().size() > 0); - assertTrue(jsonResponse.getBody().toString().length() > 0); - assertFalse(jsonResponse.getRawBody() == null); - assertEquals(200, jsonResponse.getStatus()); - - JsonNode json = jsonResponse.getBody(); - assertFalse(json.isArray()); - assertNotNull(json.getObject()); - assertNotNull(json.getArray()); - assertEquals(1, json.getArray().length()); - assertNotNull(json.getArray().get(0)); - assertNotNull(json.getObject().getJSONObject("files")); - - assertEquals("This is a test file", json.getObject().getJSONObject("files").getString("file")); - assertEquals("Mark", json.getObject().getJSONObject("form").getString("name")); - } - - @Test - public void testMultipartContentType() throws JSONException, URISyntaxException, UnirestException { - HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post").field("name", "Mark").field("file", new File(getClass().getResource("/image.jpg").toURI()), "image/jpeg").asJson(); - assertTrue(jsonResponse.getHeaders().size() > 0); - assertTrue(jsonResponse.getBody().toString().length() > 0); - assertFalse(jsonResponse.getRawBody() == null); - assertEquals(200, jsonResponse.getStatus()); - - JsonNode json = jsonResponse.getBody(); - assertFalse(json.isArray()); - assertNotNull(json.getObject()); - assertNotNull(json.getArray()); - assertEquals(1, json.getArray().length()); - assertNotNull(json.getArray().get(0)); - assertNotNull(json.getObject().getJSONObject("files")); - - assertTrue(json.getObject().getJSONObject("files").getString("file").contains("data:image/jpeg")); - assertEquals("Mark", json.getObject().getJSONObject("form").getString("name")); - } - - @Test - public void testMultipartInputStreamContentType() throws JSONException, URISyntaxException, FileNotFoundException { - FileInputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())); - - MultipartBody request = Unirest.post(MockServer.HOST + "/post") - .header("accept", ContentType.MULTIPART_FORM_DATA.toString()) - .field("name", "Mark") - .field("file", stream, ContentType.APPLICATION_OCTET_STREAM, "image.jpg"); - - HttpResponse jsonResponse = request - .asJson(); - - assertEquals(200, jsonResponse.getStatus()); - - RequestCapture json = parse(jsonResponse); - json.assertHeader("Accept", ContentType.MULTIPART_FORM_DATA.toString()); - json.assertParam("name", "Mark"); - assertEquals("application/octet-stream", json.getFile("image.jpg").type); - } - - @Test - public void testMultipartInputStreamContentTypeAsync() throws JSONException, InterruptedException, URISyntaxException, FileNotFoundException { - Unirest.post("http://httpbin.org/post").field("name", "Mark").field("file", new FileInputStream(new File(getClass().getResource("/test").toURI())), ContentType.APPLICATION_OCTET_STREAM, "test").asJsonAsync(new Callback() { - - public void failed(UnirestException e) { - fail(); - } - - public void completed(HttpResponse response) { - assertTrue(response.getHeaders().size() > 0); - assertTrue(response.getBody().toString().length() > 0); - assertFalse(response.getRawBody() == null); - assertEquals(200, response.getStatus()); - - JsonNode json = response.getBody(); - assertFalse(json.isArray()); - assertNotNull(json.getObject()); - assertNotNull(json.getArray()); - assertEquals(1, json.getArray().length()); - assertNotNull(json.getArray().get(0)); - - assertEquals("This is a test file", json.getObject().getJSONObject("files").getString("file")); - assertEquals("Mark", json.getObject().getJSONObject("form").getString("name")); - - status = true; - lock.countDown(); - } - - public void cancelled() { - fail(); - } - - }); - - lock.await(10, TimeUnit.SECONDS); - assertTrue(status); - } - - @Test - public void testMultipartByteContentType() throws JSONException, InterruptedException, ExecutionException, URISyntaxException, IOException { - final InputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())); - final byte[] bytes = new byte[stream.available()]; - stream.read(bytes); - stream.close(); - HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post").field("name", "Mark").field("file", bytes, "image.jpg").asJson(); - assertTrue(jsonResponse.getHeaders().size() > 0); - assertTrue(jsonResponse.getBody().toString().length() > 0); - assertFalse(jsonResponse.getRawBody() == null); - assertEquals(200, jsonResponse.getStatus()); - - JsonNode json = jsonResponse.getBody(); - assertFalse(json.isArray()); - assertNotNull(json.getObject()); - assertNotNull(json.getArray()); - assertEquals(1, json.getArray().length()); - assertNotNull(json.getArray().get(0)); - assertNotNull(json.getObject().getJSONObject("files")); - - assertTrue(json.getObject().getJSONObject("files").getString("file").contains("data:application/octet-stream")); - assertEquals("Mark", json.getObject().getJSONObject("form").getString("name")); - } - - @Test - public void testMultipartByteContentTypeAsync() throws JSONException, InterruptedException, ExecutionException, URISyntaxException, IOException { - final InputStream stream = new FileInputStream(new File(getClass().getResource("/test").toURI())); - final byte[] bytes = new byte[stream.available()]; - stream.read(bytes); - stream.close(); - Unirest.post("http://httpbin.org/post").field("name", "Mark").field("file", bytes, "test").asJsonAsync(new Callback() { - - public void failed(UnirestException e) { - fail(); - } - - public void completed(HttpResponse response) { - assertTrue(response.getHeaders().size() > 0); - assertTrue(response.getBody().toString().length() > 0); - assertFalse(response.getRawBody() == null); - assertEquals(200, response.getStatus()); - - JsonNode json = response.getBody(); - assertFalse(json.isArray()); - assertNotNull(json.getObject()); - assertNotNull(json.getArray()); - assertEquals(1, json.getArray().length()); - assertNotNull(json.getArray().get(0)); - - assertEquals("This is a test file", json.getObject().getJSONObject("files").getString("file")); - assertEquals("Mark", json.getObject().getJSONObject("form").getString("name")); - - status = true; - lock.countDown(); - } - - public void cancelled() { - fail(); - } - - }); - - lock.await(10, TimeUnit.SECONDS); - assertTrue(status); - } - - @Test - public void testMultipartAsync() throws JSONException, InterruptedException, ExecutionException, URISyntaxException, UnirestException { - Unirest.post("http://httpbin.org/post").field("name", "Mark").field("file", new File(getClass().getResource("/test").toURI())).asJsonAsync(new Callback() { - - public void failed(UnirestException e) { - fail(); - } - - public void completed(HttpResponse response) { - assertTrue(response.getHeaders().size() > 0); - assertTrue(response.getBody().toString().length() > 0); - assertFalse(response.getRawBody() == null); - assertEquals(200, response.getStatus()); - - JsonNode json = response.getBody(); - assertFalse(json.isArray()); - assertNotNull(json.getObject()); - assertNotNull(json.getArray()); - assertEquals(1, json.getArray().length()); - assertNotNull(json.getArray().get(0)); - - assertEquals("This is a test file", json.getObject().getJSONObject("files").getString("file")); - assertEquals("Mark", json.getObject().getJSONObject("form").getString("name")); - - status = true; - lock.countDown(); - } - - public void cancelled() { - fail(); - } - - }); - - lock.await(10, TimeUnit.SECONDS); - assertTrue(status); - } - - @Test - public void testGzip() throws JSONException { - HttpResponse jsonResponse = Unirest.get("http://httpbin.org/gzip").asJson(); - assertTrue(jsonResponse.getHeaders().size() > 0); - assertTrue(jsonResponse.getBody().toString().length() > 0); - assertFalse(jsonResponse.getRawBody() == null); - assertEquals(200, jsonResponse.getStatus()); - - JsonNode json = jsonResponse.getBody(); - assertFalse(json.isArray()); - assertTrue(json.getObject().getBoolean("gzipped")); - } - - @Test - public void testGzipAsync() throws JSONException, InterruptedException, ExecutionException { - HttpResponse jsonResponse = Unirest.get("http://httpbin.org/gzip").asJsonAsync().get(); - assertTrue(jsonResponse.getHeaders().size() > 0); - assertTrue(jsonResponse.getBody().toString().length() > 0); - assertFalse(jsonResponse.getRawBody() == null); - assertEquals(200, jsonResponse.getStatus()); - - JsonNode json = jsonResponse.getBody(); - assertFalse(json.isArray()); - assertTrue(json.getObject().getBoolean("gzipped")); - } - - @Test - public void testDefaultHeaders() throws JSONException { - Unirest.setDefaultHeader("X-Custom-Header", "hello"); - Unirest.setDefaultHeader("user-agent", "foobar"); - - HttpResponse jsonResponse = Unirest.get("http://httpbin.org/headers").asJson(); - assertTrue(jsonResponse.getHeaders().size() > 0); - assertTrue(jsonResponse.getBody().toString().length() > 0); - assertFalse(jsonResponse.getRawBody() == null); - assertEquals(200, jsonResponse.getStatus()); - - JsonNode json = jsonResponse.getBody(); - assertFalse(json.isArray()); - assertTrue(jsonResponse.getBody().getObject().getJSONObject("headers").has("X-Custom-Header")); - assertEquals("hello", json.getObject().getJSONObject("headers").getString("X-Custom-Header")); - assertTrue(jsonResponse.getBody().getObject().getJSONObject("headers").has("User-Agent")); - assertEquals("foobar", json.getObject().getJSONObject("headers").getString("User-Agent")); - - jsonResponse = Unirest.get("http://httpbin.org/headers").asJson(); - assertTrue(jsonResponse.getBody().getObject().getJSONObject("headers").has("X-Custom-Header")); - assertEquals("hello", jsonResponse.getBody().getObject().getJSONObject("headers").getString("X-Custom-Header")); - - Unirest.clearDefaultHeaders(); - - jsonResponse = Unirest.get("http://httpbin.org/headers").asJson(); - assertFalse(jsonResponse.getBody().getObject().getJSONObject("headers").has("X-Custom-Header")); - } - - @Test - public void testSetTimeouts() throws IOException { - String address = "http://" + findAvailableIpAddress() + "/"; - long start = System.currentTimeMillis(); - try { - Unirest.get("http://" + address + "/").asString(); - } catch (Exception e) { - if (System.currentTimeMillis() - start > Options.CONNECTION_TIMEOUT + 100) { // Add 100ms for code execution - fail(); - } - } - Unirest.setTimeouts(2000, 10000); - start = System.currentTimeMillis(); - try { - Unirest.get("http://" + address + "/").asString(); - } catch (Exception e) { - if (System.currentTimeMillis() - start > 2100) { // Add 100ms for code execution - fail(); - } - } - } - - @Test - public void testPathParameters() { - HttpResponse jsonResponse = Unirest.get("http://httpbin.org/{method}").routeParam("method", "get").queryString("name", "Mark").asJson(); - - assertEquals(200, jsonResponse.getStatus()); - assertEquals(jsonResponse.getBody().getObject().getJSONObject("args").getString("name"), "Mark"); - } - - @Test - public void testQueryAndBodyParameters() { - HttpResponse jsonResponse = Unirest.post("http://httpbin.org/{method}").routeParam("method", "post").queryString("name", "Mark").field("wot", "wat").asJson(); - - assertEquals(200, jsonResponse.getStatus()); - assertEquals(jsonResponse.getBody().getObject().getJSONObject("args").getString("name"), "Mark"); - assertEquals(jsonResponse.getBody().getObject().getJSONObject("form").getString("wot"), "wat"); - } - - @Test - public void testPathParameters2() { - HttpResponse jsonResponse = Unirest.patch("http://httpbin.org/{method}").routeParam("method", "patch").field("name", "Mark").asJson(); - - assertEquals(200, jsonResponse.getStatus()); - assertEquals("OK", jsonResponse.getStatusText()); - assertEquals(jsonResponse.getBody().getObject().getJSONObject("form").getString("name"), "Mark"); - } - - @Test - public void testMissingPathParameter() { - try { - Unirest.get("http://httpbin.org/{method}").routeParam("method222", "get").queryString("name", "Mark").asJson(); - fail(); - } catch (RuntimeException e) { - // OK - } - } - - @Test - public void parallelTest() throws InterruptedException { - Unirest.setConcurrency(10, 5); - - long start = System.currentTimeMillis(); - makeParallelRequests(); - long smallerConcurrencyTime = (System.currentTimeMillis() - start); - - Unirest.setConcurrency(200, 20); - start = System.currentTimeMillis(); - makeParallelRequests(); - long higherConcurrencyTime = (System.currentTimeMillis() - start); - - assertTrue(higherConcurrencyTime < smallerConcurrencyTime); - } - - private void makeParallelRequests() throws InterruptedException { - ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(10); - final AtomicInteger counter = new AtomicInteger(0); - for (int i = 0; i < 200; i++) { - newFixedThreadPool.execute(() -> { + parse(response).assertParam(testKey, testValue); + } + + @Test + public void testDelete() throws JSONException, UnirestException { + HttpResponse response = Unirest.delete(MockServer.DELETE).asJson(); + assertEquals(200, response.getStatus()); + + response = Unirest.delete(MockServer.DELETE) + .field("name", "mark") + .field("foo", "bar") + .asJson(); + + RequestCapture parse = parse(response); + parse.assertParam("name", "mark"); + parse.assertParam("foo", "bar"); + } + + @Test + public void testDeleteBody() throws JSONException, UnirestException { + String body = "{\"jsonString\":{\"members\":\"members1\"}}"; + HttpResponse response = Unirest.delete(MockServer.DELETE) + .body(body) + .asJson(); + + assertEquals(200, response.getStatus()); + parse(response).asserBody(body); + } + + @Test + public void testBasicAuth() throws JSONException, UnirestException { + HttpResponse response = Unirest.get(MockServer.GET) + .basicAuth("user", "test") + .asJson(); + + parse(response).assertHeader("Authorization", "Basic dXNlcjp0ZXN0"); + } + + @Test + public void testAsync() throws JSONException, InterruptedException, ExecutionException { + Future> future = Unirest.post(MockServer.POST) + .header("accept", "application/json") + .field("param1", "value1") + .field("param2", "bye") + .asJsonAsync(); + + assertNotNull(future); + + RequestCapture req = parse(future.get()); + req.assertParam("param1", "value1"); + req.assertParam("param2", "bye"); + } + + @Test + public void testAsyncCallback() throws JSONException, InterruptedException { + Unirest.post(MockServer.POST) + .header("accept", "application/json") + .field("param1", "value1") + .field("param2", "bye") + .asJsonAsync(new Callback() { + + public void failed(UnirestException e) { + fail(); + } + + public void completed(HttpResponse jsonResponse) { + RequestCapture req = parse(jsonResponse); + req.assertParam("param1", "value1"); + req.assertParam("param2", "bye"); + + status = true; + lock.countDown(); + } + + public void cancelled() { + fail(); + } + }); + + lock.await(10, TimeUnit.SECONDS); + assertTrue(status); + } + + @Test + public void testMultipart() throws JSONException, URISyntaxException, UnirestException { + HttpResponse jsonResponse = Unirest.post(MockServer.POST) + .field("name", "Mark") + .field("file", new File(getClass().getResource("/test").toURI())) + .asJson(); + + RequestCapture res = parse(jsonResponse); + res.getFile("test").assertBody("This is a test file"); + res.getFile("test").assertFileType("application/octet-stream"); + + res.assertParam("name", "Mark"); + } + + @Test + public void testMultipartContentType() throws JSONException, URISyntaxException, UnirestException { + HttpResponse jsonResponse = Unirest.post(MockServer.POST) + .field("name", "Mark") + .field("file", new File(getClass().getResource("/image.jpg").toURI()), "image/jpeg") + .asJson(); + + RequestCapture res = parse(jsonResponse); + res.getFile("image.jpg").assertFileType("image/jpeg"); + res.assertParam("name", "Mark"); + } + + @Test + public void testMultipartInputStreamContentType() throws JSONException, URISyntaxException, FileNotFoundException { + FileInputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())); + + HttpResponse request = Unirest.post(MockServer.POST) + .header("accept", ContentType.MULTIPART_FORM_DATA.toString()) + .field("name", "Mark") + .field("file", stream, ContentType.APPLICATION_OCTET_STREAM, "image.jpg") + .asJson(); + + assertEquals(200, request.getStatus()); + + RequestCapture json = parse(request); + json.assertHeader("Accept", ContentType.MULTIPART_FORM_DATA.toString()); + json.assertParam("name", "Mark"); + json.getFile("image.jpg").assertFileType("application/octet-stream"); + } + + @Test + public void testMultipartInputStreamContentTypeAsync() throws JSONException, InterruptedException, URISyntaxException, FileNotFoundException { + Unirest.post(MockServer.POST) + .field("name", "Mark") + .field("file", new FileInputStream(new File(getClass().getResource("/test").toURI())), ContentType.APPLICATION_OCTET_STREAM, "test") + .asJsonAsync(new Callback() { + + public void failed(UnirestException e) { + fail(); + } + + public void completed(HttpResponse response) { + RequestCapture json = parse(response); + json.assertParam("name", "Mark"); + json.getFile("test").assertFileType("application/octet-stream"); + + status = true; + lock.countDown(); + } + + public void cancelled() { + fail(); + } + }); + + lock.await(10, TimeUnit.SECONDS); + assertTrue(status); + } + + @Test + public void testMultipartByteContentType() throws JSONException, URISyntaxException, IOException { + final InputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())); + final byte[] bytes = new byte[stream.available()]; + stream.read(bytes); + stream.close(); + + HttpResponse jsonResponse = Unirest.post(MockServer.POST) + .field("name", "Mark") + .field("file", bytes, "image.jpg") + .asJson(); + + RequestCapture parse = parse(jsonResponse); + parse.getFile("image.jpg").assertFileType("application/octet-stream"); + parse.assertParam("name", "Mark"); + } + + @Test + public void testMultipartByteContentTypeAsync() throws JSONException, InterruptedException, ExecutionException, URISyntaxException, IOException { + final InputStream stream = new FileInputStream(new File(getClass().getResource("/test").toURI())); + final byte[] bytes = new byte[stream.available()]; + stream.read(bytes); + stream.close(); + + Unirest.post(MockServer.POST) + .field("name", "Mark") + .field("file", bytes, "test") + .asJsonAsync(new Callback() { + + public void failed(UnirestException e) { + fail(); + } + + public void completed(HttpResponse response) { + RequestCapture parse = parse(response); + parse.getFile("test").assertFileType("application/octet-stream"); + parse.assertParam("name", "Mark"); + + status = true; + lock.countDown(); + } + + public void cancelled() { + fail(); + } + + }); + + lock.await(10, TimeUnit.SECONDS); + assertTrue(status); + } + + @Test + public void testMultipartAsync() throws JSONException, InterruptedException, ExecutionException, URISyntaxException, UnirestException { + Unirest.post(MockServer.POST) + .field("name", "Mark") + .field("file", new File(getClass().getResource("/test").toURI())) + .asJsonAsync(new Callback() { + + public void failed(UnirestException e) { + fail(); + } + + public void completed(HttpResponse response) { + RequestCapture parse = parse(response); + parse.getFile("test").assertFileType("application/octet-stream"); + parse.getFile("test").assertBody("This is a test file"); + parse.assertParam("name", "Mark"); + + status = true; + lock.countDown(); + } + + public void cancelled() { + fail(); + } + + }); + + lock.await(10, TimeUnit.SECONDS); + assertTrue(status); + } + + @Test + public void testGzip() throws JSONException { + HttpResponse jsonResponse = Unirest.get(MockServer.GZIP) + .queryString("zipme", "up") + .asJson(); + + parse(jsonResponse).assertParam("zipme", "up"); + } + + @Test + public void testGzipAsync() throws JSONException, InterruptedException, ExecutionException { + HttpResponse jsonResponse = Unirest.get(MockServer.GZIP) + .queryString("zipme", "up") + .asJsonAsync() + .get(); + + parse(jsonResponse).assertParam("zipme", "up"); + } + + @Test + public void testDefaultHeaders() throws JSONException { + Unirest.setDefaultHeader("X-Custom-Header", "hello"); + Unirest.setDefaultHeader("user-agent", "foobar"); + + HttpResponse jsonResponse = Unirest.get(MockServer.GET).asJson(); + + RequestCapture r = parse(jsonResponse); + r.assertHeader("X-Custom-Header", "hello"); + r.assertHeader("User-Agent", "foobar"); + + jsonResponse = Unirest.get(MockServer.GET).asJson(); + r = parse(jsonResponse); + r.assertHeader("X-Custom-Header", "hello"); + r.assertHeader("User-Agent", "foobar"); + + Unirest.clearDefaultHeaders(); + + jsonResponse = Unirest.get(MockServer.GET).asJson(); + r = parse(jsonResponse); + r.assertNoHeader("X-Custom-Header"); + } + + @Test + public void testSetTimeouts() throws IOException { + String address = "http://" + findAvailableIpAddress() + "/"; + long start = System.currentTimeMillis(); + try { + Unirest.get("http://" + address + "/").asString(); + } catch (Exception e) { + if (System.currentTimeMillis() - start > Options.CONNECTION_TIMEOUT + 100) { // Add 100ms for code execution + fail(); + } + } + Unirest.setTimeouts(2000, 10000); + start = System.currentTimeMillis(); + try { + Unirest.get("http://" + address + "/").asString(); + } catch (Exception e) { + if (System.currentTimeMillis() - start > 2100) { // Add 100ms for code execution + fail(); + } + } + } + + @Test + public void testPathParameters() { + HttpResponse jsonResponse = Unirest.get(MockServer.HOST + "/{method}") + .routeParam("method", "get") + .queryString("name", "Mark") + .asJson(); + + parse(jsonResponse) + .assertParam("name", "Mark"); + } + + @Test + public void testQueryAndBodyParameters() { + HttpResponse jsonResponse = Unirest.post(MockServer.HOST + "/{method}") + .routeParam("method", "post") + .queryString("name", "Mark") + .field("wot", "wat") + .asJson(); + + parse(jsonResponse) + .assertParam("name", "Mark") + .assertParam("wot", "wat"); + } + + @Test + public void testPathParameters2() { + HttpResponse jsonResponse = Unirest.patch(MockServer.HOST + "/{method}") + .routeParam("method", "patch") + .field("name", "Mark") + .asJson(); + + parse(jsonResponse) + .assertParam("name", "Mark"); + } + + @Test + public void testMissingPathParameter() { + try { + Unirest.get(MockServer.HOST + "/{method}") + .routeParam("method222", "get") + .queryString("name", "Mark") + .asJson(); + + fail(); + } catch (RuntimeException e) { + assertEquals("Can't find route parameter name \"method222\"", e.getMessage()); + } + } + + @Test + public void parallelTest() throws InterruptedException { + Unirest.setConcurrency(10, 5); + + long start = System.currentTimeMillis(); + makeParallelRequests(); + long smallerConcurrencyTime = (System.currentTimeMillis() - start); + + Unirest.setConcurrency(200, 20); + start = System.currentTimeMillis(); + makeParallelRequests(); + long higherConcurrencyTime = (System.currentTimeMillis() - start); + + assertTrue(higherConcurrencyTime < smallerConcurrencyTime); + } + + private void makeParallelRequests() throws InterruptedException { + ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(10); + final AtomicInteger counter = new AtomicInteger(0); + for (int i = 0; i < 200; i++) { + newFixedThreadPool.execute(() -> { try { Unirest.get(MockServer.HOST + "/get").queryString("index", counter.incrementAndGet()).asString(); } catch (UnirestException e) { throw new RuntimeException(e); } }); - } + } + + newFixedThreadPool.shutdown(); + newFixedThreadPool.awaitTermination(10, TimeUnit.MINUTES); + } + + @Test + public void testAsyncCustomContentType() throws InterruptedException { + Unirest.post("http://httpbin.org/post").header("accept", "application/json").header("Content-Type", "application/json").body("{\"hello\":\"world\"}").asJsonAsync(new Callback() { + + public void failed(UnirestException e) { + fail(); + } + + public void completed(HttpResponse jsonResponse) { + JsonNode json = jsonResponse.getBody(); + assertEquals("{\"hello\":\"world\"}", json.getObject().getString("data")); + assertEquals("application/json", json.getObject().getJSONObject("headers").getString("Content-Type")); + + status = true; + lock.countDown(); + } - newFixedThreadPool.shutdown(); - newFixedThreadPool.awaitTermination(10, TimeUnit.MINUTES); - } + public void cancelled() { + fail(); + } + }); - @Test - public void testAsyncCustomContentType() throws InterruptedException { - Unirest.post("http://httpbin.org/post").header("accept", "application/json").header("Content-Type", "application/json").body("{\"hello\":\"world\"}").asJsonAsync(new Callback() { + lock.await(10, TimeUnit.SECONDS); + assertTrue(status); + } + + @Test + public void testAsyncCustomContentTypeAndFormParams() throws InterruptedException { + Unirest.post("http://httpbin.org/post").header("accept", "application/json").header("Content-Type", "application/x-www-form-urlencoded").field("name", "Mark").field("hello", "world").asJsonAsync(new Callback() { - public void failed(UnirestException e) { - fail(); - } + public void failed(UnirestException e) { + fail(); + } - public void completed(HttpResponse jsonResponse) { - JsonNode json = jsonResponse.getBody(); - assertEquals("{\"hello\":\"world\"}", json.getObject().getString("data")); - assertEquals("application/json", json.getObject().getJSONObject("headers").getString("Content-Type")); + public void completed(HttpResponse jsonResponse) { + JsonNode json = jsonResponse.getBody(); + assertEquals("Mark", json.getObject().getJSONObject("form").getString("name")); + assertEquals("world", json.getObject().getJSONObject("form").getString("hello")); - status = true; - lock.countDown(); - } + assertEquals("application/x-www-form-urlencoded", json.getObject().getJSONObject("headers").getString("Content-Type")); - public void cancelled() { - fail(); - } - }); + status = true; + lock.countDown(); + } - lock.await(10, TimeUnit.SECONDS); - assertTrue(status); - } - - @Test - public void testAsyncCustomContentTypeAndFormParams() throws InterruptedException { - Unirest.post("http://httpbin.org/post").header("accept", "application/json").header("Content-Type", "application/x-www-form-urlencoded").field("name", "Mark").field("hello", "world").asJsonAsync(new Callback() { - - public void failed(UnirestException e) { - fail(); - } - - public void completed(HttpResponse jsonResponse) { - JsonNode json = jsonResponse.getBody(); - assertEquals("Mark", json.getObject().getJSONObject("form").getString("name")); - assertEquals("world", json.getObject().getJSONObject("form").getString("hello")); - - assertEquals("application/x-www-form-urlencoded", json.getObject().getJSONObject("headers").getString("Content-Type")); - - status = true; - lock.countDown(); - } - - public void cancelled() { - fail(); - } - }); - - lock.await(10, TimeUnit.SECONDS); - assertTrue(status); - } - - @Test - public void testGetQuerystringArray() throws JSONException, UnirestException { - HttpResponse response = Unirest.get("http://httpbin.org/get").queryString("name", "Mark").queryString("name", "Tom").asJson(); - - JSONArray names = response.getBody().getObject().getJSONObject("args").getJSONArray("name"); - assertEquals(2, names.length()); - - assertEquals("Mark", names.getString(0)); - assertEquals("Tom", names.getString(1)); - } - - @Test - public void testPostMultipleFiles() throws JSONException, URISyntaxException { - HttpResponse response = Unirest.post("http://httpbin.org/post").field("param3", "wot").field("file1", new File(getClass().getResource("/test").toURI())).field("file2", new File(getClass().getResource("/test").toURI())).asJson(); - - JSONObject names = response.getBody().getObject().getJSONObject("files"); - assertEquals(2, names.length()); - - assertEquals("This is a test file", names.getString("file1")); - assertEquals("This is a test file", names.getString("file2")); - - assertEquals("wot", response.getBody().getObject().getJSONObject("form").getString("param3")); - } - - @Test - public void testGetArray() throws JSONException, UnirestException { - HttpResponse response = Unirest.get("http://httpbin.org/get").queryString("name", Arrays.asList("Mark", "Tom")).asJson(); - - JSONArray names = response.getBody().getObject().getJSONObject("args").getJSONArray("name"); - assertEquals(2, names.length()); - - assertEquals("Mark", names.getString(0)); - assertEquals("Tom", names.getString(1)); - } - - @Test - public void testPostArray() throws JSONException, UnirestException { - HttpResponse response = Unirest.post("http://httpbin.org/post").field("name", "Mark").field("name", "Tom").asJson(); - - JSONArray names = response.getBody().getObject().getJSONObject("form").getJSONArray("name"); - assertEquals(2, names.length()); - - assertEquals("Mark", names.getString(0)); - assertEquals("Tom", names.getString(1)); - } - - @Test - public void testPostCollection() throws JSONException, UnirestException { - HttpResponse response = Unirest.post("http://httpbin.org/post").field("name", Arrays.asList("Mark", "Tom")).asJson(); - - JSONArray names = response.getBody().getObject().getJSONObject("form").getJSONArray("name"); - assertEquals(2, names.length()); - - assertEquals("Mark", names.getString(0)); - assertEquals("Tom", names.getString(1)); - } - - @Test - public void testCaseInsensitiveHeaders() { - GetRequest request = Unirest.get("http://httpbin.org/headers").header("Name", "Marco"); - assertEquals(1, request.getHeaders().size()); - assertEquals("Marco", request.getHeaders().get("name").get(0)); - assertEquals("Marco", request.getHeaders().get("NAme").get(0)); - assertEquals("Marco", request.getHeaders().get("Name").get(0)); - JSONObject headers = request.asJson().getBody().getObject().getJSONObject("headers"); - assertEquals("Marco", headers.getString("Name")); - - request = Unirest.get("http://httpbin.org/headers").header("Name", "Marco").header("Name", "John"); - assertEquals(1, request.getHeaders().size()); - assertEquals("Marco", request.getHeaders().get("name").get(0)); - assertEquals("John", request.getHeaders().get("name").get(1)); - assertEquals("Marco", request.getHeaders().get("NAme").get(0)); - assertEquals("John", request.getHeaders().get("NAme").get(1)); - assertEquals("Marco", request.getHeaders().get("Name").get(0)); - assertEquals("John", request.getHeaders().get("Name").get(1)); - } - - @Test - public void setTimeoutsAndCustomClient() { - try { - Unirest.setTimeouts(1000, 2000); - } catch (Exception e) { - fail(); - } - - try { - Unirest.setAsyncHttpClient(HttpAsyncClientBuilder.create().build()); - } catch (Exception e) { - fail(); - } - - try { - Unirest.setAsyncHttpClient(HttpAsyncClientBuilder.create().build()); - Unirest.setTimeouts(1000, 2000); - fail(); - } catch (Exception e) { - // Ok - } - - try { - Unirest.setHttpClient(HttpClientBuilder.create().build()); - Unirest.setTimeouts(1000, 2000); - fail(); - } catch (Exception e) { - // Ok - } - } - - @Test - public void testObjectMapperRead() { - Unirest.setObjectMapper(new JacksonObjectMapper()); - - GetResponse getResponseMock = new GetResponse(); - getResponseMock.setUrl("http://httpbin.org/get"); - - HttpResponse getResponse = Unirest.get(getResponseMock.getUrl()).asObject(GetResponse.class); - - assertEquals(200, getResponse.getStatus()); - assertEquals(getResponse.getBody().getUrl(), getResponseMock.getUrl()); - } - - @Test - public void testObjectMapperWrite() { - Unirest.setObjectMapper(new JacksonObjectMapper()); - - GetResponse postResponseMock = new GetResponse(); - postResponseMock.setUrl("http://httpbin.org/post"); - - HttpResponse postResponse = Unirest.post(postResponseMock.getUrl()).header("accept", "application/json").header("Content-Type", "application/json").body(postResponseMock).asJson(); - - assertEquals(200, postResponse.getStatus()); - assertEquals(postResponse.getBody().getObject().getString("data"), "{\"url\":\"http://httpbin.org/post\"}"); - } - - @Test - public void testPostProvidesSortedParams() throws IOException { - // Verify that fields are encoded into the body in sorted order. - HttpRequest httpRequest = Unirest.post("test").field("z", "Z").field("y", "Y").field("x", "X").getHttpRequest(); - - InputStream content = httpRequest.getBody().getEntity().getContent(); - String body = IOUtils.toString(content, "UTF-8"); - assertEquals("x=X&y=Y&z=Z", body); - } - - @Test - public void testHeaderNamesCaseSensitive() { - // Verify that header names are the same as server (case sensitive) - final Headers headers = new Headers(); - headers.put("Content-Type", Arrays.asList("application/json")); - - assertEquals("Only header \"Content-Type\" should exist", null, headers.getFirst("cOnTeNt-TyPe")); - assertEquals("Only header \"Content-Type\" should exist", null, headers.getFirst("content-type")); - assertEquals("Only header \"Content-Type\" should exist", "application/json", headers.getFirst("Content-Type")); - } - - - private String findAvailableIpAddress() throws IOException { - for (int i = 100; i <= 255; i++) { - String ip = "192.168.1." + i; - if (!InetAddress.getByName(ip).isReachable(1000)) { - return ip; - } - } - - throw new RuntimeException("Couldn't find an available IP address in the range of 192.168.0.100-255"); - } + public void cancelled() { + fail(); + } + }); + + lock.await(10, TimeUnit.SECONDS); + assertTrue(status); + } + + @Test + public void testGetQuerystringArray() throws JSONException, UnirestException { + HttpResponse response = Unirest.get("http://httpbin.org/get").queryString("name", "Mark").queryString("name", "Tom").asJson(); + + JSONArray names = response.getBody().getObject().getJSONObject("args").getJSONArray("name"); + assertEquals(2, names.length()); + + assertEquals("Mark", names.getString(0)); + assertEquals("Tom", names.getString(1)); + } + + @Test + public void testPostMultipleFiles() throws JSONException, URISyntaxException { + HttpResponse response = Unirest.post("http://httpbin.org/post").field("param3", "wot").field("file1", new File(getClass().getResource("/test").toURI())).field("file2", new File(getClass().getResource("/test").toURI())).asJson(); + + JSONObject names = response.getBody().getObject().getJSONObject("files"); + assertEquals(2, names.length()); + + assertEquals("This is a test file", names.getString("file1")); + assertEquals("This is a test file", names.getString("file2")); + + assertEquals("wot", response.getBody().getObject().getJSONObject("form").getString("param3")); + } + + @Test + public void testGetArray() throws JSONException, UnirestException { + HttpResponse response = Unirest.get("http://httpbin.org/get").queryString("name", Arrays.asList("Mark", "Tom")).asJson(); + + JSONArray names = response.getBody().getObject().getJSONObject("args").getJSONArray("name"); + assertEquals(2, names.length()); + + assertEquals("Mark", names.getString(0)); + assertEquals("Tom", names.getString(1)); + } + + @Test + public void testPostArray() throws JSONException, UnirestException { + HttpResponse response = Unirest.post("http://httpbin.org/post").field("name", "Mark").field("name", "Tom").asJson(); + + JSONArray names = response.getBody().getObject().getJSONObject("form").getJSONArray("name"); + assertEquals(2, names.length()); + + assertEquals("Mark", names.getString(0)); + assertEquals("Tom", names.getString(1)); + } + + @Test + public void testPostCollection() throws JSONException, UnirestException { + HttpResponse response = Unirest.post("http://httpbin.org/post").field("name", Arrays.asList("Mark", "Tom")).asJson(); + + JSONArray names = response.getBody().getObject().getJSONObject("form").getJSONArray("name"); + assertEquals(2, names.length()); + + assertEquals("Mark", names.getString(0)); + assertEquals("Tom", names.getString(1)); + } + + @Test + public void testCaseInsensitiveHeaders() { + GetRequest request = Unirest.get("http://httpbin.org/headers").header("Name", "Marco"); + assertEquals(1, request.getHeaders().size()); + assertEquals("Marco", request.getHeaders().get("name").get(0)); + assertEquals("Marco", request.getHeaders().get("NAme").get(0)); + assertEquals("Marco", request.getHeaders().get("Name").get(0)); + JSONObject headers = request.asJson().getBody().getObject().getJSONObject("headers"); + assertEquals("Marco", headers.getString("Name")); + + request = Unirest.get("http://httpbin.org/headers").header("Name", "Marco").header("Name", "John"); + assertEquals(1, request.getHeaders().size()); + assertEquals("Marco", request.getHeaders().get("name").get(0)); + assertEquals("John", request.getHeaders().get("name").get(1)); + assertEquals("Marco", request.getHeaders().get("NAme").get(0)); + assertEquals("John", request.getHeaders().get("NAme").get(1)); + assertEquals("Marco", request.getHeaders().get("Name").get(0)); + assertEquals("John", request.getHeaders().get("Name").get(1)); + } + + @Test + public void setTimeoutsAndCustomClient() { + try { + Unirest.setTimeouts(1000, 2000); + } catch (Exception e) { + fail(); + } + + try { + Unirest.setAsyncHttpClient(HttpAsyncClientBuilder.create().build()); + } catch (Exception e) { + fail(); + } + + try { + Unirest.setAsyncHttpClient(HttpAsyncClientBuilder.create().build()); + Unirest.setTimeouts(1000, 2000); + fail(); + } catch (Exception e) { + // Ok + } + + try { + Unirest.setHttpClient(HttpClientBuilder.create().build()); + Unirest.setTimeouts(1000, 2000); + fail(); + } catch (Exception e) { + // Ok + } + } + + @Test + public void testObjectMapperRead() { + Unirest.setObjectMapper(new JacksonObjectMapper()); + + GetResponse getResponseMock = new GetResponse(); + getResponseMock.setUrl("http://httpbin.org/get"); + + HttpResponse getResponse = Unirest.get(getResponseMock.getUrl()).asObject(GetResponse.class); + + assertEquals(200, getResponse.getStatus()); + assertEquals(getResponse.getBody().getUrl(), getResponseMock.getUrl()); + } + + @Test + public void testObjectMapperWrite() { + Unirest.setObjectMapper(new JacksonObjectMapper()); + + GetResponse postResponseMock = new GetResponse(); + postResponseMock.setUrl("http://httpbin.org/post"); + + HttpResponse postResponse = Unirest.post(postResponseMock.getUrl()).header("accept", "application/json").header("Content-Type", "application/json").body(postResponseMock).asJson(); + + assertEquals(200, postResponse.getStatus()); + assertEquals(postResponse.getBody().getObject().getString("data"), "{\"url\":\"http://httpbin.org/post\"}"); + } + + @Test + public void testPostProvidesSortedParams() throws IOException { + // Verify that fields are encoded into the body in sorted order. + HttpRequest httpRequest = Unirest.post("test").field("z", "Z").field("y", "Y").field("x", "X").getHttpRequest(); + + InputStream content = httpRequest.getBody().getEntity().getContent(); + String body = IOUtils.toString(content, "UTF-8"); + assertEquals("x=X&y=Y&z=Z", body); + } + + @Test + public void testHeaderNamesCaseSensitive() { + // Verify that header names are the same as server (case sensitive) + final Headers headers = new Headers(); + headers.put("Content-Type", Arrays.asList("application/json")); + + assertEquals("Only header \"Content-Type\" should exist", null, headers.getFirst("cOnTeNt-TyPe")); + assertEquals("Only header \"Content-Type\" should exist", null, headers.getFirst("content-type")); + assertEquals("Only header \"Content-Type\" should exist", "application/json", headers.getFirst("Content-Type")); + } + + + private String findAvailableIpAddress() throws IOException { + for (int i = 100; i <= 255; i++) { + String ip = "192.168.1." + i; + if (!InetAddress.getByName(ip).isReachable(1000)) { + return ip; + } + } + + throw new RuntimeException("Couldn't find an available IP address in the range of 192.168.0.100-255"); + } private RequestCapture parse(HttpResponse response) { + assertEquals(200, response.getStatus()); return read(response, RequestCapture.class); } } From 4fd6f4fcc0a5ef84aa3819672428236dd8f76cc1 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 11 Mar 2018 18:56:06 -0500 Subject: [PATCH 0035/1769] yet moar test refactoring --- .../openunirest/http/RequestCapture.java | 76 ++++-- .../github/openunirest/http/UnirestTest.java | 258 ++++++++++-------- 2 files changed, 191 insertions(+), 143 deletions(-) diff --git a/src/test/java/io/github/openunirest/http/RequestCapture.java b/src/test/java/io/github/openunirest/http/RequestCapture.java index 2be607244..aefd72131 100644 --- a/src/test/java/io/github/openunirest/http/RequestCapture.java +++ b/src/test/java/io/github/openunirest/http/RequestCapture.java @@ -5,7 +5,6 @@ import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import org.apache.http.client.utils.URLEncodedUtils; -import org.apache.http.entity.ContentType; import spark.Request; import javax.servlet.MultipartConfigElement; @@ -21,14 +20,16 @@ public class RequestCapture { public Map headers = new LinkedHashMap<>(); - public Map files = new LinkedHashMap<>(); + public List files = new ArrayList<>(); public Multimap params = HashMultimap.create(); public String body; + public String url; public RequestCapture() { } public RequestCapture(Request req) { + url = req.url(); writeHeaders(req); writeQuery(req); } @@ -79,36 +80,21 @@ public void buildFilePart(Part part) throws IOException { file.fileType = part.getContentType(); file.body = TestUtil.toString(part.getInputStream()); - files.put(file.fileName, file); + files.add(file); } - public void asserBody(String s) { - assertEquals(s, body); - } - - public void assertNoHeader(String s) { - assertFalse("Should Have No Header " + s, headers.containsKey(s)); + private void writeQuery(Request req) { + req.queryParams().forEach(q -> params.putAll(q, Sets.newHashSet(req.queryMap(q).values()))); } - - public static class File { - public String fileName; - public String type; - public String inputName; - public String body; - public String fileType; - - public void assertBody(String content){ - assertEquals(content, body); - } - - public void assertFileType(String type){ - assertEquals(type, this.fileType); - } + public RequestCapture asserBody(String s) { + assertEquals(s, body); + return this; } - private void writeQuery(Request req) { - req.queryParams().forEach(q -> params.putAll(q, Sets.newHashSet(req.queryMap(q).values()))); + public RequestCapture assertNoHeader(String s) { + assertFalse("Should Have No Header " + s, headers.containsKey(s)); + return this; } private RequestCapture writeHeaders(Request req) { @@ -127,7 +113,41 @@ public RequestCapture assertParam(String key, String value) { } public File getFile(String fileName) { - return Optional.ofNullable(files.get(fileName)) - .orElseThrow(() -> new RuntimeException("No Such File! " + fileName)); + return getFileByFileName(fileName); + } + + private File getFileByFileName(String fileName) { + return files.stream() + .filter(f -> Objects.equals(f.fileName, fileName)) + .findFirst() + .orElseThrow(() -> new RuntimeException("No File With Name: " + fileName)); + } + + public RequestCapture assertFileContent(String input, String content) { + assertEquals(content, getFileByInput(input).body); + return this; + } + + private File getFileByInput(String inputName) { + return files.stream() + .filter(f -> Objects.equals(f.inputName, inputName)) + .findFirst() + .orElseThrow(() -> new RuntimeException("No File With Input Name: " + inputName)); + } + + public static class File { + public String fileName; + public String type; + public String inputName; + public String body; + public String fileType; + + public void assertBody(String content){ + assertEquals(content, body); + } + + public void assertFileType(String type){ + assertEquals(type, this.fileType); + } } } diff --git a/src/test/java/io/github/openunirest/http/UnirestTest.java b/src/test/java/io/github/openunirest/http/UnirestTest.java index 88e04dfd3..7ccd3d833 100644 --- a/src/test/java/io/github/openunirest/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/http/UnirestTest.java @@ -83,10 +83,10 @@ public void postFormReturnJson() throws JSONException, UnirestException { assertEquals(200, jsonResponse.getStatus()); - RequestCapture json = parse(jsonResponse); - json.assertHeader("Accept", "application/json"); - json.assertParam("param1", "value1"); - json.assertParam("param2", "bye"); + parse(jsonResponse) + .assertHeader("Accept", "application/json") + .assertParam("param1", "value1") + .assertParam("param2", "bye"); } @Test @@ -95,16 +95,16 @@ public void canPassQueryParamsOnStringOrWithForm() throws JSONException, Unirest .header("accept", "application/json") .asJson(); - RequestCapture json = parse(response); - json.assertParam("name", "mark"); + parse(response) + .assertParam("name", "mark"); response = Unirest.get(MockServer.GET) .header("accept", "application/json") .queryString("name", "mark2") .asJson(); - json = parse(response); - json.assertParam("name", "mark2"); + parse(response) + .assertParam("name", "mark2"); } @Test @@ -115,10 +115,10 @@ public void multipleParams() throws JSONException, UnirestException { .queryString("name", "john") .asJson(); - RequestCapture json = parse(response); - json.assertParam("name", "ringo"); - json.assertParam("name", "paul"); - json.assertParam("name", "john"); + parse(response) + .assertParam("name", "ringo") + .assertParam("name", "paul") + .assertParam("name", "john"); } @Test @@ -128,8 +128,8 @@ public void testGetUTF8() { .queryString("param3", "こんにちは") .asJson(); - RequestCapture json = parse(response); - json.assertParam("param3", "こんにちは"); + parse(response) + .assertParam("param3", "こんにちは"); } @Test @@ -139,8 +139,8 @@ public void testPostUTF8() { .field("param3", "こんにちは") .asJson(); - RequestCapture json = parse(response); - json.assertParam("param3", "こんにちは"); + parse(response) + .assertParam("param3", "こんにちは"); } @Test @@ -151,9 +151,9 @@ public void testPostBinaryUTF8() throws URISyntaxException { .field("file", new File(getClass().getResource("/test").toURI())) .asJson(); - RequestCapture json = parse(response); - json.assertParam("param3", "こんにちは"); - json.getFile("test").assertBody("This is a test file"); + parse(response) + .assertParam("param3", "こんにちは") + .assertFileContent("file", "This is a test file"); } @Test @@ -165,8 +165,8 @@ public void testPostRawBody() { .body(sentBytes) .asJson(); - RequestCapture json = parse(response); - json.asserBody(sourceString); + parse(response) + .asserBody(sourceString); } @Test @@ -338,10 +338,11 @@ public void testMultipartInputStreamContentType() throws JSONException, URISynta assertEquals(200, request.getStatus()); - RequestCapture json = parse(request); - json.assertHeader("Accept", ContentType.MULTIPART_FORM_DATA.toString()); - json.assertParam("name", "Mark"); - json.getFile("image.jpg").assertFileType("application/octet-stream"); + parse(request) + .assertHeader("Accept", ContentType.MULTIPART_FORM_DATA.toString()) + .assertParam("name", "Mark") + .getFile("image.jpg") + .assertFileType("application/octet-stream"); } @Test @@ -356,9 +357,10 @@ public void failed(UnirestException e) { } public void completed(HttpResponse response) { - RequestCapture json = parse(response); - json.assertParam("name", "Mark"); - json.getFile("test").assertFileType("application/octet-stream"); + parse(response) + .assertParam("name", "Mark") + .getFile("test") + .assertFileType("application/octet-stream"); status = true; lock.countDown(); @@ -407,9 +409,10 @@ public void failed(UnirestException e) { } public void completed(HttpResponse response) { - RequestCapture parse = parse(response); - parse.getFile("test").assertFileType("application/octet-stream"); - parse.assertParam("name", "Mark"); + parse(response) + .assertParam("name", "Mark") + .getFile("test") + .assertFileType("application/octet-stream"); status = true; lock.countDown(); @@ -438,9 +441,9 @@ public void failed(UnirestException e) { public void completed(HttpResponse response) { RequestCapture parse = parse(response); + parse.assertParam("name", "Mark"); parse.getFile("test").assertFileType("application/octet-stream"); parse.getFile("test").assertBody("This is a test file"); - parse.assertParam("name", "Mark"); status = true; lock.countDown(); @@ -482,20 +485,20 @@ public void testDefaultHeaders() throws JSONException { HttpResponse jsonResponse = Unirest.get(MockServer.GET).asJson(); - RequestCapture r = parse(jsonResponse); - r.assertHeader("X-Custom-Header", "hello"); - r.assertHeader("User-Agent", "foobar"); + parse(jsonResponse) + .assertHeader("X-Custom-Header", "hello") + .assertHeader("User-Agent", "foobar"); jsonResponse = Unirest.get(MockServer.GET).asJson(); - r = parse(jsonResponse); - r.assertHeader("X-Custom-Header", "hello"); - r.assertHeader("User-Agent", "foobar"); + parse(jsonResponse) + .assertHeader("X-Custom-Header", "hello") + .assertHeader("User-Agent", "foobar"); Unirest.clearDefaultHeaders(); jsonResponse = Unirest.get(MockServer.GET).asJson(); - r = parse(jsonResponse); - r.assertNoHeader("X-Custom-Header"); + parse(jsonResponse) + .assertNoHeader("X-Custom-Header"); } @Test @@ -570,6 +573,7 @@ public void testMissingPathParameter() { } @Test + @Ignore // this is flakey public void parallelTest() throws InterruptedException { Unirest.setConcurrency(10, 5); @@ -591,7 +595,7 @@ private void makeParallelRequests() throws InterruptedException { for (int i = 0; i < 200; i++) { newFixedThreadPool.execute(() -> { try { - Unirest.get(MockServer.HOST + "/get").queryString("index", counter.incrementAndGet()).asString(); + Unirest.get(MockServer.GET).queryString("index", counter.incrementAndGet()).asString(); } catch (UnirestException e) { throw new RuntimeException(e); } @@ -604,25 +608,29 @@ private void makeParallelRequests() throws InterruptedException { @Test public void testAsyncCustomContentType() throws InterruptedException { - Unirest.post("http://httpbin.org/post").header("accept", "application/json").header("Content-Type", "application/json").body("{\"hello\":\"world\"}").asJsonAsync(new Callback() { + Unirest.post(MockServer.POST) + .header("accept", "application/json") + .header("Content-Type", "application/json") + .body("{\"hello\":\"world\"}") + .asJsonAsync(new Callback() { - public void failed(UnirestException e) { - fail(); - } + public void failed(UnirestException e) { + fail(); + } - public void completed(HttpResponse jsonResponse) { - JsonNode json = jsonResponse.getBody(); - assertEquals("{\"hello\":\"world\"}", json.getObject().getString("data")); - assertEquals("application/json", json.getObject().getJSONObject("headers").getString("Content-Type")); + public void completed(HttpResponse jsonResponse) { + parse(jsonResponse) + .asserBody("{\"hello\":\"world\"}") + .assertHeader("Content-Type", "application/json"); - status = true; - lock.countDown(); - } + status = true; + lock.countDown(); + } - public void cancelled() { - fail(); - } - }); + public void cancelled() { + fail(); + } + }); lock.await(10, TimeUnit.SECONDS); assertTrue(status); @@ -630,27 +638,31 @@ public void cancelled() { @Test public void testAsyncCustomContentTypeAndFormParams() throws InterruptedException { - Unirest.post("http://httpbin.org/post").header("accept", "application/json").header("Content-Type", "application/x-www-form-urlencoded").field("name", "Mark").field("hello", "world").asJsonAsync(new Callback() { - - public void failed(UnirestException e) { - fail(); - } + Unirest.post(MockServer.POST) + .header("accept", "application/json") + .header("Content-Type", "application/x-www-form-urlencoded") + .field("name", "Mark") + .field("hello", "world") + .asJsonAsync(new Callback() { - public void completed(HttpResponse jsonResponse) { - JsonNode json = jsonResponse.getBody(); - assertEquals("Mark", json.getObject().getJSONObject("form").getString("name")); - assertEquals("world", json.getObject().getJSONObject("form").getString("hello")); + public void failed(UnirestException e) { + fail(); + } - assertEquals("application/x-www-form-urlencoded", json.getObject().getJSONObject("headers").getString("Content-Type")); + public void completed(HttpResponse jsonResponse) { + parse(jsonResponse) + .assertParam("name", "Mark") + .assertParam("hello", "world") + .assertHeader("Content-Type", "application/x-www-form-urlencoded"); - status = true; - lock.countDown(); - } + status = true; + lock.countDown(); + } - public void cancelled() { - fail(); - } - }); + public void cancelled() { + fail(); + } + }); lock.await(10, TimeUnit.SECONDS); assertTrue(status); @@ -658,72 +670,78 @@ public void cancelled() { @Test public void testGetQuerystringArray() throws JSONException, UnirestException { - HttpResponse response = Unirest.get("http://httpbin.org/get").queryString("name", "Mark").queryString("name", "Tom").asJson(); - - JSONArray names = response.getBody().getObject().getJSONObject("args").getJSONArray("name"); - assertEquals(2, names.length()); + HttpResponse response = Unirest.get(MockServer.GET) + .queryString("name", "Mark") + .queryString("name", "Tom") + .asJson(); - assertEquals("Mark", names.getString(0)); - assertEquals("Tom", names.getString(1)); + parse(response) + .assertParam("name", "Mark") + .assertParam("name", "Tom"); } @Test public void testPostMultipleFiles() throws JSONException, URISyntaxException { - HttpResponse response = Unirest.post("http://httpbin.org/post").field("param3", "wot").field("file1", new File(getClass().getResource("/test").toURI())).field("file2", new File(getClass().getResource("/test").toURI())).asJson(); - - JSONObject names = response.getBody().getObject().getJSONObject("files"); - assertEquals(2, names.length()); - - assertEquals("This is a test file", names.getString("file1")); - assertEquals("This is a test file", names.getString("file2")); + HttpResponse response = Unirest.post(MockServer.POST) + .field("param3", "wot") + .field("file1", new File(getClass().getResource("/test").toURI())) + .field("file2", new File(getClass().getResource("/test").toURI())) + .asJson(); - assertEquals("wot", response.getBody().getObject().getJSONObject("form").getString("param3")); + parse(response) + .assertParam("param3", "wot") + .assertFileContent("file1", "This is a test file") + .assertFileContent("file2", "This is a test file"); } @Test public void testGetArray() throws JSONException, UnirestException { - HttpResponse response = Unirest.get("http://httpbin.org/get").queryString("name", Arrays.asList("Mark", "Tom")).asJson(); - - JSONArray names = response.getBody().getObject().getJSONObject("args").getJSONArray("name"); - assertEquals(2, names.length()); + HttpResponse response = Unirest.get(MockServer.GET) + .queryString("name", Arrays.asList("Mark", "Tom")) + .asJson(); - assertEquals("Mark", names.getString(0)); - assertEquals("Tom", names.getString(1)); + parse(response) + .assertParam("name", "Mark") + .assertParam("name", "Tom"); } @Test public void testPostArray() throws JSONException, UnirestException { - HttpResponse response = Unirest.post("http://httpbin.org/post").field("name", "Mark").field("name", "Tom").asJson(); - - JSONArray names = response.getBody().getObject().getJSONObject("form").getJSONArray("name"); - assertEquals(2, names.length()); + HttpResponse response = Unirest.post(MockServer.POST) + .field("name", "Mark") + .field("name", "Tom") + .asJson(); - assertEquals("Mark", names.getString(0)); - assertEquals("Tom", names.getString(1)); + parse(response) + .assertParam("name", "Mark") + .assertParam("name", "Tom"); } @Test public void testPostCollection() throws JSONException, UnirestException { - HttpResponse response = Unirest.post("http://httpbin.org/post").field("name", Arrays.asList("Mark", "Tom")).asJson(); - - JSONArray names = response.getBody().getObject().getJSONObject("form").getJSONArray("name"); - assertEquals(2, names.length()); + HttpResponse response = Unirest.post(MockServer.POST) + .field("name", Arrays.asList("Mark", "Tom")) + .asJson(); - assertEquals("Mark", names.getString(0)); - assertEquals("Tom", names.getString(1)); + parse(response) + .assertParam("name", "Mark") + .assertParam("name", "Tom"); } @Test public void testCaseInsensitiveHeaders() { - GetRequest request = Unirest.get("http://httpbin.org/headers").header("Name", "Marco"); + GetRequest request = Unirest.get(MockServer.GET) + .header("Name", "Marco"); + assertEquals(1, request.getHeaders().size()); assertEquals("Marco", request.getHeaders().get("name").get(0)); assertEquals("Marco", request.getHeaders().get("NAme").get(0)); assertEquals("Marco", request.getHeaders().get("Name").get(0)); - JSONObject headers = request.asJson().getBody().getObject().getJSONObject("headers"); - assertEquals("Marco", headers.getString("Name")); - request = Unirest.get("http://httpbin.org/headers").header("Name", "Marco").header("Name", "John"); + parse(request.asJson()) + .assertHeader("Name", "Marco"); + + request = Unirest.get(MockServer.GET).header("Name", "Marco").header("Name", "John"); assertEquals(1, request.getHeaders().size()); assertEquals("Marco", request.getHeaders().get("name").get(0)); assertEquals("John", request.getHeaders().get("name").get(1)); @@ -769,9 +787,10 @@ public void testObjectMapperRead() { Unirest.setObjectMapper(new JacksonObjectMapper()); GetResponse getResponseMock = new GetResponse(); - getResponseMock.setUrl("http://httpbin.org/get"); + getResponseMock.setUrl(MockServer.GET); - HttpResponse getResponse = Unirest.get(getResponseMock.getUrl()).asObject(GetResponse.class); + HttpResponse getResponse = Unirest.get(getResponseMock.getUrl()) + .asObject(GetResponse.class); assertEquals(200, getResponse.getStatus()); assertEquals(getResponse.getBody().getUrl(), getResponseMock.getUrl()); @@ -782,18 +801,27 @@ public void testObjectMapperWrite() { Unirest.setObjectMapper(new JacksonObjectMapper()); GetResponse postResponseMock = new GetResponse(); - postResponseMock.setUrl("http://httpbin.org/post"); + postResponseMock.setUrl(MockServer.POST); - HttpResponse postResponse = Unirest.post(postResponseMock.getUrl()).header("accept", "application/json").header("Content-Type", "application/json").body(postResponseMock).asJson(); + HttpResponse postResponse = Unirest.post(postResponseMock.getUrl()) + .header("accept", "application/json") + .header("Content-Type", "application/json") + .body(postResponseMock) + .asJson(); assertEquals(200, postResponse.getStatus()); - assertEquals(postResponse.getBody().getObject().getString("data"), "{\"url\":\"http://httpbin.org/post\"}"); + parse(postResponse) + .asserBody("{\"url\":\"http://localhost:4567/post\"}"); } @Test public void testPostProvidesSortedParams() throws IOException { // Verify that fields are encoded into the body in sorted order. - HttpRequest httpRequest = Unirest.post("test").field("z", "Z").field("y", "Y").field("x", "X").getHttpRequest(); + HttpRequest httpRequest = Unirest.post("test") + .field("z", "Z") + .field("y", "Y") + .field("x", "X") + .getHttpRequest(); InputStream content = httpRequest.getBody().getEntity().getContent(); String body = IOUtils.toString(content, "UTF-8"); From 6b5be8d42e9592dd48069f86c7a46b9a6182ab2b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 11 Mar 2018 19:28:11 -0500 Subject: [PATCH 0036/1769] cache mvn dependencies in travis --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 47dd1f502..d34d49296 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,3 +5,8 @@ jdk: os: - linux + +cache: + directories: + - .autoconf + - $HOME/.m2 From 72cdab92380ea0ccdde209058579c77bf770b32e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 16 Mar 2018 11:48:52 -0500 Subject: [PATCH 0037/1769] dont just throw up when JSON is not JSON. Include a parsing error instead --- .../github/openunirest/http/HttpResponse.java | 20 +++++++++++++++++-- .../github/openunirest/http/MockServer.java | 7 +++++++ .../github/openunirest/http/UnirestTest.java | 11 ++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/HttpResponse.java b/src/main/java/io/github/openunirest/http/HttpResponse.java index d23630757..670b7ac40 100644 --- a/src/main/java/io/github/openunirest/http/HttpResponse.java +++ b/src/main/java/io/github/openunirest/http/HttpResponse.java @@ -36,8 +36,10 @@ a copy of this software and associated documentation files (the import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.zip.GZIPInputStream; public class HttpResponse { @@ -46,6 +48,7 @@ public class HttpResponse { private String statusText; private Headers headers = new Headers(); private InputStream rawBody; + private Optional parsingError = Optional.empty(); private T body; @SuppressWarnings("unchecked") @@ -91,8 +94,7 @@ public HttpResponse(org.apache.http.HttpResponse response, Class responseClas this.rawBody = new ByteArrayInputStream(rawBody); if (JsonNode.class.equals(responseClass)) { - String jsonString = new String(rawBody, charset).trim(); - this.body = (T) new JsonNode(jsonString); + tryParseAsJson(charset, rawBody); } else if (String.class.equals(responseClass)) { this.body = (T) new String(rawBody, charset); } else if (InputStream.class.equals(responseClass)) { @@ -110,6 +112,16 @@ public HttpResponse(org.apache.http.HttpResponse response, Class responseClas EntityUtils.consumeQuietly(responseEntity); } + private void tryParseAsJson(String charset, byte[] rawBody) throws UnsupportedEncodingException { + try { + String jsonString = new String(rawBody, charset).trim(); + this.body = (T) new JsonNode(jsonString); + }catch (RuntimeException e){ + this.body = null; + this.parsingError = Optional.of(e); + } + } + public int getStatus() { return statusCode; } @@ -133,4 +145,8 @@ public InputStream getRawBody() { public T getBody() { return body; } + + public Optional getParsingError() { + return parsingError; + } } diff --git a/src/test/java/io/github/openunirest/http/MockServer.java b/src/test/java/io/github/openunirest/http/MockServer.java index f40437059..d4f6696cc 100644 --- a/src/test/java/io/github/openunirest/http/MockServer.java +++ b/src/test/java/io/github/openunirest/http/MockServer.java @@ -45,6 +45,7 @@ public class MockServer { public static final String DELETE = HOST + "/delete"; public static final String GZIP = HOST + "/gzip"; public static final String PATCH = HOST + "/patch"; + public static final String INVALID_REQUEST = HOST + "/invalid"; public static void setJsonAsResponse(Object o){ @@ -62,6 +63,12 @@ public static void start() { get("/get", MockServer::jsonResponse); get("/gzip", MockServer::gzipResponse); patch("/patch", MockServer::jsonResponse); + get("/invalid", MockServer::inValid); + } + + private static Object inValid(Request request, Response response) { + response.status(400); + return "You did something bad"; } private static Object gzipResponse(Request request, Response response) { diff --git a/src/test/java/io/github/openunirest/http/UnirestTest.java b/src/test/java/io/github/openunirest/http/UnirestTest.java index 7ccd3d833..721d20816 100644 --- a/src/test/java/io/github/openunirest/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/http/UnirestTest.java @@ -839,6 +839,17 @@ public void testHeaderNamesCaseSensitive() { assertEquals("Only header \"Content-Type\" should exist", "application/json", headers.getFirst("Content-Type")); } + @Test + public void failureToReturnValidJsonWillResultInAnEmptyNode() { + HttpResponse response = Unirest.get(MockServer.INVALID_REQUEST).asJson(); + + assertEquals(400, response.getStatus()); + assertNull(response.getBody()); + assertEquals("You did something bad", TestUtil.toString(response.getRawBody())); + assertEquals("org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]", + response.getParsingError().get().getMessage()); + } + private String findAvailableIpAddress() throws IOException { for (int i = 100; i <= 255; i++) { From e60d32357aa2822f8c3c39b8ebf4061ba9fd151f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 16 Mar 2018 11:55:14 -0500 Subject: [PATCH 0038/1769] fix missing javadocs --- src/main/java/io/github/openunirest/http/Unirest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/openunirest/http/Unirest.java b/src/main/java/io/github/openunirest/http/Unirest.java index 85abf0dbe..ff60017ba 100644 --- a/src/main/java/io/github/openunirest/http/Unirest.java +++ b/src/main/java/io/github/openunirest/http/Unirest.java @@ -46,6 +46,7 @@ public class Unirest { /** * Set the HttpClient implementation to use for every synchronous request + * @param httpClient Custom httpClient implementation */ public static void setHttpClient(HttpClient httpClient) { Options.setOption(Option.HTTPCLIENT, httpClient); @@ -54,6 +55,7 @@ public static void setHttpClient(HttpClient httpClient) { /** * Set the asynchronous AbstractHttpAsyncClient implementation to use for every asynchronous request + * @param asyncHttpClient Custom CloseableHttpAsyncClient implementation */ public static void setAsyncHttpClient(CloseableHttpAsyncClient asyncHttpClient) { Options.setOption(Option.ASYNCHTTPCLIENT, asyncHttpClient); @@ -62,6 +64,7 @@ public static void setAsyncHttpClient(CloseableHttpAsyncClient asyncHttpClient) /** * Set a proxy + * @param proxy Proxy settings object. */ public static void setProxy(HttpHost proxy) { Options.setOption(Option.PROXY, proxy); @@ -118,7 +121,9 @@ public static void clearDefaultHeaders() { } /** - * Set default header + * Set default header to appear on all requests + * @param name The name of the header. + * @param value The value of the header. */ @SuppressWarnings("unchecked") public static void setDefaultHeader(String name, String value) { @@ -132,6 +137,7 @@ public static void setDefaultHeader(String name, String value) { /** * Close the asynchronous client and its event loop. Use this method to close all the threads and allow an application to exit. + * @throws IOException Because of course it does */ public static void shutdown() throws IOException { // Closing the Sync HTTP client From fbe5b67a4b4b007048f19008a31dd224efb84fb1 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 16 Mar 2018 13:33:51 -0500 Subject: [PATCH 0039/1769] add test for async --- .../github/openunirest/http/UnirestTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/java/io/github/openunirest/http/UnirestTest.java b/src/test/java/io/github/openunirest/http/UnirestTest.java index 721d20816..786c739c9 100644 --- a/src/test/java/io/github/openunirest/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/http/UnirestTest.java @@ -850,6 +850,36 @@ public void failureToReturnValidJsonWillResultInAnEmptyNode() { response.getParsingError().get().getMessage()); } + @Test + public void failureToReturnValidJsonWillResultInAnEmptyNodeAsync() throws InterruptedException { + Unirest.get(MockServer.INVALID_REQUEST).asJsonAsync( + new Callback() { + @Override + public void completed(HttpResponse response) { + assertEquals(400, response.getStatus()); + assertNull(response.getBody()); + assertEquals("You did something bad", TestUtil.toString(response.getRawBody())); + assertEquals("org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]", + response.getParsingError().get().getMessage()); + lock.countDown(); + status = true; + } + + @Override + public void failed(UnirestException e) { + fail("The call itself didn't fail"); + } + + @Override + public void cancelled() { + fail("The call itself didn't cancel"); + } + } + ); + lock.await(10, TimeUnit.SECONDS); + assertTrue(status); + } + private String findAvailableIpAddress() throws IOException { for (int i = 100; i <= 255; i++) { From 7726abc4747d45dc57fb57954f5e816aa04f26ce Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 16 Mar 2018 13:41:49 -0500 Subject: [PATCH 0040/1769] use system properties by default for automatic proxy detection. closes #14 --- src/main/java/io/github/openunirest/http/options/Options.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/io/github/openunirest/http/options/Options.java b/src/main/java/io/github/openunirest/http/options/Options.java index cb1e7373b..c8f6659e8 100644 --- a/src/main/java/io/github/openunirest/http/options/Options.java +++ b/src/main/java/io/github/openunirest/http/options/Options.java @@ -80,6 +80,7 @@ public static void refresh() { CloseableHttpClient build = HttpClientBuilder.create() .setDefaultRequestConfig(clientConfig) .setConnectionManager(syncConnectionManager) + .useSystemProperties() .build(); setOption(Option.HTTPCLIENT, build); @@ -96,6 +97,7 @@ public static void refresh() { CloseableHttpAsyncClient asyncClient = HttpAsyncClientBuilder.create() .setDefaultRequestConfig(clientConfig) .setConnectionManager(asyncConnectionManager) + .useSystemProperties() .build(); setOption(Option.ASYNCHTTPCLIENT, asyncClient); From 0bbc71fa90fdc78f2a45e5e13e5a281d80549804 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 16 Mar 2018 13:56:44 -0500 Subject: [PATCH 0041/1769] attempting to expose https://stackoverflow.com/questions/45304424/unirest-is-caching-basic-authentication-information --- src/test/java/io/github/openunirest/http/MockServer.java | 1 + .../java/io/github/openunirest/http/RequestCapture.java | 7 +++++++ src/test/java/io/github/openunirest/http/UnirestTest.java | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/src/test/java/io/github/openunirest/http/MockServer.java b/src/test/java/io/github/openunirest/http/MockServer.java index d4f6696cc..36dc80d6d 100644 --- a/src/test/java/io/github/openunirest/http/MockServer.java +++ b/src/test/java/io/github/openunirest/http/MockServer.java @@ -46,6 +46,7 @@ public class MockServer { public static final String GZIP = HOST + "/gzip"; public static final String PATCH = HOST + "/patch"; public static final String INVALID_REQUEST = HOST + "/invalid"; + public static final String ALTGET = "http://127.0.0.1:" + PORT + "/get"; public static void setJsonAsResponse(Object o){ diff --git a/src/test/java/io/github/openunirest/http/RequestCapture.java b/src/test/java/io/github/openunirest/http/RequestCapture.java index aefd72131..90326a9eb 100644 --- a/src/test/java/io/github/openunirest/http/RequestCapture.java +++ b/src/test/java/io/github/openunirest/http/RequestCapture.java @@ -135,6 +135,13 @@ private File getFileByInput(String inputName) { .orElseThrow(() -> new RuntimeException("No File With Input Name: " + inputName)); } + public void assertBasicAuth(String username, String password) { + String raw = headers.get("Authorization"); + assertNotNull("Authorization Header Missing", raw); + String credentials = raw.replace("Basic ",""); + assertEquals(username + ":" + password, new String(Base64.getDecoder().decode(credentials))); + } + public static class File { public String fileName; public String type; diff --git a/src/test/java/io/github/openunirest/http/UnirestTest.java b/src/test/java/io/github/openunirest/http/UnirestTest.java index 786c739c9..63afb4486 100644 --- a/src/test/java/io/github/openunirest/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/http/UnirestTest.java @@ -880,6 +880,14 @@ public void cancelled() { assertTrue(status); } + @Test + public void willNotCacheBasicAuth() { + RequestCapture r1 = parse(Unirest.get(MockServer.GET).basicAuth("foo","bar").asJson()); + RequestCapture r2 = parse(Unirest.get(MockServer.ALTGET).basicAuth("baz","qux").asJson()); + + r1.assertBasicAuth("foo", "bar"); + r2.assertBasicAuth("baz", "qux"); + } private String findAvailableIpAddress() throws IOException { for (int i = 100; i <= 255; i++) { From 328e5349e35ea05c65fb84881c6ab72ceb1508f6 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 16 Mar 2018 16:27:18 -0500 Subject: [PATCH 0042/1769] make it so we can break these tests up --- .../io/github/openunirest/http/BddTest.java | 50 +++++++++++++ .../github/openunirest/http/UnirestTest.java | 72 +++++-------------- 2 files changed, 68 insertions(+), 54 deletions(-) create mode 100644 src/test/java/io/github/openunirest/http/BddTest.java diff --git a/src/test/java/io/github/openunirest/http/BddTest.java b/src/test/java/io/github/openunirest/http/BddTest.java new file mode 100644 index 000000000..c31cd9c3d --- /dev/null +++ b/src/test/java/io/github/openunirest/http/BddTest.java @@ -0,0 +1,50 @@ +package io.github.openunirest.http; + +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import static io.github.openunirest.http.TestUtils.read; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class BddTest { + + private CountDownLatch lock; + private boolean status; + + @BeforeClass + public static void suiteSetUp() { + MockServer.start(); + } + + @AfterClass + public static void suiteTearDown() { + MockServer.shutdown(); + } + + @Before + public void setUp() { + MockServer.reset(); + lock = new CountDownLatch(1); + status = false; + } + + protected void assertAsync() throws InterruptedException { + lock.await(10, TimeUnit.SECONDS); + assertTrue(status); + } + + protected void startCountdown() { + status = true; + lock.countDown(); + } + + public static RequestCapture parse(HttpResponse response) { + assertEquals(200, response.getStatus()); + return read(response, RequestCapture.class); + } +} diff --git a/src/test/java/io/github/openunirest/http/UnirestTest.java b/src/test/java/io/github/openunirest/http/UnirestTest.java index 63afb4486..d2bb4f432 100644 --- a/src/test/java/io/github/openunirest/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/http/UnirestTest.java @@ -51,27 +51,7 @@ a copy of this software and associated documentation files (the import static io.github.openunirest.http.TestUtils.read; import static org.junit.Assert.*; -public class UnirestTest { - - private CountDownLatch lock; - private boolean status; - - @BeforeClass - public static void suiteSetUp() { - MockServer.start(); - } - - @AfterClass - public static void suiteTearDown() { - MockServer.shutdown(); - } - - @Before - public void setUp() { - MockServer.reset(); - lock = new CountDownLatch(1); - status = false; - } +public class UnirestTest extends BddTest { @Test public void postFormReturnJson() throws JSONException, UnirestException { @@ -287,8 +267,7 @@ public void completed(HttpResponse jsonResponse) { req.assertParam("param1", "value1"); req.assertParam("param2", "bye"); - status = true; - lock.countDown(); + startCountdown(); } public void cancelled() { @@ -296,8 +275,7 @@ public void cancelled() { } }); - lock.await(10, TimeUnit.SECONDS); - assertTrue(status); + assertAsync(); } @Test @@ -362,8 +340,7 @@ public void completed(HttpResponse response) { .getFile("test") .assertFileType("application/octet-stream"); - status = true; - lock.countDown(); + startCountdown(); } public void cancelled() { @@ -371,8 +348,7 @@ public void cancelled() { } }); - lock.await(10, TimeUnit.SECONDS); - assertTrue(status); + assertAsync(); } @Test @@ -414,8 +390,7 @@ public void completed(HttpResponse response) { .getFile("test") .assertFileType("application/octet-stream"); - status = true; - lock.countDown(); + startCountdown(); } public void cancelled() { @@ -424,8 +399,7 @@ public void cancelled() { }); - lock.await(10, TimeUnit.SECONDS); - assertTrue(status); + assertAsync(); } @Test @@ -445,8 +419,7 @@ public void completed(HttpResponse response) { parse.getFile("test").assertFileType("application/octet-stream"); parse.getFile("test").assertBody("This is a test file"); - status = true; - lock.countDown(); + startCountdown(); } public void cancelled() { @@ -455,8 +428,7 @@ public void cancelled() { }); - lock.await(10, TimeUnit.SECONDS); - assertTrue(status); + assertAsync(); } @Test @@ -623,8 +595,7 @@ public void completed(HttpResponse jsonResponse) { .asserBody("{\"hello\":\"world\"}") .assertHeader("Content-Type", "application/json"); - status = true; - lock.countDown(); + startCountdown(); } public void cancelled() { @@ -632,8 +603,7 @@ public void cancelled() { } }); - lock.await(10, TimeUnit.SECONDS); - assertTrue(status); + assertAsync(); } @Test @@ -655,8 +625,7 @@ public void completed(HttpResponse jsonResponse) { .assertParam("hello", "world") .assertHeader("Content-Type", "application/x-www-form-urlencoded"); - status = true; - lock.countDown(); + startCountdown(); } public void cancelled() { @@ -664,10 +633,11 @@ public void cancelled() { } }); - lock.await(10, TimeUnit.SECONDS); - assertTrue(status); + assertAsync(); } + + @Test public void testGetQuerystringArray() throws JSONException, UnirestException { HttpResponse response = Unirest.get(MockServer.GET) @@ -861,8 +831,8 @@ public void completed(HttpResponse response) { assertEquals("You did something bad", TestUtil.toString(response.getRawBody())); assertEquals("org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]", response.getParsingError().get().getMessage()); - lock.countDown(); - status = true; + + startCountdown(); } @Override @@ -876,8 +846,7 @@ public void cancelled() { } } ); - lock.await(10, TimeUnit.SECONDS); - assertTrue(status); + assertAsync(); } @Test @@ -899,9 +868,4 @@ private String findAvailableIpAddress() throws IOException { throw new RuntimeException("Couldn't find an available IP address in the range of 192.168.0.100-255"); } - - private RequestCapture parse(HttpResponse response) { - assertEquals(200, response.getStatus()); - return read(response, RequestCapture.class); - } } From 6ec9c61d30aff8bb9c4ecb0175774c73995ddf1d Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 16 Mar 2018 17:13:49 -0500 Subject: [PATCH 0043/1769] return CompletableFuture rather that boring old Futures --- .../openunirest/http/HttpClientHelper.java | 79 ++++++++----------- .../http/async/CallbackFuture.java | 29 +++++++ .../http/exceptions/UnirestException.java | 3 + .../openunirest/request/BaseRequest.java | 26 +++--- .../io/github/openunirest/http/BddTest.java | 26 +++--- .../github/openunirest/http/MockServer.java | 7 +- .../github/openunirest/http/UnirestTest.java | 16 ++-- .../http/async/CallbackFutureTest.java | 35 ++++++++ .../openunirest/http/async/MockCallback.java | 28 +++++++ .../openunirest/http/async/NoopCallback.java | 21 +++++ 10 files changed, 180 insertions(+), 90 deletions(-) create mode 100644 src/main/java/io/github/openunirest/http/async/CallbackFuture.java create mode 100644 src/test/java/io/github/openunirest/http/async/CallbackFutureTest.java create mode 100644 src/test/java/io/github/openunirest/http/async/MockCallback.java create mode 100644 src/test/java/io/github/openunirest/http/async/NoopCallback.java diff --git a/src/main/java/io/github/openunirest/http/HttpClientHelper.java b/src/main/java/io/github/openunirest/http/HttpClientHelper.java index a838b97df..a66bf5462 100644 --- a/src/main/java/io/github/openunirest/http/HttpClientHelper.java +++ b/src/main/java/io/github/openunirest/http/HttpClientHelper.java @@ -33,12 +33,11 @@ a copy of this software and associated documentation files (the import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; +import java.util.concurrent.*; +import io.github.openunirest.http.async.CallbackFuture; import org.apache.http.HttpEntity; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; @@ -68,63 +67,47 @@ public class HttpClientHelper { private static final String USER_AGENT_HEADER = "user-agent"; private static final String USER_AGENT = "unirest-java/1.3.11"; - private static FutureCallback prepareCallback(final Class responseClass, final Callback callback) { - if (callback == null) - return null; + public static CompletableFuture> requestAsync(HttpRequest request, final Class responseClass) { + return requestAsync(request, responseClass, new CompletableFuture<>()); + } - return new FutureCallback() { + public static CompletableFuture> requestAsync(HttpRequest request, final Class responseClass, Callback callback) { + return requestAsync(request, responseClass, CallbackFuture.wrap(callback)); + } - public void cancelled() { - callback.cancelled(); - } + public static CompletableFuture> requestAsync(HttpRequest request, final Class responseClass, CompletableFuture> callback) { + Objects.requireNonNull(callback); - public void completed(org.apache.http.HttpResponse arg0) { - callback.completed(new HttpResponse(arg0, responseClass)); - } + HttpUriRequest requestObj = prepareRequest(request, true); - public void failed(Exception arg0) { - callback.failed(new UnirestException(arg0)); - } + asyncClient() + .execute(requestObj, new FutureCallback() { + @Override + public void completed(org.apache.http.HttpResponse httpResponse) { + callback.complete(new HttpResponse<>(httpResponse, responseClass)); + } - }; - } + @Override + public void failed(Exception e) { + callback.completeExceptionally(e); + } - public static Future> requestAsync(HttpRequest request, final Class responseClass, Callback callback) { - HttpUriRequest requestObj = prepareRequest(request, true); + @Override + public void cancelled() { + callback.completeExceptionally(new UnirestException("canceled")); + } + }); + return callback; + } + private static CloseableHttpAsyncClient asyncClient() { CloseableHttpAsyncClient asyncHttpClient = ClientFactory.getAsyncHttpClient(); if (!asyncHttpClient.isRunning()) { asyncHttpClient.start(); AsyncIdleConnectionMonitorThread asyncIdleConnectionMonitorThread = (AsyncIdleConnectionMonitorThread) Options.getOption(Option.ASYNC_MONITOR); asyncIdleConnectionMonitorThread.start(); } - - final Future future = asyncHttpClient.execute(requestObj, prepareCallback(responseClass, callback)); - - return new Future>() { - - public boolean cancel(boolean mayInterruptIfRunning) { - return future.cancel(mayInterruptIfRunning); - } - - public boolean isCancelled() { - return future.isCancelled(); - } - - public boolean isDone() { - return future.isDone(); - } - - public HttpResponse get() throws InterruptedException, ExecutionException { - org.apache.http.HttpResponse httpResponse = future.get(); - return new HttpResponse(httpResponse, responseClass); - } - - public HttpResponse get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { - org.apache.http.HttpResponse httpResponse = future.get(timeout, unit); - return new HttpResponse(httpResponse, responseClass); - } - }; + return asyncHttpClient; } public static HttpResponse request(HttpRequest request, Class responseClass) throws UnirestException { diff --git a/src/main/java/io/github/openunirest/http/async/CallbackFuture.java b/src/main/java/io/github/openunirest/http/async/CallbackFuture.java new file mode 100644 index 000000000..a854909be --- /dev/null +++ b/src/main/java/io/github/openunirest/http/async/CallbackFuture.java @@ -0,0 +1,29 @@ +package io.github.openunirest.http.async; + +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.exceptions.UnirestException; + +import java.util.concurrent.CompletableFuture; + +public class CallbackFuture { + + public static CompletableFuture> wrap(Callback source){ + return new CompletableFuture>(){ + @Override + public boolean complete(HttpResponse value) { + source.completed(value); + return super.complete(value); + } + @Override + public boolean completeExceptionally(Throwable ex) { + source.failed(new UnirestException(ex)); + return super.completeExceptionally(ex); + } + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + source.cancelled(); + return super.cancel(mayInterruptIfRunning); + } + }; + } +} \ No newline at end of file diff --git a/src/main/java/io/github/openunirest/http/exceptions/UnirestException.java b/src/main/java/io/github/openunirest/http/exceptions/UnirestException.java index 52594c40b..5f543e78f 100644 --- a/src/main/java/io/github/openunirest/http/exceptions/UnirestException.java +++ b/src/main/java/io/github/openunirest/http/exceptions/UnirestException.java @@ -12,4 +12,7 @@ public UnirestException(String msg) { super(msg); } + public UnirestException(Throwable ex) { + super(ex); + } } diff --git a/src/main/java/io/github/openunirest/request/BaseRequest.java b/src/main/java/io/github/openunirest/request/BaseRequest.java index dcc623e57..7c52f5893 100644 --- a/src/main/java/io/github/openunirest/request/BaseRequest.java +++ b/src/main/java/io/github/openunirest/request/BaseRequest.java @@ -36,6 +36,7 @@ a copy of this software and associated documentation files (the import io.github.openunirest.http.exceptions.UnirestException; import java.io.InputStream; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.Future; public abstract class BaseRequest { @@ -60,11 +61,11 @@ public HttpResponse asString() throws UnirestException { return HttpClientHelper.request(httpRequest, String.class); } - public Future> asStringAsync() { - return HttpClientHelper.requestAsync(httpRequest, String.class, null); + public CompletableFuture> asStringAsync() { + return HttpClientHelper.requestAsync(httpRequest, String.class); } - public Future> asStringAsync(Callback callback) { + public CompletableFuture> asStringAsync(Callback callback) { return HttpClientHelper.requestAsync(httpRequest, String.class, callback); } @@ -72,11 +73,11 @@ public HttpResponse asJson() throws UnirestException { return HttpClientHelper.request(httpRequest, JsonNode.class); } - public Future> asJsonAsync() { - return HttpClientHelper.requestAsync(httpRequest, JsonNode.class, null); + public CompletableFuture> asJsonAsync() { + return HttpClientHelper.requestAsync(httpRequest, JsonNode.class); } - public Future> asJsonAsync(Callback callback) { + public CompletableFuture> asJsonAsync(Callback callback) { return HttpClientHelper.requestAsync(httpRequest, JsonNode.class, callback); } @@ -84,11 +85,11 @@ public HttpResponse asObject(Class responseClass) throws Uni return HttpClientHelper.request(httpRequest, (Class) responseClass); } - public Future> asObjectAsync(Class responseClass) { - return HttpClientHelper.requestAsync(httpRequest, (Class) responseClass, null); + public CompletableFuture> asObjectAsync(Class responseClass) { + return HttpClientHelper.requestAsync(httpRequest, (Class) responseClass); } - public Future> asObjectAsync(Class responseClass, Callback callback) { + public CompletableFuture> asObjectAsync(Class responseClass, Callback callback) { return HttpClientHelper.requestAsync(httpRequest, (Class) responseClass, callback); } @@ -96,12 +97,11 @@ public HttpResponse asBinary() throws UnirestException { return HttpClientHelper.request(httpRequest, InputStream.class); } - public Future> asBinaryAsync() { - return HttpClientHelper.requestAsync(httpRequest, InputStream.class, null); + public CompletableFuture> asBinaryAsync() { + return HttpClientHelper.requestAsync(httpRequest, InputStream.class); } - public Future> asBinaryAsync(Callback callback) { + public CompletableFuture> asBinaryAsync(Callback callback) { return HttpClientHelper.requestAsync(httpRequest, InputStream.class, callback); } - } diff --git a/src/test/java/io/github/openunirest/http/BddTest.java b/src/test/java/io/github/openunirest/http/BddTest.java index c31cd9c3d..aeebf3914 100644 --- a/src/test/java/io/github/openunirest/http/BddTest.java +++ b/src/test/java/io/github/openunirest/http/BddTest.java @@ -1,8 +1,6 @@ package io.github.openunirest.http; -import org.junit.AfterClass; import org.junit.Before; -import org.junit.BeforeClass; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -15,16 +13,7 @@ public class BddTest { private CountDownLatch lock; private boolean status; - - @BeforeClass - public static void suiteSetUp() { - MockServer.start(); - } - - @AfterClass - public static void suiteTearDown() { - MockServer.shutdown(); - } + private String fail; @Before public void setUp() { @@ -33,16 +22,21 @@ public void setUp() { status = false; } - protected void assertAsync() throws InterruptedException { - lock.await(10, TimeUnit.SECONDS); - assertTrue(status); + public void assertAsync() throws InterruptedException { + lock.await(5, TimeUnit.SECONDS); + assertTrue("Expected a async call but it never responded", status); } - protected void startCountdown() { + public void asyncSuccess() { status = true; lock.countDown(); } + public void asyncFail(String message) { + status = false; + lock.countDown(); + } + public static RequestCapture parse(HttpResponse response) { assertEquals(200, response.getStatus()); return read(response, RequestCapture.class); diff --git a/src/test/java/io/github/openunirest/http/MockServer.java b/src/test/java/io/github/openunirest/http/MockServer.java index 36dc80d6d..be2908091 100644 --- a/src/test/java/io/github/openunirest/http/MockServer.java +++ b/src/test/java/io/github/openunirest/http/MockServer.java @@ -26,16 +26,14 @@ a copy of this software and associated documentation files (the package io.github.openunirest.http; -import org.apache.http.entity.ContentType; import spark.Request; import spark.Response; -import spark.Route; import spark.Spark; -import static java.lang.System.getProperty; import static spark.Spark.*; public class MockServer { + private static final JacksonObjectMapper om = new JacksonObjectMapper(); private static Object responseBody; public static final int PORT = 4567; @@ -57,7 +55,7 @@ public static void reset(){ responseBody = null; } - public static void start() { + static { port(PORT); delete("/delete", MockServer::jsonResponse); post("/post", MockServer::jsonResponse); @@ -65,6 +63,7 @@ public static void start() { get("/gzip", MockServer::gzipResponse); patch("/patch", MockServer::jsonResponse); get("/invalid", MockServer::inValid); + Runtime.getRuntime().addShutdownHook(new Thread(Spark::stop)); } private static Object inValid(Request request, Response response) { diff --git a/src/test/java/io/github/openunirest/http/UnirestTest.java b/src/test/java/io/github/openunirest/http/UnirestTest.java index d2bb4f432..96be13280 100644 --- a/src/test/java/io/github/openunirest/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/http/UnirestTest.java @@ -36,9 +36,7 @@ a copy of this software and associated documentation files (the import org.apache.http.entity.ContentType; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; -import org.json.JSONArray; import org.json.JSONException; -import org.json.JSONObject; import org.junit.*; import java.io.*; @@ -267,7 +265,7 @@ public void completed(HttpResponse jsonResponse) { req.assertParam("param1", "value1"); req.assertParam("param2", "bye"); - startCountdown(); + asyncSuccess(); } public void cancelled() { @@ -340,7 +338,7 @@ public void completed(HttpResponse response) { .getFile("test") .assertFileType("application/octet-stream"); - startCountdown(); + asyncSuccess(); } public void cancelled() { @@ -390,7 +388,7 @@ public void completed(HttpResponse response) { .getFile("test") .assertFileType("application/octet-stream"); - startCountdown(); + asyncSuccess(); } public void cancelled() { @@ -419,7 +417,7 @@ public void completed(HttpResponse response) { parse.getFile("test").assertFileType("application/octet-stream"); parse.getFile("test").assertBody("This is a test file"); - startCountdown(); + asyncSuccess(); } public void cancelled() { @@ -595,7 +593,7 @@ public void completed(HttpResponse jsonResponse) { .asserBody("{\"hello\":\"world\"}") .assertHeader("Content-Type", "application/json"); - startCountdown(); + asyncSuccess(); } public void cancelled() { @@ -625,7 +623,7 @@ public void completed(HttpResponse jsonResponse) { .assertParam("hello", "world") .assertHeader("Content-Type", "application/x-www-form-urlencoded"); - startCountdown(); + asyncSuccess(); } public void cancelled() { @@ -832,7 +830,7 @@ public void completed(HttpResponse response) { assertEquals("org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]", response.getParsingError().get().getMessage()); - startCountdown(); + asyncSuccess(); } @Override diff --git a/src/test/java/io/github/openunirest/http/async/CallbackFutureTest.java b/src/test/java/io/github/openunirest/http/async/CallbackFutureTest.java new file mode 100644 index 000000000..26d635f98 --- /dev/null +++ b/src/test/java/io/github/openunirest/http/async/CallbackFutureTest.java @@ -0,0 +1,35 @@ +package io.github.openunirest.http.async; + +import io.github.openunirest.http.BddTest; +import io.github.openunirest.http.MockServer; +import io.github.openunirest.http.Unirest; +import org.junit.Test; + +public class CallbackFutureTest extends BddTest { + + @Test(timeout = 5000) + public void onSuccess() throws Exception { + Unirest.get(MockServer.GET) + .queryString("Snazzy", "Shoes") + .asJsonAsync() + .thenAccept(r -> { + parse(r).assertParam("Snazzy", "Shoes"); + asyncSuccess(); + }).get(); + + assertAsync(); + } + + @Test(timeout = 5000) + public void onSuccessSupplyCallback() throws Exception { + Unirest.get(MockServer.GET) + .queryString("Snazzy", "Shoes") + .asJsonAsync(new NoopCallback<>()) + .thenAccept(r -> { + parse(r).assertParam("Snazzy", "Shoes"); + asyncSuccess(); + }).get(); + + assertAsync(); + } +} \ No newline at end of file diff --git a/src/test/java/io/github/openunirest/http/async/MockCallback.java b/src/test/java/io/github/openunirest/http/async/MockCallback.java new file mode 100644 index 000000000..f3a41ec86 --- /dev/null +++ b/src/test/java/io/github/openunirest/http/async/MockCallback.java @@ -0,0 +1,28 @@ +package io.github.openunirest.http.async; + +import io.github.openunirest.http.BddTest; +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.exceptions.UnirestException; + +public class MockCallback implements Callback { + private BddTest test; + + public MockCallback(BddTest test){ + this.test = test; + } + + @Override + public void completed(HttpResponse response) { + test.asyncSuccess(); + } + + @Override + public void failed(UnirestException e) { + test.asyncFail(e.getMessage()); + } + + @Override + public void cancelled() { + test.asyncFail("canceled"); + } +} diff --git a/src/test/java/io/github/openunirest/http/async/NoopCallback.java b/src/test/java/io/github/openunirest/http/async/NoopCallback.java new file mode 100644 index 000000000..1fd8b081e --- /dev/null +++ b/src/test/java/io/github/openunirest/http/async/NoopCallback.java @@ -0,0 +1,21 @@ +package io.github.openunirest.http.async; + +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.exceptions.UnirestException; + +public class NoopCallback implements Callback { + @Override + public void completed(HttpResponse response) { + + } + + @Override + public void failed(UnirestException e) { + + } + + @Override + public void cancelled() { + + } +} From cec158e946dc6c5b63f47075cea558d066711394 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 17 Mar 2018 07:47:53 -0500 Subject: [PATCH 0044/1769] clean up tests so they are easier to read --- .../openunirest/http/RequestCapture.java | 6 +- .../github/openunirest/http/UnirestTest.java | 178 ++++-------------- .../openunirest/http/async/MockCallback.java | 7 +- 3 files changed, 50 insertions(+), 141 deletions(-) diff --git a/src/test/java/io/github/openunirest/http/RequestCapture.java b/src/test/java/io/github/openunirest/http/RequestCapture.java index 90326a9eb..96334b823 100644 --- a/src/test/java/io/github/openunirest/http/RequestCapture.java +++ b/src/test/java/io/github/openunirest/http/RequestCapture.java @@ -149,12 +149,14 @@ public static class File { public String body; public String fileType; - public void assertBody(String content){ + public File assertBody(String content){ assertEquals(content, body); + return this; } - public void assertFileType(String type){ + public File assertFileType(String type){ assertEquals(type, this.fileType); + return this; } } } diff --git a/src/test/java/io/github/openunirest/http/UnirestTest.java b/src/test/java/io/github/openunirest/http/UnirestTest.java index 96be13280..0df942796 100644 --- a/src/test/java/io/github/openunirest/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/http/UnirestTest.java @@ -26,18 +26,18 @@ a copy of this software and associated documentation files (the package io.github.openunirest.http; -import io.github.openunirest.http.async.Callback; -import io.github.openunirest.http.options.Options; +import io.github.openunirest.http.async.MockCallback; import io.github.openunirest.http.exceptions.UnirestException; +import io.github.openunirest.http.options.Options; import io.github.openunirest.request.GetRequest; import io.github.openunirest.request.HttpRequest; - import org.apache.commons.io.IOUtils; import org.apache.http.entity.ContentType; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; import org.json.JSONException; -import org.junit.*; +import org.junit.Ignore; +import org.junit.Test; import java.io.*; import java.net.InetAddress; @@ -46,7 +46,6 @@ a copy of this software and associated documentation files (the import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; -import static io.github.openunirest.http.TestUtils.read; import static org.junit.Assert.*; public class UnirestTest extends BddTest { @@ -254,24 +253,11 @@ public void testAsyncCallback() throws JSONException, InterruptedException { .header("accept", "application/json") .field("param1", "value1") .field("param2", "bye") - .asJsonAsync(new Callback() { - - public void failed(UnirestException e) { - fail(); - } - - public void completed(HttpResponse jsonResponse) { - RequestCapture req = parse(jsonResponse); - req.assertParam("param1", "value1"); - req.assertParam("param2", "bye"); - - asyncSuccess(); - } - - public void cancelled() { - fail(); - } - }); + .asJsonAsync(new MockCallback<>(this, r -> { + RequestCapture req = parse(r); + req.assertParam("param1", "value1"); + req.assertParam("param2", "bye"); + })); assertAsync(); } @@ -326,25 +312,11 @@ public void testMultipartInputStreamContentTypeAsync() throws JSONException, Int Unirest.post(MockServer.POST) .field("name", "Mark") .field("file", new FileInputStream(new File(getClass().getResource("/test").toURI())), ContentType.APPLICATION_OCTET_STREAM, "test") - .asJsonAsync(new Callback() { - - public void failed(UnirestException e) { - fail(); - } - - public void completed(HttpResponse response) { - parse(response) - .assertParam("name", "Mark") - .getFile("test") - .assertFileType("application/octet-stream"); - - asyncSuccess(); - } - - public void cancelled() { - fail(); - } - }); + .asJsonAsync(new MockCallback<>(this, r -> parse(r) + .assertParam("name", "Mark") + .getFile("test") + .assertFileType("application/octet-stream")) + ); assertAsync(); } @@ -367,7 +339,7 @@ public void testMultipartByteContentType() throws JSONException, URISyntaxExcept } @Test - public void testMultipartByteContentTypeAsync() throws JSONException, InterruptedException, ExecutionException, URISyntaxException, IOException { + public void testMultipartByteContentTypeAsync() throws Exception { final InputStream stream = new FileInputStream(new File(getClass().getResource("/test").toURI())); final byte[] bytes = new byte[stream.available()]; stream.read(bytes); @@ -376,55 +348,28 @@ public void testMultipartByteContentTypeAsync() throws JSONException, Interrupte Unirest.post(MockServer.POST) .field("name", "Mark") .field("file", bytes, "test") - .asJsonAsync(new Callback() { - - public void failed(UnirestException e) { - fail(); - } - - public void completed(HttpResponse response) { - parse(response) + .asJsonAsync(new MockCallback<>(this, r -> + parse(r) .assertParam("name", "Mark") .getFile("test") - .assertFileType("application/octet-stream"); - - asyncSuccess(); - } - - public void cancelled() { - fail(); - } - - }); + .assertFileType("application/octet-stream")) + ); assertAsync(); } @Test - public void testMultipartAsync() throws JSONException, InterruptedException, ExecutionException, URISyntaxException, UnirestException { + public void testMultipartAsync() throws Exception { Unirest.post(MockServer.POST) .field("name", "Mark") .field("file", new File(getClass().getResource("/test").toURI())) - .asJsonAsync(new Callback() { - - public void failed(UnirestException e) { - fail(); - } - - public void completed(HttpResponse response) { - RequestCapture parse = parse(response); - parse.assertParam("name", "Mark"); - parse.getFile("test").assertFileType("application/octet-stream"); - parse.getFile("test").assertBody("This is a test file"); - - asyncSuccess(); - } - - public void cancelled() { - fail(); - } - - }); + .asJsonAsync(new MockCallback<>(this, r -> + parse(r) + .assertParam("name", "Mark") + .getFile("test") + .assertFileType("application/octet-stream") + .assertBody("This is a test file")) + ); assertAsync(); } @@ -468,7 +413,7 @@ public void testDefaultHeaders() throws JSONException { jsonResponse = Unirest.get(MockServer.GET).asJson(); parse(jsonResponse) - .assertNoHeader("X-Custom-Header"); + .assertNoHeader("X-Custom-Header"); } @Test @@ -577,29 +522,15 @@ private void makeParallelRequests() throws InterruptedException { } @Test - public void testAsyncCustomContentType() throws InterruptedException { + public void testAsyncCustomContentType() throws Exception { Unirest.post(MockServer.POST) .header("accept", "application/json") .header("Content-Type", "application/json") .body("{\"hello\":\"world\"}") - .asJsonAsync(new Callback() { - - public void failed(UnirestException e) { - fail(); - } - - public void completed(HttpResponse jsonResponse) { - parse(jsonResponse) + .asJsonAsync(new MockCallback<>(this, r -> parse(r) .asserBody("{\"hello\":\"world\"}") - .assertHeader("Content-Type", "application/json"); - - asyncSuccess(); - } - - public void cancelled() { - fail(); - } - }); + .assertHeader("Content-Type", "application/json")) + ); assertAsync(); } @@ -611,31 +542,16 @@ public void testAsyncCustomContentTypeAndFormParams() throws InterruptedExceptio .header("Content-Type", "application/x-www-form-urlencoded") .field("name", "Mark") .field("hello", "world") - .asJsonAsync(new Callback() { - - public void failed(UnirestException e) { - fail(); - } - - public void completed(HttpResponse jsonResponse) { - parse(jsonResponse) + .asJsonAsync(new MockCallback<>(this, r -> parse(r) .assertParam("name", "Mark") .assertParam("hello", "world") - .assertHeader("Content-Type", "application/x-www-form-urlencoded"); - - asyncSuccess(); - } - - public void cancelled() { - fail(); - } - }); + .assertHeader("Content-Type", "application/x-www-form-urlencoded") + )); assertAsync(); } - @Test public void testGetQuerystringArray() throws JSONException, UnirestException { HttpResponse response = Unirest.get(MockServer.GET) @@ -820,37 +736,23 @@ public void failureToReturnValidJsonWillResultInAnEmptyNode() { @Test public void failureToReturnValidJsonWillResultInAnEmptyNodeAsync() throws InterruptedException { - Unirest.get(MockServer.INVALID_REQUEST).asJsonAsync( - new Callback() { - @Override - public void completed(HttpResponse response) { + Unirest.get(MockServer.INVALID_REQUEST) + .asJsonAsync(new MockCallback<>(this, response -> { assertEquals(400, response.getStatus()); assertNull(response.getBody()); assertEquals("You did something bad", TestUtil.toString(response.getRawBody())); assertEquals("org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]", response.getParsingError().get().getMessage()); - asyncSuccess(); - } + })); - @Override - public void failed(UnirestException e) { - fail("The call itself didn't fail"); - } - - @Override - public void cancelled() { - fail("The call itself didn't cancel"); - } - } - ); assertAsync(); } @Test public void willNotCacheBasicAuth() { - RequestCapture r1 = parse(Unirest.get(MockServer.GET).basicAuth("foo","bar").asJson()); - RequestCapture r2 = parse(Unirest.get(MockServer.ALTGET).basicAuth("baz","qux").asJson()); + RequestCapture r1 = parse(Unirest.get(MockServer.GET).basicAuth("foo", "bar").asJson()); + RequestCapture r2 = parse(Unirest.get(MockServer.ALTGET).basicAuth("baz", "qux").asJson()); r1.assertBasicAuth("foo", "bar"); r2.assertBasicAuth("baz", "qux"); diff --git a/src/test/java/io/github/openunirest/http/async/MockCallback.java b/src/test/java/io/github/openunirest/http/async/MockCallback.java index f3a41ec86..410aaf817 100644 --- a/src/test/java/io/github/openunirest/http/async/MockCallback.java +++ b/src/test/java/io/github/openunirest/http/async/MockCallback.java @@ -4,15 +4,20 @@ import io.github.openunirest.http.HttpResponse; import io.github.openunirest.http.exceptions.UnirestException; +import java.util.function.Consumer; + public class MockCallback implements Callback { private BddTest test; + private Consumer> completionAsserts; - public MockCallback(BddTest test){ + public MockCallback(BddTest test, Consumer> completionAsserts){ this.test = test; + this.completionAsserts = completionAsserts; } @Override public void completed(HttpResponse response) { + completionAsserts.accept(response); test.asyncSuccess(); } From e4b344415b789f50d8e728d6cb812e662a13e85c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 17 Mar 2018 10:07:44 -0500 Subject: [PATCH 0045/1769] some more tests --- .../io/github/openunirest/http/BddTest.java | 8 +++++ .../http/async/CallbackFutureTest.java | 12 ++++++++ .../openunirest/http/async/MockCallback.java | 30 ++++++++++++++++--- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/test/java/io/github/openunirest/http/BddTest.java b/src/test/java/io/github/openunirest/http/BddTest.java index aeebf3914..163877be8 100644 --- a/src/test/java/io/github/openunirest/http/BddTest.java +++ b/src/test/java/io/github/openunirest/http/BddTest.java @@ -7,6 +7,7 @@ import static io.github.openunirest.http.TestUtils.read; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; public class BddTest { @@ -27,6 +28,12 @@ public void assertAsync() throws InterruptedException { assertTrue("Expected a async call but it never responded", status); } + public void assertFailed(String message) throws InterruptedException { + lock.await(5, TimeUnit.SECONDS); + assertFalse("Should have failed", status); + assertEquals(message, fail); + } + public void asyncSuccess() { status = true; lock.countDown(); @@ -35,6 +42,7 @@ public void asyncSuccess() { public void asyncFail(String message) { status = false; lock.countDown(); + fail = message; } public static RequestCapture parse(HttpResponse response) { diff --git a/src/test/java/io/github/openunirest/http/async/CallbackFutureTest.java b/src/test/java/io/github/openunirest/http/async/CallbackFutureTest.java index 26d635f98..f3492a762 100644 --- a/src/test/java/io/github/openunirest/http/async/CallbackFutureTest.java +++ b/src/test/java/io/github/openunirest/http/async/CallbackFutureTest.java @@ -1,10 +1,13 @@ package io.github.openunirest.http.async; import io.github.openunirest.http.BddTest; +import io.github.openunirest.http.JsonNode; import io.github.openunirest.http.MockServer; import io.github.openunirest.http.Unirest; import org.junit.Test; +import static io.github.openunirest.http.async.MockCallback.json; + public class CallbackFutureTest extends BddTest { @Test(timeout = 5000) @@ -32,4 +35,13 @@ public void onSuccessSupplyCallback() throws Exception { assertAsync(); } + + @Test(timeout = 5000) + public void onFailure() throws Exception { + Unirest.get("http://localhost:0000") + .asJsonAsync(json(this)) + .isCompletedExceptionally(); + + assertFailed("java.net.ConnectException: Connection refused"); + } } \ No newline at end of file diff --git a/src/test/java/io/github/openunirest/http/async/MockCallback.java b/src/test/java/io/github/openunirest/http/async/MockCallback.java index 410aaf817..a8abc926f 100644 --- a/src/test/java/io/github/openunirest/http/async/MockCallback.java +++ b/src/test/java/io/github/openunirest/http/async/MockCallback.java @@ -2,22 +2,44 @@ import io.github.openunirest.http.BddTest; import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.JsonNode; import io.github.openunirest.http.exceptions.UnirestException; import java.util.function.Consumer; public class MockCallback implements Callback { + + public static MockCallback json(BddTest test){ + return new MockCallback<>(test); + } + private BddTest test; - private Consumer> completionAsserts; + private Consumer> onSuccess = r -> {}; + private Consumer onFail = f -> {}; + private Runnable onCancel = () -> {}; + + public MockCallback(BddTest test){ + this.test = test; + } - public MockCallback(BddTest test, Consumer> completionAsserts){ + public MockCallback(BddTest test, Consumer> onSuccess){ this.test = test; - this.completionAsserts = completionAsserts; + this.onSuccess = onSuccess; + } + + public MockCallback onFail(Consumer onFail){ + this.onFail = onFail; + return this; + } + + public MockCallback onCancel(Consumer onFail){ + this.onFail = onFail; + return this; } @Override public void completed(HttpResponse response) { - completionAsserts.accept(response); + onSuccess.accept(response); test.asyncSuccess(); } From b765926c393addbb5d65cda91924c92f29d14d30 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 17 Mar 2018 10:20:03 -0500 Subject: [PATCH 0046/1769] add changelog --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..6b603eeae --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +# 2.1.00 +* JSON parsing errors no longer just throw out of ```asJson``` but are captured and can be inspected via ```HttpResponse::getParsingError```. This resolves the fact that most API's do not return valid JSON for non-200 status codes. +* Return CompletableFuture rather that boring old Futures for all async methods. + + +# 2.0.02 +* UnirestException is no longer checked +* Namespaces have been migrated to new **io.gitgub.openunirest** namespace +* Thread leak in Options fixed From fc43b5283b3676d0b3f36a51cf05c0499d4e1d12 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 17 Mar 2018 10:22:08 -0500 Subject: [PATCH 0047/1769] bump minor. These changes may cause some users to get unexpected results. See Changelog --- README.md | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e28dd6d67..d2bc2c297 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Unirest.post("http://httpbin.org/post") io.github.openunirest unirest-java - 2.0.02 + 2.1.00 ``` diff --git a/pom.xml b/pom.xml index 1241e2bd9..935d5e887 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.0.03-SNAPSHOT + 2.1.00-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ From ed69c353081030362cafbc28a75c88a31980e6dc Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 17 Mar 2018 10:23:31 -0500 Subject: [PATCH 0048/1769] clean up release script --- deploy | 8 -------- 1 file changed, 8 deletions(-) diff --git a/deploy b/deploy index a4207e769..26a15204f 100755 --- a/deploy +++ b/deploy @@ -1,12 +1,4 @@ #!/bin/bash -mvn clean deploy -mvn release:clean -git commit -a -m "version bump" -git push origin master mvn release:prepare mvn release:perform - -# Note: Be sure that the local Maven settings.xml file is configured with the right credentials, and that the system has the right GPG keys installed (along with a valid GPG installation) - -# Now go to https://oss.sonatype.org/index.html and release it From aaf315b2db76d503f43f21b7317afacaa22f949f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 17 Mar 2018 10:24:04 -0500 Subject: [PATCH 0049/1769] [maven-release-plugin] prepare release v2.1.00 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 935d5e887..54e0d4e08 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.1.00-SNAPSHOT + 2.1.00 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.1.00 From add4ed389ca154ebbe6f9e0824fab5a0e7b7fc97 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 17 Mar 2018 10:24:10 -0500 Subject: [PATCH 0050/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 54e0d4e08..5d4f689af 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.1.00 + 2.1.01-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.1.00 + HEAD From a860fb9f0576d26eb5fef8339256597751cb0d54 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 17 Mar 2018 10:33:43 -0500 Subject: [PATCH 0051/1769] [maven-release-plugin] prepare release v2.1.01 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 5d4f689af..f7412e2f8 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.1.01-SNAPSHOT + 2.1.01 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.1.01 From f4f96a47a6cc876d631746387cffd8242260147a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 17 Mar 2018 10:33:51 -0500 Subject: [PATCH 0052/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index f7412e2f8..94e38f693 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.1.01 + 2.1.02-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.1.01 + HEAD From 25f17dbc482dbf3677b72a8271d5df476adc32ca Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 17 Mar 2018 10:38:18 -0500 Subject: [PATCH 0053/1769] update readme and release notes --- CHANGELOG.md | 2 +- README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b603eeae..5cd17d49f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 2.1.00 +# 2.1.01 * JSON parsing errors no longer just throw out of ```asJson``` but are captured and can be inspected via ```HttpResponse::getParsingError```. This resolves the fact that most API's do not return valid JSON for non-200 status codes. * Return CompletableFuture rather that boring old Futures for all async methods. diff --git a/README.md b/README.md index d2bc2c297..91949ccea 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,12 @@ Unirest.post("http://httpbin.org/post") .asJson() ``` -## Install With Maven +## Install With [Maven](https://mvnrepository.com/artifact/io.github.openunirest/unirest-java) ``` io.github.openunirest unirest-java - 2.1.00 + 2.1.01 ``` From 5e1e741a493a711e933c64bcc0987e06910c90a6 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 18 Mar 2018 08:18:53 -0500 Subject: [PATCH 0054/1769] Update README.md --- README.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/README.md b/README.md index 91949ccea..904cd007d 100644 --- a/README.md +++ b/README.md @@ -32,13 +32,6 @@ Unirest.post("http://httpbin.org/post") * Automatic JSON parsing into a native object for JSON responses * Customizable binding, with mapping from response body to java Object -## Installing -Is easy as pie. Kidding. It's about as easy as doing these little steps: - -### With Maven - -We are working on getting this new fork into Maven Central. Hold tight - ## Creating Request So you're probably wondering how using Unirest makes creating requests in Java easier, here is a basic POST request that will explain everything: From e214e1a632cf3dc83e34b69537be5d863009349c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 18 Mar 2018 08:20:14 -0500 Subject: [PATCH 0055/1769] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 904cd007d..5cc9aa51e 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ The placeholder's format is as easy as: `{custom_name}` Sometimes, well most of the time, you want your application to be asynchronous and not block, Unirest supports this in Java using anonymous callbacks, or direct method placement: ```java -Future> future = Unirest.post("http://httpbin.org/post") +CompletableFuture> future = Unirest.post("http://httpbin.org/post") .header("accept", "application/json") .field("param1", "value1") .field("param2", "value2") From 35bdad0e75da4e3152471f5607becff297063091 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 18 Mar 2018 10:44:59 -0500 Subject: [PATCH 0056/1769] switch to parsing the URL with Apache URLBuilder to resolve issues with anchors and encodings. Closes #17 --- .../openunirest/http/HttpClientHelper.java | 21 +--------- .../github/openunirest/http/UriFormatter.java | 20 ++++++++++ .../github/openunirest/http/DefectTest.java | 13 ++++++ .../openunirest/http/UriFormatterTest.java | 40 +++++++++++++++++++ 4 files changed, 75 insertions(+), 19 deletions(-) create mode 100644 src/main/java/io/github/openunirest/http/UriFormatter.java create mode 100644 src/test/java/io/github/openunirest/http/DefectTest.java create mode 100644 src/test/java/io/github/openunirest/http/UriFormatterTest.java diff --git a/src/main/java/io/github/openunirest/http/HttpClientHelper.java b/src/main/java/io/github/openunirest/http/HttpClientHelper.java index a66bf5462..0566b6521 100644 --- a/src/main/java/io/github/openunirest/http/HttpClientHelper.java +++ b/src/main/java/io/github/openunirest/http/HttpClientHelper.java @@ -27,9 +27,6 @@ a copy of this software and associated documentation files (the import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.net.URI; -import java.net.URL; -import java.net.URLDecoder; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -66,6 +63,7 @@ public class HttpClientHelper { private static final String ACCEPT_ENCODING_HEADER = "accept-encoding"; private static final String USER_AGENT_HEADER = "user-agent"; private static final String USER_AGENT = "unirest-java/1.3.11"; + private static final UriFormatter uriFormatter = new UriFormatter(); public static CompletableFuture> requestAsync(HttpRequest request, final Class responseClass) { return requestAsync(request, responseClass, new CompletableFuture<>()); @@ -149,22 +147,7 @@ private static HttpRequestBase prepareRequest(HttpRequest request, boolean async HttpRequestBase reqObj = null; - String urlToRequest = null; - try { - URL url = new URL(request.getUrl()); - URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), URLDecoder.decode(url.getPath(), "UTF-8"), "", url.getRef()); - urlToRequest = uri.toURL().toString(); - if (url.getQuery() != null && !url.getQuery().trim().equals("")) { - if (!urlToRequest.substring(urlToRequest.length() - 1).equals("?")) { - urlToRequest += "?"; - } - urlToRequest += url.getQuery(); - } else if (urlToRequest.substring(urlToRequest.length() - 1).equals("?")) { - urlToRequest = urlToRequest.substring(0, urlToRequest.length() - 1); - } - } catch (Exception e) { - throw new RuntimeException(e); - } + String urlToRequest = uriFormatter.apply(request); switch (request.getHttpMethod()) { case GET: diff --git a/src/main/java/io/github/openunirest/http/UriFormatter.java b/src/main/java/io/github/openunirest/http/UriFormatter.java new file mode 100644 index 000000000..daa028ca4 --- /dev/null +++ b/src/main/java/io/github/openunirest/http/UriFormatter.java @@ -0,0 +1,20 @@ +package io.github.openunirest.http; + +import io.github.openunirest.http.exceptions.UnirestException; +import io.github.openunirest.request.HttpRequest; +import org.apache.http.client.utils.URIBuilder; + +import java.net.URISyntaxException; +import java.util.function.Function; + +class UriFormatter implements Function { + @Override + public String apply(HttpRequest request) { + try { + return new URIBuilder(request.getUrl()).toString(); + } catch (URISyntaxException e) { + throw new UnirestException(e); + } + } + +} diff --git a/src/test/java/io/github/openunirest/http/DefectTest.java b/src/test/java/io/github/openunirest/http/DefectTest.java new file mode 100644 index 000000000..5643a0a50 --- /dev/null +++ b/src/test/java/io/github/openunirest/http/DefectTest.java @@ -0,0 +1,13 @@ +package io.github.openunirest.http; + +import org.junit.Test; + +public class DefectTest extends BddTest { + + @Test + public void hashOnLinksDoNotMessUpUri() { + parse(Unirest.get(MockServer.GET + "?a=1&b=2#some_location").asJson()) + .assertParam("a","1") + .assertParam("b", "2"); + } +} diff --git a/src/test/java/io/github/openunirest/http/UriFormatterTest.java b/src/test/java/io/github/openunirest/http/UriFormatterTest.java new file mode 100644 index 000000000..c01a5d85a --- /dev/null +++ b/src/test/java/io/github/openunirest/http/UriFormatterTest.java @@ -0,0 +1,40 @@ +package io.github.openunirest.http; + +import io.github.openunirest.request.HttpRequest; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class UriFormatterTest { + private UriFormatter helper = new UriFormatter(); + + @Test + public void testMangler_encoding() { + assertLinkSurvives("http://localhost/test%2Fthis"); + } + + @Test + public void testMangler_fragment() { + assertLinkSurvives("http://localhost/test?a=b#fragment"); + } + + @Test + public void basicBoringUri() { + assertLinkSurvives("http://localhost/test?a=b"); + } + + @Test + public void semicolonsAsParam() { + assertLinkSurvives("http://localhost/test?a=b;foo=bar"); + } + + @Test + public void utf8Chars(){ + assertLinkSurvives("http://localhost/test?foo=こんにちは"); + } + + private void assertLinkSurvives(String s) { + assertEquals(s, helper.apply(new HttpRequest(HttpMethod.GET, s))); + } + +} \ No newline at end of file From 5944d91b87887b97734b45e26504fd189bcd749a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 18 Mar 2018 10:52:33 -0500 Subject: [PATCH 0057/1769] small java-8 refactoring --- .../openunirest/request/body/MultipartBody.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/github/openunirest/request/body/MultipartBody.java b/src/main/java/io/github/openunirest/request/body/MultipartBody.java index b87aaa343..d7db45dbe 100644 --- a/src/main/java/io/github/openunirest/request/body/MultipartBody.java +++ b/src/main/java/io/github/openunirest/request/body/MultipartBody.java @@ -51,8 +51,8 @@ a copy of this software and associated documentation files (the import io.github.openunirest.request.HttpRequest; public class MultipartBody extends BaseRequest implements Body { - private Map> parameters = new LinkedHashMap>(); - private Map contentTypes = new HashMap(); + private Map> parameters = new LinkedHashMap<>(); + private Map contentTypes = new HashMap<>(); private boolean hasFile; private HttpRequest httpRequestObj; @@ -88,12 +88,9 @@ public MultipartBody field(String name, Object value, boolean file) { } public MultipartBody field(String name, Object value, boolean file, String contentType) { - List list = parameters.get(name); - if (list == null) - list = new LinkedList(); + List list = parameters.computeIfAbsent(name, n -> new LinkedList<>()); list.add(value); - parameters.put(name, list); - + ContentType type = null; if (contentType != null && contentType.length() > 0) { type = ContentType.parse(contentType); From 3e7f6dd5387f512585e2ba1dc68815f3a1d8d9ff Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 18 Mar 2018 11:00:21 -0500 Subject: [PATCH 0058/1769] set default object mapper ob tests --- src/test/java/io/github/openunirest/http/BddTest.java | 3 ++- src/test/java/io/github/openunirest/http/DefectTest.java | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/java/io/github/openunirest/http/BddTest.java b/src/test/java/io/github/openunirest/http/BddTest.java index 163877be8..0122af320 100644 --- a/src/test/java/io/github/openunirest/http/BddTest.java +++ b/src/test/java/io/github/openunirest/http/BddTest.java @@ -11,7 +11,7 @@ import static org.junit.Assert.assertTrue; public class BddTest { - + private JacksonObjectMapper objectMapper = new JacksonObjectMapper(); private CountDownLatch lock; private boolean status; private String fail; @@ -19,6 +19,7 @@ public class BddTest { @Before public void setUp() { MockServer.reset(); + Unirest.setObjectMapper(objectMapper); lock = new CountDownLatch(1); status = false; } diff --git a/src/test/java/io/github/openunirest/http/DefectTest.java b/src/test/java/io/github/openunirest/http/DefectTest.java index 5643a0a50..445641198 100644 --- a/src/test/java/io/github/openunirest/http/DefectTest.java +++ b/src/test/java/io/github/openunirest/http/DefectTest.java @@ -6,7 +6,9 @@ public class DefectTest extends BddTest { @Test public void hashOnLinksDoNotMessUpUri() { - parse(Unirest.get(MockServer.GET + "?a=1&b=2#some_location").asJson()) + Unirest.get(MockServer.GET + "?a=1&b=2#some_location") + .asObject(RequestCapture.class) + .getBody() .assertParam("a","1") .assertParam("b", "2"); } From a18aefa2765c0e787218294205d67b475370b75f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 18 Mar 2018 15:13:33 -0500 Subject: [PATCH 0059/1769] fixing npe in query map. Matches behavior of Apache URLBuilder closes #20 --- .../openunirest/http/async/Callback.java | 4 ++-- .../openunirest/request/HttpRequest.java | 10 +++++----- .../io/github/openunirest/http/DefectTest.java | 18 ++++++++++++++++++ .../openunirest/http/RequestCapture.java | 6 ++++++ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/async/Callback.java b/src/main/java/io/github/openunirest/http/async/Callback.java index a1675d7c0..b11a12850 100644 --- a/src/main/java/io/github/openunirest/http/async/Callback.java +++ b/src/main/java/io/github/openunirest/http/async/Callback.java @@ -32,7 +32,7 @@ public interface Callback { void completed(HttpResponse response); - void failed(UnirestException e); + default void failed(UnirestException e){} - void cancelled(); + default void cancelled(){} } diff --git a/src/main/java/io/github/openunirest/request/HttpRequest.java b/src/main/java/io/github/openunirest/request/HttpRequest.java index c120b973d..eacfdac05 100644 --- a/src/main/java/io/github/openunirest/request/HttpRequest.java +++ b/src/main/java/io/github/openunirest/request/HttpRequest.java @@ -109,10 +109,10 @@ public HttpRequest queryString(String name, Object value) { queryString.append("?"); } try { - queryString - .append(URLEncoder.encode(name)) - .append("=") - .append(URLEncoder.encode((value == null) ? "" : value.toString(), "UTF-8")); + queryString.append(URLEncoder.encode(name)); + if(value != null) { + queryString.append("=").append(URLEncoder.encode(value.toString(), "UTF-8")); + } } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } @@ -123,7 +123,7 @@ public HttpRequest queryString(String name, Object value) { public HttpRequest queryString(Map parameters) { if (parameters != null) { for (Entry param : parameters.entrySet()) { - if (param.getValue() instanceof String || param.getValue() instanceof Number || param.getValue() instanceof Boolean) { + if (param.getValue() instanceof String || param.getValue() instanceof Number || param.getValue() instanceof Boolean || param.getValue() == null) { queryString(param.getKey(), param.getValue()); } else { throw new RuntimeException("Parameter \"" + param.getKey() + "\" can't be sent with a GET request because of type: " + param.getValue().getClass().getName()); diff --git a/src/test/java/io/github/openunirest/http/DefectTest.java b/src/test/java/io/github/openunirest/http/DefectTest.java index 445641198..7b4e26159 100644 --- a/src/test/java/io/github/openunirest/http/DefectTest.java +++ b/src/test/java/io/github/openunirest/http/DefectTest.java @@ -2,6 +2,9 @@ import org.junit.Test; +import java.util.HashMap; +import java.util.Map; + public class DefectTest extends BddTest { @Test @@ -12,4 +15,19 @@ public void hashOnLinksDoNotMessUpUri() { .assertParam("a","1") .assertParam("b", "2"); } + + @Test + public void nullAndObjectValuesInMap(){ + Map queryParams = new HashMap<>(); + queryParams.put("foo", null); + queryParams.put("baz", "qux"); + + Unirest.get(MockServer.GET) + .queryString(queryParams) + .asObject(RequestCapture.class) + .getBody() + .assertParam("foo", "") + .assertParam("baz", "qux") + .assertQueryString("foo&baz=qux"); + } } diff --git a/src/test/java/io/github/openunirest/http/RequestCapture.java b/src/test/java/io/github/openunirest/http/RequestCapture.java index 96334b823..a28ee470b 100644 --- a/src/test/java/io/github/openunirest/http/RequestCapture.java +++ b/src/test/java/io/github/openunirest/http/RequestCapture.java @@ -24,12 +24,14 @@ public class RequestCapture { public Multimap params = HashMultimap.create(); public String body; public String url; + public String queryString; public RequestCapture() { } public RequestCapture(Request req) { url = req.url(); + queryString = req.queryString(); writeHeaders(req); writeQuery(req); } @@ -142,6 +144,10 @@ public void assertBasicAuth(String username, String password) { assertEquals(username + ":" + password, new String(Base64.getDecoder().decode(credentials))); } + public void assertQueryString(String s) { + assertEquals(s, queryString); + } + public static class File { public String fileName; public String type; From e729214aad3f65ecc7f440e3d5846f12dc8b8627 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 19 Mar 2018 20:18:30 -0500 Subject: [PATCH 0060/1769] update json dependency --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 94e38f693..58184240a 100644 --- a/pom.xml +++ b/pom.xml @@ -167,7 +167,7 @@ org.json json - 20160212 + 20180130 junit From 9612ca1031cde381b52f274c7c55970c15b1fb31 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 21 Mar 2018 13:04:55 -0500 Subject: [PATCH 0061/1769] some prefactoring of the headers to simplify the HttpRespose constructor so we can start to make it easier to add new functionality to it --- .../io/github/openunirest/http/Headers.java | 18 ++++++++++++++++++ .../github/openunirest/http/HttpResponse.java | 13 +++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/Headers.java b/src/main/java/io/github/openunirest/http/Headers.java index 958d79ed3..0cbbbd452 100644 --- a/src/main/java/io/github/openunirest/http/Headers.java +++ b/src/main/java/io/github/openunirest/http/Headers.java @@ -1,5 +1,9 @@ package io.github.openunirest.http; +import org.apache.http.Header; +import org.omg.CORBA.NameValuePair; + +import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -7,6 +11,16 @@ public class Headers extends HashMap> { private static final long serialVersionUID = 71310341388734766L; + public Headers(){ + super(); + } + + public Headers(Header[] pairs){ + for (Header header : pairs) { + add(header.getName(), header.getValue()); + } + } + public String getFirst(Object key) { List list = get(key); if (list != null && list.size() > 0) { @@ -15,4 +29,8 @@ public String getFirst(Object key) { return null; } + public void add(String name, String value){ + computeIfAbsent(name, k -> new ArrayList<>()).add(value); + } + } diff --git a/src/main/java/io/github/openunirest/http/HttpResponse.java b/src/main/java/io/github/openunirest/http/HttpResponse.java index 670b7ac40..eb8c46cfc 100644 --- a/src/main/java/io/github/openunirest/http/HttpResponse.java +++ b/src/main/java/io/github/openunirest/http/HttpResponse.java @@ -44,9 +44,9 @@ a copy of this software and associated documentation files (the public class HttpResponse { + private final Headers headers; private int statusCode; private String statusText; - private Headers headers = new Headers(); private InputStream rawBody; private Optional parsingError = Optional.empty(); private T body; @@ -56,15 +56,8 @@ public HttpResponse(org.apache.http.HttpResponse response, Class responseClas HttpEntity responseEntity = response.getEntity(); ObjectMapper objectMapper = (ObjectMapper) Options.getOption(Option.OBJECT_MAPPER); - Header[] allHeaders = response.getAllHeaders(); - for (Header header : allHeaders) { - String headerName = header.getName(); - List list = headers.get(headerName); - if (list == null) - list = new ArrayList(); - list.add(header.getValue()); - headers.put(headerName, list); - } + headers = new Headers(response.getAllHeaders()); + StatusLine statusLine = response.getStatusLine(); this.statusCode = statusLine.getStatusCode(); this.statusText = statusLine.getReasonPhrase(); From d57be3531cd052ae71be4aaa94f71a4ad94288a6 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 21 Mar 2018 13:14:00 -0500 Subject: [PATCH 0062/1769] some more prefactoring --- .../github/openunirest/http/HttpResponse.java | 32 +---- .../openunirest/http/utils/ResponseUtils.java | 118 +++++++++++------- 2 files changed, 76 insertions(+), 74 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/HttpResponse.java b/src/main/java/io/github/openunirest/http/HttpResponse.java index eb8c46cfc..dce2459f1 100644 --- a/src/main/java/io/github/openunirest/http/HttpResponse.java +++ b/src/main/java/io/github/openunirest/http/HttpResponse.java @@ -28,19 +28,14 @@ a copy of this software and associated documentation files (the import io.github.openunirest.http.options.Option; import io.github.openunirest.http.options.Options; import io.github.openunirest.http.utils.ResponseUtils; -import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.StatusLine; import org.apache.http.util.EntityUtils; import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.List; import java.util.Optional; -import java.util.zip.GZIPInputStream; public class HttpResponse { @@ -53,39 +48,22 @@ public class HttpResponse { @SuppressWarnings("unchecked") public HttpResponse(org.apache.http.HttpResponse response, Class responseClass) { - HttpEntity responseEntity = response.getEntity(); ObjectMapper objectMapper = (ObjectMapper) Options.getOption(Option.OBJECT_MAPPER); headers = new Headers(response.getAllHeaders()); - + StatusLine statusLine = response.getStatusLine(); this.statusCode = statusLine.getStatusCode(); this.statusText = statusLine.getReasonPhrase(); + HttpEntity responseEntity = response.getEntity(); if (responseEntity != null) { - String charset = "UTF-8"; - - Header contentType = responseEntity.getContentType(); - if (contentType != null) { - String responseCharset = ResponseUtils.getCharsetFromContentType(contentType.getValue()); - if (responseCharset != null && !responseCharset.trim().equals("")) { - charset = responseCharset; - } - } + String charset = ResponseUtils.getCharsetfromResponse(responseEntity); try { - byte[] rawBody; - try { - InputStream responseInputStream = responseEntity.getContent(); - if (ResponseUtils.isGzipped(responseEntity.getContentEncoding())) { - responseInputStream = new GZIPInputStream(responseEntity.getContent()); - } - rawBody = ResponseUtils.getBytes(responseInputStream); - } catch (IOException e2) { - throw new RuntimeException(e2); - } + byte[] rawBody = ResponseUtils.getRawBody(responseEntity); this.rawBody = new ByteArrayInputStream(rawBody); - + if (JsonNode.class.equals(responseClass)) { tryParseAsJson(charset, rawBody); } else if (String.class.equals(responseClass)) { diff --git a/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java b/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java index c1073cff2..6f5d6fc9f 100644 --- a/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java +++ b/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java @@ -6,57 +6,81 @@ import java.io.InputStream; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.zip.GZIPInputStream; import org.apache.http.Header; +import org.apache.http.HttpEntity; public class ResponseUtils { - private static final Pattern charsetPattern = Pattern.compile("(?i)\\bcharset=\\s*\"?([^\\s;\"]*)"); - - /** - * Parse out a charset from a content type header. - * - * @param contentType e.g. "text/html; charset=EUC-JP" - * @return "EUC-JP", or null if not found. Charset is trimmed and uppercased. - */ - public static String getCharsetFromContentType(String contentType) { - if (contentType == null) - return null; - - Matcher m = charsetPattern.matcher(contentType); - if (m.find()) { - return m.group(1).trim().toUpperCase(); - } - return null; - } - - public static byte[] getBytes(InputStream is) throws IOException { - int len; - int size = 1024; - byte[] buf; - - if (is instanceof ByteArrayInputStream) { - size = is.available(); - buf = new byte[size]; - len = is.read(buf, 0, size); - } else { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - buf = new byte[size]; - while ((len = is.read(buf, 0, size)) != -1) - bos.write(buf, 0, len); - buf = bos.toByteArray(); - } - return buf; - } - - public static boolean isGzipped(Header contentEncoding) { - if (contentEncoding != null) { - String value = contentEncoding.getValue(); - if (value != null && "gzip".equals(value.toLowerCase().trim())) { - return true; - } - } - return false; - } + private static final Pattern charsetPattern = Pattern.compile("(?i)\\bcharset=\\s*\"?([^\\s;\"]*)"); + /** + * Parse out a charset from a content type header. + * + * @param contentType e.g. "text/html; charset=EUC-JP" + * @return "EUC-JP", or null if not found. Charset is trimmed and uppercased. + */ + public static String getCharsetFromContentType(String contentType) { + if (contentType == null) + return null; + + Matcher m = charsetPattern.matcher(contentType); + if (m.find()) { + return m.group(1).trim().toUpperCase(); + } + return null; + } + + public static byte[] getBytes(InputStream is) throws IOException { + int len; + int size = 1024; + byte[] buf; + + if (is instanceof ByteArrayInputStream) { + size = is.available(); + buf = new byte[size]; + len = is.read(buf, 0, size); + } else { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + buf = new byte[size]; + while ((len = is.read(buf, 0, size)) != -1) + bos.write(buf, 0, len); + buf = bos.toByteArray(); + } + return buf; + } + + public static boolean isGzipped(Header contentEncoding) { + if (contentEncoding != null) { + String value = contentEncoding.getValue(); + if (value != null && "gzip".equals(value.toLowerCase().trim())) { + return true; + } + } + return false; + } + + public static String getCharsetfromResponse(HttpEntity responseEntity) { + Header contentType = responseEntity.getContentType(); + if (contentType != null) { + String responseCharset = getCharsetFromContentType(contentType.getValue()); + if (responseCharset != null && !responseCharset.trim().equals("")) { + return responseCharset; + } + } + return "UTF-8"; + } + + public static byte[] getRawBody(HttpEntity responseEntity) { + try { + InputStream responseInputStream = responseEntity.getContent(); + if (isGzipped(responseEntity.getContentEncoding())) { + responseInputStream = new GZIPInputStream(responseEntity.getContent()); + } + return getBytes(responseInputStream); + } catch (IOException e2) { + throw new RuntimeException(e2); + } + } } From f750deb0bae2cb81ff41a08b5753741629083edd Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 23 Mar 2018 15:44:40 -0500 Subject: [PATCH 0063/1769] split out the creation of bodies for responses so we can do more kinds of things --- .../io/github/openunirest/http/BodyData.java | 61 +++++++ .../github/openunirest/http/HttpResponse.java | 22 ++- .../openunirest/http/ResponseBuilder.java | 19 ++ .../openunirest/http/utils/ResponseUtils.java | 6 +- .../openunirest/MockApacheResponse.java | 167 ++++++++++++++++++ .../io/github/openunirest/NotImplimented.java | 4 + .../openunirest/ResponseBuilderTest.java | 57 ++++++ .../github/openunirest/http/BinaryTests.java | 19 ++ .../io/github/openunirest/http/TestUtil.java | 11 ++ 9 files changed, 356 insertions(+), 10 deletions(-) create mode 100644 src/main/java/io/github/openunirest/http/BodyData.java create mode 100644 src/main/java/io/github/openunirest/http/ResponseBuilder.java create mode 100644 src/test/java/io/github/openunirest/MockApacheResponse.java create mode 100644 src/test/java/io/github/openunirest/NotImplimented.java create mode 100644 src/test/java/io/github/openunirest/ResponseBuilderTest.java create mode 100644 src/test/java/io/github/openunirest/http/BinaryTests.java diff --git a/src/main/java/io/github/openunirest/http/BodyData.java b/src/main/java/io/github/openunirest/http/BodyData.java new file mode 100644 index 000000000..366c7a080 --- /dev/null +++ b/src/main/java/io/github/openunirest/http/BodyData.java @@ -0,0 +1,61 @@ +package io.github.openunirest.http; + +import org.apache.http.HttpEntity; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.Objects; +import java.util.function.Function; + +import static io.github.openunirest.http.utils.ResponseUtils.getCharsetfromResponse; +import static io.github.openunirest.http.utils.ResponseUtils.getRawBody; + +public class BodyData { + + public static BodyData from(HttpEntity e, Function, T> transformer) { + if(Objects.isNull(e)){ + return new BodyData<>(); + } + BodyData d = new BodyData(e); + d.transformBody(transformer); + return d; + } + + private final String charset; + + private final byte[] rawBytes; + private final InputStream rawInput; + private T transFormedBody; + + private BodyData() { + charset = null; + rawBytes = null; + rawInput = null; + } + + private BodyData(HttpEntity entity) { + this.charset = getCharsetfromResponse(entity); + this.rawBytes = getRawBody(entity); + this.rawInput = new ByteArrayInputStream(rawBytes); + } + + public String getCharset() { + return charset; + } + + public byte[] getRawBytes() { + return rawBytes; + } + + public InputStream getRawInput() { + return rawInput; + } + + public T getTransFormedBody() { + return transFormedBody; + } + + private void transformBody(Function, T> transformer) { + this.transFormedBody = transformer.apply(this); + } +} diff --git a/src/main/java/io/github/openunirest/http/HttpResponse.java b/src/main/java/io/github/openunirest/http/HttpResponse.java index dce2459f1..2e2256884 100644 --- a/src/main/java/io/github/openunirest/http/HttpResponse.java +++ b/src/main/java/io/github/openunirest/http/HttpResponse.java @@ -40,22 +40,30 @@ a copy of this software and associated documentation files (the public class HttpResponse { private final Headers headers; - private int statusCode; - private String statusText; + private final int statusCode; + private final String statusText; + private InputStream rawBody; private Optional parsingError = Optional.empty(); private T body; - @SuppressWarnings("unchecked") - public HttpResponse(org.apache.http.HttpResponse response, Class responseClass) { - ObjectMapper objectMapper = (ObjectMapper) Options.getOption(Option.OBJECT_MAPPER); - + private HttpResponse(org.apache.http.HttpResponse response){ headers = new Headers(response.getAllHeaders()); - StatusLine statusLine = response.getStatusLine(); this.statusCode = statusLine.getStatusCode(); this.statusText = statusLine.getReasonPhrase(); + } + public HttpResponse(org.apache.http.HttpResponse response, BodyData data){ + this(response); + this.rawBody = data.getRawInput(); + this.body = data.getTransFormedBody(); + } + + public HttpResponse(org.apache.http.HttpResponse response, Class responseClass) { + this(response); + + ObjectMapper objectMapper = (ObjectMapper) Options.getOption(Option.OBJECT_MAPPER); HttpEntity responseEntity = response.getEntity(); if (responseEntity != null) { String charset = ResponseUtils.getCharsetfromResponse(responseEntity); diff --git a/src/main/java/io/github/openunirest/http/ResponseBuilder.java b/src/main/java/io/github/openunirest/http/ResponseBuilder.java new file mode 100644 index 000000000..d65d8d608 --- /dev/null +++ b/src/main/java/io/github/openunirest/http/ResponseBuilder.java @@ -0,0 +1,19 @@ +package io.github.openunirest.http; + + +import java.io.InputStream; + +import static io.github.openunirest.http.BodyData.from; + +public class ResponseBuilder { + private final org.apache.http.HttpResponse response; + + public ResponseBuilder(org.apache.http.HttpResponse response) { + this.response = response; + } + + public HttpResponse asBinary(){ + return new HttpResponse<>(response, from(response.getEntity(), BodyData::getRawInput)); + } + +} diff --git a/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java b/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java index 6f5d6fc9f..541dbb85a 100644 --- a/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java +++ b/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java @@ -74,11 +74,11 @@ public static String getCharsetfromResponse(HttpEntity responseEntity) { public static byte[] getRawBody(HttpEntity responseEntity) { try { - InputStream responseInputStream = responseEntity.getContent(); + InputStream is = responseEntity.getContent(); if (isGzipped(responseEntity.getContentEncoding())) { - responseInputStream = new GZIPInputStream(responseEntity.getContent()); + is = new GZIPInputStream(responseEntity.getContent()); } - return getBytes(responseInputStream); + return getBytes(is); } catch (IOException e2) { throw new RuntimeException(e2); } diff --git a/src/test/java/io/github/openunirest/MockApacheResponse.java b/src/test/java/io/github/openunirest/MockApacheResponse.java new file mode 100644 index 000000000..4cc2fe700 --- /dev/null +++ b/src/test/java/io/github/openunirest/MockApacheResponse.java @@ -0,0 +1,167 @@ +package io.github.openunirest; + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; +import org.apache.http.*; +import org.apache.http.entity.BasicHttpEntity; +import org.apache.http.message.BasicHeader; +import org.apache.http.message.BasicStatusLine; +import org.apache.http.params.HttpParams; + +import java.io.ByteArrayInputStream; +import java.util.Locale; +import java.util.stream.Collectors; + +public class MockApacheResponse implements HttpResponse { + private Multimap headers = HashMultimap.create(); + private StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("",1,1), 0, ""); + private BasicHttpEntity entity = make(""); + + @Override + public StatusLine getStatusLine() { + return statusLine; + } + + @Override + public void setStatusLine(StatusLine statusline) { + this.statusLine = statusline; + } + + @Override + public void setStatusLine(ProtocolVersion ver, int code) { + throw new NotImplimented(); + } + + @Override + public void setStatusLine(ProtocolVersion ver, int code, String reason) { + throw new NotImplimented(); + } + + @Override + public void setStatusCode(int code) throws IllegalStateException { + throw new NotImplimented(); + } + + @Override + public void setReasonPhrase(String reason) throws IllegalStateException { + throw new NotImplimented(); + } + + @Override + public HttpEntity getEntity() { + return entity; + } + + @Override + public void setEntity(HttpEntity entity) { + throw new NotImplimented(); + } + + @Override + public Locale getLocale() { + throw new NotImplimented(); + } + + @Override + public void setLocale(Locale loc) { + throw new NotImplimented(); + } + + @Override + public ProtocolVersion getProtocolVersion() { + throw new NotImplimented(); + } + + @Override + public boolean containsHeader(String name) { + throw new NotImplimented(); + } + + @Override + public Header[] getHeaders(String name) { + throw new NotImplimented(); + } + + @Override + public Header getFirstHeader(String name) { + throw new NotImplimented(); + } + + @Override + public Header getLastHeader(String name) { + throw new NotImplimented(); + } + + @Override + public Header[] getAllHeaders() { + return headers.entries().stream() + .map(e -> new BasicHeader(e.getKey(), e.getValue())) + .collect(Collectors.toList()) + .toArray(new Header[headers.values().size()]); + } + + @Override + public void addHeader(Header header) { + throw new NotImplimented(); + } + + @Override + public void addHeader(String name, String value) { + headers.put(name, value); + } + + @Override + public void setHeader(Header header) { + throw new NotImplimented(); + } + + @Override + public void setHeader(String name, String value) { + headers.put(name, value); + } + + @Override + public void setHeaders(Header[] headers) { + throw new NotImplimented(); + } + + @Override + public void removeHeader(Header header) { + throw new NotImplimented(); + } + + @Override + public void removeHeaders(String name) { + throw new NotImplimented(); + } + + @Override + public HeaderIterator headerIterator() { + throw new NotImplimented(); + } + + @Override + public HeaderIterator headerIterator(String name) { + throw new NotImplimented(); + } + + @Override + public HttpParams getParams() { + throw new NotImplimented(); + } + + @Override + public void setParams(HttpParams params) { + throw new NotImplimented(); + } + + public void setBody(String body) { + this.entity = make(body); + } + + public static BasicHttpEntity make(String body){ + BasicHttpEntity e = new BasicHttpEntity(); + e.setContent(new ByteArrayInputStream(body.getBytes())); + return e; + } +} diff --git a/src/test/java/io/github/openunirest/NotImplimented.java b/src/test/java/io/github/openunirest/NotImplimented.java new file mode 100644 index 000000000..7af0d99d3 --- /dev/null +++ b/src/test/java/io/github/openunirest/NotImplimented.java @@ -0,0 +1,4 @@ +package io.github.openunirest; + +public class NotImplimented extends RuntimeException { +} diff --git a/src/test/java/io/github/openunirest/ResponseBuilderTest.java b/src/test/java/io/github/openunirest/ResponseBuilderTest.java new file mode 100644 index 000000000..47a90009d --- /dev/null +++ b/src/test/java/io/github/openunirest/ResponseBuilderTest.java @@ -0,0 +1,57 @@ +package io.github.openunirest; + +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.ResponseBuilder; +import io.github.openunirest.http.TestUtil; +import org.apache.http.ProtocolVersion; +import org.apache.http.entity.BasicHttpEntity; +import org.apache.http.message.BasicStatusLine; +import org.junit.Before; +import org.junit.Test; + +import java.io.InputStream; + +import static org.hamcrest.CoreMatchers.hasItem; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +public class ResponseBuilderTest { + private MockApacheResponse response; + + @Before + public void setUp() { + response = new MockApacheResponse(); + } + + @Test + public void willStartOffWithHeaders() { + response.addHeader("foo", "bar"); + response.addHeader("foo", "baz"); + response.addHeader("qux", "zip"); + + HttpResponse r = new ResponseBuilder(response).asBinary(); + + assertThat(r.getHeaders().get("foo"), hasItem("bar")); + assertThat(r.getHeaders().get("qux"), hasItem("zip")); + } + + @Test + public void willPassInStatusCode() { + response.setStatusLine(new BasicStatusLine(new ProtocolVersion("http", 1, 2), + 418, "I am a teapot")); + + HttpResponse r = new ResponseBuilder(response).asBinary(); + + assertEquals(418, r.getStatus()); + assertEquals("I am a teapot", r.getStatusText()); + } + + @Test + public void canGetBinaryResponse() { + response.setBody("I like cheese"); + + HttpResponse r = new ResponseBuilder(response).asBinary(); + + assertEquals("I like cheese", TestUtil.toString(r.getBody())); + } +} \ No newline at end of file diff --git a/src/test/java/io/github/openunirest/http/BinaryTests.java b/src/test/java/io/github/openunirest/http/BinaryTests.java new file mode 100644 index 000000000..19057f22b --- /dev/null +++ b/src/test/java/io/github/openunirest/http/BinaryTests.java @@ -0,0 +1,19 @@ +package io.github.openunirest.http; + +import org.junit.Test; + +import java.io.IOException; +import java.io.InputStream; + +public class BinaryTests extends BddTest { + @Test + public void canGetBinaryResponse() throws IOException { + HttpResponse i = Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asBinary(); + + RequestCapture cap = TestUtil.readValue(i.getBody(), RequestCapture.class); + + cap.assertParam("foo", "bar"); + } +} diff --git a/src/test/java/io/github/openunirest/http/TestUtil.java b/src/test/java/io/github/openunirest/http/TestUtil.java index b3bcfe5e9..4b10d31ae 100644 --- a/src/test/java/io/github/openunirest/http/TestUtil.java +++ b/src/test/java/io/github/openunirest/http/TestUtil.java @@ -1,13 +1,24 @@ package io.github.openunirest.http; +import com.fasterxml.jackson.datatype.guava.GuavaModule; + import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.stream.Collectors; public class TestUtil { + private static final com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper(); + static { + om.registerModule(new GuavaModule()); + } public static String toString(InputStream is) { return new BufferedReader(new InputStreamReader(is)) .lines().collect(Collectors.joining("\n")); } + + public static T readValue(InputStream i, Class clss) throws IOException { + return om.readValue(i, clss); + } } From 71803bcd8e94c7aa54dd1c35c6eb600216b30043 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 23 Mar 2018 19:22:43 -0500 Subject: [PATCH 0064/1769] wire new response mapper into Binary --- .../openunirest/http/HttpClientHelper.java | 21 +++++++++++++++++++ .../openunirest/http/ResponseBuilder.java | 7 +------ .../openunirest/request/BaseRequest.java | 7 +++---- .../openunirest/ResponseBuilderTest.java | 8 +++---- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/HttpClientHelper.java b/src/main/java/io/github/openunirest/http/HttpClientHelper.java index 0566b6521..97c003a68 100644 --- a/src/main/java/io/github/openunirest/http/HttpClientHelper.java +++ b/src/main/java/io/github/openunirest/http/HttpClientHelper.java @@ -33,6 +33,7 @@ a copy of this software and associated documentation files (the import java.util.Objects; import java.util.Set; import java.util.concurrent.*; +import java.util.function.Function; import io.github.openunirest.http.async.CallbackFuture; import org.apache.http.HttpEntity; @@ -108,6 +109,26 @@ private static CloseableHttpAsyncClient asyncClient() { return asyncHttpClient; } + public static HttpResponse request(HttpRequest request, + Function> transformer) throws UnirestException { + HttpRequestBase requestObj = prepareRequest(request, false); + HttpClient client = ClientFactory.getHttpClient(); // The + // DefaultHttpClient + // is thread-safe + + org.apache.http.HttpResponse response; + try { + response = client.execute(requestObj); + HttpResponse httpResponse = transformer.apply(response); + requestObj.releaseConnection(); + return httpResponse; + } catch (Exception e) { + throw new UnirestException(e); + } finally { + requestObj.releaseConnection(); + } + } + public static HttpResponse request(HttpRequest request, Class responseClass) throws UnirestException { HttpRequestBase requestObj = prepareRequest(request, false); HttpClient client = ClientFactory.getHttpClient(); // The diff --git a/src/main/java/io/github/openunirest/http/ResponseBuilder.java b/src/main/java/io/github/openunirest/http/ResponseBuilder.java index d65d8d608..faa291146 100644 --- a/src/main/java/io/github/openunirest/http/ResponseBuilder.java +++ b/src/main/java/io/github/openunirest/http/ResponseBuilder.java @@ -6,13 +6,8 @@ import static io.github.openunirest.http.BodyData.from; public class ResponseBuilder { - private final org.apache.http.HttpResponse response; - public ResponseBuilder(org.apache.http.HttpResponse response) { - this.response = response; - } - - public HttpResponse asBinary(){ + public HttpResponse asBinary(org.apache.http.HttpResponse response){ return new HttpResponse<>(response, from(response.getEntity(), BodyData::getRawInput)); } diff --git a/src/main/java/io/github/openunirest/request/BaseRequest.java b/src/main/java/io/github/openunirest/request/BaseRequest.java index 7c52f5893..96b400cbd 100644 --- a/src/main/java/io/github/openunirest/request/BaseRequest.java +++ b/src/main/java/io/github/openunirest/request/BaseRequest.java @@ -25,9 +25,7 @@ a copy of this software and associated documentation files (the package io.github.openunirest.request; -import io.github.openunirest.http.HttpClientHelper; -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.JsonNode; +import io.github.openunirest.http.*; import io.github.openunirest.http.async.Callback; import io.github.openunirest.http.HttpClientHelper; import io.github.openunirest.http.HttpResponse; @@ -42,6 +40,7 @@ a copy of this software and associated documentation files (the public abstract class BaseRequest { protected static final String UTF_8 = "UTF-8"; + private final ResponseBuilder builder = new ResponseBuilder(); protected HttpRequest httpRequest; @@ -94,7 +93,7 @@ public CompletableFuture> asObjectAsync(Class r } public HttpResponse asBinary() throws UnirestException { - return HttpClientHelper.request(httpRequest, InputStream.class); + return HttpClientHelper.request(httpRequest, builder::asBinary); } public CompletableFuture> asBinaryAsync() { diff --git a/src/test/java/io/github/openunirest/ResponseBuilderTest.java b/src/test/java/io/github/openunirest/ResponseBuilderTest.java index 47a90009d..0c33912a8 100644 --- a/src/test/java/io/github/openunirest/ResponseBuilderTest.java +++ b/src/test/java/io/github/openunirest/ResponseBuilderTest.java @@ -4,7 +4,6 @@ import io.github.openunirest.http.ResponseBuilder; import io.github.openunirest.http.TestUtil; import org.apache.http.ProtocolVersion; -import org.apache.http.entity.BasicHttpEntity; import org.apache.http.message.BasicStatusLine; import org.junit.Before; import org.junit.Test; @@ -16,6 +15,7 @@ import static org.junit.Assert.assertThat; public class ResponseBuilderTest { + private final ResponseBuilder builder = new ResponseBuilder(); private MockApacheResponse response; @Before @@ -29,7 +29,7 @@ public void willStartOffWithHeaders() { response.addHeader("foo", "baz"); response.addHeader("qux", "zip"); - HttpResponse r = new ResponseBuilder(response).asBinary(); + HttpResponse r = builder.asBinary(response); assertThat(r.getHeaders().get("foo"), hasItem("bar")); assertThat(r.getHeaders().get("qux"), hasItem("zip")); @@ -40,7 +40,7 @@ public void willPassInStatusCode() { response.setStatusLine(new BasicStatusLine(new ProtocolVersion("http", 1, 2), 418, "I am a teapot")); - HttpResponse r = new ResponseBuilder(response).asBinary(); + HttpResponse r = builder.asBinary(response); assertEquals(418, r.getStatus()); assertEquals("I am a teapot", r.getStatusText()); @@ -50,7 +50,7 @@ public void willPassInStatusCode() { public void canGetBinaryResponse() { response.setBody("I like cheese"); - HttpResponse r = new ResponseBuilder(response).asBinary(); + HttpResponse r = builder.asBinary(response); assertEquals("I like cheese", TestUtil.toString(r.getBody())); } From b9fa64358820d7565224590bc2e4eeed1500de46 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 23 Mar 2018 19:31:08 -0500 Subject: [PATCH 0065/1769] add additional binary tests --- .../java/io/github/openunirest/http/BddTest.java | 10 +++++++--- .../http/{BinaryTests.java => BinaryTest.java} | 15 ++++++++++++++- .../java/io/github/openunirest/http/TestUtil.java | 8 ++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) rename src/test/java/io/github/openunirest/http/{BinaryTests.java => BinaryTest.java} (50%) diff --git a/src/test/java/io/github/openunirest/http/BddTest.java b/src/test/java/io/github/openunirest/http/BddTest.java index 0122af320..af36bfe26 100644 --- a/src/test/java/io/github/openunirest/http/BddTest.java +++ b/src/test/java/io/github/openunirest/http/BddTest.java @@ -24,9 +24,13 @@ public void setUp() { status = false; } - public void assertAsync() throws InterruptedException { - lock.await(5, TimeUnit.SECONDS); - assertTrue("Expected a async call but it never responded", status); + public void assertAsync() { + try { + lock.await(5, TimeUnit.SECONDS); + assertTrue("Expected a async call but it never responded", status); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } } public void assertFailed(String message) throws InterruptedException { diff --git a/src/test/java/io/github/openunirest/http/BinaryTests.java b/src/test/java/io/github/openunirest/http/BinaryTest.java similarity index 50% rename from src/test/java/io/github/openunirest/http/BinaryTests.java rename to src/test/java/io/github/openunirest/http/BinaryTest.java index 19057f22b..468d41450 100644 --- a/src/test/java/io/github/openunirest/http/BinaryTests.java +++ b/src/test/java/io/github/openunirest/http/BinaryTest.java @@ -5,7 +5,7 @@ import java.io.IOException; import java.io.InputStream; -public class BinaryTests extends BddTest { +public class BinaryTest extends BddTest { @Test public void canGetBinaryResponse() throws IOException { HttpResponse i = Unirest.get(MockServer.GET) @@ -16,4 +16,17 @@ public void canGetBinaryResponse() throws IOException { cap.assertParam("foo", "bar"); } + + @Test + public void canGetBinaryResponseAsync() { + Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asBinaryAsync(r -> { + RequestCapture cap = TestUtil.readValue(r.getBody(), RequestCapture.class); + cap.assertParam("foo", "bar"); + asyncSuccess(); + }); + + assertAsync(); + } } diff --git a/src/test/java/io/github/openunirest/http/TestUtil.java b/src/test/java/io/github/openunirest/http/TestUtil.java index 4b10d31ae..172b924bc 100644 --- a/src/test/java/io/github/openunirest/http/TestUtil.java +++ b/src/test/java/io/github/openunirest/http/TestUtil.java @@ -18,7 +18,11 @@ public static String toString(InputStream is) { .lines().collect(Collectors.joining("\n")); } - public static T readValue(InputStream i, Class clss) throws IOException { - return om.readValue(i, clss); + public static T readValue(InputStream i, Class clss) { + try { + return om.readValue(i, clss); + } catch (IOException e) { + throw new RuntimeException(e); + } } } From a13cb4a064c1295d854906d6f3903b23504290df Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 23 Mar 2018 19:34:18 -0500 Subject: [PATCH 0066/1769] binary test without callback --- .../io/github/openunirest/http/BinaryTest.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/test/java/io/github/openunirest/http/BinaryTest.java b/src/test/java/io/github/openunirest/http/BinaryTest.java index 468d41450..ed05f0a15 100644 --- a/src/test/java/io/github/openunirest/http/BinaryTest.java +++ b/src/test/java/io/github/openunirest/http/BinaryTest.java @@ -4,21 +4,32 @@ import java.io.IOException; import java.io.InputStream; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; public class BinaryTest extends BddTest { @Test - public void canGetBinaryResponse() throws IOException { + public void canGetBinaryResponse() { HttpResponse i = Unirest.get(MockServer.GET) .queryString("foo", "bar") .asBinary(); RequestCapture cap = TestUtil.readValue(i.getBody(), RequestCapture.class); + cap.assertParam("foo", "bar"); + } + + @Test + public void canGetBinaryResponseAsync() throws ExecutionException, InterruptedException { + CompletableFuture> r = Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asBinaryAsync(); + RequestCapture cap = TestUtil.readValue(r.get().getBody(), RequestCapture.class); cap.assertParam("foo", "bar"); } @Test - public void canGetBinaryResponseAsync() { + public void canGetBinaryResponseAsyncWithCallback() { Unirest.get(MockServer.GET) .queryString("foo", "bar") .asBinaryAsync(r -> { From fe9a22a9d912801f9b7a3778e23a41d9615ec616 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 24 Mar 2018 07:29:15 -0500 Subject: [PATCH 0067/1769] refactor to use new builders --- .../openunirest/http/HttpClientHelper.java | 232 ------------------ .../openunirest/request/BaseRequest.java | 9 +- .../openunirest/request/HttpClientHelper.java | 110 +++++++++ .../request/HttpClientHelper2.java | 88 +++++++ .../{http => request}/HttpDeleteWithBody.java | 2 +- .../{http => request}/HttpPatchWithBody.java | 2 +- .../openunirest/request/RequestPrep.java | 103 ++++++++ .../async => request}/RequestThread.java | 6 +- .../{http => request}/UriFormatter.java | 2 +- .../{http => request}/UriFormatterTest.java | 4 +- 10 files changed, 313 insertions(+), 245 deletions(-) delete mode 100644 src/main/java/io/github/openunirest/http/HttpClientHelper.java create mode 100644 src/main/java/io/github/openunirest/request/HttpClientHelper.java create mode 100644 src/main/java/io/github/openunirest/request/HttpClientHelper2.java rename src/main/java/io/github/openunirest/{http => request}/HttpDeleteWithBody.java (97%) rename src/main/java/io/github/openunirest/{http => request}/HttpPatchWithBody.java (97%) create mode 100644 src/main/java/io/github/openunirest/request/RequestPrep.java rename src/main/java/io/github/openunirest/{http/async => request}/RequestThread.java (93%) rename src/main/java/io/github/openunirest/{http => request}/UriFormatter.java (93%) rename src/test/java/io/github/openunirest/{http => request}/UriFormatterTest.java (87%) diff --git a/src/main/java/io/github/openunirest/http/HttpClientHelper.java b/src/main/java/io/github/openunirest/http/HttpClientHelper.java deleted file mode 100644 index 97c003a68..000000000 --- a/src/main/java/io/github/openunirest/http/HttpClientHelper.java +++ /dev/null @@ -1,232 +0,0 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package io.github.openunirest.http; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; -import java.util.concurrent.*; -import java.util.function.Function; - -import io.github.openunirest.http.async.CallbackFuture; -import org.apache.http.HttpEntity; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpHead; -import org.apache.http.client.methods.HttpOptions; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.client.methods.HttpRequestBase; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.concurrent.FutureCallback; -import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; -import org.apache.http.nio.entity.NByteArrayEntity; - -import io.github.openunirest.http.async.Callback; -import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; -import io.github.openunirest.http.exceptions.UnirestException; -import io.github.openunirest.http.options.Option; -import io.github.openunirest.http.options.Options; -import io.github.openunirest.http.utils.ClientFactory; -import io.github.openunirest.request.HttpRequest; - -public class HttpClientHelper { - - private static final String CONTENT_TYPE = "content-type"; - private static final String ACCEPT_ENCODING_HEADER = "accept-encoding"; - private static final String USER_AGENT_HEADER = "user-agent"; - private static final String USER_AGENT = "unirest-java/1.3.11"; - private static final UriFormatter uriFormatter = new UriFormatter(); - - public static CompletableFuture> requestAsync(HttpRequest request, final Class responseClass) { - return requestAsync(request, responseClass, new CompletableFuture<>()); - } - - public static CompletableFuture> requestAsync(HttpRequest request, final Class responseClass, Callback callback) { - return requestAsync(request, responseClass, CallbackFuture.wrap(callback)); - } - - public static CompletableFuture> requestAsync(HttpRequest request, final Class responseClass, CompletableFuture> callback) { - Objects.requireNonNull(callback); - - HttpUriRequest requestObj = prepareRequest(request, true); - - asyncClient() - .execute(requestObj, new FutureCallback() { - @Override - public void completed(org.apache.http.HttpResponse httpResponse) { - callback.complete(new HttpResponse<>(httpResponse, responseClass)); - } - - @Override - public void failed(Exception e) { - callback.completeExceptionally(e); - } - - @Override - public void cancelled() { - callback.completeExceptionally(new UnirestException("canceled")); - } - }); - return callback; - } - - private static CloseableHttpAsyncClient asyncClient() { - CloseableHttpAsyncClient asyncHttpClient = ClientFactory.getAsyncHttpClient(); - if (!asyncHttpClient.isRunning()) { - asyncHttpClient.start(); - AsyncIdleConnectionMonitorThread asyncIdleConnectionMonitorThread = (AsyncIdleConnectionMonitorThread) Options.getOption(Option.ASYNC_MONITOR); - asyncIdleConnectionMonitorThread.start(); - } - return asyncHttpClient; - } - - public static HttpResponse request(HttpRequest request, - Function> transformer) throws UnirestException { - HttpRequestBase requestObj = prepareRequest(request, false); - HttpClient client = ClientFactory.getHttpClient(); // The - // DefaultHttpClient - // is thread-safe - - org.apache.http.HttpResponse response; - try { - response = client.execute(requestObj); - HttpResponse httpResponse = transformer.apply(response); - requestObj.releaseConnection(); - return httpResponse; - } catch (Exception e) { - throw new UnirestException(e); - } finally { - requestObj.releaseConnection(); - } - } - - public static HttpResponse request(HttpRequest request, Class responseClass) throws UnirestException { - HttpRequestBase requestObj = prepareRequest(request, false); - HttpClient client = ClientFactory.getHttpClient(); // The - // DefaultHttpClient - // is thread-safe - - org.apache.http.HttpResponse response; - try { - response = client.execute(requestObj); - HttpResponse httpResponse = new HttpResponse(response, responseClass); - requestObj.releaseConnection(); - return httpResponse; - } catch (Exception e) { - throw new UnirestException(e); - } finally { - requestObj.releaseConnection(); - } - } - - private static HttpRequestBase prepareRequest(HttpRequest request, boolean async) { - - Object defaultHeaders = Options.getOption(Option.DEFAULT_HEADERS); - if (defaultHeaders != null) { - @SuppressWarnings("unchecked") - Set> entrySet = ((Map) defaultHeaders).entrySet(); - for (Entry entry : entrySet) { - request.header(entry.getKey(), entry.getValue()); - } - } - - if (!request.getHeaders().containsKey(USER_AGENT_HEADER)) { - request.header(USER_AGENT_HEADER, USER_AGENT); - } - if (!request.getHeaders().containsKey(ACCEPT_ENCODING_HEADER)) { - request.header(ACCEPT_ENCODING_HEADER, "gzip"); - } - - HttpRequestBase reqObj = null; - - String urlToRequest = uriFormatter.apply(request); - - switch (request.getHttpMethod()) { - case GET: - reqObj = new HttpGet(urlToRequest); - break; - case POST: - reqObj = new HttpPost(urlToRequest); - break; - case PUT: - reqObj = new HttpPut(urlToRequest); - break; - case DELETE: - reqObj = new HttpDeleteWithBody(urlToRequest); - break; - case PATCH: - reqObj = new HttpPatchWithBody(urlToRequest); - break; - case OPTIONS: - reqObj = new HttpOptions(urlToRequest); - break; - case HEAD: - reqObj = new HttpHead(urlToRequest); - break; - } - - Set>> entrySet = request.getHeaders().entrySet(); - for (Entry> entry : entrySet) { - List values = entry.getValue(); - if (values != null) { - for (String value : values) { - reqObj.addHeader(entry.getKey(), value); - } - } - } - - // Set body - if (!(request.getHttpMethod() == HttpMethod.GET || request.getHttpMethod() == HttpMethod.HEAD)) { - if (request.getBody() != null) { - HttpEntity entity = request.getBody().getEntity(); - if (async) { - if (reqObj.getHeaders(CONTENT_TYPE) == null || reqObj.getHeaders(CONTENT_TYPE).length == 0) { - reqObj.setHeader(entity.getContentType()); - } - try { - ByteArrayOutputStream output = new ByteArrayOutputStream(); - entity.writeTo(output); - NByteArrayEntity en = new NByteArrayEntity(output.toByteArray()); - ((HttpEntityEnclosingRequestBase) reqObj).setEntity(en); - } catch (IOException e) { - throw new RuntimeException(e); - } - } else { - ((HttpEntityEnclosingRequestBase) reqObj).setEntity(entity); - } - } - } - - return reqObj; - } - -} diff --git a/src/main/java/io/github/openunirest/request/BaseRequest.java b/src/main/java/io/github/openunirest/request/BaseRequest.java index 96b400cbd..d402e91de 100644 --- a/src/main/java/io/github/openunirest/request/BaseRequest.java +++ b/src/main/java/io/github/openunirest/request/BaseRequest.java @@ -27,15 +27,12 @@ a copy of this software and associated documentation files (the import io.github.openunirest.http.*; import io.github.openunirest.http.async.Callback; -import io.github.openunirest.http.HttpClientHelper; import io.github.openunirest.http.HttpResponse; import io.github.openunirest.http.JsonNode; -import io.github.openunirest.http.async.Callback; import io.github.openunirest.http.exceptions.UnirestException; import java.io.InputStream; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Future; public abstract class BaseRequest { @@ -93,14 +90,14 @@ public CompletableFuture> asObjectAsync(Class r } public HttpResponse asBinary() throws UnirestException { - return HttpClientHelper.request(httpRequest, builder::asBinary); + return HttpClientHelper2.request(httpRequest, builder::asBinary); } public CompletableFuture> asBinaryAsync() { - return HttpClientHelper.requestAsync(httpRequest, InputStream.class); + return HttpClientHelper2.requestAsync(httpRequest, builder::asBinary); } public CompletableFuture> asBinaryAsync(Callback callback) { - return HttpClientHelper.requestAsync(httpRequest, InputStream.class, callback); + return HttpClientHelper2.requestAsync(httpRequest, builder::asBinary, callback); } } diff --git a/src/main/java/io/github/openunirest/request/HttpClientHelper.java b/src/main/java/io/github/openunirest/request/HttpClientHelper.java new file mode 100644 index 000000000..2134f9a25 --- /dev/null +++ b/src/main/java/io/github/openunirest/request/HttpClientHelper.java @@ -0,0 +1,110 @@ +/* +The MIT License + +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package io.github.openunirest.request; + +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.async.Callback; +import io.github.openunirest.http.async.CallbackFuture; +import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; +import io.github.openunirest.http.exceptions.UnirestException; +import io.github.openunirest.http.options.Option; +import io.github.openunirest.http.options.Options; +import io.github.openunirest.http.utils.ClientFactory; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.concurrent.FutureCallback; +import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; + +import java.util.Objects; +import java.util.concurrent.CompletableFuture; + +class HttpClientHelper { + + public static CompletableFuture> requestAsync(HttpRequest request, final Class responseClass) { + return requestAsync(request, responseClass, new CompletableFuture<>()); + } + + public static CompletableFuture> requestAsync(HttpRequest request, final Class responseClass, Callback callback) { + return requestAsync(request, responseClass, CallbackFuture.wrap(callback)); + } + + public static CompletableFuture> requestAsync(HttpRequest request, final Class responseClass, CompletableFuture> callback) { + Objects.requireNonNull(callback); + + HttpUriRequest requestObj = RequestPrep.prepareRequest(request, true); + + asyncClient() + .execute(requestObj, new FutureCallback() { + @Override + public void completed(org.apache.http.HttpResponse httpResponse) { + callback.complete(new HttpResponse<>(httpResponse, responseClass)); + } + + @Override + public void failed(Exception e) { + callback.completeExceptionally(e); + } + + @Override + public void cancelled() { + callback.completeExceptionally(new UnirestException("canceled")); + } + }); + return callback; + } + + private static CloseableHttpAsyncClient asyncClient() { + CloseableHttpAsyncClient asyncHttpClient = ClientFactory.getAsyncHttpClient(); + if (!asyncHttpClient.isRunning()) { + asyncHttpClient.start(); + AsyncIdleConnectionMonitorThread asyncIdleConnectionMonitorThread = (AsyncIdleConnectionMonitorThread) Options.getOption(Option.ASYNC_MONITOR); + asyncIdleConnectionMonitorThread.start(); + } + return asyncHttpClient; + } + + + + public static HttpResponse request(HttpRequest request, Class responseClass) throws UnirestException { + HttpRequestBase requestObj = RequestPrep.prepareRequest(request, false); + HttpClient client = ClientFactory.getHttpClient(); // The + // DefaultHttpClient + // is thread-safe + + org.apache.http.HttpResponse response; + try { + response = client.execute(requestObj); + HttpResponse httpResponse = new HttpResponse(response, responseClass); + requestObj.releaseConnection(); + return httpResponse; + } catch (Exception e) { + throw new UnirestException(e); + } finally { + requestObj.releaseConnection(); + } + } +} diff --git a/src/main/java/io/github/openunirest/request/HttpClientHelper2.java b/src/main/java/io/github/openunirest/request/HttpClientHelper2.java new file mode 100644 index 000000000..67cc34bfa --- /dev/null +++ b/src/main/java/io/github/openunirest/request/HttpClientHelper2.java @@ -0,0 +1,88 @@ +package io.github.openunirest.request; + +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.async.Callback; +import io.github.openunirest.http.async.CallbackFuture; +import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; +import io.github.openunirest.http.exceptions.UnirestException; +import io.github.openunirest.http.options.Option; +import io.github.openunirest.http.options.Options; +import io.github.openunirest.http.utils.ClientFactory; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.concurrent.FutureCallback; +import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; + +import java.util.Objects; +import java.util.concurrent.CompletableFuture; +import java.util.function.Function; + +class HttpClientHelper2 { + + public static HttpResponse request(HttpRequest request, + Function> transformer) { + + HttpRequestBase requestObj = RequestPrep.prepareRequest(request, false); + HttpClient client = ClientFactory.getHttpClient(); // The + // DefaultHttpClient + // is thread-safe + + org.apache.http.HttpResponse response; + try { + response = client.execute(requestObj); + HttpResponse httpResponse = transformer.apply(response); + requestObj.releaseConnection(); + return httpResponse; + } catch (Exception e) { + throw new UnirestException(e); + } finally { + requestObj.releaseConnection(); + } + } + + public static CompletableFuture> requestAsync(HttpRequest httpRequest, Function> transformer) { + return requestAsync(httpRequest, transformer, new CompletableFuture<>()); + } + + public static CompletableFuture> requestAsync(HttpRequest request, Function> transformer, Callback callback) { + return requestAsync(request, transformer, CallbackFuture.wrap(callback)); + } + + public static CompletableFuture> requestAsync(HttpRequest request, + Function> transformer, + CompletableFuture> callback) { + Objects.requireNonNull(callback); + + HttpUriRequest requestObj = RequestPrep.prepareRequest(request, true); + + asyncClient() + .execute(requestObj, new FutureCallback() { + @Override + public void completed(org.apache.http.HttpResponse httpResponse) { + callback.complete(transformer.apply(httpResponse)); + } + + @Override + public void failed(Exception e) { + callback.completeExceptionally(e); + } + + @Override + public void cancelled() { + callback.completeExceptionally(new UnirestException("canceled")); + } + }); + return callback; + } + + private static CloseableHttpAsyncClient asyncClient() { + CloseableHttpAsyncClient asyncHttpClient = ClientFactory.getAsyncHttpClient(); + if (!asyncHttpClient.isRunning()) { + asyncHttpClient.start(); + AsyncIdleConnectionMonitorThread asyncIdleConnectionMonitorThread = (AsyncIdleConnectionMonitorThread) Options.getOption(Option.ASYNC_MONITOR); + asyncIdleConnectionMonitorThread.start(); + } + return asyncHttpClient; + } +} diff --git a/src/main/java/io/github/openunirest/http/HttpDeleteWithBody.java b/src/main/java/io/github/openunirest/request/HttpDeleteWithBody.java similarity index 97% rename from src/main/java/io/github/openunirest/http/HttpDeleteWithBody.java rename to src/main/java/io/github/openunirest/request/HttpDeleteWithBody.java index 7f3f40399..e7c132f16 100644 --- a/src/main/java/io/github/openunirest/http/HttpDeleteWithBody.java +++ b/src/main/java/io/github/openunirest/request/HttpDeleteWithBody.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.http; +package io.github.openunirest.request; import java.net.URI; diff --git a/src/main/java/io/github/openunirest/http/HttpPatchWithBody.java b/src/main/java/io/github/openunirest/request/HttpPatchWithBody.java similarity index 97% rename from src/main/java/io/github/openunirest/http/HttpPatchWithBody.java rename to src/main/java/io/github/openunirest/request/HttpPatchWithBody.java index a2bb8b635..14459e5e3 100644 --- a/src/main/java/io/github/openunirest/http/HttpPatchWithBody.java +++ b/src/main/java/io/github/openunirest/request/HttpPatchWithBody.java @@ -23,7 +23,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.http; +package io.github.openunirest.request; import java.net.URI; diff --git a/src/main/java/io/github/openunirest/request/RequestPrep.java b/src/main/java/io/github/openunirest/request/RequestPrep.java new file mode 100644 index 000000000..4f83bc3a6 --- /dev/null +++ b/src/main/java/io/github/openunirest/request/RequestPrep.java @@ -0,0 +1,103 @@ +package io.github.openunirest.request; + +import io.github.openunirest.http.HttpMethod; +import io.github.openunirest.http.options.Option; +import io.github.openunirest.http.options.Options; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.*; +import org.apache.http.nio.entity.NByteArrayEntity; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Set; + +class RequestPrep { + private static final String CONTENT_TYPE = "content-type"; + private static final String ACCEPT_ENCODING_HEADER = "accept-encoding"; + private static final String USER_AGENT_HEADER = "user-agent"; + private static final String USER_AGENT = "unirest-java/1.3.11"; + private static final UriFormatter uriFormatter = new UriFormatter(); + + public static HttpRequestBase prepareRequest(HttpRequest request, boolean async) { + + Object defaultHeaders = Options.getOption(Option.DEFAULT_HEADERS); + if (defaultHeaders != null) { + @SuppressWarnings("unchecked") + Set> entrySet = ((Map) defaultHeaders).entrySet(); + for (Map.Entry entry : entrySet) { + request.header(entry.getKey(), entry.getValue()); + } + } + + if (!request.getHeaders().containsKey(USER_AGENT_HEADER)) { + request.header(USER_AGENT_HEADER, USER_AGENT); + } + if (!request.getHeaders().containsKey(ACCEPT_ENCODING_HEADER)) { + request.header(ACCEPT_ENCODING_HEADER, "gzip"); + } + + HttpRequestBase reqObj = null; + + String urlToRequest = uriFormatter.apply(request); + + switch (request.getHttpMethod()) { + case GET: + reqObj = new HttpGet(urlToRequest); + break; + case POST: + reqObj = new HttpPost(urlToRequest); + break; + case PUT: + reqObj = new HttpPut(urlToRequest); + break; + case DELETE: + reqObj = new HttpDeleteWithBody(urlToRequest); + break; + case PATCH: + reqObj = new HttpPatchWithBody(urlToRequest); + break; + case OPTIONS: + reqObj = new HttpOptions(urlToRequest); + break; + case HEAD: + reqObj = new HttpHead(urlToRequest); + break; + } + + Set>> entrySet = request.getHeaders().entrySet(); + for (Map.Entry> entry : entrySet) { + List values = entry.getValue(); + if (values != null) { + for (String value : values) { + reqObj.addHeader(entry.getKey(), value); + } + } + } + + // Set body + if (!(request.getHttpMethod() == HttpMethod.GET || request.getHttpMethod() == HttpMethod.HEAD)) { + if (request.getBody() != null) { + HttpEntity entity = request.getBody().getEntity(); + if (async) { + if (reqObj.getHeaders(CONTENT_TYPE) == null || reqObj.getHeaders(CONTENT_TYPE).length == 0) { + reqObj.setHeader(entity.getContentType()); + } + try { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + entity.writeTo(output); + NByteArrayEntity en = new NByteArrayEntity(output.toByteArray()); + ((HttpEntityEnclosingRequestBase) reqObj).setEntity(en); + } catch (IOException e) { + throw new RuntimeException(e); + } + } else { + ((HttpEntityEnclosingRequestBase) reqObj).setEntity(entity); + } + } + } + + return reqObj; + } +} diff --git a/src/main/java/io/github/openunirest/http/async/RequestThread.java b/src/main/java/io/github/openunirest/request/RequestThread.java similarity index 93% rename from src/main/java/io/github/openunirest/http/async/RequestThread.java rename to src/main/java/io/github/openunirest/request/RequestThread.java index e1010b7bf..1a7e7623c 100644 --- a/src/main/java/io/github/openunirest/http/async/RequestThread.java +++ b/src/main/java/io/github/openunirest/request/RequestThread.java @@ -23,10 +23,10 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.http.async; +package io.github.openunirest.request; -import io.github.openunirest.http.HttpClientHelper; -import io.github.openunirest.http.HttpClientHelper; +import io.github.openunirest.http.async.Callback; +import io.github.openunirest.request.HttpClientHelper; import io.github.openunirest.http.HttpResponse; import io.github.openunirest.http.exceptions.UnirestException; import io.github.openunirest.request.HttpRequest; diff --git a/src/main/java/io/github/openunirest/http/UriFormatter.java b/src/main/java/io/github/openunirest/request/UriFormatter.java similarity index 93% rename from src/main/java/io/github/openunirest/http/UriFormatter.java rename to src/main/java/io/github/openunirest/request/UriFormatter.java index daa028ca4..2215b484d 100644 --- a/src/main/java/io/github/openunirest/http/UriFormatter.java +++ b/src/main/java/io/github/openunirest/request/UriFormatter.java @@ -1,4 +1,4 @@ -package io.github.openunirest.http; +package io.github.openunirest.request; import io.github.openunirest.http.exceptions.UnirestException; import io.github.openunirest.request.HttpRequest; diff --git a/src/test/java/io/github/openunirest/http/UriFormatterTest.java b/src/test/java/io/github/openunirest/request/UriFormatterTest.java similarity index 87% rename from src/test/java/io/github/openunirest/http/UriFormatterTest.java rename to src/test/java/io/github/openunirest/request/UriFormatterTest.java index c01a5d85a..0cd71b7da 100644 --- a/src/test/java/io/github/openunirest/http/UriFormatterTest.java +++ b/src/test/java/io/github/openunirest/request/UriFormatterTest.java @@ -1,6 +1,8 @@ -package io.github.openunirest.http; +package io.github.openunirest.request; +import io.github.openunirest.http.HttpMethod; import io.github.openunirest.request.HttpRequest; +import io.github.openunirest.request.UriFormatter; import org.junit.Test; import static org.junit.Assert.*; From 9403da38b61f61cc15b2cbaca7ae0921c8e7ad56 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 24 Mar 2018 09:53:52 -0500 Subject: [PATCH 0068/1769] added some tests for the asObject methods in order to refactor them --- .../openunirest/http/ObjectMapperTest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/test/java/io/github/openunirest/http/ObjectMapperTest.java diff --git a/src/test/java/io/github/openunirest/http/ObjectMapperTest.java b/src/test/java/io/github/openunirest/http/ObjectMapperTest.java new file mode 100644 index 000000000..c56c573d2 --- /dev/null +++ b/src/test/java/io/github/openunirest/http/ObjectMapperTest.java @@ -0,0 +1,39 @@ +package io.github.openunirest.http; + +import org.junit.Test; + +import java.util.concurrent.ExecutionException; + +public class ObjectMapperTest extends BddTest { + @Test + public void canGetObjectResponse() { + Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asObject(RequestCapture.class) + .getBody() + .assertParam("foo", "bar"); + } + + @Test + public void canGetObjectResponseAsync() throws ExecutionException, InterruptedException { + Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asObjectAsync(RequestCapture.class) + .get() + .getBody() + .assertParam("foo", "bar"); + } + + @Test + public void canGetObjectResponseAsyncWithCallback() { + Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asObjectAsync(RequestCapture.class, r -> { + RequestCapture cap = r.getBody(); + cap.assertParam("foo", "bar"); + asyncSuccess(); + }); + + assertAsync(); + } +} From 15189e21b05ab87c2c0b0c3ff7588287fbbdabf0 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 24 Mar 2018 10:21:23 -0500 Subject: [PATCH 0069/1769] little method to make getting options easier --- .../openunirest/http/options/Options.java | 10 ++++++++ .../openunirest/http/options/OptionsTest.java | 25 ++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/options/Options.java b/src/main/java/io/github/openunirest/http/options/Options.java index c8f6659e8..0e46d9d4b 100644 --- a/src/main/java/io/github/openunirest/http/options/Options.java +++ b/src/main/java/io/github/openunirest/http/options/Options.java @@ -2,6 +2,8 @@ import java.util.HashMap; import java.util.Map; +import java.util.Objects; +import java.util.Optional; import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; import io.github.openunirest.http.utils.SyncIdleConnectionMonitorThread; @@ -129,4 +131,12 @@ private static void setDefaults() { setOption(Option.MAX_PER_ROUTE, MAX_PER_ROUTE); setOption(Option.SYNC_MONITOR, defaultSyncMonitor); } + + public static Optional tryGet(Option option, Class as) { + Object o = getOption(option); + if(Objects.isNull(o) || !as.isAssignableFrom(o.getClass())){ + return Optional.empty(); + } + return Optional.of((T) o); + } } diff --git a/src/test/java/io/github/openunirest/http/options/OptionsTest.java b/src/test/java/io/github/openunirest/http/options/OptionsTest.java index c97ef099c..e452c06e2 100644 --- a/src/test/java/io/github/openunirest/http/options/OptionsTest.java +++ b/src/test/java/io/github/openunirest/http/options/OptionsTest.java @@ -1,5 +1,8 @@ package io.github.openunirest.http.options; +import io.github.openunirest.http.JacksonObjectMapper; +import io.github.openunirest.http.ObjectMapper; +import io.github.openunirest.http.Unirest; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -38,16 +41,26 @@ public void shouldKeepMaxPerRouteDefault(){ assertOpDefault(Options.MAX_PER_ROUTE, Option.MAX_PER_ROUTE, 4); } - private void assertOpDefault(Object defValue, Option option, Object newValue) { - assertEquals(defValue, Options.getOption(option)); - Options.setOption(option, newValue); - assertEquals(newValue, Options.getOption(option)); - } - @Test public void shouldReuseThreadPool() { int startingCount = ManagementFactory.getThreadMXBean().getThreadCount(); IntStream.range(0,100).forEach(i -> Options.refresh()); assertThat(ManagementFactory.getThreadMXBean().getThreadCount(), is(lessThan(startingCount + 10))); } + + @Test + public void canTryGet(){ + assertEquals(false, Options.tryGet(Option.OBJECT_MAPPER, ObjectMapper.class).isPresent()); + Options.setOption(Option.OBJECT_MAPPER, "foo"); + assertEquals(false, Options.tryGet(Option.OBJECT_MAPPER, ObjectMapper.class).isPresent()); + JacksonObjectMapper value = new JacksonObjectMapper(); + Options.setOption(Option.OBJECT_MAPPER, value); + assertEquals(value, Options.tryGet(Option.OBJECT_MAPPER, ObjectMapper.class).get()); + } + + private void assertOpDefault(Object defValue, Option option, Object newValue) { + assertEquals(defValue, Options.getOption(option)); + Options.setOption(option, newValue); + assertEquals(newValue, Options.getOption(option)); + } } \ No newline at end of file From bfb17e636868a543376cd515440f2a736b5c0083 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 24 Mar 2018 11:19:21 -0500 Subject: [PATCH 0070/1769] response builder can do objects --- .../io/github/openunirest/http/BodyData.java | 14 ++++++- .../github/openunirest/http/HttpResponse.java | 1 + .../openunirest/http/ResponseBuilder.java | 29 +++++++++++++ .../openunirest/http/options/Options.java | 4 ++ .../openunirest/ResponseBuilderTest.java | 41 +++++++++++++++++-- .../io/github/openunirest/http/TestUtil.java | 24 +++++++++++ 6 files changed, 109 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/BodyData.java b/src/main/java/io/github/openunirest/http/BodyData.java index 366c7a080..f0131a017 100644 --- a/src/main/java/io/github/openunirest/http/BodyData.java +++ b/src/main/java/io/github/openunirest/http/BodyData.java @@ -1,5 +1,6 @@ package io.github.openunirest.http; +import io.github.openunirest.http.exceptions.UnirestException; import org.apache.http.HttpEntity; import java.io.ByteArrayInputStream; @@ -26,6 +27,7 @@ public static BodyData from(HttpEntity e, Function, T> transf private final byte[] rawBytes; private final InputStream rawInput; private T transFormedBody; + private RuntimeException parseEx; private BodyData() { charset = null; @@ -55,7 +57,17 @@ public T getTransFormedBody() { return transFormedBody; } + public RuntimeException getParseEx() { + return parseEx; + } + private void transformBody(Function, T> transformer) { - this.transFormedBody = transformer.apply(this); + try { + this.transFormedBody = transformer.apply(this); + }catch (UnirestException e){ + throw e; + }catch (RuntimeException e){ + parseEx = e; + } } } diff --git a/src/main/java/io/github/openunirest/http/HttpResponse.java b/src/main/java/io/github/openunirest/http/HttpResponse.java index 2e2256884..c81524c82 100644 --- a/src/main/java/io/github/openunirest/http/HttpResponse.java +++ b/src/main/java/io/github/openunirest/http/HttpResponse.java @@ -58,6 +58,7 @@ public HttpResponse(org.apache.http.HttpResponse response, BodyData data){ this(response); this.rawBody = data.getRawInput(); this.body = data.getTransFormedBody(); + this.parsingError = Optional.ofNullable(data.getParseEx()); } public HttpResponse(org.apache.http.HttpResponse response, Class responseClass) { diff --git a/src/main/java/io/github/openunirest/http/ResponseBuilder.java b/src/main/java/io/github/openunirest/http/ResponseBuilder.java index faa291146..7a332f180 100644 --- a/src/main/java/io/github/openunirest/http/ResponseBuilder.java +++ b/src/main/java/io/github/openunirest/http/ResponseBuilder.java @@ -1,7 +1,12 @@ package io.github.openunirest.http; +import io.github.openunirest.http.exceptions.UnirestException; +import io.github.openunirest.http.options.Option; +import io.github.openunirest.http.options.Options; + import java.io.InputStream; +import java.io.UnsupportedEncodingException; import static io.github.openunirest.http.BodyData.from; @@ -11,4 +16,28 @@ public HttpResponse asBinary(org.apache.http.HttpResponse response) return new HttpResponse<>(response, from(response.getEntity(), BodyData::getRawInput)); } + public HttpResponse asObject(org.apache.http.HttpResponse response, Class aClass) { + return new HttpResponse<>(response, from(response.getEntity(), b -> toObject(b, aClass))); + } + + private T toObject(BodyData b, Class aClass) { + try { + ObjectMapper o = getObjectMapper(); + return o.readValue(new String(b.getRawBytes(), b.getCharset()), aClass); + } catch (UnsupportedEncodingException e) { + throw new ParsingException(e); + } + } + + private ObjectMapper getObjectMapper() { + return Options.tryGet(Option.OBJECT_MAPPER, ObjectMapper.class) + .orElseThrow(() -> new UnirestException("No Object Mapper Configured. Please configure one with Unirest.setObjectMapper")); + } + + + public static class ParsingException extends RuntimeException { + public ParsingException(Exception e){ + super(e); + } + } } diff --git a/src/main/java/io/github/openunirest/http/options/Options.java b/src/main/java/io/github/openunirest/http/options/Options.java index 0e46d9d4b..3e47e7b0a 100644 --- a/src/main/java/io/github/openunirest/http/options/Options.java +++ b/src/main/java/io/github/openunirest/http/options/Options.java @@ -139,4 +139,8 @@ public static Optional tryGet(Option option, Class as) { } return Optional.of((T) o); } + + public static void removeOption(Option objectMapper) { + options.remove(objectMapper); + } } diff --git a/src/test/java/io/github/openunirest/ResponseBuilderTest.java b/src/test/java/io/github/openunirest/ResponseBuilderTest.java index 0c33912a8..7568150b7 100644 --- a/src/test/java/io/github/openunirest/ResponseBuilderTest.java +++ b/src/test/java/io/github/openunirest/ResponseBuilderTest.java @@ -1,8 +1,9 @@ package io.github.openunirest; -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.ResponseBuilder; -import io.github.openunirest.http.TestUtil; +import io.github.openunirest.http.*; +import io.github.openunirest.http.exceptions.UnirestException; +import io.github.openunirest.http.options.Option; +import io.github.openunirest.http.options.Options; import org.apache.http.ProtocolVersion; import org.apache.http.message.BasicStatusLine; import org.junit.Before; @@ -10,6 +11,8 @@ import java.io.InputStream; +import static io.github.openunirest.http.TestUtil.assertException; +import static io.github.openunirest.http.TestUtil.toJson; import static org.hamcrest.CoreMatchers.hasItem; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; @@ -21,6 +24,7 @@ public class ResponseBuilderTest { @Before public void setUp() { response = new MockApacheResponse(); + Options.setOption(Option.OBJECT_MAPPER, new JacksonObjectMapper()); } @Test @@ -54,4 +58,35 @@ public void canGetBinaryResponse() { assertEquals("I like cheese", TestUtil.toString(r.getBody())); } + + @Test + public void canGetObjectMappedResponse() { + response.setBody(toJson(new Foo("I like cheese"))); + + HttpResponse r = builder.asObject(response, Foo.class); + + assertEquals("I like cheese", r.getBody().bar); + } + + @Test + public void willThrowErrorIfNoObjectMapperIsConfigured(){ + Options.removeOption(Option.OBJECT_MAPPER); + + response.setBody(toJson(new Foo("I like cheese"))); + + assertException(() -> builder.asObject(response, Foo.class), + UnirestException.class, + "No Object Mapper Configured. Please configure one with Unirest.setObjectMapper"); + } + + @Test + public void ifObjectMapperHasProblemParsingReturnTheError(){ + response.setBody("I like cheese"); + + HttpResponse foo = builder.asObject(response, Foo.class); + + assertEquals("com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'I': was expecting 'null', 'true', 'false' or NaN\n" + + " at [Source: (String)\"I like cheese\"; line: 1, column: 2]", + foo.getParsingError().get().getMessage()); + } } \ No newline at end of file diff --git a/src/test/java/io/github/openunirest/http/TestUtil.java b/src/test/java/io/github/openunirest/http/TestUtil.java index 172b924bc..6c657e2b7 100644 --- a/src/test/java/io/github/openunirest/http/TestUtil.java +++ b/src/test/java/io/github/openunirest/http/TestUtil.java @@ -1,5 +1,6 @@ package io.github.openunirest.http; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.datatype.guava.GuavaModule; import java.io.BufferedReader; @@ -8,6 +9,9 @@ import java.io.InputStreamReader; import java.util.stream.Collectors; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + public class TestUtil { private static final com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper(); static { @@ -25,4 +29,24 @@ public static T readValue(InputStream i, Class clss) { throw new RuntimeException(e); } } + + public static String toJson(Object o) { + try { + return om.writeValueAsString(o); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + public static void assertException(Runnable runnable, Class exClass, String message) { + try{ + runnable.run(); + fail("Expected exception but got none. \nExpected " + exClass); + } catch (Exception e){ + if (!e.getClass().isAssignableFrom(exClass)) { + fail("Expected wrong exception type \n Expected: " + exClass + "\n but got " + e.getClass()); + } + assertEquals("Wrong Error Message", message, e.getMessage()); + } + } } From 44cb8f4e8a46ade6684dcfae355413aa949cd977 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 24 Mar 2018 11:28:18 -0500 Subject: [PATCH 0071/1769] switch asObject methods over to new response handler --- .../java/io/github/openunirest/http/ResponseBuilder.java | 4 ++-- .../java/io/github/openunirest/request/BaseRequest.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/ResponseBuilder.java b/src/main/java/io/github/openunirest/http/ResponseBuilder.java index 7a332f180..4f256e5af 100644 --- a/src/main/java/io/github/openunirest/http/ResponseBuilder.java +++ b/src/main/java/io/github/openunirest/http/ResponseBuilder.java @@ -16,11 +16,11 @@ public HttpResponse asBinary(org.apache.http.HttpResponse response) return new HttpResponse<>(response, from(response.getEntity(), BodyData::getRawInput)); } - public HttpResponse asObject(org.apache.http.HttpResponse response, Class aClass) { + public HttpResponse asObject(org.apache.http.HttpResponse response, Class aClass) { return new HttpResponse<>(response, from(response.getEntity(), b -> toObject(b, aClass))); } - private T toObject(BodyData b, Class aClass) { + private T toObject(BodyData b, Class aClass) { try { ObjectMapper o = getObjectMapper(); return o.readValue(new String(b.getRawBytes(), b.getCharset()), aClass); diff --git a/src/main/java/io/github/openunirest/request/BaseRequest.java b/src/main/java/io/github/openunirest/request/BaseRequest.java index d402e91de..a035920f7 100644 --- a/src/main/java/io/github/openunirest/request/BaseRequest.java +++ b/src/main/java/io/github/openunirest/request/BaseRequest.java @@ -78,15 +78,15 @@ public CompletableFuture> asJsonAsync(Callback } public HttpResponse asObject(Class responseClass) throws UnirestException { - return HttpClientHelper.request(httpRequest, (Class) responseClass); + return HttpClientHelper2.request(httpRequest, r -> builder.asObject(r, responseClass)); } public CompletableFuture> asObjectAsync(Class responseClass) { - return HttpClientHelper.requestAsync(httpRequest, (Class) responseClass); + return HttpClientHelper2.requestAsync(httpRequest, r -> builder.asObject(r, responseClass)); } public CompletableFuture> asObjectAsync(Class responseClass, Callback callback) { - return HttpClientHelper.requestAsync(httpRequest, (Class) responseClass, callback); + return HttpClientHelper2.requestAsync(httpRequest, r -> builder.asObject(r, responseClass), callback); } public HttpResponse asBinary() throws UnirestException { From e1f0574e2831032b2d259acea5d3d3ff306d41e3 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 24 Mar 2018 12:33:52 -0500 Subject: [PATCH 0072/1769] added asString tests --- .../github/openunirest/http/AsStringTest.java | 44 +++++++++++++++++++ .../github/openunirest/http/MockServer.java | 4 ++ .../io/github/openunirest/http/TestUtil.java | 8 ++++ 3 files changed, 56 insertions(+) create mode 100644 src/test/java/io/github/openunirest/http/AsStringTest.java diff --git a/src/test/java/io/github/openunirest/http/AsStringTest.java b/src/test/java/io/github/openunirest/http/AsStringTest.java new file mode 100644 index 000000000..34f740571 --- /dev/null +++ b/src/test/java/io/github/openunirest/http/AsStringTest.java @@ -0,0 +1,44 @@ +package io.github.openunirest.http; + +import org.junit.Test; + +import java.io.InputStream; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; + +public class AsStringTest extends BddTest { + + + @Test + public void canGetBinaryResponse() { + HttpResponse i = Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asString(); + + RequestCapture cap = TestUtil.readValue(i.getBody(), RequestCapture.class); + cap.assertParam("foo", "bar"); + } + + @Test + public void canGetBinaryResponseAsync() throws ExecutionException, InterruptedException { + CompletableFuture> r = Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asStringAsync(); + + RequestCapture cap = TestUtil.readValue(r.get().getBody(), RequestCapture.class); + cap.assertParam("foo", "bar"); + } + + @Test + public void canGetBinaryResponseAsyncWithCallback() { + Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asStringAsync(r -> { + RequestCapture cap = TestUtil.readValue(r.getBody(), RequestCapture.class); + cap.assertParam("foo", "bar"); + asyncSuccess(); + }); + + assertAsync(); + } +} diff --git a/src/test/java/io/github/openunirest/http/MockServer.java b/src/test/java/io/github/openunirest/http/MockServer.java index be2908091..59ed84161 100644 --- a/src/test/java/io/github/openunirest/http/MockServer.java +++ b/src/test/java/io/github/openunirest/http/MockServer.java @@ -88,4 +88,8 @@ private static Object jsonResponse(Request req, Response res) { public static void shutdown() { Spark.stop(); } + + public static void setStringResponse(String stringResponse) { + MockServer.responseBody = stringResponse; + } } diff --git a/src/test/java/io/github/openunirest/http/TestUtil.java b/src/test/java/io/github/openunirest/http/TestUtil.java index 6c657e2b7..e28b7a0d2 100644 --- a/src/test/java/io/github/openunirest/http/TestUtil.java +++ b/src/test/java/io/github/openunirest/http/TestUtil.java @@ -49,4 +49,12 @@ public static void assertException(Runnable runnable, Class assertEquals("Wrong Error Message", message, e.getMessage()); } } + + public static T readValue(String body, Class as) { + try { + return om.readValue(body, as); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } From 6ee3a013fa41c8cf32269af930e388570d6358ba Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 24 Mar 2018 12:34:39 -0500 Subject: [PATCH 0073/1769] rename tests --- .../openunirest/http/{BinaryTest.java => AsBinaryTest.java} | 2 +- .../http/{ObjectMapperTest.java => AsObjectTest.java} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/test/java/io/github/openunirest/http/{BinaryTest.java => AsBinaryTest.java} (96%) rename src/test/java/io/github/openunirest/http/{ObjectMapperTest.java => AsObjectTest.java} (95%) diff --git a/src/test/java/io/github/openunirest/http/BinaryTest.java b/src/test/java/io/github/openunirest/http/AsBinaryTest.java similarity index 96% rename from src/test/java/io/github/openunirest/http/BinaryTest.java rename to src/test/java/io/github/openunirest/http/AsBinaryTest.java index ed05f0a15..67b0c1d89 100644 --- a/src/test/java/io/github/openunirest/http/BinaryTest.java +++ b/src/test/java/io/github/openunirest/http/AsBinaryTest.java @@ -7,7 +7,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; -public class BinaryTest extends BddTest { +public class AsBinaryTest extends BddTest { @Test public void canGetBinaryResponse() { HttpResponse i = Unirest.get(MockServer.GET) diff --git a/src/test/java/io/github/openunirest/http/ObjectMapperTest.java b/src/test/java/io/github/openunirest/http/AsObjectTest.java similarity index 95% rename from src/test/java/io/github/openunirest/http/ObjectMapperTest.java rename to src/test/java/io/github/openunirest/http/AsObjectTest.java index c56c573d2..ebcc649ef 100644 --- a/src/test/java/io/github/openunirest/http/ObjectMapperTest.java +++ b/src/test/java/io/github/openunirest/http/AsObjectTest.java @@ -4,7 +4,7 @@ import java.util.concurrent.ExecutionException; -public class ObjectMapperTest extends BddTest { +public class AsObjectTest extends BddTest { @Test public void canGetObjectResponse() { Unirest.get(MockServer.GET) From 738f83b0f093f1a358a1d40a50db5b9dc43cd67d Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 24 Mar 2018 16:19:50 -0500 Subject: [PATCH 0074/1769] add AsString tests --- .../io/github/openunirest/http/ResponseBuilder.java | 12 ++++++++++-- .../io/github/openunirest/http/options/Options.java | 1 + .../io/github/openunirest/request/BaseRequest.java | 6 +++--- .../io/github/openunirest/ResponseBuilderTest.java | 9 +++++++++ .../io/github/openunirest/http/AsStringTest.java | 1 - 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/ResponseBuilder.java b/src/main/java/io/github/openunirest/http/ResponseBuilder.java index 4f256e5af..2a0dffc2a 100644 --- a/src/main/java/io/github/openunirest/http/ResponseBuilder.java +++ b/src/main/java/io/github/openunirest/http/ResponseBuilder.java @@ -20,10 +20,18 @@ public HttpResponse asObject(org.apache.http.HttpResponse response, Class return new HttpResponse<>(response, from(response.getEntity(), b -> toObject(b, aClass))); } + public HttpResponse asString(org.apache.http.HttpResponse response) { + return new HttpResponse<>(response, from(response.getEntity(), this::toString)); + } + private T toObject(BodyData b, Class aClass) { + ObjectMapper o = getObjectMapper(); + return o.readValue(toString(b), aClass); + } + + private String toString(BodyData b) { try { - ObjectMapper o = getObjectMapper(); - return o.readValue(new String(b.getRawBytes(), b.getCharset()), aClass); + return new String(b.getRawBytes(), b.getCharset()); } catch (UnsupportedEncodingException e) { throw new ParsingException(e); } diff --git a/src/main/java/io/github/openunirest/http/options/Options.java b/src/main/java/io/github/openunirest/http/options/Options.java index 3e47e7b0a..ddff8a2cd 100644 --- a/src/main/java/io/github/openunirest/http/options/Options.java +++ b/src/main/java/io/github/openunirest/http/options/Options.java @@ -125,6 +125,7 @@ public static void reset() { private static void setDefaults() { customClientSet = false; + options.clear(); setOption(Option.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT); setOption(Option.SOCKET_TIMEOUT, SOCKET_TIMEOUT); setOption(Option.MAX_TOTAL, MAX_TOTAL); diff --git a/src/main/java/io/github/openunirest/request/BaseRequest.java b/src/main/java/io/github/openunirest/request/BaseRequest.java index a035920f7..23590c2b7 100644 --- a/src/main/java/io/github/openunirest/request/BaseRequest.java +++ b/src/main/java/io/github/openunirest/request/BaseRequest.java @@ -54,15 +54,15 @@ protected BaseRequest() { } public HttpResponse asString() throws UnirestException { - return HttpClientHelper.request(httpRequest, String.class); + return HttpClientHelper2.request(httpRequest, builder::asString); } public CompletableFuture> asStringAsync() { - return HttpClientHelper.requestAsync(httpRequest, String.class); + return HttpClientHelper2.requestAsync(httpRequest, builder::asString); } public CompletableFuture> asStringAsync(Callback callback) { - return HttpClientHelper.requestAsync(httpRequest, String.class, callback); + return HttpClientHelper2.requestAsync(httpRequest, builder::asString, callback); } public HttpResponse asJson() throws UnirestException { diff --git a/src/test/java/io/github/openunirest/ResponseBuilderTest.java b/src/test/java/io/github/openunirest/ResponseBuilderTest.java index 7568150b7..59c0419f2 100644 --- a/src/test/java/io/github/openunirest/ResponseBuilderTest.java +++ b/src/test/java/io/github/openunirest/ResponseBuilderTest.java @@ -89,4 +89,13 @@ public void ifObjectMapperHasProblemParsingReturnTheError(){ " at [Source: (String)\"I like cheese\"; line: 1, column: 2]", foo.getParsingError().get().getMessage()); } + + @Test + public void canGetStringResponse() { + response.setBody("I like cheese"); + + HttpResponse r = builder.asString(response); + + assertEquals("I like cheese", r.getBody()); + } } \ No newline at end of file diff --git a/src/test/java/io/github/openunirest/http/AsStringTest.java b/src/test/java/io/github/openunirest/http/AsStringTest.java index 34f740571..5aeb0296c 100644 --- a/src/test/java/io/github/openunirest/http/AsStringTest.java +++ b/src/test/java/io/github/openunirest/http/AsStringTest.java @@ -2,7 +2,6 @@ import org.junit.Test; -import java.io.InputStream; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; From e020bf7b0d85b352caf2926531e96d9d62880014 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 24 Mar 2018 16:28:30 -0500 Subject: [PATCH 0075/1769] add asJson tests --- .../github/openunirest/http/AsJsonTest.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/test/java/io/github/openunirest/http/AsJsonTest.java diff --git a/src/test/java/io/github/openunirest/http/AsJsonTest.java b/src/test/java/io/github/openunirest/http/AsJsonTest.java new file mode 100644 index 000000000..1d11abe96 --- /dev/null +++ b/src/test/java/io/github/openunirest/http/AsJsonTest.java @@ -0,0 +1,44 @@ +package io.github.openunirest.http; + +import org.junit.Test; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; + +import static org.junit.Assert.assertEquals; + +public class AsJsonTest extends BddTest { + @Test + public void canGetBinaryResponse() { + HttpResponse i = Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asJson(); + + assertJson(i); + } + + @Test + public void canGetBinaryResponseAsync() throws ExecutionException, InterruptedException { + CompletableFuture> r = Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asJsonAsync(); + + assertJson(r.get()); + } + + @Test + public void canGetBinaryResponseAsyncWithCallback() { + Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asJsonAsync(r -> { + assertJson(r); + asyncSuccess(); + }); + + assertAsync(); + } + + private void assertJson(HttpResponse i) { + assertEquals("bar",i.getBody().getObject().getJSONObject("params").getJSONArray("foo").get(0)); + } +} From e087e73cc1084493814dd8e58bb5e150c3a884ff Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 24 Mar 2018 16:42:51 -0500 Subject: [PATCH 0076/1769] move json to new builder method --- .../openunirest/http/ResponseBuilder.java | 11 +++++++++- .../openunirest/request/BaseRequest.java | 6 +++--- .../openunirest/ResponseBuilderTest.java | 21 +++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/ResponseBuilder.java b/src/main/java/io/github/openunirest/http/ResponseBuilder.java index 2a0dffc2a..7795a894d 100644 --- a/src/main/java/io/github/openunirest/http/ResponseBuilder.java +++ b/src/main/java/io/github/openunirest/http/ResponseBuilder.java @@ -12,6 +12,10 @@ public class ResponseBuilder { + public HttpResponse asJson(org.apache.http.HttpResponse response) { + return new HttpResponse<>(response, from(response.getEntity(), b -> toJson(b))); + } + public HttpResponse asBinary(org.apache.http.HttpResponse response){ return new HttpResponse<>(response, from(response.getEntity(), BodyData::getRawInput)); } @@ -37,13 +41,18 @@ private String toString(BodyData b) { } } + private JsonNode toJson(BodyData b) { + String jsonString = toString(b); + return new JsonNode(jsonString); + } + private ObjectMapper getObjectMapper() { return Options.tryGet(Option.OBJECT_MAPPER, ObjectMapper.class) .orElseThrow(() -> new UnirestException("No Object Mapper Configured. Please configure one with Unirest.setObjectMapper")); } - public static class ParsingException extends RuntimeException { + public ParsingException(Exception e){ super(e); } diff --git a/src/main/java/io/github/openunirest/request/BaseRequest.java b/src/main/java/io/github/openunirest/request/BaseRequest.java index 23590c2b7..f1077b0d3 100644 --- a/src/main/java/io/github/openunirest/request/BaseRequest.java +++ b/src/main/java/io/github/openunirest/request/BaseRequest.java @@ -66,15 +66,15 @@ public CompletableFuture> asStringAsync(Callback ca } public HttpResponse asJson() throws UnirestException { - return HttpClientHelper.request(httpRequest, JsonNode.class); + return HttpClientHelper2.request(httpRequest, builder::asJson); } public CompletableFuture> asJsonAsync() { - return HttpClientHelper.requestAsync(httpRequest, JsonNode.class); + return HttpClientHelper2.requestAsync(httpRequest, builder::asJson); } public CompletableFuture> asJsonAsync(Callback callback) { - return HttpClientHelper.requestAsync(httpRequest, JsonNode.class, callback); + return HttpClientHelper2.requestAsync(httpRequest, builder::asJson, callback); } public HttpResponse asObject(Class responseClass) throws UnirestException { diff --git a/src/test/java/io/github/openunirest/ResponseBuilderTest.java b/src/test/java/io/github/openunirest/ResponseBuilderTest.java index 59c0419f2..e96611dbd 100644 --- a/src/test/java/io/github/openunirest/ResponseBuilderTest.java +++ b/src/test/java/io/github/openunirest/ResponseBuilderTest.java @@ -15,6 +15,7 @@ import static io.github.openunirest.http.TestUtil.toJson; import static org.hamcrest.CoreMatchers.hasItem; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; public class ResponseBuilderTest { @@ -98,4 +99,24 @@ public void canGetStringResponse() { assertEquals("I like cheese", r.getBody()); } + + @Test + public void canGetJsonResponse() { + response.setBody("{\"foo\": \"I like cheese\"}"); + + HttpResponse r = builder.asJson(response); + + assertEquals("I like cheese", r.getBody().getObject().get("foo")); + } + + @Test + public void willNotBlowUpOnError() { + response.setBody("I like cheese"); + + HttpResponse r = builder.asJson(response); + + assertNull(r.getBody()); + assertEquals("org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]", + r.getParsingError().get().getMessage()); + } } \ No newline at end of file From bbb12da0e89a968cf6548db2a01a63ea434a5365 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 24 Mar 2018 16:45:05 -0500 Subject: [PATCH 0077/1769] swap out old helper for new helper --- .../openunirest/request/BaseRequest.java | 24 +-- .../openunirest/request/HttpClientHelper.java | 154 ++++++++---------- .../request/HttpClientHelper2.java | 88 ---------- .../openunirest/request/RequestThread.java | 59 ------- 4 files changed, 78 insertions(+), 247 deletions(-) delete mode 100644 src/main/java/io/github/openunirest/request/HttpClientHelper2.java delete mode 100644 src/main/java/io/github/openunirest/request/RequestThread.java diff --git a/src/main/java/io/github/openunirest/request/BaseRequest.java b/src/main/java/io/github/openunirest/request/BaseRequest.java index f1077b0d3..8c787c2c9 100644 --- a/src/main/java/io/github/openunirest/request/BaseRequest.java +++ b/src/main/java/io/github/openunirest/request/BaseRequest.java @@ -54,50 +54,50 @@ protected BaseRequest() { } public HttpResponse asString() throws UnirestException { - return HttpClientHelper2.request(httpRequest, builder::asString); + return HttpClientHelper.request(httpRequest, builder::asString); } public CompletableFuture> asStringAsync() { - return HttpClientHelper2.requestAsync(httpRequest, builder::asString); + return HttpClientHelper.requestAsync(httpRequest, builder::asString); } public CompletableFuture> asStringAsync(Callback callback) { - return HttpClientHelper2.requestAsync(httpRequest, builder::asString, callback); + return HttpClientHelper.requestAsync(httpRequest, builder::asString, callback); } public HttpResponse asJson() throws UnirestException { - return HttpClientHelper2.request(httpRequest, builder::asJson); + return HttpClientHelper.request(httpRequest, builder::asJson); } public CompletableFuture> asJsonAsync() { - return HttpClientHelper2.requestAsync(httpRequest, builder::asJson); + return HttpClientHelper.requestAsync(httpRequest, builder::asJson); } public CompletableFuture> asJsonAsync(Callback callback) { - return HttpClientHelper2.requestAsync(httpRequest, builder::asJson, callback); + return HttpClientHelper.requestAsync(httpRequest, builder::asJson, callback); } public HttpResponse asObject(Class responseClass) throws UnirestException { - return HttpClientHelper2.request(httpRequest, r -> builder.asObject(r, responseClass)); + return HttpClientHelper.request(httpRequest, r -> builder.asObject(r, responseClass)); } public CompletableFuture> asObjectAsync(Class responseClass) { - return HttpClientHelper2.requestAsync(httpRequest, r -> builder.asObject(r, responseClass)); + return HttpClientHelper.requestAsync(httpRequest, r -> builder.asObject(r, responseClass)); } public CompletableFuture> asObjectAsync(Class responseClass, Callback callback) { - return HttpClientHelper2.requestAsync(httpRequest, r -> builder.asObject(r, responseClass), callback); + return HttpClientHelper.requestAsync(httpRequest, r -> builder.asObject(r, responseClass), callback); } public HttpResponse asBinary() throws UnirestException { - return HttpClientHelper2.request(httpRequest, builder::asBinary); + return HttpClientHelper.request(httpRequest, builder::asBinary); } public CompletableFuture> asBinaryAsync() { - return HttpClientHelper2.requestAsync(httpRequest, builder::asBinary); + return HttpClientHelper.requestAsync(httpRequest, builder::asBinary); } public CompletableFuture> asBinaryAsync(Callback callback) { - return HttpClientHelper2.requestAsync(httpRequest, builder::asBinary, callback); + return HttpClientHelper.requestAsync(httpRequest, builder::asBinary, callback); } } diff --git a/src/main/java/io/github/openunirest/request/HttpClientHelper.java b/src/main/java/io/github/openunirest/request/HttpClientHelper.java index 2134f9a25..b490e872c 100644 --- a/src/main/java/io/github/openunirest/request/HttpClientHelper.java +++ b/src/main/java/io/github/openunirest/request/HttpClientHelper.java @@ -1,28 +1,3 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - package io.github.openunirest.request; import io.github.openunirest.http.HttpResponse; @@ -41,70 +16,73 @@ a copy of this software and associated documentation files (the import java.util.Objects; import java.util.concurrent.CompletableFuture; +import java.util.function.Function; class HttpClientHelper { - public static CompletableFuture> requestAsync(HttpRequest request, final Class responseClass) { - return requestAsync(request, responseClass, new CompletableFuture<>()); - } - - public static CompletableFuture> requestAsync(HttpRequest request, final Class responseClass, Callback callback) { - return requestAsync(request, responseClass, CallbackFuture.wrap(callback)); - } - - public static CompletableFuture> requestAsync(HttpRequest request, final Class responseClass, CompletableFuture> callback) { - Objects.requireNonNull(callback); - - HttpUriRequest requestObj = RequestPrep.prepareRequest(request, true); - - asyncClient() - .execute(requestObj, new FutureCallback() { - @Override - public void completed(org.apache.http.HttpResponse httpResponse) { - callback.complete(new HttpResponse<>(httpResponse, responseClass)); - } - - @Override - public void failed(Exception e) { - callback.completeExceptionally(e); - } - - @Override - public void cancelled() { - callback.completeExceptionally(new UnirestException("canceled")); - } - }); - return callback; - } - - private static CloseableHttpAsyncClient asyncClient() { - CloseableHttpAsyncClient asyncHttpClient = ClientFactory.getAsyncHttpClient(); - if (!asyncHttpClient.isRunning()) { - asyncHttpClient.start(); - AsyncIdleConnectionMonitorThread asyncIdleConnectionMonitorThread = (AsyncIdleConnectionMonitorThread) Options.getOption(Option.ASYNC_MONITOR); - asyncIdleConnectionMonitorThread.start(); - } - return asyncHttpClient; - } - - - - public static HttpResponse request(HttpRequest request, Class responseClass) throws UnirestException { - HttpRequestBase requestObj = RequestPrep.prepareRequest(request, false); - HttpClient client = ClientFactory.getHttpClient(); // The - // DefaultHttpClient - // is thread-safe - - org.apache.http.HttpResponse response; - try { - response = client.execute(requestObj); - HttpResponse httpResponse = new HttpResponse(response, responseClass); - requestObj.releaseConnection(); - return httpResponse; - } catch (Exception e) { - throw new UnirestException(e); - } finally { - requestObj.releaseConnection(); - } - } + public static HttpResponse request(HttpRequest request, + Function> transformer) { + + HttpRequestBase requestObj = RequestPrep.prepareRequest(request, false); + HttpClient client = ClientFactory.getHttpClient(); // The + // DefaultHttpClient + // is thread-safe + + org.apache.http.HttpResponse response; + try { + response = client.execute(requestObj); + HttpResponse httpResponse = transformer.apply(response); + requestObj.releaseConnection(); + return httpResponse; + } catch (Exception e) { + throw new UnirestException(e); + } finally { + requestObj.releaseConnection(); + } + } + + public static CompletableFuture> requestAsync(HttpRequest httpRequest, Function> transformer) { + return requestAsync(httpRequest, transformer, new CompletableFuture<>()); + } + + public static CompletableFuture> requestAsync(HttpRequest request, Function> transformer, Callback callback) { + return requestAsync(request, transformer, CallbackFuture.wrap(callback)); + } + + public static CompletableFuture> requestAsync(HttpRequest request, + Function> transformer, + CompletableFuture> callback) { + Objects.requireNonNull(callback); + + HttpUriRequest requestObj = RequestPrep.prepareRequest(request, true); + + asyncClient() + .execute(requestObj, new FutureCallback() { + @Override + public void completed(org.apache.http.HttpResponse httpResponse) { + callback.complete(transformer.apply(httpResponse)); + } + + @Override + public void failed(Exception e) { + callback.completeExceptionally(e); + } + + @Override + public void cancelled() { + callback.completeExceptionally(new UnirestException("canceled")); + } + }); + return callback; + } + + private static CloseableHttpAsyncClient asyncClient() { + CloseableHttpAsyncClient asyncHttpClient = ClientFactory.getAsyncHttpClient(); + if (!asyncHttpClient.isRunning()) { + asyncHttpClient.start(); + AsyncIdleConnectionMonitorThread asyncIdleConnectionMonitorThread = (AsyncIdleConnectionMonitorThread) Options.getOption(Option.ASYNC_MONITOR); + asyncIdleConnectionMonitorThread.start(); + } + return asyncHttpClient; + } } diff --git a/src/main/java/io/github/openunirest/request/HttpClientHelper2.java b/src/main/java/io/github/openunirest/request/HttpClientHelper2.java deleted file mode 100644 index 67cc34bfa..000000000 --- a/src/main/java/io/github/openunirest/request/HttpClientHelper2.java +++ /dev/null @@ -1,88 +0,0 @@ -package io.github.openunirest.request; - -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.async.Callback; -import io.github.openunirest.http.async.CallbackFuture; -import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; -import io.github.openunirest.http.exceptions.UnirestException; -import io.github.openunirest.http.options.Option; -import io.github.openunirest.http.options.Options; -import io.github.openunirest.http.utils.ClientFactory; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpRequestBase; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.concurrent.FutureCallback; -import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; - -import java.util.Objects; -import java.util.concurrent.CompletableFuture; -import java.util.function.Function; - -class HttpClientHelper2 { - - public static HttpResponse request(HttpRequest request, - Function> transformer) { - - HttpRequestBase requestObj = RequestPrep.prepareRequest(request, false); - HttpClient client = ClientFactory.getHttpClient(); // The - // DefaultHttpClient - // is thread-safe - - org.apache.http.HttpResponse response; - try { - response = client.execute(requestObj); - HttpResponse httpResponse = transformer.apply(response); - requestObj.releaseConnection(); - return httpResponse; - } catch (Exception e) { - throw new UnirestException(e); - } finally { - requestObj.releaseConnection(); - } - } - - public static CompletableFuture> requestAsync(HttpRequest httpRequest, Function> transformer) { - return requestAsync(httpRequest, transformer, new CompletableFuture<>()); - } - - public static CompletableFuture> requestAsync(HttpRequest request, Function> transformer, Callback callback) { - return requestAsync(request, transformer, CallbackFuture.wrap(callback)); - } - - public static CompletableFuture> requestAsync(HttpRequest request, - Function> transformer, - CompletableFuture> callback) { - Objects.requireNonNull(callback); - - HttpUriRequest requestObj = RequestPrep.prepareRequest(request, true); - - asyncClient() - .execute(requestObj, new FutureCallback() { - @Override - public void completed(org.apache.http.HttpResponse httpResponse) { - callback.complete(transformer.apply(httpResponse)); - } - - @Override - public void failed(Exception e) { - callback.completeExceptionally(e); - } - - @Override - public void cancelled() { - callback.completeExceptionally(new UnirestException("canceled")); - } - }); - return callback; - } - - private static CloseableHttpAsyncClient asyncClient() { - CloseableHttpAsyncClient asyncHttpClient = ClientFactory.getAsyncHttpClient(); - if (!asyncHttpClient.isRunning()) { - asyncHttpClient.start(); - AsyncIdleConnectionMonitorThread asyncIdleConnectionMonitorThread = (AsyncIdleConnectionMonitorThread) Options.getOption(Option.ASYNC_MONITOR); - asyncIdleConnectionMonitorThread.start(); - } - return asyncHttpClient; - } -} diff --git a/src/main/java/io/github/openunirest/request/RequestThread.java b/src/main/java/io/github/openunirest/request/RequestThread.java deleted file mode 100644 index 1a7e7623c..000000000 --- a/src/main/java/io/github/openunirest/request/RequestThread.java +++ /dev/null @@ -1,59 +0,0 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package io.github.openunirest.request; - -import io.github.openunirest.http.async.Callback; -import io.github.openunirest.request.HttpClientHelper; -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.exceptions.UnirestException; -import io.github.openunirest.request.HttpRequest; - -public class RequestThread extends Thread { - - private HttpRequest httpRequest; - private Class responseClass; - private Callback callback; - - public RequestThread(HttpRequest httpRequest, Class responseClass, Callback callback) { - this.httpRequest = httpRequest; - this.responseClass = responseClass; - this.callback = callback; - } - - @Override - public void run() { - HttpResponse response; - try { - response = HttpClientHelper.request(httpRequest, responseClass); - if (callback != null) { - callback.completed(response); - } - } catch (UnirestException e) { - callback.failed(e); - } - } - -} From 4efcf862fcd754897d12e8ba1f4636d74e8c2587 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 25 Mar 2018 08:07:01 -0500 Subject: [PATCH 0078/1769] clean up dead legacy code --- .../github/openunirest/http/HttpResponse.java | 48 ------------------- 1 file changed, 48 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/HttpResponse.java b/src/main/java/io/github/openunirest/http/HttpResponse.java index c81524c82..63971a8e7 100644 --- a/src/main/java/io/github/openunirest/http/HttpResponse.java +++ b/src/main/java/io/github/openunirest/http/HttpResponse.java @@ -25,16 +25,9 @@ a copy of this software and associated documentation files (the package io.github.openunirest.http; -import io.github.openunirest.http.options.Option; -import io.github.openunirest.http.options.Options; -import io.github.openunirest.http.utils.ResponseUtils; -import org.apache.http.HttpEntity; import org.apache.http.StatusLine; -import org.apache.http.util.EntityUtils; -import java.io.ByteArrayInputStream; import java.io.InputStream; -import java.io.UnsupportedEncodingException; import java.util.Optional; public class HttpResponse { @@ -61,47 +54,6 @@ public HttpResponse(org.apache.http.HttpResponse response, BodyData data){ this.parsingError = Optional.ofNullable(data.getParseEx()); } - public HttpResponse(org.apache.http.HttpResponse response, Class responseClass) { - this(response); - - ObjectMapper objectMapper = (ObjectMapper) Options.getOption(Option.OBJECT_MAPPER); - HttpEntity responseEntity = response.getEntity(); - if (responseEntity != null) { - String charset = ResponseUtils.getCharsetfromResponse(responseEntity); - - try { - byte[] rawBody = ResponseUtils.getRawBody(responseEntity); - this.rawBody = new ByteArrayInputStream(rawBody); - - if (JsonNode.class.equals(responseClass)) { - tryParseAsJson(charset, rawBody); - } else if (String.class.equals(responseClass)) { - this.body = (T) new String(rawBody, charset); - } else if (InputStream.class.equals(responseClass)) { - this.body = (T) this.rawBody; - } else if (objectMapper != null) { - this.body = objectMapper.readValue(new String(rawBody, charset), responseClass); - } else { - throw new Exception("Only String, JsonNode and InputStream are supported, or an ObjectMapper implementation is required."); - } - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - EntityUtils.consumeQuietly(responseEntity); - } - - private void tryParseAsJson(String charset, byte[] rawBody) throws UnsupportedEncodingException { - try { - String jsonString = new String(rawBody, charset).trim(); - this.body = (T) new JsonNode(jsonString); - }catch (RuntimeException e){ - this.body = null; - this.parsingError = Optional.of(e); - } - } - public int getStatus() { return statusCode; } From ebac6eb3de808f062afa3880e3a25dc8446dd448 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 25 Mar 2018 11:37:35 -0500 Subject: [PATCH 0079/1769] no need to carry around the InputStream version of the body --- src/main/java/io/github/openunirest/http/BodyData.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/BodyData.java b/src/main/java/io/github/openunirest/http/BodyData.java index f0131a017..96375fbf0 100644 --- a/src/main/java/io/github/openunirest/http/BodyData.java +++ b/src/main/java/io/github/openunirest/http/BodyData.java @@ -25,20 +25,17 @@ public static BodyData from(HttpEntity e, Function, T> transf private final String charset; private final byte[] rawBytes; - private final InputStream rawInput; private T transFormedBody; private RuntimeException parseEx; private BodyData() { charset = null; rawBytes = null; - rawInput = null; } private BodyData(HttpEntity entity) { this.charset = getCharsetfromResponse(entity); this.rawBytes = getRawBody(entity); - this.rawInput = new ByteArrayInputStream(rawBytes); } public String getCharset() { @@ -50,7 +47,7 @@ public byte[] getRawBytes() { } public InputStream getRawInput() { - return rawInput; + return new ByteArrayInputStream(rawBytes); } public T getTransFormedBody() { From 99f1b0c5014fd5221fe46f71ffec6f70917edd0e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 25 Mar 2018 12:11:18 -0500 Subject: [PATCH 0080/1769] add some handy mapper methods --- .../io/github/openunirest/http/BodyData.java | 1 - .../github/openunirest/http/HttpResponse.java | 16 ++++++++++++ .../openunirest/http/HttpResponseTest.java | 26 +++++++++++++++++++ .../io/github/openunirest/http/TestUtil.java | 13 +++++++--- 4 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 src/test/java/io/github/openunirest/http/HttpResponseTest.java diff --git a/src/main/java/io/github/openunirest/http/BodyData.java b/src/main/java/io/github/openunirest/http/BodyData.java index 96375fbf0..862ee00c8 100644 --- a/src/main/java/io/github/openunirest/http/BodyData.java +++ b/src/main/java/io/github/openunirest/http/BodyData.java @@ -23,7 +23,6 @@ public static BodyData from(HttpEntity e, Function, T> transf } private final String charset; - private final byte[] rawBytes; private T transFormedBody; private RuntimeException parseEx; diff --git a/src/main/java/io/github/openunirest/http/HttpResponse.java b/src/main/java/io/github/openunirest/http/HttpResponse.java index 63971a8e7..ec224a4d7 100644 --- a/src/main/java/io/github/openunirest/http/HttpResponse.java +++ b/src/main/java/io/github/openunirest/http/HttpResponse.java @@ -27,8 +27,10 @@ a copy of this software and associated documentation files (the import org.apache.http.StatusLine; +import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.Optional; +import java.util.function.Function; public class HttpResponse { @@ -54,6 +56,12 @@ public HttpResponse(org.apache.http.HttpResponse response, BodyData data){ this.parsingError = Optional.ofNullable(data.getParseEx()); } + public HttpResponse(org.apache.http.HttpResponse response, T body, InputStream is){ + this(response); + this.body = body; + this.rawBody = is; + } + public int getStatus() { return statusCode; } @@ -81,4 +89,12 @@ public T getBody() { public Optional getParsingError() { return parsingError; } + + public V mapBody(Function func){ + return func.apply(body); + } + + public V mapRawBody(Function func) { + return func.apply(rawBody); + } } diff --git a/src/test/java/io/github/openunirest/http/HttpResponseTest.java b/src/test/java/io/github/openunirest/http/HttpResponseTest.java new file mode 100644 index 000000000..cc8666185 --- /dev/null +++ b/src/test/java/io/github/openunirest/http/HttpResponseTest.java @@ -0,0 +1,26 @@ +package io.github.openunirest.http; + +import io.github.openunirest.MockApacheResponse; +import org.junit.Test; + +import static io.github.openunirest.http.TestUtil.emptyInput; +import static org.junit.Assert.*; + +public class HttpResponseTest { + + @Test + public void canMapBody() { + MockApacheResponse r = new MockApacheResponse(); + Integer v = new HttpResponse<>(r, "42", emptyInput()).mapBody(Integer::valueOf); + assertEquals(new Integer(42), v); + } + + @Test + public void canMapRawBody() { + MockApacheResponse r = new MockApacheResponse(); + Integer v = new HttpResponse<>(r, "42", TestUtil.toInputStream("42")) + .mapRawBody(i -> Integer.valueOf(TestUtil.toString(i))); + + assertEquals(new Integer(42), v); + } +} \ No newline at end of file diff --git a/src/test/java/io/github/openunirest/http/TestUtil.java b/src/test/java/io/github/openunirest/http/TestUtil.java index e28b7a0d2..89c9728da 100644 --- a/src/test/java/io/github/openunirest/http/TestUtil.java +++ b/src/test/java/io/github/openunirest/http/TestUtil.java @@ -3,10 +3,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.datatype.guava.GuavaModule; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; +import java.io.*; import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; @@ -57,4 +54,12 @@ public static T readValue(String body, Class as) { throw new RuntimeException(e); } } + + public static InputStream emptyInput() { + return new ByteArrayInputStream(new byte[]{}); + } + + public static InputStream toInputStream(String s) { + return new ByteArrayInputStream(s.getBytes()); + } } From f37e8d61a02db1be620cdddc7c81637071bd354a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 29 Mar 2018 11:22:12 -0500 Subject: [PATCH 0081/1769] add jacoco reporting --- pom.xml | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/pom.xml b/pom.xml index 58184240a..be2edcf0e 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,45 @@ + + org.jacoco + jacoco-maven-plugin + 0.8.1 + + + default-prepare-agent + + prepare-agent + + + + default-report + + report + + + + default-check + + check + + + + + BUNDLE + + + COMPLEXITY + COVEREDRATIO + 0.60 + + + + + + + + org.apache.maven.plugins maven-release-plugin From 0b3c5cccd2d8fd68b7862a73c8c466d17bc7906d Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 29 Mar 2018 11:31:52 -0500 Subject: [PATCH 0082/1769] rm custom Base64 encoding class and just use java --- .../openunirest/http/utils/Base64Coder.java | 260 ------------------ .../openunirest/request/HttpRequest.java | 22 +- .../github/openunirest/http/UnirestTest.java | 17 +- 3 files changed, 21 insertions(+), 278 deletions(-) delete mode 100644 src/main/java/io/github/openunirest/http/utils/Base64Coder.java diff --git a/src/main/java/io/github/openunirest/http/utils/Base64Coder.java b/src/main/java/io/github/openunirest/http/utils/Base64Coder.java deleted file mode 100644 index d1102204c..000000000 --- a/src/main/java/io/github/openunirest/http/utils/Base64Coder.java +++ /dev/null @@ -1,260 +0,0 @@ -package io.github.openunirest.http.utils; - -//Copyright 2003-2010 Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland -//www.source-code.biz, www.inventec.ch/chdh -// -//This module is multi-licensed and may be used under the terms -//of any of the following licenses: -// -//EPL, Eclipse Public License, V1.0 or later, http://www.eclipse.org/legal -//LGPL, GNU Lesser General Public License, V2.1 or later, http://www.gnu.org/licenses/lgpl.html -//GPL, GNU General Public License, V2 or later, http://www.gnu.org/licenses/gpl.html -//AL, Apache License, V2.0 or later, http://www.apache.org/licenses -//BSD, BSD License, http://www.opensource.org/licenses/bsd-license.php -//MIT, MIT License, http://www.opensource.org/licenses/MIT -// -//Please contact the author if you need another license. -//This module is provided "as is", without warranties of any kind. - -/** - * A Base64 encoder/decoder. - * - *

- * This class is used to encode and decode data in Base64 format as described in RFC 1521. - * - *

- * Project home page: www.source-code.biz/base64coder/java
- * Author: Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland
- * Multi-licensed: EPL / LGPL / GPL / AL / BSD / MIT. - */ -public class Base64Coder { - - // The line separator string of the operating system. - private static final String systemLineSeparator = System.getProperty("line.separator"); - - // Mapping table from 6-bit nibbles to Base64 characters. - private static final char[] map1 = new char[64]; - static { - int i = 0; - for (char c = 'A'; c <= 'Z'; c++) - map1[i++] = c; - for (char c = 'a'; c <= 'z'; c++) - map1[i++] = c; - for (char c = '0'; c <= '9'; c++) - map1[i++] = c; - map1[i++] = '+'; - map1[i++] = '/'; - } - - // Mapping table from Base64 characters to 6-bit nibbles. - private static final byte[] map2 = new byte[128]; - static { - for (int i = 0; i < map2.length; i++) - map2[i] = -1; - for (int i = 0; i < 64; i++) - map2[map1[i]] = (byte) i; - } - - /** - * Encodes a string into Base64 format. No blanks or line breaks are inserted. - * - * @param s A String to be encoded. - * @return A String containing the Base64 encoded data. - */ - public static String encodeString(String s) { - return new String(encode(s.getBytes())); - } - - /** - * Encodes a byte array into Base 64 format and breaks the output into lines of 76 characters. This method is compatible with - * sun.misc.BASE64Encoder.encodeBuffer(byte[]). - * - * @param in An array containing the data bytes to be encoded. - * @return A String containing the Base64 encoded data, broken into lines. - */ - public static String encodeLines(byte[] in) { - return encodeLines(in, 0, in.length, 76, systemLineSeparator); - } - - /** - * Encodes a byte array into Base 64 format and breaks the output into lines. - * - * @param in An array containing the data bytes to be encoded. - * @param iOff Offset of the first byte in in to be processed. - * @param iLen Number of bytes to be processed in in, starting at iOff. - * @param lineLen Line length for the output data. Should be a multiple of 4. - * @param lineSeparator The line separator to be used to separate the output lines. - * @return A String containing the Base64 encoded data, broken into lines. - */ - public static String encodeLines(byte[] in, int iOff, int iLen, int lineLen, String lineSeparator) { - int blockLen = (lineLen * 3) / 4; - if (blockLen <= 0) - throw new IllegalArgumentException(); - int lines = (iLen + blockLen - 1) / blockLen; - int bufLen = ((iLen + 2) / 3) * 4 + lines * lineSeparator.length(); - StringBuilder buf = new StringBuilder(bufLen); - int ip = 0; - while (ip < iLen) { - int l = Math.min(iLen - ip, blockLen); - buf.append(encode(in, iOff + ip, l)); - buf.append(lineSeparator); - ip += l; - } - return buf.toString(); - } - - /** - * Encodes a byte array into Base64 format. No blanks or line breaks are inserted in the output. - * - * @param in An array containing the data bytes to be encoded. - * @return A character array containing the Base64 encoded data. - */ - public static char[] encode(byte[] in) { - return encode(in, 0, in.length); - } - - /** - * Encodes a byte array into Base64 format. No blanks or line breaks are inserted in the output. - * - * @param in An array containing the data bytes to be encoded. - * @param iLen Number of bytes to process in in. - * @return A character array containing the Base64 encoded data. - */ - public static char[] encode(byte[] in, int iLen) { - return encode(in, 0, iLen); - } - - /** - * Encodes a byte array into Base64 format. No blanks or line breaks are inserted in the output. - * - * @param in An array containing the data bytes to be encoded. - * @param iOff Offset of the first byte in in to be processed. - * @param iLen Number of bytes to process in in, starting at iOff. - * @return A character array containing the Base64 encoded data. - */ - public static char[] encode(byte[] in, int iOff, int iLen) { - int oDataLen = (iLen * 4 + 2) / 3; // output length without padding - int oLen = ((iLen + 2) / 3) * 4; // output length including padding - char[] out = new char[oLen]; - int ip = iOff; - int iEnd = iOff + iLen; - int op = 0; - while (ip < iEnd) { - int i0 = in[ip++] & 0xff; - int i1 = ip < iEnd ? in[ip++] & 0xff : 0; - int i2 = ip < iEnd ? in[ip++] & 0xff : 0; - int o0 = i0 >>> 2; - int o1 = ((i0 & 3) << 4) | (i1 >>> 4); - int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6); - int o3 = i2 & 0x3F; - out[op++] = map1[o0]; - out[op++] = map1[o1]; - out[op] = op < oDataLen ? map1[o2] : '='; - op++; - out[op] = op < oDataLen ? map1[o3] : '='; - op++; - } - return out; - } - - /** - * Decodes a string from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data. - * - * @param s A Base64 String to be decoded. - * @return A String containing the decoded data. - * @throws IllegalArgumentException If the input is not valid Base64 encoded data. - */ - public static String decodeString(String s) { - return new String(decode(s)); - } - - /** - * Decodes a byte array from Base64 format and ignores line separators, tabs and blanks. CR, LF, Tab and Space characters are ignored in the input data. This method is - * compatible with sun.misc.BASE64Decoder.decodeBuffer(String). - * - * @param s A Base64 String to be decoded. - * @return An array containing the decoded data bytes. - * @throws IllegalArgumentException If the input is not valid Base64 encoded data. - */ - public static byte[] decodeLines(String s) { - char[] buf = new char[s.length()]; - int p = 0; - for (int ip = 0; ip < s.length(); ip++) { - char c = s.charAt(ip); - if (c != ' ' && c != '\r' && c != '\n' && c != '\t') - buf[p++] = c; - } - return decode(buf, 0, p); - } - - /** - * Decodes a byte array from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data. - * - * @param s A Base64 String to be decoded. - * @return An array containing the decoded data bytes. - * @throws IllegalArgumentException If the input is not valid Base64 encoded data. - */ - public static byte[] decode(String s) { - return decode(s.toCharArray()); - } - - /** - * Decodes a byte array from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data. - * - * @param in A character array containing the Base64 encoded data. - * @return An array containing the decoded data bytes. - * @throws IllegalArgumentException If the input is not valid Base64 encoded data. - */ - public static byte[] decode(char[] in) { - return decode(in, 0, in.length); - } - - /** - * Decodes a byte array from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data. - * - * @param in A character array containing the Base64 encoded data. - * @param iOff Offset of the first character in in to be processed. - * @param iLen Number of characters to process in in, starting at iOff. - * @return An array containing the decoded data bytes. - * @throws IllegalArgumentException If the input is not valid Base64 encoded data. - */ - public static byte[] decode(char[] in, int iOff, int iLen) { - if (iLen % 4 != 0) - throw new IllegalArgumentException("Length of Base64 encoded input string is not a multiple of 4."); - while (iLen > 0 && in[iOff + iLen - 1] == '=') - iLen--; - int oLen = (iLen * 3) / 4; - byte[] out = new byte[oLen]; - int ip = iOff; - int iEnd = iOff + iLen; - int op = 0; - while (ip < iEnd) { - int i0 = in[ip++]; - int i1 = in[ip++]; - int i2 = ip < iEnd ? in[ip++] : 'A'; - int i3 = ip < iEnd ? in[ip++] : 'A'; - if (i0 > 127 || i1 > 127 || i2 > 127 || i3 > 127) - throw new IllegalArgumentException("Illegal character in Base64 encoded data."); - int b0 = map2[i0]; - int b1 = map2[i1]; - int b2 = map2[i2]; - int b3 = map2[i3]; - if (b0 < 0 || b1 < 0 || b2 < 0 || b3 < 0) - throw new IllegalArgumentException("Illegal character in Base64 encoded data."); - int o0 = (b0 << 2) | (b1 >>> 4); - int o1 = ((b1 & 0xf) << 4) | (b2 >>> 2); - int o2 = ((b2 & 3) << 6) | b3; - out[op++] = (byte) o0; - if (op < oLen) - out[op++] = (byte) o1; - if (op < oLen) - out[op++] = (byte) o2; - } - return out; - } - - // Dummy constructor. - private Base64Coder() { - } - -} // end class Base64Coder diff --git a/src/main/java/io/github/openunirest/request/HttpRequest.java b/src/main/java/io/github/openunirest/request/HttpRequest.java index eacfdac05..a07a78c1c 100644 --- a/src/main/java/io/github/openunirest/request/HttpRequest.java +++ b/src/main/java/io/github/openunirest/request/HttpRequest.java @@ -25,25 +25,17 @@ a copy of this software and associated documentation files (the package io.github.openunirest.request; +import io.github.openunirest.http.HttpMethod; +import io.github.openunirest.http.utils.URLParamEncoder; +import io.github.openunirest.request.body.Body; + import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.TreeMap; import java.util.regex.Matcher; import java.util.regex.Pattern; -import io.github.openunirest.http.HttpMethod; -import io.github.openunirest.request.body.Body; -import io.github.openunirest.http.HttpMethod; -import io.github.openunirest.http.utils.Base64Coder; -import io.github.openunirest.http.utils.URLParamEncoder; -import io.github.openunirest.request.body.Body; - public class HttpRequest extends BaseRequest { private HttpMethod httpMethod; @@ -71,14 +63,14 @@ public HttpRequest routeParam(String name, String value) { } public HttpRequest basicAuth(String username, String password) { - header("Authorization", "Basic " + Base64Coder.encodeString(username + ":" + password)); + header("Authorization", "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes())); return this; } public HttpRequest header(String name, String value) { List list = this.headers.get(name.trim()); if (list == null) { - list = new ArrayList(); + list = new ArrayList<>(); } list.add(value); this.headers.put(name.trim(), list); diff --git a/src/test/java/io/github/openunirest/http/UnirestTest.java b/src/test/java/io/github/openunirest/http/UnirestTest.java index 0df942796..2933fdda3 100644 --- a/src/test/java/io/github/openunirest/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/http/UnirestTest.java @@ -225,11 +225,22 @@ public void testDeleteBody() throws JSONException, UnirestException { @Test public void testBasicAuth() throws JSONException, UnirestException { - HttpResponse response = Unirest.get(MockServer.GET) + Unirest.get(MockServer.GET) .basicAuth("user", "test") - .asJson(); + .asObject(RequestCapture.class) + .getBody() + .assertHeader("Authorization", "Basic dXNlcjp0ZXN0"); + } + + @Test + public void unicodeBasicAuth() throws JSONException, UnirestException { + Unirest.get(MockServer.GET) + .basicAuth("こんにちは", "こんにちは") + .asObject(RequestCapture.class) + .getBody() + .assertHeader("Authorization", "Basic 44GT44KT44Gr44Gh44GvOuOBk+OCk+OBq+OBoeOBrw==") + .assertBasicAuth("こんにちは", "こんにちは"); - parse(response).assertHeader("Authorization", "Basic dXNlcjp0ZXN0"); } @Test From ac51c612ab0cc0d51b391d438754b747e2d452b3 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 29 Mar 2018 12:33:37 -0500 Subject: [PATCH 0083/1769] backfill some of the tests for body posting --- .../exceptions/UnirestConfigException.java | 7 ++ .../request/HttpRequestWithBody.java | 3 +- .../github/openunirest/http/SendBodyTest.java | 109 ++++++++++++++++++ .../github/openunirest/http/UnirestTest.java | 56 --------- 4 files changed, 118 insertions(+), 57 deletions(-) create mode 100644 src/main/java/io/github/openunirest/http/exceptions/UnirestConfigException.java create mode 100644 src/test/java/io/github/openunirest/http/SendBodyTest.java diff --git a/src/main/java/io/github/openunirest/http/exceptions/UnirestConfigException.java b/src/main/java/io/github/openunirest/http/exceptions/UnirestConfigException.java new file mode 100644 index 000000000..c9ff7a925 --- /dev/null +++ b/src/main/java/io/github/openunirest/http/exceptions/UnirestConfigException.java @@ -0,0 +1,7 @@ +package io.github.openunirest.http.exceptions; + +public class UnirestConfigException extends UnirestException { + public UnirestConfigException(String msg) { + super(msg); + } +} diff --git a/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java b/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java index 0bda751d8..c9bb19799 100644 --- a/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java +++ b/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java @@ -28,6 +28,7 @@ a copy of this software and associated documentation files (the import io.github.openunirest.http.HttpMethod; import io.github.openunirest.http.JsonNode; import io.github.openunirest.http.ObjectMapper; +import io.github.openunirest.http.exceptions.UnirestConfigException; import io.github.openunirest.request.body.MultipartBody; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.content.InputStreamBody; @@ -156,7 +157,7 @@ public RequestBodyEntity body(Object body) { ObjectMapper objectMapper = (ObjectMapper) Options.getOption(Option.OBJECT_MAPPER); if (objectMapper == null) { - throw new RuntimeException("Serialization Impossible. Can't find an ObjectMapper implementation."); + throw new UnirestConfigException("Serialization Impossible. Can't find an ObjectMapper implementation."); } return body(objectMapper.writeValue(body)); diff --git a/src/test/java/io/github/openunirest/http/SendBodyTest.java b/src/test/java/io/github/openunirest/http/SendBodyTest.java new file mode 100644 index 000000000..277317d07 --- /dev/null +++ b/src/test/java/io/github/openunirest/http/SendBodyTest.java @@ -0,0 +1,109 @@ +package io.github.openunirest.http; + +import io.github.openunirest.http.async.MockCallback; +import io.github.openunirest.http.exceptions.UnirestConfigException; +import io.github.openunirest.http.exceptions.UnirestException; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Test; + +import static io.github.openunirest.http.TestUtil.assertException; + +public class SendBodyTest extends BddTest { + @Test + public void testPostRawBody() { + String sourceString = "'\"@こんにちは-test-123-" + Math.random(); + byte[] sentBytes = sourceString.getBytes(); + + Unirest.post(MockServer.POST) + .body(sentBytes) + .asObject(RequestCapture.class) + .getBody() + .asserBody(sourceString); + } + + @Test + public void testAsyncCustomContentType() { + Unirest.post(MockServer.POST) + .header("accept", "application/json") + .header("Content-Type", "application/json") + .body("{\"hello\":\"world\"}") + .asJsonAsync(new MockCallback<>(this, r -> parse(r) + .asserBody("{\"hello\":\"world\"}") + .assertHeader("Content-Type", "application/json")) + ); + + assertAsync(); + } + + + @Test + public void postAPojoObjectUsingTheMapper() { + GetResponse postResponseMock = new GetResponse(); + postResponseMock.setUrl(MockServer.POST); + + Unirest.post(postResponseMock.getUrl()) + .header("accept", "application/json") + .header("Content-Type", "application/json") + .body(postResponseMock) + .asObject(RequestCapture.class) + .getBody() + .asserBody("{\"url\":\"http://localhost:4567/post\"}"); + } + + @Test + public void testDeleteBody() throws JSONException, UnirestException { + String body = "{\"jsonString\":{\"members\":\"members1\"}}"; + Unirest.delete(MockServer.DELETE) + .body(body) + .asObject(RequestCapture.class) + .getBody() + .asserBody(body); + } + + @Test + public void postBodyAsJson() throws JSONException, UnirestException { + JSONObject body = new JSONObject(); + body.put("krusty","krab"); + + Unirest.post(MockServer.POST) + .body(body) + .asObject(RequestCapture.class) + .getBody() + .asserBody("{\"krusty\":\"krab\"}"); + } + + @Test + public void postBodyAsJsonArray() throws JSONException, UnirestException { + JSONArray body = new JSONArray(); + body.put(0, "krusty"); + body.put(1, "krab"); + + Unirest.post(MockServer.POST) + .body(body) + .asObject(RequestCapture.class) + .getBody() + .asserBody("[\"krusty\",\"krab\"]"); + } + + @Test + public void postBodyAsJsonNode() throws JSONException, UnirestException { + JsonNode body = new JsonNode("{\"krusty\":\"krab\"}"); + + Unirest.post(MockServer.POST) + .body(body) + .asObject(RequestCapture.class) + .getBody() + .asserBody("{\"krusty\":\"krab\"}"); + } + + @Test + public void cantPostObjectWithoutObjectMapper(){ + Unirest.setObjectMapper(null); + + assertException(() -> Unirest.post(MockServer.POST).body(new Foo("die")), + UnirestConfigException.class, + "Serialization Impossible. Can't find an ObjectMapper implementation."); + } +} diff --git a/src/test/java/io/github/openunirest/http/UnirestTest.java b/src/test/java/io/github/openunirest/http/UnirestTest.java index 2933fdda3..72883c9b3 100644 --- a/src/test/java/io/github/openunirest/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/http/UnirestTest.java @@ -133,19 +133,6 @@ public void testPostBinaryUTF8() throws URISyntaxException { .assertFileContent("file", "This is a test file"); } - @Test - public void testPostRawBody() { - String sourceString = "'\"@こんにちは-test-123-" + Math.random(); - byte[] sentBytes = sourceString.getBytes(); - - HttpResponse response = Unirest.post(MockServer.POST) - .body(sentBytes) - .asJson(); - - parse(response) - .asserBody(sourceString); - } - @Test public void testCustomUserAgent() throws JSONException, UnirestException { HttpResponse response = Unirest.get(MockServer.GET) @@ -212,17 +199,6 @@ public void testDelete() throws JSONException, UnirestException { parse.assertParam("foo", "bar"); } - @Test - public void testDeleteBody() throws JSONException, UnirestException { - String body = "{\"jsonString\":{\"members\":\"members1\"}}"; - HttpResponse response = Unirest.delete(MockServer.DELETE) - .body(body) - .asJson(); - - assertEquals(200, response.getStatus()); - parse(response).asserBody(body); - } - @Test public void testBasicAuth() throws JSONException, UnirestException { Unirest.get(MockServer.GET) @@ -532,20 +508,6 @@ private void makeParallelRequests() throws InterruptedException { newFixedThreadPool.awaitTermination(10, TimeUnit.MINUTES); } - @Test - public void testAsyncCustomContentType() throws Exception { - Unirest.post(MockServer.POST) - .header("accept", "application/json") - .header("Content-Type", "application/json") - .body("{\"hello\":\"world\"}") - .asJsonAsync(new MockCallback<>(this, r -> parse(r) - .asserBody("{\"hello\":\"world\"}") - .assertHeader("Content-Type", "application/json")) - ); - - assertAsync(); - } - @Test public void testAsyncCustomContentTypeAndFormParams() throws InterruptedException { Unirest.post(MockServer.POST) @@ -691,24 +653,6 @@ public void testObjectMapperRead() { assertEquals(getResponse.getBody().getUrl(), getResponseMock.getUrl()); } - @Test - public void testObjectMapperWrite() { - Unirest.setObjectMapper(new JacksonObjectMapper()); - - GetResponse postResponseMock = new GetResponse(); - postResponseMock.setUrl(MockServer.POST); - - HttpResponse postResponse = Unirest.post(postResponseMock.getUrl()) - .header("accept", "application/json") - .header("Content-Type", "application/json") - .body(postResponseMock) - .asJson(); - - assertEquals(200, postResponse.getStatus()); - parse(postResponse) - .asserBody("{\"url\":\"http://localhost:4567/post\"}"); - } - @Test public void testPostProvidesSortedParams() throws IOException { // Verify that fields are encoded into the body in sorted order. From ee776dbda77ae46bc899d17b7904cbe6550ea8c4 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 30 Mar 2018 11:14:47 -0500 Subject: [PATCH 0084/1769] move some tests around --- .../openunirest/http/FormPostingTest.java | 241 +++++++++++++++++ .../github/openunirest/http/UnirestTest.java | 251 ------------------ 2 files changed, 241 insertions(+), 251 deletions(-) create mode 100644 src/test/java/io/github/openunirest/http/FormPostingTest.java diff --git a/src/test/java/io/github/openunirest/http/FormPostingTest.java b/src/test/java/io/github/openunirest/http/FormPostingTest.java new file mode 100644 index 000000000..5d59bad0a --- /dev/null +++ b/src/test/java/io/github/openunirest/http/FormPostingTest.java @@ -0,0 +1,241 @@ +package io.github.openunirest.http; + +import io.github.openunirest.http.async.MockCallback; +import io.github.openunirest.http.exceptions.UnirestException; +import io.github.openunirest.request.HttpRequest; +import org.apache.commons.io.IOUtils; +import org.apache.http.entity.ContentType; +import org.json.JSONException; +import org.junit.Test; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URISyntaxException; +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; + +public class FormPostingTest extends BddTest { + @Test + public void testFormFields() { + Unirest.post(MockServer.POST) + .header("accept", "application/json") + .field("param1", "value1") + .field("param2", "bye") + .asObject(RequestCapture.class) + .getBody() + .assertParam("param1", "value1") + .assertParam("param2", "bye"); + } + + @Test + public void formPostAsync() { + Unirest.post(MockServer.POST) + .header("accept", "application/json") + .field("param1", "value1") + .field("param2", "bye") + .asJsonAsync(new MockCallback<>(this, r -> { + RequestCapture req = parse(r); + req.assertParam("param1", "value1"); + req.assertParam("param2", "bye"); + })); + + assertAsync(); + } + + @Test + public void testMultipart() throws Exception { + Unirest.post(MockServer.POST) + .field("name", "Mark") + .field("file", new File(getClass().getResource("/test").toURI())) + .asObject(RequestCapture.class) + .getBody() + .assertParam("name", "Mark") + .getFile("test") + .assertBody("This is a test file") + .assertFileType("application/octet-stream"); + } + + @Test + public void testMultipartContentType() throws Exception { + Unirest.post(MockServer.POST) + .field("name", "Mark") + .field("file", new File(getClass().getResource("/image.jpg").toURI()), "image/jpeg") + .asObject(RequestCapture.class) + .getBody() + .assertParam("name", "Mark") + .getFile("image.jpg") + .assertFileType("image/jpeg"); + } + + @Test + public void testMultipartInputStreamContentType() throws Exception { + FileInputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())); + + Unirest.post(MockServer.POST) + .header("accept", ContentType.MULTIPART_FORM_DATA.toString()) + .field("name", "Mark") + .field("file", stream, ContentType.APPLICATION_OCTET_STREAM, "image.jpg") + .asObject(RequestCapture.class) + .getBody() + .assertHeader("Accept", ContentType.MULTIPART_FORM_DATA.toString()) + .assertParam("name", "Mark") + .getFile("image.jpg") + .assertFileType("application/octet-stream"); + } + + @Test + public void testMultipartInputStreamContentTypeAsync() throws Exception { + Unirest.post(MockServer.POST) + .field("name", "Mark") + .field("file", new FileInputStream(new File(getClass().getResource("/test").toURI())), ContentType.APPLICATION_OCTET_STREAM, "test") + .asJsonAsync(new MockCallback<>(this, r -> parse(r) + .assertParam("name", "Mark") + .getFile("test") + .assertFileType("application/octet-stream")) + ); + + assertAsync(); + } + + @Test + public void testMultipartByteContentType() throws Exception { + final InputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())); + final byte[] bytes = new byte[stream.available()]; + stream.read(bytes); + stream.close(); + + Unirest.post(MockServer.POST) + .field("name", "Mark") + .field("file", bytes, "image.jpg") + .asObject(RequestCapture.class) + .getBody() + .assertParam("name", "Mark") + .getFile("image.jpg") + .assertFileType("application/octet-stream"); + } + + @Test + public void testMultipartByteContentTypeAsync() throws Exception { + final InputStream stream = new FileInputStream(new File(getClass().getResource("/test").toURI())); + final byte[] bytes = new byte[stream.available()]; + stream.read(bytes); + stream.close(); + + Unirest.post(MockServer.POST) + .field("name", "Mark") + .field("file", bytes, "test") + .asJsonAsync(new MockCallback<>(this, r -> + parse(r) + .assertParam("name", "Mark") + .getFile("test") + .assertFileType("application/octet-stream")) + ); + + assertAsync(); + } + + @Test + public void testMultipartAsync() throws Exception { + Unirest.post(MockServer.POST) + .field("name", "Mark") + .field("file", new File(getClass().getResource("/test").toURI())) + .asJsonAsync(new MockCallback<>(this, r -> + parse(r) + .assertParam("name", "Mark") + .getFile("test") + .assertFileType("application/octet-stream") + .assertBody("This is a test file")) + ); + + assertAsync(); + } + + @Test + public void testAsyncCustomContentTypeAndFormParams() { + Unirest.post(MockServer.POST) + .header("accept", "application/json") + .header("Content-Type", "application/x-www-form-urlencoded") + .field("name", "Mark") + .field("hello", "world") + .asJsonAsync(new MockCallback<>(this, r -> parse(r) + .assertParam("name", "Mark") + .assertParam("hello", "world") + .assertHeader("Content-Type", "application/x-www-form-urlencoded") + )); + + assertAsync(); + } + + @Test + public void testPostMultipleFiles() throws JSONException, URISyntaxException { + Unirest.post(MockServer.POST) + .field("param3", "wot") + .field("file1", new File(getClass().getResource("/test").toURI())) + .field("file2", new File(getClass().getResource("/test").toURI())) + .asObject(RequestCapture.class) + .getBody() + .assertParam("param3", "wot") + .assertFileContent("file1", "This is a test file") + .assertFileContent("file2", "This is a test file"); + } + + @Test + public void testPostArray() throws JSONException, UnirestException { + Unirest.post(MockServer.POST) + .field("name", "Mark") + .field("name", "Tom") + .asObject(RequestCapture.class) + .getBody() + .assertParam("name", "Mark") + .assertParam("name", "Tom"); + } + + @Test + public void testPostUTF8() { + Unirest.post(MockServer.POST) + .header("accept", "application/json") + .field("param3", "こんにちは") + .asObject(RequestCapture.class) + .getBody() + .assertParam("param3", "こんにちは"); + } + + @Test + public void testPostBinaryUTF8() throws URISyntaxException { + Unirest.post(MockServer.POST) + .header("Accept", ContentType.MULTIPART_FORM_DATA.getMimeType()) + .field("param3", "こんにちは") + .field("file", new File(getClass().getResource("/test").toURI())) + .asObject(RequestCapture.class) + .getBody() + .assertParam("param3", "こんにちは") + .assertFileContent("file", "This is a test file"); + } + + @Test + public void testPostCollection() throws JSONException, UnirestException { + Unirest.post(MockServer.POST) + .field("name", Arrays.asList("Mark", "Tom")) + .asObject(RequestCapture.class) + .getBody() + .assertParam("name", "Mark") + .assertParam("name", "Tom"); + } + + @Test + public void testPostProvidesSortedParams() throws IOException { + // Verify that fields are encoded into the body in sorted order. + HttpRequest httpRequest = Unirest.post("test") + .field("z", "Z") + .field("y", "Y") + .field("x", "X") + .getHttpRequest(); + + InputStream content = httpRequest.getBody().getEntity().getContent(); + String body = IOUtils.toString(content, "UTF-8"); + assertEquals("x=X&y=Y&z=Z", body); + } +} diff --git a/src/test/java/io/github/openunirest/http/UnirestTest.java b/src/test/java/io/github/openunirest/http/UnirestTest.java index 72883c9b3..9da8284ec 100644 --- a/src/test/java/io/github/openunirest/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/http/UnirestTest.java @@ -50,22 +50,6 @@ a copy of this software and associated documentation files (the public class UnirestTest extends BddTest { - @Test - public void postFormReturnJson() throws JSONException, UnirestException { - HttpResponse jsonResponse = Unirest.post(MockServer.POST) - .header("accept", "application/json") - .field("param1", "value1") - .field("param2", "bye") - .asJson(); - - assertEquals(200, jsonResponse.getStatus()); - - parse(jsonResponse) - .assertHeader("Accept", "application/json") - .assertParam("param1", "value1") - .assertParam("param2", "bye"); - } - @Test public void canPassQueryParamsOnStringOrWithForm() throws JSONException, UnirestException { HttpResponse response = Unirest.get(MockServer.GET + "?name=mark") @@ -109,30 +93,6 @@ public void testGetUTF8() { .assertParam("param3", "こんにちは"); } - @Test - public void testPostUTF8() { - HttpResponse response = Unirest.post(MockServer.POST) - .header("accept", "application/json") - .field("param3", "こんにちは") - .asJson(); - - parse(response) - .assertParam("param3", "こんにちは"); - } - - @Test - public void testPostBinaryUTF8() throws URISyntaxException { - HttpResponse response = Unirest.post(MockServer.POST) - .header("Accept", ContentType.MULTIPART_FORM_DATA.getMimeType()) - .field("param3", "こんにちは") - .field("file", new File(getClass().getResource("/test").toURI())) - .asJson(); - - parse(response) - .assertParam("param3", "こんにちは") - .assertFileContent("file", "This is a test file"); - } - @Test public void testCustomUserAgent() throws JSONException, UnirestException { HttpResponse response = Unirest.get(MockServer.GET) @@ -216,149 +176,6 @@ public void unicodeBasicAuth() throws JSONException, UnirestException { .getBody() .assertHeader("Authorization", "Basic 44GT44KT44Gr44Gh44GvOuOBk+OCk+OBq+OBoeOBrw==") .assertBasicAuth("こんにちは", "こんにちは"); - - } - - @Test - public void testAsync() throws JSONException, InterruptedException, ExecutionException { - Future> future = Unirest.post(MockServer.POST) - .header("accept", "application/json") - .field("param1", "value1") - .field("param2", "bye") - .asJsonAsync(); - - assertNotNull(future); - - RequestCapture req = parse(future.get()); - req.assertParam("param1", "value1"); - req.assertParam("param2", "bye"); - } - - @Test - public void testAsyncCallback() throws JSONException, InterruptedException { - Unirest.post(MockServer.POST) - .header("accept", "application/json") - .field("param1", "value1") - .field("param2", "bye") - .asJsonAsync(new MockCallback<>(this, r -> { - RequestCapture req = parse(r); - req.assertParam("param1", "value1"); - req.assertParam("param2", "bye"); - })); - - assertAsync(); - } - - @Test - public void testMultipart() throws JSONException, URISyntaxException, UnirestException { - HttpResponse jsonResponse = Unirest.post(MockServer.POST) - .field("name", "Mark") - .field("file", new File(getClass().getResource("/test").toURI())) - .asJson(); - - RequestCapture res = parse(jsonResponse); - res.getFile("test").assertBody("This is a test file"); - res.getFile("test").assertFileType("application/octet-stream"); - - res.assertParam("name", "Mark"); - } - - @Test - public void testMultipartContentType() throws JSONException, URISyntaxException, UnirestException { - HttpResponse jsonResponse = Unirest.post(MockServer.POST) - .field("name", "Mark") - .field("file", new File(getClass().getResource("/image.jpg").toURI()), "image/jpeg") - .asJson(); - - RequestCapture res = parse(jsonResponse); - res.getFile("image.jpg").assertFileType("image/jpeg"); - res.assertParam("name", "Mark"); - } - - @Test - public void testMultipartInputStreamContentType() throws JSONException, URISyntaxException, FileNotFoundException { - FileInputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())); - - HttpResponse request = Unirest.post(MockServer.POST) - .header("accept", ContentType.MULTIPART_FORM_DATA.toString()) - .field("name", "Mark") - .field("file", stream, ContentType.APPLICATION_OCTET_STREAM, "image.jpg") - .asJson(); - - assertEquals(200, request.getStatus()); - - parse(request) - .assertHeader("Accept", ContentType.MULTIPART_FORM_DATA.toString()) - .assertParam("name", "Mark") - .getFile("image.jpg") - .assertFileType("application/octet-stream"); - } - - @Test - public void testMultipartInputStreamContentTypeAsync() throws JSONException, InterruptedException, URISyntaxException, FileNotFoundException { - Unirest.post(MockServer.POST) - .field("name", "Mark") - .field("file", new FileInputStream(new File(getClass().getResource("/test").toURI())), ContentType.APPLICATION_OCTET_STREAM, "test") - .asJsonAsync(new MockCallback<>(this, r -> parse(r) - .assertParam("name", "Mark") - .getFile("test") - .assertFileType("application/octet-stream")) - ); - - assertAsync(); - } - - @Test - public void testMultipartByteContentType() throws JSONException, URISyntaxException, IOException { - final InputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())); - final byte[] bytes = new byte[stream.available()]; - stream.read(bytes); - stream.close(); - - HttpResponse jsonResponse = Unirest.post(MockServer.POST) - .field("name", "Mark") - .field("file", bytes, "image.jpg") - .asJson(); - - RequestCapture parse = parse(jsonResponse); - parse.getFile("image.jpg").assertFileType("application/octet-stream"); - parse.assertParam("name", "Mark"); - } - - @Test - public void testMultipartByteContentTypeAsync() throws Exception { - final InputStream stream = new FileInputStream(new File(getClass().getResource("/test").toURI())); - final byte[] bytes = new byte[stream.available()]; - stream.read(bytes); - stream.close(); - - Unirest.post(MockServer.POST) - .field("name", "Mark") - .field("file", bytes, "test") - .asJsonAsync(new MockCallback<>(this, r -> - parse(r) - .assertParam("name", "Mark") - .getFile("test") - .assertFileType("application/octet-stream")) - ); - - assertAsync(); - } - - @Test - public void testMultipartAsync() throws Exception { - Unirest.post(MockServer.POST) - .field("name", "Mark") - .field("file", new File(getClass().getResource("/test").toURI())) - .asJsonAsync(new MockCallback<>(this, r -> - parse(r) - .assertParam("name", "Mark") - .getFile("test") - .assertFileType("application/octet-stream") - .assertBody("This is a test file")) - ); - - assertAsync(); } @Test @@ -508,23 +325,6 @@ private void makeParallelRequests() throws InterruptedException { newFixedThreadPool.awaitTermination(10, TimeUnit.MINUTES); } - @Test - public void testAsyncCustomContentTypeAndFormParams() throws InterruptedException { - Unirest.post(MockServer.POST) - .header("accept", "application/json") - .header("Content-Type", "application/x-www-form-urlencoded") - .field("name", "Mark") - .field("hello", "world") - .asJsonAsync(new MockCallback<>(this, r -> parse(r) - .assertParam("name", "Mark") - .assertParam("hello", "world") - .assertHeader("Content-Type", "application/x-www-form-urlencoded") - )); - - assertAsync(); - } - - @Test public void testGetQuerystringArray() throws JSONException, UnirestException { HttpResponse response = Unirest.get(MockServer.GET) @@ -537,20 +337,6 @@ public void testGetQuerystringArray() throws JSONException, UnirestException { .assertParam("name", "Tom"); } - @Test - public void testPostMultipleFiles() throws JSONException, URISyntaxException { - HttpResponse response = Unirest.post(MockServer.POST) - .field("param3", "wot") - .field("file1", new File(getClass().getResource("/test").toURI())) - .field("file2", new File(getClass().getResource("/test").toURI())) - .asJson(); - - parse(response) - .assertParam("param3", "wot") - .assertFileContent("file1", "This is a test file") - .assertFileContent("file2", "This is a test file"); - } - @Test public void testGetArray() throws JSONException, UnirestException { HttpResponse response = Unirest.get(MockServer.GET) @@ -562,29 +348,6 @@ public void testGetArray() throws JSONException, UnirestException { .assertParam("name", "Tom"); } - @Test - public void testPostArray() throws JSONException, UnirestException { - HttpResponse response = Unirest.post(MockServer.POST) - .field("name", "Mark") - .field("name", "Tom") - .asJson(); - - parse(response) - .assertParam("name", "Mark") - .assertParam("name", "Tom"); - } - - @Test - public void testPostCollection() throws JSONException, UnirestException { - HttpResponse response = Unirest.post(MockServer.POST) - .field("name", Arrays.asList("Mark", "Tom")) - .asJson(); - - parse(response) - .assertParam("name", "Mark") - .assertParam("name", "Tom"); - } - @Test public void testCaseInsensitiveHeaders() { GetRequest request = Unirest.get(MockServer.GET) @@ -653,20 +416,6 @@ public void testObjectMapperRead() { assertEquals(getResponse.getBody().getUrl(), getResponseMock.getUrl()); } - @Test - public void testPostProvidesSortedParams() throws IOException { - // Verify that fields are encoded into the body in sorted order. - HttpRequest httpRequest = Unirest.post("test") - .field("z", "Z") - .field("y", "Y") - .field("x", "X") - .getHttpRequest(); - - InputStream content = httpRequest.getBody().getEntity().getContent(); - String body = IOUtils.toString(content, "UTF-8"); - assertEquals("x=X&y=Y&z=Z", body); - } - @Test public void testHeaderNamesCaseSensitive() { // Verify that header names are the same as server (case sensitive) From 7aa0db3e97a8a9f95dbaf948ed15625b0e1984ee Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 30 Mar 2018 11:58:33 -0500 Subject: [PATCH 0085/1769] backfilling more form posting tests --- .../openunirest/http/FormPostingTest.java | 92 ++++++++++++++++++- .../openunirest/http/RequestCapture.java | 28 +++--- .../io/github/openunirest/http/TestUtil.java | 18 ++++ 3 files changed, 123 insertions(+), 15 deletions(-) diff --git a/src/test/java/io/github/openunirest/http/FormPostingTest.java b/src/test/java/io/github/openunirest/http/FormPostingTest.java index 5d59bad0a..a81706e93 100644 --- a/src/test/java/io/github/openunirest/http/FormPostingTest.java +++ b/src/test/java/io/github/openunirest/http/FormPostingTest.java @@ -1,5 +1,6 @@ package io.github.openunirest.http; +import com.google.common.collect.ImmutableMap; import io.github.openunirest.http.async.MockCallback; import io.github.openunirest.http.exceptions.UnirestException; import io.github.openunirest.request.HttpRequest; @@ -8,13 +9,12 @@ import org.json.JSONException; import org.junit.Test; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.net.URISyntaxException; import java.util.Arrays; +import java.util.Map; +import static com.google.common.collect.ImmutableMap.of; import static org.junit.Assert.assertEquals; public class FormPostingTest extends BddTest { @@ -238,4 +238,88 @@ public void testPostProvidesSortedParams() throws IOException { String body = IOUtils.toString(content, "UTF-8"); assertEquals("x=X&y=Y&z=Z", body); } + + @Test + public void postFileWithContentType() throws URISyntaxException { + File file = getImageFile(); + Unirest.post(MockServer.POST) + .field("testfile", file, ContentType.IMAGE_JPEG.getMimeType()) + .asObject(RequestCapture.class) + .getBody() + .getFile("image.jpg") + .assertFileType(ContentType.IMAGE_JPEG); + } + + @Test + public void nullFileResultsInEmptyPost() { + Unirest.post(MockServer.POST) + .field("testfile", (Object)null, ContentType.IMAGE_JPEG.getMimeType()) + .asObject(RequestCapture.class) + .getBody() + .assertParam("testfile", ""); + } + + @Test + public void postFileWithoutContentType() throws URISyntaxException { + File file = getImageFile(); + Unirest.post(MockServer.POST) + .field("testfile", file) + .asObject(RequestCapture.class) + .getBody() + .getFile("image.jpg") + .assertFileType("application/octet-stream"); + } + + @Test + public void postFieldsAsMap() throws URISyntaxException { + File file = getImageFile(); + + Unirest.post(MockServer.POST) + .fields(TestUtil.mapOf("big", "bird", "charlie", 42, "testfile", file, "gonzo", null)) + .asObject(RequestCapture.class) + .getBody() + .assertParam("big", "bird") + .assertParam("charlie", "42") + .assertParam("gonzo", "") + .getFile("image.jpg") + .assertFileType("application/octet-stream"); + } + + @Test + public void nullMapDoesntBomb() { + Unirest.post(MockServer.POST) + .queryString("foo","bar") + .fields(null) + .asObject(RequestCapture.class) + .getBody() + .assertParam("foo", "bar"); + } + + @Test + public void canPostInputStream() throws Exception { + File file = getImageFile(); + Unirest.post(MockServer.POST) + .field("testfile", new FileInputStream(file), "image.jpg") + .asObject(RequestCapture.class) + .getBody() + .getFileByInput("testfile") + .assertFileName("image.jpg") + .assertFileType("application/octet-stream"); + } + + @Test + public void canPostInputStreamWithContentType() throws Exception { + File file = getImageFile(); + Unirest.post(MockServer.POST) + .field("testfile", new FileInputStream(file), ContentType.IMAGE_JPEG, "image.jpg") + .asObject(RequestCapture.class) + .getBody() + .getFileByInput("testfile") + .assertFileName("image.jpg") + .assertFileType("image/jpeg"); + } + + private File getImageFile() throws URISyntaxException { + return new File(getClass().getResource("/image.jpg").toURI()); + } } diff --git a/src/test/java/io/github/openunirest/http/RequestCapture.java b/src/test/java/io/github/openunirest/http/RequestCapture.java index a28ee470b..95d35b50d 100644 --- a/src/test/java/io/github/openunirest/http/RequestCapture.java +++ b/src/test/java/io/github/openunirest/http/RequestCapture.java @@ -5,6 +5,7 @@ import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import org.apache.http.client.utils.URLEncodedUtils; +import org.apache.http.entity.ContentType; import spark.Request; import javax.servlet.MultipartConfigElement; @@ -115,28 +116,24 @@ public RequestCapture assertParam(String key, String value) { } public File getFile(String fileName) { - return getFileByFileName(fileName); - } - - private File getFileByFileName(String fileName) { return files.stream() .filter(f -> Objects.equals(f.fileName, fileName)) .findFirst() .orElseThrow(() -> new RuntimeException("No File With Name: " + fileName)); } + public File getFileByInput(String input) { + return files.stream() + .filter(f -> Objects.equals(f.inputName, input)) + .findFirst() + .orElseThrow(() -> new RuntimeException("No File from form: " + input)); + } + public RequestCapture assertFileContent(String input, String content) { assertEquals(content, getFileByInput(input).body); return this; } - private File getFileByInput(String inputName) { - return files.stream() - .filter(f -> Objects.equals(f.inputName, inputName)) - .findFirst() - .orElseThrow(() -> new RuntimeException("No File With Input Name: " + inputName)); - } - public void assertBasicAuth(String username, String password) { String raw = headers.get("Authorization"); assertNotNull("Authorization Header Missing", raw); @@ -164,5 +161,14 @@ public File assertFileType(String type){ assertEquals(type, this.fileType); return this; } + + public File assertFileType(ContentType imageJpeg) { + return assertFileType(imageJpeg.toString()); + } + + public File assertFileName(String s) { + assertEquals(s, fileName); + return this; + } } } diff --git a/src/test/java/io/github/openunirest/http/TestUtil.java b/src/test/java/io/github/openunirest/http/TestUtil.java index 89c9728da..7415cbe96 100644 --- a/src/test/java/io/github/openunirest/http/TestUtil.java +++ b/src/test/java/io/github/openunirest/http/TestUtil.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.datatype.guava.GuavaModule; import java.io.*; +import java.util.HashMap; +import java.util.Map; import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; @@ -62,4 +64,20 @@ public static InputStream emptyInput() { public static InputStream toInputStream(String s) { return new ByteArrayInputStream(s.getBytes()); } + + public static Map mapOf(Object... keyValues) { + Map map = new HashMap<>(); + + K key = null; + for (int index = 0; index < keyValues.length; index++) { + if (index % 2 == 0) { + key = (K)keyValues[index]; + } + else { + map.put(key, (V)keyValues[index]); + } + } + + return map; + } } From c59819672e3bcfc4ef210f1c37b2176662c21e63 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 30 Mar 2018 12:04:45 -0500 Subject: [PATCH 0086/1769] move header tests into their own suite --- .../github/openunirest/http/HeaderTest.java | 98 +++++++++++++++ .../github/openunirest/http/UnirestTest.java | 119 ++---------------- 2 files changed, 110 insertions(+), 107 deletions(-) create mode 100644 src/test/java/io/github/openunirest/http/HeaderTest.java diff --git a/src/test/java/io/github/openunirest/http/HeaderTest.java b/src/test/java/io/github/openunirest/http/HeaderTest.java new file mode 100644 index 000000000..1f0eb204d --- /dev/null +++ b/src/test/java/io/github/openunirest/http/HeaderTest.java @@ -0,0 +1,98 @@ +package io.github.openunirest.http; + +import io.github.openunirest.http.exceptions.UnirestException; +import io.github.openunirest.request.GetRequest; +import org.json.JSONException; +import org.junit.Test; + +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; + +public class HeaderTest extends BddTest { + @Test + public void testCustomUserAgent() throws JSONException, UnirestException { + Unirest.get(MockServer.GET) + .header("user-agent", "hello-world") + .asObject(RequestCapture.class) + .getBody() + .assertHeader("User-Agent", "hello-world"); + } + + @Test + public void testBasicAuth() throws JSONException, UnirestException { + Unirest.get(MockServer.GET) + .basicAuth("user", "test") + .asObject(RequestCapture.class) + .getBody() + .assertHeader("Authorization", "Basic dXNlcjp0ZXN0"); + } + + @Test + public void unicodeBasicAuth() throws JSONException, UnirestException { + Unirest.get(MockServer.GET) + .basicAuth("こんにちは", "こんにちは") + .asObject(RequestCapture.class) + .getBody() + .assertHeader("Authorization", "Basic 44GT44KT44Gr44Gh44GvOuOBk+OCk+OBq+OBoeOBrw==") + .assertBasicAuth("こんにちは", "こんにちは"); + } + + @Test + public void testDefaultHeaders() throws JSONException { + Unirest.setDefaultHeader("X-Custom-Header", "hello"); + Unirest.setDefaultHeader("user-agent", "foobar"); + + HttpResponse jsonResponse = Unirest.get(MockServer.GET).asJson(); + + parse(jsonResponse) + .assertHeader("X-Custom-Header", "hello") + .assertHeader("User-Agent", "foobar"); + + jsonResponse = Unirest.get(MockServer.GET).asJson(); + parse(jsonResponse) + .assertHeader("X-Custom-Header", "hello") + .assertHeader("User-Agent", "foobar"); + + Unirest.clearDefaultHeaders(); + + jsonResponse = Unirest.get(MockServer.GET).asJson(); + parse(jsonResponse) + .assertNoHeader("X-Custom-Header"); + } + + @Test + public void testCaseInsensitiveHeaders() { + GetRequest request = Unirest.get(MockServer.GET) + .header("Name", "Marco"); + + assertEquals(1, request.getHeaders().size()); + assertEquals("Marco", request.getHeaders().get("name").get(0)); + assertEquals("Marco", request.getHeaders().get("NAme").get(0)); + assertEquals("Marco", request.getHeaders().get("Name").get(0)); + + parse(request.asJson()) + .assertHeader("Name", "Marco"); + + request = Unirest.get(MockServer.GET).header("Name", "Marco").header("Name", "John"); + assertEquals(1, request.getHeaders().size()); + assertEquals("Marco", request.getHeaders().get("name").get(0)); + assertEquals("John", request.getHeaders().get("name").get(1)); + assertEquals("Marco", request.getHeaders().get("NAme").get(0)); + assertEquals("John", request.getHeaders().get("NAme").get(1)); + assertEquals("Marco", request.getHeaders().get("Name").get(0)); + assertEquals("John", request.getHeaders().get("Name").get(1)); + } + + @Test + public void testHeaderNamesCaseSensitive() { + // Verify that header names are the same as server (case sensitive) + final Headers headers = new Headers(); + headers.put("Content-Type", Arrays.asList("application/json")); + + assertEquals("Only header \"Content-Type\" should exist", null, headers.getFirst("cOnTeNt-TyPe")); + assertEquals("Only header \"Content-Type\" should exist", null, headers.getFirst("content-type")); + assertEquals("Only header \"Content-Type\" should exist", "application/json", headers.getFirst("Content-Type")); + } + +} diff --git a/src/test/java/io/github/openunirest/http/UnirestTest.java b/src/test/java/io/github/openunirest/http/UnirestTest.java index 9da8284ec..68ca5d819 100644 --- a/src/test/java/io/github/openunirest/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/http/UnirestTest.java @@ -52,31 +52,25 @@ public class UnirestTest extends BddTest { @Test public void canPassQueryParamsOnStringOrWithForm() throws JSONException, UnirestException { - HttpResponse response = Unirest.get(MockServer.GET + "?name=mark") - .header("accept", "application/json") - .asJson(); - - parse(response) + Unirest.get(MockServer.GET + "?name=mark") + .asObject(RequestCapture.class) + .getBody() .assertParam("name", "mark"); - response = Unirest.get(MockServer.GET) - .header("accept", "application/json") + Unirest.get(MockServer.GET) .queryString("name", "mark2") - .asJson(); - - parse(response) + .asObject(RequestCapture.class) + .getBody() .assertParam("name", "mark2"); } @Test public void multipleParams() throws JSONException, UnirestException { - HttpResponse response = Unirest.get(MockServer.GET + "?name=ringo") - .header("accept", "application/json") + Unirest.get(MockServer.GET + "?name=ringo") .queryString("name", "paul") .queryString("name", "john") - .asJson(); - - parse(response) + .asObject(RequestCapture.class) + .getBody() .assertParam("name", "ringo") .assertParam("name", "paul") .assertParam("name", "john"); @@ -84,23 +78,10 @@ public void multipleParams() throws JSONException, UnirestException { @Test public void testGetUTF8() { - HttpResponse response = Unirest.get(MockServer.GET) - .header("accept", "application/json") + Unirest.get(MockServer.GET) .queryString("param3", "こんにちは") - .asJson(); - - parse(response) - .assertParam("param3", "こんにちは"); - } - - @Test - public void testCustomUserAgent() throws JSONException, UnirestException { - HttpResponse response = Unirest.get(MockServer.GET) - .header("user-agent", "hello-world") - .asJson(); - - RequestCapture json = parse(response); - json.assertHeader("User-Agent", "hello-world"); + .asObject(RequestCapture.class) + .getBody().assertParam("param3", "こんにちは"); } @Test @@ -159,25 +140,6 @@ public void testDelete() throws JSONException, UnirestException { parse.assertParam("foo", "bar"); } - @Test - public void testBasicAuth() throws JSONException, UnirestException { - Unirest.get(MockServer.GET) - .basicAuth("user", "test") - .asObject(RequestCapture.class) - .getBody() - .assertHeader("Authorization", "Basic dXNlcjp0ZXN0"); - } - - @Test - public void unicodeBasicAuth() throws JSONException, UnirestException { - Unirest.get(MockServer.GET) - .basicAuth("こんにちは", "こんにちは") - .asObject(RequestCapture.class) - .getBody() - .assertHeader("Authorization", "Basic 44GT44KT44Gr44Gh44GvOuOBk+OCk+OBq+OBoeOBrw==") - .assertBasicAuth("こんにちは", "こんにちは"); - } - @Test public void testGzip() throws JSONException { HttpResponse jsonResponse = Unirest.get(MockServer.GZIP) @@ -197,29 +159,6 @@ public void testGzipAsync() throws JSONException, InterruptedException, Executio parse(jsonResponse).assertParam("zipme", "up"); } - @Test - public void testDefaultHeaders() throws JSONException { - Unirest.setDefaultHeader("X-Custom-Header", "hello"); - Unirest.setDefaultHeader("user-agent", "foobar"); - - HttpResponse jsonResponse = Unirest.get(MockServer.GET).asJson(); - - parse(jsonResponse) - .assertHeader("X-Custom-Header", "hello") - .assertHeader("User-Agent", "foobar"); - - jsonResponse = Unirest.get(MockServer.GET).asJson(); - parse(jsonResponse) - .assertHeader("X-Custom-Header", "hello") - .assertHeader("User-Agent", "foobar"); - - Unirest.clearDefaultHeaders(); - - jsonResponse = Unirest.get(MockServer.GET).asJson(); - parse(jsonResponse) - .assertNoHeader("X-Custom-Header"); - } - @Test public void testSetTimeouts() throws IOException { String address = "http://" + findAvailableIpAddress() + "/"; @@ -348,29 +287,6 @@ public void testGetArray() throws JSONException, UnirestException { .assertParam("name", "Tom"); } - @Test - public void testCaseInsensitiveHeaders() { - GetRequest request = Unirest.get(MockServer.GET) - .header("Name", "Marco"); - - assertEquals(1, request.getHeaders().size()); - assertEquals("Marco", request.getHeaders().get("name").get(0)); - assertEquals("Marco", request.getHeaders().get("NAme").get(0)); - assertEquals("Marco", request.getHeaders().get("Name").get(0)); - - parse(request.asJson()) - .assertHeader("Name", "Marco"); - - request = Unirest.get(MockServer.GET).header("Name", "Marco").header("Name", "John"); - assertEquals(1, request.getHeaders().size()); - assertEquals("Marco", request.getHeaders().get("name").get(0)); - assertEquals("John", request.getHeaders().get("name").get(1)); - assertEquals("Marco", request.getHeaders().get("NAme").get(0)); - assertEquals("John", request.getHeaders().get("NAme").get(1)); - assertEquals("Marco", request.getHeaders().get("Name").get(0)); - assertEquals("John", request.getHeaders().get("Name").get(1)); - } - @Test public void setTimeoutsAndCustomClient() { try { @@ -416,17 +332,6 @@ public void testObjectMapperRead() { assertEquals(getResponse.getBody().getUrl(), getResponseMock.getUrl()); } - @Test - public void testHeaderNamesCaseSensitive() { - // Verify that header names are the same as server (case sensitive) - final Headers headers = new Headers(); - headers.put("Content-Type", Arrays.asList("application/json")); - - assertEquals("Only header \"Content-Type\" should exist", null, headers.getFirst("cOnTeNt-TyPe")); - assertEquals("Only header \"Content-Type\" should exist", null, headers.getFirst("content-type")); - assertEquals("Only header \"Content-Type\" should exist", "application/json", headers.getFirst("Content-Type")); - } - @Test public void failureToReturnValidJsonWillResultInAnEmptyNode() { HttpResponse response = Unirest.get(MockServer.INVALID_REQUEST).asJson(); From cd580decaba6f37d875bf270b2265f13787fe5c9 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 30 Mar 2018 12:12:15 -0500 Subject: [PATCH 0087/1769] more backfill --- .../github/openunirest/http/HeaderTest.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/test/java/io/github/openunirest/http/HeaderTest.java b/src/test/java/io/github/openunirest/http/HeaderTest.java index 1f0eb204d..ab405dcd8 100644 --- a/src/test/java/io/github/openunirest/http/HeaderTest.java +++ b/src/test/java/io/github/openunirest/http/HeaderTest.java @@ -7,6 +7,7 @@ import java.util.Arrays; +import static io.github.openunirest.http.TestUtil.mapOf; import static org.junit.Assert.assertEquals; public class HeaderTest extends BddTest { @@ -25,7 +26,8 @@ public void testBasicAuth() throws JSONException, UnirestException { .basicAuth("user", "test") .asObject(RequestCapture.class) .getBody() - .assertHeader("Authorization", "Basic dXNlcjp0ZXN0"); + .assertHeader("Authorization", "Basic dXNlcjp0ZXN0") + .assertBasicAuth("user", "test"); } @Test @@ -95,4 +97,24 @@ public void testHeaderNamesCaseSensitive() { assertEquals("Only header \"Content-Type\" should exist", "application/json", headers.getFirst("Content-Type")); } + @Test + public void canPassHeadersAsMap() { + Unirest.post(MockServer.POST) + .headers(mapOf("one", "foo", "two", "bar", "three", null)) + .asObject(RequestCapture.class) + .getBody() + .assertHeader("one", "foo") + .assertHeader("two", "bar") + .assertHeader("three", ""); + } + + @Test + public void basicAuthOnPosts() { + Unirest.post(MockServer.POST) + .basicAuth("user", "test") + .asObject(RequestCapture.class) + .getBody() + .assertHeader("Authorization", "Basic dXNlcjp0ZXN0") + .assertBasicAuth("user", "test"); + } } From 9a17a63d452e7a469105eb77e844af8c6de00c44 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 30 Mar 2018 12:35:21 -0500 Subject: [PATCH 0088/1769] move more tests around --- .../openunirest/http/FormPostingTest.java | 11 ++ .../io/github/openunirest/http/GZipTest.java | 27 ++++ .../github/openunirest/http/HeaderTest.java | 15 ++ .../openunirest/http/QueryStringTest.java | 96 ++++++++++++ .../github/openunirest/http/UnirestTest.java | 143 +----------------- 5 files changed, 150 insertions(+), 142 deletions(-) create mode 100644 src/test/java/io/github/openunirest/http/GZipTest.java create mode 100644 src/test/java/io/github/openunirest/http/QueryStringTest.java diff --git a/src/test/java/io/github/openunirest/http/FormPostingTest.java b/src/test/java/io/github/openunirest/http/FormPostingTest.java index a81706e93..51ecadd9d 100644 --- a/src/test/java/io/github/openunirest/http/FormPostingTest.java +++ b/src/test/java/io/github/openunirest/http/FormPostingTest.java @@ -319,6 +319,17 @@ public void canPostInputStreamWithContentType() throws Exception { .assertFileType("image/jpeg"); } + @Test + public void testDelete() { + Unirest.delete(MockServer.DELETE) + .field("name", "mark") + .field("foo", "bar") + .asObject(RequestCapture.class) + .getBody() + .assertParam("name", "mark") + .assertParam("foo", "bar"); + } + private File getImageFile() throws URISyntaxException { return new File(getClass().getResource("/image.jpg").toURI()); } diff --git a/src/test/java/io/github/openunirest/http/GZipTest.java b/src/test/java/io/github/openunirest/http/GZipTest.java new file mode 100644 index 000000000..a7984a8dd --- /dev/null +++ b/src/test/java/io/github/openunirest/http/GZipTest.java @@ -0,0 +1,27 @@ +package io.github.openunirest.http; + +import org.json.JSONException; +import org.junit.Test; + +import java.util.concurrent.ExecutionException; + +public class GZipTest extends BddTest { + @Test + public void testGzip() throws JSONException { + Unirest.get(MockServer.GZIP) + .queryString("zipme", "up") + .asObject(RequestCapture.class) + .getBody() + .assertParam("zipme", "up"); + } + + @Test + public void testGzipAsync() throws JSONException, InterruptedException, ExecutionException { + Unirest.get(MockServer.GZIP) + .queryString("zipme", "up") + .asObjectAsync(RequestCapture.class) + .get() + .getBody() + .assertParam("zipme", "up"); + } +} diff --git a/src/test/java/io/github/openunirest/http/HeaderTest.java b/src/test/java/io/github/openunirest/http/HeaderTest.java index ab405dcd8..7062ca101 100644 --- a/src/test/java/io/github/openunirest/http/HeaderTest.java +++ b/src/test/java/io/github/openunirest/http/HeaderTest.java @@ -117,4 +117,19 @@ public void basicAuthOnPosts() { .assertHeader("Authorization", "Basic dXNlcjp0ZXN0") .assertBasicAuth("user", "test"); } + + @Test + public void willNotCacheBasicAuth() { + Unirest.get(MockServer.GET) + .basicAuth("foo", "bar") + .asObject(RequestCapture.class) + .getBody() + .assertBasicAuth("foo","bar"); + + Unirest.get(MockServer.GET) + .basicAuth("baz", "qux") + .asObject(RequestCapture.class) + .getBody() + .assertBasicAuth("baz", "qux"); + } } diff --git a/src/test/java/io/github/openunirest/http/QueryStringTest.java b/src/test/java/io/github/openunirest/http/QueryStringTest.java new file mode 100644 index 000000000..049ede862 --- /dev/null +++ b/src/test/java/io/github/openunirest/http/QueryStringTest.java @@ -0,0 +1,96 @@ +package io.github.openunirest.http; + +import io.github.openunirest.http.exceptions.UnirestException; +import org.json.JSONException; +import org.junit.Test; + +import java.util.Arrays; + +public class QueryStringTest extends BddTest { + @Test + public void testGetQueryStrings() throws JSONException, UnirestException { + Unirest.get(MockServer.GET) + .queryString("name", "mark") + .queryString("nick", "thefosk") + .asObject(RequestCapture.class) + .getBody() + .assertParam("name", "mark") + .assertParam("nick", "thefosk"); + } + + @Test + public void canPassQueryParamsDirectlyOnUriOrWithMethod() { + Unirest.get(MockServer.GET + "?name=mark") + .asObject(RequestCapture.class) + .getBody() + .assertParam("name", "mark"); + + Unirest.get(MockServer.GET) + .queryString("name", "mark2") + .asObject(RequestCapture.class) + .getBody() + .assertParam("name", "mark2"); + } + + @Test + public void multipleParams() throws JSONException, UnirestException { + Unirest.get(MockServer.GET + "?name=ringo") + .queryString("name", "paul") + .queryString("name", "john") + .asObject(RequestCapture.class) + .getBody() + .assertParam("name", "ringo") + .assertParam("name", "paul") + .assertParam("name", "john"); + } + + @Test + public void testGetUTF8() { + Unirest.get(MockServer.GET) + .queryString("param3", "こんにちは") + .asObject(RequestCapture.class) + .getBody() + .assertParam("param3", "こんにちは"); + } + + @Test + public void testGetMultiple() throws JSONException, UnirestException { + for (int i = 1; i <= 20; i++) { + HttpResponse response = Unirest.get(MockServer.GET + "?try=" + i).asJson(); + parse(response).assertParam("try", String.valueOf(i)); + } + } + + @Test + public void testQueryStringEncoding() throws JSONException, UnirestException { + String testKey = "email2=someKey&email"; + String testValue = "hello@hello.com"; + + Unirest.get(MockServer.GET) + .queryString(testKey, testValue) + .asObject(RequestCapture.class) + .getBody() + .assertParam(testKey, testValue); + } + + @Test + public void testGetQuerystringArray() throws JSONException, UnirestException { + Unirest.get(MockServer.GET) + .queryString("name", "Mark") + .queryString("name", "Tom") + .asObject(RequestCapture.class) + .getBody() + .assertParam("name", "Mark") + .assertParam("name", "Tom"); + } + + @Test + public void testGetArray() throws JSONException, UnirestException { + Unirest.get(MockServer.GET) + .queryString("name", Arrays.asList("Mark", "Tom")) + .asObject(RequestCapture.class) + .getBody() + .assertParam("name", "Mark") + .assertParam("name", "Tom"); + } +} diff --git a/src/test/java/io/github/openunirest/http/UnirestTest.java b/src/test/java/io/github/openunirest/http/UnirestTest.java index 68ca5d819..a2e6344ed 100644 --- a/src/test/java/io/github/openunirest/http/UnirestTest.java +++ b/src/test/java/io/github/openunirest/http/UnirestTest.java @@ -50,115 +50,6 @@ a copy of this software and associated documentation files (the public class UnirestTest extends BddTest { - @Test - public void canPassQueryParamsOnStringOrWithForm() throws JSONException, UnirestException { - Unirest.get(MockServer.GET + "?name=mark") - .asObject(RequestCapture.class) - .getBody() - .assertParam("name", "mark"); - - Unirest.get(MockServer.GET) - .queryString("name", "mark2") - .asObject(RequestCapture.class) - .getBody() - .assertParam("name", "mark2"); - } - - @Test - public void multipleParams() throws JSONException, UnirestException { - Unirest.get(MockServer.GET + "?name=ringo") - .queryString("name", "paul") - .queryString("name", "john") - .asObject(RequestCapture.class) - .getBody() - .assertParam("name", "ringo") - .assertParam("name", "paul") - .assertParam("name", "john"); - } - - @Test - public void testGetUTF8() { - Unirest.get(MockServer.GET) - .queryString("param3", "こんにちは") - .asObject(RequestCapture.class) - .getBody().assertParam("param3", "こんにちは"); - } - - @Test - public void testGetMultiple() throws JSONException, UnirestException { - for (int i = 1; i <= 20; i++) { - HttpResponse response = Unirest.get(MockServer.GET + "?try=" + i).asJson(); - parse(response).assertParam("try", String.valueOf(i)); - } - } - - @Test - public void testGetFields() throws JSONException, UnirestException { - HttpResponse response = Unirest.get(MockServer.GET) - .queryString("name", "mark") - .queryString("nick", "thefosk") - .asJson(); - - RequestCapture parse = parse(response); - parse.assertParam("name", "mark"); - parse.assertParam("nick", "thefosk"); - } - - @Test - public void testGetFields2() throws JSONException, UnirestException { - HttpResponse response = Unirest.get(MockServer.GET) - .queryString("email", "hello@hello.com") - .asJson(); - - parse(response).assertParam("email", "hello@hello.com"); - } - - @Test - public void testQueryStringEncoding() throws JSONException, UnirestException { - String testKey = "email2=someKey&email"; - String testValue = "hello@hello.com"; - - HttpResponse response = Unirest.get(MockServer.GET) - .queryString(testKey, testValue) - .asJson(); - - parse(response).assertParam(testKey, testValue); - } - - @Test - public void testDelete() throws JSONException, UnirestException { - HttpResponse response = Unirest.delete(MockServer.DELETE).asJson(); - assertEquals(200, response.getStatus()); - - response = Unirest.delete(MockServer.DELETE) - .field("name", "mark") - .field("foo", "bar") - .asJson(); - - RequestCapture parse = parse(response); - parse.assertParam("name", "mark"); - parse.assertParam("foo", "bar"); - } - - @Test - public void testGzip() throws JSONException { - HttpResponse jsonResponse = Unirest.get(MockServer.GZIP) - .queryString("zipme", "up") - .asJson(); - - parse(jsonResponse).assertParam("zipme", "up"); - } - - @Test - public void testGzipAsync() throws JSONException, InterruptedException, ExecutionException { - HttpResponse jsonResponse = Unirest.get(MockServer.GZIP) - .queryString("zipme", "up") - .asJsonAsync() - .get(); - - parse(jsonResponse).assertParam("zipme", "up"); - } - @Test public void testSetTimeouts() throws IOException { String address = "http://" + findAvailableIpAddress() + "/"; @@ -264,29 +155,6 @@ private void makeParallelRequests() throws InterruptedException { newFixedThreadPool.awaitTermination(10, TimeUnit.MINUTES); } - @Test - public void testGetQuerystringArray() throws JSONException, UnirestException { - HttpResponse response = Unirest.get(MockServer.GET) - .queryString("name", "Mark") - .queryString("name", "Tom") - .asJson(); - - parse(response) - .assertParam("name", "Mark") - .assertParam("name", "Tom"); - } - - @Test - public void testGetArray() throws JSONException, UnirestException { - HttpResponse response = Unirest.get(MockServer.GET) - .queryString("name", Arrays.asList("Mark", "Tom")) - .asJson(); - - parse(response) - .assertParam("name", "Mark") - .assertParam("name", "Tom"); - } - @Test public void setTimeoutsAndCustomClient() { try { @@ -344,7 +212,7 @@ public void failureToReturnValidJsonWillResultInAnEmptyNode() { } @Test - public void failureToReturnValidJsonWillResultInAnEmptyNodeAsync() throws InterruptedException { + public void failureToReturnValidJsonWillResultInAnEmptyNodeAsync() { Unirest.get(MockServer.INVALID_REQUEST) .asJsonAsync(new MockCallback<>(this, response -> { assertEquals(400, response.getStatus()); @@ -358,15 +226,6 @@ public void failureToReturnValidJsonWillResultInAnEmptyNodeAsync() throws Interr assertAsync(); } - @Test - public void willNotCacheBasicAuth() { - RequestCapture r1 = parse(Unirest.get(MockServer.GET).basicAuth("foo", "bar").asJson()); - RequestCapture r2 = parse(Unirest.get(MockServer.ALTGET).basicAuth("baz", "qux").asJson()); - - r1.assertBasicAuth("foo", "bar"); - r2.assertBasicAuth("baz", "qux"); - } - private String findAvailableIpAddress() throws IOException { for (int i = 100; i <= 255; i++) { String ip = "192.168.1." + i; From 4657cdb1a4151afbab9953641aca385a9242366e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 31 Mar 2018 09:18:06 -0500 Subject: [PATCH 0089/1769] re-organize the tests. BDD tests in their own package --- .../http => BehaviorTests}/AsBinaryTest.java | 5 ++-- .../http => BehaviorTests}/AsJsonTest.java | 3 +- .../http => BehaviorTests}/AsObjectTest.java | 3 +- .../http => BehaviorTests}/AsStringTest.java | 4 ++- .../http => BehaviorTests}/BddTest.java | 6 ++-- .../CallbackFutureTest.java | 8 ++--- .../http => BehaviorTests}/DefectTest.java | 3 +- .../http => BehaviorTests}/Foo.java | 2 +- .../FormPostingTest.java | 8 ++--- .../http => BehaviorTests}/GZipTest.java | 3 +- .../http => BehaviorTests}/GetResponse.java | 2 +- .../http => BehaviorTests}/HeaderTest.java | 5 ++-- .../http => BehaviorTests}/MockServer.java | 3 +- .../QueryStringTest.java | 5 +++- .../RequestCapture.java | 3 +- .../http => BehaviorTests}/UnirestTest.java | 14 ++++----- .../openunirest/ResponseBuilderTest.java | 7 +++-- .../openunirest/http/HttpResponseTest.java | 3 +- .../github/openunirest/http/JsonNodeTest.java | 7 ----- .../github/openunirest/http/SendBodyTest.java | 5 ++-- .../io/github/openunirest/http/TestUtils.java | 22 -------------- .../openunirest/http/options/OptionsTest.java | 4 +-- .../http => util}/JacksonObjectMapper.java | 3 +- .../http/async => util}/MockCallback.java | 5 ++-- .../http/async => util}/NoopCallback.java | 3 +- .../openunirest/http => util}/TestUtil.java | 30 +++++++++++++++++-- 26 files changed, 89 insertions(+), 77 deletions(-) rename src/test/java/{io/github/openunirest/http => BehaviorTests}/AsBinaryTest.java (94%) rename src/test/java/{io/github/openunirest/http => BehaviorTests}/AsJsonTest.java (95%) rename src/test/java/{io/github/openunirest/http => BehaviorTests}/AsObjectTest.java (94%) rename src/test/java/{io/github/openunirest/http => BehaviorTests}/AsStringTest.java (94%) rename src/test/java/{io/github/openunirest/http => BehaviorTests}/BddTest.java (92%) rename src/test/java/{io/github/openunirest/http/async => BehaviorTests}/CallbackFutureTest.java (83%) rename src/test/java/{io/github/openunirest/http => BehaviorTests}/DefectTest.java (93%) rename src/test/java/{io/github/openunirest/http => BehaviorTests}/Foo.java (77%) rename src/test/java/{io/github/openunirest/http => BehaviorTests}/FormPostingTest.java (98%) rename src/test/java/{io/github/openunirest/http => BehaviorTests}/GZipTest.java (91%) rename src/test/java/{io/github/openunirest/http => BehaviorTests}/GetResponse.java (90%) rename src/test/java/{io/github/openunirest/http => BehaviorTests}/HeaderTest.java (98%) rename src/test/java/{io/github/openunirest/http => BehaviorTests}/MockServer.java (98%) rename src/test/java/{io/github/openunirest/http => BehaviorTests}/QueryStringTest.java (95%) rename src/test/java/{io/github/openunirest/http => BehaviorTests}/RequestCapture.java (99%) rename src/test/java/{io/github/openunirest/http => BehaviorTests}/UnirestTest.java (95%) delete mode 100644 src/test/java/io/github/openunirest/http/JsonNodeTest.java delete mode 100644 src/test/java/io/github/openunirest/http/TestUtils.java rename src/test/java/{io/github/openunirest/http => util}/JacksonObjectMapper.java (94%) rename src/test/java/{io/github/openunirest/http/async => util}/MockCallback.java (93%) rename src/test/java/{io/github/openunirest/http/async => util}/NoopCallback.java (85%) rename src/test/java/{io/github/openunirest/http => util}/TestUtil.java (71%) diff --git a/src/test/java/io/github/openunirest/http/AsBinaryTest.java b/src/test/java/BehaviorTests/AsBinaryTest.java similarity index 94% rename from src/test/java/io/github/openunirest/http/AsBinaryTest.java rename to src/test/java/BehaviorTests/AsBinaryTest.java index 67b0c1d89..829a07a2e 100644 --- a/src/test/java/io/github/openunirest/http/AsBinaryTest.java +++ b/src/test/java/BehaviorTests/AsBinaryTest.java @@ -1,8 +1,9 @@ -package io.github.openunirest.http; +package BehaviorTests; +import io.github.openunirest.http.*; import org.junit.Test; +import util.TestUtil; -import java.io.IOException; import java.io.InputStream; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; diff --git a/src/test/java/io/github/openunirest/http/AsJsonTest.java b/src/test/java/BehaviorTests/AsJsonTest.java similarity index 95% rename from src/test/java/io/github/openunirest/http/AsJsonTest.java rename to src/test/java/BehaviorTests/AsJsonTest.java index 1d11abe96..ca9a47f82 100644 --- a/src/test/java/io/github/openunirest/http/AsJsonTest.java +++ b/src/test/java/BehaviorTests/AsJsonTest.java @@ -1,5 +1,6 @@ -package io.github.openunirest.http; +package BehaviorTests; +import io.github.openunirest.http.*; import org.junit.Test; import java.util.concurrent.CompletableFuture; diff --git a/src/test/java/io/github/openunirest/http/AsObjectTest.java b/src/test/java/BehaviorTests/AsObjectTest.java similarity index 94% rename from src/test/java/io/github/openunirest/http/AsObjectTest.java rename to src/test/java/BehaviorTests/AsObjectTest.java index ebcc649ef..5db6d1142 100644 --- a/src/test/java/io/github/openunirest/http/AsObjectTest.java +++ b/src/test/java/BehaviorTests/AsObjectTest.java @@ -1,5 +1,6 @@ -package io.github.openunirest.http; +package BehaviorTests; +import io.github.openunirest.http.Unirest; import org.junit.Test; import java.util.concurrent.ExecutionException; diff --git a/src/test/java/io/github/openunirest/http/AsStringTest.java b/src/test/java/BehaviorTests/AsStringTest.java similarity index 94% rename from src/test/java/io/github/openunirest/http/AsStringTest.java rename to src/test/java/BehaviorTests/AsStringTest.java index 5aeb0296c..6d80f2b4e 100644 --- a/src/test/java/io/github/openunirest/http/AsStringTest.java +++ b/src/test/java/BehaviorTests/AsStringTest.java @@ -1,6 +1,8 @@ -package io.github.openunirest.http; +package BehaviorTests; +import io.github.openunirest.http.*; import org.junit.Test; +import util.TestUtil; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; diff --git a/src/test/java/io/github/openunirest/http/BddTest.java b/src/test/java/BehaviorTests/BddTest.java similarity index 92% rename from src/test/java/io/github/openunirest/http/BddTest.java rename to src/test/java/BehaviorTests/BddTest.java index af36bfe26..0eefd2feb 100644 --- a/src/test/java/io/github/openunirest/http/BddTest.java +++ b/src/test/java/BehaviorTests/BddTest.java @@ -1,11 +1,13 @@ -package io.github.openunirest.http; +package BehaviorTests; +import io.github.openunirest.http.*; import org.junit.Before; +import util.JacksonObjectMapper; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import static io.github.openunirest.http.TestUtils.read; +import static util.TestUtil.read; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; diff --git a/src/test/java/io/github/openunirest/http/async/CallbackFutureTest.java b/src/test/java/BehaviorTests/CallbackFutureTest.java similarity index 83% rename from src/test/java/io/github/openunirest/http/async/CallbackFutureTest.java rename to src/test/java/BehaviorTests/CallbackFutureTest.java index f3492a762..f1cd47dc7 100644 --- a/src/test/java/io/github/openunirest/http/async/CallbackFutureTest.java +++ b/src/test/java/BehaviorTests/CallbackFutureTest.java @@ -1,12 +1,10 @@ -package io.github.openunirest.http.async; +package BehaviorTests; -import io.github.openunirest.http.BddTest; -import io.github.openunirest.http.JsonNode; -import io.github.openunirest.http.MockServer; import io.github.openunirest.http.Unirest; +import util.NoopCallback; import org.junit.Test; -import static io.github.openunirest.http.async.MockCallback.json; +import static util.MockCallback.json; public class CallbackFutureTest extends BddTest { diff --git a/src/test/java/io/github/openunirest/http/DefectTest.java b/src/test/java/BehaviorTests/DefectTest.java similarity index 93% rename from src/test/java/io/github/openunirest/http/DefectTest.java rename to src/test/java/BehaviorTests/DefectTest.java index 7b4e26159..a113a82f0 100644 --- a/src/test/java/io/github/openunirest/http/DefectTest.java +++ b/src/test/java/BehaviorTests/DefectTest.java @@ -1,5 +1,6 @@ -package io.github.openunirest.http; +package BehaviorTests; +import io.github.openunirest.http.Unirest; import org.junit.Test; import java.util.HashMap; diff --git a/src/test/java/io/github/openunirest/http/Foo.java b/src/test/java/BehaviorTests/Foo.java similarity index 77% rename from src/test/java/io/github/openunirest/http/Foo.java rename to src/test/java/BehaviorTests/Foo.java index b68c30d80..08d16f5a3 100644 --- a/src/test/java/io/github/openunirest/http/Foo.java +++ b/src/test/java/BehaviorTests/Foo.java @@ -1,4 +1,4 @@ -package io.github.openunirest.http; +package BehaviorTests; public class Foo { public String bar; diff --git a/src/test/java/io/github/openunirest/http/FormPostingTest.java b/src/test/java/BehaviorTests/FormPostingTest.java similarity index 98% rename from src/test/java/io/github/openunirest/http/FormPostingTest.java rename to src/test/java/BehaviorTests/FormPostingTest.java index 51ecadd9d..12b22ed23 100644 --- a/src/test/java/io/github/openunirest/http/FormPostingTest.java +++ b/src/test/java/BehaviorTests/FormPostingTest.java @@ -1,7 +1,8 @@ -package io.github.openunirest.http; +package BehaviorTests; -import com.google.common.collect.ImmutableMap; -import io.github.openunirest.http.async.MockCallback; +import util.TestUtil; +import io.github.openunirest.http.Unirest; +import util.MockCallback; import io.github.openunirest.http.exceptions.UnirestException; import io.github.openunirest.request.HttpRequest; import org.apache.commons.io.IOUtils; @@ -12,7 +13,6 @@ import java.io.*; import java.net.URISyntaxException; import java.util.Arrays; -import java.util.Map; import static com.google.common.collect.ImmutableMap.of; import static org.junit.Assert.assertEquals; diff --git a/src/test/java/io/github/openunirest/http/GZipTest.java b/src/test/java/BehaviorTests/GZipTest.java similarity index 91% rename from src/test/java/io/github/openunirest/http/GZipTest.java rename to src/test/java/BehaviorTests/GZipTest.java index a7984a8dd..a75eae812 100644 --- a/src/test/java/io/github/openunirest/http/GZipTest.java +++ b/src/test/java/BehaviorTests/GZipTest.java @@ -1,5 +1,6 @@ -package io.github.openunirest.http; +package BehaviorTests; +import io.github.openunirest.http.Unirest; import org.json.JSONException; import org.junit.Test; diff --git a/src/test/java/io/github/openunirest/http/GetResponse.java b/src/test/java/BehaviorTests/GetResponse.java similarity index 90% rename from src/test/java/io/github/openunirest/http/GetResponse.java rename to src/test/java/BehaviorTests/GetResponse.java index f6032a98a..a1e6f9434 100644 --- a/src/test/java/io/github/openunirest/http/GetResponse.java +++ b/src/test/java/BehaviorTests/GetResponse.java @@ -1,4 +1,4 @@ -package io.github.openunirest.http; +package BehaviorTests; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/test/java/io/github/openunirest/http/HeaderTest.java b/src/test/java/BehaviorTests/HeaderTest.java similarity index 98% rename from src/test/java/io/github/openunirest/http/HeaderTest.java rename to src/test/java/BehaviorTests/HeaderTest.java index 7062ca101..d8b09f6f6 100644 --- a/src/test/java/io/github/openunirest/http/HeaderTest.java +++ b/src/test/java/BehaviorTests/HeaderTest.java @@ -1,5 +1,6 @@ -package io.github.openunirest.http; +package BehaviorTests; +import io.github.openunirest.http.*; import io.github.openunirest.http.exceptions.UnirestException; import io.github.openunirest.request.GetRequest; import org.json.JSONException; @@ -7,7 +8,7 @@ import java.util.Arrays; -import static io.github.openunirest.http.TestUtil.mapOf; +import static util.TestUtil.mapOf; import static org.junit.Assert.assertEquals; public class HeaderTest extends BddTest { diff --git a/src/test/java/io/github/openunirest/http/MockServer.java b/src/test/java/BehaviorTests/MockServer.java similarity index 98% rename from src/test/java/io/github/openunirest/http/MockServer.java rename to src/test/java/BehaviorTests/MockServer.java index 59ed84161..620c015b2 100644 --- a/src/test/java/io/github/openunirest/http/MockServer.java +++ b/src/test/java/BehaviorTests/MockServer.java @@ -24,8 +24,9 @@ a copy of this software and associated documentation files (the */ -package io.github.openunirest.http; +package BehaviorTests; +import util.JacksonObjectMapper; import spark.Request; import spark.Response; import spark.Spark; diff --git a/src/test/java/io/github/openunirest/http/QueryStringTest.java b/src/test/java/BehaviorTests/QueryStringTest.java similarity index 95% rename from src/test/java/io/github/openunirest/http/QueryStringTest.java rename to src/test/java/BehaviorTests/QueryStringTest.java index 049ede862..22a363742 100644 --- a/src/test/java/io/github/openunirest/http/QueryStringTest.java +++ b/src/test/java/BehaviorTests/QueryStringTest.java @@ -1,5 +1,8 @@ -package io.github.openunirest.http; +package BehaviorTests; +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.JsonNode; +import io.github.openunirest.http.Unirest; import io.github.openunirest.http.exceptions.UnirestException; import org.json.JSONException; import org.junit.Test; diff --git a/src/test/java/io/github/openunirest/http/RequestCapture.java b/src/test/java/BehaviorTests/RequestCapture.java similarity index 99% rename from src/test/java/io/github/openunirest/http/RequestCapture.java rename to src/test/java/BehaviorTests/RequestCapture.java index 95d35b50d..133a22087 100644 --- a/src/test/java/io/github/openunirest/http/RequestCapture.java +++ b/src/test/java/BehaviorTests/RequestCapture.java @@ -1,4 +1,4 @@ -package io.github.openunirest.http; +package BehaviorTests; import com.google.common.base.Strings; import com.google.common.collect.HashMultimap; @@ -7,6 +7,7 @@ import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.entity.ContentType; import spark.Request; +import util.TestUtil; import javax.servlet.MultipartConfigElement; import javax.servlet.ServletException; diff --git a/src/test/java/io/github/openunirest/http/UnirestTest.java b/src/test/java/BehaviorTests/UnirestTest.java similarity index 95% rename from src/test/java/io/github/openunirest/http/UnirestTest.java rename to src/test/java/BehaviorTests/UnirestTest.java index a2e6344ed..3fbaa6ae1 100644 --- a/src/test/java/io/github/openunirest/http/UnirestTest.java +++ b/src/test/java/BehaviorTests/UnirestTest.java @@ -24,25 +24,21 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.http; +package BehaviorTests; -import io.github.openunirest.http.async.MockCallback; +import io.github.openunirest.http.*; +import util.MockCallback; import io.github.openunirest.http.exceptions.UnirestException; import io.github.openunirest.http.options.Options; -import io.github.openunirest.request.GetRequest; -import io.github.openunirest.request.HttpRequest; -import org.apache.commons.io.IOUtils; -import org.apache.http.entity.ContentType; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; -import org.json.JSONException; import org.junit.Ignore; import org.junit.Test; +import util.JacksonObjectMapper; +import util.TestUtil; import java.io.*; import java.net.InetAddress; -import java.net.URISyntaxException; -import java.util.Arrays; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; diff --git a/src/test/java/io/github/openunirest/ResponseBuilderTest.java b/src/test/java/io/github/openunirest/ResponseBuilderTest.java index e96611dbd..d3729c87e 100644 --- a/src/test/java/io/github/openunirest/ResponseBuilderTest.java +++ b/src/test/java/io/github/openunirest/ResponseBuilderTest.java @@ -1,5 +1,6 @@ package io.github.openunirest; +import BehaviorTests.Foo; import io.github.openunirest.http.*; import io.github.openunirest.http.exceptions.UnirestException; import io.github.openunirest.http.options.Option; @@ -8,11 +9,13 @@ import org.apache.http.message.BasicStatusLine; import org.junit.Before; import org.junit.Test; +import util.JacksonObjectMapper; +import util.TestUtil; import java.io.InputStream; -import static io.github.openunirest.http.TestUtil.assertException; -import static io.github.openunirest.http.TestUtil.toJson; +import static util.TestUtil.assertException; +import static util.TestUtil.toJson; import static org.hamcrest.CoreMatchers.hasItem; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; diff --git a/src/test/java/io/github/openunirest/http/HttpResponseTest.java b/src/test/java/io/github/openunirest/http/HttpResponseTest.java index cc8666185..277fba67a 100644 --- a/src/test/java/io/github/openunirest/http/HttpResponseTest.java +++ b/src/test/java/io/github/openunirest/http/HttpResponseTest.java @@ -2,8 +2,9 @@ import io.github.openunirest.MockApacheResponse; import org.junit.Test; +import util.TestUtil; -import static io.github.openunirest.http.TestUtil.emptyInput; +import static util.TestUtil.emptyInput; import static org.junit.Assert.*; public class HttpResponseTest { diff --git a/src/test/java/io/github/openunirest/http/JsonNodeTest.java b/src/test/java/io/github/openunirest/http/JsonNodeTest.java deleted file mode 100644 index 4839ab532..000000000 --- a/src/test/java/io/github/openunirest/http/JsonNodeTest.java +++ /dev/null @@ -1,7 +0,0 @@ -package io.github.openunirest.http; - -import static org.junit.Assert.*; - -public class JsonNodeTest { - -} \ No newline at end of file diff --git a/src/test/java/io/github/openunirest/http/SendBodyTest.java b/src/test/java/io/github/openunirest/http/SendBodyTest.java index 277317d07..dde730212 100644 --- a/src/test/java/io/github/openunirest/http/SendBodyTest.java +++ b/src/test/java/io/github/openunirest/http/SendBodyTest.java @@ -1,6 +1,7 @@ package io.github.openunirest.http; -import io.github.openunirest.http.async.MockCallback; +import BehaviorTests.*; +import util.MockCallback; import io.github.openunirest.http.exceptions.UnirestConfigException; import io.github.openunirest.http.exceptions.UnirestException; import org.json.JSONArray; @@ -8,7 +9,7 @@ import org.json.JSONObject; import org.junit.Test; -import static io.github.openunirest.http.TestUtil.assertException; +import static util.TestUtil.assertException; public class SendBodyTest extends BddTest { @Test diff --git a/src/test/java/io/github/openunirest/http/TestUtils.java b/src/test/java/io/github/openunirest/http/TestUtils.java deleted file mode 100644 index 2a52a9726..000000000 --- a/src/test/java/io/github/openunirest/http/TestUtils.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.github.openunirest.http; - -import java.io.IOException; - -public class TestUtils { - private static final JacksonObjectMapper om = new JacksonObjectMapper(); - - - public static void debugApache() { - System.setProperty("org.apache.commons.logging.Log","org.apache.commons.logging.impl.SimpleLog"); - System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); - System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "DEBUG"); - } - - public static T read(String o, Class as){ - return om.readValue(o, as); - } - - public static T read(HttpResponse r, Class as) { - return om.readValue(r.getRawBody(), as); - } -} diff --git a/src/test/java/io/github/openunirest/http/options/OptionsTest.java b/src/test/java/io/github/openunirest/http/options/OptionsTest.java index e452c06e2..a22e6d9d4 100644 --- a/src/test/java/io/github/openunirest/http/options/OptionsTest.java +++ b/src/test/java/io/github/openunirest/http/options/OptionsTest.java @@ -1,10 +1,8 @@ package io.github.openunirest.http.options; -import io.github.openunirest.http.JacksonObjectMapper; +import util.JacksonObjectMapper; import io.github.openunirest.http.ObjectMapper; -import io.github.openunirest.http.Unirest; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import java.lang.management.ManagementFactory; diff --git a/src/test/java/io/github/openunirest/http/JacksonObjectMapper.java b/src/test/java/util/JacksonObjectMapper.java similarity index 94% rename from src/test/java/io/github/openunirest/http/JacksonObjectMapper.java rename to src/test/java/util/JacksonObjectMapper.java index c13fa2334..9647ae912 100644 --- a/src/test/java/io/github/openunirest/http/JacksonObjectMapper.java +++ b/src/test/java/util/JacksonObjectMapper.java @@ -1,7 +1,8 @@ -package io.github.openunirest.http; +package util; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.datatype.guava.GuavaModule; +import io.github.openunirest.http.ObjectMapper; import java.io.IOException; import java.io.InputStream; diff --git a/src/test/java/io/github/openunirest/http/async/MockCallback.java b/src/test/java/util/MockCallback.java similarity index 93% rename from src/test/java/io/github/openunirest/http/async/MockCallback.java rename to src/test/java/util/MockCallback.java index a8abc926f..f65b55b3e 100644 --- a/src/test/java/io/github/openunirest/http/async/MockCallback.java +++ b/src/test/java/util/MockCallback.java @@ -1,8 +1,9 @@ -package io.github.openunirest.http.async; +package util; -import io.github.openunirest.http.BddTest; +import BehaviorTests.BddTest; import io.github.openunirest.http.HttpResponse; import io.github.openunirest.http.JsonNode; +import io.github.openunirest.http.async.Callback; import io.github.openunirest.http.exceptions.UnirestException; import java.util.function.Consumer; diff --git a/src/test/java/io/github/openunirest/http/async/NoopCallback.java b/src/test/java/util/NoopCallback.java similarity index 85% rename from src/test/java/io/github/openunirest/http/async/NoopCallback.java rename to src/test/java/util/NoopCallback.java index 1fd8b081e..c41e3b783 100644 --- a/src/test/java/io/github/openunirest/http/async/NoopCallback.java +++ b/src/test/java/util/NoopCallback.java @@ -1,6 +1,7 @@ -package io.github.openunirest.http.async; +package util; import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.async.Callback; import io.github.openunirest.http.exceptions.UnirestException; public class NoopCallback implements Callback { diff --git a/src/test/java/io/github/openunirest/http/TestUtil.java b/src/test/java/util/TestUtil.java similarity index 71% rename from src/test/java/io/github/openunirest/http/TestUtil.java rename to src/test/java/util/TestUtil.java index 7415cbe96..59a6862e4 100644 --- a/src/test/java/io/github/openunirest/http/TestUtil.java +++ b/src/test/java/util/TestUtil.java @@ -1,7 +1,9 @@ -package io.github.openunirest.http; +package util; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.guava.GuavaModule; +import io.github.openunirest.http.HttpResponse; import java.io.*; import java.util.HashMap; @@ -12,10 +14,12 @@ import static org.junit.Assert.fail; public class TestUtil { - private static final com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper(); + private static final ObjectMapper om = new ObjectMapper(); + static { om.registerModule(new GuavaModule()); } + public static String toString(InputStream is) { return new BufferedReader(new InputStreamReader(is)) .lines().collect(Collectors.joining("\n")); @@ -80,4 +84,26 @@ public static Map mapOf(Object... keyValues) { return map; } + + public static void debugApache() { + System.setProperty("org.apache.commons.logging.Log","org.apache.commons.logging.impl.SimpleLog"); + System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); + System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "DEBUG"); + } + + public static T read(String o, Class as){ + try { + return om.readValue(o, as); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static T read(HttpResponse r, Class as) { + try { + return om.readValue(r.getRawBody(), as); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } From 326cb938486bfb1cfc2c3cfa981f80105b48c3f3 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 31 Mar 2018 09:40:29 -0500 Subject: [PATCH 0090/1769] more test refactorings --- src/test/java/BehaviorTests/AsJsonTest.java | 29 +++++ .../java/BehaviorTests/PathParamTest.java | 62 +++++++++++ .../{UnirestTest.java => TimeoutTests.java} | 105 ++---------------- .../openunirest/request/UriFormatterTest.java | 4 +- 4 files changed, 100 insertions(+), 100 deletions(-) create mode 100644 src/test/java/BehaviorTests/PathParamTest.java rename src/test/java/BehaviorTests/{UnirestTest.java => TimeoutTests.java} (58%) diff --git a/src/test/java/BehaviorTests/AsJsonTest.java b/src/test/java/BehaviorTests/AsJsonTest.java index ca9a47f82..e693f9a0c 100644 --- a/src/test/java/BehaviorTests/AsJsonTest.java +++ b/src/test/java/BehaviorTests/AsJsonTest.java @@ -2,11 +2,14 @@ import io.github.openunirest.http.*; import org.junit.Test; +import util.MockCallback; +import util.TestUtil; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; public class AsJsonTest extends BddTest { @Test @@ -39,6 +42,32 @@ public void canGetBinaryResponseAsyncWithCallback() { assertAsync(); } + @Test + public void failureToReturnValidJsonWillResultInAnEmptyNode() { + HttpResponse response = Unirest.get(MockServer.INVALID_REQUEST).asJson(); + + assertEquals(400, response.getStatus()); + assertNull(response.getBody()); + assertEquals("You did something bad", TestUtil.toString(response.getRawBody())); + assertEquals("org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]", + response.getParsingError().get().getMessage()); + } + + @Test + public void failureToReturnValidJsonWillResultInAnEmptyNodeAsync() { + Unirest.get(MockServer.INVALID_REQUEST) + .asJsonAsync(new MockCallback<>(this, response -> { + assertEquals(400, response.getStatus()); + assertNull(response.getBody()); + assertEquals("You did something bad", TestUtil.toString(response.getRawBody())); + assertEquals("org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]", + response.getParsingError().get().getMessage()); + + })); + + assertAsync(); + } + private void assertJson(HttpResponse i) { assertEquals("bar",i.getBody().getObject().getJSONObject("params").getJSONArray("foo").get(0)); } diff --git a/src/test/java/BehaviorTests/PathParamTest.java b/src/test/java/BehaviorTests/PathParamTest.java new file mode 100644 index 000000000..a99adf972 --- /dev/null +++ b/src/test/java/BehaviorTests/PathParamTest.java @@ -0,0 +1,62 @@ +package BehaviorTests; + +import io.github.openunirest.http.Unirest; +import io.github.openunirest.http.exceptions.UnirestException; +import org.junit.Test; +import util.TestUtil; + +public class PathParamTest extends BddTest { + + @Test + public void testPathParameters() { + Unirest.get(MockServer.HOST + "/{method}") + .routeParam("method", "get") + .queryString("name", "Mark") + .asObject(RequestCapture.class) + .getBody() + .assertParam("name", "Mark"); + } + + @Test + public void testQueryAndBodyParameters() { + Unirest.post(MockServer.HOST + "/{method}") + .routeParam("method", "post") + .queryString("name", "Mark") + .field("wot", "wat") + .asObject(RequestCapture.class) + .getBody() + .assertParam("name", "Mark") + .assertParam("wot", "wat"); + } + + @Test + public void testPathParameters2() { + Unirest.patch(MockServer.HOST + "/{method}") + .routeParam("method", "patch") + .field("name", "Mark") + .asObject(RequestCapture.class) + .getBody() + .assertParam("name", "Mark"); + } + + @Test + public void testMissingPathParameter() { + TestUtil.assertException(() -> + Unirest.get(MockServer.HOST + "/{method}") + .routeParam("method222", "get") + .queryString("name", "Mark") + .asBinary(), + RuntimeException.class, + "Can't find route parameter name \"method222\""); + } + + @Test + public void testMissingPathParameterValue() { + TestUtil.assertException(() -> + Unirest.get(MockServer.HOST + "/{method}") + .queryString("name", "Mark") + .asBinary(), + UnirestException.class, + "java.net.URISyntaxException: Illegal character in path at index 22: http://localhost:4567/{method}?name=Mark"); + } +} diff --git a/src/test/java/BehaviorTests/UnirestTest.java b/src/test/java/BehaviorTests/TimeoutTests.java similarity index 58% rename from src/test/java/BehaviorTests/UnirestTest.java rename to src/test/java/BehaviorTests/TimeoutTests.java index 3fbaa6ae1..c24c82614 100644 --- a/src/test/java/BehaviorTests/UnirestTest.java +++ b/src/test/java/BehaviorTests/TimeoutTests.java @@ -26,25 +26,25 @@ a copy of this software and associated documentation files (the package BehaviorTests; -import io.github.openunirest.http.*; -import util.MockCallback; +import io.github.openunirest.http.Unirest; import io.github.openunirest.http.exceptions.UnirestException; import io.github.openunirest.http.options.Options; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; import org.junit.Ignore; import org.junit.Test; -import util.JacksonObjectMapper; -import util.TestUtil; -import java.io.*; +import java.io.IOException; import java.net.InetAddress; -import java.util.concurrent.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; -public class UnirestTest extends BddTest { +public class TimeoutTests extends BddTest { @Test public void testSetTimeouts() throws IOException { @@ -68,55 +68,6 @@ public void testSetTimeouts() throws IOException { } } - @Test - public void testPathParameters() { - HttpResponse jsonResponse = Unirest.get(MockServer.HOST + "/{method}") - .routeParam("method", "get") - .queryString("name", "Mark") - .asJson(); - - parse(jsonResponse) - .assertParam("name", "Mark"); - } - - @Test - public void testQueryAndBodyParameters() { - HttpResponse jsonResponse = Unirest.post(MockServer.HOST + "/{method}") - .routeParam("method", "post") - .queryString("name", "Mark") - .field("wot", "wat") - .asJson(); - - parse(jsonResponse) - .assertParam("name", "Mark") - .assertParam("wot", "wat"); - } - - @Test - public void testPathParameters2() { - HttpResponse jsonResponse = Unirest.patch(MockServer.HOST + "/{method}") - .routeParam("method", "patch") - .field("name", "Mark") - .asJson(); - - parse(jsonResponse) - .assertParam("name", "Mark"); - } - - @Test - public void testMissingPathParameter() { - try { - Unirest.get(MockServer.HOST + "/{method}") - .routeParam("method222", "get") - .queryString("name", "Mark") - .asJson(); - - fail(); - } catch (RuntimeException e) { - assertEquals("Can't find route parameter name \"method222\"", e.getMessage()); - } - } - @Test @Ignore // this is flakey public void parallelTest() throws InterruptedException { @@ -182,46 +133,6 @@ public void setTimeoutsAndCustomClient() { } } - @Test - public void testObjectMapperRead() { - Unirest.setObjectMapper(new JacksonObjectMapper()); - - GetResponse getResponseMock = new GetResponse(); - getResponseMock.setUrl(MockServer.GET); - - HttpResponse getResponse = Unirest.get(getResponseMock.getUrl()) - .asObject(GetResponse.class); - - assertEquals(200, getResponse.getStatus()); - assertEquals(getResponse.getBody().getUrl(), getResponseMock.getUrl()); - } - - @Test - public void failureToReturnValidJsonWillResultInAnEmptyNode() { - HttpResponse response = Unirest.get(MockServer.INVALID_REQUEST).asJson(); - - assertEquals(400, response.getStatus()); - assertNull(response.getBody()); - assertEquals("You did something bad", TestUtil.toString(response.getRawBody())); - assertEquals("org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]", - response.getParsingError().get().getMessage()); - } - - @Test - public void failureToReturnValidJsonWillResultInAnEmptyNodeAsync() { - Unirest.get(MockServer.INVALID_REQUEST) - .asJsonAsync(new MockCallback<>(this, response -> { - assertEquals(400, response.getStatus()); - assertNull(response.getBody()); - assertEquals("You did something bad", TestUtil.toString(response.getRawBody())); - assertEquals("org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]", - response.getParsingError().get().getMessage()); - - })); - - assertAsync(); - } - private String findAvailableIpAddress() throws IOException { for (int i = 100; i <= 255; i++) { String ip = "192.168.1." + i; diff --git a/src/test/java/io/github/openunirest/request/UriFormatterTest.java b/src/test/java/io/github/openunirest/request/UriFormatterTest.java index 0cd71b7da..5fa3fc998 100644 --- a/src/test/java/io/github/openunirest/request/UriFormatterTest.java +++ b/src/test/java/io/github/openunirest/request/UriFormatterTest.java @@ -1,11 +1,9 @@ package io.github.openunirest.request; import io.github.openunirest.http.HttpMethod; -import io.github.openunirest.request.HttpRequest; -import io.github.openunirest.request.UriFormatter; import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; public class UriFormatterTest { private UriFormatter helper = new UriFormatter(); From 91ba2dcd6218f77612a6db0c150fa4ee852d7fea Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 31 Mar 2018 09:50:21 -0500 Subject: [PATCH 0091/1769] move some stuff around and make things internal that the general public should not be messing with --- .../java/io/github/openunirest/http/BodyData.java | 1 + .../io/github/openunirest/http/HttpResponse.java | 1 - .../io/github/openunirest/request/BaseRequest.java | 1 - .../openunirest/request/HttpDeleteWithBody.java | 6 +++--- .../{http => request}/ResponseBuilder.java | 9 +++++++-- .../{ => request}/ResponseBuilderTest.java | 12 ++++++------ 6 files changed, 17 insertions(+), 13 deletions(-) rename src/main/java/io/github/openunirest/{http => request}/ResponseBuilder.java (89%) rename src/test/java/io/github/openunirest/{ => request}/ResponseBuilderTest.java (94%) diff --git a/src/main/java/io/github/openunirest/http/BodyData.java b/src/main/java/io/github/openunirest/http/BodyData.java index 862ee00c8..8b803b020 100644 --- a/src/main/java/io/github/openunirest/http/BodyData.java +++ b/src/main/java/io/github/openunirest/http/BodyData.java @@ -11,6 +11,7 @@ import static io.github.openunirest.http.utils.ResponseUtils.getCharsetfromResponse; import static io.github.openunirest.http.utils.ResponseUtils.getRawBody; +@Deprecated // use at your own risk public class BodyData { public static BodyData from(HttpEntity e, Function, T> transformer) { diff --git a/src/main/java/io/github/openunirest/http/HttpResponse.java b/src/main/java/io/github/openunirest/http/HttpResponse.java index ec224a4d7..4be7f4a7d 100644 --- a/src/main/java/io/github/openunirest/http/HttpResponse.java +++ b/src/main/java/io/github/openunirest/http/HttpResponse.java @@ -27,7 +27,6 @@ a copy of this software and associated documentation files (the import org.apache.http.StatusLine; -import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.Optional; import java.util.function.Function; diff --git a/src/main/java/io/github/openunirest/request/BaseRequest.java b/src/main/java/io/github/openunirest/request/BaseRequest.java index 8c787c2c9..da181cbe6 100644 --- a/src/main/java/io/github/openunirest/request/BaseRequest.java +++ b/src/main/java/io/github/openunirest/request/BaseRequest.java @@ -25,7 +25,6 @@ a copy of this software and associated documentation files (the package io.github.openunirest.request; -import io.github.openunirest.http.*; import io.github.openunirest.http.async.Callback; import io.github.openunirest.http.HttpResponse; import io.github.openunirest.http.JsonNode; diff --git a/src/main/java/io/github/openunirest/request/HttpDeleteWithBody.java b/src/main/java/io/github/openunirest/request/HttpDeleteWithBody.java index e7c132f16..f104db0ae 100644 --- a/src/main/java/io/github/openunirest/request/HttpDeleteWithBody.java +++ b/src/main/java/io/github/openunirest/request/HttpDeleteWithBody.java @@ -25,11 +25,11 @@ a copy of this software and associated documentation files (the package io.github.openunirest.request; -import java.net.URI; - import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; -class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase { +import java.net.URI; + +public class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase { public static final String METHOD_NAME = "DELETE"; public String getMethod() { diff --git a/src/main/java/io/github/openunirest/http/ResponseBuilder.java b/src/main/java/io/github/openunirest/request/ResponseBuilder.java similarity index 89% rename from src/main/java/io/github/openunirest/http/ResponseBuilder.java rename to src/main/java/io/github/openunirest/request/ResponseBuilder.java index 7795a894d..a0f68080f 100644 --- a/src/main/java/io/github/openunirest/http/ResponseBuilder.java +++ b/src/main/java/io/github/openunirest/request/ResponseBuilder.java @@ -1,6 +1,10 @@ -package io.github.openunirest.http; +package io.github.openunirest.request; +import io.github.openunirest.http.BodyData; +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.JsonNode; +import io.github.openunirest.http.ObjectMapper; import io.github.openunirest.http.exceptions.UnirestException; import io.github.openunirest.http.options.Option; import io.github.openunirest.http.options.Options; @@ -10,7 +14,8 @@ import static io.github.openunirest.http.BodyData.from; -public class ResponseBuilder { + +class ResponseBuilder { public HttpResponse asJson(org.apache.http.HttpResponse response) { return new HttpResponse<>(response, from(response.getEntity(), b -> toJson(b))); diff --git a/src/test/java/io/github/openunirest/ResponseBuilderTest.java b/src/test/java/io/github/openunirest/request/ResponseBuilderTest.java similarity index 94% rename from src/test/java/io/github/openunirest/ResponseBuilderTest.java rename to src/test/java/io/github/openunirest/request/ResponseBuilderTest.java index d3729c87e..7c6e3eefb 100644 --- a/src/test/java/io/github/openunirest/ResponseBuilderTest.java +++ b/src/test/java/io/github/openunirest/request/ResponseBuilderTest.java @@ -1,7 +1,9 @@ -package io.github.openunirest; +package io.github.openunirest.request; import BehaviorTests.Foo; -import io.github.openunirest.http.*; +import io.github.openunirest.MockApacheResponse; +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.JsonNode; import io.github.openunirest.http.exceptions.UnirestException; import io.github.openunirest.http.options.Option; import io.github.openunirest.http.options.Options; @@ -14,12 +16,10 @@ import java.io.InputStream; +import static org.hamcrest.CoreMatchers.hasItem; +import static org.junit.Assert.*; import static util.TestUtil.assertException; import static util.TestUtil.toJson; -import static org.hamcrest.CoreMatchers.hasItem; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; public class ResponseBuilderTest { private final ResponseBuilder builder = new ResponseBuilder(); From 7b98b0a980a155716d83384256d3504c8d28c3b6 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 31 Mar 2018 09:52:00 -0500 Subject: [PATCH 0092/1769] bump intermediate due to extensive internal refactoring. The classes removed sholdnt have been used by most users. but you never know --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index be2edcf0e..1975762ff 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.1.02-SNAPSHOT + 2.2.00-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ From 3f1df39a4c14cdbd59070de3041c33406a712007 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 31 Mar 2018 09:56:38 -0500 Subject: [PATCH 0093/1769] [maven-release-plugin] prepare release v2.2.00 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 1975762ff..c266dc4df 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.00-SNAPSHOT + 2.2.00 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.2.00 From 42c9a97ee3251a30f9920ae1c00633f7bcfda875 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 31 Mar 2018 09:56:45 -0500 Subject: [PATCH 0094/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c266dc4df..cb609d9b1 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.00 + 2.2.01-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.2.00 + HEAD From 8b5dc288bac9de086da05fcff5f1bfedeac1a26d Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 1 Apr 2018 07:46:13 -0500 Subject: [PATCH 0095/1769] Update CHANGELOG.md --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cd17d49f..a25a1d6cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 2.2.00 +* Major refactoring of how response objects are built. This internalizes HttpClientHelper which was previously public but not needed if you were using the library in in the expected way. This refactoring sets up the library for future work to extend the number of supported formats and for greater expression in the methods for those formats. +* Additional of functional map methods to HttpResponse so you don't have to stop the flow for further transformations. +* Update the org.json dependency +* Fixed issue with achor hashes in URLs (#17) +* Fixed NPE in passing args as maps (#20) + # 2.1.01 * JSON parsing errors no longer just throw out of ```asJson``` but are captured and can be inspected via ```HttpResponse::getParsingError```. This resolves the fact that most API's do not return valid JSON for non-200 status codes. * Return CompletableFuture rather that boring old Futures for all async methods. From 914141b2e48972ebcf061e61521a0c5782205981 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 1 Apr 2018 07:46:45 -0500 Subject: [PATCH 0096/1769] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5cc9aa51e..ebec07602 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Unirest.post("http://httpbin.org/post") io.github.openunirest unirest-java - 2.1.01 + 2.2.00 ``` From 782bcc32486635b8bd817c831d0992ceef71c463 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 1 Apr 2018 14:32:11 -0500 Subject: [PATCH 0097/1769] quitely consume the entity --- .../java/io/github/openunirest/http/utils/ResponseUtils.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java b/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java index 541dbb85a..4241befcf 100644 --- a/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java +++ b/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java @@ -10,6 +10,7 @@ import org.apache.http.Header; import org.apache.http.HttpEntity; +import org.apache.http.util.EntityUtils; public class ResponseUtils { @@ -81,6 +82,8 @@ public static byte[] getRawBody(HttpEntity responseEntity) { return getBytes(is); } catch (IOException e2) { throw new RuntimeException(e2); + } finally { + EntityUtils.consumeQuietly(responseEntity); } } } From fc0a65fd00b73ec82ed9270416a3a52723b5d66f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 1 Apr 2018 15:58:56 -0500 Subject: [PATCH 0098/1769] [maven-release-plugin] prepare release v2.2.01 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index cb609d9b1..b55b8e823 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.01-SNAPSHOT + 2.2.01 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.2.01 From f830261f0a400b46409d66b33f66a51673765e25 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 1 Apr 2018 15:59:05 -0500 Subject: [PATCH 0099/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b55b8e823..83e4cad75 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.01 + 2.2.02-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.2.01 + HEAD From 51c1843b895071e22c045917d872fa47cad620d3 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 1 Apr 2018 14:33:24 -0500 Subject: [PATCH 0100/1769] throw unirest exception --- .../java/io/github/openunirest/http/utils/ResponseUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java b/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java index 4241befcf..20164d63d 100644 --- a/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java +++ b/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java @@ -8,6 +8,7 @@ import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; +import io.github.openunirest.http.exceptions.UnirestException; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.util.EntityUtils; @@ -81,7 +82,7 @@ public static byte[] getRawBody(HttpEntity responseEntity) { } return getBytes(is); } catch (IOException e2) { - throw new RuntimeException(e2); + throw new UnirestException(e2); } finally { EntityUtils.consumeQuietly(responseEntity); } From 61d1b09cf8de71a4a5d3a3a9cfe53789dfa2423b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 1 Apr 2018 18:05:27 -0500 Subject: [PATCH 0101/1769] add shutdown test --- pom.xml | 7 +++ .../java/BehaviorTests/LifeCycleTest.java | 47 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/test/java/BehaviorTests/LifeCycleTest.java diff --git a/pom.xml b/pom.xml index 83e4cad75..63ecf8dd1 100644 --- a/pom.xml +++ b/pom.xml @@ -227,6 +227,13 @@ 2.4 test + + + org.mockito + mockito-all + 2.0.2-beta + test + com.google.guava diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java new file mode 100644 index 000000000..1154a1edc --- /dev/null +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -0,0 +1,47 @@ +package BehaviorTests; + +import io.github.openunirest.http.Unirest; +import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; +import io.github.openunirest.http.options.Options; +import io.github.openunirest.http.utils.SyncIdleConnectionMonitorThread; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; +import org.junit.After; +import org.junit.Test; + +import java.io.IOException; + +import static io.github.openunirest.http.options.Option.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class LifeCycleTest extends BddTest { + @After + public void tearDown() throws Exception { + Options.reset(); + } + + @Test + public void testShutdown() throws IOException { + CloseableHttpClient httpc = mock(CloseableHttpClient.class); + SyncIdleConnectionMonitorThread connMonitor = mock(SyncIdleConnectionMonitorThread.class); + CloseableHttpAsyncClient asyncClient = mock(CloseableHttpAsyncClient.class); + when(asyncClient.isRunning()).thenReturn(true); + AsyncIdleConnectionMonitorThread asyncMonitor = mock(AsyncIdleConnectionMonitorThread.class); + + Options.setOption(HTTPCLIENT, httpc); + Options.setOption(SYNC_MONITOR, connMonitor); + Options.setOption(ASYNCHTTPCLIENT, asyncClient); + Options.setOption(ASYNC_MONITOR, asyncMonitor); + + Unirest.shutdown(); + + verify(httpc).close(); + verify(connMonitor).interrupt(); + verify(asyncClient).close(); + verify(asyncMonitor).interrupt(); + + + } +} From d3aa55e8cb11e275f4460ad24b541e215225ab46 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 2 Apr 2018 07:02:03 -0500 Subject: [PATCH 0102/1769] more shutdown tests --- .../java/BehaviorTests/LifeCycleTest.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index 1154a1edc..584edc9e5 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -7,17 +7,16 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.junit.After; +import org.junit.Before; import org.junit.Test; import java.io.IOException; import static io.github.openunirest.http.options.Option.*; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; public class LifeCycleTest extends BddTest { - @After + @After @Before public void tearDown() throws Exception { Options.reset(); } @@ -41,7 +40,27 @@ public void testShutdown() throws IOException { verify(connMonitor).interrupt(); verify(asyncClient).close(); verify(asyncMonitor).interrupt(); + } + + @Test + public void DoesNotBombOnNullOptions() throws IOException { + Options.setOption(HTTPCLIENT, null); + Options.setOption(SYNC_MONITOR, null); + Options.setOption(ASYNCHTTPCLIENT, null); + Options.setOption(ASYNC_MONITOR, null); + + Unirest.shutdown(); + } + @Test + public void willNotShutdownInactiveAsyncClient() throws IOException { + CloseableHttpAsyncClient asyncClient = mock(CloseableHttpAsyncClient.class); + when(asyncClient.isRunning()).thenReturn(false); + + Options.setOption(ASYNCHTTPCLIENT, asyncClient); + + Unirest.shutdown(); + verify(asyncClient, never()).close(); } } From 05d275df14c6474407e4557f57eceab75fcf3da0 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 2 Apr 2018 07:18:42 -0500 Subject: [PATCH 0103/1769] do not bomb on head because there is no body --- .../io/github/openunirest/http/BodyData.java | 3 + src/test/java/BehaviorTests/MockServer.java | 3 + .../java/BehaviorTests/RequestCapture.java | 7 +++ src/test/java/BehaviorTests/VerbTests.java | 61 +++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 src/test/java/BehaviorTests/VerbTests.java diff --git a/src/main/java/io/github/openunirest/http/BodyData.java b/src/main/java/io/github/openunirest/http/BodyData.java index 8b803b020..50edc8dc8 100644 --- a/src/main/java/io/github/openunirest/http/BodyData.java +++ b/src/main/java/io/github/openunirest/http/BodyData.java @@ -47,6 +47,9 @@ public byte[] getRawBytes() { } public InputStream getRawInput() { + if(rawBytes == null){ + return null; + } return new ByteArrayInputStream(rawBytes); } diff --git a/src/test/java/BehaviorTests/MockServer.java b/src/test/java/BehaviorTests/MockServer.java index 620c015b2..f76f92992 100644 --- a/src/test/java/BehaviorTests/MockServer.java +++ b/src/test/java/BehaviorTests/MockServer.java @@ -64,6 +64,9 @@ public static void reset(){ get("/gzip", MockServer::gzipResponse); patch("/patch", MockServer::jsonResponse); get("/invalid", MockServer::inValid); + options("/get", MockServer::jsonResponse); + head("/get", MockServer::jsonResponse); + put("/post", MockServer::jsonResponse); Runtime.getRuntime().addShutdownHook(new Thread(Spark::stop)); } diff --git a/src/test/java/BehaviorTests/RequestCapture.java b/src/test/java/BehaviorTests/RequestCapture.java index 133a22087..3f85e8a3c 100644 --- a/src/test/java/BehaviorTests/RequestCapture.java +++ b/src/test/java/BehaviorTests/RequestCapture.java @@ -4,6 +4,7 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import com.google.common.collect.Sets; +import io.github.openunirest.http.HttpMethod; import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.entity.ContentType; import spark.Request; @@ -27,6 +28,7 @@ public class RequestCapture { public String body; public String url; public String queryString; + public HttpMethod method; public RequestCapture() { } @@ -34,6 +36,7 @@ public RequestCapture() { public RequestCapture(Request req) { url = req.url(); queryString = req.queryString(); + method = HttpMethod.valueOf(req.requestMethod()); writeHeaders(req); writeQuery(req); } @@ -146,6 +149,10 @@ public void assertQueryString(String s) { assertEquals(s, queryString); } + public void asserMethod(HttpMethod get) { + assertEquals(get, method); + } + public static class File { public String fileName; public String type; diff --git a/src/test/java/BehaviorTests/VerbTests.java b/src/test/java/BehaviorTests/VerbTests.java new file mode 100644 index 000000000..90bbc1d13 --- /dev/null +++ b/src/test/java/BehaviorTests/VerbTests.java @@ -0,0 +1,61 @@ +package BehaviorTests; + +import io.github.openunirest.http.HttpMethod; +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.Unirest; +import org.junit.Test; + +import java.io.InputStream; + +import static org.junit.Assert.assertEquals; + +public class VerbTests extends BddTest { + @Test + public void get() { + Unirest.get(MockServer.GET) + .asObject(RequestCapture.class) + .getBody() + .asserMethod(HttpMethod.GET); + } + + @Test + public void post() { + Unirest.post(MockServer.POST) + .asObject(RequestCapture.class) + .getBody() + .asserMethod(HttpMethod.POST); + } + + @Test + public void put() { + Unirest.put(MockServer.POST) + .asObject(RequestCapture.class) + .getBody() + .asserMethod(HttpMethod.PUT); + } + + @Test + public void patch() { + Unirest.patch(MockServer.PATCH) + .asObject(RequestCapture.class) + .getBody() + .asserMethod(HttpMethod.PATCH); + } + + @Test + public void head() { + HttpResponse response = Unirest.head(MockServer.GET).asBinary(); + + assertEquals(200, response.getStatus()); + assertEquals("text/html;charset=utf-8", response.getHeaders().getFirst("Content-Type")); + } + + @Test + public void option() { + Unirest.options(MockServer.GET) + .asObject(RequestCapture.class) + .getBody() + .asserMethod(HttpMethod.OPTIONS); + } + +} From 24fb71aa6922a1f490e1bd38e39d5942d09018d8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 2 Apr 2018 08:22:09 -0500 Subject: [PATCH 0104/1769] return a empty body rather than null --- src/main/java/io/github/openunirest/http/BodyData.java | 2 +- src/test/java/BehaviorTests/{VerbTests.java => VerbTest.java} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/test/java/BehaviorTests/{VerbTests.java => VerbTest.java} (97%) diff --git a/src/main/java/io/github/openunirest/http/BodyData.java b/src/main/java/io/github/openunirest/http/BodyData.java index 50edc8dc8..17437f3de 100644 --- a/src/main/java/io/github/openunirest/http/BodyData.java +++ b/src/main/java/io/github/openunirest/http/BodyData.java @@ -48,7 +48,7 @@ public byte[] getRawBytes() { public InputStream getRawInput() { if(rawBytes == null){ - return null; + return new ByteArrayInputStream(new byte[]{}); } return new ByteArrayInputStream(rawBytes); } diff --git a/src/test/java/BehaviorTests/VerbTests.java b/src/test/java/BehaviorTests/VerbTest.java similarity index 97% rename from src/test/java/BehaviorTests/VerbTests.java rename to src/test/java/BehaviorTests/VerbTest.java index 90bbc1d13..72e4d4624 100644 --- a/src/test/java/BehaviorTests/VerbTests.java +++ b/src/test/java/BehaviorTests/VerbTest.java @@ -9,7 +9,7 @@ import static org.junit.Assert.assertEquals; -public class VerbTests extends BddTest { +public class VerbTest extends BddTest { @Test public void get() { Unirest.get(MockServer.GET) From f8a4ea36dce6f62a29cbc67808b02b67bcd2462a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 2 Apr 2018 08:23:54 -0500 Subject: [PATCH 0105/1769] [maven-release-plugin] prepare release v2.2.02 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 63ecf8dd1..9056d97da 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.02-SNAPSHOT + 2.2.02 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.2.02 From df7bdaf5a35ba930cc5fe307914d0d32fdb0e2cd Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 2 Apr 2018 08:23:59 -0500 Subject: [PATCH 0106/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 9056d97da..cc84db610 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.02 + 2.2.03-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.2.02 + HEAD From 8845ff4fdd1ed69bcae6c96483b46021849d7851 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 2 Apr 2018 11:02:37 -0500 Subject: [PATCH 0107/1769] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ebec07602..5679b7b3c 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Unirest.post("http://httpbin.org/post") io.github.openunirest unirest-java - 2.2.00 + 2.2.01 ``` From ae1e2cdf00501772db81cb4c761accd8516f18e2 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 2 Apr 2018 19:41:02 -0500 Subject: [PATCH 0108/1769] add json node tests. Remove impossible code --- .../io/github/openunirest/http/JsonNode.java | 7 ++-- .../github/openunirest/http/JsonNodeTest.java | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 src/test/java/io/github/openunirest/http/JsonNodeTest.java diff --git a/src/main/java/io/github/openunirest/http/JsonNode.java b/src/main/java/io/github/openunirest/http/JsonNode.java index 856128d41..1a9ca869d 100644 --- a/src/main/java/io/github/openunirest/http/JsonNode.java +++ b/src/main/java/io/github/openunirest/http/JsonNode.java @@ -74,12 +74,9 @@ public boolean isArray() { @Override public String toString() { if (isArray()) { - if (jsonArray == null) - return null; return jsonArray.toString(); + } else { + return jsonObject.toString(); } - if (jsonObject == null) - return null; - return jsonObject.toString(); } } diff --git a/src/test/java/io/github/openunirest/http/JsonNodeTest.java b/src/test/java/io/github/openunirest/http/JsonNodeTest.java new file mode 100644 index 000000000..2b2efa84e --- /dev/null +++ b/src/test/java/io/github/openunirest/http/JsonNodeTest.java @@ -0,0 +1,34 @@ +package io.github.openunirest.http; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class JsonNodeTest { + + @Test + public void canParseARegularObject() { + String json = "{\"foo\":\"bar\"}"; + JsonNode node = new JsonNode(json); + assertEquals(false, node.isArray()); + assertEquals("bar", node.getObject().getString("foo")); + assertEquals("bar", node.getArray().getJSONObject(0).getString("foo")); + assertEquals(json, node.toString()); + } + + @Test + public void canParseArrayObject() { + String json = "[{\"foo\":\"bar\"}]"; + JsonNode node = new JsonNode(json); + assertEquals(true, node.isArray()); + assertEquals("bar", node.getArray().getJSONObject(0).getString("foo")); + assertEquals(null, node.getObject()); + assertEquals(json, node.toString()); + } + + @Test + public void nullAndEmptyObjectsResultInEmptyJson() { + assertEquals("{}", new JsonNode("").toString()); + assertEquals("{}", new JsonNode(null).toString()); + } +} \ No newline at end of file From d6de85f32024a224c1d788105b2fe5491d8dec42 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 2 Apr 2018 19:46:05 -0500 Subject: [PATCH 0109/1769] small java-8 refactoring --- .../io/github/openunirest/http/Headers.java | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/Headers.java b/src/main/java/io/github/openunirest/http/Headers.java index 0cbbbd452..08e5f73d9 100644 --- a/src/main/java/io/github/openunirest/http/Headers.java +++ b/src/main/java/io/github/openunirest/http/Headers.java @@ -4,33 +4,33 @@ import org.omg.CORBA.NameValuePair; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; public class Headers extends HashMap> { - private static final long serialVersionUID = 71310341388734766L; - - public Headers(){ - super(); - } - - public Headers(Header[] pairs){ - for (Header header : pairs) { - add(header.getName(), header.getValue()); - } - } - - public String getFirst(Object key) { - List list = get(key); - if (list != null && list.size() > 0) { - return list.get(0); - } - return null; - } - - public void add(String name, String value){ - computeIfAbsent(name, k -> new ArrayList<>()).add(value); - } + private static final long serialVersionUID = 71310341388734766L; + + public Headers() { + super(); + } + + public Headers(Header[] pairs) { + for (Header header : pairs) { + add(header.getName(), header.getValue()); + } + } + + public String getFirst(Object key) { + return getOrDefault(key, Collections.emptyList()) + .stream() + .findFirst() + .orElse(null); + } + + public void add(String name, String value) { + computeIfAbsent(name, k -> new ArrayList<>()).add(value); + } } From 83abd9270ba8b29b443e9a2ff559ab4635f3ca04 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 2 Apr 2018 19:56:50 -0500 Subject: [PATCH 0110/1769] add more tests for character sets --- .../io/github/openunirest/http/BodyData.java | 4 +-- .../openunirest/http/utils/ResponseUtils.java | 2 +- .../http/utils/ResponseUtilsTest.java | 31 +++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 src/test/java/io/github/openunirest/http/utils/ResponseUtilsTest.java diff --git a/src/main/java/io/github/openunirest/http/BodyData.java b/src/main/java/io/github/openunirest/http/BodyData.java index 17437f3de..fbc911495 100644 --- a/src/main/java/io/github/openunirest/http/BodyData.java +++ b/src/main/java/io/github/openunirest/http/BodyData.java @@ -8,7 +8,7 @@ import java.util.Objects; import java.util.function.Function; -import static io.github.openunirest.http.utils.ResponseUtils.getCharsetfromResponse; +import static io.github.openunirest.http.utils.ResponseUtils.getCharSet; import static io.github.openunirest.http.utils.ResponseUtils.getRawBody; @Deprecated // use at your own risk @@ -34,7 +34,7 @@ private BodyData() { } private BodyData(HttpEntity entity) { - this.charset = getCharsetfromResponse(entity); + this.charset = getCharSet(entity); this.rawBytes = getRawBody(entity); } diff --git a/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java b/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java index 20164d63d..1c5635476 100644 --- a/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java +++ b/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java @@ -63,7 +63,7 @@ public static boolean isGzipped(Header contentEncoding) { return false; } - public static String getCharsetfromResponse(HttpEntity responseEntity) { + public static String getCharSet(HttpEntity responseEntity) { Header contentType = responseEntity.getContentType(); if (contentType != null) { String responseCharset = getCharsetFromContentType(contentType.getValue()); diff --git a/src/test/java/io/github/openunirest/http/utils/ResponseUtilsTest.java b/src/test/java/io/github/openunirest/http/utils/ResponseUtilsTest.java new file mode 100644 index 000000000..50f369401 --- /dev/null +++ b/src/test/java/io/github/openunirest/http/utils/ResponseUtilsTest.java @@ -0,0 +1,31 @@ +package io.github.openunirest.http.utils; + +import org.apache.http.HttpEntity; +import org.apache.http.entity.BasicHttpEntity; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ResponseUtilsTest { + + @Test + public void getCharsetDefaults() { + assertEquals("UTF-8", ResponseUtils.getCharSet(entity(null))); + assertEquals("UTF-8", ResponseUtils.getCharSet(entity(""))); + assertEquals("UTF-8", ResponseUtils.getCharSet(entity(" "))); + assertEquals("UTF-8", ResponseUtils.getCharSet(new BasicHttpEntity())); + assertEquals("UTF-8", ResponseUtils.getCharSet(entity("Content-Type: text/html;"))); + assertEquals("UTF-8", ResponseUtils.getCharSet(entity("Content-Type: text/html; charset="))); + } + + @Test + public void contentTypeWhenYouGotIt() { + assertEquals("LATIN-1", ResponseUtils.getCharSet(entity("Content-Type: text/html; charset=latin-1"))); + } + + private HttpEntity entity(String charset) { + BasicHttpEntity e = new BasicHttpEntity(); + e.setContentType(charset); + return e; + } +} \ No newline at end of file From 8a3a184137b8162c61da7362ca232a3ad6c404c7 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 3 Apr 2018 07:25:23 -0500 Subject: [PATCH 0111/1769] fix issues with URL encoding path params --- .../http/utils/URLParamEncoder.java | 29 +++++-------------- src/test/java/BehaviorTests/MockServer.java | 2 ++ .../java/BehaviorTests/PathParamTest.java | 14 +++++++++ .../java/BehaviorTests/RequestCapture.java | 12 ++++++++ 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/utils/URLParamEncoder.java b/src/main/java/io/github/openunirest/http/utils/URLParamEncoder.java index c6403b892..3336667ba 100644 --- a/src/main/java/io/github/openunirest/http/utils/URLParamEncoder.java +++ b/src/main/java/io/github/openunirest/http/utils/URLParamEncoder.java @@ -25,30 +25,15 @@ a copy of this software and associated documentation files (the package io.github.openunirest.http.utils; -public class URLParamEncoder { +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +public class URLParamEncoder { public static String encode(String input) { - StringBuilder resultStr = new StringBuilder(); - for (char ch : input.toCharArray()) { - if (isUnsafe(ch)) { - resultStr.append('%'); - resultStr.append(toHex(ch / 16)); - resultStr.append(toHex(ch % 16)); - } else { - resultStr.append(ch); - } + try { + return URLEncoder.encode(input, "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); } - return resultStr.toString(); - } - - private static char toHex(int ch) { - return (char) (ch < 10 ? '0' + ch : 'A' + ch - 10); } - - private static boolean isUnsafe(char ch) { - if (ch > 128 || ch < 0) - return true; - return " %$&+,/:;=?@<>#%".indexOf(ch) >= 0; - } - } diff --git a/src/test/java/BehaviorTests/MockServer.java b/src/test/java/BehaviorTests/MockServer.java index f76f92992..61eeb6ef5 100644 --- a/src/test/java/BehaviorTests/MockServer.java +++ b/src/test/java/BehaviorTests/MockServer.java @@ -45,6 +45,7 @@ public class MockServer { public static final String GZIP = HOST + "/gzip"; public static final String PATCH = HOST + "/patch"; public static final String INVALID_REQUEST = HOST + "/invalid"; + public static final String PASSED_PATH_PARAM = GET + "/{param}/passed"; public static final String ALTGET = "http://127.0.0.1:" + PORT + "/get"; @@ -67,6 +68,7 @@ public static void reset(){ options("/get", MockServer::jsonResponse); head("/get", MockServer::jsonResponse); put("/post", MockServer::jsonResponse); + get("/get/:p/passed", MockServer::jsonResponse); Runtime.getRuntime().addShutdownHook(new Thread(Spark::stop)); } diff --git a/src/test/java/BehaviorTests/PathParamTest.java b/src/test/java/BehaviorTests/PathParamTest.java index a99adf972..90c2d3a22 100644 --- a/src/test/java/BehaviorTests/PathParamTest.java +++ b/src/test/java/BehaviorTests/PathParamTest.java @@ -1,7 +1,9 @@ package BehaviorTests; +import io.github.openunirest.http.HttpResponse; import io.github.openunirest.http.Unirest; import io.github.openunirest.http.exceptions.UnirestException; +import io.github.openunirest.request.HttpRequest; import org.junit.Test; import util.TestUtil; @@ -59,4 +61,16 @@ public void testMissingPathParameterValue() { UnirestException.class, "java.net.URISyntaxException: Illegal character in path at index 22: http://localhost:4567/{method}?name=Mark"); } + + @Test + public void illigalPathParams() { + String value = "/?ЊЯЯ"; + + Unirest.get(MockServer.PASSED_PATH_PARAM) + .routeParam("param", value) + .asObject(RequestCapture.class) + .getBody() + .assertUrl("http://localhost:4567/get/%2F%3F%D0%8A%D0%AF%D0%AF/passed") + .assertPathParam(value); + } } diff --git a/src/test/java/BehaviorTests/RequestCapture.java b/src/test/java/BehaviorTests/RequestCapture.java index 3f85e8a3c..c5848712e 100644 --- a/src/test/java/BehaviorTests/RequestCapture.java +++ b/src/test/java/BehaviorTests/RequestCapture.java @@ -29,6 +29,7 @@ public class RequestCapture { public String url; public String queryString; public HttpMethod method; + public String param; public RequestCapture() { } @@ -39,6 +40,7 @@ public RequestCapture(Request req) { method = HttpMethod.valueOf(req.requestMethod()); writeHeaders(req); writeQuery(req); + param = req.params("p"); } public void writeBody(Request req) { @@ -153,6 +155,16 @@ public void asserMethod(HttpMethod get) { assertEquals(get, method); } + public RequestCapture assertPathParam(String value) { + assertEquals(value, param); + return this; + } + + public RequestCapture assertUrl(String s) { + assertEquals(s, url); + return this; + } + public static class File { public String fileName; public String type; From 4663d4a84e2148c9d88cd19628425ac1bba9b947 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 3 Apr 2018 10:31:44 -0500 Subject: [PATCH 0112/1769] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5679b7b3c..74bba9e87 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Unirest.post("http://httpbin.org/post") io.github.openunirest unirest-java - 2.2.01 + 2.2.02 ``` From 9fb5e9d36bc45a78e8f386c059aef99d33fc77f6 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 3 Apr 2018 10:34:32 -0500 Subject: [PATCH 0113/1769] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a25a1d6cb..7b79bbc39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 2.2.01 +* Fix NPE with null bodies from HEAD requests. + +# 2.2.01 +* Quitly consume and close InputStreams that may not be complete. + # 2.2.00 * Major refactoring of how response objects are built. This internalizes HttpClientHelper which was previously public but not needed if you were using the library in in the expected way. This refactoring sets up the library for future work to extend the number of supported formats and for greater expression in the methods for those formats. * Additional of functional map methods to HttpResponse so you don't have to stop the flow for further transformations. From 6aaedf38c7a1c9666299106403a6aa4dcf0efcb2 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 3 Apr 2018 10:35:30 -0500 Subject: [PATCH 0114/1769] Update CHANGELOG.md --- CHANGELOG.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b79bbc39..947695120 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,22 +1,22 @@ -# 2.2.01 +## 2.2.02 * Fix NPE with null bodies from HEAD requests. -# 2.2.01 +## 2.2.01 * Quitly consume and close InputStreams that may not be complete. -# 2.2.00 +## 2.2.00 * Major refactoring of how response objects are built. This internalizes HttpClientHelper which was previously public but not needed if you were using the library in in the expected way. This refactoring sets up the library for future work to extend the number of supported formats and for greater expression in the methods for those formats. * Additional of functional map methods to HttpResponse so you don't have to stop the flow for further transformations. * Update the org.json dependency * Fixed issue with achor hashes in URLs (#17) * Fixed NPE in passing args as maps (#20) -# 2.1.01 +## 2.1.01 * JSON parsing errors no longer just throw out of ```asJson``` but are captured and can be inspected via ```HttpResponse::getParsingError```. This resolves the fact that most API's do not return valid JSON for non-200 status codes. * Return CompletableFuture rather that boring old Futures for all async methods. -# 2.0.02 +## 2.0.02 * UnirestException is no longer checked * Namespaces have been migrated to new **io.gitgub.openunirest** namespace * Thread leak in Options fixed From 2804e8e71998fd858c428f79a7df314664fece76 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 11 Apr 2018 11:24:42 -0500 Subject: [PATCH 0115/1769] test formatting cleanup --- src/test/java/BehaviorTests/AsBinaryTest.java | 6 ++--- src/test/java/BehaviorTests/AsJsonTest.java | 7 +++--- src/test/java/BehaviorTests/AsObjectTest.java | 4 +--- src/test/java/BehaviorTests/AsStringTest.java | 6 ++--- .../BehaviorTests/CallbackFutureTest.java | 2 +- src/test/java/BehaviorTests/DefectTest.java | 16 ++++++------- .../java/BehaviorTests/FormPostingTest.java | 23 +++++++++---------- src/test/java/BehaviorTests/GZipTest.java | 7 ++---- src/test/java/BehaviorTests/HeaderTest.java | 19 +++++++-------- .../java/BehaviorTests/LifeCycleTest.java | 5 ++-- .../java/BehaviorTests/PathParamTest.java | 2 -- .../java/BehaviorTests/QueryStringTest.java | 14 +++++------ src/test/java/BehaviorTests/VerbTest.java | 1 - 13 files changed, 52 insertions(+), 60 deletions(-) diff --git a/src/test/java/BehaviorTests/AsBinaryTest.java b/src/test/java/BehaviorTests/AsBinaryTest.java index 829a07a2e..fce12644f 100644 --- a/src/test/java/BehaviorTests/AsBinaryTest.java +++ b/src/test/java/BehaviorTests/AsBinaryTest.java @@ -1,12 +1,12 @@ package BehaviorTests; -import io.github.openunirest.http.*; +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.Unirest; import org.junit.Test; import util.TestUtil; import java.io.InputStream; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; public class AsBinaryTest extends BddTest { @Test @@ -20,7 +20,7 @@ public void canGetBinaryResponse() { } @Test - public void canGetBinaryResponseAsync() throws ExecutionException, InterruptedException { + public void canGetBinaryResponseAsync() throws Exception { CompletableFuture> r = Unirest.get(MockServer.GET) .queryString("foo", "bar") .asBinaryAsync(); diff --git a/src/test/java/BehaviorTests/AsJsonTest.java b/src/test/java/BehaviorTests/AsJsonTest.java index e693f9a0c..b63d09ada 100644 --- a/src/test/java/BehaviorTests/AsJsonTest.java +++ b/src/test/java/BehaviorTests/AsJsonTest.java @@ -1,12 +1,13 @@ package BehaviorTests; -import io.github.openunirest.http.*; +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.JsonNode; +import io.github.openunirest.http.Unirest; import org.junit.Test; import util.MockCallback; import util.TestUtil; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; @@ -22,7 +23,7 @@ public void canGetBinaryResponse() { } @Test - public void canGetBinaryResponseAsync() throws ExecutionException, InterruptedException { + public void canGetBinaryResponseAsync() throws Exception { CompletableFuture> r = Unirest.get(MockServer.GET) .queryString("foo", "bar") .asJsonAsync(); diff --git a/src/test/java/BehaviorTests/AsObjectTest.java b/src/test/java/BehaviorTests/AsObjectTest.java index 5db6d1142..10e14f27b 100644 --- a/src/test/java/BehaviorTests/AsObjectTest.java +++ b/src/test/java/BehaviorTests/AsObjectTest.java @@ -3,8 +3,6 @@ import io.github.openunirest.http.Unirest; import org.junit.Test; -import java.util.concurrent.ExecutionException; - public class AsObjectTest extends BddTest { @Test public void canGetObjectResponse() { @@ -16,7 +14,7 @@ public void canGetObjectResponse() { } @Test - public void canGetObjectResponseAsync() throws ExecutionException, InterruptedException { + public void canGetObjectResponseAsync() throws Exception { Unirest.get(MockServer.GET) .queryString("foo", "bar") .asObjectAsync(RequestCapture.class) diff --git a/src/test/java/BehaviorTests/AsStringTest.java b/src/test/java/BehaviorTests/AsStringTest.java index 6d80f2b4e..4a10ca46e 100644 --- a/src/test/java/BehaviorTests/AsStringTest.java +++ b/src/test/java/BehaviorTests/AsStringTest.java @@ -1,11 +1,11 @@ package BehaviorTests; -import io.github.openunirest.http.*; +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.Unirest; import org.junit.Test; import util.TestUtil; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; public class AsStringTest extends BddTest { @@ -21,7 +21,7 @@ public void canGetBinaryResponse() { } @Test - public void canGetBinaryResponseAsync() throws ExecutionException, InterruptedException { + public void canGetBinaryResponseAsync() throws Exception { CompletableFuture> r = Unirest.get(MockServer.GET) .queryString("foo", "bar") .asStringAsync(); diff --git a/src/test/java/BehaviorTests/CallbackFutureTest.java b/src/test/java/BehaviorTests/CallbackFutureTest.java index f1cd47dc7..c7102d33e 100644 --- a/src/test/java/BehaviorTests/CallbackFutureTest.java +++ b/src/test/java/BehaviorTests/CallbackFutureTest.java @@ -36,7 +36,7 @@ public void onSuccessSupplyCallback() throws Exception { @Test(timeout = 5000) public void onFailure() throws Exception { - Unirest.get("http://localhost:0000") + Unirest.get("http://localhost:0000") .asJsonAsync(json(this)) .isCompletedExceptionally(); diff --git a/src/test/java/BehaviorTests/DefectTest.java b/src/test/java/BehaviorTests/DefectTest.java index a113a82f0..b7400188f 100644 --- a/src/test/java/BehaviorTests/DefectTest.java +++ b/src/test/java/BehaviorTests/DefectTest.java @@ -13,22 +13,22 @@ public void hashOnLinksDoNotMessUpUri() { Unirest.get(MockServer.GET + "?a=1&b=2#some_location") .asObject(RequestCapture.class) .getBody() - .assertParam("a","1") + .assertParam("a", "1") .assertParam("b", "2"); } @Test - public void nullAndObjectValuesInMap(){ + public void nullAndObjectValuesInMap() { Map queryParams = new HashMap<>(); queryParams.put("foo", null); queryParams.put("baz", "qux"); Unirest.get(MockServer.GET) - .queryString(queryParams) - .asObject(RequestCapture.class) - .getBody() - .assertParam("foo", "") - .assertParam("baz", "qux") - .assertQueryString("foo&baz=qux"); + .queryString(queryParams) + .asObject(RequestCapture.class) + .getBody() + .assertParam("foo", "") + .assertParam("baz", "qux") + .assertQueryString("foo&baz=qux"); } } diff --git a/src/test/java/BehaviorTests/FormPostingTest.java b/src/test/java/BehaviorTests/FormPostingTest.java index 12b22ed23..2e752ef23 100644 --- a/src/test/java/BehaviorTests/FormPostingTest.java +++ b/src/test/java/BehaviorTests/FormPostingTest.java @@ -1,20 +1,19 @@ package BehaviorTests; -import util.TestUtil; import io.github.openunirest.http.Unirest; -import util.MockCallback; -import io.github.openunirest.http.exceptions.UnirestException; import io.github.openunirest.request.HttpRequest; import org.apache.commons.io.IOUtils; import org.apache.http.entity.ContentType; -import org.json.JSONException; import org.junit.Test; +import util.MockCallback; +import util.TestUtil; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; import java.net.URISyntaxException; import java.util.Arrays; -import static com.google.common.collect.ImmutableMap.of; import static org.junit.Assert.assertEquals; public class FormPostingTest extends BddTest { @@ -170,7 +169,7 @@ public void testAsyncCustomContentTypeAndFormParams() { } @Test - public void testPostMultipleFiles() throws JSONException, URISyntaxException { + public void testPostMultipleFiles()throws Exception { Unirest.post(MockServer.POST) .field("param3", "wot") .field("file1", new File(getClass().getResource("/test").toURI())) @@ -183,7 +182,7 @@ public void testPostMultipleFiles() throws JSONException, URISyntaxException { } @Test - public void testPostArray() throws JSONException, UnirestException { + public void testPostArray() { Unirest.post(MockServer.POST) .field("name", "Mark") .field("name", "Tom") @@ -204,7 +203,7 @@ public void testPostUTF8() { } @Test - public void testPostBinaryUTF8() throws URISyntaxException { + public void testPostBinaryUTF8() throws Exception { Unirest.post(MockServer.POST) .header("Accept", ContentType.MULTIPART_FORM_DATA.getMimeType()) .field("param3", "こんにちは") @@ -216,7 +215,7 @@ public void testPostBinaryUTF8() throws URISyntaxException { } @Test - public void testPostCollection() throws JSONException, UnirestException { + public void testPostCollection() { Unirest.post(MockServer.POST) .field("name", Arrays.asList("Mark", "Tom")) .asObject(RequestCapture.class) @@ -226,7 +225,7 @@ public void testPostCollection() throws JSONException, UnirestException { } @Test - public void testPostProvidesSortedParams() throws IOException { + public void testPostProvidesSortedParams() throws Exception { // Verify that fields are encoded into the body in sorted order. HttpRequest httpRequest = Unirest.post("test") .field("z", "Z") @@ -240,7 +239,7 @@ public void testPostProvidesSortedParams() throws IOException { } @Test - public void postFileWithContentType() throws URISyntaxException { + public void postFileWithContentType() throws Exception { File file = getImageFile(); Unirest.post(MockServer.POST) .field("testfile", file, ContentType.IMAGE_JPEG.getMimeType()) diff --git a/src/test/java/BehaviorTests/GZipTest.java b/src/test/java/BehaviorTests/GZipTest.java index a75eae812..b1ac1906e 100644 --- a/src/test/java/BehaviorTests/GZipTest.java +++ b/src/test/java/BehaviorTests/GZipTest.java @@ -1,14 +1,11 @@ package BehaviorTests; import io.github.openunirest.http.Unirest; -import org.json.JSONException; import org.junit.Test; -import java.util.concurrent.ExecutionException; - public class GZipTest extends BddTest { @Test - public void testGzip() throws JSONException { + public void testGzip() { Unirest.get(MockServer.GZIP) .queryString("zipme", "up") .asObject(RequestCapture.class) @@ -17,7 +14,7 @@ public void testGzip() throws JSONException { } @Test - public void testGzipAsync() throws JSONException, InterruptedException, ExecutionException { + public void testGzipAsync() throws Exception { Unirest.get(MockServer.GZIP) .queryString("zipme", "up") .asObjectAsync(RequestCapture.class) diff --git a/src/test/java/BehaviorTests/HeaderTest.java b/src/test/java/BehaviorTests/HeaderTest.java index d8b09f6f6..f4fdaf7a4 100644 --- a/src/test/java/BehaviorTests/HeaderTest.java +++ b/src/test/java/BehaviorTests/HeaderTest.java @@ -1,19 +1,20 @@ package BehaviorTests; -import io.github.openunirest.http.*; -import io.github.openunirest.http.exceptions.UnirestException; +import io.github.openunirest.http.Headers; +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.JsonNode; +import io.github.openunirest.http.Unirest; import io.github.openunirest.request.GetRequest; -import org.json.JSONException; import org.junit.Test; import java.util.Arrays; -import static util.TestUtil.mapOf; import static org.junit.Assert.assertEquals; +import static util.TestUtil.mapOf; public class HeaderTest extends BddTest { @Test - public void testCustomUserAgent() throws JSONException, UnirestException { + public void testCustomUserAgent() { Unirest.get(MockServer.GET) .header("user-agent", "hello-world") .asObject(RequestCapture.class) @@ -22,7 +23,7 @@ public void testCustomUserAgent() throws JSONException, UnirestException { } @Test - public void testBasicAuth() throws JSONException, UnirestException { + public void testBasicAuth() { Unirest.get(MockServer.GET) .basicAuth("user", "test") .asObject(RequestCapture.class) @@ -32,7 +33,7 @@ public void testBasicAuth() throws JSONException, UnirestException { } @Test - public void unicodeBasicAuth() throws JSONException, UnirestException { + public void unicodeBasicAuth() { Unirest.get(MockServer.GET) .basicAuth("こんにちは", "こんにちは") .asObject(RequestCapture.class) @@ -42,7 +43,7 @@ public void unicodeBasicAuth() throws JSONException, UnirestException { } @Test - public void testDefaultHeaders() throws JSONException { + public void testDefaultHeaders() { Unirest.setDefaultHeader("X-Custom-Header", "hello"); Unirest.setDefaultHeader("user-agent", "foobar"); @@ -125,7 +126,7 @@ public void willNotCacheBasicAuth() { .basicAuth("foo", "bar") .asObject(RequestCapture.class) .getBody() - .assertBasicAuth("foo","bar"); + .assertBasicAuth("foo", "bar"); Unirest.get(MockServer.GET) .basicAuth("baz", "qux") diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index 584edc9e5..e505f0b5f 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -16,8 +16,9 @@ import static org.mockito.Mockito.*; public class LifeCycleTest extends BddTest { - @After @Before - public void tearDown() throws Exception { + @After + @Before + public void tearDown() { Options.reset(); } diff --git a/src/test/java/BehaviorTests/PathParamTest.java b/src/test/java/BehaviorTests/PathParamTest.java index 90c2d3a22..066c3fbcf 100644 --- a/src/test/java/BehaviorTests/PathParamTest.java +++ b/src/test/java/BehaviorTests/PathParamTest.java @@ -1,9 +1,7 @@ package BehaviorTests; -import io.github.openunirest.http.HttpResponse; import io.github.openunirest.http.Unirest; import io.github.openunirest.http.exceptions.UnirestException; -import io.github.openunirest.request.HttpRequest; import org.junit.Test; import util.TestUtil; diff --git a/src/test/java/BehaviorTests/QueryStringTest.java b/src/test/java/BehaviorTests/QueryStringTest.java index 22a363742..7934b29e8 100644 --- a/src/test/java/BehaviorTests/QueryStringTest.java +++ b/src/test/java/BehaviorTests/QueryStringTest.java @@ -3,15 +3,13 @@ import io.github.openunirest.http.HttpResponse; import io.github.openunirest.http.JsonNode; import io.github.openunirest.http.Unirest; -import io.github.openunirest.http.exceptions.UnirestException; -import org.json.JSONException; import org.junit.Test; import java.util.Arrays; public class QueryStringTest extends BddTest { @Test - public void testGetQueryStrings() throws JSONException, UnirestException { + public void testGetQueryStrings() { Unirest.get(MockServer.GET) .queryString("name", "mark") .queryString("nick", "thefosk") @@ -36,7 +34,7 @@ public void canPassQueryParamsDirectlyOnUriOrWithMethod() { } @Test - public void multipleParams() throws JSONException, UnirestException { + public void multipleParams() { Unirest.get(MockServer.GET + "?name=ringo") .queryString("name", "paul") .queryString("name", "john") @@ -57,7 +55,7 @@ public void testGetUTF8() { } @Test - public void testGetMultiple() throws JSONException, UnirestException { + public void testGetMultiple() { for (int i = 1; i <= 20; i++) { HttpResponse response = Unirest.get(MockServer.GET + "?try=" + i).asJson(); parse(response).assertParam("try", String.valueOf(i)); @@ -65,7 +63,7 @@ public void testGetMultiple() throws JSONException, UnirestException { } @Test - public void testQueryStringEncoding() throws JSONException, UnirestException { + public void testQueryStringEncoding() { String testKey = "email2=someKey&email"; String testValue = "hello@hello.com"; @@ -77,7 +75,7 @@ public void testQueryStringEncoding() throws JSONException, UnirestException { } @Test - public void testGetQuerystringArray() throws JSONException, UnirestException { + public void testGetQuerystringArray() { Unirest.get(MockServer.GET) .queryString("name", "Mark") .queryString("name", "Tom") @@ -88,7 +86,7 @@ public void testGetQuerystringArray() throws JSONException, UnirestException { } @Test - public void testGetArray() throws JSONException, UnirestException { + public void testGetArray() { Unirest.get(MockServer.GET) .queryString("name", Arrays.asList("Mark", "Tom")) .asObject(RequestCapture.class) diff --git a/src/test/java/BehaviorTests/VerbTest.java b/src/test/java/BehaviorTests/VerbTest.java index 72e4d4624..7b260f1ec 100644 --- a/src/test/java/BehaviorTests/VerbTest.java +++ b/src/test/java/BehaviorTests/VerbTest.java @@ -57,5 +57,4 @@ public void option() { .getBody() .asserMethod(HttpMethod.OPTIONS); } - } From 1311040b1a442ad53d07dc75666cf51c747c963f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 11 Apr 2018 11:50:30 -0500 Subject: [PATCH 0116/1769] add checkstyle and enforce style --- checkstyle.xml | 240 ++++++++++++++++++ pom.xml | 28 ++ .../io/github/openunirest/http/Headers.java | 1 - .../github/openunirest/http/HttpMethod.java | 3 +- .../github/openunirest/http/HttpResponse.java | 3 +- .../io/github/openunirest/http/JsonNode.java | 3 +- .../io/github/openunirest/http/Unirest.java | 5 +- .../openunirest/http/async/Callback.java | 3 +- .../openunirest/http/options/Options.java | 16 +- .../openunirest/http/utils/MapUtil.java | 9 +- .../openunirest/http/utils/ResponseUtils.java | 20 +- .../http/utils/URLParamEncoder.java | 3 +- .../openunirest/request/BaseRequest.java | 3 +- .../openunirest/request/GetRequest.java | 8 +- .../request/HttpDeleteWithBody.java | 3 +- .../request/HttpPatchWithBody.java | 7 +- .../openunirest/request/HttpRequest.java | 16 +- .../request/HttpRequestWithBody.java | 13 +- .../openunirest/request/RequestPrep.java | 98 ++++--- .../openunirest/request/UriFormatter.java | 1 - .../github/openunirest/request/body/Body.java | 3 +- .../request/body/MultipartBody.java | 33 +-- .../openunirest/request/body/RawBody.java | 9 +- .../request/body/RequestBodyEntity.java | 15 +- suppressions.xml | 9 + 25 files changed, 419 insertions(+), 133 deletions(-) create mode 100644 checkstyle.xml create mode 100644 suppressions.xml diff --git a/checkstyle.xml b/checkstyle.xml new file mode 100644 index 000000000..4c1c3fe68 --- /dev/null +++ b/checkstyle.xml @@ -0,0 +1,240 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index cc84db610..92875253a 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,34 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.13 + + + com.puppycrawl.tools + checkstyle + 5.9 + + + + + compile + auto-checkstyle + + checkstyle + check + + + + + ${basedir}/checkstyle.xml + ${basedir}/suppressions.xml + true + false + + org.jacoco jacoco-maven-plugin diff --git a/src/main/java/io/github/openunirest/http/Headers.java b/src/main/java/io/github/openunirest/http/Headers.java index 08e5f73d9..09be5d7c6 100644 --- a/src/main/java/io/github/openunirest/http/Headers.java +++ b/src/main/java/io/github/openunirest/http/Headers.java @@ -1,7 +1,6 @@ package io.github.openunirest.http; import org.apache.http.Header; -import org.omg.CORBA.NameValuePair; import java.util.ArrayList; import java.util.Collections; diff --git a/src/main/java/io/github/openunirest/http/HttpMethod.java b/src/main/java/io/github/openunirest/http/HttpMethod.java index 84e98115f..889f5c8b3 100644 --- a/src/main/java/io/github/openunirest/http/HttpMethod.java +++ b/src/main/java/io/github/openunirest/http/HttpMethod.java @@ -1,7 +1,8 @@ /* The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/io/github/openunirest/http/HttpResponse.java b/src/main/java/io/github/openunirest/http/HttpResponse.java index 4be7f4a7d..aeb4eb2a9 100644 --- a/src/main/java/io/github/openunirest/http/HttpResponse.java +++ b/src/main/java/io/github/openunirest/http/HttpResponse.java @@ -1,7 +1,8 @@ /* The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/io/github/openunirest/http/JsonNode.java b/src/main/java/io/github/openunirest/http/JsonNode.java index 1a9ca869d..db197706c 100644 --- a/src/main/java/io/github/openunirest/http/JsonNode.java +++ b/src/main/java/io/github/openunirest/http/JsonNode.java @@ -1,7 +1,8 @@ /* The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/io/github/openunirest/http/Unirest.java b/src/main/java/io/github/openunirest/http/Unirest.java index ff60017ba..cd957413f 100644 --- a/src/main/java/io/github/openunirest/http/Unirest.java +++ b/src/main/java/io/github/openunirest/http/Unirest.java @@ -1,7 +1,8 @@ /* The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -25,8 +26,6 @@ a copy of this software and associated documentation files (the package io.github.openunirest.http; -import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; -import io.github.openunirest.http.utils.SyncIdleConnectionMonitorThread; import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; import io.github.openunirest.http.options.Option; import io.github.openunirest.http.options.Options; diff --git a/src/main/java/io/github/openunirest/http/async/Callback.java b/src/main/java/io/github/openunirest/http/async/Callback.java index b11a12850..e19cc5d83 100644 --- a/src/main/java/io/github/openunirest/http/async/Callback.java +++ b/src/main/java/io/github/openunirest/http/async/Callback.java @@ -1,7 +1,8 @@ /* The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/io/github/openunirest/http/options/Options.java b/src/main/java/io/github/openunirest/http/options/Options.java index ddff8a2cd..892226a4d 100644 --- a/src/main/java/io/github/openunirest/http/options/Options.java +++ b/src/main/java/io/github/openunirest/http/options/Options.java @@ -1,10 +1,5 @@ package io.github.openunirest.http.options; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; import io.github.openunirest.http.utils.SyncIdleConnectionMonitorThread; import org.apache.http.HttpHost; @@ -18,8 +13,10 @@ import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor; import org.apache.http.nio.reactor.IOReactorException; -import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; -import io.github.openunirest.http.utils.SyncIdleConnectionMonitorThread; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; public class Options { public static final int MAX_TOTAL = 200; @@ -50,7 +47,10 @@ public static void setOption(Option option, Object value) { private static void validateOption(Option option) { if ((option == Option.CONNECTION_TIMEOUT || option == Option.SOCKET_TIMEOUT) && customClientSet) { - throw new RuntimeException("You can't set custom timeouts when providing custom client implementations. Set the timeouts directly in your custom client configuration instead."); + throw new RuntimeException( + "You can't set custom timeouts when providing custom client implementations. " + + "Set the timeouts directly in your custom client configuration instead." + ); } } diff --git a/src/main/java/io/github/openunirest/http/utils/MapUtil.java b/src/main/java/io/github/openunirest/http/utils/MapUtil.java index babe0e106..847f900f6 100644 --- a/src/main/java/io/github/openunirest/http/utils/MapUtil.java +++ b/src/main/java/io/github/openunirest/http/utils/MapUtil.java @@ -1,7 +1,8 @@ /* The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -25,15 +26,15 @@ a copy of this software and associated documentation files (the package io.github.openunirest.http.utils; +import org.apache.http.NameValuePair; +import org.apache.http.message.BasicNameValuePair; + import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; -import org.apache.http.NameValuePair; -import org.apache.http.message.BasicNameValuePair; - public class MapUtil { public static List getList(Map> parameters) { diff --git a/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java b/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java index 1c5635476..6d6539ab6 100644 --- a/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java +++ b/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java @@ -1,5 +1,10 @@ package io.github.openunirest.http.utils; +import io.github.openunirest.http.exceptions.UnirestException; +import org.apache.http.Header; +import org.apache.http.HttpEntity; +import org.apache.http.util.EntityUtils; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -8,14 +13,9 @@ import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; -import io.github.openunirest.http.exceptions.UnirestException; -import org.apache.http.Header; -import org.apache.http.HttpEntity; -import org.apache.http.util.EntityUtils; - public class ResponseUtils { - private static final Pattern charsetPattern = Pattern.compile("(?i)\\bcharset=\\s*\"?([^\\s;\"]*)"); + private static final Pattern CHARSET_PATTERN = Pattern.compile("(?i)\\bcharset=\\s*\"?([^\\s;\"]*)"); /** * Parse out a charset from a content type header. @@ -24,10 +24,11 @@ public class ResponseUtils { * @return "EUC-JP", or null if not found. Charset is trimmed and uppercased. */ public static String getCharsetFromContentType(String contentType) { - if (contentType == null) + if (contentType == null) { return null; + } - Matcher m = charsetPattern.matcher(contentType); + Matcher m = CHARSET_PATTERN.matcher(contentType); if (m.find()) { return m.group(1).trim().toUpperCase(); } @@ -46,8 +47,9 @@ public static byte[] getBytes(InputStream is) throws IOException { } else { ByteArrayOutputStream bos = new ByteArrayOutputStream(); buf = new byte[size]; - while ((len = is.read(buf, 0, size)) != -1) + while ((len = is.read(buf, 0, size)) != -1) { bos.write(buf, 0, len); + } buf = bos.toByteArray(); } return buf; diff --git a/src/main/java/io/github/openunirest/http/utils/URLParamEncoder.java b/src/main/java/io/github/openunirest/http/utils/URLParamEncoder.java index 3336667ba..dc85a9769 100644 --- a/src/main/java/io/github/openunirest/http/utils/URLParamEncoder.java +++ b/src/main/java/io/github/openunirest/http/utils/URLParamEncoder.java @@ -1,7 +1,8 @@ /* The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/io/github/openunirest/request/BaseRequest.java b/src/main/java/io/github/openunirest/request/BaseRequest.java index da181cbe6..d6eca3931 100644 --- a/src/main/java/io/github/openunirest/request/BaseRequest.java +++ b/src/main/java/io/github/openunirest/request/BaseRequest.java @@ -1,7 +1,8 @@ /* The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/io/github/openunirest/request/GetRequest.java b/src/main/java/io/github/openunirest/request/GetRequest.java index 4f7d3e901..b01e54d4f 100644 --- a/src/main/java/io/github/openunirest/request/GetRequest.java +++ b/src/main/java/io/github/openunirest/request/GetRequest.java @@ -1,7 +1,8 @@ /* The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -25,11 +26,10 @@ a copy of this software and associated documentation files (the package io.github.openunirest.request; -import java.util.Map; - -import io.github.openunirest.http.HttpMethod; import io.github.openunirest.http.HttpMethod; +import java.util.Map; + public class GetRequest extends HttpRequest { public GetRequest(HttpMethod method, String url) { diff --git a/src/main/java/io/github/openunirest/request/HttpDeleteWithBody.java b/src/main/java/io/github/openunirest/request/HttpDeleteWithBody.java index f104db0ae..e0deb02f4 100644 --- a/src/main/java/io/github/openunirest/request/HttpDeleteWithBody.java +++ b/src/main/java/io/github/openunirest/request/HttpDeleteWithBody.java @@ -1,7 +1,8 @@ /* The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/io/github/openunirest/request/HttpPatchWithBody.java b/src/main/java/io/github/openunirest/request/HttpPatchWithBody.java index 14459e5e3..127f05178 100644 --- a/src/main/java/io/github/openunirest/request/HttpPatchWithBody.java +++ b/src/main/java/io/github/openunirest/request/HttpPatchWithBody.java @@ -1,7 +1,8 @@ /* The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -25,10 +26,10 @@ a copy of this software and associated documentation files (the package io.github.openunirest.request; -import java.net.URI; - import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; +import java.net.URI; + class HttpPatchWithBody extends HttpEntityEnclosingRequestBase { public static final String METHOD_NAME = "PATCH"; diff --git a/src/main/java/io/github/openunirest/request/HttpRequest.java b/src/main/java/io/github/openunirest/request/HttpRequest.java index a07a78c1c..7c165169a 100644 --- a/src/main/java/io/github/openunirest/request/HttpRequest.java +++ b/src/main/java/io/github/openunirest/request/HttpRequest.java @@ -1,7 +1,8 @@ /* The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -77,9 +78,9 @@ public HttpRequest header(String name, String value) { return this; } - public HttpRequest headers(Map headers) { + public HttpRequest headers(Map headerMap) { if (headers != null) { - for (Map.Entry entry : headers.entrySet()) { + for (Map.Entry entry : headerMap.entrySet()) { header(entry.getKey(), entry.getValue()); } } @@ -118,7 +119,9 @@ public HttpRequest queryString(Map parameters) { if (param.getValue() instanceof String || param.getValue() instanceof Number || param.getValue() instanceof Boolean || param.getValue() == null) { queryString(param.getKey(), param.getValue()); } else { - throw new RuntimeException("Parameter \"" + param.getKey() + "\" can't be sent with a GET request because of type: " + param.getValue().getClass().getName()); + throw new RuntimeException("Parameter \"" + param.getKey() + + "\" can't be sent with a GET request because of type: " + + param.getValue().getClass().getName()); } } } @@ -134,8 +137,9 @@ public String getUrl() { } public Map> getHeaders() { - if (headers == null) - return new HashMap>(); + if (headers == null) { + return new HashMap<>(); + } return headers; } diff --git a/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java b/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java index c9bb19799..4075b2017 100644 --- a/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java +++ b/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java @@ -1,7 +1,8 @@ /* The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -29,19 +30,13 @@ a copy of this software and associated documentation files (the import io.github.openunirest.http.JsonNode; import io.github.openunirest.http.ObjectMapper; import io.github.openunirest.http.exceptions.UnirestConfigException; -import io.github.openunirest.request.body.MultipartBody; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.mime.content.InputStreamBody; - -import io.github.openunirest.http.HttpMethod; -import io.github.openunirest.http.JsonNode; -import io.github.openunirest.http.ObjectMapper; import io.github.openunirest.http.options.Option; import io.github.openunirest.http.options.Options; import io.github.openunirest.request.body.MultipartBody; import io.github.openunirest.request.body.RawBody; import io.github.openunirest.request.body.RequestBodyEntity; - +import org.apache.http.entity.ContentType; +import org.apache.http.entity.mime.content.InputStreamBody; import org.json.JSONArray; import org.json.JSONObject; diff --git a/src/main/java/io/github/openunirest/request/RequestPrep.java b/src/main/java/io/github/openunirest/request/RequestPrep.java index 4f83bc3a6..1b31c333b 100644 --- a/src/main/java/io/github/openunirest/request/RequestPrep.java +++ b/src/main/java/io/github/openunirest/request/RequestPrep.java @@ -18,10 +18,62 @@ class RequestPrep { private static final String ACCEPT_ENCODING_HEADER = "accept-encoding"; private static final String USER_AGENT_HEADER = "user-agent"; private static final String USER_AGENT = "unirest-java/1.3.11"; - private static final UriFormatter uriFormatter = new UriFormatter(); + private static final UriFormatter URI_FORMATTER = new UriFormatter(); public static HttpRequestBase prepareRequest(HttpRequest request, boolean async) { + setDefaultHeaders(request); + + if (!request.getHeaders().containsKey(USER_AGENT_HEADER)) { + request.header(USER_AGENT_HEADER, USER_AGENT); + } + if (!request.getHeaders().containsKey(ACCEPT_ENCODING_HEADER)) { + request.header(ACCEPT_ENCODING_HEADER, "gzip"); + } + + HttpRequestBase reqObj = getHttpRequest(request); + setRequestHeaders(request, reqObj); + setBody(request, async, reqObj); + + return reqObj; + } + + private static void setBody(HttpRequest request, boolean async, HttpRequestBase reqObj) { + if (!(request.getHttpMethod() == HttpMethod.GET || request.getHttpMethod() == HttpMethod.HEAD)) { + if (request.getBody() != null) { + HttpEntity entity = request.getBody().getEntity(); + if (async) { + if (reqObj.getHeaders(CONTENT_TYPE) == null || reqObj.getHeaders(CONTENT_TYPE).length == 0) { + reqObj.setHeader(entity.getContentType()); + } + try { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + entity.writeTo(output); + NByteArrayEntity en = new NByteArrayEntity(output.toByteArray()); + ((HttpEntityEnclosingRequestBase) reqObj).setEntity(en); + } catch (IOException e) { + throw new RuntimeException(e); + } + } else { + ((HttpEntityEnclosingRequestBase) reqObj).setEntity(entity); + } + } + } + } + + private static void setRequestHeaders(HttpRequest request, HttpRequestBase reqObj) { + Set>> entrySet = request.getHeaders().entrySet(); + for (Map.Entry> entry : entrySet) { + List values = entry.getValue(); + if (values != null) { + for (String value : values) { + reqObj.addHeader(entry.getKey(), value); + } + } + } + } + + private static void setDefaultHeaders(HttpRequest request) { Object defaultHeaders = Options.getOption(Option.DEFAULT_HEADERS); if (defaultHeaders != null) { @SuppressWarnings("unchecked") @@ -30,17 +82,12 @@ public static HttpRequestBase prepareRequest(HttpRequest request, boolean async) request.header(entry.getKey(), entry.getValue()); } } + } - if (!request.getHeaders().containsKey(USER_AGENT_HEADER)) { - request.header(USER_AGENT_HEADER, USER_AGENT); - } - if (!request.getHeaders().containsKey(ACCEPT_ENCODING_HEADER)) { - request.header(ACCEPT_ENCODING_HEADER, "gzip"); - } - + private static HttpRequestBase getHttpRequest(HttpRequest request) { HttpRequestBase reqObj = null; - String urlToRequest = uriFormatter.apply(request); + String urlToRequest = URI_FORMATTER.apply(request); switch (request.getHttpMethod()) { case GET: @@ -65,39 +112,6 @@ public static HttpRequestBase prepareRequest(HttpRequest request, boolean async) reqObj = new HttpHead(urlToRequest); break; } - - Set>> entrySet = request.getHeaders().entrySet(); - for (Map.Entry> entry : entrySet) { - List values = entry.getValue(); - if (values != null) { - for (String value : values) { - reqObj.addHeader(entry.getKey(), value); - } - } - } - - // Set body - if (!(request.getHttpMethod() == HttpMethod.GET || request.getHttpMethod() == HttpMethod.HEAD)) { - if (request.getBody() != null) { - HttpEntity entity = request.getBody().getEntity(); - if (async) { - if (reqObj.getHeaders(CONTENT_TYPE) == null || reqObj.getHeaders(CONTENT_TYPE).length == 0) { - reqObj.setHeader(entity.getContentType()); - } - try { - ByteArrayOutputStream output = new ByteArrayOutputStream(); - entity.writeTo(output); - NByteArrayEntity en = new NByteArrayEntity(output.toByteArray()); - ((HttpEntityEnclosingRequestBase) reqObj).setEntity(en); - } catch (IOException e) { - throw new RuntimeException(e); - } - } else { - ((HttpEntityEnclosingRequestBase) reqObj).setEntity(entity); - } - } - } - return reqObj; } } diff --git a/src/main/java/io/github/openunirest/request/UriFormatter.java b/src/main/java/io/github/openunirest/request/UriFormatter.java index 2215b484d..8d9a8473e 100644 --- a/src/main/java/io/github/openunirest/request/UriFormatter.java +++ b/src/main/java/io/github/openunirest/request/UriFormatter.java @@ -1,7 +1,6 @@ package io.github.openunirest.request; import io.github.openunirest.http.exceptions.UnirestException; -import io.github.openunirest.request.HttpRequest; import org.apache.http.client.utils.URIBuilder; import java.net.URISyntaxException; diff --git a/src/main/java/io/github/openunirest/request/body/Body.java b/src/main/java/io/github/openunirest/request/body/Body.java index 699f6ab69..ed0781e44 100644 --- a/src/main/java/io/github/openunirest/request/body/Body.java +++ b/src/main/java/io/github/openunirest/request/body/Body.java @@ -1,7 +1,8 @@ /* The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/io/github/openunirest/request/body/MultipartBody.java b/src/main/java/io/github/openunirest/request/body/MultipartBody.java index d7db45dbe..383c9aa3d 100644 --- a/src/main/java/io/github/openunirest/request/body/MultipartBody.java +++ b/src/main/java/io/github/openunirest/request/body/MultipartBody.java @@ -1,7 +1,8 @@ /* The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -25,30 +26,20 @@ a copy of this software and associated documentation files (the package io.github.openunirest.request.body; -import java.io.File; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.LinkedHashMap; - +import io.github.openunirest.http.utils.MapUtil; +import io.github.openunirest.request.BaseRequest; +import io.github.openunirest.request.HttpRequest; import org.apache.http.HttpEntity; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.HttpMultipartMode; import org.apache.http.entity.mime.MultipartEntityBuilder; -import org.apache.http.entity.mime.content.ByteArrayBody; -import org.apache.http.entity.mime.content.ContentBody; -import org.apache.http.entity.mime.content.FileBody; -import org.apache.http.entity.mime.content.InputStreamBody; -import org.apache.http.entity.mime.content.StringBody; +import org.apache.http.entity.mime.content.*; -import io.github.openunirest.http.utils.MapUtil; -import io.github.openunirest.request.BaseRequest; -import io.github.openunirest.request.HttpRequest; +import java.io.File; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.util.*; public class MultipartBody extends BaseRequest implements Body { private Map> parameters = new LinkedHashMap<>(); @@ -137,8 +128,8 @@ public MultipartBody basicAuth(String username, String password) { return this; } - public MultipartBody mode(String mode) { - this.mode = HttpMultipartMode.valueOf(mode); + public MultipartBody mode(String value) { + this.mode = HttpMultipartMode.valueOf(value); return this; } diff --git a/src/main/java/io/github/openunirest/request/body/RawBody.java b/src/main/java/io/github/openunirest/request/body/RawBody.java index 9c7c4b00b..f29e75693 100644 --- a/src/main/java/io/github/openunirest/request/body/RawBody.java +++ b/src/main/java/io/github/openunirest/request/body/RawBody.java @@ -1,7 +1,8 @@ /* The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -25,8 +26,6 @@ a copy of this software and associated documentation files (the package io.github.openunirest.request.body; -import io.github.openunirest.request.BaseRequest; -import io.github.openunirest.request.HttpRequest; import io.github.openunirest.request.BaseRequest; import io.github.openunirest.request.HttpRequest; import org.apache.http.HttpEntity; @@ -40,8 +39,8 @@ public RawBody(HttpRequest httpRequest) { super(httpRequest); } - public RawBody body(byte[] body) { - this.body = body; + public RawBody body(byte[] bodyBytes) { + this.body = bodyBytes; return this; } diff --git a/src/main/java/io/github/openunirest/request/body/RequestBodyEntity.java b/src/main/java/io/github/openunirest/request/body/RequestBodyEntity.java index 798f443fd..9920eb48c 100644 --- a/src/main/java/io/github/openunirest/request/body/RequestBodyEntity.java +++ b/src/main/java/io/github/openunirest/request/body/RequestBodyEntity.java @@ -1,7 +1,8 @@ /* The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -31,10 +32,6 @@ a copy of this software and associated documentation files (the import org.apache.http.HttpEntity; import org.apache.http.entity.StringEntity; -import io.github.openunirest.http.JsonNode; -import io.github.openunirest.request.BaseRequest; -import io.github.openunirest.request.HttpRequest; - public class RequestBodyEntity extends BaseRequest implements Body { private Object body; @@ -43,13 +40,13 @@ public RequestBodyEntity(HttpRequest httpRequest) { super(httpRequest); } - public RequestBodyEntity body(String body) { - this.body = body; + public RequestBodyEntity body(String bodyAsString) { + this.body = bodyAsString; return this; } - public RequestBodyEntity body(JsonNode body) { - this.body = body.toString(); + public RequestBodyEntity body(JsonNode jsonBody) { + this.body = jsonBody.toString(); return this; } diff --git a/suppressions.xml b/suppressions.xml new file mode 100644 index 000000000..cb3791156 --- /dev/null +++ b/suppressions.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file From b5ca7f4bb3000862a37253ed6082c4d792e37e3c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 8 May 2018 10:36:24 -0500 Subject: [PATCH 0117/1769] update style --- .../io/github/openunirest/http/Unirest.java | 297 +++++++++--------- 1 file changed, 151 insertions(+), 146 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/Unirest.java b/src/main/java/io/github/openunirest/http/Unirest.java index cd957413f..16b39c3ec 100644 --- a/src/main/java/io/github/openunirest/http/Unirest.java +++ b/src/main/java/io/github/openunirest/http/Unirest.java @@ -43,151 +43,156 @@ a copy of this software and associated documentation files (the public class Unirest { - /** - * Set the HttpClient implementation to use for every synchronous request - * @param httpClient Custom httpClient implementation - */ - public static void setHttpClient(HttpClient httpClient) { - Options.setOption(Option.HTTPCLIENT, httpClient); - Options.customClientSet(); - } - - /** - * Set the asynchronous AbstractHttpAsyncClient implementation to use for every asynchronous request - * @param asyncHttpClient Custom CloseableHttpAsyncClient implementation - */ - public static void setAsyncHttpClient(CloseableHttpAsyncClient asyncHttpClient) { - Options.setOption(Option.ASYNCHTTPCLIENT, asyncHttpClient); - Options.customClientSet(); - } - - /** - * Set a proxy - * @param proxy Proxy settings object. - */ - public static void setProxy(HttpHost proxy) { - Options.setOption(Option.PROXY, proxy); - - // Reload the client implementations - Options.refresh(); - } - - /** - * Set the ObjectMapper implementation to use for Response to Object binding - * - * @param objectMapper Custom implementation of ObjectMapper interface - */ - public static void setObjectMapper(ObjectMapper objectMapper) { - Options.setOption(Option.OBJECT_MAPPER, objectMapper); - - // Reload the client implementations - Options.refresh(); - } - - /** - * Set the connection timeout and socket timeout - * - * @param connectionTimeout The timeout until a connection with the server is established (in milliseconds). Default is 10000. Set to zero to disable the timeout. - * @param socketTimeout The timeout to receive data (in milliseconds). Default is 60000. Set to zero to disable the timeout. - */ - public static void setTimeouts(int connectionTimeout, int socketTimeout) { - Options.setOption(Option.CONNECTION_TIMEOUT, connectionTimeout); - Options.setOption(Option.SOCKET_TIMEOUT, socketTimeout); - - // Reload the client implementations - Options.refresh(); - } - - /** - * Set the concurrency levels - * - * @param maxTotal Defines the overall connection limit for a connection pool. Default is 200. - * @param maxPerRoute Defines a connection limit per one HTTP route (this can be considered a per target host limit). Default is 20. - */ - public static void setConcurrency(int maxTotal, int maxPerRoute) { - Options.setOption(Option.MAX_TOTAL, maxTotal); - Options.setOption(Option.MAX_PER_ROUTE, maxPerRoute); - - // Reload the client implementations - Options.refresh(); - } - - /** - * Clear default headers - */ - public static void clearDefaultHeaders() { - Options.setOption(Option.DEFAULT_HEADERS, null); - } - - /** - * Set default header to appear on all requests - * @param name The name of the header. - * @param value The value of the header. - */ - @SuppressWarnings("unchecked") - public static void setDefaultHeader(String name, String value) { - Object headers = Options.getOption(Option.DEFAULT_HEADERS); - if (headers == null) { - headers = new HashMap(); - } - ((Map) headers).put(name, value); - Options.setOption(Option.DEFAULT_HEADERS, headers); - } - - /** - * Close the asynchronous client and its event loop. Use this method to close all the threads and allow an application to exit. - * @throws IOException Because of course it does - */ - public static void shutdown() throws IOException { - // Closing the Sync HTTP client - CloseableHttpClient syncClient = (CloseableHttpClient) Options.getOption(Option.HTTPCLIENT); - if (syncClient != null) { - syncClient.close(); - } - - SyncIdleConnectionMonitorThread syncIdleConnectionMonitorThread = (SyncIdleConnectionMonitorThread) Options.getOption(Option.SYNC_MONITOR); - if (syncIdleConnectionMonitorThread != null) { - syncIdleConnectionMonitorThread.interrupt(); - } - - // Closing the Async HTTP client (if running) - CloseableHttpAsyncClient asyncClient = (CloseableHttpAsyncClient) Options.getOption(Option.ASYNCHTTPCLIENT); - if (asyncClient != null && asyncClient.isRunning()) { - asyncClient.close(); - } - - AsyncIdleConnectionMonitorThread asyncMonitorThread = (AsyncIdleConnectionMonitorThread) Options.getOption(Option.ASYNC_MONITOR); - if (asyncMonitorThread != null) { - asyncMonitorThread.interrupt(); - } - } - - public static GetRequest get(String url) { - return new GetRequest(HttpMethod.GET, url); - } - - public static GetRequest head(String url) { - return new GetRequest(HttpMethod.HEAD, url); - } - - public static HttpRequestWithBody options(String url) { - return new HttpRequestWithBody(HttpMethod.OPTIONS, url); - } - - public static HttpRequestWithBody post(String url) { - return new HttpRequestWithBody(HttpMethod.POST, url); - } - - public static HttpRequestWithBody delete(String url) { - return new HttpRequestWithBody(HttpMethod.DELETE, url); - } - - public static HttpRequestWithBody patch(String url) { - return new HttpRequestWithBody(HttpMethod.PATCH, url); - } - - public static HttpRequestWithBody put(String url) { - return new HttpRequestWithBody(HttpMethod.PUT, url); - } + /** + * Set the HttpClient implementation to use for every synchronous request + * + * @param httpClient Custom httpClient implementation + */ + public static void setHttpClient(HttpClient httpClient) { + Options.setOption(Option.HTTPCLIENT, httpClient); + Options.customClientSet(); + } + + /** + * Set the asynchronous AbstractHttpAsyncClient implementation to use for every asynchronous request + * + * @param asyncHttpClient Custom CloseableHttpAsyncClient implementation + */ + public static void setAsyncHttpClient(CloseableHttpAsyncClient asyncHttpClient) { + Options.setOption(Option.ASYNCHTTPCLIENT, asyncHttpClient); + Options.customClientSet(); + } + + /** + * Set a proxy + * + * @param proxy Proxy settings object. + */ + public static void setProxy(HttpHost proxy) { + Options.setOption(Option.PROXY, proxy); + + // Reload the client implementations + Options.refresh(); + } + + /** + * Set the ObjectMapper implementation to use for Response to Object binding + * + * @param objectMapper Custom implementation of ObjectMapper interface + */ + public static void setObjectMapper(ObjectMapper objectMapper) { + Options.setOption(Option.OBJECT_MAPPER, objectMapper); + + // Reload the client implementations + Options.refresh(); + } + + /** + * Set the connection timeout and socket timeout + * + * @param connectionTimeout The timeout until a connection with the server is established (in milliseconds). Default is 10000. Set to zero to disable the timeout. + * @param socketTimeout The timeout to receive data (in milliseconds). Default is 60000. Set to zero to disable the timeout. + */ + public static void setTimeouts(int connectionTimeout, int socketTimeout) { + Options.setOption(Option.CONNECTION_TIMEOUT, connectionTimeout); + Options.setOption(Option.SOCKET_TIMEOUT, socketTimeout); + + // Reload the client implementations + Options.refresh(); + } + + /** + * Set the concurrency levels + * + * @param maxTotal Defines the overall connection limit for a connection pool. Default is 200. + * @param maxPerRoute Defines a connection limit per one HTTP route (this can be considered a per target host limit). Default is 20. + */ + public static void setConcurrency(int maxTotal, int maxPerRoute) { + Options.setOption(Option.MAX_TOTAL, maxTotal); + Options.setOption(Option.MAX_PER_ROUTE, maxPerRoute); + + // Reload the client implementations + Options.refresh(); + } + + /** + * Clear default headers + */ + public static void clearDefaultHeaders() { + Options.setOption(Option.DEFAULT_HEADERS, null); + } + + /** + * Set default header to appear on all requests + * + * @param name The name of the header. + * @param value The value of the header. + */ + @SuppressWarnings("unchecked") + public static void setDefaultHeader(String name, String value) { + Object headers = Options.getOption(Option.DEFAULT_HEADERS); + if (headers == null) { + headers = new HashMap(); + } + ((Map) headers).put(name, value); + Options.setOption(Option.DEFAULT_HEADERS, headers); + } + + /** + * Close the asynchronous client and its event loop. Use this method to close all the threads and allow an application to exit. + * + * @throws IOException Because of course it does + */ + public static void shutdown() throws IOException { + // Closing the Sync HTTP client + CloseableHttpClient syncClient = (CloseableHttpClient) Options.getOption(Option.HTTPCLIENT); + if (syncClient != null) { + syncClient.close(); + } + + SyncIdleConnectionMonitorThread syncIdleConnectionMonitorThread = (SyncIdleConnectionMonitorThread) Options.getOption(Option.SYNC_MONITOR); + if (syncIdleConnectionMonitorThread != null) { + syncIdleConnectionMonitorThread.interrupt(); + } + + // Closing the Async HTTP client (if running) + CloseableHttpAsyncClient asyncClient = (CloseableHttpAsyncClient) Options.getOption(Option.ASYNCHTTPCLIENT); + if (asyncClient != null && asyncClient.isRunning()) { + asyncClient.close(); + } + + AsyncIdleConnectionMonitorThread asyncMonitorThread = (AsyncIdleConnectionMonitorThread) Options.getOption(Option.ASYNC_MONITOR); + if (asyncMonitorThread != null) { + asyncMonitorThread.interrupt(); + } + } + + public static GetRequest get(String url) { + return new GetRequest(HttpMethod.GET, url); + } + + public static GetRequest head(String url) { + return new GetRequest(HttpMethod.HEAD, url); + } + + public static HttpRequestWithBody options(String url) { + return new HttpRequestWithBody(HttpMethod.OPTIONS, url); + } + + public static HttpRequestWithBody post(String url) { + return new HttpRequestWithBody(HttpMethod.POST, url); + } + + public static HttpRequestWithBody delete(String url) { + return new HttpRequestWithBody(HttpMethod.DELETE, url); + } + + public static HttpRequestWithBody patch(String url) { + return new HttpRequestWithBody(HttpMethod.PATCH, url); + } + + public static HttpRequestWithBody put(String url) { + return new HttpRequestWithBody(HttpMethod.PUT, url); + } } From 088b16364c37cc5313db3554adb0b8df37571200 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 8 May 2018 10:38:34 -0500 Subject: [PATCH 0118/1769] change shutdown to now throw exceptions and to be cleaner --- .../io/github/openunirest/http/Unirest.java | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/Unirest.java b/src/main/java/io/github/openunirest/http/Unirest.java index 16b39c3ec..81c9e3fa6 100644 --- a/src/main/java/io/github/openunirest/http/Unirest.java +++ b/src/main/java/io/github/openunirest/http/Unirest.java @@ -27,6 +27,7 @@ a copy of this software and associated documentation files (the package io.github.openunirest.http; import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; +import io.github.openunirest.http.exceptions.UnirestException; import io.github.openunirest.http.options.Option; import io.github.openunirest.http.options.Options; import io.github.openunirest.http.utils.SyncIdleConnectionMonitorThread; @@ -37,6 +38,7 @@ a copy of this software and associated documentation files (the import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; +import java.io.Closeable; import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -141,29 +143,31 @@ public static void setDefaultHeader(String name, String value) { /** * Close the asynchronous client and its event loop. Use this method to close all the threads and allow an application to exit. * - * @throws IOException Because of course it does */ - public static void shutdown() throws IOException { - // Closing the Sync HTTP client - CloseableHttpClient syncClient = (CloseableHttpClient) Options.getOption(Option.HTTPCLIENT); - if (syncClient != null) { - syncClient.close(); - } - - SyncIdleConnectionMonitorThread syncIdleConnectionMonitorThread = (SyncIdleConnectionMonitorThread) Options.getOption(Option.SYNC_MONITOR); - if (syncIdleConnectionMonitorThread != null) { - syncIdleConnectionMonitorThread.interrupt(); - } - - // Closing the Async HTTP client (if running) - CloseableHttpAsyncClient asyncClient = (CloseableHttpAsyncClient) Options.getOption(Option.ASYNCHTTPCLIENT); - if (asyncClient != null && asyncClient.isRunning()) { - asyncClient.close(); - } - - AsyncIdleConnectionMonitorThread asyncMonitorThread = (AsyncIdleConnectionMonitorThread) Options.getOption(Option.ASYNC_MONITOR); - if (asyncMonitorThread != null) { - asyncMonitorThread.interrupt(); + public static void shutdown() { + Options.tryGet(Option.HTTPCLIENT, + CloseableHttpClient.class) + .ifPresent(Unirest::closeIt); + + Options.tryGet(Option.SYNC_MONITOR, + SyncIdleConnectionMonitorThread.class) + .ifPresent(Thread::interrupt); + + Options.tryGet(Option.ASYNCHTTPCLIENT, + CloseableHttpAsyncClient.class) + .filter(CloseableHttpAsyncClient::isRunning) + .ifPresent(Unirest::closeIt); + + Options.tryGet(Option.ASYNC_MONITOR, + AsyncIdleConnectionMonitorThread.class) + .ifPresent(Thread::interrupt); + } + + private static void closeIt(Closeable c) { + try { + c.close(); + }catch (IOException e){ + throw new UnirestException(e); } } From 87380aaa7d80b293c91252494313057618832b93 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 8 May 2018 10:43:34 -0500 Subject: [PATCH 0119/1769] make it possible to completely re-init unirest back to original state. closes #25 --- .../io/github/openunirest/http/options/Options.java | 11 +++++++---- src/test/java/BehaviorTests/LifeCycleTest.java | 2 +- .../github/openunirest/http/options/OptionsTest.java | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/options/Options.java b/src/main/java/io/github/openunirest/http/options/Options.java index 892226a4d..95815066c 100644 --- a/src/main/java/io/github/openunirest/http/options/Options.java +++ b/src/main/java/io/github/openunirest/http/options/Options.java @@ -1,5 +1,6 @@ package io.github.openunirest.http.options; +import io.github.openunirest.http.Unirest; import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; import io.github.openunirest.http.utils.SyncIdleConnectionMonitorThread; import org.apache.http.HttpHost; @@ -29,7 +30,7 @@ public class Options { private static PoolingHttpClientConnectionManager syncConnectionManager; static { - init(); + createMonitors(); setDefaults(); refresh(); } @@ -62,7 +63,7 @@ private static T getOptionOrDefault(Option option, T defaultValue){ return (T)options.computeIfAbsent(option, o -> defaultValue); } - private static void init() { + private static void createMonitors() { syncConnectionManager = new PoolingHttpClientConnectionManager(); defaultSyncMonitor = new SyncIdleConnectionMonitorThread(syncConnectionManager); defaultSyncMonitor.start(); @@ -118,9 +119,11 @@ private static RequestConfig getRequestConfig() { .build(); } - public static void reset() { + public static void init() { + Unirest.shutdown(); + createMonitors(); setDefaults(); - + refresh(); } private static void setDefaults() { diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index e505f0b5f..b5976d140 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -19,7 +19,7 @@ public class LifeCycleTest extends BddTest { @After @Before public void tearDown() { - Options.reset(); + Options.init(); } @Test diff --git a/src/test/java/io/github/openunirest/http/options/OptionsTest.java b/src/test/java/io/github/openunirest/http/options/OptionsTest.java index a22e6d9d4..d5eee5a5c 100644 --- a/src/test/java/io/github/openunirest/http/options/OptionsTest.java +++ b/src/test/java/io/github/openunirest/http/options/OptionsTest.java @@ -16,7 +16,7 @@ public class OptionsTest { @Before public void before(){ - Options.reset(); + Options.init(); } @Test From 7508188503ad269b500f6926f2c153ad176fe395 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 8 May 2018 13:18:54 -0500 Subject: [PATCH 0120/1769] [maven-release-plugin] prepare release v2.2.03 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 92875253a..deae54385 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.03-SNAPSHOT + 2.2.03 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.2.03 From cf91bc9c41bb6676ce7f43978e4368224ce084a2 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 8 May 2018 13:19:03 -0500 Subject: [PATCH 0121/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index deae54385..e5ceaa475 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.03 + 2.2.04-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.2.03 + HEAD From 0963cc776be4bf2f55f587e37de1b86e441bc51c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 8 May 2018 17:24:27 -0500 Subject: [PATCH 0122/1769] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 947695120..99779a133 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.2.03 +* Expose the ```Options.init()``` method to restore the system to a fresh start after a shutdown. + ## 2.2.02 * Fix NPE with null bodies from HEAD requests. From ec3e9d3c5c4e8de7549d664d4bd663dbebe3714c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 8 May 2018 17:26:06 -0500 Subject: [PATCH 0123/1769] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99779a133..959b36bfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 2.2.03 * Expose the ```Options.init()``` method to restore the system to a fresh start after a shutdown. +* ```Unirest.shutdown()``` no longer throws a checked exception ## 2.2.02 * Fix NPE with null bodies from HEAD requests. From fd106996ad2732650484460efb5eb7f12da002ff Mon Sep 17 00:00:00 2001 From: Jon Bevan Date: Wed, 9 May 2018 11:46:52 +0100 Subject: [PATCH 0124/1769] Update README for HttpResponse.getParsingError() and Options.init() --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 74bba9e87..c96a87fbe 100644 --- a/README.md +++ b/README.md @@ -14,14 +14,14 @@ Unirest.post("http://httpbin.org/post") io.github.openunirest unirest-java - 2.2.02 + 2.2.03 ``` ## Features * Make `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `HEAD`, `OPTIONS` requests -* Both syncronous and asynchronous (non-blocking) requests +* Both synchronous and asynchronous (non-blocking) requests * It supports form parameters, file uploads and custom body entities * Easily add route parameters without ugly string concatenations * Supports gzip @@ -213,6 +213,7 @@ Upon recieving a response Unirest returns the result in the form of an Object, t - `.getHeaders()` - HTTP Response Headers - `.getBody()` - Parsed response body where applicable, for example JSON responses are parsed to Objects / Associative Arrays. - `.getRawBody()` - Un-parsed response body +- `.getParsingError()` - Optional RuntimeException containing the error that was thrown when parsing the response body # Advanced Configuration @@ -277,5 +278,6 @@ Unirest starts a background event loop and your Java application won't be able t Unirest.shutdown(); ``` +Once shutdown, you can call `Options.init()` to re-initialize Unirest. From 27449185bb2bbfbae67d6bface84c50edeadffc1 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 9 May 2018 16:31:54 -0500 Subject: [PATCH 0125/1769] automatically start back up after a shutdown when the library is used again --- .../io/github/openunirest/http/Unirest.java | 34 ++---------- .../openunirest/http/options/Options.java | 55 ++++++++++++++++--- src/test/java/BehaviorTests/BddTest.java | 2 + .../java/BehaviorTests/LifeCycleTest.java | 30 +++++++--- 4 files changed, 75 insertions(+), 46 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/Unirest.java b/src/main/java/io/github/openunirest/http/Unirest.java index 81c9e3fa6..e17f18e0a 100644 --- a/src/main/java/io/github/openunirest/http/Unirest.java +++ b/src/main/java/io/github/openunirest/http/Unirest.java @@ -26,20 +26,14 @@ a copy of this software and associated documentation files (the package io.github.openunirest.http; -import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; -import io.github.openunirest.http.exceptions.UnirestException; import io.github.openunirest.http.options.Option; import io.github.openunirest.http.options.Options; -import io.github.openunirest.http.utils.SyncIdleConnectionMonitorThread; import io.github.openunirest.request.GetRequest; import io.github.openunirest.request.HttpRequestWithBody; import org.apache.http.HttpHost; import org.apache.http.client.HttpClient; -import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; -import java.io.Closeable; -import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -145,30 +139,7 @@ public static void setDefaultHeader(String name, String value) { * */ public static void shutdown() { - Options.tryGet(Option.HTTPCLIENT, - CloseableHttpClient.class) - .ifPresent(Unirest::closeIt); - - Options.tryGet(Option.SYNC_MONITOR, - SyncIdleConnectionMonitorThread.class) - .ifPresent(Thread::interrupt); - - Options.tryGet(Option.ASYNCHTTPCLIENT, - CloseableHttpAsyncClient.class) - .filter(CloseableHttpAsyncClient::isRunning) - .ifPresent(Unirest::closeIt); - - Options.tryGet(Option.ASYNC_MONITOR, - AsyncIdleConnectionMonitorThread.class) - .ifPresent(Thread::interrupt); - } - - private static void closeIt(Closeable c) { - try { - c.close(); - }catch (IOException e){ - throw new UnirestException(e); - } + Options.shutDown(); } public static GetRequest get(String url) { @@ -199,4 +170,7 @@ public static HttpRequestWithBody put(String url) { return new HttpRequestWithBody(HttpMethod.PUT, url); } + public static boolean isRunning() { + return Options.isRunning(); + } } diff --git a/src/main/java/io/github/openunirest/http/options/Options.java b/src/main/java/io/github/openunirest/http/options/Options.java index 95815066c..d7f3272f3 100644 --- a/src/main/java/io/github/openunirest/http/options/Options.java +++ b/src/main/java/io/github/openunirest/http/options/Options.java @@ -1,7 +1,7 @@ package io.github.openunirest.http.options; -import io.github.openunirest.http.Unirest; import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; +import io.github.openunirest.http.exceptions.UnirestException; import io.github.openunirest.http.utils.SyncIdleConnectionMonitorThread; import org.apache.http.HttpHost; import org.apache.http.client.config.RequestConfig; @@ -14,6 +14,8 @@ import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor; import org.apache.http.nio.reactor.IOReactorException; +import java.io.Closeable; +import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Objects; @@ -28,13 +30,7 @@ public class Options { private static Map options = new HashMap<>(); private static boolean customClientSet = false; private static PoolingHttpClientConnectionManager syncConnectionManager; - - static { - createMonitors(); - setDefaults(); - refresh(); - } - + private static boolean isRunning = true; private static SyncIdleConnectionMonitorThread defaultSyncMonitor; public static void customClientSet() { @@ -56,10 +52,18 @@ private static void validateOption(Option option) { } public static Object getOption(Option option) { + warmUp(); return options.get(option); } + private static void warmUp() { + if(!isRunning()){ + init(); + } + } + private static T getOptionOrDefault(Option option, T defaultValue){ + warmUp(); return (T)options.computeIfAbsent(option, o -> defaultValue); } @@ -68,6 +72,7 @@ private static void createMonitors() { defaultSyncMonitor = new SyncIdleConnectionMonitorThread(syncConnectionManager); defaultSyncMonitor.start(); setOption(Option.SYNC_MONITOR, defaultSyncMonitor); + isRunning = true; } @@ -120,7 +125,6 @@ private static RequestConfig getRequestConfig() { } public static void init() { - Unirest.shutdown(); createMonitors(); setDefaults(); refresh(); @@ -147,4 +151,37 @@ public static Optional tryGet(Option option, Class as) { public static void removeOption(Option objectMapper) { options.remove(objectMapper); } + + public static boolean isRunning() { + return isRunning; + } + + public static void shutDown() { + tryGet(Option.HTTPCLIENT, + CloseableHttpClient.class) + .ifPresent(Options::closeIt); + + tryGet(Option.SYNC_MONITOR, + SyncIdleConnectionMonitorThread.class) + .ifPresent(Thread::interrupt); + + tryGet(Option.ASYNCHTTPCLIENT, + CloseableHttpAsyncClient.class) + .filter(CloseableHttpAsyncClient::isRunning) + .ifPresent(Options::closeIt); + + tryGet(Option.ASYNC_MONITOR, + AsyncIdleConnectionMonitorThread.class) + .ifPresent(Thread::interrupt); + + isRunning = false; + } + + public static void closeIt(Closeable c) { + try { + c.close(); + }catch (IOException e){ + throw new UnirestException(e); + } + } } diff --git a/src/test/java/BehaviorTests/BddTest.java b/src/test/java/BehaviorTests/BddTest.java index 0eefd2feb..b25e9e201 100644 --- a/src/test/java/BehaviorTests/BddTest.java +++ b/src/test/java/BehaviorTests/BddTest.java @@ -1,6 +1,7 @@ package BehaviorTests; import io.github.openunirest.http.*; +import io.github.openunirest.http.options.Options; import org.junit.Before; import util.JacksonObjectMapper; @@ -21,6 +22,7 @@ public class BddTest { @Before public void setUp() { MockServer.reset(); + Options.init(); Unirest.setObjectMapper(objectMapper); lock = new CountDownLatch(1); status = false; diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index b5976d140..50f1681f5 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -6,21 +6,16 @@ import io.github.openunirest.http.utils.SyncIdleConnectionMonitorThread; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; -import org.junit.After; -import org.junit.Before; import org.junit.Test; import java.io.IOException; import static io.github.openunirest.http.options.Option.*; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.*; public class LifeCycleTest extends BddTest { - @After - @Before - public void tearDown() { - Options.init(); - } @Test public void testShutdown() throws IOException { @@ -64,4 +59,25 @@ public void willNotShutdownInactiveAsyncClient() throws IOException { verify(asyncClient, never()).close(); } + + @Test + public void canDetectIfSystemIsRunning() { + Unirest.get(MockServer.GET).asBinary(); + assertTrue(Unirest.isRunning()); + + Unirest.shutdown(); + assertFalse(Unirest.isRunning()); + + Options.init(); + assertTrue(Unirest.isRunning()); + } + + @Test + public void willReinitIfLibraryIsUsedAfterShutdown() { + Unirest.shutdown(); + assertFalse(Unirest.isRunning()); + + Unirest.get(MockServer.GET).asBinary(); + assertTrue(Unirest.isRunning()); + } } From 887453568519c065b8587b2edc5c39698e0639bb Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 15 Jun 2018 19:45:12 -0500 Subject: [PATCH 0126/1769] add interceptors --- .../openunirest/http/options/Options.java | 56 ++++++++++++------- .../java/BehaviorTests/InterceptorTest.java | 42 ++++++++++++++ 2 files changed, 79 insertions(+), 19 deletions(-) create mode 100644 src/test/java/BehaviorTests/InterceptorTest.java diff --git a/src/main/java/io/github/openunirest/http/options/Options.java b/src/main/java/io/github/openunirest/http/options/Options.java index d7f3272f3..17a1248df 100644 --- a/src/main/java/io/github/openunirest/http/options/Options.java +++ b/src/main/java/io/github/openunirest/http/options/Options.java @@ -4,6 +4,7 @@ import io.github.openunirest.http.exceptions.UnirestException; import io.github.openunirest.http.utils.SyncIdleConnectionMonitorThread; import org.apache.http.HttpHost; +import org.apache.http.HttpRequestInterceptor; import org.apache.http.client.config.RequestConfig; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; @@ -16,10 +17,7 @@ import java.io.Closeable; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; +import java.util.*; public class Options { public static final int MAX_TOTAL = 200; @@ -27,11 +25,12 @@ public class Options { public static final int CONNECTION_TIMEOUT = 10000; public static final int SOCKET_TIMEOUT = 60000; - private static Map options = new HashMap<>(); private static boolean customClientSet = false; - private static PoolingHttpClientConnectionManager syncConnectionManager; private static boolean isRunning = true; + private static Map options = new HashMap<>(); + private static PoolingHttpClientConnectionManager syncConnectionManager; private static SyncIdleConnectionMonitorThread defaultSyncMonitor; + private static List interceptors = new ArrayList<>(); public static void customClientSet() { customClientSet = true; @@ -77,6 +76,9 @@ private static void createMonitors() { public static void refresh() { + if(syncConnectionManager == null){ + createMonitors(); + } RequestConfig clientConfig = getRequestConfig(); Integer maxTotal = getOptionOrDefault(Option.MAX_TOTAL, MAX_TOTAL); @@ -84,14 +86,7 @@ public static void refresh() { syncConnectionManager.setMaxTotal(maxTotal); syncConnectionManager.setDefaultMaxPerRoute(maxPerRoute); - // Create clients - CloseableHttpClient build = HttpClientBuilder.create() - .setDefaultRequestConfig(clientConfig) - .setConnectionManager(syncConnectionManager) - .useSystemProperties() - .build(); - - setOption(Option.HTTPCLIENT, build); + buildHttpClient(clientConfig); PoolingNHttpClientConnectionManager asyncConnectionManager; try { @@ -102,16 +97,33 @@ public static void refresh() { throw new RuntimeException(e); } - CloseableHttpAsyncClient asyncClient = HttpAsyncClientBuilder.create() - .setDefaultRequestConfig(clientConfig) - .setConnectionManager(asyncConnectionManager) - .useSystemProperties() - .build(); + CloseableHttpAsyncClient asyncClient = buildAsyncClient(clientConfig, asyncConnectionManager); setOption(Option.ASYNCHTTPCLIENT, asyncClient); setOption(Option.ASYNC_MONITOR, new AsyncIdleConnectionMonitorThread(asyncConnectionManager)); } + private static CloseableHttpAsyncClient buildAsyncClient(RequestConfig clientConfig, PoolingNHttpClientConnectionManager asyncConnectionManager) { + HttpAsyncClientBuilder asyncBuilder = HttpAsyncClientBuilder.create() + .setDefaultRequestConfig(clientConfig) + .setConnectionManager(asyncConnectionManager) + .useSystemProperties(); + interceptors.stream().forEach(i -> asyncBuilder.addInterceptorFirst(i)); + return asyncBuilder.build(); + } + + private static void buildHttpClient(RequestConfig clientConfig) { + // Create clients + HttpClientBuilder httpClientBuilder = HttpClientBuilder.create() + .setDefaultRequestConfig(clientConfig) + .setConnectionManager(syncConnectionManager) + .useSystemProperties(); + interceptors.stream().forEach(i -> httpClientBuilder.addInterceptorFirst(i)); + CloseableHttpClient build = httpClientBuilder.build(); + + setOption(Option.HTTPCLIENT, build); + } + private static RequestConfig getRequestConfig() { Integer connectionTimeout = getOptionOrDefault(Option.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT); Integer socketTimeout = getOptionOrDefault(Option.SOCKET_TIMEOUT, SOCKET_TIMEOUT); @@ -138,6 +150,7 @@ private static void setDefaults() { setOption(Option.MAX_TOTAL, MAX_TOTAL); setOption(Option.MAX_PER_ROUTE, MAX_PER_ROUTE); setOption(Option.SYNC_MONITOR, defaultSyncMonitor); + interceptors.clear(); } public static Optional tryGet(Option option, Class as) { @@ -184,4 +197,9 @@ public static void closeIt(Closeable c) { throw new UnirestException(e); } } + + public static void addInterceptor(HttpRequestInterceptor interceptor) { + interceptors.add(interceptor); + refresh(); + } } diff --git a/src/test/java/BehaviorTests/InterceptorTest.java b/src/test/java/BehaviorTests/InterceptorTest.java new file mode 100644 index 000000000..41e18cdf4 --- /dev/null +++ b/src/test/java/BehaviorTests/InterceptorTest.java @@ -0,0 +1,42 @@ +package BehaviorTests; + +import io.github.openunirest.http.Unirest; +import io.github.openunirest.http.options.Options; +import org.apache.http.HttpException; +import org.apache.http.HttpRequest; +import org.apache.http.HttpRequestInterceptor; +import org.apache.http.protocol.HttpContext; +import org.junit.Test; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +public class InterceptorTest extends BddTest { + @Test + public void canAddInterceptor() { + Options.addInterceptor(new TestInterceptor()); + + Unirest.get(MockServer.GET) + .asObject(RequestCapture.class) + .getBody() + .assertHeader("x-custom", "foo"); + } + + @Test + public void canAddInterceptorToAsync() throws ExecutionException, InterruptedException { + Options.addInterceptor(new TestInterceptor()); + + Unirest.get(MockServer.GET) + .asObjectAsync(RequestCapture.class) + .get() + .getBody() + .assertHeader("x-custom", "foo"); + } + + private class TestInterceptor implements HttpRequestInterceptor { + @Override + public void process(HttpRequest httpRequest, HttpContext httpContext) throws HttpException, IOException { + httpRequest.addHeader("x-custom", "foo"); + } + } +} From 127ac52d077970e4e5fdb52e0ce7abfcf2a6c10e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 16 Jun 2018 07:24:12 -0500 Subject: [PATCH 0127/1769] switch encoding over to charset to avoid checked exceptions --- .../java/io/github/openunirest/request/BaseRequest.java | 4 +++- .../io/github/openunirest/request/body/MultipartBody.java | 7 +------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/github/openunirest/request/BaseRequest.java b/src/main/java/io/github/openunirest/request/BaseRequest.java index d6eca3931..c6018be1d 100644 --- a/src/main/java/io/github/openunirest/request/BaseRequest.java +++ b/src/main/java/io/github/openunirest/request/BaseRequest.java @@ -32,11 +32,13 @@ a copy of this software and associated documentation files (the import io.github.openunirest.http.exceptions.UnirestException; import java.io.InputStream; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.concurrent.CompletableFuture; public abstract class BaseRequest { - protected static final String UTF_8 = "UTF-8"; + protected static final Charset UTF_8 = StandardCharsets.UTF_8; private final ResponseBuilder builder = new ResponseBuilder(); protected HttpRequest httpRequest; diff --git a/src/main/java/io/github/openunirest/request/body/MultipartBody.java b/src/main/java/io/github/openunirest/request/body/MultipartBody.java index 383c9aa3d..0b0712ccf 100644 --- a/src/main/java/io/github/openunirest/request/body/MultipartBody.java +++ b/src/main/java/io/github/openunirest/request/body/MultipartBody.java @@ -38,7 +38,6 @@ a copy of this software and associated documentation files (the import java.io.File; import java.io.InputStream; -import java.io.UnsupportedEncodingException; import java.util.*; public class MultipartBody extends BaseRequest implements Body { @@ -157,11 +156,7 @@ public HttpEntity getEntity() { } return builder.build(); } else { - try { - return new UrlEncodedFormEntity(MapUtil.getList(parameters), UTF_8); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } + return new UrlEncodedFormEntity(MapUtil.getList(parameters), UTF_8); } } From ecccc5c870fd1325bb34c2e0d0634f327ab1b0f2 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 19 Jun 2018 20:45:28 -0500 Subject: [PATCH 0128/1769] create a custom multimap impl to start to simplify things --- .../openunirest/http/utils/MapUtil.java | 9 +++----- .../openunirest/http/utils/Multimap.java | 23 +++++++++++++++++++ .../request/body/MultipartBody.java | 6 ++--- 3 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 src/main/java/io/github/openunirest/http/utils/Multimap.java diff --git a/src/main/java/io/github/openunirest/http/utils/MapUtil.java b/src/main/java/io/github/openunirest/http/utils/MapUtil.java index 847f900f6..81db9c81b 100644 --- a/src/main/java/io/github/openunirest/http/utils/MapUtil.java +++ b/src/main/java/io/github/openunirest/http/utils/MapUtil.java @@ -31,17 +31,14 @@ a copy of this software and associated documentation files (the import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.Map.Entry; -import java.util.TreeMap; public class MapUtil { - public static List getList(Map> parameters) { - List result = new ArrayList(); + public static List getList(Multimap parameters) { + List result = new ArrayList<>(); if (parameters != null) { - TreeMap> sortedParameters = new TreeMap>(parameters); - for (Entry> entry : sortedParameters.entrySet()) { + for (Entry> entry : parameters.entrySet()) { List entryValue = entry.getValue(); if (entryValue != null) { for (Object cur : entryValue) { diff --git a/src/main/java/io/github/openunirest/http/utils/Multimap.java b/src/main/java/io/github/openunirest/http/utils/Multimap.java new file mode 100644 index 000000000..299fa5eeb --- /dev/null +++ b/src/main/java/io/github/openunirest/http/utils/Multimap.java @@ -0,0 +1,23 @@ +package io.github.openunirest.http.utils; + +import java.util.*; + +public class Multimap { + private Map> inList = new TreeMap<>(); + + public Set keySet() { + return inList.keySet(); + } + + public List get(K key) { + return inList.get(key); + } + + public Set>> entrySet() { + return inList.entrySet(); + } + + public void add(K key, V value) { + inList.computeIfAbsent(key, k -> new ArrayList<>()).add(value); + } +} diff --git a/src/main/java/io/github/openunirest/request/body/MultipartBody.java b/src/main/java/io/github/openunirest/request/body/MultipartBody.java index 0b0712ccf..ad84aaf2c 100644 --- a/src/main/java/io/github/openunirest/request/body/MultipartBody.java +++ b/src/main/java/io/github/openunirest/request/body/MultipartBody.java @@ -27,6 +27,7 @@ a copy of this software and associated documentation files (the package io.github.openunirest.request.body; import io.github.openunirest.http.utils.MapUtil; +import io.github.openunirest.http.utils.Multimap; import io.github.openunirest.request.BaseRequest; import io.github.openunirest.request.HttpRequest; import org.apache.http.HttpEntity; @@ -41,7 +42,7 @@ a copy of this software and associated documentation files (the import java.util.*; public class MultipartBody extends BaseRequest implements Body { - private Map> parameters = new LinkedHashMap<>(); + private Multimap parameters = new Multimap<>(); private Map contentTypes = new HashMap<>(); private boolean hasFile; @@ -78,8 +79,7 @@ public MultipartBody field(String name, Object value, boolean file) { } public MultipartBody field(String name, Object value, boolean file, String contentType) { - List list = parameters.computeIfAbsent(name, n -> new LinkedList<>()); - list.add(value); + parameters.add(name, value); ContentType type = null; if (contentType != null && contentType.length() > 0) { From 7bad38706e1b1a5803ded520c07ac390d85a2d3d Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 19 Jun 2018 21:12:55 -0500 Subject: [PATCH 0129/1769] move to a single collection of formparts to simplify the parts --- .../openunirest/http/utils/MapUtil.java | 30 +++++------ .../request/body/MultipartBody.java | 51 ++++++++++++------- 2 files changed, 48 insertions(+), 33 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/utils/MapUtil.java b/src/main/java/io/github/openunirest/http/utils/MapUtil.java index 81db9c81b..21f246774 100644 --- a/src/main/java/io/github/openunirest/http/utils/MapUtil.java +++ b/src/main/java/io/github/openunirest/http/utils/MapUtil.java @@ -26,6 +26,7 @@ a copy of this software and associated documentation files (the package io.github.openunirest.http.utils; +import io.github.openunirest.request.body.MultipartBody; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; @@ -35,21 +36,18 @@ a copy of this software and associated documentation files (the public class MapUtil { - public static List getList(Multimap parameters) { - List result = new ArrayList<>(); - if (parameters != null) { - for (Entry> entry : parameters.entrySet()) { - List entryValue = entry.getValue(); - if (entryValue != null) { - for (Object cur : entryValue) { - if (cur != null) { - result.add(new BasicNameValuePair(entry.getKey(), cur.toString())); - } - } - } - } - } - return result; - } + public static List getList(Multimap parameters) { + List result = new ArrayList<>(); + if (parameters != null) { + for (Entry> entry : parameters.entrySet()) { + for (MultipartBody.FormPart cur : entry.getValue()) { + if (cur != null) { + result.add(new BasicNameValuePair(entry.getKey(), cur.getValue().toString())); + } + } + } + } + return result; + } } diff --git a/src/main/java/io/github/openunirest/request/body/MultipartBody.java b/src/main/java/io/github/openunirest/request/body/MultipartBody.java index ad84aaf2c..3a79ece6d 100644 --- a/src/main/java/io/github/openunirest/request/body/MultipartBody.java +++ b/src/main/java/io/github/openunirest/request/body/MultipartBody.java @@ -39,11 +39,29 @@ a copy of this software and associated documentation files (the import java.io.File; import java.io.InputStream; -import java.util.*; +import java.util.Collection; +import java.util.List; public class MultipartBody extends BaseRequest implements Body { - private Multimap parameters = new Multimap<>(); - private Map contentTypes = new HashMap<>(); + private Multimap parameters = new Multimap<>(); + + public static final class FormPart { + private final Object o; + private final ContentType contentType; + + public FormPart(Object o, ContentType contentType){ + this.o = o; + this.contentType = contentType; + } + + public Object getValue() { + return o; + } + + public ContentType getContentType() { + return contentType; + } + } private boolean hasFile; private HttpRequest httpRequestObj; @@ -79,8 +97,7 @@ public MultipartBody field(String name, Object value, boolean file) { } public MultipartBody field(String name, Object value, boolean file, String contentType) { - parameters.add(name, value); - + ContentType type = null; if (contentType != null && contentType.length() > 0) { type = ContentType.parse(contentType); @@ -89,7 +106,8 @@ public MultipartBody field(String name, Object value, boolean file, String conte } else { type = ContentType.APPLICATION_FORM_URLENCODED.withCharset(UTF_8); } - contentTypes.put(name, type); + + parameters.add(name, new FormPart(value, type)); if (!hasFile && file) { hasFile = true; @@ -139,18 +157,17 @@ public HttpEntity getEntity() { builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); } for (String key : parameters.keySet()) { - List value = parameters.get(key); - ContentType contentType = contentTypes.get(key); - for (Object cur : value) { - if (cur instanceof File) { - File file = (File) cur; - builder.addPart(key, new FileBody(file, contentType, file.getName())); - } else if (cur instanceof InputStreamBody) { - builder.addPart(key, (ContentBody) cur); - } else if (cur instanceof ByteArrayBody) { - builder.addPart(key, (ContentBody) cur); + List value = parameters.get(key); + for (FormPart cur : value) { + if (cur.getValue() instanceof File) { + File file = (File) cur.getValue(); + builder.addPart(key, new FileBody(file, cur.getContentType(), file.getName())); + } else if (cur.getValue() instanceof InputStreamBody) { + builder.addPart(key, (ContentBody) cur.getValue()); + } else if (cur.getValue() instanceof ByteArrayBody) { + builder.addPart(key, (ContentBody) cur.getValue()); } else { - builder.addPart(key, new StringBody(cur.toString(), contentType)); + builder.addPart(key, new StringBody(cur.getValue().toString(), cur.getContentType())); } } } From 44a66ffe84b5342dc86297f7781cc5767c55bc61 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 19 Jun 2018 21:25:55 -0500 Subject: [PATCH 0130/1769] params cannot be null --- .../openunirest/http/utils/MapUtil.java | 14 +- .../openunirest/request/body/FormPart.java | 37 +++ .../request/body/MultipartBody.java | 242 ++++++++---------- 3 files changed, 149 insertions(+), 144 deletions(-) create mode 100644 src/main/java/io/github/openunirest/request/body/FormPart.java diff --git a/src/main/java/io/github/openunirest/http/utils/MapUtil.java b/src/main/java/io/github/openunirest/http/utils/MapUtil.java index 21f246774..29e672d98 100644 --- a/src/main/java/io/github/openunirest/http/utils/MapUtil.java +++ b/src/main/java/io/github/openunirest/http/utils/MapUtil.java @@ -26,7 +26,7 @@ a copy of this software and associated documentation files (the package io.github.openunirest.http.utils; -import io.github.openunirest.request.body.MultipartBody; +import io.github.openunirest.request.body.FormPart; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; @@ -36,15 +36,11 @@ a copy of this software and associated documentation files (the public class MapUtil { - public static List getList(Multimap parameters) { + public static List getList(Multimap parameters) { List result = new ArrayList<>(); - if (parameters != null) { - for (Entry> entry : parameters.entrySet()) { - for (MultipartBody.FormPart cur : entry.getValue()) { - if (cur != null) { - result.add(new BasicNameValuePair(entry.getKey(), cur.getValue().toString())); - } - } + for (Entry> entry : parameters.entrySet()) { + for (FormPart cur : entry.getValue()) { + result.add(new BasicNameValuePair(entry.getKey(), cur.getValue().toString())); } } return result; diff --git a/src/main/java/io/github/openunirest/request/body/FormPart.java b/src/main/java/io/github/openunirest/request/body/FormPart.java new file mode 100644 index 000000000..8bd36dc72 --- /dev/null +++ b/src/main/java/io/github/openunirest/request/body/FormPart.java @@ -0,0 +1,37 @@ +package io.github.openunirest.request.body; + +import org.apache.http.entity.ContentType; +import org.apache.http.entity.mime.content.*; + +import java.io.File; + +public final class FormPart { + private final Object o; + private final ContentType contentType; + + public FormPart(Object o, ContentType contentType) { + this.o = o; + this.contentType = contentType; + } + + public Object getValue() { + return o; + } + + public ContentType getContentType() { + return contentType; + } + + public ContentBody toApachePart() { + if (o instanceof File) { + File file = (File) o; + return new FileBody(file, contentType, file.getName()); + } else if (o instanceof InputStreamBody) { + return (ContentBody) o; + } else if (o instanceof ByteArrayBody) { + return (ContentBody) o; + } else { + return new StringBody(o.toString(), contentType); + } + } +} diff --git a/src/main/java/io/github/openunirest/request/body/MultipartBody.java b/src/main/java/io/github/openunirest/request/body/MultipartBody.java index 3a79ece6d..ab32de96e 100644 --- a/src/main/java/io/github/openunirest/request/body/MultipartBody.java +++ b/src/main/java/io/github/openunirest/request/body/MultipartBody.java @@ -35,146 +35,118 @@ a copy of this software and associated documentation files (the import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.HttpMultipartMode; import org.apache.http.entity.mime.MultipartEntityBuilder; -import org.apache.http.entity.mime.content.*; +import org.apache.http.entity.mime.content.ByteArrayBody; +import org.apache.http.entity.mime.content.InputStreamBody; import java.io.File; import java.io.InputStream; import java.util.Collection; -import java.util.List; public class MultipartBody extends BaseRequest implements Body { - private Multimap parameters = new Multimap<>(); - - public static final class FormPart { - private final Object o; - private final ContentType contentType; - - public FormPart(Object o, ContentType contentType){ - this.o = o; - this.contentType = contentType; - } - - public Object getValue() { - return o; - } - - public ContentType getContentType() { - return contentType; - } - } - - private boolean hasFile; - private HttpRequest httpRequestObj; - private HttpMultipartMode mode; - - public MultipartBody(HttpRequest httpRequest) { - super(httpRequest); - this.httpRequestObj = httpRequest; - } - - public MultipartBody field(String name, String value) { - return field(name, value, false, null); - } - - public MultipartBody field(String name, String value, String contentType) { - return field(name, value, false, contentType); - } - - public MultipartBody field(String name, Collection collection) { - for (Object current : collection) { - boolean isFile = current instanceof File; - field(name, current, isFile, null); - } - return this; - } - - public MultipartBody field(String name, Object value) { - return field(name, value, false, null); - } - - public MultipartBody field(String name, Object value, boolean file) { - return field(name, value, file, null); - } - - public MultipartBody field(String name, Object value, boolean file, String contentType) { - - ContentType type = null; - if (contentType != null && contentType.length() > 0) { - type = ContentType.parse(contentType); - } else if (file) { - type = ContentType.APPLICATION_OCTET_STREAM; - } else { - type = ContentType.APPLICATION_FORM_URLENCODED.withCharset(UTF_8); - } - - parameters.add(name, new FormPart(value, type)); - - if (!hasFile && file) { - hasFile = true; - } - - return this; - } - - public MultipartBody field(String name, File file) { - return field(name, file, true, null); - } - - public MultipartBody field(String name, File file, String contentType) { - return field(name, file, true, contentType); - } - - public MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName) { - return field(name, new InputStreamBody(stream, contentType, fileName), true, contentType.getMimeType()); - } - - public MultipartBody field(String name, InputStream stream, String fileName) { - return field(name, new InputStreamBody(stream, ContentType.APPLICATION_OCTET_STREAM, fileName), true, ContentType.APPLICATION_OCTET_STREAM.getMimeType()); - } - - public MultipartBody field(String name, byte[] bytes, ContentType contentType, String fileName) { - return field(name, new ByteArrayBody(bytes, contentType, fileName), true, contentType.getMimeType()); - } - - public MultipartBody field(String name, byte[] bytes, String fileName) { - return field(name, new ByteArrayBody(bytes, ContentType.APPLICATION_OCTET_STREAM, fileName), true, ContentType.APPLICATION_OCTET_STREAM.getMimeType()); - } - - public MultipartBody basicAuth(String username, String password) { - httpRequestObj.basicAuth(username, password); - return this; - } - - public MultipartBody mode(String value) { - this.mode = HttpMultipartMode.valueOf(value); - return this; - } - - public HttpEntity getEntity() { - if (hasFile) { - MultipartEntityBuilder builder = MultipartEntityBuilder.create(); - if (mode != null) { - builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); - } - for (String key : parameters.keySet()) { - List value = parameters.get(key); - for (FormPart cur : value) { - if (cur.getValue() instanceof File) { - File file = (File) cur.getValue(); - builder.addPart(key, new FileBody(file, cur.getContentType(), file.getName())); - } else if (cur.getValue() instanceof InputStreamBody) { - builder.addPart(key, (ContentBody) cur.getValue()); - } else if (cur.getValue() instanceof ByteArrayBody) { - builder.addPart(key, (ContentBody) cur.getValue()); - } else { - builder.addPart(key, new StringBody(cur.getValue().toString(), cur.getContentType())); - } - } - } - return builder.build(); - } else { - return new UrlEncodedFormEntity(MapUtil.getList(parameters), UTF_8); - } - } + private Multimap parameters = new Multimap<>(); + + private boolean hasFile; + private HttpRequest httpRequestObj; + private HttpMultipartMode mode; + + public MultipartBody(HttpRequest httpRequest) { + super(httpRequest); + this.httpRequestObj = httpRequest; + } + + public MultipartBody field(String name, String value) { + return field(name, value, false, null); + } + + public MultipartBody field(String name, String value, String contentType) { + return field(name, value, false, contentType); + } + + public MultipartBody field(String name, Collection collection) { + for (Object current : collection) { + boolean isFile = current instanceof File; + field(name, current, isFile, null); + } + return this; + } + + public MultipartBody field(String name, Object value) { + return field(name, value, false, null); + } + + public MultipartBody field(String name, Object value, boolean file) { + return field(name, value, file, null); + } + + public MultipartBody field(String name, Object value, boolean file, String contentType) { + + ContentType type = null; + if (contentType != null && contentType.length() > 0) { + type = ContentType.parse(contentType); + } else if (file) { + type = ContentType.APPLICATION_OCTET_STREAM; + } else { + type = ContentType.APPLICATION_FORM_URLENCODED.withCharset(UTF_8); + } + + parameters.add(name, new FormPart(value, type)); + + if (!hasFile && file) { + hasFile = true; + } + + return this; + } + + public MultipartBody field(String name, File file) { + return field(name, file, true, null); + } + + public MultipartBody field(String name, File file, String contentType) { + return field(name, file, true, contentType); + } + + public MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName) { + return field(name, new InputStreamBody(stream, contentType, fileName), true, contentType.getMimeType()); + } + + public MultipartBody field(String name, InputStream stream, String fileName) { + return field(name, new InputStreamBody(stream, ContentType.APPLICATION_OCTET_STREAM, fileName), true, ContentType.APPLICATION_OCTET_STREAM.getMimeType()); + } + + public MultipartBody field(String name, byte[] bytes, ContentType contentType, String fileName) { + return field(name, new ByteArrayBody(bytes, contentType, fileName), true, contentType.getMimeType()); + } + + public MultipartBody field(String name, byte[] bytes, String fileName) { + return field(name, new ByteArrayBody(bytes, ContentType.APPLICATION_OCTET_STREAM, fileName), true, ContentType.APPLICATION_OCTET_STREAM.getMimeType()); + } + + public MultipartBody basicAuth(String username, String password) { + httpRequestObj.basicAuth(username, password); + return this; + } + + public MultipartBody mode(String value) { + this.mode = HttpMultipartMode.valueOf(value); + return this; + } + + public HttpEntity getEntity() { + if (hasFile) { + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + if (mode != null) { + builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); + } + for (String key : parameters.keySet()) { + for (FormPart cur : parameters.get(key)) { + builder.addPart(key, cur.toApachePart()); + } + } + return builder.build(); + } else { + return new UrlEncodedFormEntity(MapUtil.getList(parameters), UTF_8); + } + } } From 83fd95727af8f06776f9947574f928b73403905c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 20 Jun 2018 08:18:07 -0500 Subject: [PATCH 0131/1769] move from a map to a self contained FormPart --- .../openunirest/http/utils/MapUtil.java | 10 ++--- .../openunirest/request/body/FormPart.java | 38 +++++++++++++------ .../request/body/MultipartBody.java | 16 ++++---- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/utils/MapUtil.java b/src/main/java/io/github/openunirest/http/utils/MapUtil.java index 29e672d98..511b4518a 100644 --- a/src/main/java/io/github/openunirest/http/utils/MapUtil.java +++ b/src/main/java/io/github/openunirest/http/utils/MapUtil.java @@ -31,17 +31,15 @@ a copy of this software and associated documentation files (the import org.apache.http.message.BasicNameValuePair; import java.util.ArrayList; +import java.util.Collection; import java.util.List; -import java.util.Map.Entry; public class MapUtil { - public static List getList(Multimap parameters) { + public static List getList(Collection parameters) { List result = new ArrayList<>(); - for (Entry> entry : parameters.entrySet()) { - for (FormPart cur : entry.getValue()) { - result.add(new BasicNameValuePair(entry.getKey(), cur.getValue().toString())); - } + for (FormPart entry : parameters) { + result.add(new BasicNameValuePair(entry.getName(), entry.getValue().toString())); } return result; } diff --git a/src/main/java/io/github/openunirest/request/body/FormPart.java b/src/main/java/io/github/openunirest/request/body/FormPart.java index 8bd36dc72..1e7eee0bf 100644 --- a/src/main/java/io/github/openunirest/request/body/FormPart.java +++ b/src/main/java/io/github/openunirest/request/body/FormPart.java @@ -5,17 +5,19 @@ import java.io.File; -public final class FormPart { - private final Object o; +public final class FormPart implements Comparable { + private final String name; + private final Object value; private final ContentType contentType; - public FormPart(Object o, ContentType contentType) { - this.o = o; + public FormPart(String name, Object value, ContentType contentType) { + this.name = name; + this.value = value; this.contentType = contentType; } public Object getValue() { - return o; + return value; } public ContentType getContentType() { @@ -23,15 +25,27 @@ public ContentType getContentType() { } public ContentBody toApachePart() { - if (o instanceof File) { - File file = (File) o; + if (value instanceof File) { + File file = (File) value; return new FileBody(file, contentType, file.getName()); - } else if (o instanceof InputStreamBody) { - return (ContentBody) o; - } else if (o instanceof ByteArrayBody) { - return (ContentBody) o; + } else if (value instanceof InputStreamBody) { + return (ContentBody) value; + } else if (value instanceof ByteArrayBody) { + return (ContentBody) value; } else { - return new StringBody(o.toString(), contentType); + return new StringBody(value.toString(), contentType); } } + + public String getName() { + return name == null ? "" : name; + } + + @Override + public int compareTo(Object o) { + if(o instanceof FormPart){ + return getName().compareTo(((FormPart)o).getName()); + } + return 0; + } } diff --git a/src/main/java/io/github/openunirest/request/body/MultipartBody.java b/src/main/java/io/github/openunirest/request/body/MultipartBody.java index ab32de96e..6bbf70dcd 100644 --- a/src/main/java/io/github/openunirest/request/body/MultipartBody.java +++ b/src/main/java/io/github/openunirest/request/body/MultipartBody.java @@ -27,7 +27,6 @@ a copy of this software and associated documentation files (the package io.github.openunirest.request.body; import io.github.openunirest.http.utils.MapUtil; -import io.github.openunirest.http.utils.Multimap; import io.github.openunirest.request.BaseRequest; import io.github.openunirest.request.HttpRequest; import org.apache.http.HttpEntity; @@ -40,10 +39,13 @@ a copy of this software and associated documentation files (the import java.io.File; import java.io.InputStream; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.List; public class MultipartBody extends BaseRequest implements Body { - private Multimap parameters = new Multimap<>(); + private List parameters = new ArrayList<>(); private boolean hasFile; private HttpRequest httpRequestObj; @@ -79,7 +81,6 @@ public MultipartBody field(String name, Object value, boolean file) { } public MultipartBody field(String name, Object value, boolean file, String contentType) { - ContentType type = null; if (contentType != null && contentType.length() > 0) { type = ContentType.parse(contentType); @@ -89,7 +90,8 @@ public MultipartBody field(String name, Object value, boolean file, String conte type = ContentType.APPLICATION_FORM_URLENCODED.withCharset(UTF_8); } - parameters.add(name, new FormPart(value, type)); + parameters.add(new FormPart(name, value, type)); + Collections.sort(parameters); if (!hasFile && file) { hasFile = true; @@ -138,10 +140,8 @@ public HttpEntity getEntity() { if (mode != null) { builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); } - for (String key : parameters.keySet()) { - for (FormPart cur : parameters.get(key)) { - builder.addPart(key, cur.toApachePart()); - } + for (FormPart key : parameters) { + builder.addPart(key.getName(), key.toApachePart()); } return builder.build(); } else { From 287535a4601dbf6b89e6c2c6ff474f35791e448e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 20 Jun 2018 08:20:53 -0500 Subject: [PATCH 0132/1769] rm the Multimap since we dont need it anymore --- .../openunirest/http/utils/Multimap.java | 23 ------------------- 1 file changed, 23 deletions(-) delete mode 100644 src/main/java/io/github/openunirest/http/utils/Multimap.java diff --git a/src/main/java/io/github/openunirest/http/utils/Multimap.java b/src/main/java/io/github/openunirest/http/utils/Multimap.java deleted file mode 100644 index 299fa5eeb..000000000 --- a/src/main/java/io/github/openunirest/http/utils/Multimap.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.github.openunirest.http.utils; - -import java.util.*; - -public class Multimap { - private Map> inList = new TreeMap<>(); - - public Set keySet() { - return inList.keySet(); - } - - public List get(K key) { - return inList.get(key); - } - - public Set>> entrySet() { - return inList.entrySet(); - } - - public void add(K key, V value) { - inList.computeIfAbsent(key, k -> new ArrayList<>()).add(value); - } -} From 2e7acec73db05f9c622fc31d7731a5f1cac37a8f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 20 Jun 2018 08:27:48 -0500 Subject: [PATCH 0133/1769] start to remove usage of boolean params --- .../request/HttpRequestWithBody.java | 2 +- .../request/body/MultipartBody.java | 30 +++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java b/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java index 4075b2017..04634f8e5 100644 --- a/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java +++ b/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java @@ -127,7 +127,7 @@ public MultipartBody fields(Map parameters) { public MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName) { InputStreamBody inputStreamBody = new InputStreamBody(stream, contentType, fileName); - MultipartBody body = new MultipartBody(this).field(name, inputStreamBody, true, contentType.toString()); + MultipartBody body = new MultipartBody(this).field(name, inputStreamBody, contentType); this.body = body; return body; } diff --git a/src/main/java/io/github/openunirest/request/body/MultipartBody.java b/src/main/java/io/github/openunirest/request/body/MultipartBody.java index 6bbf70dcd..86dd12830 100644 --- a/src/main/java/io/github/openunirest/request/body/MultipartBody.java +++ b/src/main/java/io/github/openunirest/request/body/MultipartBody.java @@ -72,15 +72,7 @@ public MultipartBody field(String name, Collection collection) { return this; } - public MultipartBody field(String name, Object value) { - return field(name, value, false, null); - } - - public MultipartBody field(String name, Object value, boolean file) { - return field(name, value, file, null); - } - - public MultipartBody field(String name, Object value, boolean file, String contentType) { + private MultipartBody field(String name, Object value, boolean file, String contentType) { ContentType type = null; if (contentType != null && contentType.length() > 0) { type = ContentType.parse(contentType); @@ -90,14 +82,28 @@ public MultipartBody field(String name, Object value, boolean file, String conte type = ContentType.APPLICATION_FORM_URLENCODED.withCharset(UTF_8); } - parameters.add(new FormPart(name, value, type)); - Collections.sort(parameters); + addPart(name, value, type); + + toggleFile(file); + + return this; + } + + public MultipartBody field(String name, Object value, ContentType contentType) { + addPart(name, value, contentType); + toggleFile(true); + return this; + } + private void toggleFile(boolean file) { if (!hasFile && file) { hasFile = true; } + } - return this; + private void addPart(String name, Object value, ContentType type) { + parameters.add(new FormPart(name, value, type)); + Collections.sort(parameters); } public MultipartBody field(String name, File file) { From 72249baf316fe90307644f30929cdba1dba7daf0 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Jun 2018 08:20:48 -0500 Subject: [PATCH 0134/1769] rm bool passing from string methods --- .../openunirest/request/body/MultipartBody.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/openunirest/request/body/MultipartBody.java b/src/main/java/io/github/openunirest/request/body/MultipartBody.java index 86dd12830..4b6ae0747 100644 --- a/src/main/java/io/github/openunirest/request/body/MultipartBody.java +++ b/src/main/java/io/github/openunirest/request/body/MultipartBody.java @@ -45,6 +45,7 @@ a copy of this software and associated documentation files (the import java.util.List; public class MultipartBody extends BaseRequest implements Body { + private final ContentType defaultType = ContentType.APPLICATION_FORM_URLENCODED.withCharset(UTF_8); private List parameters = new ArrayList<>(); private boolean hasFile; @@ -57,11 +58,21 @@ public MultipartBody(HttpRequest httpRequest) { } public MultipartBody field(String name, String value) { - return field(name, value, false, null); + addPart(name, value, defaultType); + return this; } public MultipartBody field(String name, String value, String contentType) { - return field(name, value, false, contentType); + addPart(name, value, tryParse(contentType)); + return this; + } + + private ContentType tryParse(String contentType) { + if (contentType != null && contentType.length() > 0) { + return ContentType.parse(contentType); + } else { + return defaultType; + } } public MultipartBody field(String name, Collection collection) { @@ -79,7 +90,7 @@ private MultipartBody field(String name, Object value, boolean file, String cont } else if (file) { type = ContentType.APPLICATION_OCTET_STREAM; } else { - type = ContentType.APPLICATION_FORM_URLENCODED.withCharset(UTF_8); + type = defaultType; } addPart(name, value, type); From d176835a67960067a355500f98fd4ab7a9f38aaf Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Jun 2018 08:25:13 -0500 Subject: [PATCH 0135/1769] rm bool parsing from File methods --- .../request/body/MultipartBody.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/openunirest/request/body/MultipartBody.java b/src/main/java/io/github/openunirest/request/body/MultipartBody.java index 4b6ae0747..aef344bf8 100644 --- a/src/main/java/io/github/openunirest/request/body/MultipartBody.java +++ b/src/main/java/io/github/openunirest/request/body/MultipartBody.java @@ -46,6 +46,7 @@ a copy of this software and associated documentation files (the public class MultipartBody extends BaseRequest implements Body { private final ContentType defaultType = ContentType.APPLICATION_FORM_URLENCODED.withCharset(UTF_8); + private final ContentType defaultFileType = ContentType.APPLICATION_OCTET_STREAM; private List parameters = new ArrayList<>(); private boolean hasFile; @@ -88,7 +89,7 @@ private MultipartBody field(String name, Object value, boolean file, String cont if (contentType != null && contentType.length() > 0) { type = ContentType.parse(contentType); } else if (file) { - type = ContentType.APPLICATION_OCTET_STREAM; + type = defaultFileType; } else { type = defaultType; } @@ -118,11 +119,23 @@ private void addPart(String name, Object value, ContentType type) { } public MultipartBody field(String name, File file) { - return field(name, file, true, null); + addPart(name, file, defaultFileType); + toggleFile(true); + return this; } public MultipartBody field(String name, File file, String contentType) { - return field(name, file, true, contentType); + addPart(name, file, tryParseFileType(contentType)); + toggleFile(true); + return this; + } + + private ContentType tryParseFileType(String contentType) { + if (contentType != null && contentType.length() > 0) { + return ContentType.parse(contentType); + } else { + return defaultFileType; + } } public MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName) { From 3a7a5f6435a5572cef7779ab41e6ac0ef5633c5a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Jun 2018 18:58:21 -0500 Subject: [PATCH 0136/1769] ignore local gitconfig --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ed3c04537..7baad6ab7 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ release.properties META-INF .idea *.iml +.gitconfig From 3060cb7c08063a1c41e0c568ba247343cb910e12 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Jun 2018 19:10:12 -0500 Subject: [PATCH 0137/1769] rm another bool --- .../io/github/openunirest/request/body/MultipartBody.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/openunirest/request/body/MultipartBody.java b/src/main/java/io/github/openunirest/request/body/MultipartBody.java index aef344bf8..2c287bc5a 100644 --- a/src/main/java/io/github/openunirest/request/body/MultipartBody.java +++ b/src/main/java/io/github/openunirest/request/body/MultipartBody.java @@ -139,7 +139,9 @@ private ContentType tryParseFileType(String contentType) { } public MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName) { - return field(name, new InputStreamBody(stream, contentType, fileName), true, contentType.getMimeType()); + addPart(name, new InputStreamBody(stream, contentType, fileName), contentType); + toggleFile(true); + return this; } public MultipartBody field(String name, InputStream stream, String fileName) { From 501f2ba365cce0602044cc4b4a0e3e8153ebdbca Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Jun 2018 19:22:13 -0500 Subject: [PATCH 0138/1769] more bool removal --- .../openunirest/request/body/MultipartBody.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/openunirest/request/body/MultipartBody.java b/src/main/java/io/github/openunirest/request/body/MultipartBody.java index 2c287bc5a..681c4334f 100644 --- a/src/main/java/io/github/openunirest/request/body/MultipartBody.java +++ b/src/main/java/io/github/openunirest/request/body/MultipartBody.java @@ -145,15 +145,21 @@ public MultipartBody field(String name, InputStream stream, ContentType contentT } public MultipartBody field(String name, InputStream stream, String fileName) { - return field(name, new InputStreamBody(stream, ContentType.APPLICATION_OCTET_STREAM, fileName), true, ContentType.APPLICATION_OCTET_STREAM.getMimeType()); + addPart(name, new InputStreamBody(stream, ContentType.APPLICATION_OCTET_STREAM, fileName), ContentType.APPLICATION_OCTET_STREAM); + toggleFile(true); + return this; } public MultipartBody field(String name, byte[] bytes, ContentType contentType, String fileName) { - return field(name, new ByteArrayBody(bytes, contentType, fileName), true, contentType.getMimeType()); + addPart(name, new ByteArrayBody(bytes, contentType, fileName), contentType); + toggleFile(true); + return this; } public MultipartBody field(String name, byte[] bytes, String fileName) { - return field(name, new ByteArrayBody(bytes, ContentType.APPLICATION_OCTET_STREAM, fileName), true, ContentType.APPLICATION_OCTET_STREAM.getMimeType()); + addPart(name, new ByteArrayBody(bytes, ContentType.APPLICATION_OCTET_STREAM, fileName), ContentType.APPLICATION_OCTET_STREAM); + toggleFile(true); + return this; } public MultipartBody basicAuth(String username, String password) { From 1695fc0b9b1a2dee303ab3beeb90173a00cd25de Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Jun 2018 19:46:39 -0500 Subject: [PATCH 0139/1769] rm more of the boolean param --- .../request/body/MultipartBody.java | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/main/java/io/github/openunirest/request/body/MultipartBody.java b/src/main/java/io/github/openunirest/request/body/MultipartBody.java index 681c4334f..ee137b44c 100644 --- a/src/main/java/io/github/openunirest/request/body/MultipartBody.java +++ b/src/main/java/io/github/openunirest/request/body/MultipartBody.java @@ -79,25 +79,13 @@ private ContentType tryParse(String contentType) { public MultipartBody field(String name, Collection collection) { for (Object current : collection) { boolean isFile = current instanceof File; - field(name, current, isFile, null); - } - return this; - } - - private MultipartBody field(String name, Object value, boolean file, String contentType) { - ContentType type = null; - if (contentType != null && contentType.length() > 0) { - type = ContentType.parse(contentType); - } else if (file) { - type = defaultFileType; - } else { - type = defaultType; + if(isFile){ + addPart(name, current, defaultFileType); + toggleFile(true); + } else { + addPart(name, current, defaultType); + } } - - addPart(name, value, type); - - toggleFile(file); - return this; } From 820254e81a1432ee575c87df289e35561e15d314 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 23 Jun 2018 21:25:19 -0500 Subject: [PATCH 0140/1769] rm weird boolean --- .../request/HttpRequestWithBody.java | 4 +- .../openunirest/request/body/FormPart.java | 21 ++++- .../request/body/MultipartBody.java | 82 +++++++------------ 3 files changed, 50 insertions(+), 57 deletions(-) diff --git a/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java b/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java index 04634f8e5..a58ef703a 100644 --- a/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java +++ b/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java @@ -36,7 +36,6 @@ a copy of this software and associated documentation files (the import io.github.openunirest.request.body.RawBody; import io.github.openunirest.request.body.RequestBodyEntity; import org.apache.http.entity.ContentType; -import org.apache.http.entity.mime.content.InputStreamBody; import org.json.JSONArray; import org.json.JSONObject; @@ -126,8 +125,7 @@ public MultipartBody fields(Map parameters) { } public MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName) { - InputStreamBody inputStreamBody = new InputStreamBody(stream, contentType, fileName); - MultipartBody body = new MultipartBody(this).field(name, inputStreamBody, contentType); + MultipartBody body = new MultipartBody(this).field(name, stream, contentType, fileName); this.body = body; return body; } diff --git a/src/main/java/io/github/openunirest/request/body/FormPart.java b/src/main/java/io/github/openunirest/request/body/FormPart.java index 1e7eee0bf..2fe356513 100644 --- a/src/main/java/io/github/openunirest/request/body/FormPart.java +++ b/src/main/java/io/github/openunirest/request/body/FormPart.java @@ -4,12 +4,17 @@ import org.apache.http.entity.mime.content.*; import java.io.File; +import java.nio.charset.StandardCharsets; public final class FormPart implements Comparable { private final String name; private final Object value; private final ContentType contentType; + public FormPart(String name, Object value){ + this(name, value, null); + } + public FormPart(String name, Object value, ContentType contentType) { this.name = name; this.value = value; @@ -21,19 +26,25 @@ public Object getValue() { } public ContentType getContentType() { + if(contentType == null){ + if(isFile()){ + return ContentType.APPLICATION_OCTET_STREAM; + } + return ContentType.APPLICATION_FORM_URLENCODED.withCharset(StandardCharsets.UTF_8); + } return contentType; } public ContentBody toApachePart() { if (value instanceof File) { File file = (File) value; - return new FileBody(file, contentType, file.getName()); + return new FileBody(file, getContentType(), file.getName()); } else if (value instanceof InputStreamBody) { return (ContentBody) value; } else if (value instanceof ByteArrayBody) { return (ContentBody) value; } else { - return new StringBody(value.toString(), contentType); + return new StringBody(value.toString(), getContentType()); } } @@ -48,4 +59,10 @@ public int compareTo(Object o) { } return 0; } + + public boolean isFile(){ + return value instanceof File + || value instanceof InputStreamBody + || value instanceof ByteArrayBody; + } } diff --git a/src/main/java/io/github/openunirest/request/body/MultipartBody.java b/src/main/java/io/github/openunirest/request/body/MultipartBody.java index ee137b44c..b74b5688f 100644 --- a/src/main/java/io/github/openunirest/request/body/MultipartBody.java +++ b/src/main/java/io/github/openunirest/request/body/MultipartBody.java @@ -45,11 +45,8 @@ a copy of this software and associated documentation files (the import java.util.List; public class MultipartBody extends BaseRequest implements Body { - private final ContentType defaultType = ContentType.APPLICATION_FORM_URLENCODED.withCharset(UTF_8); - private final ContentType defaultFileType = ContentType.APPLICATION_OCTET_STREAM; private List parameters = new ArrayList<>(); - private boolean hasFile; private HttpRequest httpRequestObj; private HttpMultipartMode mode; @@ -59,7 +56,7 @@ public MultipartBody(HttpRequest httpRequest) { } public MultipartBody field(String name, String value) { - addPart(name, value, defaultType); + addPart(name, value); return this; } @@ -68,85 +65,50 @@ public MultipartBody field(String name, String value, String contentType) { return this; } - private ContentType tryParse(String contentType) { - if (contentType != null && contentType.length() > 0) { - return ContentType.parse(contentType); - } else { - return defaultType; - } - } - public MultipartBody field(String name, Collection collection) { - for (Object current : collection) { - boolean isFile = current instanceof File; - if(isFile){ - addPart(name, current, defaultFileType); - toggleFile(true); - } else { - addPart(name, current, defaultType); - } + for (Object current: collection) { + addPart(name, current, null); } return this; } - public MultipartBody field(String name, Object value, ContentType contentType) { - addPart(name, value, contentType); - toggleFile(true); + public MultipartBody field(String name, InputStream value, ContentType contentType) { + addPart(name, new InputStreamBody(value, contentType), contentType); return this; } - private void toggleFile(boolean file) { - if (!hasFile && file) { - hasFile = true; - } - } - - private void addPart(String name, Object value, ContentType type) { - parameters.add(new FormPart(name, value, type)); - Collections.sort(parameters); - } - public MultipartBody field(String name, File file) { - addPart(name, file, defaultFileType); - toggleFile(true); + addPart(name, file); return this; } public MultipartBody field(String name, File file, String contentType) { - addPart(name, file, tryParseFileType(contentType)); - toggleFile(true); - return this; - } + addPart(name, file, tryParse(contentType)); - private ContentType tryParseFileType(String contentType) { - if (contentType != null && contentType.length() > 0) { - return ContentType.parse(contentType); - } else { - return defaultFileType; - } + return this; } public MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName) { addPart(name, new InputStreamBody(stream, contentType, fileName), contentType); - toggleFile(true); + return this; } public MultipartBody field(String name, InputStream stream, String fileName) { addPart(name, new InputStreamBody(stream, ContentType.APPLICATION_OCTET_STREAM, fileName), ContentType.APPLICATION_OCTET_STREAM); - toggleFile(true); + return this; } public MultipartBody field(String name, byte[] bytes, ContentType contentType, String fileName) { addPart(name, new ByteArrayBody(bytes, contentType, fileName), contentType); - toggleFile(true); + return this; } public MultipartBody field(String name, byte[] bytes, String fileName) { addPart(name, new ByteArrayBody(bytes, ContentType.APPLICATION_OCTET_STREAM, fileName), ContentType.APPLICATION_OCTET_STREAM); - toggleFile(true); + return this; } @@ -161,12 +123,12 @@ public MultipartBody mode(String value) { } public HttpEntity getEntity() { - if (hasFile) { + if (parameters.stream().anyMatch(FormPart::isFile)) { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); if (mode != null) { builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); } - for (FormPart key : parameters) { + for (FormPart key: parameters) { builder.addPart(key.getName(), key.toApachePart()); } return builder.build(); @@ -175,4 +137,20 @@ public HttpEntity getEntity() { } } + private void addPart(String name, Object value, ContentType type) { + parameters.add(new FormPart(name, value, type)); + Collections.sort(parameters); + } + + private void addPart(String name, Object value) { + addPart(name, value, null); + } + + private ContentType tryParse(String contentType) { + if (contentType != null && contentType.length() > 0) { + return ContentType.parse(contentType); + } else { + return null; + } + } } From 45cc36f03eee5ba09ccaa2cfcdd050c7815f54ea Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 24 Jun 2018 07:48:45 -0500 Subject: [PATCH 0141/1769] move test --- .../request/HttpRequestWithBody.java | 16 ++++++++-------- .../openunirest/request/body/MultipartBody.java | 2 +- .../http => BehaviorTests}/SendBodyTest.java | 17 ++++++++--------- 3 files changed, 17 insertions(+), 18 deletions(-) rename src/test/java/{io/github/openunirest/http => BehaviorTests}/SendBodyTest.java (87%) diff --git a/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java b/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java index a58ef703a..63b90a6c8 100644 --- a/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java +++ b/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java @@ -89,22 +89,22 @@ public MultipartBody field(String name, Collection value) { return body; } - public MultipartBody field(String name, Object value) { - return field(name, value, null); - } - public MultipartBody field(String name, File file) { return field(name, file, null); } - public MultipartBody field(String name, Object value, String contentType) { - MultipartBody body = new MultipartBody(this).field(name, (value == null) ? "" : value.toString(), contentType); + public MultipartBody field(String name, File file, String contentType) { + MultipartBody body = new MultipartBody(this).field(name, file, contentType); this.body = body; return body; } - public MultipartBody field(String name, File file, String contentType) { - MultipartBody body = new MultipartBody(this).field(name, file, contentType); + public MultipartBody field(String name, Object value) { + return field(name, value, null); + } + + public MultipartBody field(String name, Object value, String contentType) { + MultipartBody body = new MultipartBody(this).field(name, (value == null) ? "" : value.toString(), contentType); this.body = body; return body; } diff --git a/src/main/java/io/github/openunirest/request/body/MultipartBody.java b/src/main/java/io/github/openunirest/request/body/MultipartBody.java index b74b5688f..875d8055f 100644 --- a/src/main/java/io/github/openunirest/request/body/MultipartBody.java +++ b/src/main/java/io/github/openunirest/request/body/MultipartBody.java @@ -128,7 +128,7 @@ public HttpEntity getEntity() { if (mode != null) { builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); } - for (FormPart key: parameters) { + for (FormPart key : parameters) { builder.addPart(key.getName(), key.toApachePart()); } return builder.build(); diff --git a/src/test/java/io/github/openunirest/http/SendBodyTest.java b/src/test/java/BehaviorTests/SendBodyTest.java similarity index 87% rename from src/test/java/io/github/openunirest/http/SendBodyTest.java rename to src/test/java/BehaviorTests/SendBodyTest.java index dde730212..336fd66c4 100644 --- a/src/test/java/io/github/openunirest/http/SendBodyTest.java +++ b/src/test/java/BehaviorTests/SendBodyTest.java @@ -1,13 +1,12 @@ -package io.github.openunirest.http; +package BehaviorTests; -import BehaviorTests.*; -import util.MockCallback; +import io.github.openunirest.http.JsonNode; +import io.github.openunirest.http.Unirest; import io.github.openunirest.http.exceptions.UnirestConfigException; -import io.github.openunirest.http.exceptions.UnirestException; import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; import org.junit.Test; +import util.MockCallback; import static util.TestUtil.assertException; @@ -54,7 +53,7 @@ public void postAPojoObjectUsingTheMapper() { } @Test - public void testDeleteBody() throws JSONException, UnirestException { + public void testDeleteBody() { String body = "{\"jsonString\":{\"members\":\"members1\"}}"; Unirest.delete(MockServer.DELETE) .body(body) @@ -64,7 +63,7 @@ public void testDeleteBody() throws JSONException, UnirestException { } @Test - public void postBodyAsJson() throws JSONException, UnirestException { + public void postBodyAsJson() { JSONObject body = new JSONObject(); body.put("krusty","krab"); @@ -76,7 +75,7 @@ public void postBodyAsJson() throws JSONException, UnirestException { } @Test - public void postBodyAsJsonArray() throws JSONException, UnirestException { + public void postBodyAsJsonArray() { JSONArray body = new JSONArray(); body.put(0, "krusty"); body.put(1, "krab"); @@ -89,7 +88,7 @@ public void postBodyAsJsonArray() throws JSONException, UnirestException { } @Test - public void postBodyAsJsonNode() throws JSONException, UnirestException { + public void postBodyAsJsonNode() { JsonNode body = new JsonNode("{\"krusty\":\"krab\"}"); Unirest.post(MockServer.POST) From 3fab8434bbfdfead248839bf4962fc610611bc36 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 28 Jun 2018 13:31:02 -0500 Subject: [PATCH 0142/1769] add the default charset as a settable field. closes #18 --- checkstyle.xml | 2 +- .../request/HttpRequestWithBody.java | 28 +++++++++++- .../request/body/MultipartBody.java | 14 ++++-- .../request/body/RequestBodyEntity.java | 14 ++++-- .../java/BehaviorTests/FormPostingTest.java | 45 +++++++++++++++++++ .../java/BehaviorTests/RequestCapture.java | 7 +++ 6 files changed, 100 insertions(+), 10 deletions(-) diff --git a/checkstyle.xml b/checkstyle.xml index 4c1c3fe68..6fcfd982d 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -144,7 +144,7 @@ - + diff --git a/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java b/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java index 63b90a6c8..49b377d53 100644 --- a/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java +++ b/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java @@ -41,12 +41,16 @@ a copy of this software and associated documentation files (the import java.io.File; import java.io.InputStream; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Map; import java.util.Map.Entry; public class HttpRequestWithBody extends HttpRequest { + private Charset charSet = StandardCharsets.UTF_8; + public HttpRequestWithBody(HttpMethod method, String url) { super(method, url); } @@ -104,7 +108,7 @@ public MultipartBody field(String name, Object value) { } public MultipartBody field(String name, Object value, String contentType) { - MultipartBody body = new MultipartBody(this).field(name, (value == null) ? "" : value.toString(), contentType); + MultipartBody body = new MultipartBody(this).field(name, nullToEmpty(value), contentType); this.body = body; return body; } @@ -116,7 +120,7 @@ public MultipartBody fields(Map parameters) { if (param.getValue() instanceof File) { body.field(param.getKey(), (File) param.getValue()); } else { - body.field(param.getKey(), (param.getValue() == null) ? "" : param.getValue().toString()); + body.field(param.getKey(), nullToEmpty(param.getValue())); } } } @@ -124,6 +128,13 @@ public MultipartBody fields(Map parameters) { return body; } + private String nullToEmpty(Object v) { + if(v == null){ + return ""; + } + return v.toString(); + } + public MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName) { MultipartBody body = new MultipartBody(this).field(name, stream, contentType, fileName); this.body = body; @@ -136,6 +147,11 @@ public MultipartBody field(String name, InputStream stream, String fileName) { return body; } + public HttpRequestWithBody charset(Charset charset) { + this.charSet = charset; + return this; + } + public RequestBodyEntity body(JsonNode body) { return body(body.toString()); } @@ -181,4 +197,12 @@ public RequestBodyEntity body(JSONObject body) { public RequestBodyEntity body(JSONArray body) { return body(body.toString()); } + + public Charset getCharset() { + return charSet; + } + + void setCharset(Charset charset) { + this.charSet = charset; + } } diff --git a/src/main/java/io/github/openunirest/request/body/MultipartBody.java b/src/main/java/io/github/openunirest/request/body/MultipartBody.java index 875d8055f..610ee330c 100644 --- a/src/main/java/io/github/openunirest/request/body/MultipartBody.java +++ b/src/main/java/io/github/openunirest/request/body/MultipartBody.java @@ -28,7 +28,7 @@ a copy of this software and associated documentation files (the import io.github.openunirest.http.utils.MapUtil; import io.github.openunirest.request.BaseRequest; -import io.github.openunirest.request.HttpRequest; +import io.github.openunirest.request.HttpRequestWithBody; import org.apache.http.HttpEntity; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.entity.ContentType; @@ -39,6 +39,7 @@ a copy of this software and associated documentation files (the import java.io.File; import java.io.InputStream; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -47,10 +48,10 @@ a copy of this software and associated documentation files (the public class MultipartBody extends BaseRequest implements Body { private List parameters = new ArrayList<>(); - private HttpRequest httpRequestObj; + private HttpRequestWithBody httpRequestObj; private HttpMultipartMode mode; - public MultipartBody(HttpRequest httpRequest) { + public MultipartBody(HttpRequestWithBody httpRequest) { super(httpRequest); this.httpRequestObj = httpRequest; } @@ -112,6 +113,11 @@ public MultipartBody field(String name, byte[] bytes, String fileName) { return this; } + public MultipartBody charset(Charset charset) { + httpRequestObj.charset(charset); + return this; + } + public MultipartBody basicAuth(String username, String password) { httpRequestObj.basicAuth(username, password); return this; @@ -133,7 +139,7 @@ public HttpEntity getEntity() { } return builder.build(); } else { - return new UrlEncodedFormEntity(MapUtil.getList(parameters), UTF_8); + return new UrlEncodedFormEntity(MapUtil.getList(parameters), httpRequestObj.getCharset()); } } diff --git a/src/main/java/io/github/openunirest/request/body/RequestBodyEntity.java b/src/main/java/io/github/openunirest/request/body/RequestBodyEntity.java index 9920eb48c..17d3c5fba 100644 --- a/src/main/java/io/github/openunirest/request/body/RequestBodyEntity.java +++ b/src/main/java/io/github/openunirest/request/body/RequestBodyEntity.java @@ -28,16 +28,20 @@ a copy of this software and associated documentation files (the import io.github.openunirest.http.JsonNode; import io.github.openunirest.request.BaseRequest; -import io.github.openunirest.request.HttpRequest; +import io.github.openunirest.request.HttpRequestWithBody; import org.apache.http.HttpEntity; import org.apache.http.entity.StringEntity; +import java.nio.charset.Charset; + public class RequestBodyEntity extends BaseRequest implements Body { + private final HttpRequestWithBody request; private Object body; - public RequestBodyEntity(HttpRequest httpRequest) { + public RequestBodyEntity(HttpRequestWithBody httpRequest) { super(httpRequest); + request = httpRequest; } public RequestBodyEntity body(String bodyAsString) { @@ -55,7 +59,11 @@ public Object getBody() { } public HttpEntity getEntity() { - return new StringEntity(body.toString(), UTF_8); + return new StringEntity(body.toString(), request.getCharset()); } + public RequestBodyEntity charset(Charset charset) { + request.charset(charset); + return this; + } } diff --git a/src/test/java/BehaviorTests/FormPostingTest.java b/src/test/java/BehaviorTests/FormPostingTest.java index 2e752ef23..04bec2698 100644 --- a/src/test/java/BehaviorTests/FormPostingTest.java +++ b/src/test/java/BehaviorTests/FormPostingTest.java @@ -12,6 +12,7 @@ import java.io.FileInputStream; import java.io.InputStream; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import static org.junit.Assert.assertEquals; @@ -329,6 +330,50 @@ public void testDelete() { .assertParam("foo", "bar"); } + @Test + public void testChangingEncodingToForms(){ + Unirest.post(MockServer.POST) + .charset(StandardCharsets.US_ASCII) + .field("foo", "bar") + .asObject(RequestCapture.class) + .getBody() + .assertParam("foo", "bar") + .assertCharset(StandardCharsets.US_ASCII); + } + + @Test + public void testChangingEncodingAfterMovingToForm(){ + Unirest.post(MockServer.POST) + .field("foo", "bar") + .charset(StandardCharsets.US_ASCII) + .asObject(RequestCapture.class) + .getBody() + .assertParam("foo", "bar") + .assertCharset(StandardCharsets.US_ASCII); + } + + @Test + public void canSetCharsetOfBody(){ + Unirest.post(MockServer.POST) + .charset(StandardCharsets.US_ASCII) + .body("foo") + .asObject(RequestCapture.class) + .getBody() + .asserBody("foo") + .assertCharset(StandardCharsets.US_ASCII); + } + + @Test + public void canSetCharsetOfBodyAfterMovingToBody(){ + Unirest.post(MockServer.POST) + .body("foo") + .charset(StandardCharsets.US_ASCII) + .asObject(RequestCapture.class) + .getBody() + .asserBody("foo") + .assertCharset(StandardCharsets.US_ASCII); + } + private File getImageFile() throws URISyntaxException { return new File(getClass().getResource("/image.jpg").toURI()); } diff --git a/src/test/java/BehaviorTests/RequestCapture.java b/src/test/java/BehaviorTests/RequestCapture.java index c5848712e..e516bb164 100644 --- a/src/test/java/BehaviorTests/RequestCapture.java +++ b/src/test/java/BehaviorTests/RequestCapture.java @@ -18,6 +18,7 @@ import java.util.*; import static java.lang.System.getProperty; +import static org.hamcrest.CoreMatchers.endsWith; import static org.hamcrest.CoreMatchers.hasItem; import static org.junit.Assert.*; @@ -30,6 +31,7 @@ public class RequestCapture { public String queryString; public HttpMethod method; public String param; + public String contentType; public RequestCapture() { } @@ -41,6 +43,7 @@ public RequestCapture(Request req) { writeHeaders(req); writeQuery(req); param = req.params("p"); + contentType = req.contentType(); } public void writeBody(Request req) { @@ -165,6 +168,10 @@ public RequestCapture assertUrl(String s) { return this; } + public void assertCharset(Charset charset) { + assertThat(contentType, endsWith(charset.toString())); + } + public static class File { public String fileName; public String type; From 2c8e095fd9da8b77ca5a627896a0f647e632dbdc Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 28 Jun 2018 13:42:32 -0500 Subject: [PATCH 0143/1769] [maven-release-plugin] prepare release v2.2.04 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e5ceaa475..b51f52bc6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.04-SNAPSHOT + 2.2.04 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.2.04 From a4d04181f5cf262bf6b171f01cf92046f3f2d488 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 28 Jun 2018 13:42:38 -0500 Subject: [PATCH 0144/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b51f52bc6..7337204e3 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.04 + 2.2.05-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.2.04 + HEAD From bca8a5200555efc426318501bd081464321cb14b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 28 Jun 2018 13:40:45 -0500 Subject: [PATCH 0145/1769] bump version and docs --- CHANGELOG.md | 4 ++++ README.md | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 959b36bfd..71eb03ffa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.2.04 +* Add ```.charset(Charset charset)``` to POSTS (both form and body) +* Clean up some ambiguous methods in form posting. This may be a breaking change for a very small number of users. There are better methods for handling these cases. + ## 2.2.03 * Expose the ```Options.init()``` method to restore the system to a fresh start after a shutdown. * ```Unirest.shutdown()``` no longer throws a checked exception diff --git a/README.md b/README.md index c96a87fbe..63785d1a0 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Unirest.post("http://httpbin.org/post") io.github.openunirest unirest-java - 2.2.03 + 2.3.03 ``` From 13ed300d90e2fc8c8b8c331cb1d0fa5d1dfb9195 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 2 Jul 2018 11:59:15 -0500 Subject: [PATCH 0146/1769] update documentation --- CHANGELOG.md | 1 + README.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71eb03ffa..ec7957499 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 2.2.04 * Add ```.charset(Charset charset)``` to POSTS (both form and body) * Clean up some ambiguous methods in form posting. This may be a breaking change for a very small number of users. There are better methods for handling these cases. +* Added the ability to add HttpRequestInterceptors to the client. Though ``` Options.addInterceptor(new TestInterceptor()); ``` ## 2.2.03 * Expose the ```Options.init()``` method to restore the system to a fresh start after a shutdown. diff --git a/README.md b/README.md index 63785d1a0..40283c8e1 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Unirest.post("http://httpbin.org/post") io.github.openunirest unirest-java - 2.3.03 + 2.3.04 ``` From 0a66b5fb7e4d75131582a5d176264aa6c65cbf10 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 6 Jul 2018 07:31:24 -0500 Subject: [PATCH 0147/1769] add an option to ignore redirects. closes #24 --- .../openunirest/http/options/Option.java | 13 ++++++++- .../openunirest/http/options/Options.java | 26 +++++++++++++----- src/test/java/BehaviorTests/MockServer.java | 9 ++++++- .../java/BehaviorTests/RedirectHandling.java | 27 +++++++++++++++++++ 4 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 src/test/java/BehaviorTests/RedirectHandling.java diff --git a/src/main/java/io/github/openunirest/http/options/Option.java b/src/main/java/io/github/openunirest/http/options/Option.java index c9e30e514..c41682e71 100644 --- a/src/main/java/io/github/openunirest/http/options/Option.java +++ b/src/main/java/io/github/openunirest/http/options/Option.java @@ -1,5 +1,16 @@ package io.github.openunirest.http.options; public enum Option { - HTTPCLIENT, ASYNCHTTPCLIENT, CONNECTION_TIMEOUT, SOCKET_TIMEOUT, DEFAULT_HEADERS, SYNC_MONITOR, ASYNC_MONITOR, MAX_TOTAL, MAX_PER_ROUTE, PROXY, OBJECT_MAPPER + HTTPCLIENT, + ASYNCHTTPCLIENT, + CONNECTION_TIMEOUT, + SOCKET_TIMEOUT, + DEFAULT_HEADERS, + SYNC_MONITOR, + ASYNC_MONITOR, + MAX_TOTAL, + MAX_PER_ROUTE, + PROXY, + OBJECT_MAPPER, + FOLLOW_REDIRECTS } diff --git a/src/main/java/io/github/openunirest/http/options/Options.java b/src/main/java/io/github/openunirest/http/options/Options.java index 17a1248df..7bf6d9292 100644 --- a/src/main/java/io/github/openunirest/http/options/Options.java +++ b/src/main/java/io/github/openunirest/http/options/Options.java @@ -19,6 +19,8 @@ import java.io.IOException; import java.util.*; +import static io.github.openunirest.http.options.Option.FOLLOW_REDIRECTS; + public class Options { public static final int MAX_TOTAL = 200; public static final int MAX_PER_ROUTE = 20; @@ -104,26 +106,33 @@ public static void refresh() { } private static CloseableHttpAsyncClient buildAsyncClient(RequestConfig clientConfig, PoolingNHttpClientConnectionManager asyncConnectionManager) { - HttpAsyncClientBuilder asyncBuilder = HttpAsyncClientBuilder.create() + HttpAsyncClientBuilder ab = HttpAsyncClientBuilder.create() .setDefaultRequestConfig(clientConfig) .setConnectionManager(asyncConnectionManager) .useSystemProperties(); - interceptors.stream().forEach(i -> asyncBuilder.addInterceptorFirst(i)); - return asyncBuilder.build(); + interceptors.stream().forEach(i -> ab.addInterceptorFirst(i)); + return ab.build(); } private static void buildHttpClient(RequestConfig clientConfig) { // Create clients - HttpClientBuilder httpClientBuilder = HttpClientBuilder.create() + HttpClientBuilder cb = HttpClientBuilder.create() .setDefaultRequestConfig(clientConfig) .setConnectionManager(syncConnectionManager) .useSystemProperties(); - interceptors.stream().forEach(i -> httpClientBuilder.addInterceptorFirst(i)); - CloseableHttpClient build = httpClientBuilder.build(); + disableRedirects(cb); + interceptors.stream().forEach(i -> cb.addInterceptorFirst(i)); + CloseableHttpClient build = cb.build(); setOption(Option.HTTPCLIENT, build); } + private static void disableRedirects(HttpClientBuilder cb) { + if(!(Boolean)options.getOrDefault(FOLLOW_REDIRECTS, true)){ + cb.disableRedirectHandling(); + } + } + private static RequestConfig getRequestConfig() { Integer connectionTimeout = getOptionOrDefault(Option.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT); Integer socketTimeout = getOptionOrDefault(Option.SOCKET_TIMEOUT, SOCKET_TIMEOUT); @@ -202,4 +211,9 @@ public static void addInterceptor(HttpRequestInterceptor interceptor) { interceptors.add(interceptor); refresh(); } + + public static void followRedirects(boolean enable) { + options.put(FOLLOW_REDIRECTS, enable); + refresh(); + } } diff --git a/src/test/java/BehaviorTests/MockServer.java b/src/test/java/BehaviorTests/MockServer.java index 61eeb6ef5..be0750769 100644 --- a/src/test/java/BehaviorTests/MockServer.java +++ b/src/test/java/BehaviorTests/MockServer.java @@ -35,10 +35,11 @@ a copy of this software and associated documentation files (the public class MockServer { - private static final JacksonObjectMapper om = new JacksonObjectMapper(); + private static final JacksonObjectMapper om = new JacksonObjectMapper(); private static Object responseBody; public static final int PORT = 4567; public static final String HOST = "http://localhost:" + PORT; + public static final String REDIRECT = HOST + "/redirect"; public static final String POST = HOST + "/post"; public static final String GET = HOST + "/get"; public static final String DELETE = HOST + "/delete"; @@ -63,6 +64,7 @@ public static void reset(){ post("/post", MockServer::jsonResponse); get("/get", MockServer::jsonResponse); get("/gzip", MockServer::gzipResponse); + get("/redirect", MockServer::redirect); patch("/patch", MockServer::jsonResponse); get("/invalid", MockServer::inValid); options("/get", MockServer::jsonResponse); @@ -72,6 +74,11 @@ public static void reset(){ Runtime.getRuntime().addShutdownHook(new Thread(Spark::stop)); } + private static Object redirect(Request request, Response response) { + response.redirect("/get", 301); + return null; + } + private static Object inValid(Request request, Response response) { response.status(400); return "You did something bad"; diff --git a/src/test/java/BehaviorTests/RedirectHandling.java b/src/test/java/BehaviorTests/RedirectHandling.java new file mode 100644 index 000000000..ec5571d90 --- /dev/null +++ b/src/test/java/BehaviorTests/RedirectHandling.java @@ -0,0 +1,27 @@ +package BehaviorTests; + +import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.Unirest; +import io.github.openunirest.http.options.Options; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class RedirectHandling extends BddTest { + + @Test + public void willFollowRedirectsByDefault() { + Unirest.get(MockServer.REDIRECT) + .asObject(RequestCapture.class) + .getBody() + .assertUrl("http://localhost:4567/get"); + } + + @Test + public void canDisableRedirects(){ + Options.followRedirects(false); + HttpResponse response = Unirest.get(MockServer.REDIRECT).asBinary(); + + assertEquals(301, response.getStatus()); + } +} From ddf7baa47bbfd3554cf3966f985705f7e341202e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 6 Jul 2018 10:27:51 -0500 Subject: [PATCH 0148/1769] add an option to ignore redirects in async. closes #24 --- .../openunirest/http/options/NoRedirects.java | 19 +++++++++++++++++++ .../openunirest/http/options/Options.java | 13 ++++++++----- .../java/BehaviorTests/RedirectHandling.java | 19 +++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 src/main/java/io/github/openunirest/http/options/NoRedirects.java diff --git a/src/main/java/io/github/openunirest/http/options/NoRedirects.java b/src/main/java/io/github/openunirest/http/options/NoRedirects.java new file mode 100644 index 000000000..a409fd1d9 --- /dev/null +++ b/src/main/java/io/github/openunirest/http/options/NoRedirects.java @@ -0,0 +1,19 @@ +package io.github.openunirest.http.options; + +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.client.RedirectStrategy; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.protocol.HttpContext; + +class NoRedirects implements RedirectStrategy { + @Override + public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) { + return false; + } + + @Override + public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) { + return null; + } +} diff --git a/src/main/java/io/github/openunirest/http/options/Options.java b/src/main/java/io/github/openunirest/http/options/Options.java index 7bf6d9292..19831bfae 100644 --- a/src/main/java/io/github/openunirest/http/options/Options.java +++ b/src/main/java/io/github/openunirest/http/options/Options.java @@ -110,6 +110,9 @@ private static CloseableHttpAsyncClient buildAsyncClient(RequestConfig clientCon .setDefaultRequestConfig(clientConfig) .setConnectionManager(asyncConnectionManager) .useSystemProperties(); + if(shouldDisableRedirects()){ + ab.setRedirectStrategy(new NoRedirects()); + } interceptors.stream().forEach(i -> ab.addInterceptorFirst(i)); return ab.build(); } @@ -120,17 +123,17 @@ private static void buildHttpClient(RequestConfig clientConfig) { .setDefaultRequestConfig(clientConfig) .setConnectionManager(syncConnectionManager) .useSystemProperties(); - disableRedirects(cb); + if(shouldDisableRedirects()){ + cb.disableRedirectHandling(); + } interceptors.stream().forEach(i -> cb.addInterceptorFirst(i)); CloseableHttpClient build = cb.build(); setOption(Option.HTTPCLIENT, build); } - private static void disableRedirects(HttpClientBuilder cb) { - if(!(Boolean)options.getOrDefault(FOLLOW_REDIRECTS, true)){ - cb.disableRedirectHandling(); - } + private static boolean shouldDisableRedirects() { + return !(Boolean)options.getOrDefault(FOLLOW_REDIRECTS, true); } private static RequestConfig getRequestConfig() { diff --git a/src/test/java/BehaviorTests/RedirectHandling.java b/src/test/java/BehaviorTests/RedirectHandling.java index ec5571d90..51cd4b497 100644 --- a/src/test/java/BehaviorTests/RedirectHandling.java +++ b/src/test/java/BehaviorTests/RedirectHandling.java @@ -5,6 +5,8 @@ import io.github.openunirest.http.options.Options; import org.junit.Test; +import java.util.concurrent.ExecutionException; + import static org.junit.Assert.assertEquals; public class RedirectHandling extends BddTest { @@ -24,4 +26,21 @@ public void canDisableRedirects(){ assertEquals(301, response.getStatus()); } + + @Test + public void willFollowRedirectsByDefaultAsync() throws ExecutionException, InterruptedException { + Unirest.get(MockServer.REDIRECT) + .asObjectAsync(RequestCapture.class) + .get() + .getBody() + .assertUrl("http://localhost:4567/get"); + } + + @Test + public void canDisableRedirectsAsync() throws ExecutionException, InterruptedException { + Options.followRedirects(false); + HttpResponse response = Unirest.get(MockServer.REDIRECT).asBinaryAsync().get(); + + assertEquals(301, response.getStatus()); + } } From a21ba14fff020b5ceb745fdea36774753a667607 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 9 Jul 2018 07:50:46 -0500 Subject: [PATCH 0149/1769] [maven-release-plugin] prepare release v2.2.05 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 7337204e3..8fd2f53d8 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.05-SNAPSHOT + 2.2.05 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.2.05 From 1bc62dec3b3f8a6c74f79cd8f6d5cfa15ab4ae80 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 9 Jul 2018 07:50:52 -0500 Subject: [PATCH 0150/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 8fd2f53d8..29bfdf262 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.05 + 2.2.06-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.2.05 + HEAD From a35b30cecf9d072c93ad2d95f09a5a0f7de87fdb Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 9 Jul 2018 08:30:59 -0500 Subject: [PATCH 0151/1769] [maven-release-plugin] prepare release v2.2.06 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 29bfdf262..17aee7d6b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.06-SNAPSHOT + 2.2.06 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.2.06 From 7176e99cb3444b31926ce25ab56fbf96a8b1f3d3 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 9 Jul 2018 08:31:05 -0500 Subject: [PATCH 0152/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 17aee7d6b..4a621e71b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.06 + 2.2.07-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.2.06 + HEAD From 6a86df8e97b1281034539ffd00e82d2487a0f797 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 9 Jul 2018 08:34:32 -0500 Subject: [PATCH 0153/1769] just do the tests once --- deploy | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/deploy b/deploy index 26a15204f..0f74788bc 100755 --- a/deploy +++ b/deploy @@ -1,4 +1,5 @@ #!/bin/bash -mvn release:prepare -mvn release:perform +mvn clean verify +mvn release:prepare -DskipTests +mvn release:perform -DskipTests From bd15a0baa32a584839d75629321b39e5ebc7bea5 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 10 Jul 2018 10:24:09 -0500 Subject: [PATCH 0154/1769] state should be off by default --- src/main/java/io/github/openunirest/http/options/Options.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/openunirest/http/options/Options.java b/src/main/java/io/github/openunirest/http/options/Options.java index 19831bfae..b178215d6 100644 --- a/src/main/java/io/github/openunirest/http/options/Options.java +++ b/src/main/java/io/github/openunirest/http/options/Options.java @@ -28,7 +28,7 @@ public class Options { public static final int SOCKET_TIMEOUT = 60000; private static boolean customClientSet = false; - private static boolean isRunning = true; + private static boolean isRunning = false; private static Map options = new HashMap<>(); private static PoolingHttpClientConnectionManager syncConnectionManager; private static SyncIdleConnectionMonitorThread defaultSyncMonitor; From 8d30ab2fced65a4b8b593e43e7b1888a91831527 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 10 Jul 2018 10:25:49 -0500 Subject: [PATCH 0155/1769] [maven-release-plugin] prepare release v2.2.07 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 4a621e71b..bf09cd884 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.07-SNAPSHOT + 2.2.07 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.2.07 From cc459a73c639b3f22491e473bbd29129af4ecfdb Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 10 Jul 2018 10:25:55 -0500 Subject: [PATCH 0156/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index bf09cd884..bdfbda7b2 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.07 + 2.2.08-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.2.07 + HEAD From 1599ba4871af8c7246b09db5df9f20ce59d72571 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 10 Jul 2018 12:20:28 -0500 Subject: [PATCH 0157/1769] update docs --- CHANGELOG.md | 6 ++++++ README.md | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec7957499..c9d4a567f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.2.07 +* Fix init error + +## 2.2.06 +* added ability to turn off redirect following with ```Options.followRedirects(boolean enable)``` (default is true) + ## 2.2.04 * Add ```.charset(Charset charset)``` to POSTS (both form and body) * Clean up some ambiguous methods in form posting. This may be a breaking change for a very small number of users. There are better methods for handling these cases. diff --git a/README.md b/README.md index 40283c8e1..40168a34e 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Unirest.post("http://httpbin.org/post") io.github.openunirest unirest-java - 2.3.04 + 2.3.07 ``` From 6deae2418b8771e9d70a67506c6b755b3fcbbc17 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 13 Jul 2018 13:28:06 -0500 Subject: [PATCH 0158/1769] basic auth test --- .../java/BehaviorTests/BasicAuthTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/test/java/BehaviorTests/BasicAuthTest.java diff --git a/src/test/java/BehaviorTests/BasicAuthTest.java b/src/test/java/BehaviorTests/BasicAuthTest.java new file mode 100644 index 000000000..4596bdf30 --- /dev/null +++ b/src/test/java/BehaviorTests/BasicAuthTest.java @@ -0,0 +1,26 @@ +package BehaviorTests; + +import io.github.openunirest.http.Unirest; +import org.junit.Test; + +public class BasicAuthTest extends BddTest { + @Test + public void canSendDifferentBasicAuths() { + Unirest.get(MockServer.GET) + .basicAuth("george","guitar") + .asObject(RequestCapture.class) + .getBody() + .assertBasicAuth("george","guitar"); + + Unirest.get(MockServer.GET) + .asObject(RequestCapture.class) + .getBody() + .assertNoHeader("Authorization"); + + Unirest.get(MockServer.GET) + .basicAuth("ringo","drums") + .asObject(RequestCapture.class) + .getBody() + .assertBasicAuth("ringo","drums"); + } +} From bd6d86cb975aaa8708f74683683223b9edb72b70 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 13 Jul 2018 13:34:18 -0500 Subject: [PATCH 0159/1769] more header tests --- .../openunirest/request/HttpRequest.java | 2 +- .../java/BehaviorTests/BasicAuthTest.java | 26 --------------- src/test/java/BehaviorTests/HeaderTest.java | 33 ++++++++++++++++--- 3 files changed, 30 insertions(+), 31 deletions(-) delete mode 100644 src/test/java/BehaviorTests/BasicAuthTest.java diff --git a/src/main/java/io/github/openunirest/request/HttpRequest.java b/src/main/java/io/github/openunirest/request/HttpRequest.java index 7c165169a..d456b9a72 100644 --- a/src/main/java/io/github/openunirest/request/HttpRequest.java +++ b/src/main/java/io/github/openunirest/request/HttpRequest.java @@ -41,7 +41,7 @@ public class HttpRequest extends BaseRequest { private HttpMethod httpMethod; protected String url; - Map> headers = new TreeMap>(String.CASE_INSENSITIVE_ORDER); + Map> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); protected Body body; public HttpRequest(HttpMethod method, String url) { diff --git a/src/test/java/BehaviorTests/BasicAuthTest.java b/src/test/java/BehaviorTests/BasicAuthTest.java deleted file mode 100644 index 4596bdf30..000000000 --- a/src/test/java/BehaviorTests/BasicAuthTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package BehaviorTests; - -import io.github.openunirest.http.Unirest; -import org.junit.Test; - -public class BasicAuthTest extends BddTest { - @Test - public void canSendDifferentBasicAuths() { - Unirest.get(MockServer.GET) - .basicAuth("george","guitar") - .asObject(RequestCapture.class) - .getBody() - .assertBasicAuth("george","guitar"); - - Unirest.get(MockServer.GET) - .asObject(RequestCapture.class) - .getBody() - .assertNoHeader("Authorization"); - - Unirest.get(MockServer.GET) - .basicAuth("ringo","drums") - .asObject(RequestCapture.class) - .getBody() - .assertBasicAuth("ringo","drums"); - } -} diff --git a/src/test/java/BehaviorTests/HeaderTest.java b/src/test/java/BehaviorTests/HeaderTest.java index f4fdaf7a4..40f7051fa 100644 --- a/src/test/java/BehaviorTests/HeaderTest.java +++ b/src/test/java/BehaviorTests/HeaderTest.java @@ -123,15 +123,40 @@ public void basicAuthOnPosts() { @Test public void willNotCacheBasicAuth() { Unirest.get(MockServer.GET) - .basicAuth("foo", "bar") + .basicAuth("george","guitar") .asObject(RequestCapture.class) .getBody() - .assertBasicAuth("foo", "bar"); + .assertBasicAuth("george","guitar"); Unirest.get(MockServer.GET) - .basicAuth("baz", "qux") .asObject(RequestCapture.class) .getBody() - .assertBasicAuth("baz", "qux"); + .assertNoHeader("Authorization"); + + Unirest.get(MockServer.GET) + .basicAuth("ringo","drums") + .asObject(RequestCapture.class) + .getBody() + .assertBasicAuth("ringo","drums"); + } + + @Test + public void willNotCacheHeadersAccrossRequests() { + Unirest.get(MockServer.GET) + .header("foo", "bar") + .asObject(RequestCapture.class) + .getBody() + .assertHeader("foo", "bar"); + + Unirest.get(MockServer.GET) + .asObject(RequestCapture.class) + .getBody() + .assertNoHeader("foo"); + + Unirest.get(MockServer.GET) + .header("baz", "qux") + .asObject(RequestCapture.class) + .getBody() + .assertHeader("baz", "qux"); } } From 249ca0bbf7a4fcd05897e8701fb407280290a95e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 13 Jul 2018 15:00:32 -0500 Subject: [PATCH 0160/1769] no caching across types --- src/test/java/BehaviorTests/HeaderTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/BehaviorTests/HeaderTest.java b/src/test/java/BehaviorTests/HeaderTest.java index 40f7051fa..4d7168ebe 100644 --- a/src/test/java/BehaviorTests/HeaderTest.java +++ b/src/test/java/BehaviorTests/HeaderTest.java @@ -159,4 +159,19 @@ public void willNotCacheHeadersAccrossRequests() { .getBody() .assertHeader("baz", "qux"); } + + @Test + public void doesNotCacheAcrossTypes(){ + Unirest.get(MockServer.GET) + .basicAuth("user1","pass1") + .asObject(RequestCapture.class) + .getBody() + .assertBasicAuth("user1","pass1"); + + Unirest.post(MockServer.POST) + .basicAuth("user2", "pass2") + .asObject(RequestCapture.class) + .getBody() + .assertBasicAuth("user2", "pass2"); + } } From 77f7fe7ca89142459343c4b15bb740bfc957dc80 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 13 Jul 2018 15:10:02 -0500 Subject: [PATCH 0161/1769] more tests --- src/test/java/BehaviorTests/HeaderTest.java | 19 +++++++++++++++++++ .../java/BehaviorTests/RequestCapture.java | 4 +--- src/test/java/util/TestUtil.java | 8 ++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/test/java/BehaviorTests/HeaderTest.java b/src/test/java/BehaviorTests/HeaderTest.java index 4d7168ebe..013d6517f 100644 --- a/src/test/java/BehaviorTests/HeaderTest.java +++ b/src/test/java/BehaviorTests/HeaderTest.java @@ -5,11 +5,13 @@ import io.github.openunirest.http.JsonNode; import io.github.openunirest.http.Unirest; import io.github.openunirest.request.GetRequest; +import org.junit.Ignore; import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertEquals; +import static util.TestUtil.assertBasicAuth; import static util.TestUtil.mapOf; public class HeaderTest extends BddTest { @@ -174,4 +176,21 @@ public void doesNotCacheAcrossTypes(){ .getBody() .assertBasicAuth("user2", "pass2"); } + + @Test @Ignore + public void doesNotCacheAuthAcrossDomains(){ + Unirest.get(MockServer.GET) + .basicAuth("user1","pass1") + .asObject(RequestCapture.class) + .getBody() + .assertBasicAuth("user1","pass1"); + + JsonNode bin = Unirest.post("http://httpbin.org/post") + .basicAuth("user2", "pass2") + .asJson() + .getBody(); + + String header = bin.getObject().getJSONObject("headers").getString("Authorization"); + assertBasicAuth(header, "user2", "pass2"); + } } diff --git a/src/test/java/BehaviorTests/RequestCapture.java b/src/test/java/BehaviorTests/RequestCapture.java index e516bb164..853851ca5 100644 --- a/src/test/java/BehaviorTests/RequestCapture.java +++ b/src/test/java/BehaviorTests/RequestCapture.java @@ -145,9 +145,7 @@ public RequestCapture assertFileContent(String input, String content) { public void assertBasicAuth(String username, String password) { String raw = headers.get("Authorization"); - assertNotNull("Authorization Header Missing", raw); - String credentials = raw.replace("Basic ",""); - assertEquals(username + ":" + password, new String(Base64.getDecoder().decode(credentials))); + TestUtil.assertBasicAuth(raw, username, password); } public void assertQueryString(String s) { diff --git a/src/test/java/util/TestUtil.java b/src/test/java/util/TestUtil.java index 59a6862e4..19a05b7d0 100644 --- a/src/test/java/util/TestUtil.java +++ b/src/test/java/util/TestUtil.java @@ -6,11 +6,13 @@ import io.github.openunirest.http.HttpResponse; import java.io.*; +import java.util.Base64; import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; public class TestUtil { @@ -106,4 +108,10 @@ public static T read(HttpResponse r, Class as) { throw new RuntimeException(e); } } + + public static void assertBasicAuth(String raw, String username, String password) { + assertNotNull("Authorization Header Missing", raw); + String credentials = raw.replace("Basic ",""); + assertEquals(username + ":" + password, new String(Base64.getDecoder().decode(credentials))); + } } From 9e3699dbf2f688b873db3a9f575ddebcaa24649a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 13 Jul 2018 16:07:27 -0500 Subject: [PATCH 0162/1769] enable toggling cookie management --- .../github/openunirest/http/options/Option.java | 3 ++- .../github/openunirest/http/options/Options.java | 16 ++++++++++++++++ src/test/java/BehaviorTests/MockServer.java | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/openunirest/http/options/Option.java b/src/main/java/io/github/openunirest/http/options/Option.java index c41682e71..4541f39a3 100644 --- a/src/main/java/io/github/openunirest/http/options/Option.java +++ b/src/main/java/io/github/openunirest/http/options/Option.java @@ -12,5 +12,6 @@ public enum Option { MAX_PER_ROUTE, PROXY, OBJECT_MAPPER, - FOLLOW_REDIRECTS + FOLLOW_REDIRECTS, + COOKIE_MANAGEMENT } diff --git a/src/main/java/io/github/openunirest/http/options/Options.java b/src/main/java/io/github/openunirest/http/options/Options.java index b178215d6..71ab7c0bc 100644 --- a/src/main/java/io/github/openunirest/http/options/Options.java +++ b/src/main/java/io/github/openunirest/http/options/Options.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.util.*; +import static io.github.openunirest.http.options.Option.COOKIE_MANAGEMENT; import static io.github.openunirest.http.options.Option.FOLLOW_REDIRECTS; public class Options { @@ -113,6 +114,9 @@ private static CloseableHttpAsyncClient buildAsyncClient(RequestConfig clientCon if(shouldDisableRedirects()){ ab.setRedirectStrategy(new NoRedirects()); } + if(shouldDisableCookieManagement()){ + ab.disableCookieManagement(); + } interceptors.stream().forEach(i -> ab.addInterceptorFirst(i)); return ab.build(); } @@ -126,12 +130,19 @@ private static void buildHttpClient(RequestConfig clientConfig) { if(shouldDisableRedirects()){ cb.disableRedirectHandling(); } + if(shouldDisableCookieManagement()){ + cb.disableCookieManagement(); + } interceptors.stream().forEach(i -> cb.addInterceptorFirst(i)); CloseableHttpClient build = cb.build(); setOption(Option.HTTPCLIENT, build); } + private static boolean shouldDisableCookieManagement() { + return !(Boolean)options.getOrDefault(COOKIE_MANAGEMENT, true); + } + private static boolean shouldDisableRedirects() { return !(Boolean)options.getOrDefault(FOLLOW_REDIRECTS, true); } @@ -219,4 +230,9 @@ public static void followRedirects(boolean enable) { options.put(FOLLOW_REDIRECTS, enable); refresh(); } + + public static void enableCookieManagement(boolean enable){ + options.put(COOKIE_MANAGEMENT, enable); + refresh(); + } } diff --git a/src/test/java/BehaviorTests/MockServer.java b/src/test/java/BehaviorTests/MockServer.java index be0750769..ae9811dcc 100644 --- a/src/test/java/BehaviorTests/MockServer.java +++ b/src/test/java/BehaviorTests/MockServer.java @@ -90,6 +90,7 @@ private static Object gzipResponse(Request request, Response response) { } private static Object jsonResponse(Request req, Response res) { + res.cookie("JSESSIONID", "ABC123"); if(responseBody != null){ return responseBody; } From bc0c180a2e7e92d5070de3023378bbac633a8516 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 13 Jul 2018 16:10:08 -0500 Subject: [PATCH 0163/1769] [maven-release-plugin] prepare release v2.2.08 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index bdfbda7b2..86e7fac18 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.08-SNAPSHOT + 2.2.08 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.2.08 From b12ed2808e909c4ea7ce387bf8f280108f9e9f6c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 13 Jul 2018 16:10:17 -0500 Subject: [PATCH 0164/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 86e7fac18..c43fdc5e4 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.08 + 2.2.09-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.2.08 + HEAD From 9f934f0e25e0a493fb9925a6d2303efa0c7affcb Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 16 Jul 2018 10:13:36 -0500 Subject: [PATCH 0165/1769] update docs --- CHANGELOG.md | 4 ++++ README.md | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9d4a567f..b89bc5fa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +#2.2.08 +* add an option to disable cookie management with ```Options.enableCookieManagement(false)```. + * In the future ignoring cookies will be the default. + ## 2.2.07 * Fix init error diff --git a/README.md b/README.md index 40168a34e..bf56c3079 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Unirest.post("http://httpbin.org/post") io.github.openunirest unirest-java - 2.3.07 + 2.3.08 ``` From bba1dd9951b0af0c92c45ca13455b7495f76a1c1 Mon Sep 17 00:00:00 2001 From: xxRockOnxx Date: Mon, 23 Jul 2018 10:21:25 +0800 Subject: [PATCH 0166/1769] fix wrong version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf56c3079..630b89241 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Unirest.post("http://httpbin.org/post") io.github.openunirest unirest-java - 2.3.08 + 2.2.08 ``` From 480239d0bb3a1a8f6e31a74e13ce37df8685b943 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 13 Aug 2018 15:54:40 -0500 Subject: [PATCH 0167/1769] update readme --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 630b89241..35b3821b6 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,14 @@ # Unirest for Java [![Build Status](https://travis-ci.org/OpenUnirest/unirest-java.svg?branch=master)](https://travis-ci.org/OpenUnirest/unirest-java) -Do yourself a favor, and start making HTTP requests like this: +## About This Repository +This repo is an updated, maintained, and independenct fork of the original Mashape/Kong Unirest-Java project. That project is no longer being maintained so this project was set up to keep it alive. + +There are several such forks in the world. The guiding principals of this project is: + * ***Maintain backwards compatibity whenever possible with the original project***: Other than a namespace change your code should work exactly like it did before for the vast majority of use cases. + * ***Security Patches are a Top Priority!*** + * ***Move the project forward into modern Java***: This project does require Java 8 as a minimum. + -```java -Unirest.post("http://httpbin.org/post") - .queryString("name", "Mark") - .field("last", "Polo") - .asJson() -``` ## Install With [Maven](https://mvnrepository.com/artifact/io.github.openunirest/unirest-java) ``` From b2e5a82ecc4cbdddfacc4488e043d25541ceebe3 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 13 Aug 2018 16:02:40 -0500 Subject: [PATCH 0168/1769] update Apache dependencies --- CHANGELOG.md | 7 +++++-- pom.xml | 10 +++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b89bc5fa0..1f2f21c0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ -#2.2.08 -* add an option to disable cookie management with ```Options.enableCookieManagement(false)```. +## 2.2.09 +* Update Apache dependencies https://archive.apache.org/dist/httpcomponents/httpclient/RELEASE_NOTES-4.5.x.txt + +## 2.2.08 + * add an option to disable cookie management with ```Options.enableCookieManagement(false)```. * In the future ignoring cookies will be the default. ## 2.2.07 diff --git a/pom.xml b/pom.xml index c43fdc5e4..f869b2ffb 100644 --- a/pom.xml +++ b/pom.xml @@ -219,17 +219,17 @@ org.apache.httpcomponents httpclient - 4.5.5 + 4.5.6 org.apache.httpcomponents - httpasyncclient - 4.1.3 + httpmime + 4.5.6 org.apache.httpcomponents - httpmime - 4.5.5 + httpasyncclient + 4.1.4 org.json From 109fb03df75c72e89a33db7fb1589bd1fa208284 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 30 Jul 2018 15:02:40 -0500 Subject: [PATCH 0169/1769] supply custom manifest --- pom.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pom.xml b/pom.xml index f869b2ffb..3de678cda 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,16 @@ + + org.apache.maven.plugins + maven-jar-plugin + + + src/main/resources/META-INF/MANIFEST.MF + + + + org.apache.maven.plugins maven-checkstyle-plugin From 4b68e830ed82e520d4681bc462f3d4ab70b7306d Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 13 Aug 2018 14:25:57 -0500 Subject: [PATCH 0170/1769] pause for 2 sec to let Spark warm up --- src/test/java/BehaviorTests/MockServer.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/java/BehaviorTests/MockServer.java b/src/test/java/BehaviorTests/MockServer.java index ae9811dcc..ae6aea82e 100644 --- a/src/test/java/BehaviorTests/MockServer.java +++ b/src/test/java/BehaviorTests/MockServer.java @@ -31,6 +31,9 @@ a copy of this software and associated documentation files (the import spark.Response; import spark.Spark; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + import static spark.Spark.*; public class MockServer { @@ -72,6 +75,11 @@ public static void reset(){ put("/post", MockServer::jsonResponse); get("/get/:p/passed", MockServer::jsonResponse); Runtime.getRuntime().addShutdownHook(new Thread(Spark::stop)); + try { + new CountDownLatch(1).await(2, TimeUnit.SECONDS); + } catch (InterruptedException e) { + e.printStackTrace(); + } } private static Object redirect(Request request, Response response) { From 50dbaef610b258283d032bc214f5d880c0473b88 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 13 Aug 2018 16:08:06 -0500 Subject: [PATCH 0171/1769] [maven-release-plugin] prepare release v2.2.09 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3de678cda..7c8aed254 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.09-SNAPSHOT + 2.2.09 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.2.09 From f3ab7b8c6f0b41d1436f5ebb35c8855ddd42fa09 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 13 Aug 2018 16:08:17 -0500 Subject: [PATCH 0172/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 7c8aed254..2d8f51b33 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.09 + 2.2.10-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.2.09 + HEAD From b70c127bd0e16f104141130a0635c3498649cf8b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 13 Aug 2018 17:09:50 -0500 Subject: [PATCH 0173/1769] always sign with Unirest --- pom.xml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 2d8f51b33..274279c2d 100644 --- a/pom.xml +++ b/pom.xml @@ -78,12 +78,13 @@ org.apache.maven.plugins maven-jar-plugin + 3.1.0 - - src/main/resources/META-INF/MANIFEST.MF - - - + + Unirest + + + org.apache.maven.plugins From 835918074721e6b944dd46cc68a920eb176da222 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 13 Aug 2018 17:49:53 -0500 Subject: [PATCH 0174/1769] fix manifest archiver --- pom.xml | 523 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 263 insertions(+), 260 deletions(-) diff --git a/pom.xml b/pom.xml index 274279c2d..5e913f337 100644 --- a/pom.xml +++ b/pom.xml @@ -1,54 +1,55 @@ - - 4.0.0 - io.github.openunirest - unirest-java - jar - 2.2.10-SNAPSHOT - unirest-java - Simplified, lightweight HTTP client library - http://github.com/OpenUnirest/ + + 4.0.0 + io.github.openunirest + unirest-java + jar + 2.2.10-SNAPSHOT + unirest-java + Simplified, lightweight HTTP client library + http://github.com/OpenUnirest/ - - - MIT - http://opensource.org/licenses/MIT - repo - - + + + MIT + http://opensource.org/licenses/MIT + repo + + - - https://github.com/OpenUnirest/unirest-java - scm:git:git@github.com:OpenUnirest/unirest-java.git - scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD - + + https://github.com/OpenUnirest/unirest-java + scm:git:git@github.com:OpenUnirest/unirest-java.git + scm:git:git@github.com:OpenUnirest/unirest-java.git + HEAD + - - - Ryber - Ryan Bergman - https://github.com/OpenUnirest - OpenUnirest - - + + + Ryber + Ryan Bergman + https://github.com/OpenUnirest + OpenUnirest + + - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + - - UTF-8 - UTF-8 - 2.9.4 - + + UTF-8 + UTF-8 + 2.9.4 + @@ -73,86 +74,88 @@ - - - - org.apache.maven.plugins - maven-jar-plugin - 3.1.0 - - - Unirest - - - + + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.0 + + + + Unirest + + + + - - org.apache.maven.plugins - maven-checkstyle-plugin - 2.13 - - - com.puppycrawl.tools - checkstyle - 5.9 - - - - - compile - auto-checkstyle - - checkstyle - check - - - - - ${basedir}/checkstyle.xml - ${basedir}/suppressions.xml - true - false - - - - org.jacoco - jacoco-maven-plugin - 0.8.1 - - - default-prepare-agent - - prepare-agent - - - - default-report - - report - - - - default-check - - check - - - - - BUNDLE - - - COMPLEXITY - COVEREDRATIO - 0.60 - - - - - - - - + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.13 + + + com.puppycrawl.tools + checkstyle + 5.9 + + + + + compile + auto-checkstyle + + checkstyle + check + + + + + ${basedir}/checkstyle.xml + ${basedir}/suppressions.xml + true + false + + + + org.jacoco + jacoco-maven-plugin + 0.8.1 + + + default-prepare-agent + + prepare-agent + + + + default-report + + report + + + + default-check + + check + + + + + BUNDLE + + + COMPLEXITY + COVEREDRATIO + 0.60 + + + + + + + + org.apache.maven.plugins maven-release-plugin @@ -162,142 +165,142 @@ v@{project.version} - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.7 - true - - ossrh - https://oss.sonatype.org/ - true - - + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrh + https://oss.sonatype.org/ + true + + - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - true - 128m - 512m - 1.8 - 1.8 - UTF-8 - - - - org.apache.maven.plugins - maven-assembly-plugin - 2.4 - - - jar-with-dependencies - - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - attach-javadocs - - jar - - - - - - + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + true + 128m + 512m + 1.8 + 1.8 + UTF-8 + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.4 + + + jar-with-dependencies + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + + + + - - - org.apache.httpcomponents - httpclient - 4.5.6 - - - org.apache.httpcomponents - httpmime - 4.5.6 - - - org.apache.httpcomponents - httpasyncclient - 4.1.4 - - - org.json - json - 20180130 - - - junit - junit - 4.12 - test - - - - org.hamcrest - hamcrest-all - 1.3 - test - - - commons-io - commons-io - 2.4 - test - - - - org.mockito - mockito-all - 2.0.2-beta - test - - - - com.google.guava - guava - 24.0-jre - test - - - - com.fasterxml.jackson.datatype - jackson-datatype-guava - ${jackson.version} - test - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - test - - - com.sparkjava - spark-core - 2.6.0 - test - - + + + org.apache.httpcomponents + httpclient + 4.5.6 + + + org.apache.httpcomponents + httpmime + 4.5.6 + + + org.apache.httpcomponents + httpasyncclient + 4.1.4 + + + org.json + json + 20180130 + + + junit + junit + 4.12 + test + + + + org.hamcrest + hamcrest-all + 1.3 + test + + + commons-io + commons-io + 2.4 + test + + + + org.mockito + mockito-all + 2.0.2-beta + test + + + + com.google.guava + guava + 24.0-jre + test + + + + com.fasterxml.jackson.datatype + jackson-datatype-guava + ${jackson.version} + test + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + test + + + com.sparkjava + spark-core + 2.6.0 + test + + From d2ab5d9fbfe0b104aebfbe65c03081fa9ce3dd43 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 13 Aug 2018 20:24:21 -0500 Subject: [PATCH 0175/1769] [maven-release-plugin] prepare release v2.2.10 --- pom.xml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 5e913f337..a1e269f4e 100644 --- a/pom.xml +++ b/pom.xml @@ -1,11 +1,10 @@ - + 4.0.0 io.github.openunirest unirest-java jar - 2.2.10-SNAPSHOT + 2.2.10 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -22,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.2.10 From 72d075658bd7d4e478fad34723bf42d40ecbc29a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 13 Aug 2018 20:24:29 -0500 Subject: [PATCH 0176/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index a1e269f4e..6d7f84b5a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.10 + 2.2.11-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.2.10 + HEAD From 54bc5ac4b185acaaeffc7499aba47fc2d909a9f9 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 13 Aug 2018 22:22:51 -0500 Subject: [PATCH 0177/1769] update doc --- CHANGELOG.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f2f21c0b..f54703d01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 2.2.09 +## 2.2.10 * Update Apache dependencies https://archive.apache.org/dist/httpcomponents/httpclient/RELEASE_NOTES-4.5.x.txt ## 2.2.08 diff --git a/README.md b/README.md index 35b3821b6..59b8ee9c1 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ There are several such forks in the world. The guiding principals of this projec io.github.openunirest unirest-java - 2.2.08 + 2.2.10 ``` From dd51c3522cc1a4e6e49a7d9ba383d320e7868f26 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 16 Aug 2018 15:59:22 -0500 Subject: [PATCH 0178/1769] Create CODE_OF_CONDUCT.md --- CODE_OF_CONDUCT.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 CODE_OF_CONDUCT.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 000000000..ae6a4bb21 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,46 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at ryan.bergman@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ From 8c782bd29230c0dac73494d482053bfefe3a4f8a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 16 Aug 2018 16:31:59 -0500 Subject: [PATCH 0179/1769] add contributing file --- CONTRIBUTING.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..ade83b9b5 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,34 @@ +# Contributing to Atom + +:+1::tada: First off, thanks for taking the time to contribute! :tada::+1: + +## Code of Conduct + +This project and everyone participating in it is governed by the [Atom Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. + +## How Can I Contribute? + +### Reporting Bugs +**Explain how to produce the problem** in as many details as possible. When listing steps, **don't just say what you did, but explain how you did it**. +* **Provide specific examples to demonstrate the steps**. Include links to files or GitHub projects, or copy/pasteable snippets, which you use in those examples. If you're providing snippets in the issue, use [Markdown code blocks](https://help.github.com/articles/markdown-basics/#multiple-lines). +* **Describe the behavior you observed after following the steps** and point out what exactly is the problem with that behavior. +* **Explain which behavior you expected to see instead and why.** + +Include details about your configuration and environment: + +* **What version of Unirest were you using?** +* **What version of Java were you running it on?** +* **Did you do any custom configuration to the client?** + + +### Contributing Code + +* Before you put in all the work to add a new feature. Try opening a issue and checking if it's something that will be accepted. Sometimes a feature you think might be useful might be contrary to the goals or direction of the project. We won't want folks to get frustrated, so take a minute and talk it through with us. +* If we do all agree it's a good idea we would expect: + * Backwards compatibility is important to this project and you should go out of your way to not make breaking changes. + * All contributions should be issued as pull requests and get reviewed by the admins of this project. + * All code should follow style guidelines enforced by the checkstyle and other static analysis. + * All code should have tests. + * Unit tests + * Behavioral tests (see https://github.com/OpenUnirest/unirest-java/tree/master/src/test/java/BehaviorTests) + * You should have run verify before submitting and the PR needs to have passed TravisCI before being merged. From f2872b747f5403e0d33f4c8e19fdc30a696f0837 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 16 Aug 2018 21:18:15 -0500 Subject: [PATCH 0180/1769] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 59b8ee9c1..d4dc18cf2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Unirest for Java [![Build Status](https://travis-ci.org/OpenUnirest/unirest-java.svg?branch=master)](https://travis-ci.org/OpenUnirest/unirest-java) +[![DepShield Badge](https://depshield.sonatype.org/badges/OpenUnirest/unirest-java/depshield.svg)](https://depshield.github.io) + ## About This Repository This repo is an updated, maintained, and independenct fork of the original Mashape/Kong Unirest-Java project. That project is no longer being maintained so this project was set up to keep it alive. From 61cc47fd20db25d92e78810246ede0b66dea7b1f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 21 Aug 2018 14:31:13 -0500 Subject: [PATCH 0181/1769] use browser mode by default rather than strict because its 2018. Closes #35 --- .../request/body/MultipartBody.java | 12 +++++--- .../java/BehaviorTests/FormPostingTest.java | 30 +++++++++++++++++++ .../java/BehaviorTests/RequestCapture.java | 5 +++- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/openunirest/request/body/MultipartBody.java b/src/main/java/io/github/openunirest/request/body/MultipartBody.java index 610ee330c..af050e5da 100644 --- a/src/main/java/io/github/openunirest/request/body/MultipartBody.java +++ b/src/main/java/io/github/openunirest/request/body/MultipartBody.java @@ -49,7 +49,7 @@ public class MultipartBody extends BaseRequest implements Body { private List parameters = new ArrayList<>(); private HttpRequestWithBody httpRequestObj; - private HttpMultipartMode mode; + private HttpMultipartMode mode = HttpMultipartMode.BROWSER_COMPATIBLE; public MultipartBody(HttpRequestWithBody httpRequest) { super(httpRequest); @@ -128,12 +128,16 @@ public MultipartBody mode(String value) { return this; } + public MultipartBody mode(HttpMultipartMode value) { + this.mode = value; + return this; + } + public HttpEntity getEntity() { if (parameters.stream().anyMatch(FormPart::isFile)) { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); - if (mode != null) { - builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); - } + builder.setCharset(httpRequestObj.getCharset()); + builder.setMode(mode); for (FormPart key : parameters) { builder.addPart(key.getName(), key.toApachePart()); } diff --git a/src/test/java/BehaviorTests/FormPostingTest.java b/src/test/java/BehaviorTests/FormPostingTest.java index 04bec2698..c0a55ad19 100644 --- a/src/test/java/BehaviorTests/FormPostingTest.java +++ b/src/test/java/BehaviorTests/FormPostingTest.java @@ -4,10 +4,12 @@ import io.github.openunirest.request.HttpRequest; import org.apache.commons.io.IOUtils; import org.apache.http.entity.ContentType; +import org.apache.http.entity.mime.HttpMultipartMode; import org.junit.Test; import util.MockCallback; import util.TestUtil; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; @@ -374,6 +376,34 @@ public void canSetCharsetOfBodyAfterMovingToBody(){ .assertCharset(StandardCharsets.US_ASCII); } + @Test + public void utf8FileNames() { + InputStream fileData = new ByteArrayInputStream(new byte[] {'t', 'e', 's', 't'}); + final String filename = "fileäöü.pöf"; + + Unirest.post(MockServer.POST) + .field("file", fileData, filename) + .asObject(RequestCapture.class) + .getBody() + .getFile(filename) + .assertFileName(filename); + } + + @Test + public void canSetModeToStrictForLegacySupport() { + InputStream fileData = new ByteArrayInputStream(new byte[] {'t', 'e', 's', 't'}); + final String filename = "fileäöü.pöf"; + + Unirest.post(MockServer.POST) + .field("file", fileData, filename) + .mode(HttpMultipartMode.STRICT) + .asObject(RequestCapture.class) + .getBody() + .getFile("file???.p?f") + .assertFileName("file???.p?f"); + } + + private File getImageFile() throws URISyntaxException { return new File(getClass().getResource("/image.jpg").toURI()); } diff --git a/src/test/java/BehaviorTests/RequestCapture.java b/src/test/java/BehaviorTests/RequestCapture.java index 853851ca5..69fb03d65 100644 --- a/src/test/java/BehaviorTests/RequestCapture.java +++ b/src/test/java/BehaviorTests/RequestCapture.java @@ -5,6 +5,7 @@ import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import io.github.openunirest.http.HttpMethod; +import io.github.openunirest.http.HttpResponse; import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.entity.ContentType; import spark.Request; @@ -16,6 +17,7 @@ import java.io.IOException; import java.nio.charset.Charset; import java.util.*; +import java.util.stream.Collectors; import static java.lang.System.getProperty; import static org.hamcrest.CoreMatchers.endsWith; @@ -128,7 +130,8 @@ public File getFile(String fileName) { return files.stream() .filter(f -> Objects.equals(f.fileName, fileName)) .findFirst() - .orElseThrow(() -> new RuntimeException("No File With Name: " + fileName)); + .orElseThrow(() -> new RuntimeException("\nNo File With Name: " + fileName + "\n" + + "Found: " + files.stream().map(f -> f.fileName).collect(Collectors.joining(" ")))); } public File getFileByInput(String input) { From 5a55e40bc087dcfe611ec9ac4ba230d630f4d25b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 21 Aug 2018 14:47:18 -0500 Subject: [PATCH 0182/1769] [maven-release-plugin] prepare release v2.2.11 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 6d7f84b5a..861a9c7ba 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.11-SNAPSHOT + 2.2.11 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.2.11 From db0994c1d6f54dc6a7c9ad5f7fb8e0e2f126088a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 21 Aug 2018 14:47:24 -0500 Subject: [PATCH 0183/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 861a9c7ba..bb1912f3c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.11 + 2.2.12-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.2.11 + HEAD From aed747b603c25cba17b2f915fa36ac571b3ae0c0 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 21 Aug 2018 14:52:26 -0500 Subject: [PATCH 0184/1769] update docs --- CHANGELOG.md | 3 +++ README.md | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f54703d01..07f2e65a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.2.11 +* Change default MultiPart mode to BROWSER_COMPATIBLE in order to support unicode filenames. Clients wishing to use the legacy mode can set it to STRICT. This should not be a problem for most users as few servers today lack support for unicode file names. Issue #35 + ## 2.2.10 * Update Apache dependencies https://archive.apache.org/dist/httpcomponents/httpclient/RELEASE_NOTES-4.5.x.txt diff --git a/README.md b/README.md index d4dc18cf2..c68b04b9d 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ There are several such forks in the world. The guiding principals of this projec io.github.openunirest unirest-java - 2.2.10 + 2.2.11 ``` From 5cc6aa3ea2b4d613d82a0ff566ec2cb85cfde6a6 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 21 Aug 2018 14:45:48 -0500 Subject: [PATCH 0185/1769] retain some options. Possibly addresses #34 --- .../io/github/openunirest/http/Unirest.java | 12 +++++- .../openunirest/http/options/Option.java | 21 ++++++++--- .../openunirest/http/options/Options.java | 37 ++++++++++++++----- .../openunirest/http/options/OptionsTest.java | 26 +++++++++++-- 4 files changed, 77 insertions(+), 19 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/Unirest.java b/src/main/java/io/github/openunirest/http/Unirest.java index e17f18e0a..337b66e0e 100644 --- a/src/main/java/io/github/openunirest/http/Unirest.java +++ b/src/main/java/io/github/openunirest/http/Unirest.java @@ -136,10 +136,18 @@ public static void setDefaultHeader(String name, String value) { /** * Close the asynchronous client and its event loop. Use this method to close all the threads and allow an application to exit. - * + * This will also clear any options returning Unirest to a default state */ public static void shutdown() { - Options.shutDown(); + shutdown(true); + } + + /** + * Close the asynchronous client and its event loop. Use this method to close all the threads and allow an application to exit. + * @param clearOptions indicates if options should be cleared. Note that the HttpClient, AsyncClient and thread monitors will not be retained after shutdown. + */ + public static void shutdown(boolean clearOptions) { + Options.shutDown(clearOptions); } public static GetRequest get(String url) { diff --git a/src/main/java/io/github/openunirest/http/options/Option.java b/src/main/java/io/github/openunirest/http/options/Option.java index 4541f39a3..5f8504b59 100644 --- a/src/main/java/io/github/openunirest/http/options/Option.java +++ b/src/main/java/io/github/openunirest/http/options/Option.java @@ -1,17 +1,28 @@ package io.github.openunirest.http.options; public enum Option { - HTTPCLIENT, - ASYNCHTTPCLIENT, + HTTPCLIENT(false), + ASYNCHTTPCLIENT(false), CONNECTION_TIMEOUT, SOCKET_TIMEOUT, DEFAULT_HEADERS, - SYNC_MONITOR, - ASYNC_MONITOR, + SYNC_MONITOR(false), + ASYNC_MONITOR(false), MAX_TOTAL, MAX_PER_ROUTE, PROXY, OBJECT_MAPPER, FOLLOW_REDIRECTS, - COOKIE_MANAGEMENT + COOKIE_MANAGEMENT; + + private final boolean canSurviveShutdown; + + Option(){this(true);} + Option(boolean canSurviveShutdown){ + this.canSurviveShutdown = canSurviveShutdown; + } + + public boolean canSurviveShutdown() { + return canSurviveShutdown; + } } diff --git a/src/main/java/io/github/openunirest/http/options/Options.java b/src/main/java/io/github/openunirest/http/options/Options.java index 71ab7c0bc..5f24412da 100644 --- a/src/main/java/io/github/openunirest/http/options/Options.java +++ b/src/main/java/io/github/openunirest/http/options/Options.java @@ -39,6 +39,11 @@ public static void customClientSet() { customClientSet = true; } + private static void setIfAbsent(Option option, Object value) { + validateOption(option); + options.putIfAbsent(option, value); + } + public static void setOption(Option option, Object value) { validateOption(option); options.put(option, value); @@ -167,13 +172,11 @@ public static void init() { private static void setDefaults() { customClientSet = false; - options.clear(); - setOption(Option.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT); - setOption(Option.SOCKET_TIMEOUT, SOCKET_TIMEOUT); - setOption(Option.MAX_TOTAL, MAX_TOTAL); - setOption(Option.MAX_PER_ROUTE, MAX_PER_ROUTE); - setOption(Option.SYNC_MONITOR, defaultSyncMonitor); - interceptors.clear(); + setIfAbsent(Option.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT); + setIfAbsent(Option.SOCKET_TIMEOUT, SOCKET_TIMEOUT); + setIfAbsent(Option.MAX_TOTAL, MAX_TOTAL); + setIfAbsent(Option.MAX_PER_ROUTE, MAX_PER_ROUTE); + setIfAbsent(Option.SYNC_MONITOR, defaultSyncMonitor); } public static Optional tryGet(Option option, Class as) { @@ -192,24 +195,36 @@ public static boolean isRunning() { return isRunning; } - public static void shutDown() { + public static void shutDown(){ + shutDown(true); + } + + public static void shutDown(boolean clearOptions) { tryGet(Option.HTTPCLIENT, CloseableHttpClient.class) .ifPresent(Options::closeIt); + options.remove(Option.HTTPCLIENT); tryGet(Option.SYNC_MONITOR, SyncIdleConnectionMonitorThread.class) .ifPresent(Thread::interrupt); + options.remove(Option.SYNC_MONITOR); tryGet(Option.ASYNCHTTPCLIENT, CloseableHttpAsyncClient.class) .filter(CloseableHttpAsyncClient::isRunning) .ifPresent(Options::closeIt); + options.remove(Option.ASYNCHTTPCLIENT); tryGet(Option.ASYNC_MONITOR, AsyncIdleConnectionMonitorThread.class) .ifPresent(Thread::interrupt); - + options.remove(Option.ASYNC_MONITOR); + + if(clearOptions){ + options.clear(); + interceptors.clear(); + } isRunning = false; } @@ -235,4 +250,8 @@ public static void enableCookieManagement(boolean enable){ options.put(COOKIE_MANAGEMENT, enable); refresh(); } + + public static List getInterceptors() { + return interceptors; + } } diff --git a/src/test/java/io/github/openunirest/http/options/OptionsTest.java b/src/test/java/io/github/openunirest/http/options/OptionsTest.java index d5eee5a5c..44d22ccbd 100644 --- a/src/test/java/io/github/openunirest/http/options/OptionsTest.java +++ b/src/test/java/io/github/openunirest/http/options/OptionsTest.java @@ -1,5 +1,8 @@ package io.github.openunirest.http.options; +import org.apache.http.HttpRequestInterceptor; +import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; +import org.junit.After; import util.JacksonObjectMapper; import io.github.openunirest.http.ObjectMapper; import org.junit.Before; @@ -8,20 +11,22 @@ import java.lang.management.ManagementFactory; import java.util.stream.IntStream; +import static io.github.openunirest.http.options.Option.CONNECTION_TIMEOUT; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.lessThan; import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; public class OptionsTest { - @Before + @Before @After public void before(){ - Options.init(); + Options.shutDown(true); } @Test public void shouldKeepConnectionTimeOutDefault(){ - assertOpDefault(Options.CONNECTION_TIMEOUT, Option.CONNECTION_TIMEOUT, 4L); + assertOpDefault(Options.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT, 4L); } @Test @@ -56,6 +61,21 @@ public void canTryGet(){ assertEquals(value, Options.tryGet(Option.OBJECT_MAPPER, ObjectMapper.class).get()); } + @Test + public void canSaveSomeOptions(){ + HttpRequestInterceptor i = mock(HttpRequestInterceptor.class); + CloseableHttpAsyncClient c = mock(CloseableHttpAsyncClient.class); + Options.addInterceptor(i); + Options.setOption(Option.ASYNCHTTPCLIENT, c); + Options.setOption(CONNECTION_TIMEOUT, 4000); + + Options.shutDown(false); + + assertNotEquals(c, Options.getOption(Option.ASYNCHTTPCLIENT)); + assertEquals(i, Options.getInterceptors().get(0)); + assertEquals(4000, Options.getOption(CONNECTION_TIMEOUT)); + } + private void assertOpDefault(Object defValue, Option option, Object newValue) { assertEquals(defValue, Options.getOption(option)); Options.setOption(option, newValue); From c351a790a990397cd6b484e065ec035d96b3cadb Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 23 Aug 2018 06:41:07 -0500 Subject: [PATCH 0186/1769] [maven-release-plugin] prepare release v2.2.12 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index bb1912f3c..c94692959 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.12-SNAPSHOT + 2.2.12 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.2.12 From 1c620ccb94e6ba9b498a577da7683128383b3bc8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 23 Aug 2018 06:41:16 -0500 Subject: [PATCH 0187/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c94692959..85da1e4e6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.12 + 2.2.13-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.2.12 + HEAD From 07c45e3e461b4caa9d7646d797b7c0e2d2c88d28 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 23 Aug 2018 06:55:49 -0500 Subject: [PATCH 0188/1769] update docs --- CHANGELOG.md | 3 +++ README.md | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07f2e65a6..df1b5d748 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.2.12 +* Add optional flag overload to ```Unirest.shutDown(false)```. The flag indicates if the various Options should be cleared. This only applies to options that could survive a shutdown. The HttpClients and thread monitors will still be discarded. + ## 2.2.11 * Change default MultiPart mode to BROWSER_COMPATIBLE in order to support unicode filenames. Clients wishing to use the legacy mode can set it to STRICT. This should not be a problem for most users as few servers today lack support for unicode file names. Issue #35 diff --git a/README.md b/README.md index c68b04b9d..efda81a37 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ There are several such forks in the world. The guiding principals of this projec io.github.openunirest unirest-java - 2.2.11 + 2.2.12 ``` From c9a9cefac2c383fb41d07aaa7750fba1cd07bae0 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 5 Sep 2018 20:53:37 -0500 Subject: [PATCH 0189/1769] add support for JSON patch RFC6902 --- pom.xml | 6 + .../io/github/openunirest/http/Unirest.java | 5 + .../github/openunirest/request/JsonPatch.java | 60 ++++++++ .../openunirest/request/JsonPatchItem.java | 71 ++++++++++ .../request/JsonPatchOperation.java | 21 +++ .../openunirest/request/JsonPatchRequest.java | 61 ++++++++ src/test/java/BehaviorTests/BddTest.java | 1 - .../java/BehaviorTests/JsonPatchTest.java | 132 ++++++++++++++++++ src/test/java/BehaviorTests/MockServer.java | 2 +- .../java/BehaviorTests/RequestCapture.java | 34 ++++- .../openunirest/http/JacksonObjectMapper.java | 86 ++++++++++++ .../http/JacksonObjectMapperTest.java | 41 ++++++ .../openunirest/http/options/OptionsTest.java | 2 +- .../request/ResponseBuilderTest.java | 2 +- src/test/java/util/JacksonObjectMapper.java | 41 ------ 15 files changed, 513 insertions(+), 52 deletions(-) create mode 100644 src/main/java/io/github/openunirest/request/JsonPatch.java create mode 100644 src/main/java/io/github/openunirest/request/JsonPatchItem.java create mode 100644 src/main/java/io/github/openunirest/request/JsonPatchOperation.java create mode 100644 src/main/java/io/github/openunirest/request/JsonPatchRequest.java create mode 100644 src/test/java/BehaviorTests/JsonPatchTest.java create mode 100644 src/test/java/io/github/openunirest/http/JacksonObjectMapper.java create mode 100644 src/test/java/io/github/openunirest/http/JacksonObjectMapperTest.java delete mode 100644 src/test/java/util/JacksonObjectMapper.java diff --git a/pom.xml b/pom.xml index 85da1e4e6..95873f197 100644 --- a/pom.xml +++ b/pom.xml @@ -301,5 +301,11 @@ 2.6.0 test + + org.skyscreamer + jsonassert + 1.5.0 + test + diff --git a/src/main/java/io/github/openunirest/http/Unirest.java b/src/main/java/io/github/openunirest/http/Unirest.java index 337b66e0e..ae20e586a 100644 --- a/src/main/java/io/github/openunirest/http/Unirest.java +++ b/src/main/java/io/github/openunirest/http/Unirest.java @@ -30,6 +30,7 @@ a copy of this software and associated documentation files (the import io.github.openunirest.http.options.Options; import io.github.openunirest.request.GetRequest; import io.github.openunirest.request.HttpRequestWithBody; +import io.github.openunirest.request.JsonPatchRequest; import org.apache.http.HttpHost; import org.apache.http.client.HttpClient; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; @@ -178,6 +179,10 @@ public static HttpRequestWithBody put(String url) { return new HttpRequestWithBody(HttpMethod.PUT, url); } + public static JsonPatchRequest jsonPatch(String url) { + return new JsonPatchRequest(url); + } + public static boolean isRunning() { return Options.isRunning(); } diff --git a/src/main/java/io/github/openunirest/request/JsonPatch.java b/src/main/java/io/github/openunirest/request/JsonPatch.java new file mode 100644 index 000000000..4674f5656 --- /dev/null +++ b/src/main/java/io/github/openunirest/request/JsonPatch.java @@ -0,0 +1,60 @@ +package io.github.openunirest.request; + +import org.json.JSONArray; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static io.github.openunirest.request.JsonPatchOperation.*; + +public class JsonPatch { + + private List items = new ArrayList<>(); + + public JsonPatch(){} + + public JsonPatch(String fromString){ + for (Object row : new JSONArray(fromString)) { + if(row instanceof JSONObject){ + items.add(new JsonPatchItem((JSONObject)row)); + } + } + } + + public void add(String path, Object value) { + items.add(new JsonPatchItem(add, path, value)); + } + + public void remove(String path) { + items.add(new JsonPatchItem(remove, path)); + } + + public void replace(String path, Object value) { + items.add(new JsonPatchItem(replace, path, value)); + } + + public void test(String path, Object value) { + items.add(new JsonPatchItem(test, path, value)); + } + + public void move(String from, String path) { + items.add(new JsonPatchItem(move, path, from)); + } + + public void copy(String from, String path) { + items.add(new JsonPatchItem(copy, path, from)); + } + + @Override + public String toString() { + JSONArray a = new JSONArray(); + items.forEach(i -> a.put(new JSONObject(i.toString()))); + return a.toString(); + } + + public Iterable getOperations(){ + return Collections.unmodifiableList(items); + } +} \ No newline at end of file diff --git a/src/main/java/io/github/openunirest/request/JsonPatchItem.java b/src/main/java/io/github/openunirest/request/JsonPatchItem.java new file mode 100644 index 000000000..577d82e39 --- /dev/null +++ b/src/main/java/io/github/openunirest/request/JsonPatchItem.java @@ -0,0 +1,71 @@ +package io.github.openunirest.request; + +import org.json.JSONObject; + +import java.util.Objects; + +public class JsonPatchItem { + private final JsonPatchOperation op; + private final String path; + private final Object value; + + public JsonPatchItem(JsonPatchOperation op, String path, Object value){ + this.op = op; + this.path = path; + this.value = value; + } + + public JsonPatchItem(JsonPatchOperation remove, String path) { + this(remove, path, null); + } + + public JsonPatchItem(JSONObject row) { + this.op = JsonPatchOperation.valueOf(row.getString("op")); + this.path = row.getString("path"); + if(row.has(op.getOperationtype())) { + this.value = row.get(op.getOperationtype()); + } else { + this.value = null; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) {return true;} + if (o == null || getClass() != o.getClass()) {return false;} + JsonPatchItem that = (JsonPatchItem) o; + return op == that.op && + Objects.equals(path, that.path) && + Objects.equals(toString(), that.toString()); + } + + @Override + public int hashCode() { + return Objects.hash(op, path, value); + } + + @Override + public String toString() { + JSONObject json = new JSONObject() + .put("op", op) + .put("path", path); + + if(Objects.nonNull(value)){ + json.put(op.getOperationtype(), value); + } + + return json.toString(); + } + + public JsonPatchOperation getOp() { + return op; + } + + public String getPath() { + return path; + } + + public Object getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/io/github/openunirest/request/JsonPatchOperation.java b/src/main/java/io/github/openunirest/request/JsonPatchOperation.java new file mode 100644 index 000000000..250919cc7 --- /dev/null +++ b/src/main/java/io/github/openunirest/request/JsonPatchOperation.java @@ -0,0 +1,21 @@ +package io.github.openunirest.request; + +public enum JsonPatchOperation { + add("value"), + remove("value"), + replace("value"), + test("value"), + move("from"), + copy("from"); + + private final String operationtype; + + JsonPatchOperation(String operationtype) { + + this.operationtype = operationtype; + } + + public String getOperationtype() { + return operationtype; + } +} diff --git a/src/main/java/io/github/openunirest/request/JsonPatchRequest.java b/src/main/java/io/github/openunirest/request/JsonPatchRequest.java new file mode 100644 index 000000000..1f76cbf8f --- /dev/null +++ b/src/main/java/io/github/openunirest/request/JsonPatchRequest.java @@ -0,0 +1,61 @@ +package io.github.openunirest.request; + + +import io.github.openunirest.http.HttpMethod; +import io.github.openunirest.request.body.Body; +import org.apache.http.HttpEntity; +import org.apache.http.entity.BasicHttpEntity; + +import java.io.ByteArrayInputStream; + +public class JsonPatchRequest extends HttpRequest implements Body { + public static final String CONTENT_TYPE = "application/json-patch+json"; + private JsonPatch items = new JsonPatch(); + + public JsonPatchRequest(String url) { + super(HttpMethod.PATCH, url); + header("Content-Type", CONTENT_TYPE); + } + + public JsonPatchRequest add(String path, Object value) { + items.add(path, value); + return this; + } + + public JsonPatchRequest remove(String path) { + items.remove(path); + return this; + } + + public JsonPatchRequest replace(String path, Object value) { + items.replace(path, value); + return this; + } + + public JsonPatchRequest test(String path, Object value) { + items.test(path, value); + return this; + } + + public JsonPatchRequest move(String from, String path) { + items.move(from, path); + return this; + } + + public JsonPatchRequest copy(String from, String path) { + items.copy(from, path); + return this; + } + + @Override + public Body getBody() { + return this; + } + + @Override + public HttpEntity getEntity() { + BasicHttpEntity e = new BasicHttpEntity(); + e.setContent(new ByteArrayInputStream(items.toString().getBytes())); + return e; + } +} \ No newline at end of file diff --git a/src/test/java/BehaviorTests/BddTest.java b/src/test/java/BehaviorTests/BddTest.java index b25e9e201..41713dbfa 100644 --- a/src/test/java/BehaviorTests/BddTest.java +++ b/src/test/java/BehaviorTests/BddTest.java @@ -3,7 +3,6 @@ import io.github.openunirest.http.*; import io.github.openunirest.http.options.Options; import org.junit.Before; -import util.JacksonObjectMapper; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; diff --git a/src/test/java/BehaviorTests/JsonPatchTest.java b/src/test/java/BehaviorTests/JsonPatchTest.java new file mode 100644 index 000000000..86870928c --- /dev/null +++ b/src/test/java/BehaviorTests/JsonPatchTest.java @@ -0,0 +1,132 @@ +package BehaviorTests; + +import com.google.common.collect.ImmutableMap; +import io.github.openunirest.http.Unirest; +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.Test; + +import static io.github.openunirest.request.JsonPatchOperation.*; + +public class JsonPatchTest extends BddTest { + + @Test + public void canAddThings() { + Unirest.jsonPatch(MockServer.PATCH) + .add("/some/path", "a value") + .add("/another/path", 42) + .add("/third/path", true) + .asObject(RequestCapture.class) + .getBody() + .assertJsonPatch(add, "/some/path", "a value") + .assertJsonPatch(add, "/another/path", 42) + .assertJsonPatch(add, "/third/path", true); + } + + @Test + public void canRemoveThings() { + Unirest.jsonPatch(MockServer.PATCH) + .remove("/some/path") + .remove("/another/path") + .remove("/third/path") + .asObject(RequestCapture.class) + .getBody() + .assertJsonPatch(remove, "/some/path", null) + .assertJsonPatch(remove, "/another/path", null) + .assertJsonPatch(remove, "/third/path", null); + } + + @Test + public void canReplaceThings() { + Unirest.jsonPatch(MockServer.PATCH) + .replace("/some/path", "a value") + .replace("/another/path", 42) + .replace("/third/path", true) + .asObject(RequestCapture.class) + .getBody() + .assertJsonPatch(replace, "/some/path", "a value") + .assertJsonPatch(replace, "/another/path", 42) + .assertJsonPatch(replace, "/third/path", true); + } + + @Test + public void canTestThings() { + Unirest.jsonPatch(MockServer.PATCH) + .test("/some/path", "a value") + .test("/another/path", 42) + .test("/third/path", true) + .asObject(RequestCapture.class) + .getBody() + .assertJsonPatch(test, "/some/path", "a value") + .assertJsonPatch(test, "/another/path", 42) + .assertJsonPatch(test, "/third/path", true); + } + + @Test + public void canUseJsonForValues() { + Unirest.jsonPatch(MockServer.PATCH) + .add("/some/path", new JSONObject().put("id", "foo")) + .asObject(RequestCapture.class) + .getBody() + .assertJsonPatch(add, "/some/path", new JSONObject().put("id", "foo")); + } + + @Test + public void lotsOfDifferentWaysToMakeObjects() { + JSONObject basicJson = new JSONObject().put("foo", "bar"); + + Unirest.jsonPatch(MockServer.PATCH) + .add("/stringArrays", new String[]{"foo, bar"}) + .add("/maps", ImmutableMap.of("foo", "bar")) + .add("/jsonObjects", basicJson) + .add("/jsonArrays", new JSONArray().put(basicJson)) + .asObject(RequestCapture.class) + .getBody() + .assertJsonPatch(add, "/stringArrays", new String[]{"foo, bar"}) + .assertJsonPatch(add, "/maps", basicJson) + .assertJsonPatch(add, "/jsonObjects", basicJson) + .assertJsonPatch(add, "/jsonArrays", new JSONArray().put(basicJson)) + ; + } + + @Test + public void canMoveObjects() { + Unirest.jsonPatch(MockServer.PATCH) + .move("/old/location", "/new/location") + .asObject(RequestCapture.class) + .getBody() + .assertJsonPatch(move, "/new/location", "/old/location"); + } + + @Test + public void canCopyObjects() { + Unirest.jsonPatch(MockServer.PATCH) + .copy("/old/location", "/new/location") + .asObject(RequestCapture.class) + .getBody() + .assertJsonPatch(copy, "/new/location", "/old/location"); + } + + @Test + public void allTogetherNow() { + Unirest.jsonPatch(MockServer.PATCH) + .add("/fruits/-", "Apple") + .remove("/bugs") + .replace("/lastname", "Flintsone") + .test("/firstname", "Fred") + .move("/old/location", "/new/location") + .copy("/original/location", "/new/location") + .asString(); + + /* This produces + [ + {"op":"add","path":"/fruits/-","value":"Apple"}, + {"op":"remove","path":"/bugs"}, + {"op":"replace","path":"/lastname","value":"Flintsone"}, + {"op":"test","path":"/firstname","value":"Fred"}, + {"op":"move","path":"/new/location","from":"/old/location"}, + {"op":"copy","path":"/new/location","from":"/original/location"} + ] + */ + } +} diff --git a/src/test/java/BehaviorTests/MockServer.java b/src/test/java/BehaviorTests/MockServer.java index ae6aea82e..21aefd9c5 100644 --- a/src/test/java/BehaviorTests/MockServer.java +++ b/src/test/java/BehaviorTests/MockServer.java @@ -26,7 +26,7 @@ a copy of this software and associated documentation files (the package BehaviorTests; -import util.JacksonObjectMapper; +import io.github.openunirest.http.JacksonObjectMapper; import spark.Request; import spark.Response; import spark.Spark; diff --git a/src/test/java/BehaviorTests/RequestCapture.java b/src/test/java/BehaviorTests/RequestCapture.java index 69fb03d65..f2b6c7a6a 100644 --- a/src/test/java/BehaviorTests/RequestCapture.java +++ b/src/test/java/BehaviorTests/RequestCapture.java @@ -4,8 +4,10 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import com.google.common.collect.Sets; -import io.github.openunirest.http.HttpMethod; -import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.*; +import io.github.openunirest.request.JsonPatch; +import io.github.openunirest.request.JsonPatchItem; +import io.github.openunirest.request.JsonPatchOperation; import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.entity.ContentType; import spark.Request; @@ -19,6 +21,7 @@ import java.util.*; import java.util.stream.Collectors; +import static io.github.openunirest.request.JsonPatchRequest.CONTENT_TYPE; import static java.lang.System.getProperty; import static org.hamcrest.CoreMatchers.endsWith; import static org.hamcrest.CoreMatchers.hasItem; @@ -34,6 +37,7 @@ public class RequestCapture { public HttpMethod method; public String param; public String contentType; + public JsonPatch jsonPatches; public RequestCapture() { } @@ -49,8 +53,14 @@ public RequestCapture(Request req) { } public void writeBody(Request req) { - //parseBodyToFormParams(req); - writeMultipart(req); + if(Strings.nullToEmpty(req.contentType()).equals(CONTENT_TYPE)){ + String body = req.body(); + jsonPatches = new JsonPatch(body); + this.body = jsonPatches.toString(); + } else { + //parseBodyToFormParams(req); + writeMultipart(req); + } } private void parseBodyToFormParams() { @@ -131,7 +141,7 @@ public File getFile(String fileName) { .filter(f -> Objects.equals(f.fileName, fileName)) .findFirst() .orElseThrow(() -> new RuntimeException("\nNo File With Name: " + fileName + "\n" - + "Found: " + files.stream().map(f -> f.fileName).collect(Collectors.joining(" ")))); + + "Found: " + files.stream().map(f -> f.fileName).collect(Collectors.joining(" ")))); } public File getFileByInput(String input) { @@ -165,14 +175,24 @@ public RequestCapture assertPathParam(String value) { } public RequestCapture assertUrl(String s) { - assertEquals(s, url); - return this; + assertEquals(s, url); + return this; } public void assertCharset(Charset charset) { assertThat(contentType, endsWith(charset.toString())); } + public RequestCapture assertJsonPatch(JsonPatchOperation op, String path, Object value) { + assertNotNull("Asserting JSONPatch but no patch object present", jsonPatches); + assertThat(jsonPatches.getOperations(), hasItem(new JsonPatchItem(op, path, value))); + return this; + } + + public void setPatch(JsonPatch patch) { + this.jsonPatches = patch; + } + public static class File { public String fileName; public String type; diff --git a/src/test/java/io/github/openunirest/http/JacksonObjectMapper.java b/src/test/java/io/github/openunirest/http/JacksonObjectMapper.java new file mode 100644 index 000000000..ec9e8ff47 --- /dev/null +++ b/src/test/java/io/github/openunirest/http/JacksonObjectMapper.java @@ -0,0 +1,86 @@ +package io.github.openunirest.http; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.datatype.guava.GuavaModule; +import io.github.openunirest.request.JsonPatch; +import io.github.openunirest.request.JsonPatchItem; +import org.json.JSONObject; + +import java.io.IOException; +import java.io.InputStream; + +public class JacksonObjectMapper implements ObjectMapper { + + private com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper(); + + public JacksonObjectMapper(){ + om.registerModule(new GuavaModule()); + SimpleModule simpleModule = new SimpleModule(); + simpleModule.addSerializer(JsonPatchItem.class, new PatchSerializer()); + simpleModule.addSerializer(JsonPatch.class, new JsonPatchSerializer()); + simpleModule.addDeserializer(JsonPatchItem.class, new PatchDeserializer()); + simpleModule.addDeserializer(JsonPatch.class, new JsonPatchDeSerializer()); + om.registerModule(simpleModule); + } + + public T readValue(String value, Class valueType) { + try { + return om.readValue(value, valueType); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public String writeValue(Object value) { + try { + return om.writeValueAsString(value); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + public T readValue(InputStream rawBody, Class as) { + try { + return om.readValue(rawBody, as); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static class JsonPatchSerializer extends JsonSerializer{ + @Override + public void serialize(JsonPatch patch, JsonGenerator jgen, SerializerProvider serializerProvider) throws IOException { + jgen.writeRawValue(patch.toString()); + } + } + + public static class JsonPatchDeSerializer extends JsonDeserializer{ + @Override + public JsonPatch deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { + String s = jsonParser.readValueAsTree().toString(); + return new JsonPatch(s); + } + } + + public static class PatchSerializer extends JsonSerializer { + @Override + public void serialize(JsonPatchItem jwk, JsonGenerator jgen, SerializerProvider serializerProvider) throws IOException { + jgen.writeRaw(jwk.toString()); + } + } + + public static class PatchDeserializer extends JsonDeserializer { + @Override + public JsonPatchItem deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { + String s = jsonParser.readValueAsTree().toString(); + return new JsonPatchItem(new JSONObject(s)); + } + } +} diff --git a/src/test/java/io/github/openunirest/http/JacksonObjectMapperTest.java b/src/test/java/io/github/openunirest/http/JacksonObjectMapperTest.java new file mode 100644 index 000000000..cfc31fe60 --- /dev/null +++ b/src/test/java/io/github/openunirest/http/JacksonObjectMapperTest.java @@ -0,0 +1,41 @@ +package io.github.openunirest.http; + +import BehaviorTests.RequestCapture; +import io.github.openunirest.request.JsonPatch; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +public class JacksonObjectMapperTest { + + private JacksonObjectMapper om = new JacksonObjectMapper(); + + @Test + public void jsonPatch() { + JsonPatch patch = new JsonPatch(); + patch.add("/foo", "bar"); + patch.add("/baz", "qux"); + + String expectStr = patch.toString(); + String actualStr = om.writeValue(patch); + + JSONAssert.assertEquals(expectStr, + actualStr, + true); + } + + @Test + public void jsonPatchInRequestCapture() { + JsonPatch patch = new JsonPatch(); + patch.add("/foo", "bar"); + patch.add("/baz", "qux"); + + RequestCapture rc = new RequestCapture(); + rc.setPatch(patch); + + String actualStr = om.writeValue(rc); + System.out.println("actualStr = " + actualStr); + JSONAssert.assertEquals("{}", + actualStr, + false); + } +} \ No newline at end of file diff --git a/src/test/java/io/github/openunirest/http/options/OptionsTest.java b/src/test/java/io/github/openunirest/http/options/OptionsTest.java index 44d22ccbd..0bcd1d33d 100644 --- a/src/test/java/io/github/openunirest/http/options/OptionsTest.java +++ b/src/test/java/io/github/openunirest/http/options/OptionsTest.java @@ -1,9 +1,9 @@ package io.github.openunirest.http.options; +import io.github.openunirest.http.JacksonObjectMapper; import org.apache.http.HttpRequestInterceptor; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.junit.After; -import util.JacksonObjectMapper; import io.github.openunirest.http.ObjectMapper; import org.junit.Before; import org.junit.Test; diff --git a/src/test/java/io/github/openunirest/request/ResponseBuilderTest.java b/src/test/java/io/github/openunirest/request/ResponseBuilderTest.java index 7c6e3eefb..af6a15465 100644 --- a/src/test/java/io/github/openunirest/request/ResponseBuilderTest.java +++ b/src/test/java/io/github/openunirest/request/ResponseBuilderTest.java @@ -3,6 +3,7 @@ import BehaviorTests.Foo; import io.github.openunirest.MockApacheResponse; import io.github.openunirest.http.HttpResponse; +import io.github.openunirest.http.JacksonObjectMapper; import io.github.openunirest.http.JsonNode; import io.github.openunirest.http.exceptions.UnirestException; import io.github.openunirest.http.options.Option; @@ -11,7 +12,6 @@ import org.apache.http.message.BasicStatusLine; import org.junit.Before; import org.junit.Test; -import util.JacksonObjectMapper; import util.TestUtil; import java.io.InputStream; diff --git a/src/test/java/util/JacksonObjectMapper.java b/src/test/java/util/JacksonObjectMapper.java deleted file mode 100644 index 9647ae912..000000000 --- a/src/test/java/util/JacksonObjectMapper.java +++ /dev/null @@ -1,41 +0,0 @@ -package util; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.datatype.guava.GuavaModule; -import io.github.openunirest.http.ObjectMapper; - -import java.io.IOException; -import java.io.InputStream; - -public class JacksonObjectMapper implements ObjectMapper { - - private com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper(); - - public JacksonObjectMapper(){ - om.registerModule(new GuavaModule()); - } - - public T readValue(String value, Class valueType) { - try { - return om.readValue(value, valueType); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public String writeValue(Object value) { - try { - return om.writeValueAsString(value); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - } - - public T readValue(InputStream rawBody, Class as) { - try { - return om.readValue(rawBody, as); - } catch (IOException e) { - throw new RuntimeException(e); - } - } -} From 4572955a8356c332e7df12aa7c0080ae71643be0 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 5 Sep 2018 21:10:16 -0500 Subject: [PATCH 0190/1769] add support for JSON patch RFC6902 --- CHANGELOG.md | 13 ++++++++++ README.md | 25 +++++++++++++++++++ pom.xml | 2 +- .../java/BehaviorTests/JsonPatchTest.java | 2 +- 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df1b5d748..7dd747597 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +## 2.3.00 +* Add support for the JSON Patch standard (RFC6902) https://tools.ietf.org/html/rfc6902 +```java + Unirest.jsonPatch(MockServer.PATCH) + .add("/fruits/-", "Apple") + .remove("/bugs") + .replace("/lastname", "Flintsone") + .test("/firstname", "Fred") + .move("/old/location", "/new/location") + .copy("/original/location", "/new/location") + .asJson(); +``` + ## 2.2.12 * Add optional flag overload to ```Unirest.shutDown(false)```. The flag indicates if the various Options should be cleared. This only applies to options that could survive a shutdown. The HttpClients and thread monitors will still be discarded. diff --git a/README.md b/README.md index efda81a37..f4515f74f 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,31 @@ If you already have a map of parameters or do not wish to use seperate field met `.headers(Map headers)` is also supported in replacement of multiple header methods. +## JSON Patch Requests +Unirest has full native support for JSON Patch requests +```java + Unirest.jsonPatch(MockServer.PATCH) + .add("/fruits/-", "Apple") + .remove("/bugs") + .replace("/lastname", "Flintsone") + .test("/firstname", "Fred") + .move("/old/location", "/new/location") + .copy("/original/location", "/new/location") + .asJson(); +``` +will send a request with a body of +```json + [ + {"op":"add","path":"/fruits/-","value":"Apple"}, + {"op":"remove","path":"/bugs"}, + {"op":"replace","path":"/lastname","value":"Flintsone"}, + {"op":"test","path":"/firstname","value":"Fred"}, + {"op":"move","path":"/new/location","from":"/old/location"}, + {"op":"copy","path":"/new/location","from":"/original/location"} + ] + +``` + ## Serialization Before an `asObject(Class)` or a `.body(Object)` invokation, is necessary to provide a custom implementation of the `ObjectMapper` interface. This should be done only the first time, as the instance of the ObjectMapper will be shared globally. diff --git a/pom.xml b/pom.xml index 95873f197..014df311f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.2.13-SNAPSHOT + 2.3.00-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ diff --git a/src/test/java/BehaviorTests/JsonPatchTest.java b/src/test/java/BehaviorTests/JsonPatchTest.java index 86870928c..c8156152c 100644 --- a/src/test/java/BehaviorTests/JsonPatchTest.java +++ b/src/test/java/BehaviorTests/JsonPatchTest.java @@ -116,7 +116,7 @@ public void allTogetherNow() { .test("/firstname", "Fred") .move("/old/location", "/new/location") .copy("/original/location", "/new/location") - .asString(); + .asJson(); /* This produces [ From 710cb34bb2662c19267f5b4329eca7446d04d182 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 5 Sep 2018 21:12:56 -0500 Subject: [PATCH 0191/1769] [maven-release-plugin] prepare release v2.3.00 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 014df311f..312509234 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.3.00-SNAPSHOT + 2.3.00 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.3.00 From 5699737913a5b63cb4782b590217d30a4628618b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 5 Sep 2018 21:13:07 -0500 Subject: [PATCH 0192/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 312509234..99e3cd421 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.3.00 + 2.3.01-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.3.00 + HEAD From 55c4b7c843d59be2436ccc240d95b552ac5a8cec Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 5 Sep 2018 21:20:56 -0500 Subject: [PATCH 0193/1769] more documentation --- README.md | 6 +++--- src/test/java/BehaviorTests/JsonPatchTest.java | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f4515f74f..a1600ba30 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ There are several such forks in the world. The guiding principals of this projec io.github.openunirest unirest-java - 2.2.12 + 2.3.00 ``` @@ -62,7 +62,7 @@ Unirest has full native support for JSON Patch requests Unirest.jsonPatch(MockServer.PATCH) .add("/fruits/-", "Apple") .remove("/bugs") - .replace("/lastname", "Flintsone") + .replace("/lastname", "Flintstone") .test("/firstname", "Fred") .move("/old/location", "/new/location") .copy("/original/location", "/new/location") @@ -73,7 +73,7 @@ will send a request with a body of [ {"op":"add","path":"/fruits/-","value":"Apple"}, {"op":"remove","path":"/bugs"}, - {"op":"replace","path":"/lastname","value":"Flintsone"}, + {"op":"replace","path":"/lastname","value":"Flintstone"}, {"op":"test","path":"/firstname","value":"Fred"}, {"op":"move","path":"/new/location","from":"/old/location"}, {"op":"copy","path":"/new/location","from":"/original/location"} diff --git a/src/test/java/BehaviorTests/JsonPatchTest.java b/src/test/java/BehaviorTests/JsonPatchTest.java index c8156152c..4ce663853 100644 --- a/src/test/java/BehaviorTests/JsonPatchTest.java +++ b/src/test/java/BehaviorTests/JsonPatchTest.java @@ -112,17 +112,16 @@ public void allTogetherNow() { Unirest.jsonPatch(MockServer.PATCH) .add("/fruits/-", "Apple") .remove("/bugs") - .replace("/lastname", "Flintsone") + .replace("/lastname", "Flintstone") .test("/firstname", "Fred") .move("/old/location", "/new/location") .copy("/original/location", "/new/location") .asJson(); - - /* This produces + /* resulting body [ {"op":"add","path":"/fruits/-","value":"Apple"}, {"op":"remove","path":"/bugs"}, - {"op":"replace","path":"/lastname","value":"Flintsone"}, + {"op":"replace","path":"/lastname","value":"Flintstone"}, {"op":"test","path":"/firstname","value":"Fred"}, {"op":"move","path":"/new/location","from":"/old/location"}, {"op":"copy","path":"/new/location","from":"/original/location"} From 45f02f1d7a51b5cbe3055fb5ff6f6ea8b6031bd2 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 6 Sep 2018 07:18:43 -0500 Subject: [PATCH 0194/1769] start cleaning up the documentation --- README.md | 88 ++++++------------- .../java/BehaviorTests/JsonPatchTest.java | 2 +- 2 files changed, 27 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index a1600ba30..541187549 100644 --- a/README.md +++ b/README.md @@ -40,12 +40,12 @@ There are several such forks in the world. The guiding principals of this projec So you're probably wondering how using Unirest makes creating requests in Java easier, here is a basic POST request that will explain everything: ```java -HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") - .header("accept", "application/json") - .queryString("apiKey", "123") - .field("parameter", "value") - .field("foo", "bar") - .asJson(); +HttpResponse response = Unirest.post("http://httpbin.org/post") + .header("accept", "application/json") + .queryString("apiKey", "123") + .field("parameter", "value") + .field("foo", "bar") + .asJson(); ``` Requests are made when `as[Type]()` is invoked, possible types include `Json`, `Binary`, `String`, `Object`. @@ -81,7 +81,7 @@ will send a request with a body of ``` -## Serialization +## Advanced Object Mapping with Jackson, GSON, JAX-B or others Before an `asObject(Class)` or a `.body(Object)` invokation, is necessary to provide a custom implementation of the `ObjectMapper` interface. This should be done only the first time, as the instance of the ObjectMapper will be shared globally. @@ -111,25 +111,24 @@ Unirest.setObjectMapper(new ObjectMapper() { }); // Response to Object -HttpResponse bookResponse = Unirest.get("http://httpbin.org/books/1").asObject(Book.class); -Book bookObject = bookResponse.getBody(); +Book book = Unirest.get("http://httpbin.org/books/1") + .asObject(Book.class) + .getBody(); -HttpResponse authorResponse = Unirest.get("http://httpbin.org/books/{id}/author") - .routeParam("id", bookObject.getId()) - .asObject(Author.class); - -Author authorObject = authorResponse.getBody(); +Author author = Unirest.get("http://httpbin.org/books/{id}/author") + .routeParam("id", bookObject.getId()) + .asObject(Author.class) + .getBody(); -// Object to Json -HttpResponse postResponse = Unirest.post("http://httpbin.org/authors/post") +// Sending a JSON object +Unirest.post("http://httpbin.org/authors/post") .header("accept", "application/json") .header("Content-Type", "application/json") - .body(authorObject) + .body(author) .asJson(); ``` ### Route Parameters - Sometimes you want to add dynamic parameters in the URL, you can easily do that by adding a placeholder in the URL, and then by setting the route parameters with the `routeParam` function, like: ```java @@ -150,24 +149,12 @@ CompletableFuture> future = Unirest.post("http://httpbin. .header("accept", "application/json") .field("param1", "value1") .field("param2", "value2") - .asJsonAsync(new Callback() { - - public void failed(UnirestException e) { - System.out.println("The request has failed"); - } - - public void completed(HttpResponse response) { - int code = response.getStatus(); - Map headers = response.getHeaders(); - JsonNode body = response.getBody(); - InputStream rawBody = response.getRawBody(); - } - - public void cancelled() { - System.out.println("The request has been cancelled"); - } - -}); + .asJsonAsync(response -> { + int code = response.getStatus(); + Map headers = response.getHeaders(); + JsonNode body = response.getBody(); + InputStream rawBody = response.getRawBody(); + }); ``` ## File Uploads @@ -215,34 +202,11 @@ HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") ## Basic Authentication Authenticating the request with basic authentication can be done by calling the `basicAuth(username, password)` function: ```java -HttpResponse response = Unirest.get("http://httpbin.org/headers").basicAuth("username", "password").asJson(); -``` - -# Request - -The Java Unirest library follows the builder style conventions. You start building your request by creating a `HttpRequest` object using one of the following: - -```java -GetRequest request = Unirest.get(String url); -GetRequest request = Unirest.head(String url); -HttpRequestWithBody request = Unirest.post(String url); -HttpRequestWithBody request = Unirest.put(String url); -HttpRequestWithBody request = Unirest.patch(String url); -HttpRequestWithBody request = Unirest.options(String url); -HttpRequestWithBody request = Unirest.delete(String url); + Unirest.get("http://httpbin.org/headers") + .basicAuth("username", "password") + .asJson(); ``` -# Response - -Upon recieving a response Unirest returns the result in the form of an Object, this object should always have the same keys for each language regarding to the response details. - -- `.getStatus()` - HTTP Response Status Code (Example: 200) -- `.getStatusText()` - HTTP Response Status Text (Example: "OK") -- `.getHeaders()` - HTTP Response Headers -- `.getBody()` - Parsed response body where applicable, for example JSON responses are parsed to Objects / Associative Arrays. -- `.getRawBody()` - Un-parsed response body -- `.getParsingError()` - Optional RuntimeException containing the error that was thrown when parsing the response body - # Advanced Configuration You can set some advanced configuration to tune Unirest-Java: diff --git a/src/test/java/BehaviorTests/JsonPatchTest.java b/src/test/java/BehaviorTests/JsonPatchTest.java index 4ce663853..9cbf256aa 100644 --- a/src/test/java/BehaviorTests/JsonPatchTest.java +++ b/src/test/java/BehaviorTests/JsonPatchTest.java @@ -109,7 +109,7 @@ public void canCopyObjects() { @Test public void allTogetherNow() { - Unirest.jsonPatch(MockServer.PATCH) + Unirest.jsonPatch("http://localhost/thing") .add("/fruits/-", "Apple") .remove("/bugs") .replace("/lastname", "Flintstone") From aeb7df8fc8a7d1e8fd653c003d14cdefe3f34cd6 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 9 Sep 2018 07:53:37 -0500 Subject: [PATCH 0195/1769] add support for generic types --- pom.xml | 6 ++ .../github/openunirest/http/ObjectMapper.java | 8 +- .../openunirest/request/BaseRequest.java | 9 ++- .../openunirest/request/GenericType.java | 25 ++++++ .../openunirest/request/ResponseBuilder.java | 9 +++ .../java/BehaviorTests/AsGenericTypeTest.java | 81 +++++++++++++++++++ src/test/java/BehaviorTests/Foo.java | 7 ++ src/test/java/BehaviorTests/MockServer.java | 1 + .../openunirest/http/GsonObjectMapper.java | 24 ++++++ .../openunirest/http/JacksonObjectMapper.java | 12 +++ 10 files changed, 176 insertions(+), 6 deletions(-) create mode 100644 src/main/java/io/github/openunirest/request/GenericType.java create mode 100644 src/test/java/BehaviorTests/AsGenericTypeTest.java create mode 100644 src/test/java/io/github/openunirest/http/GsonObjectMapper.java diff --git a/pom.xml b/pom.xml index 99e3cd421..d15ba0ffe 100644 --- a/pom.xml +++ b/pom.xml @@ -307,5 +307,11 @@ 1.5.0 test + + com.google.code.gson + gson + 2.8.1 + test + diff --git a/src/main/java/io/github/openunirest/http/ObjectMapper.java b/src/main/java/io/github/openunirest/http/ObjectMapper.java index a1a58809d..11e7cb10a 100644 --- a/src/main/java/io/github/openunirest/http/ObjectMapper.java +++ b/src/main/java/io/github/openunirest/http/ObjectMapper.java @@ -1,8 +1,12 @@ package io.github.openunirest.http; -public interface ObjectMapper { +import io.github.openunirest.http.exceptions.UnirestException; +import io.github.openunirest.request.GenericType; +public interface ObjectMapper { T readValue(String value, Class valueType); - + default T readValue(String value, GenericType genericType){ + throw new UnirestException("Please implement me"); + } String writeValue(Object value); } diff --git a/src/main/java/io/github/openunirest/request/BaseRequest.java b/src/main/java/io/github/openunirest/request/BaseRequest.java index c6018be1d..762c9597c 100644 --- a/src/main/java/io/github/openunirest/request/BaseRequest.java +++ b/src/main/java/io/github/openunirest/request/BaseRequest.java @@ -26,19 +26,16 @@ a copy of this software and associated documentation files (the package io.github.openunirest.request; -import io.github.openunirest.http.async.Callback; import io.github.openunirest.http.HttpResponse; import io.github.openunirest.http.JsonNode; +import io.github.openunirest.http.async.Callback; import io.github.openunirest.http.exceptions.UnirestException; import java.io.InputStream; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; import java.util.concurrent.CompletableFuture; public abstract class BaseRequest { - protected static final Charset UTF_8 = StandardCharsets.UTF_8; private final ResponseBuilder builder = new ResponseBuilder(); protected HttpRequest httpRequest; @@ -83,6 +80,10 @@ public HttpResponse asObject(Class responseClass) throws Uni return HttpClientHelper.request(httpRequest, r -> builder.asObject(r, responseClass)); } + public HttpResponse asObject(GenericType genericType) throws UnirestException { + return HttpClientHelper.request(httpRequest, r -> builder.asObject(r, genericType)); + } + public CompletableFuture> asObjectAsync(Class responseClass) { return HttpClientHelper.requestAsync(httpRequest, r -> builder.asObject(r, responseClass)); } diff --git a/src/main/java/io/github/openunirest/request/GenericType.java b/src/main/java/io/github/openunirest/request/GenericType.java new file mode 100644 index 000000000..4ead549d4 --- /dev/null +++ b/src/main/java/io/github/openunirest/request/GenericType.java @@ -0,0 +1,25 @@ +package io.github.openunirest.request; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +public abstract class GenericType implements Comparable> { + protected final Type type; + + protected GenericType() { + Type superClass = this.getClass().getGenericSuperclass(); + if (superClass instanceof Class) { + throw new IllegalArgumentException("Internal error: TypeReference constructed without actual type information"); + } else { + this.type = ((ParameterizedType)superClass).getActualTypeArguments()[0]; + } + } + + public Type getType() { + return this.type; + } + + public int compareTo(GenericType o) { + return 0; + } +} diff --git a/src/main/java/io/github/openunirest/request/ResponseBuilder.java b/src/main/java/io/github/openunirest/request/ResponseBuilder.java index a0f68080f..5d62163a2 100644 --- a/src/main/java/io/github/openunirest/request/ResponseBuilder.java +++ b/src/main/java/io/github/openunirest/request/ResponseBuilder.java @@ -29,10 +29,19 @@ public HttpResponse asObject(org.apache.http.HttpResponse response, Class return new HttpResponse<>(response, from(response.getEntity(), b -> toObject(b, aClass))); } + public HttpResponse asObject(org.apache.http.HttpResponse response, GenericType genericType) { + return new HttpResponse<>(response, from(response.getEntity(), b -> toObject(b, genericType))); + } + public HttpResponse asString(org.apache.http.HttpResponse response) { return new HttpResponse<>(response, from(response.getEntity(), this::toString)); } + private T toObject(BodyData b, GenericType genericType) { + ObjectMapper o = getObjectMapper(); + return o.readValue(toString(b), genericType); + } + private T toObject(BodyData b, Class aClass) { ObjectMapper o = getObjectMapper(); return o.readValue(toString(b), aClass); diff --git a/src/test/java/BehaviorTests/AsGenericTypeTest.java b/src/test/java/BehaviorTests/AsGenericTypeTest.java new file mode 100644 index 000000000..56b3e2ff4 --- /dev/null +++ b/src/test/java/BehaviorTests/AsGenericTypeTest.java @@ -0,0 +1,81 @@ +package BehaviorTests; + +import io.github.openunirest.http.GsonObjectMapper; +import io.github.openunirest.http.Unirest; +import io.github.openunirest.request.GenericType; +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class AsGenericTypeTest extends BddTest { + + private final List foos = Arrays.asList( + new Foo("foo"), + new Foo("bar"), + new Foo("baz") + ); + + @Test + public void canGetAListOfObjects() { + MockServer.setJsonAsResponse(foos); + + List foos = Unirest.get(MockServer.GET) + .asObject(new GenericType>(){}) + .getBody(); + + assertTheFoos(foos); + } + + @Test + public void soManyLayersOfGenerics() { + MockServer.setJsonAsResponse(new WeirdType<>(foos, "hey")); + + WeirdType> foos = Unirest.get(MockServer.GET) + .asObject(new GenericType>>(){}) + .getBody(); + + List someTees = foos.getSomeTees(); + assertTheFoos(someTees); + } + + @Test + public void itAlsoWorksWithGson() { + Unirest.setObjectMapper(new GsonObjectMapper()); + + MockServer.setJsonAsResponse(new WeirdType<>(foos, "hey")); + + WeirdType> foos = Unirest.get(MockServer.GET) + .asObject(new GenericType>>(){}) + .getBody(); + + List someTees = foos.getSomeTees(); + assertTheFoos(someTees); + } + + private void assertTheFoos(List someTees) { + assertEquals(3, someTees.size()); + assertEquals("foo", someTees.get(0).bar); + assertEquals("bar", someTees.get(1).bar); + assertEquals("baz", someTees.get(2).bar); + } + + public static class WeirdType { + + private T someTees; + private String words; + + public WeirdType(){} + + public WeirdType(T someTees, String words){ + this.someTees = someTees; + this.words = words; + } + + public T getSomeTees() { + return someTees; + } + } +} diff --git a/src/test/java/BehaviorTests/Foo.java b/src/test/java/BehaviorTests/Foo.java index 08d16f5a3..7e345d6fd 100644 --- a/src/test/java/BehaviorTests/Foo.java +++ b/src/test/java/BehaviorTests/Foo.java @@ -1,5 +1,7 @@ package BehaviorTests; +import com.google.common.base.MoreObjects; + public class Foo { public String bar; @@ -8,4 +10,9 @@ public Foo(){ } public Foo(String bar) { this.bar = bar; } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this).add("bar",bar).toString(); + } } diff --git a/src/test/java/BehaviorTests/MockServer.java b/src/test/java/BehaviorTests/MockServer.java index 21aefd9c5..bdd79f6d7 100644 --- a/src/test/java/BehaviorTests/MockServer.java +++ b/src/test/java/BehaviorTests/MockServer.java @@ -31,6 +31,7 @@ a copy of this software and associated documentation files (the import spark.Response; import spark.Spark; +import java.util.Arrays; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; diff --git a/src/test/java/io/github/openunirest/http/GsonObjectMapper.java b/src/test/java/io/github/openunirest/http/GsonObjectMapper.java new file mode 100644 index 000000000..cfbdf2131 --- /dev/null +++ b/src/test/java/io/github/openunirest/http/GsonObjectMapper.java @@ -0,0 +1,24 @@ +package io.github.openunirest.http; + +import com.google.gson.Gson; +import io.github.openunirest.request.GenericType; + +public class GsonObjectMapper implements ObjectMapper { + + private final Gson gson = new Gson(); + + @Override + public T readValue(String value, Class valueType) { + return gson.fromJson(value, valueType); + } + + @Override + public T readValue(String value, GenericType genericType) { + return gson.fromJson(value, genericType.getType()); + } + + @Override + public String writeValue(Object value) { + return gson.toJson(value); + } +} diff --git a/src/test/java/io/github/openunirest/http/JacksonObjectMapper.java b/src/test/java/io/github/openunirest/http/JacksonObjectMapper.java index ec9e8ff47..c25323079 100644 --- a/src/test/java/io/github/openunirest/http/JacksonObjectMapper.java +++ b/src/test/java/io/github/openunirest/http/JacksonObjectMapper.java @@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.datatype.guava.GuavaModule; +import io.github.openunirest.request.GenericType; import io.github.openunirest.request.JsonPatch; import io.github.openunirest.request.JsonPatchItem; import org.json.JSONObject; @@ -30,6 +31,7 @@ public JacksonObjectMapper(){ om.registerModule(simpleModule); } + @Override public T readValue(String value, Class valueType) { try { return om.readValue(value, valueType); @@ -38,6 +40,16 @@ public T readValue(String value, Class valueType) { } } + @Override + public T readValue(String value, GenericType genericType) { + try { + return om.readValue(value, om.constructType(genericType.getType())); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override public String writeValue(Object value) { try { return om.writeValueAsString(value); From 930e3eb1d6cc79d59e0d8c43091b1266720503ac Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 9 Sep 2018 08:16:54 -0500 Subject: [PATCH 0196/1769] fix broken test. Make it useful --- .../java/BehaviorTests/JsonPatchTest.java | 29 ++++++++++--------- src/test/java/util/TestUtil.java | 6 ++++ src/test/resources/test-json-patch.json | 8 +++++ 3 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 src/test/resources/test-json-patch.json diff --git a/src/test/java/BehaviorTests/JsonPatchTest.java b/src/test/java/BehaviorTests/JsonPatchTest.java index 9cbf256aa..e28b3a93f 100644 --- a/src/test/java/BehaviorTests/JsonPatchTest.java +++ b/src/test/java/BehaviorTests/JsonPatchTest.java @@ -5,6 +5,10 @@ import org.json.JSONArray; import org.json.JSONObject; import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import util.TestUtil; + +import java.io.IOException; import static io.github.openunirest.request.JsonPatchOperation.*; @@ -85,7 +89,7 @@ public void lotsOfDifferentWaysToMakeObjects() { .assertJsonPatch(add, "/stringArrays", new String[]{"foo, bar"}) .assertJsonPatch(add, "/maps", basicJson) .assertJsonPatch(add, "/jsonObjects", basicJson) - .assertJsonPatch(add, "/jsonArrays", new JSONArray().put(basicJson)) + .assertJsonPatch(add, "/jsonArrays", new JSONArray().put(basicJson)) ; } @@ -108,24 +112,21 @@ public void canCopyObjects() { } @Test - public void allTogetherNow() { - Unirest.jsonPatch("http://localhost/thing") + public void thatsSomeValidJson() throws IOException { + String patch = Unirest.jsonPatch(MockServer.PATCH) .add("/fruits/-", "Apple") .remove("/bugs") .replace("/lastname", "Flintstone") .test("/firstname", "Fred") .move("/old/location", "/new/location") .copy("/original/location", "/new/location") - .asJson(); - /* resulting body - [ - {"op":"add","path":"/fruits/-","value":"Apple"}, - {"op":"remove","path":"/bugs"}, - {"op":"replace","path":"/lastname","value":"Flintstone"}, - {"op":"test","path":"/firstname","value":"Fred"}, - {"op":"move","path":"/new/location","from":"/old/location"}, - {"op":"copy","path":"/new/location","from":"/original/location"} - ] - */ + .asObject(RequestCapture.class) + .getBody() + .body; + + String expected = TestUtil.getResource("test-json-patch.json"); + + JSONAssert.assertEquals(expected, patch, true); } + } diff --git a/src/test/java/util/TestUtil.java b/src/test/java/util/TestUtil.java index 19a05b7d0..4f0ded88d 100644 --- a/src/test/java/util/TestUtil.java +++ b/src/test/java/util/TestUtil.java @@ -3,6 +3,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.guava.GuavaModule; +import com.google.common.base.Charsets; +import com.google.common.io.Resources; import io.github.openunirest.http.HttpResponse; import java.io.*; @@ -114,4 +116,8 @@ public static void assertBasicAuth(String raw, String username, String password) String credentials = raw.replace("Basic ",""); assertEquals(username + ":" + password, new String(Base64.getDecoder().decode(credentials))); } + + public static String getResource(String resourceName) throws IOException { + return Resources.toString(Resources.getResource(resourceName), Charsets.UTF_8); + } } diff --git a/src/test/resources/test-json-patch.json b/src/test/resources/test-json-patch.json new file mode 100644 index 000000000..6882fc6e2 --- /dev/null +++ b/src/test/resources/test-json-patch.json @@ -0,0 +1,8 @@ +[ + {"op":"add","path":"/fruits/-","value":"Apple"}, + {"op":"remove","path":"/bugs"}, + {"op":"replace","path":"/lastname","value":"Flintstone"}, + {"op":"test","path":"/firstname","value":"Fred"}, + {"op":"move","path":"/new/location","from":"/old/location"}, + {"op":"copy","path":"/new/location","from":"/original/location"} +] \ No newline at end of file From 98a40e74109bbe92507453560f68b1a9df58d701 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 9 Sep 2018 08:21:22 -0500 Subject: [PATCH 0197/1769] add copyright --- .../openunirest/request/GenericType.java | 24 ++++++++++++++++++ .../github/openunirest/request/JsonPatch.java | 25 +++++++++++++++++++ .../openunirest/request/JsonPatchItem.java | 25 +++++++++++++++++++ .../request/JsonPatchOperation.java | 25 +++++++++++++++++++ .../openunirest/request/JsonPatchRequest.java | 23 +++++++++++++++++ 5 files changed, 122 insertions(+) diff --git a/src/main/java/io/github/openunirest/request/GenericType.java b/src/main/java/io/github/openunirest/request/GenericType.java index 4ead549d4..db8b53192 100644 --- a/src/main/java/io/github/openunirest/request/GenericType.java +++ b/src/main/java/io/github/openunirest/request/GenericType.java @@ -1,4 +1,28 @@ package io.github.openunirest.request; +/* +The MIT License + +Copyright OpenUnirest (c) 2018. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; diff --git a/src/main/java/io/github/openunirest/request/JsonPatch.java b/src/main/java/io/github/openunirest/request/JsonPatch.java index 4674f5656..bc7dbf499 100644 --- a/src/main/java/io/github/openunirest/request/JsonPatch.java +++ b/src/main/java/io/github/openunirest/request/JsonPatch.java @@ -1,5 +1,30 @@ package io.github.openunirest.request; +/* +The MIT License + +Copyright OpenUnirest (c) 2018. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + import org.json.JSONArray; import org.json.JSONObject; diff --git a/src/main/java/io/github/openunirest/request/JsonPatchItem.java b/src/main/java/io/github/openunirest/request/JsonPatchItem.java index 577d82e39..9eace35d4 100644 --- a/src/main/java/io/github/openunirest/request/JsonPatchItem.java +++ b/src/main/java/io/github/openunirest/request/JsonPatchItem.java @@ -1,5 +1,30 @@ package io.github.openunirest.request; +/* +The MIT License + +Copyright OpenUnirest (c) 2018. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + import org.json.JSONObject; import java.util.Objects; diff --git a/src/main/java/io/github/openunirest/request/JsonPatchOperation.java b/src/main/java/io/github/openunirest/request/JsonPatchOperation.java index 250919cc7..1fd6b5723 100644 --- a/src/main/java/io/github/openunirest/request/JsonPatchOperation.java +++ b/src/main/java/io/github/openunirest/request/JsonPatchOperation.java @@ -1,5 +1,30 @@ package io.github.openunirest.request; +/* +The MIT License + +Copyright OpenUnirest (c) 2018. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + public enum JsonPatchOperation { add("value"), remove("value"), diff --git a/src/main/java/io/github/openunirest/request/JsonPatchRequest.java b/src/main/java/io/github/openunirest/request/JsonPatchRequest.java index 1f76cbf8f..8a04ea9d0 100644 --- a/src/main/java/io/github/openunirest/request/JsonPatchRequest.java +++ b/src/main/java/io/github/openunirest/request/JsonPatchRequest.java @@ -1,5 +1,28 @@ package io.github.openunirest.request; +/* +The MIT License +Copyright OpenUnirest (c) 2018. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ import io.github.openunirest.http.HttpMethod; import io.github.openunirest.request.body.Body; From 27582fcb6ac4e76f303b5e6810202718c8c1c660 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 9 Sep 2018 08:22:47 -0500 Subject: [PATCH 0198/1769] new generic feature so lets bump minor --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d15ba0ffe..3e4f2ff76 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.3.01-SNAPSHOT + 2.4.00-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ From 6fd7e86a6298b471156c77e3b0daea3c3b259b96 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 9 Sep 2018 08:25:44 -0500 Subject: [PATCH 0199/1769] [maven-release-plugin] prepare release v2.4.00 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3e4f2ff76..7f2c716e0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.4.00-SNAPSHOT + 2.4.00 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.4.00 From 1cb65f2a2f388e6930434626339e75f58843f2d4 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 9 Sep 2018 08:25:53 -0500 Subject: [PATCH 0200/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 7f2c716e0..a09dac57e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.4.00 + 2.4.01-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.4.00 + HEAD From 71285a2358954abf271975e05e2b16b20db82520 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 9 Sep 2018 08:30:36 -0500 Subject: [PATCH 0201/1769] note where we lifed code from Jackson --- .../io/github/openunirest/request/GenericType.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/io/github/openunirest/request/GenericType.java b/src/main/java/io/github/openunirest/request/GenericType.java index db8b53192..a775482df 100644 --- a/src/main/java/io/github/openunirest/request/GenericType.java +++ b/src/main/java/io/github/openunirest/request/GenericType.java @@ -1,5 +1,17 @@ package io.github.openunirest.request; /* +Parts of this file were taken from Jackson/core TypeReference under the Apache License: + +Apache (Software) License, version 2.0 ("the License"). +See the License for details about distribution rights, and the +specific rights regarding derivate works. + +You may obtain a copy of the License at: + +http://www.apache.org/licenses/LICENSE-2.0 + +The remaining +=========================== The MIT License Copyright OpenUnirest (c) 2018. From 0ca4162ba86ed2aea94b7e51f421b1483f018a3a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 9 Sep 2018 09:01:47 -0500 Subject: [PATCH 0202/1769] update docs --- CHANGELOG.md | 3 +++ README.md | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7dd747597..655cc03be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.4.00 +* Issue #19 Add support for generic types with object mappers. + ## 2.3.00 * Add support for the JSON Patch standard (RFC6902) https://tools.ietf.org/html/rfc6902 ```java diff --git a/README.md b/README.md index 541187549..2428dbec2 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ There are several such forks in the world. The guiding principals of this projec io.github.openunirest unirest-java - 2.3.00 + 2.4.00 ``` From 5211e5f8e9847ba28c6b38db097059b65286ed61 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 10 Sep 2018 07:24:58 -0500 Subject: [PATCH 0203/1769] add async versions of generic methods --- CHANGELOG.md | 3 ++ .../openunirest/request/BaseRequest.java | 8 ++++++ .../java/BehaviorTests/AsGenericTypeTest.java | 28 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 655cc03be..ac7daba4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.4.01 +* Add async versions of generic type methods + ## 2.4.00 * Issue #19 Add support for generic types with object mappers. diff --git a/src/main/java/io/github/openunirest/request/BaseRequest.java b/src/main/java/io/github/openunirest/request/BaseRequest.java index 762c9597c..1215311e2 100644 --- a/src/main/java/io/github/openunirest/request/BaseRequest.java +++ b/src/main/java/io/github/openunirest/request/BaseRequest.java @@ -92,6 +92,14 @@ public CompletableFuture> asObjectAsync(Class r return HttpClientHelper.requestAsync(httpRequest, r -> builder.asObject(r, responseClass), callback); } + public CompletableFuture> asObjectAsync(GenericType genericType) { + return HttpClientHelper.requestAsync(httpRequest, r -> builder.asObject(r, genericType)); + } + + public CompletableFuture> asObjectAsync(GenericType genericType, Callback callback) { + return HttpClientHelper.requestAsync(httpRequest, r -> builder.asObject(r, genericType), callback); + } + public HttpResponse asBinary() throws UnirestException { return HttpClientHelper.request(httpRequest, builder::asBinary); } diff --git a/src/test/java/BehaviorTests/AsGenericTypeTest.java b/src/test/java/BehaviorTests/AsGenericTypeTest.java index 56b3e2ff4..9b1af1cb2 100644 --- a/src/test/java/BehaviorTests/AsGenericTypeTest.java +++ b/src/test/java/BehaviorTests/AsGenericTypeTest.java @@ -7,6 +7,7 @@ import java.util.Arrays; import java.util.List; +import java.util.concurrent.ExecutionException; import static org.junit.Assert.assertEquals; @@ -29,6 +30,33 @@ public void canGetAListOfObjects() { assertTheFoos(foos); } + @Test + public void canGetAListOfObjectsAsync() throws ExecutionException, InterruptedException { + MockServer.setJsonAsResponse(foos); + + List foos = Unirest.get(MockServer.GET) + .asObjectAsync(new GenericType>(){}) + .get() + .getBody(); + + assertTheFoos(foos); + } + + @Test + public void canGetAListOfObjectsAsyncWithCallback() { + MockServer.setJsonAsResponse(foos); + + Unirest.get(MockServer.GET) + .asObjectAsync(new GenericType>(){}, + r -> { + List f = r.getBody(); + assertTheFoos(f); + asyncSuccess(); + }); + + assertAsync(); + } + @Test public void soManyLayersOfGenerics() { MockServer.setJsonAsResponse(new WeirdType<>(foos, "hey")); From 3e1b5afaadf7949bcb0726b469173f2f50c5a5c9 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 10 Sep 2018 08:09:48 -0500 Subject: [PATCH 0204/1769] [maven-release-plugin] prepare release v2.4.01 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index a09dac57e..1c9af01e0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.4.01-SNAPSHOT + 2.4.01 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.4.01 From 3cf15d1992801c29d10792cc4df91254620ec163 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 10 Sep 2018 08:09:55 -0500 Subject: [PATCH 0205/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 1c9af01e0..a13a99d98 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.4.01 + 2.4.02-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.4.01 + HEAD From add8b39e8bd0653d63b16fecf4ef9b836c265f81 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 11 Sep 2018 06:49:18 -0500 Subject: [PATCH 0206/1769] update readme --- README.md | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 2428dbec2..831d58fef 100644 --- a/README.md +++ b/README.md @@ -84,31 +84,13 @@ will send a request with a body of ## Advanced Object Mapping with Jackson, GSON, JAX-B or others Before an `asObject(Class)` or a `.body(Object)` invokation, is necessary to provide a custom implementation of the `ObjectMapper` interface. This should be done only the first time, as the instance of the ObjectMapper will be shared globally. +Open Unirest offers a few plug-ins implementing popular object mappers like Jackson and Gson. See [mvn central](https://mvnrepository.com/artifact/io.github.openunirest) for details. For example, serializing Json from\to Object using the popular Jackson ObjectMapper takes only few lines of code. ```java // Only one time -Unirest.setObjectMapper(new ObjectMapper() { - private com.fasterxml.jackson.databind.ObjectMapper jacksonObjectMapper - = new com.fasterxml.jackson.databind.ObjectMapper(); - - public T readValue(String value, Class valueType) { - try { - return jacksonObjectMapper.readValue(value, valueType); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public String writeValue(Object value) { - try { - return jacksonObjectMapper.writeValueAsString(value); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - } -}); +Unirest.setObjectMapper(new JacksonObjectMapper()); // Response to Object Book book = Unirest.get("http://httpbin.org/books/1") From 5ad72a4fa081af77e1bc5a621e48dc1e42db0bc7 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 11 Sep 2018 06:52:48 -0500 Subject: [PATCH 0207/1769] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 831d58fef..e05b76624 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ There are several such forks in the world. The guiding principals of this projec io.github.openunirest unirest-java - 2.4.00 + 2.4.01 ``` From 8153ef7fbd65629d3bf4d095bfbd40fcf5b4f61b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 17 Sep 2018 13:29:45 -0500 Subject: [PATCH 0208/1769] update version of org.json --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a13a99d98..d2d3a1cb1 100644 --- a/pom.xml +++ b/pom.xml @@ -247,7 +247,7 @@ org.json json - 20180130 + 20180813 junit From 722d07e3a781eb175d9c5ec9ee012418463a4a51 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 17 Sep 2018 15:21:09 -0500 Subject: [PATCH 0209/1769] [maven-release-plugin] prepare release v2.4.02 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d2d3a1cb1..21226844c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.4.02-SNAPSHOT + 2.4.02 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.4.02 From ddaf9174694e61982456ac785ab4e4b26b152099 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 17 Sep 2018 15:21:16 -0500 Subject: [PATCH 0210/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 21226844c..1569c966f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.4.02 + 2.4.03-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.4.02 + HEAD From 25331ffd348d7b4e457f8186b208810b571ac267 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 18 Sep 2018 08:12:27 -0500 Subject: [PATCH 0211/1769] update spark test dependency --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1569c966f..123f36add 100644 --- a/pom.xml +++ b/pom.xml @@ -298,7 +298,7 @@ com.sparkjava spark-core - 2.6.0 + 2.8.0 test From b4c0226723989964ecb7764a7b565553f1c7e79b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 18 Sep 2018 08:37:23 -0500 Subject: [PATCH 0212/1769] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e05b76624..9cfd95796 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ -# Unirest for Java [![Build Status](https://travis-ci.org/OpenUnirest/unirest-java.svg?branch=master)](https://travis-ci.org/OpenUnirest/unirest-java) +# Unirest for Java +[![Build Status](https://travis-ci.org/OpenUnirest/unirest-java.svg?branch=master)](https://travis-ci.org/OpenUnirest/unirest-java) +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.openunirest/unirest-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.openunirest/unirest-java) [![DepShield Badge](https://depshield.sonatype.org/badges/OpenUnirest/unirest-java/depshield.svg)](https://depshield.github.io) ## About This Repository @@ -17,7 +19,7 @@ There are several such forks in the world. The guiding principals of this projec io.github.openunirest unirest-java - 2.4.01 + 2.4.02 ``` From d20f5b37fc57f15d7c3a3fefd978dac83177af17 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 18 Sep 2018 08:38:18 -0500 Subject: [PATCH 0213/1769] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac7daba4f..4ac671a79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.4.02 +* Updated org.json dependency + ## 2.4.01 * Add async versions of generic type methods From 2cd22373ebaa40002bd22ea033cddd613728d08c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 25 Sep 2018 07:01:41 -0500 Subject: [PATCH 0214/1769] add some logging --- pom.xml | 6 ++++++ src/test/java/BehaviorTests/BddTest.java | 2 ++ src/test/java/BehaviorTests/JsonPatchTest.java | 1 + src/test/java/util/TestUtil.java | 1 + 4 files changed, 10 insertions(+) diff --git a/pom.xml b/pom.xml index 123f36add..f0e3eb9c9 100644 --- a/pom.xml +++ b/pom.xml @@ -307,6 +307,12 @@ 1.5.0 test + + org.slf4j + slf4j-simple + 1.7.25 + test + com.google.code.gson gson diff --git a/src/test/java/BehaviorTests/BddTest.java b/src/test/java/BehaviorTests/BddTest.java index 41713dbfa..01db4610d 100644 --- a/src/test/java/BehaviorTests/BddTest.java +++ b/src/test/java/BehaviorTests/BddTest.java @@ -3,6 +3,7 @@ import io.github.openunirest.http.*; import io.github.openunirest.http.options.Options; import org.junit.Before; +import util.TestUtil; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -20,6 +21,7 @@ public class BddTest { @Before public void setUp() { + //TestUtil.debugApache(); MockServer.reset(); Options.init(); Unirest.setObjectMapper(objectMapper); diff --git a/src/test/java/BehaviorTests/JsonPatchTest.java b/src/test/java/BehaviorTests/JsonPatchTest.java index e28b3a93f..fa6f17329 100644 --- a/src/test/java/BehaviorTests/JsonPatchTest.java +++ b/src/test/java/BehaviorTests/JsonPatchTest.java @@ -16,6 +16,7 @@ public class JsonPatchTest extends BddTest { @Test public void canAddThings() { + Unirest.jsonPatch(MockServer.PATCH) .add("/some/path", "a value") .add("/another/path", 42) diff --git a/src/test/java/util/TestUtil.java b/src/test/java/util/TestUtil.java index 4f0ded88d..f7c8efa97 100644 --- a/src/test/java/util/TestUtil.java +++ b/src/test/java/util/TestUtil.java @@ -92,6 +92,7 @@ public static Map mapOf(Object... keyValues) { public static void debugApache() { System.setProperty("org.apache.commons.logging.Log","org.apache.commons.logging.impl.SimpleLog"); System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); + System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "DEBUG"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "DEBUG"); } From 012ae68856bff46a755d728ef5a1749a32212cee Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 26 Sep 2018 10:27:41 -0500 Subject: [PATCH 0215/1769] extract interface for HttpResponse --- .../github/openunirest/http/HttpResponse.java | 95 ++------------- .../openunirest/request/HttpResponseImpl.java | 111 ++++++++++++++++++ .../openunirest/request/ResponseBuilder.java | 15 +-- .../{http => request}/HttpResponseTest.java | 8 +- 4 files changed, 130 insertions(+), 99 deletions(-) create mode 100644 src/main/java/io/github/openunirest/request/HttpResponseImpl.java rename src/test/java/io/github/openunirest/{http => request}/HttpResponseTest.java (67%) diff --git a/src/main/java/io/github/openunirest/http/HttpResponse.java b/src/main/java/io/github/openunirest/http/HttpResponse.java index aeb4eb2a9..4f6345961 100644 --- a/src/main/java/io/github/openunirest/http/HttpResponse.java +++ b/src/main/java/io/github/openunirest/http/HttpResponse.java @@ -1,100 +1,23 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - package io.github.openunirest.http; -import org.apache.http.StatusLine; - import java.io.InputStream; import java.util.Optional; import java.util.function.Function; -public class HttpResponse { - - private final Headers headers; - private final int statusCode; - private final String statusText; - - private InputStream rawBody; - private Optional parsingError = Optional.empty(); - private T body; - - private HttpResponse(org.apache.http.HttpResponse response){ - headers = new Headers(response.getAllHeaders()); - StatusLine statusLine = response.getStatusLine(); - this.statusCode = statusLine.getStatusCode(); - this.statusText = statusLine.getReasonPhrase(); - } - - public HttpResponse(org.apache.http.HttpResponse response, BodyData data){ - this(response); - this.rawBody = data.getRawInput(); - this.body = data.getTransFormedBody(); - this.parsingError = Optional.ofNullable(data.getParseEx()); - } - - public HttpResponse(org.apache.http.HttpResponse response, T body, InputStream is){ - this(response); - this.body = body; - this.rawBody = is; - } - - public int getStatus() { - return statusCode; - } +public interface HttpResponse { + int getStatus(); - public String getStatusText() { - return statusText; - } + String getStatusText(); - /** - * @return Response Headers (map) with same case as server response. - * For instance use getHeaders().getFirst("Location") and not getHeaders().getFirst("location") to get first header "Location" - */ - public Headers getHeaders() { - return headers; - } + Headers getHeaders(); - public InputStream getRawBody() { - return rawBody; - } + InputStream getRawBody(); - public T getBody() { - return body; - } + T getBody(); - public Optional getParsingError() { - return parsingError; - } + Optional getParsingError(); - public V mapBody(Function func){ - return func.apply(body); - } + V mapBody(Function func); - public V mapRawBody(Function func) { - return func.apply(rawBody); - } + V mapRawBody(Function func); } diff --git a/src/main/java/io/github/openunirest/request/HttpResponseImpl.java b/src/main/java/io/github/openunirest/request/HttpResponseImpl.java new file mode 100644 index 000000000..298f9291c --- /dev/null +++ b/src/main/java/io/github/openunirest/request/HttpResponseImpl.java @@ -0,0 +1,111 @@ +/* +The MIT License + +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package io.github.openunirest.request; + +import io.github.openunirest.http.BodyData; +import io.github.openunirest.http.Headers; +import io.github.openunirest.http.HttpResponse; +import org.apache.http.StatusLine; + +import java.io.InputStream; +import java.util.Optional; +import java.util.function.Function; + +class HttpResponseImpl implements HttpResponse { + + private final Headers headers; + private final int statusCode; + private final String statusText; + + private InputStream rawBody; + private Optional parsingError = Optional.empty(); + private T body; + + private HttpResponseImpl(org.apache.http.HttpResponse response){ + headers = new Headers(response.getAllHeaders()); + StatusLine statusLine = response.getStatusLine(); + this.statusCode = statusLine.getStatusCode(); + this.statusText = statusLine.getReasonPhrase(); + } + + public HttpResponseImpl(org.apache.http.HttpResponse response, BodyData data){ + this(response); + this.rawBody = data.getRawInput(); + this.body = data.getTransFormedBody(); + this.parsingError = Optional.ofNullable(data.getParseEx()); + } + + public HttpResponseImpl(org.apache.http.HttpResponse response, T body, InputStream is){ + this(response); + this.body = body; + this.rawBody = is; + } + + @Override + public int getStatus() { + return statusCode; + } + + @Override + public String getStatusText() { + return statusText; + } + + /** + * @return Response Headers (map) with same case as server response. + * For instance use getHeaders().getFirst("Location") and not getHeaders().getFirst("location") to get first header "Location" + */ + @Override + public Headers getHeaders() { + return headers; + } + + @Override + public InputStream getRawBody() { + return rawBody; + } + + @Override + public T getBody() { + return body; + } + + @Override + public Optional getParsingError() { + return parsingError; + } + + @Override + public V mapBody(Function func){ + return func.apply(body); + } + + @Override + public V mapRawBody(Function func) { + return func.apply(rawBody); + } +} diff --git a/src/main/java/io/github/openunirest/request/ResponseBuilder.java b/src/main/java/io/github/openunirest/request/ResponseBuilder.java index 5d62163a2..debf6956a 100644 --- a/src/main/java/io/github/openunirest/request/ResponseBuilder.java +++ b/src/main/java/io/github/openunirest/request/ResponseBuilder.java @@ -1,10 +1,7 @@ package io.github.openunirest.request; -import io.github.openunirest.http.BodyData; -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.JsonNode; -import io.github.openunirest.http.ObjectMapper; +import io.github.openunirest.http.*; import io.github.openunirest.http.exceptions.UnirestException; import io.github.openunirest.http.options.Option; import io.github.openunirest.http.options.Options; @@ -18,23 +15,23 @@ class ResponseBuilder { public HttpResponse asJson(org.apache.http.HttpResponse response) { - return new HttpResponse<>(response, from(response.getEntity(), b -> toJson(b))); + return new HttpResponseImpl<>(response, from(response.getEntity(), b -> toJson(b))); } public HttpResponse asBinary(org.apache.http.HttpResponse response){ - return new HttpResponse<>(response, from(response.getEntity(), BodyData::getRawInput)); + return new HttpResponseImpl<>(response, from(response.getEntity(), BodyData::getRawInput)); } public HttpResponse asObject(org.apache.http.HttpResponse response, Class aClass) { - return new HttpResponse<>(response, from(response.getEntity(), b -> toObject(b, aClass))); + return new HttpResponseImpl<>(response, from(response.getEntity(), b -> toObject(b, aClass))); } public HttpResponse asObject(org.apache.http.HttpResponse response, GenericType genericType) { - return new HttpResponse<>(response, from(response.getEntity(), b -> toObject(b, genericType))); + return new HttpResponseImpl<>(response, from(response.getEntity(), b -> toObject(b, genericType))); } public HttpResponse asString(org.apache.http.HttpResponse response) { - return new HttpResponse<>(response, from(response.getEntity(), this::toString)); + return new HttpResponseImpl<>(response, from(response.getEntity(), this::toString)); } private T toObject(BodyData b, GenericType genericType) { diff --git a/src/test/java/io/github/openunirest/http/HttpResponseTest.java b/src/test/java/io/github/openunirest/request/HttpResponseTest.java similarity index 67% rename from src/test/java/io/github/openunirest/http/HttpResponseTest.java rename to src/test/java/io/github/openunirest/request/HttpResponseTest.java index 277fba67a..55323524e 100644 --- a/src/test/java/io/github/openunirest/http/HttpResponseTest.java +++ b/src/test/java/io/github/openunirest/request/HttpResponseTest.java @@ -1,25 +1,25 @@ -package io.github.openunirest.http; +package io.github.openunirest.request; import io.github.openunirest.MockApacheResponse; import org.junit.Test; import util.TestUtil; +import static org.junit.Assert.assertEquals; import static util.TestUtil.emptyInput; -import static org.junit.Assert.*; public class HttpResponseTest { @Test public void canMapBody() { MockApacheResponse r = new MockApacheResponse(); - Integer v = new HttpResponse<>(r, "42", emptyInput()).mapBody(Integer::valueOf); + Integer v = new HttpResponseImpl<>(r, "42", emptyInput()).mapBody(Integer::valueOf); assertEquals(new Integer(42), v); } @Test public void canMapRawBody() { MockApacheResponse r = new MockApacheResponse(); - Integer v = new HttpResponse<>(r, "42", TestUtil.toInputStream("42")) + Integer v = new HttpResponseImpl<>(r, "42", TestUtil.toInputStream("42")) .mapRawBody(i -> Integer.valueOf(TestUtil.toString(i))); assertEquals(new Integer(42), v); From 2a6ba0695d7444a19da729540d24e78495d63456 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 26 Sep 2018 10:28:25 -0500 Subject: [PATCH 0216/1769] bump minor for interface change --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f0e3eb9c9..be9567954 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.4.03-SNAPSHOT + 2.5.00-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ From 2325fa5f46abd621643238f6d2eb9de771abf6af Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 26 Sep 2018 10:29:47 -0500 Subject: [PATCH 0217/1769] [maven-release-plugin] prepare release v2.5.00 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index be9567954..c5a14d95e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.5.00-SNAPSHOT + 2.5.00 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.5.00 From 8abc1bdf21498692ca871a142e74a4189c23192d Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 26 Sep 2018 10:29:54 -0500 Subject: [PATCH 0218/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c5a14d95e..fcb249170 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.5.00 + 2.5.01-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.5.00 + HEAD From c32d269e9ce92af5d14d0672276067553cadcf3e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 16 Oct 2018 11:20:20 -0700 Subject: [PATCH 0219/1769] upgrade jackson dependency in the tests --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fcb249170..b2ed6420f 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,7 @@ UTF-8 UTF-8 - 2.9.4 + 2.9.5 From fcc20d204017df86aed8d04b6cb3f5f8b95ed1b7 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 24 Oct 2018 14:25:45 -0500 Subject: [PATCH 0220/1769] possible fix for #41 --- .../io/github/openunirest/request/HttpClientHelper.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/openunirest/request/HttpClientHelper.java b/src/main/java/io/github/openunirest/request/HttpClientHelper.java index b490e872c..95ba48d70 100644 --- a/src/main/java/io/github/openunirest/request/HttpClientHelper.java +++ b/src/main/java/io/github/openunirest/request/HttpClientHelper.java @@ -78,11 +78,17 @@ public void cancelled() { private static CloseableHttpAsyncClient asyncClient() { CloseableHttpAsyncClient asyncHttpClient = ClientFactory.getAsyncHttpClient(); + if (!asyncHttpClient.isRunning()) { + tryStart(asyncHttpClient); + } + return asyncHttpClient; + } + + private static synchronized void tryStart(CloseableHttpAsyncClient asyncHttpClient) { if (!asyncHttpClient.isRunning()) { asyncHttpClient.start(); AsyncIdleConnectionMonitorThread asyncIdleConnectionMonitorThread = (AsyncIdleConnectionMonitorThread) Options.getOption(Option.ASYNC_MONITOR); asyncIdleConnectionMonitorThread.start(); } - return asyncHttpClient; } } From c41d467bd7a37dcf24c2462814825c69d08b8ea8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 24 Oct 2018 14:28:49 -0500 Subject: [PATCH 0221/1769] [maven-release-plugin] prepare release v2.5.01 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b2ed6420f..ee1196d2c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.5.01-SNAPSHOT + 2.5.01 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.5.01 From 317234458bb3e81e2a3f25779b14c804aa638fb2 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 24 Oct 2018 14:28:57 -0500 Subject: [PATCH 0222/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index ee1196d2c..5f3c46ff6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.5.01 + 2.5.02-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.5.01 + HEAD From 84a3d0d1f35aea433fd28f1719f7d87c1ffb2314 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 1 Nov 2018 15:14:40 -0500 Subject: [PATCH 0223/1769] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9cfd95796..741e4986b 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ There are several such forks in the world. The guiding principals of this projec io.github.openunirest unirest-java - 2.4.02 + 2.5.01 ``` From b64a7bf59da5b11bb6407096416c9fd2ac5c4724 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 1 Nov 2018 15:16:39 -0500 Subject: [PATCH 0224/1769] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ac671a79..743588a74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.5.01 +* Fix Issue #41: possible init error in HttpClient under heavy load + +## 2.5.00 +* Extracted Interface for HttpResponse to make testing easier + ## 2.4.02 * Updated org.json dependency From 531f4ec56618ae82bca3470ecbb7c3ddd062acbd Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 1 Nov 2018 15:27:36 -0500 Subject: [PATCH 0225/1769] move all classes into a single package --- .../AsyncIdleConnectionMonitorThread.java | 2 +- .../request => unirest}/BaseRequest.java | 7 +------ .../request/body => unirest}/Body.java | 2 +- .../openunirest/http => unirest}/BodyData.java | 7 +++---- .../http/async => unirest}/Callback.java | 5 +---- .../http/async => unirest}/CallbackFuture.java | 5 +---- .../http/utils => unirest}/ClientFactory.java | 5 +---- .../request/body => unirest}/FormPart.java | 2 +- .../request => unirest}/GenericType.java | 5 +++-- .../request => unirest}/GetRequest.java | 4 +--- .../openunirest/http => unirest}/Headers.java | 2 +- .../request => unirest}/HttpClientHelper.java | 10 +--------- .../HttpDeleteWithBody.java | 2 +- .../http => unirest}/HttpMethod.java | 2 +- .../request => unirest}/HttpPatchWithBody.java | 2 +- .../request => unirest}/HttpRequest.java | 6 +----- .../HttpRequestWithBody.java | 13 ++----------- .../http => unirest}/HttpResponse.java | 2 +- .../request => unirest}/HttpResponseImpl.java | 5 +---- .../openunirest/http => unirest}/JsonNode.java | 2 +- .../request => unirest}/JsonPatch.java | 4 ++-- .../request => unirest}/JsonPatchItem.java | 2 +- .../JsonPatchOperation.java | 2 +- .../request => unirest}/JsonPatchRequest.java | 4 +--- .../http/utils => unirest}/MapUtil.java | 9 +++------ .../body => unirest}/MultipartBody.java | 5 +---- .../http/options => unirest}/NoRedirects.java | 2 +- .../http => unirest}/ObjectMapper.java | 5 +---- .../http/options => unirest}/Option.java | 2 +- .../http/options => unirest}/Options.java | 9 +++------ .../request/body => unirest}/RawBody.java | 4 +--- .../body => unirest}/RequestBodyEntity.java | 5 +---- .../request => unirest}/RequestPrep.java | 5 +---- .../request => unirest}/ResponseBuilder.java | 9 ++------- .../http/utils => unirest}/ResponseUtils.java | 3 +-- .../SyncIdleConnectionMonitorThread.java | 2 +- .../utils => unirest}/URLParamEncoder.java | 2 +- .../openunirest/http => unirest}/Unirest.java | 7 +------ .../UnirestConfigException.java | 2 +- .../UnirestException.java | 2 +- .../request => unirest}/UriFormatter.java | 3 +-- src/test/java/BehaviorTests/AsBinaryTest.java | 6 +++--- .../java/BehaviorTests/AsGenericTypeTest.java | 6 +++--- src/test/java/BehaviorTests/AsJsonTest.java | 10 +++++----- src/test/java/BehaviorTests/AsObjectTest.java | 2 +- src/test/java/BehaviorTests/AsStringTest.java | 6 +++--- src/test/java/BehaviorTests/BddTest.java | 6 ++---- .../java/BehaviorTests/CallbackFutureTest.java | 6 +++--- src/test/java/BehaviorTests/DefectTest.java | 2 +- .../java/BehaviorTests/FormPostingTest.java | 8 ++++---- src/test/java/BehaviorTests/GZipTest.java | 2 +- src/test/java/BehaviorTests/HeaderTest.java | 14 +++++++------- .../java/BehaviorTests/InterceptorTest.java | 4 ++-- src/test/java/BehaviorTests/JsonPatchTest.java | 6 +++--- src/test/java/BehaviorTests/LifeCycleTest.java | 10 +++++----- src/test/java/BehaviorTests/MockServer.java | 3 +-- src/test/java/BehaviorTests/PathParamTest.java | 6 +++--- .../java/BehaviorTests/QueryStringTest.java | 6 +++--- .../java/BehaviorTests/RedirectHandling.java | 6 +++--- .../java/BehaviorTests/RequestCapture.java | 12 ++++++------ src/test/java/BehaviorTests/SendBodyTest.java | 10 +++++----- src/test/java/BehaviorTests/TimeoutTests.java | 6 +++--- src/test/java/BehaviorTests/VerbTest.java | 6 +++--- .../http => unirest}/GsonObjectMapper.java | 5 +++-- .../request => unirest}/HttpResponseTest.java | 9 +++++---- .../http => unirest}/JacksonObjectMapper.java | 9 +++++---- .../JacksonObjectMapperTest.java | 3 +-- .../http => unirest}/JsonNodeTest.java | 3 ++- .../MockApacheResponse.java | 3 ++- .../java/{util => unirest}/MockCallback.java | 6 +----- .../java/{util => unirest}/NoopCallback.java | 8 ++++---- .../NotImplimented.java | 2 +- .../http/options => unirest}/OptionsTest.java | 10 ++++++---- .../ResponseBuilderTest.java | 18 +++++++----------- .../utils => unirest}/ResponseUtilsTest.java | 3 ++- src/test/java/{util => unirest}/TestUtil.java | 4 ++-- .../request => unirest}/UriFormatterTest.java | 6 ++++-- 77 files changed, 167 insertions(+), 243 deletions(-) rename src/main/java/{io/github/openunirest/http/async/utils => unirest}/AsyncIdleConnectionMonitorThread.java (94%) rename src/main/java/{io/github/openunirest/request => unirest}/BaseRequest.java (94%) rename src/main/java/{io/github/openunirest/request/body => unirest}/Body.java (96%) rename src/main/java/{io/github/openunirest/http => unirest}/BodyData.java (86%) rename src/main/java/{io/github/openunirest/http/async => unirest}/Callback.java (90%) rename src/main/java/{io/github/openunirest/http/async => unirest}/CallbackFuture.java (84%) rename src/main/java/{io/github/openunirest/http/utils => unirest}/ClientFactory.java (73%) rename src/main/java/{io/github/openunirest/request/body => unirest}/FormPart.java (97%) rename src/main/java/{io/github/openunirest/request => unirest}/GenericType.java (98%) rename src/main/java/{io/github/openunirest/request => unirest}/GetRequest.java (95%) rename src/main/java/{io/github/openunirest/http => unirest}/Headers.java (95%) rename src/main/java/{io/github/openunirest/request => unirest}/HttpClientHelper.java (88%) rename src/main/java/{io/github/openunirest/request => unirest}/HttpDeleteWithBody.java (97%) rename src/main/java/{io/github/openunirest/http => unirest}/HttpMethod.java (97%) rename src/main/java/{io/github/openunirest/request => unirest}/HttpPatchWithBody.java (97%) rename src/main/java/{io/github/openunirest/request => unirest}/HttpRequest.java (95%) rename src/main/java/{io/github/openunirest/request => unirest}/HttpRequestWithBody.java (91%) rename src/main/java/{io/github/openunirest/http => unirest}/HttpResponse.java (91%) rename src/main/java/{io/github/openunirest/request => unirest}/HttpResponseImpl.java (94%) rename src/main/java/{io/github/openunirest/http => unirest}/JsonNode.java (98%) rename src/main/java/{io/github/openunirest/request => unirest}/JsonPatch.java (96%) rename src/main/java/{io/github/openunirest/request => unirest}/JsonPatchItem.java (98%) rename src/main/java/{io/github/openunirest/request => unirest}/JsonPatchOperation.java (97%) rename src/main/java/{io/github/openunirest/request => unirest}/JsonPatchRequest.java (94%) rename src/main/java/{io/github/openunirest/http/utils => unirest}/MapUtil.java (89%) rename src/main/java/{io/github/openunirest/request/body => unirest}/MultipartBody.java (96%) rename src/main/java/{io/github/openunirest/http/options => unirest}/NoRedirects.java (92%) rename src/main/java/{io/github/openunirest/http => unirest}/ObjectMapper.java (62%) rename src/main/java/{io/github/openunirest/http/options => unirest}/Option.java (91%) rename src/main/java/{io/github/openunirest/http/options => unirest}/Options.java (94%) rename src/main/java/{io/github/openunirest/request/body => unirest}/RawBody.java (92%) rename src/main/java/{io/github/openunirest/request/body => unirest}/RequestBodyEntity.java (91%) rename src/main/java/{io/github/openunirest/request => unirest}/RequestPrep.java (95%) rename src/main/java/{io/github/openunirest/request => unirest}/ResponseBuilder.java (88%) rename src/main/java/{io/github/openunirest/http/utils => unirest}/ResponseUtils.java (96%) rename src/main/java/{io/github/openunirest/http/utils => unirest}/SyncIdleConnectionMonitorThread.java (94%) rename src/main/java/{io/github/openunirest/http/utils => unirest}/URLParamEncoder.java (97%) rename src/main/java/{io/github/openunirest/http => unirest}/Unirest.java (95%) rename src/main/java/{io/github/openunirest/http/exceptions => unirest}/UnirestConfigException.java (74%) rename src/main/java/{io/github/openunirest/http/exceptions => unirest}/UnirestException.java (86%) rename src/main/java/{io/github/openunirest/request => unirest}/UriFormatter.java (80%) rename src/test/java/{io/github/openunirest/http => unirest}/GsonObjectMapper.java (85%) rename src/test/java/{io/github/openunirest/request => unirest}/HttpResponseTest.java (80%) rename src/test/java/{io/github/openunirest/http => unirest}/JacksonObjectMapper.java (94%) rename src/test/java/{io/github/openunirest/http => unirest}/JacksonObjectMapperTest.java (92%) rename src/test/java/{io/github/openunirest/http => unirest}/JsonNodeTest.java (96%) rename src/test/java/{io/github/openunirest => unirest}/MockApacheResponse.java (98%) rename src/test/java/{util => unirest}/MockCallback.java (84%) rename src/test/java/{util => unirest}/NoopCallback.java (59%) rename src/test/java/{io/github/openunirest => unirest}/NotImplimented.java (65%) rename src/test/java/{io/github/openunirest/http/options => unirest}/OptionsTest.java (92%) rename src/test/java/{io/github/openunirest/request => unirest}/ResponseBuilderTest.java (87%) rename src/test/java/{io/github/openunirest/http/utils => unirest}/ResponseUtilsTest.java (95%) rename src/test/java/{util => unirest}/TestUtil.java (98%) rename src/test/java/{io/github/openunirest/request => unirest}/UriFormatterTest.java (89%) diff --git a/src/main/java/io/github/openunirest/http/async/utils/AsyncIdleConnectionMonitorThread.java b/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java similarity index 94% rename from src/main/java/io/github/openunirest/http/async/utils/AsyncIdleConnectionMonitorThread.java rename to src/main/java/unirest/AsyncIdleConnectionMonitorThread.java index aaa6e447d..ab00de7ec 100644 --- a/src/main/java/io/github/openunirest/http/async/utils/AsyncIdleConnectionMonitorThread.java +++ b/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java @@ -1,4 +1,4 @@ -package io.github.openunirest.http.async.utils; +package unirest; import java.util.concurrent.TimeUnit; diff --git a/src/main/java/io/github/openunirest/request/BaseRequest.java b/src/main/java/unirest/BaseRequest.java similarity index 94% rename from src/main/java/io/github/openunirest/request/BaseRequest.java rename to src/main/java/unirest/BaseRequest.java index 1215311e2..f99e0b109 100644 --- a/src/main/java/io/github/openunirest/request/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -24,12 +24,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.request; - -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.JsonNode; -import io.github.openunirest.http.async.Callback; -import io.github.openunirest.http.exceptions.UnirestException; +package unirest; import java.io.InputStream; import java.util.concurrent.CompletableFuture; diff --git a/src/main/java/io/github/openunirest/request/body/Body.java b/src/main/java/unirest/Body.java similarity index 96% rename from src/main/java/io/github/openunirest/request/body/Body.java rename to src/main/java/unirest/Body.java index ed0781e44..e8afaf4a1 100644 --- a/src/main/java/io/github/openunirest/request/body/Body.java +++ b/src/main/java/unirest/Body.java @@ -24,7 +24,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.request.body; +package unirest; import org.apache.http.HttpEntity; diff --git a/src/main/java/io/github/openunirest/http/BodyData.java b/src/main/java/unirest/BodyData.java similarity index 86% rename from src/main/java/io/github/openunirest/http/BodyData.java rename to src/main/java/unirest/BodyData.java index fbc911495..b156a0332 100644 --- a/src/main/java/io/github/openunirest/http/BodyData.java +++ b/src/main/java/unirest/BodyData.java @@ -1,6 +1,5 @@ -package io.github.openunirest.http; +package unirest; -import io.github.openunirest.http.exceptions.UnirestException; import org.apache.http.HttpEntity; import java.io.ByteArrayInputStream; @@ -8,8 +7,8 @@ import java.util.Objects; import java.util.function.Function; -import static io.github.openunirest.http.utils.ResponseUtils.getCharSet; -import static io.github.openunirest.http.utils.ResponseUtils.getRawBody; +import static unirest.ResponseUtils.getCharSet; +import static unirest.ResponseUtils.getRawBody; @Deprecated // use at your own risk public class BodyData { diff --git a/src/main/java/io/github/openunirest/http/async/Callback.java b/src/main/java/unirest/Callback.java similarity index 90% rename from src/main/java/io/github/openunirest/http/async/Callback.java rename to src/main/java/unirest/Callback.java index e19cc5d83..ae9c2bece 100644 --- a/src/main/java/io/github/openunirest/http/async/Callback.java +++ b/src/main/java/unirest/Callback.java @@ -24,10 +24,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.http.async; - -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.exceptions.UnirestException; +package unirest; public interface Callback { diff --git a/src/main/java/io/github/openunirest/http/async/CallbackFuture.java b/src/main/java/unirest/CallbackFuture.java similarity index 84% rename from src/main/java/io/github/openunirest/http/async/CallbackFuture.java rename to src/main/java/unirest/CallbackFuture.java index a854909be..2990a9a33 100644 --- a/src/main/java/io/github/openunirest/http/async/CallbackFuture.java +++ b/src/main/java/unirest/CallbackFuture.java @@ -1,7 +1,4 @@ -package io.github.openunirest.http.async; - -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.exceptions.UnirestException; +package unirest; import java.util.concurrent.CompletableFuture; diff --git a/src/main/java/io/github/openunirest/http/utils/ClientFactory.java b/src/main/java/unirest/ClientFactory.java similarity index 73% rename from src/main/java/io/github/openunirest/http/utils/ClientFactory.java rename to src/main/java/unirest/ClientFactory.java index 37a9bf010..b4f3b2700 100644 --- a/src/main/java/io/github/openunirest/http/utils/ClientFactory.java +++ b/src/main/java/unirest/ClientFactory.java @@ -1,11 +1,8 @@ -package io.github.openunirest.http.utils; +package unirest; import org.apache.http.client.HttpClient; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; -import io.github.openunirest.http.options.Option; -import io.github.openunirest.http.options.Options; - public class ClientFactory { public static HttpClient getHttpClient() { diff --git a/src/main/java/io/github/openunirest/request/body/FormPart.java b/src/main/java/unirest/FormPart.java similarity index 97% rename from src/main/java/io/github/openunirest/request/body/FormPart.java rename to src/main/java/unirest/FormPart.java index 2fe356513..7e4e0ed0e 100644 --- a/src/main/java/io/github/openunirest/request/body/FormPart.java +++ b/src/main/java/unirest/FormPart.java @@ -1,4 +1,4 @@ -package io.github.openunirest.request.body; +package unirest; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.content.*; diff --git a/src/main/java/io/github/openunirest/request/GenericType.java b/src/main/java/unirest/GenericType.java similarity index 98% rename from src/main/java/io/github/openunirest/request/GenericType.java rename to src/main/java/unirest/GenericType.java index a775482df..066fcb04f 100644 --- a/src/main/java/io/github/openunirest/request/GenericType.java +++ b/src/main/java/unirest/GenericType.java @@ -1,4 +1,4 @@ -package io.github.openunirest.request; +package unirest; /* Parts of this file were taken from Jackson/core TypeReference under the Apache License: @@ -34,7 +34,8 @@ a copy of this software and associated documentation files (the LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ + +*/ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; diff --git a/src/main/java/io/github/openunirest/request/GetRequest.java b/src/main/java/unirest/GetRequest.java similarity index 95% rename from src/main/java/io/github/openunirest/request/GetRequest.java rename to src/main/java/unirest/GetRequest.java index b01e54d4f..0ec59f1eb 100644 --- a/src/main/java/io/github/openunirest/request/GetRequest.java +++ b/src/main/java/unirest/GetRequest.java @@ -24,9 +24,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.request; - -import io.github.openunirest.http.HttpMethod; +package unirest; import java.util.Map; diff --git a/src/main/java/io/github/openunirest/http/Headers.java b/src/main/java/unirest/Headers.java similarity index 95% rename from src/main/java/io/github/openunirest/http/Headers.java rename to src/main/java/unirest/Headers.java index 09be5d7c6..0b38023be 100644 --- a/src/main/java/io/github/openunirest/http/Headers.java +++ b/src/main/java/unirest/Headers.java @@ -1,4 +1,4 @@ -package io.github.openunirest.http; +package unirest; import org.apache.http.Header; diff --git a/src/main/java/io/github/openunirest/request/HttpClientHelper.java b/src/main/java/unirest/HttpClientHelper.java similarity index 88% rename from src/main/java/io/github/openunirest/request/HttpClientHelper.java rename to src/main/java/unirest/HttpClientHelper.java index 95ba48d70..44d90d562 100644 --- a/src/main/java/io/github/openunirest/request/HttpClientHelper.java +++ b/src/main/java/unirest/HttpClientHelper.java @@ -1,13 +1,5 @@ -package io.github.openunirest.request; +package unirest; -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.async.Callback; -import io.github.openunirest.http.async.CallbackFuture; -import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; -import io.github.openunirest.http.exceptions.UnirestException; -import io.github.openunirest.http.options.Option; -import io.github.openunirest.http.options.Options; -import io.github.openunirest.http.utils.ClientFactory; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.client.methods.HttpUriRequest; diff --git a/src/main/java/io/github/openunirest/request/HttpDeleteWithBody.java b/src/main/java/unirest/HttpDeleteWithBody.java similarity index 97% rename from src/main/java/io/github/openunirest/request/HttpDeleteWithBody.java rename to src/main/java/unirest/HttpDeleteWithBody.java index e0deb02f4..370baed4c 100644 --- a/src/main/java/io/github/openunirest/request/HttpDeleteWithBody.java +++ b/src/main/java/unirest/HttpDeleteWithBody.java @@ -24,7 +24,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.request; +package unirest; import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; diff --git a/src/main/java/io/github/openunirest/http/HttpMethod.java b/src/main/java/unirest/HttpMethod.java similarity index 97% rename from src/main/java/io/github/openunirest/http/HttpMethod.java rename to src/main/java/unirest/HttpMethod.java index 889f5c8b3..74c55b7e1 100644 --- a/src/main/java/io/github/openunirest/http/HttpMethod.java +++ b/src/main/java/unirest/HttpMethod.java @@ -24,7 +24,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.http; +package unirest; public enum HttpMethod { GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS; diff --git a/src/main/java/io/github/openunirest/request/HttpPatchWithBody.java b/src/main/java/unirest/HttpPatchWithBody.java similarity index 97% rename from src/main/java/io/github/openunirest/request/HttpPatchWithBody.java rename to src/main/java/unirest/HttpPatchWithBody.java index 127f05178..8fc966c5d 100644 --- a/src/main/java/io/github/openunirest/request/HttpPatchWithBody.java +++ b/src/main/java/unirest/HttpPatchWithBody.java @@ -24,7 +24,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.request; +package unirest; import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; diff --git a/src/main/java/io/github/openunirest/request/HttpRequest.java b/src/main/java/unirest/HttpRequest.java similarity index 95% rename from src/main/java/io/github/openunirest/request/HttpRequest.java rename to src/main/java/unirest/HttpRequest.java index d456b9a72..aeea71bc5 100644 --- a/src/main/java/io/github/openunirest/request/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -24,11 +24,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.request; - -import io.github.openunirest.http.HttpMethod; -import io.github.openunirest.http.utils.URLParamEncoder; -import io.github.openunirest.request.body.Body; +package unirest; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; diff --git a/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java b/src/main/java/unirest/HttpRequestWithBody.java similarity index 91% rename from src/main/java/io/github/openunirest/request/HttpRequestWithBody.java rename to src/main/java/unirest/HttpRequestWithBody.java index 49b377d53..9f73e02da 100644 --- a/src/main/java/io/github/openunirest/request/HttpRequestWithBody.java +++ b/src/main/java/unirest/HttpRequestWithBody.java @@ -24,17 +24,8 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.request; - -import io.github.openunirest.http.HttpMethod; -import io.github.openunirest.http.JsonNode; -import io.github.openunirest.http.ObjectMapper; -import io.github.openunirest.http.exceptions.UnirestConfigException; -import io.github.openunirest.http.options.Option; -import io.github.openunirest.http.options.Options; -import io.github.openunirest.request.body.MultipartBody; -import io.github.openunirest.request.body.RawBody; -import io.github.openunirest.request.body.RequestBodyEntity; +package unirest; + import org.apache.http.entity.ContentType; import org.json.JSONArray; import org.json.JSONObject; diff --git a/src/main/java/io/github/openunirest/http/HttpResponse.java b/src/main/java/unirest/HttpResponse.java similarity index 91% rename from src/main/java/io/github/openunirest/http/HttpResponse.java rename to src/main/java/unirest/HttpResponse.java index 4f6345961..fceebb302 100644 --- a/src/main/java/io/github/openunirest/http/HttpResponse.java +++ b/src/main/java/unirest/HttpResponse.java @@ -1,4 +1,4 @@ -package io.github.openunirest.http; +package unirest; import java.io.InputStream; import java.util.Optional; diff --git a/src/main/java/io/github/openunirest/request/HttpResponseImpl.java b/src/main/java/unirest/HttpResponseImpl.java similarity index 94% rename from src/main/java/io/github/openunirest/request/HttpResponseImpl.java rename to src/main/java/unirest/HttpResponseImpl.java index 298f9291c..4c8458d5d 100644 --- a/src/main/java/io/github/openunirest/request/HttpResponseImpl.java +++ b/src/main/java/unirest/HttpResponseImpl.java @@ -24,11 +24,8 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.request; +package unirest; -import io.github.openunirest.http.BodyData; -import io.github.openunirest.http.Headers; -import io.github.openunirest.http.HttpResponse; import org.apache.http.StatusLine; import java.io.InputStream; diff --git a/src/main/java/io/github/openunirest/http/JsonNode.java b/src/main/java/unirest/JsonNode.java similarity index 98% rename from src/main/java/io/github/openunirest/http/JsonNode.java rename to src/main/java/unirest/JsonNode.java index db197706c..fce4e1eb2 100644 --- a/src/main/java/io/github/openunirest/http/JsonNode.java +++ b/src/main/java/unirest/JsonNode.java @@ -24,7 +24,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.http; +package unirest; import org.json.JSONArray; import org.json.JSONException; diff --git a/src/main/java/io/github/openunirest/request/JsonPatch.java b/src/main/java/unirest/JsonPatch.java similarity index 96% rename from src/main/java/io/github/openunirest/request/JsonPatch.java rename to src/main/java/unirest/JsonPatch.java index bc7dbf499..7bed32af5 100644 --- a/src/main/java/io/github/openunirest/request/JsonPatch.java +++ b/src/main/java/unirest/JsonPatch.java @@ -1,4 +1,4 @@ -package io.github.openunirest.request; +package unirest; /* The MIT License @@ -32,7 +32,7 @@ a copy of this software and associated documentation files (the import java.util.Collections; import java.util.List; -import static io.github.openunirest.request.JsonPatchOperation.*; +import static unirest.JsonPatchOperation.*; public class JsonPatch { diff --git a/src/main/java/io/github/openunirest/request/JsonPatchItem.java b/src/main/java/unirest/JsonPatchItem.java similarity index 98% rename from src/main/java/io/github/openunirest/request/JsonPatchItem.java rename to src/main/java/unirest/JsonPatchItem.java index 9eace35d4..05f619907 100644 --- a/src/main/java/io/github/openunirest/request/JsonPatchItem.java +++ b/src/main/java/unirest/JsonPatchItem.java @@ -1,4 +1,4 @@ -package io.github.openunirest.request; +package unirest; /* The MIT License diff --git a/src/main/java/io/github/openunirest/request/JsonPatchOperation.java b/src/main/java/unirest/JsonPatchOperation.java similarity index 97% rename from src/main/java/io/github/openunirest/request/JsonPatchOperation.java rename to src/main/java/unirest/JsonPatchOperation.java index 1fd6b5723..0072c1d6f 100644 --- a/src/main/java/io/github/openunirest/request/JsonPatchOperation.java +++ b/src/main/java/unirest/JsonPatchOperation.java @@ -1,4 +1,4 @@ -package io.github.openunirest.request; +package unirest; /* The MIT License diff --git a/src/main/java/io/github/openunirest/request/JsonPatchRequest.java b/src/main/java/unirest/JsonPatchRequest.java similarity index 94% rename from src/main/java/io/github/openunirest/request/JsonPatchRequest.java rename to src/main/java/unirest/JsonPatchRequest.java index 8a04ea9d0..6c503b14e 100644 --- a/src/main/java/io/github/openunirest/request/JsonPatchRequest.java +++ b/src/main/java/unirest/JsonPatchRequest.java @@ -1,4 +1,4 @@ -package io.github.openunirest.request; +package unirest; /* The MIT License @@ -24,8 +24,6 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import io.github.openunirest.http.HttpMethod; -import io.github.openunirest.request.body.Body; import org.apache.http.HttpEntity; import org.apache.http.entity.BasicHttpEntity; diff --git a/src/main/java/io/github/openunirest/http/utils/MapUtil.java b/src/main/java/unirest/MapUtil.java similarity index 89% rename from src/main/java/io/github/openunirest/http/utils/MapUtil.java rename to src/main/java/unirest/MapUtil.java index 511b4518a..d6289b907 100644 --- a/src/main/java/io/github/openunirest/http/utils/MapUtil.java +++ b/src/main/java/unirest/MapUtil.java @@ -24,9 +24,8 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.http.utils; +package unirest; -import io.github.openunirest.request.body.FormPart; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; @@ -34,14 +33,12 @@ a copy of this software and associated documentation files (the import java.util.Collection; import java.util.List; -public class MapUtil { - - public static List getList(Collection parameters) { +class MapUtil { + static List getList(Collection parameters) { List result = new ArrayList<>(); for (FormPart entry : parameters) { result.add(new BasicNameValuePair(entry.getName(), entry.getValue().toString())); } return result; } - } diff --git a/src/main/java/io/github/openunirest/request/body/MultipartBody.java b/src/main/java/unirest/MultipartBody.java similarity index 96% rename from src/main/java/io/github/openunirest/request/body/MultipartBody.java rename to src/main/java/unirest/MultipartBody.java index af050e5da..bc38df360 100644 --- a/src/main/java/io/github/openunirest/request/body/MultipartBody.java +++ b/src/main/java/unirest/MultipartBody.java @@ -24,11 +24,8 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.request.body; +package unirest; -import io.github.openunirest.http.utils.MapUtil; -import io.github.openunirest.request.BaseRequest; -import io.github.openunirest.request.HttpRequestWithBody; import org.apache.http.HttpEntity; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.entity.ContentType; diff --git a/src/main/java/io/github/openunirest/http/options/NoRedirects.java b/src/main/java/unirest/NoRedirects.java similarity index 92% rename from src/main/java/io/github/openunirest/http/options/NoRedirects.java rename to src/main/java/unirest/NoRedirects.java index a409fd1d9..e86edc53e 100644 --- a/src/main/java/io/github/openunirest/http/options/NoRedirects.java +++ b/src/main/java/unirest/NoRedirects.java @@ -1,4 +1,4 @@ -package io.github.openunirest.http.options; +package unirest; import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; diff --git a/src/main/java/io/github/openunirest/http/ObjectMapper.java b/src/main/java/unirest/ObjectMapper.java similarity index 62% rename from src/main/java/io/github/openunirest/http/ObjectMapper.java rename to src/main/java/unirest/ObjectMapper.java index 11e7cb10a..2c00e67b2 100644 --- a/src/main/java/io/github/openunirest/http/ObjectMapper.java +++ b/src/main/java/unirest/ObjectMapper.java @@ -1,7 +1,4 @@ -package io.github.openunirest.http; - -import io.github.openunirest.http.exceptions.UnirestException; -import io.github.openunirest.request.GenericType; +package unirest; public interface ObjectMapper { T readValue(String value, Class valueType); diff --git a/src/main/java/io/github/openunirest/http/options/Option.java b/src/main/java/unirest/Option.java similarity index 91% rename from src/main/java/io/github/openunirest/http/options/Option.java rename to src/main/java/unirest/Option.java index 5f8504b59..adfa7f8a0 100644 --- a/src/main/java/io/github/openunirest/http/options/Option.java +++ b/src/main/java/unirest/Option.java @@ -1,4 +1,4 @@ -package io.github.openunirest.http.options; +package unirest; public enum Option { HTTPCLIENT(false), diff --git a/src/main/java/io/github/openunirest/http/options/Options.java b/src/main/java/unirest/Options.java similarity index 94% rename from src/main/java/io/github/openunirest/http/options/Options.java rename to src/main/java/unirest/Options.java index 5f24412da..42cfe6539 100644 --- a/src/main/java/io/github/openunirest/http/options/Options.java +++ b/src/main/java/unirest/Options.java @@ -1,8 +1,5 @@ -package io.github.openunirest.http.options; +package unirest; -import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; -import io.github.openunirest.http.exceptions.UnirestException; -import io.github.openunirest.http.utils.SyncIdleConnectionMonitorThread; import org.apache.http.HttpHost; import org.apache.http.HttpRequestInterceptor; import org.apache.http.client.config.RequestConfig; @@ -19,8 +16,8 @@ import java.io.IOException; import java.util.*; -import static io.github.openunirest.http.options.Option.COOKIE_MANAGEMENT; -import static io.github.openunirest.http.options.Option.FOLLOW_REDIRECTS; +import static unirest.Option.COOKIE_MANAGEMENT; +import static unirest.Option.FOLLOW_REDIRECTS; public class Options { public static final int MAX_TOTAL = 200; diff --git a/src/main/java/io/github/openunirest/request/body/RawBody.java b/src/main/java/unirest/RawBody.java similarity index 92% rename from src/main/java/io/github/openunirest/request/body/RawBody.java rename to src/main/java/unirest/RawBody.java index f29e75693..e012be1d0 100644 --- a/src/main/java/io/github/openunirest/request/body/RawBody.java +++ b/src/main/java/unirest/RawBody.java @@ -24,10 +24,8 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.request.body; +package unirest; -import io.github.openunirest.request.BaseRequest; -import io.github.openunirest.request.HttpRequest; import org.apache.http.HttpEntity; import org.apache.http.entity.ByteArrayEntity; diff --git a/src/main/java/io/github/openunirest/request/body/RequestBodyEntity.java b/src/main/java/unirest/RequestBodyEntity.java similarity index 91% rename from src/main/java/io/github/openunirest/request/body/RequestBodyEntity.java rename to src/main/java/unirest/RequestBodyEntity.java index 17d3c5fba..81db20837 100644 --- a/src/main/java/io/github/openunirest/request/body/RequestBodyEntity.java +++ b/src/main/java/unirest/RequestBodyEntity.java @@ -24,11 +24,8 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.request.body; +package unirest; -import io.github.openunirest.http.JsonNode; -import io.github.openunirest.request.BaseRequest; -import io.github.openunirest.request.HttpRequestWithBody; import org.apache.http.HttpEntity; import org.apache.http.entity.StringEntity; diff --git a/src/main/java/io/github/openunirest/request/RequestPrep.java b/src/main/java/unirest/RequestPrep.java similarity index 95% rename from src/main/java/io/github/openunirest/request/RequestPrep.java rename to src/main/java/unirest/RequestPrep.java index 1b31c333b..7dafd2222 100644 --- a/src/main/java/io/github/openunirest/request/RequestPrep.java +++ b/src/main/java/unirest/RequestPrep.java @@ -1,8 +1,5 @@ -package io.github.openunirest.request; +package unirest; -import io.github.openunirest.http.HttpMethod; -import io.github.openunirest.http.options.Option; -import io.github.openunirest.http.options.Options; import org.apache.http.HttpEntity; import org.apache.http.client.methods.*; import org.apache.http.nio.entity.NByteArrayEntity; diff --git a/src/main/java/io/github/openunirest/request/ResponseBuilder.java b/src/main/java/unirest/ResponseBuilder.java similarity index 88% rename from src/main/java/io/github/openunirest/request/ResponseBuilder.java rename to src/main/java/unirest/ResponseBuilder.java index debf6956a..d4de53180 100644 --- a/src/main/java/io/github/openunirest/request/ResponseBuilder.java +++ b/src/main/java/unirest/ResponseBuilder.java @@ -1,15 +1,10 @@ -package io.github.openunirest.request; +package unirest; -import io.github.openunirest.http.*; -import io.github.openunirest.http.exceptions.UnirestException; -import io.github.openunirest.http.options.Option; -import io.github.openunirest.http.options.Options; - import java.io.InputStream; import java.io.UnsupportedEncodingException; -import static io.github.openunirest.http.BodyData.from; +import static unirest.BodyData.from; class ResponseBuilder { diff --git a/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java b/src/main/java/unirest/ResponseUtils.java similarity index 96% rename from src/main/java/io/github/openunirest/http/utils/ResponseUtils.java rename to src/main/java/unirest/ResponseUtils.java index 6d6539ab6..81c4eea0d 100644 --- a/src/main/java/io/github/openunirest/http/utils/ResponseUtils.java +++ b/src/main/java/unirest/ResponseUtils.java @@ -1,6 +1,5 @@ -package io.github.openunirest.http.utils; +package unirest; -import io.github.openunirest.http.exceptions.UnirestException; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.util.EntityUtils; diff --git a/src/main/java/io/github/openunirest/http/utils/SyncIdleConnectionMonitorThread.java b/src/main/java/unirest/SyncIdleConnectionMonitorThread.java similarity index 94% rename from src/main/java/io/github/openunirest/http/utils/SyncIdleConnectionMonitorThread.java rename to src/main/java/unirest/SyncIdleConnectionMonitorThread.java index 696dacafd..0ea3c82d4 100644 --- a/src/main/java/io/github/openunirest/http/utils/SyncIdleConnectionMonitorThread.java +++ b/src/main/java/unirest/SyncIdleConnectionMonitorThread.java @@ -1,4 +1,4 @@ -package io.github.openunirest.http.utils; +package unirest; import java.util.concurrent.TimeUnit; diff --git a/src/main/java/io/github/openunirest/http/utils/URLParamEncoder.java b/src/main/java/unirest/URLParamEncoder.java similarity index 97% rename from src/main/java/io/github/openunirest/http/utils/URLParamEncoder.java rename to src/main/java/unirest/URLParamEncoder.java index dc85a9769..d07ffb9a4 100644 --- a/src/main/java/io/github/openunirest/http/utils/URLParamEncoder.java +++ b/src/main/java/unirest/URLParamEncoder.java @@ -24,7 +24,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.http.utils; +package unirest; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; diff --git a/src/main/java/io/github/openunirest/http/Unirest.java b/src/main/java/unirest/Unirest.java similarity index 95% rename from src/main/java/io/github/openunirest/http/Unirest.java rename to src/main/java/unirest/Unirest.java index ae20e586a..7f7f3fa41 100644 --- a/src/main/java/io/github/openunirest/http/Unirest.java +++ b/src/main/java/unirest/Unirest.java @@ -24,13 +24,8 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package io.github.openunirest.http; +package unirest; -import io.github.openunirest.http.options.Option; -import io.github.openunirest.http.options.Options; -import io.github.openunirest.request.GetRequest; -import io.github.openunirest.request.HttpRequestWithBody; -import io.github.openunirest.request.JsonPatchRequest; import org.apache.http.HttpHost; import org.apache.http.client.HttpClient; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; diff --git a/src/main/java/io/github/openunirest/http/exceptions/UnirestConfigException.java b/src/main/java/unirest/UnirestConfigException.java similarity index 74% rename from src/main/java/io/github/openunirest/http/exceptions/UnirestConfigException.java rename to src/main/java/unirest/UnirestConfigException.java index c9ff7a925..1d814404f 100644 --- a/src/main/java/io/github/openunirest/http/exceptions/UnirestConfigException.java +++ b/src/main/java/unirest/UnirestConfigException.java @@ -1,4 +1,4 @@ -package io.github.openunirest.http.exceptions; +package unirest; public class UnirestConfigException extends UnirestException { public UnirestConfigException(String msg) { diff --git a/src/main/java/io/github/openunirest/http/exceptions/UnirestException.java b/src/main/java/unirest/UnirestException.java similarity index 86% rename from src/main/java/io/github/openunirest/http/exceptions/UnirestException.java rename to src/main/java/unirest/UnirestException.java index 5f543e78f..d8f1dd2f1 100644 --- a/src/main/java/io/github/openunirest/http/exceptions/UnirestException.java +++ b/src/main/java/unirest/UnirestException.java @@ -1,4 +1,4 @@ -package io.github.openunirest.http.exceptions; +package unirest; public class UnirestException extends RuntimeException { diff --git a/src/main/java/io/github/openunirest/request/UriFormatter.java b/src/main/java/unirest/UriFormatter.java similarity index 80% rename from src/main/java/io/github/openunirest/request/UriFormatter.java rename to src/main/java/unirest/UriFormatter.java index 8d9a8473e..a8d9f553e 100644 --- a/src/main/java/io/github/openunirest/request/UriFormatter.java +++ b/src/main/java/unirest/UriFormatter.java @@ -1,6 +1,5 @@ -package io.github.openunirest.request; +package unirest; -import io.github.openunirest.http.exceptions.UnirestException; import org.apache.http.client.utils.URIBuilder; import java.net.URISyntaxException; diff --git a/src/test/java/BehaviorTests/AsBinaryTest.java b/src/test/java/BehaviorTests/AsBinaryTest.java index fce12644f..302bdadc8 100644 --- a/src/test/java/BehaviorTests/AsBinaryTest.java +++ b/src/test/java/BehaviorTests/AsBinaryTest.java @@ -1,9 +1,9 @@ package BehaviorTests; -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.Unirest; +import unirest.HttpResponse; +import unirest.Unirest; import org.junit.Test; -import util.TestUtil; +import unirest.TestUtil; import java.io.InputStream; import java.util.concurrent.CompletableFuture; diff --git a/src/test/java/BehaviorTests/AsGenericTypeTest.java b/src/test/java/BehaviorTests/AsGenericTypeTest.java index 9b1af1cb2..d61127e07 100644 --- a/src/test/java/BehaviorTests/AsGenericTypeTest.java +++ b/src/test/java/BehaviorTests/AsGenericTypeTest.java @@ -1,8 +1,8 @@ package BehaviorTests; -import io.github.openunirest.http.GsonObjectMapper; -import io.github.openunirest.http.Unirest; -import io.github.openunirest.request.GenericType; +import unirest.GsonObjectMapper; +import unirest.Unirest; +import unirest.GenericType; import org.junit.Test; import java.util.Arrays; diff --git a/src/test/java/BehaviorTests/AsJsonTest.java b/src/test/java/BehaviorTests/AsJsonTest.java index b63d09ada..5a70fd544 100644 --- a/src/test/java/BehaviorTests/AsJsonTest.java +++ b/src/test/java/BehaviorTests/AsJsonTest.java @@ -1,11 +1,11 @@ package BehaviorTests; -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.JsonNode; -import io.github.openunirest.http.Unirest; +import unirest.HttpResponse; +import unirest.JsonNode; +import unirest.Unirest; import org.junit.Test; -import util.MockCallback; -import util.TestUtil; +import unirest.MockCallback; +import unirest.TestUtil; import java.util.concurrent.CompletableFuture; diff --git a/src/test/java/BehaviorTests/AsObjectTest.java b/src/test/java/BehaviorTests/AsObjectTest.java index 10e14f27b..c48b44003 100644 --- a/src/test/java/BehaviorTests/AsObjectTest.java +++ b/src/test/java/BehaviorTests/AsObjectTest.java @@ -1,6 +1,6 @@ package BehaviorTests; -import io.github.openunirest.http.Unirest; +import unirest.Unirest; import org.junit.Test; public class AsObjectTest extends BddTest { diff --git a/src/test/java/BehaviorTests/AsStringTest.java b/src/test/java/BehaviorTests/AsStringTest.java index 4a10ca46e..0794bf8c8 100644 --- a/src/test/java/BehaviorTests/AsStringTest.java +++ b/src/test/java/BehaviorTests/AsStringTest.java @@ -1,9 +1,9 @@ package BehaviorTests; -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.Unirest; +import unirest.HttpResponse; +import unirest.Unirest; import org.junit.Test; -import util.TestUtil; +import unirest.TestUtil; import java.util.concurrent.CompletableFuture; diff --git a/src/test/java/BehaviorTests/BddTest.java b/src/test/java/BehaviorTests/BddTest.java index 01db4610d..589572a89 100644 --- a/src/test/java/BehaviorTests/BddTest.java +++ b/src/test/java/BehaviorTests/BddTest.java @@ -1,14 +1,12 @@ package BehaviorTests; -import io.github.openunirest.http.*; -import io.github.openunirest.http.options.Options; +import unirest.*; import org.junit.Before; -import util.TestUtil; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import static util.TestUtil.read; +import static unirest.TestUtil.read; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; diff --git a/src/test/java/BehaviorTests/CallbackFutureTest.java b/src/test/java/BehaviorTests/CallbackFutureTest.java index c7102d33e..33bab536e 100644 --- a/src/test/java/BehaviorTests/CallbackFutureTest.java +++ b/src/test/java/BehaviorTests/CallbackFutureTest.java @@ -1,10 +1,10 @@ package BehaviorTests; -import io.github.openunirest.http.Unirest; -import util.NoopCallback; +import unirest.Unirest; +import unirest.NoopCallback; import org.junit.Test; -import static util.MockCallback.json; +import static unirest.MockCallback.json; public class CallbackFutureTest extends BddTest { diff --git a/src/test/java/BehaviorTests/DefectTest.java b/src/test/java/BehaviorTests/DefectTest.java index b7400188f..36e0f2588 100644 --- a/src/test/java/BehaviorTests/DefectTest.java +++ b/src/test/java/BehaviorTests/DefectTest.java @@ -1,6 +1,6 @@ package BehaviorTests; -import io.github.openunirest.http.Unirest; +import unirest.Unirest; import org.junit.Test; import java.util.HashMap; diff --git a/src/test/java/BehaviorTests/FormPostingTest.java b/src/test/java/BehaviorTests/FormPostingTest.java index c0a55ad19..d82ef36ab 100644 --- a/src/test/java/BehaviorTests/FormPostingTest.java +++ b/src/test/java/BehaviorTests/FormPostingTest.java @@ -1,13 +1,13 @@ package BehaviorTests; -import io.github.openunirest.http.Unirest; -import io.github.openunirest.request.HttpRequest; +import unirest.Unirest; +import unirest.HttpRequest; import org.apache.commons.io.IOUtils; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.HttpMultipartMode; import org.junit.Test; -import util.MockCallback; -import util.TestUtil; +import unirest.MockCallback; +import unirest.TestUtil; import java.io.ByteArrayInputStream; import java.io.File; diff --git a/src/test/java/BehaviorTests/GZipTest.java b/src/test/java/BehaviorTests/GZipTest.java index b1ac1906e..e9b514814 100644 --- a/src/test/java/BehaviorTests/GZipTest.java +++ b/src/test/java/BehaviorTests/GZipTest.java @@ -1,6 +1,6 @@ package BehaviorTests; -import io.github.openunirest.http.Unirest; +import unirest.Unirest; import org.junit.Test; public class GZipTest extends BddTest { diff --git a/src/test/java/BehaviorTests/HeaderTest.java b/src/test/java/BehaviorTests/HeaderTest.java index 013d6517f..06eb53611 100644 --- a/src/test/java/BehaviorTests/HeaderTest.java +++ b/src/test/java/BehaviorTests/HeaderTest.java @@ -1,18 +1,18 @@ package BehaviorTests; -import io.github.openunirest.http.Headers; -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.JsonNode; -import io.github.openunirest.http.Unirest; -import io.github.openunirest.request.GetRequest; +import unirest.Headers; +import unirest.HttpResponse; +import unirest.JsonNode; +import unirest.Unirest; +import unirest.GetRequest; import org.junit.Ignore; import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertEquals; -import static util.TestUtil.assertBasicAuth; -import static util.TestUtil.mapOf; +import static unirest.TestUtil.assertBasicAuth; +import static unirest.TestUtil.mapOf; public class HeaderTest extends BddTest { @Test diff --git a/src/test/java/BehaviorTests/InterceptorTest.java b/src/test/java/BehaviorTests/InterceptorTest.java index 41e18cdf4..abff8b1be 100644 --- a/src/test/java/BehaviorTests/InterceptorTest.java +++ b/src/test/java/BehaviorTests/InterceptorTest.java @@ -1,7 +1,7 @@ package BehaviorTests; -import io.github.openunirest.http.Unirest; -import io.github.openunirest.http.options.Options; +import unirest.Unirest; +import unirest.Options; import org.apache.http.HttpException; import org.apache.http.HttpRequest; import org.apache.http.HttpRequestInterceptor; diff --git a/src/test/java/BehaviorTests/JsonPatchTest.java b/src/test/java/BehaviorTests/JsonPatchTest.java index fa6f17329..f13b28ea0 100644 --- a/src/test/java/BehaviorTests/JsonPatchTest.java +++ b/src/test/java/BehaviorTests/JsonPatchTest.java @@ -1,16 +1,16 @@ package BehaviorTests; import com.google.common.collect.ImmutableMap; -import io.github.openunirest.http.Unirest; +import unirest.Unirest; import org.json.JSONArray; import org.json.JSONObject; import org.junit.Test; import org.skyscreamer.jsonassert.JSONAssert; -import util.TestUtil; +import unirest.TestUtil; import java.io.IOException; -import static io.github.openunirest.request.JsonPatchOperation.*; +import static unirest.JsonPatchOperation.*; public class JsonPatchTest extends BddTest { diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index 50f1681f5..34949a5d4 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -1,16 +1,16 @@ package BehaviorTests; -import io.github.openunirest.http.Unirest; -import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; -import io.github.openunirest.http.options.Options; -import io.github.openunirest.http.utils.SyncIdleConnectionMonitorThread; +import unirest.Unirest; +import unirest.AsyncIdleConnectionMonitorThread; +import unirest.Options; +import unirest.SyncIdleConnectionMonitorThread; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.junit.Test; import java.io.IOException; -import static io.github.openunirest.http.options.Option.*; +import static unirest.Option.*; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.*; diff --git a/src/test/java/BehaviorTests/MockServer.java b/src/test/java/BehaviorTests/MockServer.java index bdd79f6d7..a3b132397 100644 --- a/src/test/java/BehaviorTests/MockServer.java +++ b/src/test/java/BehaviorTests/MockServer.java @@ -26,12 +26,11 @@ a copy of this software and associated documentation files (the package BehaviorTests; -import io.github.openunirest.http.JacksonObjectMapper; +import unirest.JacksonObjectMapper; import spark.Request; import spark.Response; import spark.Spark; -import java.util.Arrays; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; diff --git a/src/test/java/BehaviorTests/PathParamTest.java b/src/test/java/BehaviorTests/PathParamTest.java index 066c3fbcf..d4052d2ea 100644 --- a/src/test/java/BehaviorTests/PathParamTest.java +++ b/src/test/java/BehaviorTests/PathParamTest.java @@ -1,9 +1,9 @@ package BehaviorTests; -import io.github.openunirest.http.Unirest; -import io.github.openunirest.http.exceptions.UnirestException; +import unirest.Unirest; +import unirest.UnirestException; import org.junit.Test; -import util.TestUtil; +import unirest.TestUtil; public class PathParamTest extends BddTest { diff --git a/src/test/java/BehaviorTests/QueryStringTest.java b/src/test/java/BehaviorTests/QueryStringTest.java index 7934b29e8..2f1716e51 100644 --- a/src/test/java/BehaviorTests/QueryStringTest.java +++ b/src/test/java/BehaviorTests/QueryStringTest.java @@ -1,8 +1,8 @@ package BehaviorTests; -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.JsonNode; -import io.github.openunirest.http.Unirest; +import unirest.HttpResponse; +import unirest.JsonNode; +import unirest.Unirest; import org.junit.Test; import java.util.Arrays; diff --git a/src/test/java/BehaviorTests/RedirectHandling.java b/src/test/java/BehaviorTests/RedirectHandling.java index 51cd4b497..1940b15b8 100644 --- a/src/test/java/BehaviorTests/RedirectHandling.java +++ b/src/test/java/BehaviorTests/RedirectHandling.java @@ -1,8 +1,8 @@ package BehaviorTests; -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.Unirest; -import io.github.openunirest.http.options.Options; +import unirest.HttpResponse; +import unirest.Unirest; +import unirest.Options; import org.junit.Test; import java.util.concurrent.ExecutionException; diff --git a/src/test/java/BehaviorTests/RequestCapture.java b/src/test/java/BehaviorTests/RequestCapture.java index f2b6c7a6a..dc898abf2 100644 --- a/src/test/java/BehaviorTests/RequestCapture.java +++ b/src/test/java/BehaviorTests/RequestCapture.java @@ -4,14 +4,14 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import com.google.common.collect.Sets; -import io.github.openunirest.http.*; -import io.github.openunirest.request.JsonPatch; -import io.github.openunirest.request.JsonPatchItem; -import io.github.openunirest.request.JsonPatchOperation; +import unirest.JsonPatch; +import unirest.JsonPatchItem; +import unirest.JsonPatchOperation; import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.entity.ContentType; import spark.Request; -import util.TestUtil; +import unirest.HttpMethod; +import unirest.TestUtil; import javax.servlet.MultipartConfigElement; import javax.servlet.ServletException; @@ -21,7 +21,7 @@ import java.util.*; import java.util.stream.Collectors; -import static io.github.openunirest.request.JsonPatchRequest.CONTENT_TYPE; +import static unirest.JsonPatchRequest.CONTENT_TYPE; import static java.lang.System.getProperty; import static org.hamcrest.CoreMatchers.endsWith; import static org.hamcrest.CoreMatchers.hasItem; diff --git a/src/test/java/BehaviorTests/SendBodyTest.java b/src/test/java/BehaviorTests/SendBodyTest.java index 336fd66c4..dcde5ddc8 100644 --- a/src/test/java/BehaviorTests/SendBodyTest.java +++ b/src/test/java/BehaviorTests/SendBodyTest.java @@ -1,14 +1,14 @@ package BehaviorTests; -import io.github.openunirest.http.JsonNode; -import io.github.openunirest.http.Unirest; -import io.github.openunirest.http.exceptions.UnirestConfigException; +import unirest.JsonNode; +import unirest.Unirest; +import unirest.UnirestConfigException; import org.json.JSONArray; import org.json.JSONObject; import org.junit.Test; -import util.MockCallback; +import unirest.MockCallback; -import static util.TestUtil.assertException; +import static unirest.TestUtil.assertException; public class SendBodyTest extends BddTest { @Test diff --git a/src/test/java/BehaviorTests/TimeoutTests.java b/src/test/java/BehaviorTests/TimeoutTests.java index c24c82614..5502cd3fa 100644 --- a/src/test/java/BehaviorTests/TimeoutTests.java +++ b/src/test/java/BehaviorTests/TimeoutTests.java @@ -26,9 +26,9 @@ a copy of this software and associated documentation files (the package BehaviorTests; -import io.github.openunirest.http.Unirest; -import io.github.openunirest.http.exceptions.UnirestException; -import io.github.openunirest.http.options.Options; +import unirest.Unirest; +import unirest.UnirestException; +import unirest.Options; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; import org.junit.Ignore; diff --git a/src/test/java/BehaviorTests/VerbTest.java b/src/test/java/BehaviorTests/VerbTest.java index 7b260f1ec..a8cd013cf 100644 --- a/src/test/java/BehaviorTests/VerbTest.java +++ b/src/test/java/BehaviorTests/VerbTest.java @@ -1,8 +1,8 @@ package BehaviorTests; -import io.github.openunirest.http.HttpMethod; -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.Unirest; +import unirest.HttpMethod; +import unirest.HttpResponse; +import unirest.Unirest; import org.junit.Test; import java.io.InputStream; diff --git a/src/test/java/io/github/openunirest/http/GsonObjectMapper.java b/src/test/java/unirest/GsonObjectMapper.java similarity index 85% rename from src/test/java/io/github/openunirest/http/GsonObjectMapper.java rename to src/test/java/unirest/GsonObjectMapper.java index cfbdf2131..578743854 100644 --- a/src/test/java/io/github/openunirest/http/GsonObjectMapper.java +++ b/src/test/java/unirest/GsonObjectMapper.java @@ -1,7 +1,8 @@ -package io.github.openunirest.http; +package unirest; import com.google.gson.Gson; -import io.github.openunirest.request.GenericType; +import unirest.GenericType; +import unirest.ObjectMapper; public class GsonObjectMapper implements ObjectMapper { diff --git a/src/test/java/io/github/openunirest/request/HttpResponseTest.java b/src/test/java/unirest/HttpResponseTest.java similarity index 80% rename from src/test/java/io/github/openunirest/request/HttpResponseTest.java rename to src/test/java/unirest/HttpResponseTest.java index 55323524e..87a03921d 100644 --- a/src/test/java/io/github/openunirest/request/HttpResponseTest.java +++ b/src/test/java/unirest/HttpResponseTest.java @@ -1,11 +1,12 @@ -package io.github.openunirest.request; +package unirest; -import io.github.openunirest.MockApacheResponse; +import unirest.MockApacheResponse; import org.junit.Test; -import util.TestUtil; +import unirest.HttpResponseImpl; +import unirest.TestUtil; import static org.junit.Assert.assertEquals; -import static util.TestUtil.emptyInput; +import static unirest.TestUtil.emptyInput; public class HttpResponseTest { diff --git a/src/test/java/io/github/openunirest/http/JacksonObjectMapper.java b/src/test/java/unirest/JacksonObjectMapper.java similarity index 94% rename from src/test/java/io/github/openunirest/http/JacksonObjectMapper.java rename to src/test/java/unirest/JacksonObjectMapper.java index c25323079..fa3d559e6 100644 --- a/src/test/java/io/github/openunirest/http/JacksonObjectMapper.java +++ b/src/test/java/unirest/JacksonObjectMapper.java @@ -1,4 +1,4 @@ -package io.github.openunirest.http; +package unirest; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; @@ -9,10 +9,11 @@ import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.datatype.guava.GuavaModule; -import io.github.openunirest.request.GenericType; -import io.github.openunirest.request.JsonPatch; -import io.github.openunirest.request.JsonPatchItem; +import unirest.GenericType; +import unirest.JsonPatch; +import unirest.JsonPatchItem; import org.json.JSONObject; +import unirest.ObjectMapper; import java.io.IOException; import java.io.InputStream; diff --git a/src/test/java/io/github/openunirest/http/JacksonObjectMapperTest.java b/src/test/java/unirest/JacksonObjectMapperTest.java similarity index 92% rename from src/test/java/io/github/openunirest/http/JacksonObjectMapperTest.java rename to src/test/java/unirest/JacksonObjectMapperTest.java index cfc31fe60..55907f976 100644 --- a/src/test/java/io/github/openunirest/http/JacksonObjectMapperTest.java +++ b/src/test/java/unirest/JacksonObjectMapperTest.java @@ -1,7 +1,6 @@ -package io.github.openunirest.http; +package unirest; import BehaviorTests.RequestCapture; -import io.github.openunirest.request.JsonPatch; import org.junit.Test; import org.skyscreamer.jsonassert.JSONAssert; diff --git a/src/test/java/io/github/openunirest/http/JsonNodeTest.java b/src/test/java/unirest/JsonNodeTest.java similarity index 96% rename from src/test/java/io/github/openunirest/http/JsonNodeTest.java rename to src/test/java/unirest/JsonNodeTest.java index 2b2efa84e..fc0d6cf28 100644 --- a/src/test/java/io/github/openunirest/http/JsonNodeTest.java +++ b/src/test/java/unirest/JsonNodeTest.java @@ -1,6 +1,7 @@ -package io.github.openunirest.http; +package unirest; import org.junit.Test; +import unirest.JsonNode; import static org.junit.Assert.*; diff --git a/src/test/java/io/github/openunirest/MockApacheResponse.java b/src/test/java/unirest/MockApacheResponse.java similarity index 98% rename from src/test/java/io/github/openunirest/MockApacheResponse.java rename to src/test/java/unirest/MockApacheResponse.java index 4cc2fe700..ed29c1ca3 100644 --- a/src/test/java/io/github/openunirest/MockApacheResponse.java +++ b/src/test/java/unirest/MockApacheResponse.java @@ -1,8 +1,9 @@ -package io.github.openunirest; +package unirest; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import org.apache.http.*; +import org.apache.http.HttpResponse; import org.apache.http.entity.BasicHttpEntity; import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicStatusLine; diff --git a/src/test/java/util/MockCallback.java b/src/test/java/unirest/MockCallback.java similarity index 84% rename from src/test/java/util/MockCallback.java rename to src/test/java/unirest/MockCallback.java index f65b55b3e..062065031 100644 --- a/src/test/java/util/MockCallback.java +++ b/src/test/java/unirest/MockCallback.java @@ -1,10 +1,6 @@ -package util; +package unirest; import BehaviorTests.BddTest; -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.JsonNode; -import io.github.openunirest.http.async.Callback; -import io.github.openunirest.http.exceptions.UnirestException; import java.util.function.Consumer; diff --git a/src/test/java/util/NoopCallback.java b/src/test/java/unirest/NoopCallback.java similarity index 59% rename from src/test/java/util/NoopCallback.java rename to src/test/java/unirest/NoopCallback.java index c41e3b783..d387841a6 100644 --- a/src/test/java/util/NoopCallback.java +++ b/src/test/java/unirest/NoopCallback.java @@ -1,8 +1,8 @@ -package util; +package unirest; -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.async.Callback; -import io.github.openunirest.http.exceptions.UnirestException; +import unirest.HttpResponse; +import unirest.Callback; +import unirest.UnirestException; public class NoopCallback implements Callback { @Override diff --git a/src/test/java/io/github/openunirest/NotImplimented.java b/src/test/java/unirest/NotImplimented.java similarity index 65% rename from src/test/java/io/github/openunirest/NotImplimented.java rename to src/test/java/unirest/NotImplimented.java index 7af0d99d3..f876df344 100644 --- a/src/test/java/io/github/openunirest/NotImplimented.java +++ b/src/test/java/unirest/NotImplimented.java @@ -1,4 +1,4 @@ -package io.github.openunirest; +package unirest; public class NotImplimented extends RuntimeException { } diff --git a/src/test/java/io/github/openunirest/http/options/OptionsTest.java b/src/test/java/unirest/OptionsTest.java similarity index 92% rename from src/test/java/io/github/openunirest/http/options/OptionsTest.java rename to src/test/java/unirest/OptionsTest.java index 0bcd1d33d..81a432d54 100644 --- a/src/test/java/io/github/openunirest/http/options/OptionsTest.java +++ b/src/test/java/unirest/OptionsTest.java @@ -1,17 +1,19 @@ -package io.github.openunirest.http.options; +package unirest; -import io.github.openunirest.http.JacksonObjectMapper; +import unirest.JacksonObjectMapper; import org.apache.http.HttpRequestInterceptor; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.junit.After; -import io.github.openunirest.http.ObjectMapper; +import unirest.ObjectMapper; import org.junit.Before; import org.junit.Test; +import unirest.Option; +import unirest.Options; import java.lang.management.ManagementFactory; import java.util.stream.IntStream; -import static io.github.openunirest.http.options.Option.CONNECTION_TIMEOUT; +import static unirest.Option.CONNECTION_TIMEOUT; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.lessThan; import static org.junit.Assert.*; diff --git a/src/test/java/io/github/openunirest/request/ResponseBuilderTest.java b/src/test/java/unirest/ResponseBuilderTest.java similarity index 87% rename from src/test/java/io/github/openunirest/request/ResponseBuilderTest.java rename to src/test/java/unirest/ResponseBuilderTest.java index af6a15465..39605d0bd 100644 --- a/src/test/java/io/github/openunirest/request/ResponseBuilderTest.java +++ b/src/test/java/unirest/ResponseBuilderTest.java @@ -1,25 +1,21 @@ -package io.github.openunirest.request; +package unirest; import BehaviorTests.Foo; -import io.github.openunirest.MockApacheResponse; -import io.github.openunirest.http.HttpResponse; -import io.github.openunirest.http.JacksonObjectMapper; -import io.github.openunirest.http.JsonNode; -import io.github.openunirest.http.exceptions.UnirestException; -import io.github.openunirest.http.options.Option; -import io.github.openunirest.http.options.Options; +import unirest.MockApacheResponse; +import unirest.*; +import unirest.JacksonObjectMapper; import org.apache.http.ProtocolVersion; import org.apache.http.message.BasicStatusLine; import org.junit.Before; import org.junit.Test; -import util.TestUtil; +import unirest.TestUtil; import java.io.InputStream; import static org.hamcrest.CoreMatchers.hasItem; import static org.junit.Assert.*; -import static util.TestUtil.assertException; -import static util.TestUtil.toJson; +import static unirest.TestUtil.assertException; +import static unirest.TestUtil.toJson; public class ResponseBuilderTest { private final ResponseBuilder builder = new ResponseBuilder(); diff --git a/src/test/java/io/github/openunirest/http/utils/ResponseUtilsTest.java b/src/test/java/unirest/ResponseUtilsTest.java similarity index 95% rename from src/test/java/io/github/openunirest/http/utils/ResponseUtilsTest.java rename to src/test/java/unirest/ResponseUtilsTest.java index 50f369401..e59d6097f 100644 --- a/src/test/java/io/github/openunirest/http/utils/ResponseUtilsTest.java +++ b/src/test/java/unirest/ResponseUtilsTest.java @@ -1,8 +1,9 @@ -package io.github.openunirest.http.utils; +package unirest; import org.apache.http.HttpEntity; import org.apache.http.entity.BasicHttpEntity; import org.junit.Test; +import unirest.ResponseUtils; import static org.junit.Assert.*; diff --git a/src/test/java/util/TestUtil.java b/src/test/java/unirest/TestUtil.java similarity index 98% rename from src/test/java/util/TestUtil.java rename to src/test/java/unirest/TestUtil.java index f7c8efa97..593241cc2 100644 --- a/src/test/java/util/TestUtil.java +++ b/src/test/java/unirest/TestUtil.java @@ -1,11 +1,11 @@ -package util; +package unirest; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.guava.GuavaModule; import com.google.common.base.Charsets; import com.google.common.io.Resources; -import io.github.openunirest.http.HttpResponse; +import unirest.HttpResponse; import java.io.*; import java.util.Base64; diff --git a/src/test/java/io/github/openunirest/request/UriFormatterTest.java b/src/test/java/unirest/UriFormatterTest.java similarity index 89% rename from src/test/java/io/github/openunirest/request/UriFormatterTest.java rename to src/test/java/unirest/UriFormatterTest.java index 5fa3fc998..59da4ddde 100644 --- a/src/test/java/io/github/openunirest/request/UriFormatterTest.java +++ b/src/test/java/unirest/UriFormatterTest.java @@ -1,7 +1,9 @@ -package io.github.openunirest.request; +package unirest; -import io.github.openunirest.http.HttpMethod; +import unirest.HttpMethod; import org.junit.Test; +import unirest.HttpRequest; +import unirest.UriFormatter; import static org.junit.Assert.assertEquals; From 14ce96f7b3524bef495cbf215208c5f94129b5cb Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 1 Nov 2018 15:31:39 -0500 Subject: [PATCH 0226/1769] clean up options and move the client 'factory' into options so everything is in the same place --- src/main/java/unirest/ClientFactory.java | 16 ---------------- src/main/java/unirest/HttpClientHelper.java | 4 ++-- src/main/java/unirest/Option.java | 19 ++++--------------- src/main/java/unirest/Options.java | 9 +++++++++ 4 files changed, 15 insertions(+), 33 deletions(-) delete mode 100644 src/main/java/unirest/ClientFactory.java diff --git a/src/main/java/unirest/ClientFactory.java b/src/main/java/unirest/ClientFactory.java deleted file mode 100644 index b4f3b2700..000000000 --- a/src/main/java/unirest/ClientFactory.java +++ /dev/null @@ -1,16 +0,0 @@ -package unirest; - -import org.apache.http.client.HttpClient; -import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; - -public class ClientFactory { - - public static HttpClient getHttpClient() { - return (HttpClient) Options.getOption(Option.HTTPCLIENT); - } - - public static CloseableHttpAsyncClient getAsyncHttpClient() { - return (CloseableHttpAsyncClient) Options.getOption(Option.ASYNCHTTPCLIENT); - } - -} diff --git a/src/main/java/unirest/HttpClientHelper.java b/src/main/java/unirest/HttpClientHelper.java index 44d90d562..ae6c4a46d 100644 --- a/src/main/java/unirest/HttpClientHelper.java +++ b/src/main/java/unirest/HttpClientHelper.java @@ -16,7 +16,7 @@ public static HttpResponse request(HttpRequest request, Function> transformer) { HttpRequestBase requestObj = RequestPrep.prepareRequest(request, false); - HttpClient client = ClientFactory.getHttpClient(); // The + HttpClient client = Options.getHttpClient(); // The // DefaultHttpClient // is thread-safe @@ -69,7 +69,7 @@ public void cancelled() { } private static CloseableHttpAsyncClient asyncClient() { - CloseableHttpAsyncClient asyncHttpClient = ClientFactory.getAsyncHttpClient(); + CloseableHttpAsyncClient asyncHttpClient = Options.getAsyncHttpClient(); if (!asyncHttpClient.isRunning()) { tryStart(asyncHttpClient); } diff --git a/src/main/java/unirest/Option.java b/src/main/java/unirest/Option.java index adfa7f8a0..e026b6fef 100644 --- a/src/main/java/unirest/Option.java +++ b/src/main/java/unirest/Option.java @@ -1,28 +1,17 @@ package unirest; public enum Option { - HTTPCLIENT(false), - ASYNCHTTPCLIENT(false), + HTTPCLIENT, + ASYNCHTTPCLIENT, CONNECTION_TIMEOUT, SOCKET_TIMEOUT, DEFAULT_HEADERS, - SYNC_MONITOR(false), - ASYNC_MONITOR(false), + SYNC_MONITOR, + ASYNC_MONITOR, MAX_TOTAL, MAX_PER_ROUTE, PROXY, OBJECT_MAPPER, FOLLOW_REDIRECTS, COOKIE_MANAGEMENT; - - private final boolean canSurviveShutdown; - - Option(){this(true);} - Option(boolean canSurviveShutdown){ - this.canSurviveShutdown = canSurviveShutdown; - } - - public boolean canSurviveShutdown() { - return canSurviveShutdown; - } } diff --git a/src/main/java/unirest/Options.java b/src/main/java/unirest/Options.java index 42cfe6539..3689902ff 100644 --- a/src/main/java/unirest/Options.java +++ b/src/main/java/unirest/Options.java @@ -2,6 +2,7 @@ import org.apache.http.HttpHost; import org.apache.http.HttpRequestInterceptor; +import org.apache.http.client.HttpClient; import org.apache.http.client.config.RequestConfig; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; @@ -251,4 +252,12 @@ public static void enableCookieManagement(boolean enable){ public static List getInterceptors() { return interceptors; } + + public static HttpClient getHttpClient() { + return (HttpClient) getOption(Option.HTTPCLIENT); + } + + public static CloseableHttpAsyncClient getAsyncHttpClient() { + return (CloseableHttpAsyncClient) getOption(Option.ASYNCHTTPCLIENT); + } } From 1abf31a44cea7ca0401bd7d3ab1bedc37f0832a0 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 1 Nov 2018 15:36:02 -0500 Subject: [PATCH 0227/1769] move the headers above the package so Intellij folds them --- src/main/java/unirest/JsonPatch.java | 4 ++-- src/main/java/unirest/JsonPatchItem.java | 4 ++-- src/main/java/unirest/JsonPatchOperation.java | 4 ++-- src/main/java/unirest/JsonPatchRequest.java | 3 ++- src/main/java/unirest/ResponseBuilder.java | 1 - 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/unirest/JsonPatch.java b/src/main/java/unirest/JsonPatch.java index 7bed32af5..11019bb39 100644 --- a/src/main/java/unirest/JsonPatch.java +++ b/src/main/java/unirest/JsonPatch.java @@ -1,5 +1,3 @@ -package unirest; - /* The MIT License @@ -25,6 +23,8 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +package unirest; + import org.json.JSONArray; import org.json.JSONObject; diff --git a/src/main/java/unirest/JsonPatchItem.java b/src/main/java/unirest/JsonPatchItem.java index 05f619907..823f7dd23 100644 --- a/src/main/java/unirest/JsonPatchItem.java +++ b/src/main/java/unirest/JsonPatchItem.java @@ -1,5 +1,3 @@ -package unirest; - /* The MIT License @@ -25,6 +23,8 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +package unirest; + import org.json.JSONObject; import java.util.Objects; diff --git a/src/main/java/unirest/JsonPatchOperation.java b/src/main/java/unirest/JsonPatchOperation.java index 0072c1d6f..c54746958 100644 --- a/src/main/java/unirest/JsonPatchOperation.java +++ b/src/main/java/unirest/JsonPatchOperation.java @@ -1,5 +1,3 @@ -package unirest; - /* The MIT License @@ -25,6 +23,8 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +package unirest; + public enum JsonPatchOperation { add("value"), remove("value"), diff --git a/src/main/java/unirest/JsonPatchRequest.java b/src/main/java/unirest/JsonPatchRequest.java index 6c503b14e..186dcaef9 100644 --- a/src/main/java/unirest/JsonPatchRequest.java +++ b/src/main/java/unirest/JsonPatchRequest.java @@ -1,4 +1,3 @@ -package unirest; /* The MIT License @@ -24,6 +23,8 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +package unirest; + import org.apache.http.HttpEntity; import org.apache.http.entity.BasicHttpEntity; diff --git a/src/main/java/unirest/ResponseBuilder.java b/src/main/java/unirest/ResponseBuilder.java index d4de53180..32ce84c5b 100644 --- a/src/main/java/unirest/ResponseBuilder.java +++ b/src/main/java/unirest/ResponseBuilder.java @@ -1,6 +1,5 @@ package unirest; - import java.io.InputStream; import java.io.UnsupportedEncodingException; From c6e4bd6ef8f8bf3f0abca0776d32a05f1b86b2a4 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 1 Nov 2018 15:47:51 -0500 Subject: [PATCH 0228/1769] update licenses --- build/fileHeader.txt | 23 ++++++++ docs/styles/fonts.css | 26 ++++++++ docs/styles/homepage.css | 26 ++++++++ docs/styles/library.css | 26 ++++++++ docs/styles/normalize.css | 26 ++++++++ pom.xml | 30 ++++++++++ .../AsyncIdleConnectionMonitorThread.java | 26 ++++++++ src/main/java/unirest/BaseRequest.java | 48 +++++++-------- src/main/java/unirest/Body.java | 48 +++++++-------- src/main/java/unirest/BodyData.java | 26 ++++++++ src/main/java/unirest/Callback.java | 48 +++++++-------- src/main/java/unirest/CallbackFuture.java | 26 ++++++++ src/main/java/unirest/FormPart.java | 26 ++++++++ src/main/java/unirest/GenericType.java | 59 ++++++++++--------- src/main/java/unirest/GetRequest.java | 48 +++++++-------- src/main/java/unirest/Headers.java | 26 ++++++++ src/main/java/unirest/HttpClientHelper.java | 26 ++++++++ src/main/java/unirest/HttpDeleteWithBody.java | 48 +++++++-------- src/main/java/unirest/HttpMethod.java | 48 +++++++-------- src/main/java/unirest/HttpPatchWithBody.java | 48 +++++++-------- src/main/java/unirest/HttpRequest.java | 48 +++++++-------- .../java/unirest/HttpRequestWithBody.java | 48 +++++++-------- src/main/java/unirest/HttpResponse.java | 26 ++++++++ src/main/java/unirest/HttpResponseImpl.java | 48 +++++++-------- src/main/java/unirest/JsonNode.java | 48 +++++++-------- src/main/java/unirest/JsonPatch.java | 47 +++++++-------- src/main/java/unirest/JsonPatchItem.java | 47 +++++++-------- src/main/java/unirest/JsonPatchOperation.java | 47 +++++++-------- src/main/java/unirest/JsonPatchRequest.java | 47 +++++++-------- src/main/java/unirest/MapUtil.java | 48 +++++++-------- src/main/java/unirest/MultipartBody.java | 48 +++++++-------- src/main/java/unirest/NoRedirects.java | 26 ++++++++ src/main/java/unirest/ObjectMapper.java | 26 ++++++++ src/main/java/unirest/Option.java | 26 ++++++++ src/main/java/unirest/Options.java | 26 ++++++++ src/main/java/unirest/RawBody.java | 48 +++++++-------- src/main/java/unirest/RequestBodyEntity.java | 48 +++++++-------- src/main/java/unirest/RequestPrep.java | 26 ++++++++ src/main/java/unirest/ResponseBuilder.java | 26 ++++++++ src/main/java/unirest/ResponseUtils.java | 26 ++++++++ .../SyncIdleConnectionMonitorThread.java | 26 ++++++++ src/main/java/unirest/URLParamEncoder.java | 48 +++++++-------- src/main/java/unirest/Unirest.java | 48 +++++++-------- .../java/unirest/UnirestConfigException.java | 26 ++++++++ src/main/java/unirest/UnirestException.java | 26 ++++++++ src/main/java/unirest/UriFormatter.java | 26 ++++++++ src/test/java/BehaviorTests/AsBinaryTest.java | 26 ++++++++ .../java/BehaviorTests/AsGenericTypeTest.java | 26 ++++++++ src/test/java/BehaviorTests/AsJsonTest.java | 26 ++++++++ src/test/java/BehaviorTests/AsObjectTest.java | 26 ++++++++ src/test/java/BehaviorTests/AsStringTest.java | 26 ++++++++ src/test/java/BehaviorTests/BddTest.java | 26 ++++++++ .../BehaviorTests/CallbackFutureTest.java | 26 ++++++++ src/test/java/BehaviorTests/DefectTest.java | 26 ++++++++ src/test/java/BehaviorTests/Foo.java | 26 ++++++++ .../java/BehaviorTests/FormPostingTest.java | 26 ++++++++ src/test/java/BehaviorTests/GZipTest.java | 26 ++++++++ src/test/java/BehaviorTests/GetResponse.java | 26 ++++++++ src/test/java/BehaviorTests/HeaderTest.java | 26 ++++++++ .../java/BehaviorTests/InterceptorTest.java | 26 ++++++++ .../java/BehaviorTests/JsonPatchTest.java | 26 ++++++++ .../java/BehaviorTests/LifeCycleTest.java | 26 ++++++++ src/test/java/BehaviorTests/MockServer.java | 26 ++++++++ .../java/BehaviorTests/PathParamTest.java | 26 ++++++++ .../java/BehaviorTests/QueryStringTest.java | 26 ++++++++ .../java/BehaviorTests/RedirectHandling.java | 26 ++++++++ .../java/BehaviorTests/RequestCapture.java | 26 ++++++++ src/test/java/BehaviorTests/SendBodyTest.java | 26 ++++++++ src/test/java/BehaviorTests/TimeoutTests.java | 50 ++++++++-------- src/test/java/BehaviorTests/VerbTest.java | 26 ++++++++ src/test/java/unirest/GsonObjectMapper.java | 26 ++++++++ src/test/java/unirest/HttpResponseTest.java | 26 ++++++++ .../java/unirest/JacksonObjectMapper.java | 26 ++++++++ .../java/unirest/JacksonObjectMapperTest.java | 26 ++++++++ src/test/java/unirest/JsonNodeTest.java | 26 ++++++++ src/test/java/unirest/MockApacheResponse.java | 26 ++++++++ src/test/java/unirest/MockCallback.java | 26 ++++++++ src/test/java/unirest/NoopCallback.java | 26 ++++++++ src/test/java/unirest/NotImplimented.java | 26 ++++++++ src/test/java/unirest/OptionsTest.java | 26 ++++++++ .../java/unirest/ResponseBuilderTest.java | 26 ++++++++ src/test/java/unirest/ResponseUtilsTest.java | 26 ++++++++ src/test/java/unirest/TestUtil.java | 26 ++++++++ src/test/java/unirest/UriFormatterTest.java | 26 ++++++++ 84 files changed, 2147 insertions(+), 553 deletions(-) create mode 100644 build/fileHeader.txt diff --git a/build/fileHeader.txt b/build/fileHeader.txt new file mode 100644 index 000000000..8b23035b1 --- /dev/null +++ b/build/fileHeader.txt @@ -0,0 +1,23 @@ +The MIT License + +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/docs/styles/fonts.css b/docs/styles/fonts.css index a3334fbf2..abf68bd76 100644 --- a/docs/styles/fonts.css +++ b/docs/styles/fonts.css @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + @font-face { font-family: 'Open Sans'; font-style: normal; diff --git a/docs/styles/homepage.css b/docs/styles/homepage.css index 373eb70bb..0141ca1f8 100644 --- a/docs/styles/homepage.css +++ b/docs/styles/homepage.css @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + @import url('fonts.css'); @import url('normalize.css'); diff --git a/docs/styles/library.css b/docs/styles/library.css index e91f9be69..f0d39d8db 100644 --- a/docs/styles/library.css +++ b/docs/styles/library.css @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + @import url('fonts.css'); @import url('normalize.css'); diff --git a/docs/styles/normalize.css b/docs/styles/normalize.css index 8aea936bc..a5ffe0cca 100644 --- a/docs/styles/normalize.css +++ b/docs/styles/normalize.css @@ -1 +1,27 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + /*! normalize.css v2.0.1 | MIT License | git.io/normalize */article,aside,details,figcaption,figure,footer,header,hgroup,nav,section,summary{display:block}audio,canvas,video{display:inline-block}audio:not([controls]){display:none;height:0}[hidden]{display:none}html{font-family:sans-serif;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}body{margin:0}a:focus{outline:thin dotted}a:active,a:hover{outline:0}h1{font-size:2em}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}dfn{font-style:italic}mark{background:#ff0;color:#000}code,kbd,pre,samp{font-family:monospace,serif;font-size:1em}pre{white-space:pre;white-space:pre-wrap;word-wrap:break-word}q{quotes:"\201C" "\201D" "\2018" "\2019"}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:0}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:.35em .625em .75em}legend{border:0;padding:0}button,input,select,textarea{font-family:inherit;font-size:100%;margin:0}button,input{line-height:normal}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}button[disabled],input[disabled]{cursor:default}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}textarea{overflow:auto;vertical-align:top}table{border-collapse:collapse;border-spacing:0} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5f3c46ff6..77fe2ae4d 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,36 @@ + + com.mycila.maven-license-plugin + maven-license-plugin + 1.8.0 + + +
build/fileHeader.txt
+ true + + **/*.html + **/*.xml + **/*.txt + **/*.log + **/*.md + **/*.yml + .idea/** + .github/** + .git* + LICENSE + +
+ + + validate + + format + + + +
org.apache.maven.plugins maven-jar-plugin diff --git a/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java b/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java index ab00de7ec..f0a34e8b6 100644 --- a/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java +++ b/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import java.util.concurrent.TimeUnit; diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index f99e0b109..67ec5f6bf 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -1,27 +1,27 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/Body.java b/src/main/java/unirest/Body.java index e8afaf4a1..ee967fb36 100644 --- a/src/main/java/unirest/Body.java +++ b/src/main/java/unirest/Body.java @@ -1,27 +1,27 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/BodyData.java b/src/main/java/unirest/BodyData.java index b156a0332..3ea967239 100644 --- a/src/main/java/unirest/BodyData.java +++ b/src/main/java/unirest/BodyData.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import org.apache.http.HttpEntity; diff --git a/src/main/java/unirest/Callback.java b/src/main/java/unirest/Callback.java index ae9c2bece..cd57bf9d8 100644 --- a/src/main/java/unirest/Callback.java +++ b/src/main/java/unirest/Callback.java @@ -1,27 +1,27 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/CallbackFuture.java b/src/main/java/unirest/CallbackFuture.java index 2990a9a33..293cc67e8 100644 --- a/src/main/java/unirest/CallbackFuture.java +++ b/src/main/java/unirest/CallbackFuture.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import java.util.concurrent.CompletableFuture; diff --git a/src/main/java/unirest/FormPart.java b/src/main/java/unirest/FormPart.java index 7e4e0ed0e..585de25ae 100644 --- a/src/main/java/unirest/FormPart.java +++ b/src/main/java/unirest/FormPart.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import org.apache.http.entity.ContentType; diff --git a/src/main/java/unirest/GenericType.java b/src/main/java/unirest/GenericType.java index 066fcb04f..322b1908b 100644 --- a/src/main/java/unirest/GenericType.java +++ b/src/main/java/unirest/GenericType.java @@ -1,4 +1,34 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + /* Parts of this file were taken from Jackson/core TypeReference under the Apache License: @@ -10,36 +40,7 @@ http://www.apache.org/licenses/LICENSE-2.0 -The remaining -=========================== -The MIT License - -Copyright OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; - public abstract class GenericType implements Comparable> { protected final Type type; diff --git a/src/main/java/unirest/GetRequest.java b/src/main/java/unirest/GetRequest.java index 0ec59f1eb..30f17a8b7 100644 --- a/src/main/java/unirest/GetRequest.java +++ b/src/main/java/unirest/GetRequest.java @@ -1,27 +1,27 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/Headers.java b/src/main/java/unirest/Headers.java index 0b38023be..46926270b 100644 --- a/src/main/java/unirest/Headers.java +++ b/src/main/java/unirest/Headers.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import org.apache.http.Header; diff --git a/src/main/java/unirest/HttpClientHelper.java b/src/main/java/unirest/HttpClientHelper.java index ae6c4a46d..1a703a3e1 100644 --- a/src/main/java/unirest/HttpClientHelper.java +++ b/src/main/java/unirest/HttpClientHelper.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import org.apache.http.client.HttpClient; diff --git a/src/main/java/unirest/HttpDeleteWithBody.java b/src/main/java/unirest/HttpDeleteWithBody.java index 370baed4c..ef5e6c96c 100644 --- a/src/main/java/unirest/HttpDeleteWithBody.java +++ b/src/main/java/unirest/HttpDeleteWithBody.java @@ -1,27 +1,27 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/HttpMethod.java b/src/main/java/unirest/HttpMethod.java index 74c55b7e1..bb0a769f4 100644 --- a/src/main/java/unirest/HttpMethod.java +++ b/src/main/java/unirest/HttpMethod.java @@ -1,27 +1,27 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/HttpPatchWithBody.java b/src/main/java/unirest/HttpPatchWithBody.java index 8fc966c5d..810c8fa3b 100644 --- a/src/main/java/unirest/HttpPatchWithBody.java +++ b/src/main/java/unirest/HttpPatchWithBody.java @@ -1,27 +1,27 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index aeea71bc5..2d08c060f 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -1,27 +1,27 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/HttpRequestWithBody.java b/src/main/java/unirest/HttpRequestWithBody.java index 9f73e02da..38b1a7e04 100644 --- a/src/main/java/unirest/HttpRequestWithBody.java +++ b/src/main/java/unirest/HttpRequestWithBody.java @@ -1,27 +1,27 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/HttpResponse.java b/src/main/java/unirest/HttpResponse.java index fceebb302..9f4813eb0 100644 --- a/src/main/java/unirest/HttpResponse.java +++ b/src/main/java/unirest/HttpResponse.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import java.io.InputStream; diff --git a/src/main/java/unirest/HttpResponseImpl.java b/src/main/java/unirest/HttpResponseImpl.java index 4c8458d5d..695be1890 100644 --- a/src/main/java/unirest/HttpResponseImpl.java +++ b/src/main/java/unirest/HttpResponseImpl.java @@ -1,27 +1,27 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/JsonNode.java b/src/main/java/unirest/JsonNode.java index fce4e1eb2..1a2ea77cd 100644 --- a/src/main/java/unirest/JsonNode.java +++ b/src/main/java/unirest/JsonNode.java @@ -1,27 +1,27 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/JsonPatch.java b/src/main/java/unirest/JsonPatch.java index 11019bb39..b3b399235 100644 --- a/src/main/java/unirest/JsonPatch.java +++ b/src/main/java/unirest/JsonPatch.java @@ -1,26 +1,27 @@ -/* -The MIT License - -Copyright OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/JsonPatchItem.java b/src/main/java/unirest/JsonPatchItem.java index 823f7dd23..b0f672a31 100644 --- a/src/main/java/unirest/JsonPatchItem.java +++ b/src/main/java/unirest/JsonPatchItem.java @@ -1,26 +1,27 @@ -/* -The MIT License - -Copyright OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/JsonPatchOperation.java b/src/main/java/unirest/JsonPatchOperation.java index c54746958..a3834421b 100644 --- a/src/main/java/unirest/JsonPatchOperation.java +++ b/src/main/java/unirest/JsonPatchOperation.java @@ -1,26 +1,27 @@ -/* -The MIT License - -Copyright OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/JsonPatchRequest.java b/src/main/java/unirest/JsonPatchRequest.java index 186dcaef9..d564169dd 100644 --- a/src/main/java/unirest/JsonPatchRequest.java +++ b/src/main/java/unirest/JsonPatchRequest.java @@ -1,26 +1,27 @@ -/* -The MIT License - -Copyright OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/MapUtil.java b/src/main/java/unirest/MapUtil.java index d6289b907..c126cee7b 100644 --- a/src/main/java/unirest/MapUtil.java +++ b/src/main/java/unirest/MapUtil.java @@ -1,27 +1,27 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/MultipartBody.java b/src/main/java/unirest/MultipartBody.java index bc38df360..f71fbd314 100644 --- a/src/main/java/unirest/MultipartBody.java +++ b/src/main/java/unirest/MultipartBody.java @@ -1,27 +1,27 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/NoRedirects.java b/src/main/java/unirest/NoRedirects.java index e86edc53e..552b316c1 100644 --- a/src/main/java/unirest/NoRedirects.java +++ b/src/main/java/unirest/NoRedirects.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import org.apache.http.HttpRequest; diff --git a/src/main/java/unirest/ObjectMapper.java b/src/main/java/unirest/ObjectMapper.java index 2c00e67b2..38a486eb7 100644 --- a/src/main/java/unirest/ObjectMapper.java +++ b/src/main/java/unirest/ObjectMapper.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; public interface ObjectMapper { diff --git a/src/main/java/unirest/Option.java b/src/main/java/unirest/Option.java index e026b6fef..b6d2835f5 100644 --- a/src/main/java/unirest/Option.java +++ b/src/main/java/unirest/Option.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; public enum Option { diff --git a/src/main/java/unirest/Options.java b/src/main/java/unirest/Options.java index 3689902ff..14783f906 100644 --- a/src/main/java/unirest/Options.java +++ b/src/main/java/unirest/Options.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import org.apache.http.HttpHost; diff --git a/src/main/java/unirest/RawBody.java b/src/main/java/unirest/RawBody.java index e012be1d0..c0af12eb4 100644 --- a/src/main/java/unirest/RawBody.java +++ b/src/main/java/unirest/RawBody.java @@ -1,27 +1,27 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/RequestBodyEntity.java b/src/main/java/unirest/RequestBodyEntity.java index 81db20837..4f0022201 100644 --- a/src/main/java/unirest/RequestBodyEntity.java +++ b/src/main/java/unirest/RequestBodyEntity.java @@ -1,27 +1,27 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/RequestPrep.java b/src/main/java/unirest/RequestPrep.java index 7dafd2222..4170e3eb8 100644 --- a/src/main/java/unirest/RequestPrep.java +++ b/src/main/java/unirest/RequestPrep.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import org.apache.http.HttpEntity; diff --git a/src/main/java/unirest/ResponseBuilder.java b/src/main/java/unirest/ResponseBuilder.java index 32ce84c5b..c439472bf 100644 --- a/src/main/java/unirest/ResponseBuilder.java +++ b/src/main/java/unirest/ResponseBuilder.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import java.io.InputStream; diff --git a/src/main/java/unirest/ResponseUtils.java b/src/main/java/unirest/ResponseUtils.java index 81c4eea0d..94dfdd0b7 100644 --- a/src/main/java/unirest/ResponseUtils.java +++ b/src/main/java/unirest/ResponseUtils.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import org.apache.http.Header; diff --git a/src/main/java/unirest/SyncIdleConnectionMonitorThread.java b/src/main/java/unirest/SyncIdleConnectionMonitorThread.java index 0ea3c82d4..d92b8440f 100644 --- a/src/main/java/unirest/SyncIdleConnectionMonitorThread.java +++ b/src/main/java/unirest/SyncIdleConnectionMonitorThread.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import java.util.concurrent.TimeUnit; diff --git a/src/main/java/unirest/URLParamEncoder.java b/src/main/java/unirest/URLParamEncoder.java index d07ffb9a4..cb84a3687 100644 --- a/src/main/java/unirest/URLParamEncoder.java +++ b/src/main/java/unirest/URLParamEncoder.java @@ -1,27 +1,27 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/Unirest.java b/src/main/java/unirest/Unirest.java index 7f7f3fa41..367dbaa9a 100644 --- a/src/main/java/unirest/Unirest.java +++ b/src/main/java/unirest/Unirest.java @@ -1,27 +1,27 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package unirest; diff --git a/src/main/java/unirest/UnirestConfigException.java b/src/main/java/unirest/UnirestConfigException.java index 1d814404f..d76852796 100644 --- a/src/main/java/unirest/UnirestConfigException.java +++ b/src/main/java/unirest/UnirestConfigException.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; public class UnirestConfigException extends UnirestException { diff --git a/src/main/java/unirest/UnirestException.java b/src/main/java/unirest/UnirestException.java index d8f1dd2f1..fbf150a7e 100644 --- a/src/main/java/unirest/UnirestException.java +++ b/src/main/java/unirest/UnirestException.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; public class UnirestException extends RuntimeException { diff --git a/src/main/java/unirest/UriFormatter.java b/src/main/java/unirest/UriFormatter.java index a8d9f553e..ef4cbad55 100644 --- a/src/main/java/unirest/UriFormatter.java +++ b/src/main/java/unirest/UriFormatter.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import org.apache.http.client.utils.URIBuilder; diff --git a/src/test/java/BehaviorTests/AsBinaryTest.java b/src/test/java/BehaviorTests/AsBinaryTest.java index 302bdadc8..4496e05c9 100644 --- a/src/test/java/BehaviorTests/AsBinaryTest.java +++ b/src/test/java/BehaviorTests/AsBinaryTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import unirest.HttpResponse; diff --git a/src/test/java/BehaviorTests/AsGenericTypeTest.java b/src/test/java/BehaviorTests/AsGenericTypeTest.java index d61127e07..2b950627e 100644 --- a/src/test/java/BehaviorTests/AsGenericTypeTest.java +++ b/src/test/java/BehaviorTests/AsGenericTypeTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import unirest.GsonObjectMapper; diff --git a/src/test/java/BehaviorTests/AsJsonTest.java b/src/test/java/BehaviorTests/AsJsonTest.java index 5a70fd544..3f00e3e9e 100644 --- a/src/test/java/BehaviorTests/AsJsonTest.java +++ b/src/test/java/BehaviorTests/AsJsonTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import unirest.HttpResponse; diff --git a/src/test/java/BehaviorTests/AsObjectTest.java b/src/test/java/BehaviorTests/AsObjectTest.java index c48b44003..7fc18bee3 100644 --- a/src/test/java/BehaviorTests/AsObjectTest.java +++ b/src/test/java/BehaviorTests/AsObjectTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import unirest.Unirest; diff --git a/src/test/java/BehaviorTests/AsStringTest.java b/src/test/java/BehaviorTests/AsStringTest.java index 0794bf8c8..ec49f4519 100644 --- a/src/test/java/BehaviorTests/AsStringTest.java +++ b/src/test/java/BehaviorTests/AsStringTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import unirest.HttpResponse; diff --git a/src/test/java/BehaviorTests/BddTest.java b/src/test/java/BehaviorTests/BddTest.java index 589572a89..473574fef 100644 --- a/src/test/java/BehaviorTests/BddTest.java +++ b/src/test/java/BehaviorTests/BddTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import unirest.*; diff --git a/src/test/java/BehaviorTests/CallbackFutureTest.java b/src/test/java/BehaviorTests/CallbackFutureTest.java index 33bab536e..cc760236d 100644 --- a/src/test/java/BehaviorTests/CallbackFutureTest.java +++ b/src/test/java/BehaviorTests/CallbackFutureTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import unirest.Unirest; diff --git a/src/test/java/BehaviorTests/DefectTest.java b/src/test/java/BehaviorTests/DefectTest.java index 36e0f2588..907a85fc7 100644 --- a/src/test/java/BehaviorTests/DefectTest.java +++ b/src/test/java/BehaviorTests/DefectTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import unirest.Unirest; diff --git a/src/test/java/BehaviorTests/Foo.java b/src/test/java/BehaviorTests/Foo.java index 7e345d6fd..7dcb38fe3 100644 --- a/src/test/java/BehaviorTests/Foo.java +++ b/src/test/java/BehaviorTests/Foo.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import com.google.common.base.MoreObjects; diff --git a/src/test/java/BehaviorTests/FormPostingTest.java b/src/test/java/BehaviorTests/FormPostingTest.java index d82ef36ab..254338035 100644 --- a/src/test/java/BehaviorTests/FormPostingTest.java +++ b/src/test/java/BehaviorTests/FormPostingTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import unirest.Unirest; diff --git a/src/test/java/BehaviorTests/GZipTest.java b/src/test/java/BehaviorTests/GZipTest.java index e9b514814..7f6326fc3 100644 --- a/src/test/java/BehaviorTests/GZipTest.java +++ b/src/test/java/BehaviorTests/GZipTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import unirest.Unirest; diff --git a/src/test/java/BehaviorTests/GetResponse.java b/src/test/java/BehaviorTests/GetResponse.java index a1e6f9434..096d34edf 100644 --- a/src/test/java/BehaviorTests/GetResponse.java +++ b/src/test/java/BehaviorTests/GetResponse.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; diff --git a/src/test/java/BehaviorTests/HeaderTest.java b/src/test/java/BehaviorTests/HeaderTest.java index 06eb53611..f5ae376eb 100644 --- a/src/test/java/BehaviorTests/HeaderTest.java +++ b/src/test/java/BehaviorTests/HeaderTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import unirest.Headers; diff --git a/src/test/java/BehaviorTests/InterceptorTest.java b/src/test/java/BehaviorTests/InterceptorTest.java index abff8b1be..06027144a 100644 --- a/src/test/java/BehaviorTests/InterceptorTest.java +++ b/src/test/java/BehaviorTests/InterceptorTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import unirest.Unirest; diff --git a/src/test/java/BehaviorTests/JsonPatchTest.java b/src/test/java/BehaviorTests/JsonPatchTest.java index f13b28ea0..27d48e0b7 100644 --- a/src/test/java/BehaviorTests/JsonPatchTest.java +++ b/src/test/java/BehaviorTests/JsonPatchTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import com.google.common.collect.ImmutableMap; diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index 34949a5d4..2e35e72c3 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import unirest.Unirest; diff --git a/src/test/java/BehaviorTests/MockServer.java b/src/test/java/BehaviorTests/MockServer.java index a3b132397..03712ac6b 100644 --- a/src/test/java/BehaviorTests/MockServer.java +++ b/src/test/java/BehaviorTests/MockServer.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + /* The MIT License diff --git a/src/test/java/BehaviorTests/PathParamTest.java b/src/test/java/BehaviorTests/PathParamTest.java index d4052d2ea..4c86358d3 100644 --- a/src/test/java/BehaviorTests/PathParamTest.java +++ b/src/test/java/BehaviorTests/PathParamTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import unirest.Unirest; diff --git a/src/test/java/BehaviorTests/QueryStringTest.java b/src/test/java/BehaviorTests/QueryStringTest.java index 2f1716e51..0644fc7f6 100644 --- a/src/test/java/BehaviorTests/QueryStringTest.java +++ b/src/test/java/BehaviorTests/QueryStringTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import unirest.HttpResponse; diff --git a/src/test/java/BehaviorTests/RedirectHandling.java b/src/test/java/BehaviorTests/RedirectHandling.java index 1940b15b8..2ced3acc2 100644 --- a/src/test/java/BehaviorTests/RedirectHandling.java +++ b/src/test/java/BehaviorTests/RedirectHandling.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import unirest.HttpResponse; diff --git a/src/test/java/BehaviorTests/RequestCapture.java b/src/test/java/BehaviorTests/RequestCapture.java index dc898abf2..bbfa3a232 100644 --- a/src/test/java/BehaviorTests/RequestCapture.java +++ b/src/test/java/BehaviorTests/RequestCapture.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import com.google.common.base.Strings; diff --git a/src/test/java/BehaviorTests/SendBodyTest.java b/src/test/java/BehaviorTests/SendBodyTest.java index dcde5ddc8..282c5146e 100644 --- a/src/test/java/BehaviorTests/SendBodyTest.java +++ b/src/test/java/BehaviorTests/SendBodyTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import unirest.JsonNode; diff --git a/src/test/java/BehaviorTests/TimeoutTests.java b/src/test/java/BehaviorTests/TimeoutTests.java index 5502cd3fa..4801bbb14 100644 --- a/src/test/java/BehaviorTests/TimeoutTests.java +++ b/src/test/java/BehaviorTests/TimeoutTests.java @@ -1,29 +1,31 @@ -/* -The MIT License - -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + + package BehaviorTests; import unirest.Unirest; diff --git a/src/test/java/BehaviorTests/VerbTest.java b/src/test/java/BehaviorTests/VerbTest.java index a8cd013cf..0fea2fe50 100644 --- a/src/test/java/BehaviorTests/VerbTest.java +++ b/src/test/java/BehaviorTests/VerbTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import unirest.HttpMethod; diff --git a/src/test/java/unirest/GsonObjectMapper.java b/src/test/java/unirest/GsonObjectMapper.java index 578743854..b3eff147d 100644 --- a/src/test/java/unirest/GsonObjectMapper.java +++ b/src/test/java/unirest/GsonObjectMapper.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import com.google.gson.Gson; diff --git a/src/test/java/unirest/HttpResponseTest.java b/src/test/java/unirest/HttpResponseTest.java index 87a03921d..95320032a 100644 --- a/src/test/java/unirest/HttpResponseTest.java +++ b/src/test/java/unirest/HttpResponseTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import unirest.MockApacheResponse; diff --git a/src/test/java/unirest/JacksonObjectMapper.java b/src/test/java/unirest/JacksonObjectMapper.java index fa3d559e6..b2d36e572 100644 --- a/src/test/java/unirest/JacksonObjectMapper.java +++ b/src/test/java/unirest/JacksonObjectMapper.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import com.fasterxml.jackson.core.JsonGenerator; diff --git a/src/test/java/unirest/JacksonObjectMapperTest.java b/src/test/java/unirest/JacksonObjectMapperTest.java index 55907f976..b1db84fca 100644 --- a/src/test/java/unirest/JacksonObjectMapperTest.java +++ b/src/test/java/unirest/JacksonObjectMapperTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import BehaviorTests.RequestCapture; diff --git a/src/test/java/unirest/JsonNodeTest.java b/src/test/java/unirest/JsonNodeTest.java index fc0d6cf28..e21c99b05 100644 --- a/src/test/java/unirest/JsonNodeTest.java +++ b/src/test/java/unirest/JsonNodeTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import org.junit.Test; diff --git a/src/test/java/unirest/MockApacheResponse.java b/src/test/java/unirest/MockApacheResponse.java index ed29c1ca3..c32b0e2f2 100644 --- a/src/test/java/unirest/MockApacheResponse.java +++ b/src/test/java/unirest/MockApacheResponse.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import com.google.common.collect.HashMultimap; diff --git a/src/test/java/unirest/MockCallback.java b/src/test/java/unirest/MockCallback.java index 062065031..9ef28908c 100644 --- a/src/test/java/unirest/MockCallback.java +++ b/src/test/java/unirest/MockCallback.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import BehaviorTests.BddTest; diff --git a/src/test/java/unirest/NoopCallback.java b/src/test/java/unirest/NoopCallback.java index d387841a6..cacfbc3ed 100644 --- a/src/test/java/unirest/NoopCallback.java +++ b/src/test/java/unirest/NoopCallback.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import unirest.HttpResponse; diff --git a/src/test/java/unirest/NotImplimented.java b/src/test/java/unirest/NotImplimented.java index f876df344..10915f499 100644 --- a/src/test/java/unirest/NotImplimented.java +++ b/src/test/java/unirest/NotImplimented.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; public class NotImplimented extends RuntimeException { diff --git a/src/test/java/unirest/OptionsTest.java b/src/test/java/unirest/OptionsTest.java index 81a432d54..3bebfcd47 100644 --- a/src/test/java/unirest/OptionsTest.java +++ b/src/test/java/unirest/OptionsTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import unirest.JacksonObjectMapper; diff --git a/src/test/java/unirest/ResponseBuilderTest.java b/src/test/java/unirest/ResponseBuilderTest.java index 39605d0bd..5295e6e1e 100644 --- a/src/test/java/unirest/ResponseBuilderTest.java +++ b/src/test/java/unirest/ResponseBuilderTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import BehaviorTests.Foo; diff --git a/src/test/java/unirest/ResponseUtilsTest.java b/src/test/java/unirest/ResponseUtilsTest.java index e59d6097f..07af4c009 100644 --- a/src/test/java/unirest/ResponseUtilsTest.java +++ b/src/test/java/unirest/ResponseUtilsTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import org.apache.http.HttpEntity; diff --git a/src/test/java/unirest/TestUtil.java b/src/test/java/unirest/TestUtil.java index 593241cc2..fb4adaf2f 100644 --- a/src/test/java/unirest/TestUtil.java +++ b/src/test/java/unirest/TestUtil.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import com.fasterxml.jackson.core.JsonProcessingException; diff --git a/src/test/java/unirest/UriFormatterTest.java b/src/test/java/unirest/UriFormatterTest.java index 59da4ddde..b2048ae0f 100644 --- a/src/test/java/unirest/UriFormatterTest.java +++ b/src/test/java/unirest/UriFormatterTest.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import unirest.HttpMethod; From 51338d7f8b8a5666e74a8aa352af59e5899c6182 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 1 Nov 2018 15:58:48 -0500 Subject: [PATCH 0229/1769] clean up some things that should be package local --- src/main/java/unirest/CallbackFuture.java | 4 +- src/main/java/unirest/HttpClientHelper.java | 12 ++-- src/main/java/unirest/JsonPatchOperation.java | 1 - src/main/java/unirest/RequestPrep.java | 2 +- src/main/java/unirest/ResponseUtils.java | 58 +++++++++---------- src/main/java/unirest/URLParamEncoder.java | 4 +- 6 files changed, 40 insertions(+), 41 deletions(-) diff --git a/src/main/java/unirest/CallbackFuture.java b/src/main/java/unirest/CallbackFuture.java index 293cc67e8..24b1c2744 100644 --- a/src/main/java/unirest/CallbackFuture.java +++ b/src/main/java/unirest/CallbackFuture.java @@ -28,9 +28,9 @@ import java.util.concurrent.CompletableFuture; -public class CallbackFuture { +class CallbackFuture { - public static CompletableFuture> wrap(Callback source){ + static CompletableFuture> wrap(Callback source){ return new CompletableFuture>(){ @Override public boolean complete(HttpResponse value) { diff --git a/src/main/java/unirest/HttpClientHelper.java b/src/main/java/unirest/HttpClientHelper.java index 1a703a3e1..00090d4e1 100644 --- a/src/main/java/unirest/HttpClientHelper.java +++ b/src/main/java/unirest/HttpClientHelper.java @@ -38,7 +38,7 @@ class HttpClientHelper { - public static HttpResponse request(HttpRequest request, + static HttpResponse request(HttpRequest request, Function> transformer) { HttpRequestBase requestObj = RequestPrep.prepareRequest(request, false); @@ -59,17 +59,17 @@ public static HttpResponse request(HttpRequest request, } } - public static CompletableFuture> requestAsync(HttpRequest httpRequest, Function> transformer) { + static CompletableFuture> requestAsync(HttpRequest httpRequest, Function> transformer) { return requestAsync(httpRequest, transformer, new CompletableFuture<>()); } - public static CompletableFuture> requestAsync(HttpRequest request, Function> transformer, Callback callback) { + static CompletableFuture> requestAsync(HttpRequest request, Function> transformer, Callback callback) { return requestAsync(request, transformer, CallbackFuture.wrap(callback)); } - public static CompletableFuture> requestAsync(HttpRequest request, - Function> transformer, - CompletableFuture> callback) { + private static CompletableFuture> requestAsync(HttpRequest request, + Function> transformer, + CompletableFuture> callback) { Objects.requireNonNull(callback); HttpUriRequest requestObj = RequestPrep.prepareRequest(request, true); diff --git a/src/main/java/unirest/JsonPatchOperation.java b/src/main/java/unirest/JsonPatchOperation.java index a3834421b..a67e5f208 100644 --- a/src/main/java/unirest/JsonPatchOperation.java +++ b/src/main/java/unirest/JsonPatchOperation.java @@ -37,7 +37,6 @@ public enum JsonPatchOperation { private final String operationtype; JsonPatchOperation(String operationtype) { - this.operationtype = operationtype; } diff --git a/src/main/java/unirest/RequestPrep.java b/src/main/java/unirest/RequestPrep.java index 4170e3eb8..37cee9c69 100644 --- a/src/main/java/unirest/RequestPrep.java +++ b/src/main/java/unirest/RequestPrep.java @@ -43,7 +43,7 @@ class RequestPrep { private static final String USER_AGENT = "unirest-java/1.3.11"; private static final UriFormatter URI_FORMATTER = new UriFormatter(); - public static HttpRequestBase prepareRequest(HttpRequest request, boolean async) { + static HttpRequestBase prepareRequest(HttpRequest request, boolean async) { setDefaultHeaders(request); diff --git a/src/main/java/unirest/ResponseUtils.java b/src/main/java/unirest/ResponseUtils.java index 94dfdd0b7..042b00efc 100644 --- a/src/main/java/unirest/ResponseUtils.java +++ b/src/main/java/unirest/ResponseUtils.java @@ -38,17 +38,42 @@ import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; -public class ResponseUtils { +class ResponseUtils { private static final Pattern CHARSET_PATTERN = Pattern.compile("(?i)\\bcharset=\\s*\"?([^\\s;\"]*)"); + static String getCharSet(HttpEntity responseEntity) { + Header contentType = responseEntity.getContentType(); + if (contentType != null) { + String responseCharset = getCharsetFromContentType(contentType.getValue()); + if (responseCharset != null && !responseCharset.trim().equals("")) { + return responseCharset; + } + } + return "UTF-8"; + } + + static byte[] getRawBody(HttpEntity responseEntity) { + try { + InputStream is = responseEntity.getContent(); + if (isGzipped(responseEntity.getContentEncoding())) { + is = new GZIPInputStream(responseEntity.getContent()); + } + return getBytes(is); + } catch (IOException e2) { + throw new UnirestException(e2); + } finally { + EntityUtils.consumeQuietly(responseEntity); + } + } + /** * Parse out a charset from a content type header. * * @param contentType e.g. "text/html; charset=EUC-JP" * @return "EUC-JP", or null if not found. Charset is trimmed and uppercased. */ - public static String getCharsetFromContentType(String contentType) { + private static String getCharsetFromContentType(String contentType) { if (contentType == null) { return null; } @@ -60,7 +85,7 @@ public static String getCharsetFromContentType(String contentType) { return null; } - public static byte[] getBytes(InputStream is) throws IOException { + private static byte[] getBytes(InputStream is) throws IOException { int len; int size = 1024; byte[] buf; @@ -80,7 +105,7 @@ public static byte[] getBytes(InputStream is) throws IOException { return buf; } - public static boolean isGzipped(Header contentEncoding) { + private static boolean isGzipped(Header contentEncoding) { if (contentEncoding != null) { String value = contentEncoding.getValue(); if (value != null && "gzip".equals(value.toLowerCase().trim())) { @@ -89,29 +114,4 @@ public static boolean isGzipped(Header contentEncoding) { } return false; } - - public static String getCharSet(HttpEntity responseEntity) { - Header contentType = responseEntity.getContentType(); - if (contentType != null) { - String responseCharset = getCharsetFromContentType(contentType.getValue()); - if (responseCharset != null && !responseCharset.trim().equals("")) { - return responseCharset; - } - } - return "UTF-8"; - } - - public static byte[] getRawBody(HttpEntity responseEntity) { - try { - InputStream is = responseEntity.getContent(); - if (isGzipped(responseEntity.getContentEncoding())) { - is = new GZIPInputStream(responseEntity.getContent()); - } - return getBytes(is); - } catch (IOException e2) { - throw new UnirestException(e2); - } finally { - EntityUtils.consumeQuietly(responseEntity); - } - } } diff --git a/src/main/java/unirest/URLParamEncoder.java b/src/main/java/unirest/URLParamEncoder.java index cb84a3687..30c9f258a 100644 --- a/src/main/java/unirest/URLParamEncoder.java +++ b/src/main/java/unirest/URLParamEncoder.java @@ -29,8 +29,8 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -public class URLParamEncoder { - public static String encode(String input) { +class URLParamEncoder { + static String encode(String input) { try { return URLEncoder.encode(input, "UTF-8"); } catch (UnsupportedEncodingException e) { From a990e2f915c1002ee69b1aedc342fc5be589df08 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 3 Nov 2018 15:51:10 -0500 Subject: [PATCH 0230/1769] replace messy, static, configuration system with something cleaner that supports multiple configurations --- .travis.yml | 5 + checkstyle.xml | 2 +- src/main/java/unirest/AsyncConfig.java | 65 ++++ src/main/java/unirest/BaseRequest.java | 47 +-- src/main/java/unirest/ClientConfig.java | 75 ++++ src/main/java/unirest/ClientFactory.java | 118 +++++++ src/main/java/unirest/Config.java | 321 ++++++++++++++++++ src/main/java/unirest/GetRequest.java | 4 +- src/main/java/unirest/HttpClientHelper.java | 37 +- src/main/java/unirest/HttpRequest.java | 4 +- .../java/unirest/HttpRequestWithBody.java | 28 +- src/main/java/unirest/JsonPatchRequest.java | 4 +- src/main/java/unirest/MultipartBody.java | 4 +- src/main/java/unirest/Options.java | 289 ---------------- src/main/java/unirest/RawBody.java | 4 +- src/main/java/unirest/RequestBodyEntity.java | 4 +- src/main/java/unirest/RequestPrep.java | 13 - src/main/java/unirest/ResponseBuilder.java | 10 +- src/main/java/unirest/Unirest.java | 130 ++----- .../java/unirest/UnirestConfigException.java | 4 + src/main/java/unirest/UnirestException.java | 7 + src/main/java/unirest/Util.java | 64 ++++ .../java/BehaviorTests/AsGenericTypeTest.java | 2 +- src/test/java/BehaviorTests/BddTest.java | 9 +- src/test/java/BehaviorTests/HeaderTest.java | 6 +- .../java/BehaviorTests/InterceptorTest.java | 5 +- .../java/BehaviorTests/LifeCycleTest.java | 96 ++++-- .../java/BehaviorTests/RedirectHandling.java | 5 +- src/test/java/BehaviorTests/SendBodyTest.java | 4 +- src/test/java/BehaviorTests/TimeoutTests.java | 23 +- ...ptionsTest.java => ClientFactoryTest.java} | 62 +--- src/test/java/unirest/ConfigTest.java | 61 ++++ .../java/unirest/ResponseBuilderTest.java | 14 +- src/test/java/unirest/UriFormatterTest.java | 2 +- .../java/unirest/UtilTest.java} | 32 +- 35 files changed, 944 insertions(+), 616 deletions(-) create mode 100644 src/main/java/unirest/AsyncConfig.java create mode 100644 src/main/java/unirest/ClientConfig.java create mode 100644 src/main/java/unirest/ClientFactory.java create mode 100644 src/main/java/unirest/Config.java delete mode 100644 src/main/java/unirest/Options.java create mode 100644 src/main/java/unirest/Util.java rename src/test/java/unirest/{OptionsTest.java => ClientFactoryTest.java} (52%) create mode 100644 src/test/java/unirest/ConfigTest.java rename src/{main/java/unirest/Option.java => test/java/unirest/UtilTest.java} (77%) diff --git a/.travis.yml b/.travis.yml index d34d49296..669cc8039 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,3 +10,8 @@ cache: directories: - .autoconf - $HOME/.m2 + +# blocklist +branches: + except: + - v3 diff --git a/checkstyle.xml b/checkstyle.xml index 6fcfd982d..87809dbab 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -62,7 +62,7 @@ - + diff --git a/src/main/java/unirest/AsyncConfig.java b/src/main/java/unirest/AsyncConfig.java new file mode 100644 index 000000000..26535d035 --- /dev/null +++ b/src/main/java/unirest/AsyncConfig.java @@ -0,0 +1,65 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; +import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; +import org.apache.http.nio.client.HttpAsyncClient; + +import java.util.Objects; +import java.util.stream.Stream; + +public class AsyncConfig { + + private final HttpAsyncClient client; + private final PoolingNHttpClientConnectionManager manager; + private final AsyncIdleConnectionMonitorThread syncMonitor; + + public AsyncConfig(HttpAsyncClient client, + PoolingNHttpClientConnectionManager manager, + AsyncIdleConnectionMonitorThread syncMonitor) { + this.syncMonitor = syncMonitor; + Objects.requireNonNull(client, "Client may not be null"); + this.client = client; + this.manager = manager; + } + + + public HttpAsyncClient getClient() { + return client; + } + + public Stream close() { + return Config.collectExceptions(Util.tryCast(client, CloseableHttpAsyncClient.class) + .filter(c -> c.isRunning()) + .map(c -> Util.tryDo(c, d -> d.close())) + .filter(c -> c.isPresent()) + .map(c -> c.get()), + Util.tryDo(manager, m -> m.shutdown()), + Util.tryDo(syncMonitor, m -> m.interrupt())); + } +} diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 67ec5f6bf..0aaf60b33 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -31,79 +31,82 @@ public abstract class BaseRequest { - private final ResponseBuilder builder = new ResponseBuilder(); - + private final ResponseBuilder builder; + private final Config config; protected HttpRequest httpRequest; - protected BaseRequest(HttpRequest httpRequest) { + protected BaseRequest(Config config, HttpRequest httpRequest) { + this.config = config; this.httpRequest = httpRequest; + this.builder = new ResponseBuilder(config); } - public HttpRequest getHttpRequest() { - return this.httpRequest; + protected BaseRequest(Config config) { + this.config = config; + this.builder = new ResponseBuilder(config); } - protected BaseRequest() { - super(); + public HttpRequest getHttpRequest() { + return this.httpRequest; } public HttpResponse asString() throws UnirestException { - return HttpClientHelper.request(httpRequest, builder::asString); + return HttpClientHelper.request(config, httpRequest, builder::asString); } public CompletableFuture> asStringAsync() { - return HttpClientHelper.requestAsync(httpRequest, builder::asString); + return HttpClientHelper.requestAsync(config, httpRequest, builder::asString); } public CompletableFuture> asStringAsync(Callback callback) { - return HttpClientHelper.requestAsync(httpRequest, builder::asString, callback); + return HttpClientHelper.requestAsync(config, httpRequest, builder::asString, callback); } public HttpResponse asJson() throws UnirestException { - return HttpClientHelper.request(httpRequest, builder::asJson); + return HttpClientHelper.request(config, httpRequest, builder::asJson); } public CompletableFuture> asJsonAsync() { - return HttpClientHelper.requestAsync(httpRequest, builder::asJson); + return HttpClientHelper.requestAsync(config, httpRequest, builder::asJson); } public CompletableFuture> asJsonAsync(Callback callback) { - return HttpClientHelper.requestAsync(httpRequest, builder::asJson, callback); + return HttpClientHelper.requestAsync(config, httpRequest, builder::asJson, callback); } public HttpResponse asObject(Class responseClass) throws UnirestException { - return HttpClientHelper.request(httpRequest, r -> builder.asObject(r, responseClass)); + return HttpClientHelper.request(config, httpRequest, r -> builder.asObject(r, responseClass)); } public HttpResponse asObject(GenericType genericType) throws UnirestException { - return HttpClientHelper.request(httpRequest, r -> builder.asObject(r, genericType)); + return HttpClientHelper.request(config, httpRequest, r -> builder.asObject(r, genericType)); } public CompletableFuture> asObjectAsync(Class responseClass) { - return HttpClientHelper.requestAsync(httpRequest, r -> builder.asObject(r, responseClass)); + return HttpClientHelper.requestAsync(config, httpRequest, r -> builder.asObject(r, responseClass)); } public CompletableFuture> asObjectAsync(Class responseClass, Callback callback) { - return HttpClientHelper.requestAsync(httpRequest, r -> builder.asObject(r, responseClass), callback); + return HttpClientHelper.requestAsync(config, httpRequest, r -> builder.asObject(r, responseClass), callback); } public CompletableFuture> asObjectAsync(GenericType genericType) { - return HttpClientHelper.requestAsync(httpRequest, r -> builder.asObject(r, genericType)); + return HttpClientHelper.requestAsync(config, httpRequest, r -> builder.asObject(r, genericType)); } public CompletableFuture> asObjectAsync(GenericType genericType, Callback callback) { - return HttpClientHelper.requestAsync(httpRequest, r -> builder.asObject(r, genericType), callback); + return HttpClientHelper.requestAsync(config, httpRequest, r -> builder.asObject(r, genericType), callback); } public HttpResponse asBinary() throws UnirestException { - return HttpClientHelper.request(httpRequest, builder::asBinary); + return HttpClientHelper.request(config, httpRequest, builder::asBinary); } public CompletableFuture> asBinaryAsync() { - return HttpClientHelper.requestAsync(httpRequest, builder::asBinary); + return HttpClientHelper.requestAsync(config, httpRequest, builder::asBinary); } public CompletableFuture> asBinaryAsync(Callback callback) { - return HttpClientHelper.requestAsync(httpRequest, builder::asBinary, callback); + return HttpClientHelper.requestAsync(config, httpRequest, builder::asBinary, callback); } } diff --git a/src/main/java/unirest/ClientConfig.java b/src/main/java/unirest/ClientConfig.java new file mode 100644 index 000000000..762358490 --- /dev/null +++ b/src/main/java/unirest/ClientConfig.java @@ -0,0 +1,75 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.apache.http.client.HttpClient; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; + +import java.io.Closeable; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Stream; + +public class ClientConfig { + private final HttpClient client; + private final PoolingHttpClientConnectionManager manager; + private final SyncIdleConnectionMonitorThread syncMonitor; + + public ClientConfig(HttpClient client, + PoolingHttpClientConnectionManager manager, + SyncIdleConnectionMonitorThread syncMonitor) { + Objects.requireNonNull(client, "Client may not be null"); + this.client = client; + this.manager = manager; + this.syncMonitor = syncMonitor; + } + + public HttpClient getClient() { + return client; + } + + public PoolingHttpClientConnectionManager getManager() { + return manager; + } + + public SyncIdleConnectionMonitorThread getSyncMonitor() { + return syncMonitor; + } + + public Stream close() { + return Config.collectExceptions(Util.tryCast(client, CloseableHttpClient.class) + .map(c -> Util.tryDo(c, Closeable::close)) + .filter(Optional::isPresent) + .map(Optional::get), + Util.tryDo(manager, m -> m.close()), + Util.tryDo(syncMonitor, i -> i.interrupt()) + ); + + } + +} diff --git a/src/main/java/unirest/ClientFactory.java b/src/main/java/unirest/ClientFactory.java new file mode 100644 index 000000000..42f1965c1 --- /dev/null +++ b/src/main/java/unirest/ClientFactory.java @@ -0,0 +1,118 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.apache.http.HttpHost; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; +import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; +import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; +import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor; +import org.apache.http.nio.reactor.IOReactorException; + +class ClientFactory { + + private final Config config; + + public ClientFactory(Config config) { + this.config = config; + } + + public AsyncConfig buildAsyncClient() { + + try { + PoolingNHttpClientConnectionManager manager = new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor()); + manager.setMaxTotal(config.getMaxConnections()); + manager.setDefaultMaxPerRoute(config.getMaxPerRoutes()); + + HttpAsyncClientBuilder ab = HttpAsyncClientBuilder.create() + .setDefaultRequestConfig(getRequestConfig()) + .setConnectionManager(manager) + .useSystemProperties(); + + if (shouldDisableRedirects()) { + ab.setRedirectStrategy(new NoRedirects()); + } + if (shouldDisableCookieManagement()) { + ab.disableCookieManagement(); + } + config.getInterceptors().forEach(ab::addInterceptorFirst); + + CloseableHttpAsyncClient build = ab.build(); + build.start(); + AsyncIdleConnectionMonitorThread syncMonitor = new AsyncIdleConnectionMonitorThread(manager); + syncMonitor.start(); + return new AsyncConfig(build, manager, syncMonitor); + + } catch (IOReactorException e) { + throw new UnirestConfigException(e); + } + } + + public ClientConfig buildHttpClient() { + PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(); + SyncIdleConnectionMonitorThread syncMonitor = new SyncIdleConnectionMonitorThread(manager); + syncMonitor.start(); + + HttpClientBuilder cb = HttpClientBuilder.create() + .setDefaultRequestConfig(getRequestConfig()) + .setConnectionManager(manager) + .useSystemProperties(); + + if (shouldDisableRedirects()) { + cb.disableRedirectHandling(); + } + if (shouldDisableCookieManagement()) { + cb.disableCookieManagement(); + } + config.getInterceptors().stream().forEach(cb::addInterceptorFirst); + + return new ClientConfig(cb.build(), manager, syncMonitor); + } + + private boolean shouldDisableCookieManagement() { + return !config.getEnabledCookieManagement(); + } + + private boolean shouldDisableRedirects() { + return !config.getFollowRedirects(); + } + + private RequestConfig getRequestConfig() { + Integer connectionTimeout = config.getConnectionTimeout(); + Integer socketTimeout = config.getSocketTimeout(); + HttpHost proxy = config.getProxy(); + return RequestConfig.custom() + .setConnectTimeout(connectionTimeout) + .setSocketTimeout(socketTimeout) + .setConnectionRequestTimeout(socketTimeout) + .setProxy(proxy) + .build(); + } +} diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java new file mode 100644 index 000000000..62ab5ca5b --- /dev/null +++ b/src/main/java/unirest/Config.java @@ -0,0 +1,321 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.apache.http.HttpHost; +import org.apache.http.HttpRequestInterceptor; +import org.apache.http.client.HttpClient; +import org.apache.http.nio.client.HttpAsyncClient; + +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class Config { + public static final int DEFAULT_CONNECTION_TIMEOUT = 10000; + public static final int DEFAULT_MAX_CONNECTIONS = 200; + public static final int DEFAULT_MAX_PER_ROUTE = 20; + public static final int DEFAULT_CONNECT_TIMEOUT = 10000; + public static final int DEFAULT_SOCKET_TIMEOUT = 60000; + + private ClientFactory factory = new ClientFactory(this); + + private Optional client = Optional.empty(); + private Optional asyncClient = Optional.empty(); + private Optional objectMapper = Optional.empty(); + + private List interceptors = new ArrayList<>(); + private HttpHost proxy; + private Headers defaultHeaders; + private int connectionTimeout; + private int socketTimeout; + private int maxTotal; + private int maxPerRoute; + private boolean followRedirects; + private boolean cookieManagement; + + private void setDefaults(){ + interceptors.clear(); + proxy = null; + defaultHeaders = new Headers(); + connectionTimeout = DEFAULT_CONNECTION_TIMEOUT; + socketTimeout = DEFAULT_SOCKET_TIMEOUT; + maxTotal = DEFAULT_MAX_CONNECTIONS; + maxPerRoute = DEFAULT_MAX_PER_ROUTE; + followRedirects = true; + cookieManagement = true; + } + + public Config(){ + setDefaults(); + } + + /** + * Set the HttpClient implementation to use for every synchronous request + * + * @param httpClient Custom httpClient implementation + */ + public Config httpClient(HttpClient httpClient) { + client = Optional.of(new ClientConfig(httpClient, null, null)); + return this; + } + + /** + * Set the HttpClient implementation to use for every synchronous request + * + * @param httpClient Custom httpClient implementation + */ + public Config httpClient(ClientConfig httpClient) { + client = Optional.of(httpClient); + return this; + } + + /** + * Set the asynchronous AbstractHttpAsyncClient implementation to use for every asynchronous request + * + * @param value Custom CloseableHttpAsyncClient implementation + */ + public Config asyncClient(HttpAsyncClient value) { + this.asyncClient = Optional.of(new AsyncConfig(value, null, null)); + return this; + } + + /** + * Set the full async configuration including monitors. These will be shutDown on a Unirest.shudown() + * + * @param value Custom AsyncConfig class. The actual AsyncHttpClient is required. + */ + public Config asyncClient(AsyncConfig value) { + asyncClient = Optional.of(value); + return this; + } + + /** + * Set a proxy + * + * @param value Proxy settings object. + */ + public Config proxy(HttpHost value) { + this.proxy = value; + return this; + } + + /** + * Set the ObjectMapper implementation to use for Response to Object binding + * + * @param om Custom implementation of ObjectMapper interface + */ + public Config setObjectMapper(ObjectMapper om) { + this.objectMapper = Optional.ofNullable(om); + return this; + } + + /** + * Set the connection timeout + * + * @param inMillies The timeout until a connection with the server is established (in milliseconds). Default is 10000. Set to zero to disable the timeout. + */ + public Config connectTimeout(int inMillies) { + validateNotCustomClient(); + this.connectionTimeout = inMillies; + return this; + } + + /** + * Set the socket timeout + * + * @param inMillies The timeout to receive data (in milliseconds). Default is 60000. Set to zero to disable the timeout. + */ + public Config socketTimeout(int inMillies) { + validateNotCustomClient(); + this.socketTimeout = inMillies; + return this; + } + + /** + * Set the concurrency levels + * + * @param total Defines the overall connection limit for a connection pool. Default is 200. + * @param perRoute Defines a connection limit per one HTTP route (this can be considered a per target host limit). Default is 20. + */ + public Config concurrency(int total, int perRoute) { + validateNotCustomClient(); + this.maxTotal = total; + this.maxPerRoute = perRoute; + return this; + } + + /** + * Clear default headers + */ + public Config clearDefaultHeaders() { + defaultHeaders.clear(); + return this; + } + + /** + * Set default header to appear on all requests + * + * @param name The name of the header. + * @param value The value of the header. + */ + public Config setDefaultHeader(String name, String value) { + defaultHeaders.add(name, value); + return this; + } + + /** + * Add a HttpRequestInterceptor to the clients. This can be called multiple times to add as many as you like. + * https://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/HttpRequestInterceptor.html + * + * @param interceptor The addInterceptor + */ + public Config addInterceptor(HttpRequestInterceptor interceptor) { + validateNotCustomClient(); + interceptors.add(interceptor); + return this; + } + + /** + * Allow the client to follow redirects. Defaults to TRUE + * + * @param enable The name of the header. + */ + public Config followRedirects(boolean enable) { + validateNotCustomClient(); + this.followRedirects = enable; + return this; + } + + /** + * Allow the client to manage cookies. Defaults to TRUE + * + * @param enable The name of the header. + */ + public Config enableCookieManagement(boolean enable) { + validateNotCustomClient(); + this.cookieManagement = enable; + return this; + } + + public void shutDown(boolean clearOptions) { + List ex = Stream.concat( + client.map(ClientConfig::close).orElseGet(Stream::empty), + asyncClient.map(AsyncConfig::close).orElseGet(Stream::empty) + ).collect(Collectors.toList()); + + client = Optional.empty(); + asyncClient = Optional.empty(); + + if (clearOptions) { + setDefaults(); + } + + if(!ex.isEmpty()){ + throw new UnirestException(ex); + } + } + + // Accessors for unirest. + boolean getEnabledCookieManagement() { + return cookieManagement; + } + + boolean getFollowRedirects() { + return followRedirects; + } + + int getMaxConnections() { + return maxTotal; + } + + int getMaxPerRoutes() { + return maxPerRoute; + } + + int getConnectionTimeout() { + return connectionTimeout; + } + + int getSocketTimeout() { + return socketTimeout; + } + + ObjectMapper getObjectMapper() { + return objectMapper.orElseThrow(() -> new UnirestException("No Object Mapper Configured. Please config one with Unirest.config().setObjectMapper")); + } + + private void validateNotCustomClient() { + if (client.isPresent() || asyncClient.isPresent()) { + throw new UnirestConfigException( + "You can't set custom client settings when providing custom client implementations. " + + "Set the timeouts directly in your custom client configuration instead." + ); + } + } + + public HttpClient getClient() { + if (!client.isPresent()) { + client = Optional.of(factory.buildHttpClient()); + } + return client.get().getClient(); + } + + public HttpAsyncClient getAsyncHttpClient() { + if (!asyncClient.isPresent()) { + buildAsyncClient(); + } + return asyncClient.get().getClient(); + } + + private synchronized void buildAsyncClient() { + if (!asyncClient.isPresent()) { + AsyncConfig value = factory.buildAsyncClient(); + asyncClient = Optional.of(value); + } + } + + List getInterceptors() { + return interceptors; + } + + HttpHost getProxy() { + return proxy; + } + + public Headers getDefaultHeaders() { + return defaultHeaders; + } + + public boolean isRunning() { + return client.isPresent() || asyncClient.isPresent(); + } + + public static Stream collectExceptions(Optional... ex) { + return Stream.of(ex).flatMap(Util::stream); + } +} diff --git a/src/main/java/unirest/GetRequest.java b/src/main/java/unirest/GetRequest.java index 30f17a8b7..04d87fcca 100644 --- a/src/main/java/unirest/GetRequest.java +++ b/src/main/java/unirest/GetRequest.java @@ -30,8 +30,8 @@ public class GetRequest extends HttpRequest { - public GetRequest(HttpMethod method, String url) { - super(method, url); + public GetRequest(Config config, HttpMethod method, String url) { + super(config, method, url); } public GetRequest routeParam(String name, String value) { diff --git a/src/main/java/unirest/HttpClientHelper.java b/src/main/java/unirest/HttpClientHelper.java index 00090d4e1..c83b5a79e 100644 --- a/src/main/java/unirest/HttpClientHelper.java +++ b/src/main/java/unirest/HttpClientHelper.java @@ -30,7 +30,6 @@ import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.concurrent.FutureCallback; -import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import java.util.Objects; import java.util.concurrent.CompletableFuture; @@ -38,13 +37,11 @@ class HttpClientHelper { - static HttpResponse request(HttpRequest request, + static HttpResponse request(Config config, HttpRequest request, Function> transformer) { HttpRequestBase requestObj = RequestPrep.prepareRequest(request, false); - HttpClient client = Options.getHttpClient(); // The - // DefaultHttpClient - // is thread-safe + HttpClient client = config.getClient(); org.apache.http.HttpResponse response; try { @@ -59,22 +56,25 @@ static HttpResponse request(HttpRequest request, } } - static CompletableFuture> requestAsync(HttpRequest httpRequest, Function> transformer) { - return requestAsync(httpRequest, transformer, new CompletableFuture<>()); + static CompletableFuture> requestAsync(Config config, HttpRequest httpRequest, Function> transformer) { + return requestAsync(config, httpRequest, transformer, new CompletableFuture<>()); } - static CompletableFuture> requestAsync(HttpRequest request, Function> transformer, Callback callback) { - return requestAsync(request, transformer, CallbackFuture.wrap(callback)); + static CompletableFuture> requestAsync(Config config, + HttpRequest request, + Function> transformer, + Callback callback) { + return requestAsync(config, request, transformer, CallbackFuture.wrap(callback)); } - private static CompletableFuture> requestAsync(HttpRequest request, + private static CompletableFuture> requestAsync(Config config, HttpRequest request, Function> transformer, CompletableFuture> callback) { Objects.requireNonNull(callback); HttpUriRequest requestObj = RequestPrep.prepareRequest(request, true); - asyncClient() + config.getAsyncHttpClient() .execute(requestObj, new FutureCallback() { @Override public void completed(org.apache.http.HttpResponse httpResponse) { @@ -94,19 +94,4 @@ public void cancelled() { return callback; } - private static CloseableHttpAsyncClient asyncClient() { - CloseableHttpAsyncClient asyncHttpClient = Options.getAsyncHttpClient(); - if (!asyncHttpClient.isRunning()) { - tryStart(asyncHttpClient); - } - return asyncHttpClient; - } - - private static synchronized void tryStart(CloseableHttpAsyncClient asyncHttpClient) { - if (!asyncHttpClient.isRunning()) { - asyncHttpClient.start(); - AsyncIdleConnectionMonitorThread asyncIdleConnectionMonitorThread = (AsyncIdleConnectionMonitorThread) Options.getOption(Option.ASYNC_MONITOR); - asyncIdleConnectionMonitorThread.start(); - } - } } diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index 2d08c060f..141bb9da2 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -40,10 +40,12 @@ public class HttpRequest extends BaseRequest { Map> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); protected Body body; - public HttpRequest(HttpMethod method, String url) { + public HttpRequest(Config config, HttpMethod method, String url) { + super(config); this.httpMethod = method; this.url = url; super.httpRequest = this; + headers.putAll(config.getDefaultHeaders()); } public HttpRequest routeParam(String name, String value) { diff --git a/src/main/java/unirest/HttpRequestWithBody.java b/src/main/java/unirest/HttpRequestWithBody.java index 38b1a7e04..8a36ecf90 100644 --- a/src/main/java/unirest/HttpRequestWithBody.java +++ b/src/main/java/unirest/HttpRequestWithBody.java @@ -40,10 +40,12 @@ public class HttpRequestWithBody extends HttpRequest { + private final Config config; private Charset charSet = StandardCharsets.UTF_8; - public HttpRequestWithBody(HttpMethod method, String url) { - super(method, url); + public HttpRequestWithBody(Config config, HttpMethod method, String url) { + super(config, method, url); + this.config = config; } @Override @@ -79,7 +81,7 @@ public HttpRequestWithBody queryString(String name, Object value) { } public MultipartBody field(String name, Collection value) { - MultipartBody body = new MultipartBody(this).field(name, value); + MultipartBody body = new MultipartBody(config, this).field(name, value); this.body = body; return body; } @@ -89,7 +91,7 @@ public MultipartBody field(String name, File file) { } public MultipartBody field(String name, File file, String contentType) { - MultipartBody body = new MultipartBody(this).field(name, file, contentType); + MultipartBody body = new MultipartBody(config, this).field(name, file, contentType); this.body = body; return body; } @@ -99,13 +101,13 @@ public MultipartBody field(String name, Object value) { } public MultipartBody field(String name, Object value, String contentType) { - MultipartBody body = new MultipartBody(this).field(name, nullToEmpty(value), contentType); + MultipartBody body = new MultipartBody(config, this).field(name, nullToEmpty(value), contentType); this.body = body; return body; } public MultipartBody fields(Map parameters) { - MultipartBody body = new MultipartBody(this); + MultipartBody body = new MultipartBody(config, this); if (parameters != null) { for (Entry param : parameters.entrySet()) { if (param.getValue() instanceof File) { @@ -127,7 +129,7 @@ private String nullToEmpty(Object v) { } public MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName) { - MultipartBody body = new MultipartBody(this).field(name, stream, contentType, fileName); + MultipartBody body = new MultipartBody(config, this).field(name, stream, contentType, fileName); this.body = body; return body; } @@ -148,23 +150,17 @@ public RequestBodyEntity body(JsonNode body) { } public RequestBodyEntity body(String body) { - RequestBodyEntity b = new RequestBodyEntity(this).body(body); + RequestBodyEntity b = new RequestBodyEntity(config, this).body(body); this.body = b; return b; } public RequestBodyEntity body(Object body) { - ObjectMapper objectMapper = (ObjectMapper) Options.getOption(Option.OBJECT_MAPPER); - - if (objectMapper == null) { - throw new UnirestConfigException("Serialization Impossible. Can't find an ObjectMapper implementation."); - } - - return body(objectMapper.writeValue(body)); + return body(config.getObjectMapper().writeValue(body)); } public RawBody body(byte[] body) { - RawBody b = new RawBody(this).body(body); + RawBody b = new RawBody(config, this).body(body); this.body = b; return b; } diff --git a/src/main/java/unirest/JsonPatchRequest.java b/src/main/java/unirest/JsonPatchRequest.java index d564169dd..33b9125b4 100644 --- a/src/main/java/unirest/JsonPatchRequest.java +++ b/src/main/java/unirest/JsonPatchRequest.java @@ -35,8 +35,8 @@ public class JsonPatchRequest extends HttpRequest implements Body { public static final String CONTENT_TYPE = "application/json-patch+json"; private JsonPatch items = new JsonPatch(); - public JsonPatchRequest(String url) { - super(HttpMethod.PATCH, url); + public JsonPatchRequest(Config config, String url) { + super(config, HttpMethod.PATCH, url); header("Content-Type", CONTENT_TYPE); } diff --git a/src/main/java/unirest/MultipartBody.java b/src/main/java/unirest/MultipartBody.java index f71fbd314..1c84cbc7d 100644 --- a/src/main/java/unirest/MultipartBody.java +++ b/src/main/java/unirest/MultipartBody.java @@ -48,8 +48,8 @@ public class MultipartBody extends BaseRequest implements Body { private HttpRequestWithBody httpRequestObj; private HttpMultipartMode mode = HttpMultipartMode.BROWSER_COMPATIBLE; - public MultipartBody(HttpRequestWithBody httpRequest) { - super(httpRequest); + public MultipartBody(Config config, HttpRequestWithBody httpRequest) { + super(config, httpRequest); this.httpRequestObj = httpRequest; } diff --git a/src/main/java/unirest/Options.java b/src/main/java/unirest/Options.java deleted file mode 100644 index 14783f906..000000000 --- a/src/main/java/unirest/Options.java +++ /dev/null @@ -1,289 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package unirest; - -import org.apache.http.HttpHost; -import org.apache.http.HttpRequestInterceptor; -import org.apache.http.client.HttpClient; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; -import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; -import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; -import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; -import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor; -import org.apache.http.nio.reactor.IOReactorException; - -import java.io.Closeable; -import java.io.IOException; -import java.util.*; - -import static unirest.Option.COOKIE_MANAGEMENT; -import static unirest.Option.FOLLOW_REDIRECTS; - -public class Options { - public static final int MAX_TOTAL = 200; - public static final int MAX_PER_ROUTE = 20; - public static final int CONNECTION_TIMEOUT = 10000; - public static final int SOCKET_TIMEOUT = 60000; - - private static boolean customClientSet = false; - private static boolean isRunning = false; - private static Map options = new HashMap<>(); - private static PoolingHttpClientConnectionManager syncConnectionManager; - private static SyncIdleConnectionMonitorThread defaultSyncMonitor; - private static List interceptors = new ArrayList<>(); - - public static void customClientSet() { - customClientSet = true; - } - - private static void setIfAbsent(Option option, Object value) { - validateOption(option); - options.putIfAbsent(option, value); - } - - public static void setOption(Option option, Object value) { - validateOption(option); - options.put(option, value); - } - - private static void validateOption(Option option) { - if ((option == Option.CONNECTION_TIMEOUT || option == Option.SOCKET_TIMEOUT) && customClientSet) { - throw new RuntimeException( - "You can't set custom timeouts when providing custom client implementations. " + - "Set the timeouts directly in your custom client configuration instead." - ); - } - } - - public static Object getOption(Option option) { - warmUp(); - return options.get(option); - } - - private static void warmUp() { - if(!isRunning()){ - init(); - } - } - - private static T getOptionOrDefault(Option option, T defaultValue){ - warmUp(); - return (T)options.computeIfAbsent(option, o -> defaultValue); - } - - private static void createMonitors() { - syncConnectionManager = new PoolingHttpClientConnectionManager(); - defaultSyncMonitor = new SyncIdleConnectionMonitorThread(syncConnectionManager); - defaultSyncMonitor.start(); - setOption(Option.SYNC_MONITOR, defaultSyncMonitor); - isRunning = true; - } - - - public static void refresh() { - if(syncConnectionManager == null){ - createMonitors(); - } - RequestConfig clientConfig = getRequestConfig(); - - Integer maxTotal = getOptionOrDefault(Option.MAX_TOTAL, MAX_TOTAL); - Integer maxPerRoute = getOptionOrDefault(Option.MAX_PER_ROUTE, MAX_PER_ROUTE); - syncConnectionManager.setMaxTotal(maxTotal); - syncConnectionManager.setDefaultMaxPerRoute(maxPerRoute); - - buildHttpClient(clientConfig); - - PoolingNHttpClientConnectionManager asyncConnectionManager; - try { - asyncConnectionManager = new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor()); - asyncConnectionManager.setMaxTotal(maxTotal); - asyncConnectionManager.setDefaultMaxPerRoute(maxPerRoute); - } catch (IOReactorException e) { - throw new RuntimeException(e); - } - - CloseableHttpAsyncClient asyncClient = buildAsyncClient(clientConfig, asyncConnectionManager); - - setOption(Option.ASYNCHTTPCLIENT, asyncClient); - setOption(Option.ASYNC_MONITOR, new AsyncIdleConnectionMonitorThread(asyncConnectionManager)); - } - - private static CloseableHttpAsyncClient buildAsyncClient(RequestConfig clientConfig, PoolingNHttpClientConnectionManager asyncConnectionManager) { - HttpAsyncClientBuilder ab = HttpAsyncClientBuilder.create() - .setDefaultRequestConfig(clientConfig) - .setConnectionManager(asyncConnectionManager) - .useSystemProperties(); - if(shouldDisableRedirects()){ - ab.setRedirectStrategy(new NoRedirects()); - } - if(shouldDisableCookieManagement()){ - ab.disableCookieManagement(); - } - interceptors.stream().forEach(i -> ab.addInterceptorFirst(i)); - return ab.build(); - } - - private static void buildHttpClient(RequestConfig clientConfig) { - // Create clients - HttpClientBuilder cb = HttpClientBuilder.create() - .setDefaultRequestConfig(clientConfig) - .setConnectionManager(syncConnectionManager) - .useSystemProperties(); - if(shouldDisableRedirects()){ - cb.disableRedirectHandling(); - } - if(shouldDisableCookieManagement()){ - cb.disableCookieManagement(); - } - interceptors.stream().forEach(i -> cb.addInterceptorFirst(i)); - CloseableHttpClient build = cb.build(); - - setOption(Option.HTTPCLIENT, build); - } - - private static boolean shouldDisableCookieManagement() { - return !(Boolean)options.getOrDefault(COOKIE_MANAGEMENT, true); - } - - private static boolean shouldDisableRedirects() { - return !(Boolean)options.getOrDefault(FOLLOW_REDIRECTS, true); - } - - private static RequestConfig getRequestConfig() { - Integer connectionTimeout = getOptionOrDefault(Option.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT); - Integer socketTimeout = getOptionOrDefault(Option.SOCKET_TIMEOUT, SOCKET_TIMEOUT); - HttpHost proxy = (HttpHost) Options.getOption(Option.PROXY); - return RequestConfig.custom() - .setConnectTimeout(connectionTimeout) - .setSocketTimeout(socketTimeout) - .setConnectionRequestTimeout(socketTimeout) - .setProxy(proxy) - .build(); - } - - public static void init() { - createMonitors(); - setDefaults(); - refresh(); - } - - private static void setDefaults() { - customClientSet = false; - setIfAbsent(Option.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT); - setIfAbsent(Option.SOCKET_TIMEOUT, SOCKET_TIMEOUT); - setIfAbsent(Option.MAX_TOTAL, MAX_TOTAL); - setIfAbsent(Option.MAX_PER_ROUTE, MAX_PER_ROUTE); - setIfAbsent(Option.SYNC_MONITOR, defaultSyncMonitor); - } - - public static Optional tryGet(Option option, Class as) { - Object o = getOption(option); - if(Objects.isNull(o) || !as.isAssignableFrom(o.getClass())){ - return Optional.empty(); - } - return Optional.of((T) o); - } - - public static void removeOption(Option objectMapper) { - options.remove(objectMapper); - } - - public static boolean isRunning() { - return isRunning; - } - - public static void shutDown(){ - shutDown(true); - } - - public static void shutDown(boolean clearOptions) { - tryGet(Option.HTTPCLIENT, - CloseableHttpClient.class) - .ifPresent(Options::closeIt); - options.remove(Option.HTTPCLIENT); - - tryGet(Option.SYNC_MONITOR, - SyncIdleConnectionMonitorThread.class) - .ifPresent(Thread::interrupt); - options.remove(Option.SYNC_MONITOR); - - tryGet(Option.ASYNCHTTPCLIENT, - CloseableHttpAsyncClient.class) - .filter(CloseableHttpAsyncClient::isRunning) - .ifPresent(Options::closeIt); - options.remove(Option.ASYNCHTTPCLIENT); - - tryGet(Option.ASYNC_MONITOR, - AsyncIdleConnectionMonitorThread.class) - .ifPresent(Thread::interrupt); - options.remove(Option.ASYNC_MONITOR); - - if(clearOptions){ - options.clear(); - interceptors.clear(); - } - isRunning = false; - } - - public static void closeIt(Closeable c) { - try { - c.close(); - }catch (IOException e){ - throw new UnirestException(e); - } - } - - public static void addInterceptor(HttpRequestInterceptor interceptor) { - interceptors.add(interceptor); - refresh(); - } - - public static void followRedirects(boolean enable) { - options.put(FOLLOW_REDIRECTS, enable); - refresh(); - } - - public static void enableCookieManagement(boolean enable){ - options.put(COOKIE_MANAGEMENT, enable); - refresh(); - } - - public static List getInterceptors() { - return interceptors; - } - - public static HttpClient getHttpClient() { - return (HttpClient) getOption(Option.HTTPCLIENT); - } - - public static CloseableHttpAsyncClient getAsyncHttpClient() { - return (CloseableHttpAsyncClient) getOption(Option.ASYNCHTTPCLIENT); - } -} diff --git a/src/main/java/unirest/RawBody.java b/src/main/java/unirest/RawBody.java index c0af12eb4..289a99b8d 100644 --- a/src/main/java/unirest/RawBody.java +++ b/src/main/java/unirest/RawBody.java @@ -33,8 +33,8 @@ public class RawBody extends BaseRequest implements Body { private byte[] body; - public RawBody(HttpRequest httpRequest) { - super(httpRequest); + public RawBody(Config config, HttpRequest httpRequest) { + super(config, httpRequest); } public RawBody body(byte[] bodyBytes) { diff --git a/src/main/java/unirest/RequestBodyEntity.java b/src/main/java/unirest/RequestBodyEntity.java index 4f0022201..75841e500 100644 --- a/src/main/java/unirest/RequestBodyEntity.java +++ b/src/main/java/unirest/RequestBodyEntity.java @@ -36,8 +36,8 @@ public class RequestBodyEntity extends BaseRequest implements Body { private final HttpRequestWithBody request; private Object body; - public RequestBodyEntity(HttpRequestWithBody httpRequest) { - super(httpRequest); + public RequestBodyEntity(Config config, HttpRequestWithBody httpRequest) { + super(config, httpRequest); request = httpRequest; } diff --git a/src/main/java/unirest/RequestPrep.java b/src/main/java/unirest/RequestPrep.java index 37cee9c69..39058ef20 100644 --- a/src/main/java/unirest/RequestPrep.java +++ b/src/main/java/unirest/RequestPrep.java @@ -45,8 +45,6 @@ class RequestPrep { static HttpRequestBase prepareRequest(HttpRequest request, boolean async) { - setDefaultHeaders(request); - if (!request.getHeaders().containsKey(USER_AGENT_HEADER)) { request.header(USER_AGENT_HEADER, USER_AGENT); } @@ -96,17 +94,6 @@ private static void setRequestHeaders(HttpRequest request, HttpRequestBase reqOb } } - private static void setDefaultHeaders(HttpRequest request) { - Object defaultHeaders = Options.getOption(Option.DEFAULT_HEADERS); - if (defaultHeaders != null) { - @SuppressWarnings("unchecked") - Set> entrySet = ((Map) defaultHeaders).entrySet(); - for (Map.Entry entry : entrySet) { - request.header(entry.getKey(), entry.getValue()); - } - } - } - private static HttpRequestBase getHttpRequest(HttpRequest request) { HttpRequestBase reqObj = null; diff --git a/src/main/java/unirest/ResponseBuilder.java b/src/main/java/unirest/ResponseBuilder.java index c439472bf..f9b082c01 100644 --- a/src/main/java/unirest/ResponseBuilder.java +++ b/src/main/java/unirest/ResponseBuilder.java @@ -34,6 +34,12 @@ class ResponseBuilder { + private final Config config; + + public ResponseBuilder(Config config) { + this.config = config; + } + public HttpResponse asJson(org.apache.http.HttpResponse response) { return new HttpResponseImpl<>(response, from(response.getEntity(), b -> toJson(b))); } @@ -78,12 +84,10 @@ private JsonNode toJson(BodyData b) { } private ObjectMapper getObjectMapper() { - return Options.tryGet(Option.OBJECT_MAPPER, ObjectMapper.class) - .orElseThrow(() -> new UnirestException("No Object Mapper Configured. Please configure one with Unirest.setObjectMapper")); + return config.getObjectMapper(); } public static class ParsingException extends RuntimeException { - public ParsingException(Exception e){ super(e); } diff --git a/src/main/java/unirest/Unirest.java b/src/main/java/unirest/Unirest.java index 367dbaa9a..caa284c1b 100644 --- a/src/main/java/unirest/Unirest.java +++ b/src/main/java/unirest/Unirest.java @@ -26,159 +26,71 @@ package unirest; -import org.apache.http.HttpHost; -import org.apache.http.client.HttpClient; -import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; - -import java.util.HashMap; -import java.util.Map; - public class Unirest { - /** - * Set the HttpClient implementation to use for every synchronous request - * - * @param httpClient Custom httpClient implementation - */ - public static void setHttpClient(HttpClient httpClient) { - Options.setOption(Option.HTTPCLIENT, httpClient); - Options.customClientSet(); - } - - /** - * Set the asynchronous AbstractHttpAsyncClient implementation to use for every asynchronous request - * - * @param asyncHttpClient Custom CloseableHttpAsyncClient implementation - */ - public static void setAsyncHttpClient(CloseableHttpAsyncClient asyncHttpClient) { - Options.setOption(Option.ASYNCHTTPCLIENT, asyncHttpClient); - Options.customClientSet(); - } - - /** - * Set a proxy - * - * @param proxy Proxy settings object. - */ - public static void setProxy(HttpHost proxy) { - Options.setOption(Option.PROXY, proxy); - - // Reload the client implementations - Options.refresh(); - } + private static Unirest primaryInstance = new Unirest(new Config()); + private final Config config; - /** - * Set the ObjectMapper implementation to use for Response to Object binding - * - * @param objectMapper Custom implementation of ObjectMapper interface - */ - public static void setObjectMapper(ObjectMapper objectMapper) { - Options.setOption(Option.OBJECT_MAPPER, objectMapper); - - // Reload the client implementations - Options.refresh(); - } - - /** - * Set the connection timeout and socket timeout - * - * @param connectionTimeout The timeout until a connection with the server is established (in milliseconds). Default is 10000. Set to zero to disable the timeout. - * @param socketTimeout The timeout to receive data (in milliseconds). Default is 60000. Set to zero to disable the timeout. - */ - public static void setTimeouts(int connectionTimeout, int socketTimeout) { - Options.setOption(Option.CONNECTION_TIMEOUT, connectionTimeout); - Options.setOption(Option.SOCKET_TIMEOUT, socketTimeout); - - // Reload the client implementations - Options.refresh(); - } - - /** - * Set the concurrency levels - * - * @param maxTotal Defines the overall connection limit for a connection pool. Default is 200. - * @param maxPerRoute Defines a connection limit per one HTTP route (this can be considered a per target host limit). Default is 20. - */ - public static void setConcurrency(int maxTotal, int maxPerRoute) { - Options.setOption(Option.MAX_TOTAL, maxTotal); - Options.setOption(Option.MAX_PER_ROUTE, maxPerRoute); - - // Reload the client implementations - Options.refresh(); - } - - /** - * Clear default headers - */ - public static void clearDefaultHeaders() { - Options.setOption(Option.DEFAULT_HEADERS, null); + public Unirest(Config config) { + this.config = config; } /** - * Set default header to appear on all requests - * - * @param name The name of the header. - * @param value The value of the header. + * Access the default configuration for the primary Unirest instance. */ - @SuppressWarnings("unchecked") - public static void setDefaultHeader(String name, String value) { - Object headers = Options.getOption(Option.DEFAULT_HEADERS); - if (headers == null) { - headers = new HashMap(); - } - ((Map) headers).put(name, value); - Options.setOption(Option.DEFAULT_HEADERS, headers); + public static Config config(){ + return primaryInstance.config; } /** * Close the asynchronous client and its event loop. Use this method to close all the threads and allow an application to exit. * This will also clear any options returning Unirest to a default state */ - public static void shutdown() { - shutdown(true); + public static void shutDown() { + shutDown(true); } /** * Close the asynchronous client and its event loop. Use this method to close all the threads and allow an application to exit. - * @param clearOptions indicates if options should be cleared. Note that the HttpClient, AsyncClient and thread monitors will not be retained after shutdown. + * @param clearOptions indicates if options should be cleared. Note that the HttpClient, AsyncClient and thread monitors will not be retained after shutDown. */ - public static void shutdown(boolean clearOptions) { - Options.shutDown(clearOptions); + public static void shutDown(boolean clearOptions) { + primaryInstance.config.shutDown(clearOptions); } public static GetRequest get(String url) { - return new GetRequest(HttpMethod.GET, url); + return new GetRequest(primaryInstance.config, HttpMethod.GET, url); } public static GetRequest head(String url) { - return new GetRequest(HttpMethod.HEAD, url); + return new GetRequest(primaryInstance.config, HttpMethod.HEAD, url); } public static HttpRequestWithBody options(String url) { - return new HttpRequestWithBody(HttpMethod.OPTIONS, url); + return new HttpRequestWithBody(primaryInstance.config, HttpMethod.OPTIONS, url); } public static HttpRequestWithBody post(String url) { - return new HttpRequestWithBody(HttpMethod.POST, url); + return new HttpRequestWithBody(primaryInstance.config, HttpMethod.POST, url); } public static HttpRequestWithBody delete(String url) { - return new HttpRequestWithBody(HttpMethod.DELETE, url); + return new HttpRequestWithBody(primaryInstance.config, HttpMethod.DELETE, url); } public static HttpRequestWithBody patch(String url) { - return new HttpRequestWithBody(HttpMethod.PATCH, url); + return new HttpRequestWithBody(primaryInstance.config, HttpMethod.PATCH, url); } public static HttpRequestWithBody put(String url) { - return new HttpRequestWithBody(HttpMethod.PUT, url); + return new HttpRequestWithBody(primaryInstance.config, HttpMethod.PUT, url); } public static JsonPatchRequest jsonPatch(String url) { - return new JsonPatchRequest(url); + return new JsonPatchRequest(primaryInstance.config, url); } public static boolean isRunning() { - return Options.isRunning(); + return primaryInstance.config.isRunning(); } } diff --git a/src/main/java/unirest/UnirestConfigException.java b/src/main/java/unirest/UnirestConfigException.java index d76852796..1f5f47edf 100644 --- a/src/main/java/unirest/UnirestConfigException.java +++ b/src/main/java/unirest/UnirestConfigException.java @@ -27,6 +27,10 @@ package unirest; public class UnirestConfigException extends UnirestException { + public UnirestConfigException(Exception e){ + super(e); + } + public UnirestConfigException(String msg) { super(msg); } diff --git a/src/main/java/unirest/UnirestException.java b/src/main/java/unirest/UnirestException.java index fbf150a7e..50fba4f6a 100644 --- a/src/main/java/unirest/UnirestException.java +++ b/src/main/java/unirest/UnirestException.java @@ -26,6 +26,9 @@ package unirest; +import java.util.Collection; +import java.util.stream.Collectors; + public class UnirestException extends RuntimeException { private static final long serialVersionUID = -3714840499934575734L; @@ -41,4 +44,8 @@ public UnirestException(String msg) { public UnirestException(Throwable ex) { super(ex); } + + public UnirestException(Collection ex) { + super(ex.stream().map(e -> e.getClass().getName() + " " + e.getMessage()).collect(Collectors.joining("\n"))); + } } diff --git a/src/main/java/unirest/Util.java b/src/main/java/unirest/Util.java new file mode 100644 index 000000000..1f7f6d403 --- /dev/null +++ b/src/main/java/unirest/Util.java @@ -0,0 +1,64 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Stream; + +class Util { + + //In Java 9 this has been added as Optional::stream. Remove this whenever we get there. + static Stream stream(Optional opt) { + return opt.map(Stream::of).orElseGet(Stream::empty); + } + + static Optional tryCast(T original, Class too) { + if (original != null && too.isAssignableFrom(original.getClass())) { + return Optional.of((M) original); + } + return Optional.empty(); + } + + public static Optional tryDo(T c, ExConsumer consumer) { + try { + if (Objects.nonNull(c)) { + consumer.accept(c); + } + return Optional.empty(); + } catch (Exception e) { + return Optional.of(e); + } + } + + + + @FunctionalInterface + public interface ExConsumer{ + void accept(T t) throws Exception; + } +} diff --git a/src/test/java/BehaviorTests/AsGenericTypeTest.java b/src/test/java/BehaviorTests/AsGenericTypeTest.java index 2b950627e..5281e87fe 100644 --- a/src/test/java/BehaviorTests/AsGenericTypeTest.java +++ b/src/test/java/BehaviorTests/AsGenericTypeTest.java @@ -97,7 +97,7 @@ public void soManyLayersOfGenerics() { @Test public void itAlsoWorksWithGson() { - Unirest.setObjectMapper(new GsonObjectMapper()); + Unirest.config().setObjectMapper(new GsonObjectMapper()); MockServer.setJsonAsResponse(new WeirdType<>(foos, "hey")); diff --git a/src/test/java/BehaviorTests/BddTest.java b/src/test/java/BehaviorTests/BddTest.java index 473574fef..50640d836 100644 --- a/src/test/java/BehaviorTests/BddTest.java +++ b/src/test/java/BehaviorTests/BddTest.java @@ -26,6 +26,7 @@ package BehaviorTests; +import org.junit.After; import unirest.*; import org.junit.Before; @@ -47,12 +48,16 @@ public class BddTest { public void setUp() { //TestUtil.debugApache(); MockServer.reset(); - Options.init(); - Unirest.setObjectMapper(objectMapper); + Unirest.config().setObjectMapper(objectMapper); lock = new CountDownLatch(1); status = false; } + @After + public void tearDown() { + Unirest.shutDown(true); + } + public void assertAsync() { try { lock.await(5, TimeUnit.SECONDS); diff --git a/src/test/java/BehaviorTests/HeaderTest.java b/src/test/java/BehaviorTests/HeaderTest.java index f5ae376eb..b436754e8 100644 --- a/src/test/java/BehaviorTests/HeaderTest.java +++ b/src/test/java/BehaviorTests/HeaderTest.java @@ -72,8 +72,8 @@ public void unicodeBasicAuth() { @Test public void testDefaultHeaders() { - Unirest.setDefaultHeader("X-Custom-Header", "hello"); - Unirest.setDefaultHeader("user-agent", "foobar"); + Unirest.config().setDefaultHeader("X-Custom-Header", "hello"); + Unirest.config().setDefaultHeader("user-agent", "foobar"); HttpResponse jsonResponse = Unirest.get(MockServer.GET).asJson(); @@ -86,7 +86,7 @@ public void testDefaultHeaders() { .assertHeader("X-Custom-Header", "hello") .assertHeader("User-Agent", "foobar"); - Unirest.clearDefaultHeaders(); + Unirest.config().clearDefaultHeaders(); jsonResponse = Unirest.get(MockServer.GET).asJson(); parse(jsonResponse) diff --git a/src/test/java/BehaviorTests/InterceptorTest.java b/src/test/java/BehaviorTests/InterceptorTest.java index 06027144a..b08533ce5 100644 --- a/src/test/java/BehaviorTests/InterceptorTest.java +++ b/src/test/java/BehaviorTests/InterceptorTest.java @@ -27,7 +27,6 @@ package BehaviorTests; import unirest.Unirest; -import unirest.Options; import org.apache.http.HttpException; import org.apache.http.HttpRequest; import org.apache.http.HttpRequestInterceptor; @@ -40,7 +39,7 @@ public class InterceptorTest extends BddTest { @Test public void canAddInterceptor() { - Options.addInterceptor(new TestInterceptor()); + Unirest.config().addInterceptor(new TestInterceptor()); Unirest.get(MockServer.GET) .asObject(RequestCapture.class) @@ -50,7 +49,7 @@ public void canAddInterceptor() { @Test public void canAddInterceptorToAsync() throws ExecutionException, InterruptedException { - Options.addInterceptor(new TestInterceptor()); + Unirest.config().addInterceptor(new TestInterceptor()); Unirest.get(MockServer.GET) .asObjectAsync(RequestCapture.class) diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index 2e35e72c3..f72e3efe9 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -26,52 +26,96 @@ package BehaviorTests; -import unirest.Unirest; -import unirest.AsyncIdleConnectionMonitorThread; -import unirest.Options; -import unirest.SyncIdleConnectionMonitorThread; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import unirest.*; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.junit.Test; import java.io.IOException; - -import static unirest.Option.*; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.*; +@RunWith(MockitoJUnitRunner.class) public class LifeCycleTest extends BddTest { + @Mock + private CloseableHttpClient httpc; + @Mock + private PoolingHttpClientConnectionManager clientManager; + @Mock + private SyncIdleConnectionMonitorThread connMonitor; + @Mock + private CloseableHttpAsyncClient asyncClient; + @Mock + private AsyncIdleConnectionMonitorThread asyncMonitor; + @Mock + private PoolingNHttpClientConnectionManager manager; + @Test public void testShutdown() throws IOException { - CloseableHttpClient httpc = mock(CloseableHttpClient.class); - SyncIdleConnectionMonitorThread connMonitor = mock(SyncIdleConnectionMonitorThread.class); - CloseableHttpAsyncClient asyncClient = mock(CloseableHttpAsyncClient.class); when(asyncClient.isRunning()).thenReturn(true); - AsyncIdleConnectionMonitorThread asyncMonitor = mock(AsyncIdleConnectionMonitorThread.class); - Options.setOption(HTTPCLIENT, httpc); - Options.setOption(SYNC_MONITOR, connMonitor); - Options.setOption(ASYNCHTTPCLIENT, asyncClient); - Options.setOption(ASYNC_MONITOR, asyncMonitor); + Unirest.config() + .httpClient(new ClientConfig(httpc, clientManager, connMonitor)) + .asyncClient(new AsyncConfig(asyncClient, manager, asyncMonitor)); - Unirest.shutdown(); + Unirest.shutDown(); verify(httpc).close(); + verify(clientManager).close(); verify(connMonitor).interrupt(); verify(asyncClient).close(); verify(asyncMonitor).interrupt(); } @Test - public void DoesNotBombOnNullOptions() throws IOException { - Options.setOption(HTTPCLIENT, null); - Options.setOption(SYNC_MONITOR, null); - Options.setOption(ASYNCHTTPCLIENT, null); - Options.setOption(ASYNC_MONITOR, null); + public void willPowerThroughErrors() throws IOException { + when(asyncClient.isRunning()).thenReturn(true); + doThrow(new IOException("1")).when(httpc).close(); + doThrow(new RuntimeException("2")).when(clientManager).close(); + doThrow(new RuntimeException("3")).when(connMonitor).interrupt(); + doThrow(new IOException("4")).when(asyncClient).close(); + doThrow(new RuntimeException("5")).when(asyncMonitor).interrupt(); + + Unirest.config() + .httpClient(new ClientConfig(httpc, clientManager, connMonitor)) + .asyncClient(new AsyncConfig(asyncClient, manager, asyncMonitor)); + - Unirest.shutdown(); + TestUtil.assertException(Unirest::shutDown, + UnirestException.class, + "java.io.IOException 1\n" + + "java.lang.RuntimeException 2\n" + + "java.lang.RuntimeException 3\n" + + "java.io.IOException 4\n" + + "java.lang.RuntimeException 5"); + + verify(httpc).close(); + verify(clientManager).close(); + verify(connMonitor).interrupt(); + verify(asyncClient).close(); + verify(asyncMonitor).interrupt(); + } + + @Test + public void doesNotBombOnNullOptions() throws IOException { + when(asyncClient.isRunning()).thenReturn(true); + + Unirest.config() + .httpClient(new ClientConfig(httpc, null, null)) + .asyncClient(new AsyncConfig(asyncClient, null, null)); + + Unirest.shutDown(); + + verify(httpc).close(); + verify(asyncClient).close(); } @Test @@ -79,9 +123,9 @@ public void willNotShutdownInactiveAsyncClient() throws IOException { CloseableHttpAsyncClient asyncClient = mock(CloseableHttpAsyncClient.class); when(asyncClient.isRunning()).thenReturn(false); - Options.setOption(ASYNCHTTPCLIENT, asyncClient); + Unirest.config().asyncClient(asyncClient); - Unirest.shutdown(); + Unirest.shutDown(); verify(asyncClient, never()).close(); } @@ -91,16 +135,16 @@ public void canDetectIfSystemIsRunning() { Unirest.get(MockServer.GET).asBinary(); assertTrue(Unirest.isRunning()); - Unirest.shutdown(); + Unirest.shutDown(); assertFalse(Unirest.isRunning()); - Options.init(); + Unirest.get(MockServer.GET).asBinary(); assertTrue(Unirest.isRunning()); } @Test public void willReinitIfLibraryIsUsedAfterShutdown() { - Unirest.shutdown(); + Unirest.shutDown(); assertFalse(Unirest.isRunning()); Unirest.get(MockServer.GET).asBinary(); diff --git a/src/test/java/BehaviorTests/RedirectHandling.java b/src/test/java/BehaviorTests/RedirectHandling.java index 2ced3acc2..3cc69b675 100644 --- a/src/test/java/BehaviorTests/RedirectHandling.java +++ b/src/test/java/BehaviorTests/RedirectHandling.java @@ -28,7 +28,6 @@ import unirest.HttpResponse; import unirest.Unirest; -import unirest.Options; import org.junit.Test; import java.util.concurrent.ExecutionException; @@ -47,7 +46,7 @@ public void willFollowRedirectsByDefault() { @Test public void canDisableRedirects(){ - Options.followRedirects(false); + Unirest.config().followRedirects(false); HttpResponse response = Unirest.get(MockServer.REDIRECT).asBinary(); assertEquals(301, response.getStatus()); @@ -64,7 +63,7 @@ public void willFollowRedirectsByDefaultAsync() throws ExecutionException, Inter @Test public void canDisableRedirectsAsync() throws ExecutionException, InterruptedException { - Options.followRedirects(false); + Unirest.config().followRedirects(false); HttpResponse response = Unirest.get(MockServer.REDIRECT).asBinaryAsync().get(); assertEquals(301, response.getStatus()); diff --git a/src/test/java/BehaviorTests/SendBodyTest.java b/src/test/java/BehaviorTests/SendBodyTest.java index 282c5146e..14f1d03d6 100644 --- a/src/test/java/BehaviorTests/SendBodyTest.java +++ b/src/test/java/BehaviorTests/SendBodyTest.java @@ -126,10 +126,10 @@ public void postBodyAsJsonNode() { @Test public void cantPostObjectWithoutObjectMapper(){ - Unirest.setObjectMapper(null); + Unirest.config().setObjectMapper(null); assertException(() -> Unirest.post(MockServer.POST).body(new Foo("die")), UnirestConfigException.class, - "Serialization Impossible. Can't find an ObjectMapper implementation."); + "No Object Mapper Configured. Please config one with Unirest.config().setObjectMapper"); } } diff --git a/src/test/java/BehaviorTests/TimeoutTests.java b/src/test/java/BehaviorTests/TimeoutTests.java index 4801bbb14..2476fc861 100644 --- a/src/test/java/BehaviorTests/TimeoutTests.java +++ b/src/test/java/BehaviorTests/TimeoutTests.java @@ -28,9 +28,9 @@ package BehaviorTests; +import unirest.Config; import unirest.Unirest; import unirest.UnirestException; -import unirest.Options; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; import org.junit.Ignore; @@ -55,11 +55,12 @@ public void testSetTimeouts() throws IOException { try { Unirest.get("http://" + address + "/").asString(); } catch (Exception e) { - if (System.currentTimeMillis() - start > Options.CONNECTION_TIMEOUT + 100) { // Add 100ms for code execution + if (System.currentTimeMillis() - start > Config.DEFAULT_CONNECTION_TIMEOUT + 100) { // Add 100ms for code execution fail(); } } - Unirest.setTimeouts(2000, 10000); + Unirest.config().connectTimeout(2000).socketTimeout(10000); + start = System.currentTimeMillis(); try { Unirest.get("http://" + address + "/").asString(); @@ -73,13 +74,13 @@ public void testSetTimeouts() throws IOException { @Test @Ignore // this is flakey public void parallelTest() throws InterruptedException { - Unirest.setConcurrency(10, 5); + Unirest.config().connectTimeout(10).socketTimeout(5); long start = System.currentTimeMillis(); makeParallelRequests(); long smallerConcurrencyTime = (System.currentTimeMillis() - start); - Unirest.setConcurrency(200, 20); + Unirest.config().connectTimeout(200).socketTimeout(20); start = System.currentTimeMillis(); makeParallelRequests(); long higherConcurrencyTime = (System.currentTimeMillis() - start); @@ -107,28 +108,28 @@ private void makeParallelRequests() throws InterruptedException { @Test public void setTimeoutsAndCustomClient() { try { - Unirest.setTimeouts(1000, 2000); + Unirest.config().connectTimeout(1000).socketTimeout(2000); } catch (Exception e) { fail(); } try { - Unirest.setAsyncHttpClient(HttpAsyncClientBuilder.create().build()); + Unirest.config().asyncClient(HttpAsyncClientBuilder.create().build()); } catch (Exception e) { fail(); } try { - Unirest.setAsyncHttpClient(HttpAsyncClientBuilder.create().build()); - Unirest.setTimeouts(1000, 2000); + Unirest.config().asyncClient(HttpAsyncClientBuilder.create().build()); + Unirest.config().connectTimeout(1000).socketTimeout(2000); fail(); } catch (Exception e) { // Ok } try { - Unirest.setHttpClient(HttpClientBuilder.create().build()); - Unirest.setTimeouts(1000, 2000); + Unirest.config().httpClient(HttpClientBuilder.create().build()); + Unirest.config().connectTimeout(1000).socketTimeout(2000); fail(); } catch (Exception e) { // Ok diff --git a/src/test/java/unirest/OptionsTest.java b/src/test/java/unirest/ClientFactoryTest.java similarity index 52% rename from src/test/java/unirest/OptionsTest.java rename to src/test/java/unirest/ClientFactoryTest.java index 3bebfcd47..cdec84235 100644 --- a/src/test/java/unirest/OptionsTest.java +++ b/src/test/java/unirest/ClientFactoryTest.java @@ -26,87 +26,47 @@ package unirest; -import unirest.JacksonObjectMapper; import org.apache.http.HttpRequestInterceptor; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.junit.After; -import unirest.ObjectMapper; import org.junit.Before; import org.junit.Test; -import unirest.Option; -import unirest.Options; import java.lang.management.ManagementFactory; -import java.util.stream.IntStream; -import static unirest.Option.CONNECTION_TIMEOUT; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.lessThan; import static org.junit.Assert.*; import static org.mockito.Mockito.mock; -public class OptionsTest { +public class ClientFactoryTest { @Before @After public void before(){ - Options.shutDown(true); - } - - @Test - public void shouldKeepConnectionTimeOutDefault(){ - assertOpDefault(Options.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT, 4L); - } - - @Test - public void shouldKeepSocketTimeoutDefault(){ - assertOpDefault(Options.SOCKET_TIMEOUT, Option.SOCKET_TIMEOUT, 4L); - } - - @Test - public void shouldKeepMaxTotalDefault(){ - assertOpDefault(Options.MAX_TOTAL, Option.MAX_TOTAL, 4); - } - - @Test - public void shouldKeepMaxPerRouteDefault(){ - assertOpDefault(Options.MAX_PER_ROUTE, Option.MAX_PER_ROUTE, 4); + Unirest.shutDown(true); } @Test public void shouldReuseThreadPool() { int startingCount = ManagementFactory.getThreadMXBean().getThreadCount(); - IntStream.range(0,100).forEach(i -> Options.refresh()); + //IntStream.range(0,100).forEach(i -> ClientFactory.refresh()); assertThat(ManagementFactory.getThreadMXBean().getThreadCount(), is(lessThan(startingCount + 10))); } - @Test - public void canTryGet(){ - assertEquals(false, Options.tryGet(Option.OBJECT_MAPPER, ObjectMapper.class).isPresent()); - Options.setOption(Option.OBJECT_MAPPER, "foo"); - assertEquals(false, Options.tryGet(Option.OBJECT_MAPPER, ObjectMapper.class).isPresent()); - JacksonObjectMapper value = new JacksonObjectMapper(); - Options.setOption(Option.OBJECT_MAPPER, value); - assertEquals(value, Options.tryGet(Option.OBJECT_MAPPER, ObjectMapper.class).get()); - } - @Test public void canSaveSomeOptions(){ HttpRequestInterceptor i = mock(HttpRequestInterceptor.class); CloseableHttpAsyncClient c = mock(CloseableHttpAsyncClient.class); - Options.addInterceptor(i); - Options.setOption(Option.ASYNCHTTPCLIENT, c); - Options.setOption(CONNECTION_TIMEOUT, 4000); - Options.shutDown(false); + Unirest.config() + .addInterceptor(i) + .connectTimeout(4000) + .asyncClient(c); - assertNotEquals(c, Options.getOption(Option.ASYNCHTTPCLIENT)); - assertEquals(i, Options.getInterceptors().get(0)); - assertEquals(4000, Options.getOption(CONNECTION_TIMEOUT)); - } + Unirest.shutDown(false); - private void assertOpDefault(Object defValue, Option option, Object newValue) { - assertEquals(defValue, Options.getOption(option)); - Options.setOption(option, newValue); - assertEquals(newValue, Options.getOption(option)); + assertNotEquals(c, Unirest.config().getAsyncHttpClient()); + assertEquals(i, Unirest.config().getInterceptors().get(0)); + assertEquals(4000, Unirest.config().getConnectionTimeout()); } } \ No newline at end of file diff --git a/src/test/java/unirest/ConfigTest.java b/src/test/java/unirest/ConfigTest.java new file mode 100644 index 000000000..ea8c8501e --- /dev/null +++ b/src/test/java/unirest/ConfigTest.java @@ -0,0 +1,61 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.runners.MockitoJUnitRunner; + +import static org.junit.Assert.*; + +@RunWith(MockitoJUnitRunner.class) +public class ConfigTest { + + @InjectMocks + private Config config; + + @Test + public void shouldKeepConnectionTimeOutDefault(){ + assertEquals(Config.DEFAULT_CONNECT_TIMEOUT, config.getConnectionTimeout()); + } + + @Test + public void shouldKeepSocketTimeoutDefault(){ + assertEquals(Config.DEFAULT_SOCKET_TIMEOUT, config.getSocketTimeout()); + } + + @Test + public void shouldKeepMaxTotalDefault(){ + assertEquals(Config.DEFAULT_MAX_CONNECTIONS, config.getMaxConnections()); + } + + @Test + public void shouldKeepMaxPerRouteDefault(){ + assertEquals(Config.DEFAULT_MAX_PER_ROUTE, config.getMaxPerRoutes()); + } +} \ No newline at end of file diff --git a/src/test/java/unirest/ResponseBuilderTest.java b/src/test/java/unirest/ResponseBuilderTest.java index 5295e6e1e..04472f774 100644 --- a/src/test/java/unirest/ResponseBuilderTest.java +++ b/src/test/java/unirest/ResponseBuilderTest.java @@ -27,14 +27,10 @@ package unirest; import BehaviorTests.Foo; -import unirest.MockApacheResponse; -import unirest.*; -import unirest.JacksonObjectMapper; import org.apache.http.ProtocolVersion; import org.apache.http.message.BasicStatusLine; import org.junit.Before; import org.junit.Test; -import unirest.TestUtil; import java.io.InputStream; @@ -44,13 +40,15 @@ import static unirest.TestUtil.toJson; public class ResponseBuilderTest { - private final ResponseBuilder builder = new ResponseBuilder(); + private Config config; + private ResponseBuilder builder; private MockApacheResponse response; @Before public void setUp() { response = new MockApacheResponse(); - Options.setOption(Option.OBJECT_MAPPER, new JacksonObjectMapper()); + config = new Config().setObjectMapper(new JacksonObjectMapper()); + builder = new ResponseBuilder(config); } @Test @@ -96,13 +94,13 @@ public void canGetObjectMappedResponse() { @Test public void willThrowErrorIfNoObjectMapperIsConfigured(){ - Options.removeOption(Option.OBJECT_MAPPER); + config.setObjectMapper(null); response.setBody(toJson(new Foo("I like cheese"))); assertException(() -> builder.asObject(response, Foo.class), UnirestException.class, - "No Object Mapper Configured. Please configure one with Unirest.setObjectMapper"); + "No Object Mapper Configured. Please config one with Unirest.config().setObjectMapper"); } @Test diff --git a/src/test/java/unirest/UriFormatterTest.java b/src/test/java/unirest/UriFormatterTest.java index b2048ae0f..94496680d 100644 --- a/src/test/java/unirest/UriFormatterTest.java +++ b/src/test/java/unirest/UriFormatterTest.java @@ -62,7 +62,7 @@ public void utf8Chars(){ } private void assertLinkSurvives(String s) { - assertEquals(s, helper.apply(new HttpRequest(HttpMethod.GET, s))); + assertEquals(s, helper.apply(new HttpRequest(new Config(), HttpMethod.GET, s))); } } \ No newline at end of file diff --git a/src/main/java/unirest/Option.java b/src/test/java/unirest/UtilTest.java similarity index 77% rename from src/main/java/unirest/Option.java rename to src/test/java/unirest/UtilTest.java index b6d2835f5..31e251221 100644 --- a/src/main/java/unirest/Option.java +++ b/src/test/java/unirest/UtilTest.java @@ -26,18 +26,20 @@ package unirest; -public enum Option { - HTTPCLIENT, - ASYNCHTTPCLIENT, - CONNECTION_TIMEOUT, - SOCKET_TIMEOUT, - DEFAULT_HEADERS, - SYNC_MONITOR, - ASYNC_MONITOR, - MAX_TOTAL, - MAX_PER_ROUTE, - PROXY, - OBJECT_MAPPER, - FOLLOW_REDIRECTS, - COOKIE_MANAGEMENT; -} +import org.junit.Test; + +import static org.junit.Assert.*; + +public class UtilTest { + + @Test + public void canCast() { + Object foo = new Foo(); + + assertEquals(foo, Util.tryCast(foo, Foo.class).get()); + assertEquals(false, Util.tryCast("foo", Foo.class).isPresent()); + assertEquals(false, Util.tryCast(null, Foo.class).isPresent()); + } + + public class Foo {} +} \ No newline at end of file From ca5c24e145c778766e87911303cb67068a8da168 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 6 Nov 2018 21:27:48 -0600 Subject: [PATCH 0231/1769] move static methods into the only class they are used --- src/main/java/unirest/BaseRequest.java | 225 +++++++++++++------- src/main/java/unirest/HttpClientHelper.java | 97 --------- 2 files changed, 147 insertions(+), 175 deletions(-) delete mode 100644 src/main/java/unirest/HttpClientHelper.java diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 0aaf60b33..93c30379e 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -26,87 +26,156 @@ package unirest; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.concurrent.FutureCallback; + import java.io.InputStream; +import java.util.Objects; import java.util.concurrent.CompletableFuture; +import java.util.function.Function; public abstract class BaseRequest { - private final ResponseBuilder builder; - private final Config config; - protected HttpRequest httpRequest; - - protected BaseRequest(Config config, HttpRequest httpRequest) { - this.config = config; - this.httpRequest = httpRequest; - this.builder = new ResponseBuilder(config); - } - - protected BaseRequest(Config config) { - this.config = config; - this.builder = new ResponseBuilder(config); - } - - public HttpRequest getHttpRequest() { - return this.httpRequest; - } - - public HttpResponse asString() throws UnirestException { - return HttpClientHelper.request(config, httpRequest, builder::asString); - } - - public CompletableFuture> asStringAsync() { - return HttpClientHelper.requestAsync(config, httpRequest, builder::asString); - } - - public CompletableFuture> asStringAsync(Callback callback) { - return HttpClientHelper.requestAsync(config, httpRequest, builder::asString, callback); - } - - public HttpResponse asJson() throws UnirestException { - return HttpClientHelper.request(config, httpRequest, builder::asJson); - } - - public CompletableFuture> asJsonAsync() { - return HttpClientHelper.requestAsync(config, httpRequest, builder::asJson); - } - - public CompletableFuture> asJsonAsync(Callback callback) { - return HttpClientHelper.requestAsync(config, httpRequest, builder::asJson, callback); - } - - public HttpResponse asObject(Class responseClass) throws UnirestException { - return HttpClientHelper.request(config, httpRequest, r -> builder.asObject(r, responseClass)); - } - - public HttpResponse asObject(GenericType genericType) throws UnirestException { - return HttpClientHelper.request(config, httpRequest, r -> builder.asObject(r, genericType)); - } - - public CompletableFuture> asObjectAsync(Class responseClass) { - return HttpClientHelper.requestAsync(config, httpRequest, r -> builder.asObject(r, responseClass)); - } - - public CompletableFuture> asObjectAsync(Class responseClass, Callback callback) { - return HttpClientHelper.requestAsync(config, httpRequest, r -> builder.asObject(r, responseClass), callback); - } - - public CompletableFuture> asObjectAsync(GenericType genericType) { - return HttpClientHelper.requestAsync(config, httpRequest, r -> builder.asObject(r, genericType)); - } - - public CompletableFuture> asObjectAsync(GenericType genericType, Callback callback) { - return HttpClientHelper.requestAsync(config, httpRequest, r -> builder.asObject(r, genericType), callback); - } - - public HttpResponse asBinary() throws UnirestException { - return HttpClientHelper.request(config, httpRequest, builder::asBinary); - } - - public CompletableFuture> asBinaryAsync() { - return HttpClientHelper.requestAsync(config, httpRequest, builder::asBinary); - } - - public CompletableFuture> asBinaryAsync(Callback callback) { - return HttpClientHelper.requestAsync(config, httpRequest, builder::asBinary, callback); - } + private final ResponseBuilder builder; + private final Config config; + protected HttpRequest httpRequest; + + protected BaseRequest(Config config, HttpRequest httpRequest) { + this.config = config; + this.httpRequest = httpRequest; + this.builder = new ResponseBuilder(config); + } + + protected BaseRequest(Config config) { + this.config = config; + this.builder = new ResponseBuilder(config); + } + + public HttpRequest getHttpRequest() { + return this.httpRequest; + } + + public HttpResponse asString() throws UnirestException { + return request(httpRequest, builder::asString); + } + + public CompletableFuture> asStringAsync() { + return requestAsync(httpRequest, builder::asString); + } + + public CompletableFuture> asStringAsync(Callback callback) { + return requestAsync(httpRequest, builder::asString, callback); + } + + public HttpResponse asJson() throws UnirestException { + return request(httpRequest, builder::asJson); + } + + public CompletableFuture> asJsonAsync() { + return requestAsync(httpRequest, builder::asJson); + } + + public CompletableFuture> asJsonAsync(Callback callback) { + return requestAsync(httpRequest, builder::asJson, callback); + } + + public HttpResponse asObject(Class responseClass) throws UnirestException { + return request(httpRequest, r -> builder.asObject(r, responseClass)); + } + + public HttpResponse asObject(GenericType genericType) throws UnirestException { + return request(httpRequest, r -> builder.asObject(r, genericType)); + } + + public CompletableFuture> asObjectAsync(Class responseClass) { + return requestAsync(httpRequest, r -> builder.asObject(r, responseClass)); + } + + public CompletableFuture> asObjectAsync(Class responseClass, Callback callback) { + return requestAsync(httpRequest, r -> builder.asObject(r, responseClass), callback); + } + + public CompletableFuture> asObjectAsync(GenericType genericType) { + return requestAsync(httpRequest, r -> builder.asObject(r, genericType)); + } + + public CompletableFuture> asObjectAsync(GenericType genericType, Callback callback) { + return requestAsync(httpRequest, r -> builder.asObject(r, genericType), callback); + } + + public HttpResponse asBinary() throws UnirestException { + return request(httpRequest, builder::asBinary); + } + + public CompletableFuture> asBinaryAsync() { + return requestAsync(httpRequest, builder::asBinary); + } + + public CompletableFuture> asBinaryAsync(Callback callback) { + return requestAsync(httpRequest, builder::asBinary, callback); + } + + + private HttpResponse request(HttpRequest request, + Function> transformer) { + + HttpRequestBase requestObj = RequestPrep.prepareRequest(request, false); + HttpClient client = config.getClient(); + + org.apache.http.HttpResponse response; + try { + response = client.execute(requestObj); + HttpResponse httpResponse = transformer.apply(response); + requestObj.releaseConnection(); + return httpResponse; + } catch (Exception e) { + throw new UnirestException(e); + } finally { + requestObj.releaseConnection(); + } + } + + private CompletableFuture> requestAsync( + HttpRequest request, + Function> transformer) { + return requestAsync(request, transformer, new CompletableFuture<>()); + } + + private CompletableFuture> requestAsync( + HttpRequest request, + Function> transformer, + Callback callback) { + return requestAsync(request, transformer, CallbackFuture.wrap(callback)); + } + + private CompletableFuture> requestAsync( + HttpRequest request, + Function> transformer, + CompletableFuture> callback) { + + Objects.requireNonNull(callback); + + HttpUriRequest requestObj = RequestPrep.prepareRequest(request, true); + + config.getAsyncHttpClient() + .execute(requestObj, new FutureCallback() { + @Override + public void completed(org.apache.http.HttpResponse httpResponse) { + callback.complete(transformer.apply(httpResponse)); + } + + @Override + public void failed(Exception e) { + callback.completeExceptionally(e); + } + + @Override + public void cancelled() { + callback.completeExceptionally(new UnirestException("canceled")); + } + }); + return callback; + } } diff --git a/src/main/java/unirest/HttpClientHelper.java b/src/main/java/unirest/HttpClientHelper.java deleted file mode 100644 index c83b5a79e..000000000 --- a/src/main/java/unirest/HttpClientHelper.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package unirest; - -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpRequestBase; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.concurrent.FutureCallback; - -import java.util.Objects; -import java.util.concurrent.CompletableFuture; -import java.util.function.Function; - -class HttpClientHelper { - - static HttpResponse request(Config config, HttpRequest request, - Function> transformer) { - - HttpRequestBase requestObj = RequestPrep.prepareRequest(request, false); - HttpClient client = config.getClient(); - - org.apache.http.HttpResponse response; - try { - response = client.execute(requestObj); - HttpResponse httpResponse = transformer.apply(response); - requestObj.releaseConnection(); - return httpResponse; - } catch (Exception e) { - throw new UnirestException(e); - } finally { - requestObj.releaseConnection(); - } - } - - static CompletableFuture> requestAsync(Config config, HttpRequest httpRequest, Function> transformer) { - return requestAsync(config, httpRequest, transformer, new CompletableFuture<>()); - } - - static CompletableFuture> requestAsync(Config config, - HttpRequest request, - Function> transformer, - Callback callback) { - return requestAsync(config, request, transformer, CallbackFuture.wrap(callback)); - } - - private static CompletableFuture> requestAsync(Config config, HttpRequest request, - Function> transformer, - CompletableFuture> callback) { - Objects.requireNonNull(callback); - - HttpUriRequest requestObj = RequestPrep.prepareRequest(request, true); - - config.getAsyncHttpClient() - .execute(requestObj, new FutureCallback() { - @Override - public void completed(org.apache.http.HttpResponse httpResponse) { - callback.complete(transformer.apply(httpResponse)); - } - - @Override - public void failed(Exception e) { - callback.completeExceptionally(e); - } - - @Override - public void cancelled() { - callback.completeExceptionally(new UnirestException("canceled")); - } - }); - return callback; - } - -} From 61f4aaa032f4b89f289e9b05b68092c06456f108 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 7 Nov 2018 18:10:06 -0600 Subject: [PATCH 0232/1769] clean up headers --- src/main/java/unirest/BaseRequest.java | 5 +- src/main/java/unirest/Headers.java | 23 ++++++--- src/main/java/unirest/HttpRequest.java | 14 ++---- src/main/java/unirest/RequestPrep.java | 13 +---- src/main/java/unirest/Util.java | 8 ++- src/test/java/BehaviorTests/HeaderTest.java | 11 ---- src/test/java/unirest/HeadersTest.java | 56 +++++++++++++++++++++ 7 files changed, 85 insertions(+), 45 deletions(-) create mode 100644 src/test/java/unirest/HeadersTest.java diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 93c30379e..92f4256f9 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -124,10 +124,9 @@ private HttpResponse request(HttpRequest request, HttpRequestBase requestObj = RequestPrep.prepareRequest(request, false); HttpClient client = config.getClient(); - org.apache.http.HttpResponse response; try { - response = client.execute(requestObj); - HttpResponse httpResponse = transformer.apply(response); + org.apache.http.HttpResponse execute = client.execute(requestObj); + HttpResponse httpResponse = transformer.apply(execute); requestObj.releaseConnection(); return httpResponse; } catch (Exception e) { diff --git a/src/main/java/unirest/Headers.java b/src/main/java/unirest/Headers.java index 46926270b..f5409bb01 100644 --- a/src/main/java/unirest/Headers.java +++ b/src/main/java/unirest/Headers.java @@ -27,18 +27,17 @@ package unirest; import org.apache.http.Header; +import org.apache.http.message.BasicHeader; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; +import java.util.*; +import java.util.stream.Stream; -public class Headers extends HashMap> { +public class Headers extends TreeMap> { private static final long serialVersionUID = 71310341388734766L; public Headers() { - super(); + super(String.CASE_INSENSITIVE_ORDER); } public Headers(Header[] pairs) { @@ -55,7 +54,17 @@ public String getFirst(Object key) { } public void add(String name, String value) { - computeIfAbsent(name, k -> new ArrayList<>()).add(value); + if(Objects.nonNull(name)){ + computeIfAbsent(name, k -> new ArrayList<>()).add(Util.nullToEmpty(value)); + } + } + + public Stream
entries() { + return entrySet().stream().flatMap(this::toEntries); } + private Stream
toEntries(Map.Entry> k) { + String key = k.getKey(); + return k.getValue().stream().map(e -> new BasicHeader(key, e)); + } } diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index 141bb9da2..3c26953a4 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -37,7 +37,7 @@ public class HttpRequest extends BaseRequest { private HttpMethod httpMethod; protected String url; - Map> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + protected Headers headers = new Headers(); protected Body body; public HttpRequest(Config config, HttpMethod method, String url) { @@ -67,12 +67,7 @@ public HttpRequest basicAuth(String username, String password) { } public HttpRequest header(String name, String value) { - List list = this.headers.get(name.trim()); - if (list == null) { - list = new ArrayList<>(); - } - list.add(value); - this.headers.put(name.trim(), list); + this.headers.add(name.trim(), value); return this; } @@ -134,10 +129,7 @@ public String getUrl() { return url; } - public Map> getHeaders() { - if (headers == null) { - return new HashMap<>(); - } + public Headers getHeaders() { return headers; } diff --git a/src/main/java/unirest/RequestPrep.java b/src/main/java/unirest/RequestPrep.java index 39058ef20..2a6a0e609 100644 --- a/src/main/java/unirest/RequestPrep.java +++ b/src/main/java/unirest/RequestPrep.java @@ -32,9 +32,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.Set; class RequestPrep { private static final String CONTENT_TYPE = "content-type"; @@ -83,15 +80,7 @@ private static void setBody(HttpRequest request, boolean async, HttpRequestBase } private static void setRequestHeaders(HttpRequest request, HttpRequestBase reqObj) { - Set>> entrySet = request.getHeaders().entrySet(); - for (Map.Entry> entry : entrySet) { - List values = entry.getValue(); - if (values != null) { - for (String value : values) { - reqObj.addHeader(entry.getKey(), value); - } - } - } + request.getHeaders().entries().forEach(reqObj::addHeader); } private static HttpRequestBase getHttpRequest(HttpRequest request) { diff --git a/src/main/java/unirest/Util.java b/src/main/java/unirest/Util.java index 1f7f6d403..b9b23c030 100644 --- a/src/main/java/unirest/Util.java +++ b/src/main/java/unirest/Util.java @@ -44,7 +44,7 @@ static Optional tryCast(T original, Class too) { return Optional.empty(); } - public static Optional tryDo(T c, ExConsumer consumer) { + static Optional tryDo(T c, ExConsumer consumer) { try { if (Objects.nonNull(c)) { consumer.accept(c); @@ -55,6 +55,12 @@ public static Optional tryDo(T c, ExConsumer consumer) { } } + static String nullToEmpty(String value) { + if(value == null){ + return ""; + } + return value; + } @FunctionalInterface diff --git a/src/test/java/BehaviorTests/HeaderTest.java b/src/test/java/BehaviorTests/HeaderTest.java index b436754e8..c56cf781c 100644 --- a/src/test/java/BehaviorTests/HeaderTest.java +++ b/src/test/java/BehaviorTests/HeaderTest.java @@ -116,17 +116,6 @@ public void testCaseInsensitiveHeaders() { assertEquals("John", request.getHeaders().get("Name").get(1)); } - @Test - public void testHeaderNamesCaseSensitive() { - // Verify that header names are the same as server (case sensitive) - final Headers headers = new Headers(); - headers.put("Content-Type", Arrays.asList("application/json")); - - assertEquals("Only header \"Content-Type\" should exist", null, headers.getFirst("cOnTeNt-TyPe")); - assertEquals("Only header \"Content-Type\" should exist", null, headers.getFirst("content-type")); - assertEquals("Only header \"Content-Type\" should exist", "application/json", headers.getFirst("Content-Type")); - } - @Test public void canPassHeadersAsMap() { Unirest.post(MockServer.POST) diff --git a/src/test/java/unirest/HeadersTest.java b/src/test/java/unirest/HeadersTest.java new file mode 100644 index 000000000..7f35845de --- /dev/null +++ b/src/test/java/unirest/HeadersTest.java @@ -0,0 +1,56 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.apache.http.Header; +import org.junit.Test; + +import java.util.stream.Collectors; + +import static org.junit.Assert.*; + +public class HeadersTest { + + @Test + public void canGetApacheHeaders() { + Headers headers = new Headers(); + headers.add("foo","bar"); + + Header h = headers.entries().findAny().get(); + + assertEquals("foo", h.getName()); + assertEquals("bar", h.getValue()); + } + + @Test + public void dontBombOnNull(){ + Headers h = new Headers(); + h.add(null, "foo"); + + assertEquals(0, h.entries().collect(Collectors.toSet()).size()); + } +} \ No newline at end of file From 88cbcf5f8a12f88cab88436a7a50a92afa1e08ef Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 8 Nov 2018 08:01:49 -0600 Subject: [PATCH 0233/1769] add accept and content-type for 1st class header support --- src/main/java/unirest/HttpRequest.java | 7 +++- src/main/java/unirest/MultipartBody.java | 16 ++++++++++ src/test/java/BehaviorTests/HeaderTest.java | 32 ++++++++++++++----- .../java/BehaviorTests/RequestCapture.java | 9 ++++-- 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index 3c26953a4..e6f9a5acf 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -26,6 +26,8 @@ package unirest; +import org.apache.http.HttpHeaders; + import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.*; @@ -66,6 +68,10 @@ public HttpRequest basicAuth(String username, String password) { return this; } + public HttpRequest accept(String value) { + return header(HttpHeaders.ACCEPT, value); + } + public HttpRequest header(String name, String value) { this.headers.add(name.trim(), value); return this; @@ -136,5 +142,4 @@ public Headers getHeaders() { public Body getBody() { return body; } - } diff --git a/src/main/java/unirest/MultipartBody.java b/src/main/java/unirest/MultipartBody.java index 1c84cbc7d..707f9bd8e 100644 --- a/src/main/java/unirest/MultipartBody.java +++ b/src/main/java/unirest/MultipartBody.java @@ -27,6 +27,7 @@ package unirest; import org.apache.http.HttpEntity; +import org.apache.http.HttpHeaders; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.HttpMultipartMode; @@ -115,11 +116,26 @@ public MultipartBody charset(Charset charset) { return this; } + public MultipartBody accept(String mimeType) { + httpRequestObj.accept(mimeType); + return this; + } + + public MultipartBody contentType(String mimeType) { + httpRequestObj.header(HttpHeaders.CONTENT_TYPE, mimeType); + return this; + } + public MultipartBody basicAuth(String username, String password) { httpRequestObj.basicAuth(username, password); return this; } + public MultipartBody header(String name, String value) { + httpRequestObj.header(name, value); + return this; + } + public MultipartBody mode(String value) { this.mode = HttpMultipartMode.valueOf(value); return this; diff --git a/src/test/java/BehaviorTests/HeaderTest.java b/src/test/java/BehaviorTests/HeaderTest.java index c56cf781c..1ea99035a 100644 --- a/src/test/java/BehaviorTests/HeaderTest.java +++ b/src/test/java/BehaviorTests/HeaderTest.java @@ -26,15 +26,12 @@ package BehaviorTests; -import unirest.Headers; +import org.junit.Ignore; +import org.junit.Test; +import unirest.GetRequest; import unirest.HttpResponse; import unirest.JsonNode; import unirest.Unirest; -import unirest.GetRequest; -import org.junit.Ignore; -import org.junit.Test; - -import java.util.Arrays; import static org.junit.Assert.assertEquals; import static unirest.TestUtil.assertBasicAuth; @@ -42,12 +39,14 @@ public class HeaderTest extends BddTest { @Test - public void testCustomUserAgent() { + public void testHeadersOnGetRequests() { Unirest.get(MockServer.GET) .header("user-agent", "hello-world") + .accept("application/cheese-wiz") .asObject(RequestCapture.class) .getBody() - .assertHeader("User-Agent", "hello-world"); + .assertHeader("User-Agent", "hello-world") + .assertHeader("Accept","application/cheese-wiz"); } @Test @@ -116,6 +115,23 @@ public void testCaseInsensitiveHeaders() { assertEquals("John", request.getHeaders().get("Name").get(1)); } + @Test + public void headersOnMultipart() { + Unirest.post(MockServer.POST) + .field("one","a") + .accept("application/json") + .basicAuth("tony","tuna") + .header("cheese", "cheddar") + .contentType("application/xml") + .asObject(RequestCapture.class) + .getBody() + .assertHeader("Accept", "application/json") + .assertBasicAuth("tony","tuna") + .assertHeader("cheese", "cheddar") + .assertHeader("Content-Type", "application/xml"); + + } + @Test public void canPassHeadersAsMap() { Unirest.post(MockServer.POST) diff --git a/src/test/java/BehaviorTests/RequestCapture.java b/src/test/java/BehaviorTests/RequestCapture.java index bbfa3a232..b98ced36d 100644 --- a/src/test/java/BehaviorTests/RequestCapture.java +++ b/src/test/java/BehaviorTests/RequestCapture.java @@ -182,17 +182,20 @@ public RequestCapture assertFileContent(String input, String content) { return this; } - public void assertBasicAuth(String username, String password) { + public RequestCapture assertBasicAuth(String username, String password) { String raw = headers.get("Authorization"); TestUtil.assertBasicAuth(raw, username, password); + return this; } - public void assertQueryString(String s) { + public RequestCapture assertQueryString(String s) { assertEquals(s, queryString); + return this; } - public void asserMethod(HttpMethod get) { + public RequestCapture asserMethod(HttpMethod get) { assertEquals(get, method); + return this; } public RequestCapture assertPathParam(String value) { From 158a8b8454f5a77f0f4c847dd62b29ac061ac97a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 10 Nov 2018 17:25:56 -0600 Subject: [PATCH 0234/1769] refactor requestprep a little --- src/main/java/unirest/BaseRequest.java | 4 +- src/main/java/unirest/RequestPrep.java | 89 +++++++++---------- src/main/java/unirest/UriFormatter.java | 44 --------- .../java/BehaviorTests/PathParamTest.java | 2 +- src/test/java/unirest/UriFormatterTest.java | 6 +- 5 files changed, 47 insertions(+), 98 deletions(-) delete mode 100644 src/main/java/unirest/UriFormatter.java diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 92f4256f9..af328535b 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -121,7 +121,7 @@ public CompletableFuture> asBinaryAsync(Callback HttpResponse request(HttpRequest request, Function> transformer) { - HttpRequestBase requestObj = RequestPrep.prepareRequest(request, false); + HttpRequestBase requestObj = new RequestPrep(request, false).prepare(); HttpClient client = config.getClient(); try { @@ -156,7 +156,7 @@ private CompletableFuture> requestAsync( Objects.requireNonNull(callback); - HttpUriRequest requestObj = RequestPrep.prepareRequest(request, true); + HttpUriRequest requestObj = new RequestPrep(request, true).prepare(); config.getAsyncHttpClient() .execute(requestObj, new FutureCallback() { diff --git a/src/main/java/unirest/RequestPrep.java b/src/main/java/unirest/RequestPrep.java index 2a6a0e609..9315ac58c 100644 --- a/src/main/java/unirest/RequestPrep.java +++ b/src/main/java/unirest/RequestPrep.java @@ -32,16 +32,46 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + +import static unirest.HttpMethod.*; class RequestPrep { private static final String CONTENT_TYPE = "content-type"; private static final String ACCEPT_ENCODING_HEADER = "accept-encoding"; private static final String USER_AGENT_HEADER = "user-agent"; - private static final String USER_AGENT = "unirest-java/1.3.11"; - private static final UriFormatter URI_FORMATTER = new UriFormatter(); + private static final String USER_AGENT = "unirest-java/3.0.00"; + private static final Map> FACTORIES; + private final HttpRequest request; + private final boolean async; + + static { + FACTORIES = new HashMap<>(); + FACTORIES.put(GET, HttpGet::new); + FACTORIES.put(POST, HttpPost::new); + FACTORIES.put(PUT, HttpPut::new); + FACTORIES.put(DELETE, HttpDeleteWithBody::new); + FACTORIES.put(PATCH, HttpPatchWithBody::new); + FACTORIES.put(OPTIONS, HttpOptions::new); + FACTORIES.put(HEAD, HttpHead::new); + } + + RequestPrep(HttpRequest request, boolean async){ + this.request = request; + this.async = async; + } - static HttpRequestBase prepareRequest(HttpRequest request, boolean async) { + HttpRequestBase prepare(){ + HttpRequestBase reqObj = getHttpRequestBase(); + setBody(reqObj); + + return reqObj; + } + + private HttpRequestBase getHttpRequestBase() { if (!request.getHeaders().containsKey(USER_AGENT_HEADER)) { request.header(USER_AGENT_HEADER, USER_AGENT); } @@ -49,15 +79,17 @@ static HttpRequestBase prepareRequest(HttpRequest request, boolean async) { request.header(ACCEPT_ENCODING_HEADER, "gzip"); } - HttpRequestBase reqObj = getHttpRequest(request); - setRequestHeaders(request, reqObj); - setBody(request, async, reqObj); - - return reqObj; + try { + HttpRequestBase reqObj = FACTORIES.get(request.getHttpMethod()).apply(request.url); + request.getHeaders().entries().forEach(reqObj::addHeader); + return reqObj; + }catch (RuntimeException e){ + throw new UnirestException(e); + } } - private static void setBody(HttpRequest request, boolean async, HttpRequestBase reqObj) { - if (!(request.getHttpMethod() == HttpMethod.GET || request.getHttpMethod() == HttpMethod.HEAD)) { + private void setBody(HttpRequestBase reqObj) { + if (!(request.getHttpMethod() == GET || request.getHttpMethod() == HttpMethod.HEAD)) { if (request.getBody() != null) { HttpEntity entity = request.getBody().getEntity(); if (async) { @@ -70,7 +102,7 @@ private static void setBody(HttpRequest request, boolean async, HttpRequestBase NByteArrayEntity en = new NByteArrayEntity(output.toByteArray()); ((HttpEntityEnclosingRequestBase) reqObj).setEntity(en); } catch (IOException e) { - throw new RuntimeException(e); + throw new UnirestException(e); } } else { ((HttpEntityEnclosingRequestBase) reqObj).setEntity(entity); @@ -78,39 +110,4 @@ private static void setBody(HttpRequest request, boolean async, HttpRequestBase } } } - - private static void setRequestHeaders(HttpRequest request, HttpRequestBase reqObj) { - request.getHeaders().entries().forEach(reqObj::addHeader); - } - - private static HttpRequestBase getHttpRequest(HttpRequest request) { - HttpRequestBase reqObj = null; - - String urlToRequest = URI_FORMATTER.apply(request); - - switch (request.getHttpMethod()) { - case GET: - reqObj = new HttpGet(urlToRequest); - break; - case POST: - reqObj = new HttpPost(urlToRequest); - break; - case PUT: - reqObj = new HttpPut(urlToRequest); - break; - case DELETE: - reqObj = new HttpDeleteWithBody(urlToRequest); - break; - case PATCH: - reqObj = new HttpPatchWithBody(urlToRequest); - break; - case OPTIONS: - reqObj = new HttpOptions(urlToRequest); - break; - case HEAD: - reqObj = new HttpHead(urlToRequest); - break; - } - return reqObj; - } } diff --git a/src/main/java/unirest/UriFormatter.java b/src/main/java/unirest/UriFormatter.java deleted file mode 100644 index ef4cbad55..000000000 --- a/src/main/java/unirest/UriFormatter.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package unirest; - -import org.apache.http.client.utils.URIBuilder; - -import java.net.URISyntaxException; -import java.util.function.Function; - -class UriFormatter implements Function { - @Override - public String apply(HttpRequest request) { - try { - return new URIBuilder(request.getUrl()).toString(); - } catch (URISyntaxException e) { - throw new UnirestException(e); - } - } - -} diff --git a/src/test/java/BehaviorTests/PathParamTest.java b/src/test/java/BehaviorTests/PathParamTest.java index 4c86358d3..b47c46abb 100644 --- a/src/test/java/BehaviorTests/PathParamTest.java +++ b/src/test/java/BehaviorTests/PathParamTest.java @@ -83,7 +83,7 @@ public void testMissingPathParameterValue() { .queryString("name", "Mark") .asBinary(), UnirestException.class, - "java.net.URISyntaxException: Illegal character in path at index 22: http://localhost:4567/{method}?name=Mark"); + "java.lang.IllegalArgumentException: Illegal character in path at index 22: http://localhost:4567/{method}?name=Mark"); } @Test diff --git a/src/test/java/unirest/UriFormatterTest.java b/src/test/java/unirest/UriFormatterTest.java index 94496680d..afc359c4e 100644 --- a/src/test/java/unirest/UriFormatterTest.java +++ b/src/test/java/unirest/UriFormatterTest.java @@ -26,15 +26,11 @@ package unirest; -import unirest.HttpMethod; import org.junit.Test; -import unirest.HttpRequest; -import unirest.UriFormatter; import static org.junit.Assert.assertEquals; public class UriFormatterTest { - private UriFormatter helper = new UriFormatter(); @Test public void testMangler_encoding() { @@ -62,7 +58,7 @@ public void utf8Chars(){ } private void assertLinkSurvives(String s) { - assertEquals(s, helper.apply(new HttpRequest(new Config(), HttpMethod.GET, s))); + assertEquals(s, new HttpRequest(new Config(), HttpMethod.GET, s).url); } } \ No newline at end of file From 67edb93331cb22a766e3e1966d8ec4a2d24a3ff2 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 10 Nov 2018 17:40:26 -0600 Subject: [PATCH 0235/1769] move the guts of Unirest into a instance --- src/main/java/unirest/Unirest.java | 29 +++---- src/main/java/unirest/UnirestInstance.java | 95 ++++++++++++++++++++++ 2 files changed, 107 insertions(+), 17 deletions(-) create mode 100644 src/main/java/unirest/UnirestInstance.java diff --git a/src/main/java/unirest/Unirest.java b/src/main/java/unirest/Unirest.java index caa284c1b..5c8c9e8dc 100644 --- a/src/main/java/unirest/Unirest.java +++ b/src/main/java/unirest/Unirest.java @@ -28,18 +28,13 @@ public class Unirest { - private static Unirest primaryInstance = new Unirest(new Config()); - private final Config config; - - public Unirest(Config config) { - this.config = config; - } + private static UnirestInstance primaryInstance = new UnirestInstance(new Config()); /** * Access the default configuration for the primary Unirest instance. */ public static Config config(){ - return primaryInstance.config; + return primaryInstance.config(); } /** @@ -55,42 +50,42 @@ public static void shutDown() { * @param clearOptions indicates if options should be cleared. Note that the HttpClient, AsyncClient and thread monitors will not be retained after shutDown. */ public static void shutDown(boolean clearOptions) { - primaryInstance.config.shutDown(clearOptions); + primaryInstance.shutDown(clearOptions); } public static GetRequest get(String url) { - return new GetRequest(primaryInstance.config, HttpMethod.GET, url); + return primaryInstance.get(url); } public static GetRequest head(String url) { - return new GetRequest(primaryInstance.config, HttpMethod.HEAD, url); + return primaryInstance.head(url); } public static HttpRequestWithBody options(String url) { - return new HttpRequestWithBody(primaryInstance.config, HttpMethod.OPTIONS, url); + return primaryInstance.options(url); } public static HttpRequestWithBody post(String url) { - return new HttpRequestWithBody(primaryInstance.config, HttpMethod.POST, url); + return primaryInstance.post(url); } public static HttpRequestWithBody delete(String url) { - return new HttpRequestWithBody(primaryInstance.config, HttpMethod.DELETE, url); + return primaryInstance.delete(url); } public static HttpRequestWithBody patch(String url) { - return new HttpRequestWithBody(primaryInstance.config, HttpMethod.PATCH, url); + return primaryInstance.patch(url); } public static HttpRequestWithBody put(String url) { - return new HttpRequestWithBody(primaryInstance.config, HttpMethod.PUT, url); + return primaryInstance.put(url); } public static JsonPatchRequest jsonPatch(String url) { - return new JsonPatchRequest(primaryInstance.config, url); + return primaryInstance.jsonPatch(url); } public static boolean isRunning() { - return primaryInstance.config.isRunning(); + return primaryInstance.isRunning(); } } diff --git a/src/main/java/unirest/UnirestInstance.java b/src/main/java/unirest/UnirestInstance.java new file mode 100644 index 000000000..1de4025b4 --- /dev/null +++ b/src/main/java/unirest/UnirestInstance.java @@ -0,0 +1,95 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +public class UnirestInstance { + + private final Config config; + + public UnirestInstance(Config config){ + this.config = config; + } + /** + * Access the default configuration for the primary Unirest instance. + */ + public Config config() { + return config; + } + + /** + * Close the asynchronous client and its event loop. Use this method to close all the threads and allow an application to exit. + * This will also clear any options returning Unirest to a default state + */ + public void shutDown() { + shutDown(true); + } + + /** + * Close the asynchronous client and its event loop. Use this method to close all the threads and allow an application to exit. + * + * @param clearOptions indicates if options should be cleared. Note that the HttpClient, AsyncClient and thread monitors will not be retained after shutDown. + */ + public void shutDown(boolean clearOptions) { + config.shutDown(clearOptions); + } + + public GetRequest get(String url) { + return new GetRequest(config, HttpMethod.GET, url); + } + + public GetRequest head(String url) { + return new GetRequest(config, HttpMethod.HEAD, url); + } + + public HttpRequestWithBody options(String url) { + return new HttpRequestWithBody(config, HttpMethod.OPTIONS, url); + } + + public HttpRequestWithBody post(String url) { + return new HttpRequestWithBody(config, HttpMethod.POST, url); + } + + public HttpRequestWithBody delete(String url) { + return new HttpRequestWithBody(config, HttpMethod.DELETE, url); + } + + public HttpRequestWithBody patch(String url) { + return new HttpRequestWithBody(config, HttpMethod.PATCH, url); + } + + public HttpRequestWithBody put(String url) { + return new HttpRequestWithBody(config, HttpMethod.PUT, url); + } + + public JsonPatchRequest jsonPatch(String url) { + return new JsonPatchRequest(config, url); + } + + public boolean isRunning() { + return config.isRunning(); + } +} From ebd6652fdd56ed0f454b70878f06d39eb375b5a1 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 11 Nov 2018 15:46:48 -0600 Subject: [PATCH 0236/1769] get get a reference to the primary instance of Unirest --- src/main/java/unirest/Unirest.java | 4 ++++ src/test/java/BehaviorTests/LifeCycleTest.java | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/unirest/Unirest.java b/src/main/java/unirest/Unirest.java index 5c8c9e8dc..7e171cc99 100644 --- a/src/main/java/unirest/Unirest.java +++ b/src/main/java/unirest/Unirest.java @@ -88,4 +88,8 @@ public static JsonPatchRequest jsonPatch(String url) { public static boolean isRunning() { return primaryInstance.isRunning(); } + + public static UnirestInstance getInstance() { + return primaryInstance; + } } diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index f72e3efe9..044fa3f89 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -37,9 +37,8 @@ import org.junit.Test; import java.io.IOException; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; + +import static org.junit.Assert.*; import static org.mockito.Mockito.*; @RunWith(MockitoJUnitRunner.class) @@ -150,4 +149,9 @@ public void willReinitIfLibraryIsUsedAfterShutdown() { Unirest.get(MockServer.GET).asBinary(); assertTrue(Unirest.isRunning()); } + + @Test + public void canGetTheCommonInstanceOfUnirest(){ + assertSame(Unirest.getInstance(), Unirest.getInstance()); + } } From ecd7fd2482f42936820528abc55656efdf4d4744 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 11 Nov 2018 16:24:47 -0600 Subject: [PATCH 0237/1769] merge the RawBody with the ResponseWithBody --- .../java/unirest/HttpRequestWithBody.java | 4 +- src/main/java/unirest/RawBody.java | 52 ------------------- src/main/java/unirest/RequestBodyEntity.java | 21 ++++---- 3 files changed, 14 insertions(+), 63 deletions(-) delete mode 100644 src/main/java/unirest/RawBody.java diff --git a/src/main/java/unirest/HttpRequestWithBody.java b/src/main/java/unirest/HttpRequestWithBody.java index 8a36ecf90..a835aaae4 100644 --- a/src/main/java/unirest/HttpRequestWithBody.java +++ b/src/main/java/unirest/HttpRequestWithBody.java @@ -159,8 +159,8 @@ public RequestBodyEntity body(Object body) { return body(config.getObjectMapper().writeValue(body)); } - public RawBody body(byte[] body) { - RawBody b = new RawBody(config, this).body(body); + public RequestBodyEntity body(byte[] body) { + RequestBodyEntity b = new RequestBodyEntity(config, this).body(body); this.body = b; return b; } diff --git a/src/main/java/unirest/RawBody.java b/src/main/java/unirest/RawBody.java deleted file mode 100644 index 289a99b8d..000000000 --- a/src/main/java/unirest/RawBody.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package unirest; - -import org.apache.http.HttpEntity; -import org.apache.http.entity.ByteArrayEntity; - -public class RawBody extends BaseRequest implements Body { - - private byte[] body; - - public RawBody(Config config, HttpRequest httpRequest) { - super(config, httpRequest); - } - - public RawBody body(byte[] bodyBytes) { - this.body = bodyBytes; - return this; - } - - public Object getBody() { - return body; - } - - public HttpEntity getEntity() { - return new ByteArrayEntity(body); - } -} diff --git a/src/main/java/unirest/RequestBodyEntity.java b/src/main/java/unirest/RequestBodyEntity.java index 75841e500..be44ddb91 100644 --- a/src/main/java/unirest/RequestBodyEntity.java +++ b/src/main/java/unirest/RequestBodyEntity.java @@ -27,36 +27,39 @@ package unirest; import org.apache.http.HttpEntity; +import org.apache.http.entity.ByteArrayEntity; import org.apache.http.entity.StringEntity; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.util.function.Supplier; public class RequestBodyEntity extends BaseRequest implements Body { private final HttpRequestWithBody request; - private Object body; + private Supplier body = () -> new StringEntity("", StandardCharsets.UTF_8); - public RequestBodyEntity(Config config, HttpRequestWithBody httpRequest) { + RequestBodyEntity(Config config, HttpRequestWithBody httpRequest) { super(config, httpRequest); request = httpRequest; } - public RequestBodyEntity body(String bodyAsString) { - this.body = bodyAsString; + public RequestBodyEntity body(byte[] bodyBytes) { + this.body = () -> new ByteArrayEntity(bodyBytes); return this; } - public RequestBodyEntity body(JsonNode jsonBody) { - this.body = jsonBody.toString(); + public RequestBodyEntity body(String bodyAsString) { + this.body = () -> new StringEntity(bodyAsString, request.getCharset()); return this; } - public Object getBody() { - return body; + public RequestBodyEntity body(JsonNode jsonBody) { + return body(jsonBody.toString()); } public HttpEntity getEntity() { - return new StringEntity(body.toString(), request.getCharset()); + return body.get(); } public RequestBodyEntity charset(Charset charset) { From 0570615b134022fc0f6196cb380e6a8e8dc9f3ea Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 12 Nov 2018 19:44:10 -0600 Subject: [PATCH 0238/1769] HttpRequest is abstract --- src/main/java/unirest/HttpRequest.java | 2 +- src/test/java/unirest/UriFormatterTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index e6f9a5acf..0dc89371d 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -35,7 +35,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -public class HttpRequest extends BaseRequest { +public abstract class HttpRequest extends BaseRequest { private HttpMethod httpMethod; protected String url; diff --git a/src/test/java/unirest/UriFormatterTest.java b/src/test/java/unirest/UriFormatterTest.java index afc359c4e..f1c6a6804 100644 --- a/src/test/java/unirest/UriFormatterTest.java +++ b/src/test/java/unirest/UriFormatterTest.java @@ -58,7 +58,7 @@ public void utf8Chars(){ } private void assertLinkSurvives(String s) { - assertEquals(s, new HttpRequest(new Config(), HttpMethod.GET, s).url); + assertEquals(s, new HttpRequest(new Config(), HttpMethod.GET, s){}.url); } } \ No newline at end of file From f2f0ded4fc56ad9b6bab42d045f967a10dfa9f98 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 12 Nov 2018 19:52:14 -0600 Subject: [PATCH 0239/1769] add some generic trickery so we can flatten this weird hierarchy --- src/main/java/unirest/BaseRequest.java | 2 +- src/main/java/unirest/GetRequest.java | 2 +- src/main/java/unirest/HttpRequest.java | 32 +++++++++---------- .../java/unirest/HttpRequestWithBody.java | 2 +- src/main/java/unirest/JsonPatchRequest.java | 2 +- src/main/java/unirest/MultipartBody.java | 2 +- src/main/java/unirest/RequestBodyEntity.java | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index af328535b..cf81ef620 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -36,7 +36,7 @@ import java.util.concurrent.CompletableFuture; import java.util.function.Function; -public abstract class BaseRequest { +public abstract class BaseRequest { private final ResponseBuilder builder; private final Config config; diff --git a/src/main/java/unirest/GetRequest.java b/src/main/java/unirest/GetRequest.java index 04d87fcca..7fb9dd653 100644 --- a/src/main/java/unirest/GetRequest.java +++ b/src/main/java/unirest/GetRequest.java @@ -28,7 +28,7 @@ import java.util.Map; -public class GetRequest extends HttpRequest { +public class GetRequest extends HttpRequest { public GetRequest(Config config, HttpMethod method, String url) { super(config, method, url); diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index 0dc89371d..8f816c6bb 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -35,7 +35,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -public abstract class HttpRequest extends BaseRequest { +public abstract class HttpRequest extends BaseRequest { private HttpMethod httpMethod; protected String url; @@ -50,7 +50,7 @@ public HttpRequest(Config config, HttpMethod method, String url) { headers.putAll(config.getDefaultHeaders()); } - public HttpRequest routeParam(String name, String value) { + public R routeParam(String name, String value) { Matcher matcher = Pattern.compile("\\{" + name + "\\}").matcher(url); int count = 0; while (matcher.find()) { @@ -60,40 +60,40 @@ public HttpRequest routeParam(String name, String value) { throw new RuntimeException("Can't find route parameter name \"" + name + "\""); } this.url = url.replaceAll("\\{" + name + "\\}", URLParamEncoder.encode(value)); - return this; + return (R)this; } - public HttpRequest basicAuth(String username, String password) { + public R basicAuth(String username, String password) { header("Authorization", "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes())); - return this; + return (R)this; } - public HttpRequest accept(String value) { + public R accept(String value) { return header(HttpHeaders.ACCEPT, value); } - public HttpRequest header(String name, String value) { + public R header(String name, String value) { this.headers.add(name.trim(), value); - return this; + return (R)this; } - public HttpRequest headers(Map headerMap) { + public R headers(Map headerMap) { if (headers != null) { for (Map.Entry entry : headerMap.entrySet()) { header(entry.getKey(), entry.getValue()); } } - return this; + return (R)this; } - public HttpRequest queryString(String name, Collection value) { + public R queryString(String name, Collection value) { for (Object cur : value) { queryString(name, cur); } - return this; + return (R)this; } - public HttpRequest queryString(String name, Object value) { + public R queryString(String name, Object value) { StringBuilder queryString = new StringBuilder(); if (this.url.contains("?")) { queryString.append("&"); @@ -109,10 +109,10 @@ public HttpRequest queryString(String name, Object value) { throw new RuntimeException(e); } this.url += queryString.toString(); - return this; + return (R)this; } - public HttpRequest queryString(Map parameters) { + public R queryString(Map parameters) { if (parameters != null) { for (Entry param : parameters.entrySet()) { if (param.getValue() instanceof String || param.getValue() instanceof Number || param.getValue() instanceof Boolean || param.getValue() == null) { @@ -124,7 +124,7 @@ public HttpRequest queryString(Map parameters) { } } } - return this; + return (R)this; } public HttpMethod getHttpMethod() { diff --git a/src/main/java/unirest/HttpRequestWithBody.java b/src/main/java/unirest/HttpRequestWithBody.java index a835aaae4..579e3aff4 100644 --- a/src/main/java/unirest/HttpRequestWithBody.java +++ b/src/main/java/unirest/HttpRequestWithBody.java @@ -38,7 +38,7 @@ import java.util.Map; import java.util.Map.Entry; -public class HttpRequestWithBody extends HttpRequest { +public class HttpRequestWithBody extends HttpRequest { private final Config config; private Charset charSet = StandardCharsets.UTF_8; diff --git a/src/main/java/unirest/JsonPatchRequest.java b/src/main/java/unirest/JsonPatchRequest.java index 33b9125b4..5d0374534 100644 --- a/src/main/java/unirest/JsonPatchRequest.java +++ b/src/main/java/unirest/JsonPatchRequest.java @@ -31,7 +31,7 @@ import java.io.ByteArrayInputStream; -public class JsonPatchRequest extends HttpRequest implements Body { +public class JsonPatchRequest extends HttpRequest implements Body { public static final String CONTENT_TYPE = "application/json-patch+json"; private JsonPatch items = new JsonPatch(); diff --git a/src/main/java/unirest/MultipartBody.java b/src/main/java/unirest/MultipartBody.java index 707f9bd8e..380812e21 100644 --- a/src/main/java/unirest/MultipartBody.java +++ b/src/main/java/unirest/MultipartBody.java @@ -43,7 +43,7 @@ import java.util.Collections; import java.util.List; -public class MultipartBody extends BaseRequest implements Body { +public class MultipartBody extends BaseRequest implements Body { private List parameters = new ArrayList<>(); private HttpRequestWithBody httpRequestObj; diff --git a/src/main/java/unirest/RequestBodyEntity.java b/src/main/java/unirest/RequestBodyEntity.java index be44ddb91..bc5c66bde 100644 --- a/src/main/java/unirest/RequestBodyEntity.java +++ b/src/main/java/unirest/RequestBodyEntity.java @@ -34,7 +34,7 @@ import java.nio.charset.StandardCharsets; import java.util.function.Supplier; -public class RequestBodyEntity extends BaseRequest implements Body { +public class RequestBodyEntity extends BaseRequest implements Body { private final HttpRequestWithBody request; private Supplier body = () -> new StringEntity("", StandardCharsets.UTF_8); From ad3b4b5f45da61f9ca911e07605e55e19bdef6bd Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 12 Nov 2018 19:54:20 -0600 Subject: [PATCH 0240/1769] GetRequest is kind of boring now --- src/main/java/unirest/GetRequest.java | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/src/main/java/unirest/GetRequest.java b/src/main/java/unirest/GetRequest.java index 7fb9dd653..dbb041e81 100644 --- a/src/main/java/unirest/GetRequest.java +++ b/src/main/java/unirest/GetRequest.java @@ -26,32 +26,10 @@ package unirest; -import java.util.Map; - public class GetRequest extends HttpRequest { public GetRequest(Config config, HttpMethod method, String url) { super(config, method, url); } - public GetRequest routeParam(String name, String value) { - super.routeParam(name, value); - return this; - } - - @Override - public GetRequest header(String name, String value) { - return (GetRequest) super.header(name, value); - } - - @Override - public GetRequest headers(Map headers) { - return (GetRequest) super.headers(headers); - } - - @Override - public GetRequest basicAuth(String username, String password) { - super.basicAuth(username, password); - return this; - } } From 027d6ffeff5df1c9740ff2c6e749055e9f5ea2e9 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 12 Nov 2018 19:55:33 -0600 Subject: [PATCH 0241/1769] HttpRequestWithBody now only needs to deal with body stuff --- .../java/unirest/HttpRequestWithBody.java | 32 ------------------- 1 file changed, 32 deletions(-) diff --git a/src/main/java/unirest/HttpRequestWithBody.java b/src/main/java/unirest/HttpRequestWithBody.java index 579e3aff4..1441bb53a 100644 --- a/src/main/java/unirest/HttpRequestWithBody.java +++ b/src/main/java/unirest/HttpRequestWithBody.java @@ -48,38 +48,6 @@ public HttpRequestWithBody(Config config, HttpMethod method, String url) { this.config = config; } - @Override - public HttpRequestWithBody routeParam(String name, String value) { - super.routeParam(name, value); - return this; - } - - @Override - public HttpRequestWithBody header(String name, String value) { - return (HttpRequestWithBody) super.header(name, value); - } - - @Override - public HttpRequestWithBody headers(Map headers) { - return (HttpRequestWithBody) super.headers(headers); - } - - @Override - public HttpRequestWithBody basicAuth(String username, String password) { - super.basicAuth(username, password); - return this; - } - - @Override - public HttpRequestWithBody queryString(Map parameters) { - return (HttpRequestWithBody) super.queryString(parameters); - } - - @Override - public HttpRequestWithBody queryString(String name, Object value) { - return (HttpRequestWithBody) super.queryString(name, value); - } - public MultipartBody field(String name, Collection value) { MultipartBody body = new MultipartBody(config, this).field(name, value); this.body = body; From 1a7568ae7a15bf1cde4b828792ba04a5c68929ea Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 12 Nov 2018 20:05:41 -0600 Subject: [PATCH 0242/1769] move url and method up to base --- src/main/java/unirest/BaseRequest.java | 8 +++++++- src/main/java/unirest/HttpRequest.java | 10 +++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index cf81ef620..0516eaa60 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -40,17 +40,23 @@ public abstract class BaseRequest { private final ResponseBuilder builder; private final Config config; + protected HttpMethod method; + protected String url; protected HttpRequest httpRequest; protected BaseRequest(Config config, HttpRequest httpRequest) { this.config = config; this.httpRequest = httpRequest; this.builder = new ResponseBuilder(config); + this.method = httpRequest.method; + this.url = httpRequest.url; } - protected BaseRequest(Config config) { + protected BaseRequest(Config config, HttpMethod method, String url) { this.config = config; this.builder = new ResponseBuilder(config); + this.method = method; + this.url = url; } public HttpRequest getHttpRequest() { diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index 8f816c6bb..333905e70 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -37,15 +37,11 @@ public abstract class HttpRequest extends BaseRequest { - private HttpMethod httpMethod; - protected String url; protected Headers headers = new Headers(); protected Body body; public HttpRequest(Config config, HttpMethod method, String url) { - super(config); - this.httpMethod = method; - this.url = url; + super(config, method, url); super.httpRequest = this; headers.putAll(config.getDefaultHeaders()); } @@ -108,7 +104,7 @@ public R queryString(String name, Object value) { } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } - this.url += queryString.toString(); + super.url += queryString.toString(); return (R)this; } @@ -128,7 +124,7 @@ public R queryString(Map parameters) { } public HttpMethod getHttpMethod() { - return httpMethod; + return super.method; } public String getUrl() { From 3ae3bf84ce2447b0e8fc3a2066ee2e049bcb0a84 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 12 Nov 2018 20:07:07 -0600 Subject: [PATCH 0243/1769] Everyone wants to use route params --- src/main/java/unirest/BaseRequest.java | 15 +++++++++++++++ src/main/java/unirest/HttpRequest.java | 19 +++---------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 0516eaa60..1a5974233 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -35,6 +35,8 @@ import java.util.Objects; import java.util.concurrent.CompletableFuture; import java.util.function.Function; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public abstract class BaseRequest { @@ -59,6 +61,19 @@ protected BaseRequest(Config config, HttpMethod method, String url) { this.url = url; } + public R routeParam(String name, String value) { + Matcher matcher = Pattern.compile("\\{" + name + "\\}").matcher(url); + int count = 0; + while (matcher.find()) { + count++; + } + if (count == 0) { + throw new RuntimeException("Can't find route parameter name \"" + name + "\""); + } + this.url = url.replaceAll("\\{" + name + "\\}", URLParamEncoder.encode(value)); + return (R)this; + } + public HttpRequest getHttpRequest() { return this.httpRequest; } diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index 333905e70..1f13dbd11 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -30,10 +30,10 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -import java.util.*; +import java.util.Base64; +import java.util.Collection; +import java.util.Map; import java.util.Map.Entry; -import java.util.regex.Matcher; -import java.util.regex.Pattern; public abstract class HttpRequest extends BaseRequest { @@ -46,19 +46,6 @@ public HttpRequest(Config config, HttpMethod method, String url) { headers.putAll(config.getDefaultHeaders()); } - public R routeParam(String name, String value) { - Matcher matcher = Pattern.compile("\\{" + name + "\\}").matcher(url); - int count = 0; - while (matcher.find()) { - count++; - } - if (count == 0) { - throw new RuntimeException("Can't find route parameter name \"" + name + "\""); - } - this.url = url.replaceAll("\\{" + name + "\\}", URLParamEncoder.encode(value)); - return (R)this; - } - public R basicAuth(String username, String password) { header("Authorization", "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes())); return (R)this; From 364bfc32fe1a94592e5bb40d94fd2aacb2ec7e71 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 12 Nov 2018 20:09:14 -0600 Subject: [PATCH 0244/1769] move the header object up to the base --- src/main/java/unirest/BaseRequest.java | 3 +++ src/main/java/unirest/HttpRequest.java | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 1a5974233..a73dfdd82 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -40,6 +40,7 @@ public abstract class BaseRequest { + protected Headers headers = new Headers(); private final ResponseBuilder builder; private final Config config; protected HttpMethod method; @@ -52,6 +53,7 @@ protected BaseRequest(Config config, HttpRequest httpRequest) { this.builder = new ResponseBuilder(config); this.method = httpRequest.method; this.url = httpRequest.url; + headers.putAll(config.getDefaultHeaders()); } protected BaseRequest(Config config, HttpMethod method, String url) { @@ -59,6 +61,7 @@ protected BaseRequest(Config config, HttpMethod method, String url) { this.builder = new ResponseBuilder(config); this.method = method; this.url = url; + headers.putAll(config.getDefaultHeaders()); } public R routeParam(String name, String value) { diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index 1f13dbd11..87f1abc5a 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -36,14 +36,11 @@ import java.util.Map.Entry; public abstract class HttpRequest extends BaseRequest { - - protected Headers headers = new Headers(); protected Body body; public HttpRequest(Config config, HttpMethod method, String url) { super(config, method, url); super.httpRequest = this; - headers.putAll(config.getDefaultHeaders()); } public R basicAuth(String username, String password) { From 8a8ef93c5e0efd2deea56b135967fe3a49ec4a5e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 12 Nov 2018 20:18:39 -0600 Subject: [PATCH 0245/1769] move the rest of the stuff up to the base. tmp bump up checkstyle to get past this messy time --- checkstyle.xml | 2 +- src/main/java/unirest/BaseRequest.java | 89 ++++++++++++++++++++++++++ src/main/java/unirest/Headers.java | 4 ++ src/main/java/unirest/HttpRequest.java | 89 +------------------------- 4 files changed, 95 insertions(+), 89 deletions(-) diff --git a/checkstyle.xml b/checkstyle.xml index 87809dbab..520740440 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -144,7 +144,7 @@ - + diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index a73dfdd82..0efbf044f 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -26,12 +26,18 @@ package unirest; +import org.apache.http.HttpHeaders; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.concurrent.FutureCallback; import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.Base64; +import java.util.Collection; +import java.util.Map; import java.util.Objects; import java.util.concurrent.CompletableFuture; import java.util.function.Function; @@ -40,6 +46,7 @@ public abstract class BaseRequest { + protected Body body; protected Headers headers = new Headers(); private final ResponseBuilder builder; private final Config config; @@ -53,6 +60,7 @@ protected BaseRequest(Config config, HttpRequest httpRequest) { this.builder = new ResponseBuilder(config); this.method = httpRequest.method; this.url = httpRequest.url; + this.headers.addAll(httpRequest.headers); headers.putAll(config.getDefaultHeaders()); } @@ -77,6 +85,70 @@ public R routeParam(String name, String value) { return (R)this; } + public R basicAuth(String username, String password) { + header("Authorization", "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes())); + return (R)this; + } + + public R accept(String value) { + return header(HttpHeaders.ACCEPT, value); + } + + public R header(String name, String value) { + this.headers.add(name.trim(), value); + return (R)this; + } + + public R headers(Map headerMap) { + if (headers != null) { + for (Map.Entry entry : headerMap.entrySet()) { + header(entry.getKey(), entry.getValue()); + } + } + return (R)this; + } + + public R queryString(String name, Collection value) { + for (Object cur : value) { + queryString(name, cur); + } + return (R)this; + } + + public R queryString(String name, Object value) { + StringBuilder queryString = new StringBuilder(); + if (url.contains("?")) { + queryString.append("&"); + } else { + queryString.append("?"); + } + try { + queryString.append(URLEncoder.encode(name)); + if(value != null) { + queryString.append("=").append(URLEncoder.encode(value.toString(), "UTF-8")); + } + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + url += queryString.toString(); + return (R)this; + } + + public R queryString(Map parameters) { + if (parameters != null) { + for (Map.Entry param : parameters.entrySet()) { + if (param.getValue() instanceof String || param.getValue() instanceof Number || param.getValue() instanceof Boolean || param.getValue() == null) { + queryString(param.getKey(), param.getValue()); + } else { + throw new RuntimeException("Parameter \"" + param.getKey() + + "\" can't be sent with a GET request because of type: " + + param.getValue().getClass().getName()); + } + } + } + return (R)this; + } + public HttpRequest getHttpRequest() { return this.httpRequest; } @@ -201,4 +273,21 @@ public void cancelled() { }); return callback; } + + + public HttpMethod getHttpMethod() { + return method; + } + + public String getUrl() { + return url; + } + + public Headers getHeaders() { + return headers; + } + + public Body getBody() { + return body; + } } diff --git a/src/main/java/unirest/Headers.java b/src/main/java/unirest/Headers.java index f5409bb01..b0c88cbfe 100644 --- a/src/main/java/unirest/Headers.java +++ b/src/main/java/unirest/Headers.java @@ -67,4 +67,8 @@ private Stream
toEntries(Map.Entry> k) { String key = k.getKey(); return k.getValue().stream().map(e -> new BasicHeader(key, e)); } + + public void addAll(Headers headers) { + headers.entries().forEach(e -> add(e.getName(), e.getValue())); + } } diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index 87f1abc5a..438e9e2bc 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -26,100 +26,13 @@ package unirest; -import org.apache.http.HttpHeaders; - -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.Base64; -import java.util.Collection; -import java.util.Map; -import java.util.Map.Entry; - public abstract class HttpRequest extends BaseRequest { - protected Body body; + public HttpRequest(Config config, HttpMethod method, String url) { super(config, method, url); super.httpRequest = this; } - public R basicAuth(String username, String password) { - header("Authorization", "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes())); - return (R)this; - } - - public R accept(String value) { - return header(HttpHeaders.ACCEPT, value); - } - - public R header(String name, String value) { - this.headers.add(name.trim(), value); - return (R)this; - } - - public R headers(Map headerMap) { - if (headers != null) { - for (Map.Entry entry : headerMap.entrySet()) { - header(entry.getKey(), entry.getValue()); - } - } - return (R)this; - } - - public R queryString(String name, Collection value) { - for (Object cur : value) { - queryString(name, cur); - } - return (R)this; - } - public R queryString(String name, Object value) { - StringBuilder queryString = new StringBuilder(); - if (this.url.contains("?")) { - queryString.append("&"); - } else { - queryString.append("?"); - } - try { - queryString.append(URLEncoder.encode(name)); - if(value != null) { - queryString.append("=").append(URLEncoder.encode(value.toString(), "UTF-8")); - } - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - super.url += queryString.toString(); - return (R)this; - } - - public R queryString(Map parameters) { - if (parameters != null) { - for (Entry param : parameters.entrySet()) { - if (param.getValue() instanceof String || param.getValue() instanceof Number || param.getValue() instanceof Boolean || param.getValue() == null) { - queryString(param.getKey(), param.getValue()); - } else { - throw new RuntimeException("Parameter \"" + param.getKey() + - "\" can't be sent with a GET request because of type: " - + param.getValue().getClass().getName()); - } - } - } - return (R)this; - } - - public HttpMethod getHttpMethod() { - return super.method; - } - - public String getUrl() { - return url; - } - - public Headers getHeaders() { - return headers; - } - - public Body getBody() { - return body; - } } From 689e1cd0646ce43fffcd513e148dd6b59ff7e56d Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 15 Nov 2018 20:15:46 -0600 Subject: [PATCH 0246/1769] move the url manipulation methods into a path class --- src/main/java/unirest/BaseRequest.java | 48 ++--------- src/main/java/unirest/Path.java | 90 +++++++++++++++++++++ src/main/java/unirest/RequestPrep.java | 2 +- src/test/java/unirest/UriFormatterTest.java | 2 +- 4 files changed, 98 insertions(+), 44 deletions(-) create mode 100644 src/main/java/unirest/Path.java diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 0efbf044f..289a0dc2a 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -33,16 +33,12 @@ import org.apache.http.concurrent.FutureCallback; import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; import java.util.Base64; import java.util.Collection; import java.util.Map; import java.util.Objects; import java.util.concurrent.CompletableFuture; import java.util.function.Function; -import java.util.regex.Matcher; -import java.util.regex.Pattern; public abstract class BaseRequest { @@ -51,7 +47,7 @@ public abstract class BaseRequest { private final ResponseBuilder builder; private final Config config; protected HttpMethod method; - protected String url; + protected Path url; protected HttpRequest httpRequest; protected BaseRequest(Config config, HttpRequest httpRequest) { @@ -68,20 +64,12 @@ protected BaseRequest(Config config, HttpMethod method, String url) { this.config = config; this.builder = new ResponseBuilder(config); this.method = method; - this.url = url; + this.url = new Path(url); headers.putAll(config.getDefaultHeaders()); } public R routeParam(String name, String value) { - Matcher matcher = Pattern.compile("\\{" + name + "\\}").matcher(url); - int count = 0; - while (matcher.find()) { - count++; - } - if (count == 0) { - throw new RuntimeException("Can't find route parameter name \"" + name + "\""); - } - this.url = url.replaceAll("\\{" + name + "\\}", URLParamEncoder.encode(value)); + url.param(name, value); return (R)this; } @@ -116,36 +104,12 @@ public R queryString(String name, Collection value) { } public R queryString(String name, Object value) { - StringBuilder queryString = new StringBuilder(); - if (url.contains("?")) { - queryString.append("&"); - } else { - queryString.append("?"); - } - try { - queryString.append(URLEncoder.encode(name)); - if(value != null) { - queryString.append("=").append(URLEncoder.encode(value.toString(), "UTF-8")); - } - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - url += queryString.toString(); + url.queryString(name, value); return (R)this; } public R queryString(Map parameters) { - if (parameters != null) { - for (Map.Entry param : parameters.entrySet()) { - if (param.getValue() instanceof String || param.getValue() instanceof Number || param.getValue() instanceof Boolean || param.getValue() == null) { - queryString(param.getKey(), param.getValue()); - } else { - throw new RuntimeException("Parameter \"" + param.getKey() + - "\" can't be sent with a GET request because of type: " - + param.getValue().getClass().getName()); - } - } - } + url.queryString(parameters); return (R)this; } @@ -280,7 +244,7 @@ public HttpMethod getHttpMethod() { } public String getUrl() { - return url; + return url.toString(); } public Headers getHeaders() { diff --git a/src/main/java/unirest/Path.java b/src/main/java/unirest/Path.java new file mode 100644 index 000000000..771b2cb21 --- /dev/null +++ b/src/main/java/unirest/Path.java @@ -0,0 +1,90 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Path { + private String url; + + public Path(String url) { + this.url = url; + } + + public void param(String name, String value) { + Matcher matcher = Pattern.compile("\\{" + name + "\\}").matcher(url); + int count = 0; + while (matcher.find()) { + count++; + } + if (count == 0) { + throw new RuntimeException("Can't find route parameter name \"" + name + "\""); + } + this.url = url.replaceAll("\\{" + name + "\\}", URLParamEncoder.encode(value)); + } + + public void queryString(String name, Object value) { + StringBuilder queryString = new StringBuilder(); + if (url.contains("?")) { + queryString.append("&"); + } else { + queryString.append("?"); + } + try { + queryString.append(URLEncoder.encode(name)); + if(value != null) { + queryString.append("=").append(URLEncoder.encode(value.toString(), "UTF-8")); + } + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + url += queryString.toString(); + } + + public void queryString(Map parameters) { + if (parameters != null) { + for (Map.Entry param : parameters.entrySet()) { + if (param.getValue() instanceof String || param.getValue() instanceof Number || param.getValue() instanceof Boolean || param.getValue() == null) { + queryString(param.getKey(), param.getValue()); + } else { + throw new RuntimeException("Parameter \"" + param.getKey() + + "\" can't be sent with a GET request because of type: " + + param.getValue().getClass().getName()); + } + } + } + } + + @Override + public String toString() { + return url; + } +} diff --git a/src/main/java/unirest/RequestPrep.java b/src/main/java/unirest/RequestPrep.java index 9315ac58c..ba9be135e 100644 --- a/src/main/java/unirest/RequestPrep.java +++ b/src/main/java/unirest/RequestPrep.java @@ -80,7 +80,7 @@ private HttpRequestBase getHttpRequestBase() { } try { - HttpRequestBase reqObj = FACTORIES.get(request.getHttpMethod()).apply(request.url); + HttpRequestBase reqObj = FACTORIES.get(request.getHttpMethod()).apply(request.url.toString()); request.getHeaders().entries().forEach(reqObj::addHeader); return reqObj; }catch (RuntimeException e){ diff --git a/src/test/java/unirest/UriFormatterTest.java b/src/test/java/unirest/UriFormatterTest.java index f1c6a6804..1858b9aa4 100644 --- a/src/test/java/unirest/UriFormatterTest.java +++ b/src/test/java/unirest/UriFormatterTest.java @@ -58,7 +58,7 @@ public void utf8Chars(){ } private void assertLinkSurvives(String s) { - assertEquals(s, new HttpRequest(new Config(), HttpMethod.GET, s){}.url); + assertEquals(s, new HttpRequest(new Config(), HttpMethod.GET, s){}.url.toString()); } } \ No newline at end of file From 77aefb8f2f9ed0ca0b77646d14c2384a75286d09 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 15 Nov 2018 20:22:18 -0600 Subject: [PATCH 0247/1769] Extract the base into an interface and get rid of middle class --- src/main/java/unirest/BaseRequest.java | 42 ++++++++++--- src/main/java/unirest/GetRequest.java | 2 +- src/main/java/unirest/HttpRequest.java | 62 +++++++++++++++++-- .../java/unirest/HttpRequestWithBody.java | 2 +- src/main/java/unirest/JsonPatchRequest.java | 2 +- src/main/java/unirest/MultipartBody.java | 2 +- src/main/java/unirest/RequestBodyEntity.java | 2 +- src/main/java/unirest/RequestPrep.java | 2 +- .../java/BehaviorTests/FormPostingTest.java | 5 +- src/test/java/unirest/UriFormatterTest.java | 2 +- 10 files changed, 100 insertions(+), 23 deletions(-) diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 289a0dc2a..0608ac423 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -40,24 +40,23 @@ import java.util.concurrent.CompletableFuture; import java.util.function.Function; -public abstract class BaseRequest { +public abstract class BaseRequest implements HttpRequest { protected Body body; protected Headers headers = new Headers(); - private final ResponseBuilder builder; - private final Config config; + protected final ResponseBuilder builder; + protected final Config config; protected HttpMethod method; protected Path url; protected HttpRequest httpRequest; - protected BaseRequest(Config config, HttpRequest httpRequest) { - this.config = config; + protected BaseRequest(BaseRequest httpRequest) { + this.config = httpRequest.config; this.httpRequest = httpRequest; - this.builder = new ResponseBuilder(config); + this.builder = httpRequest.builder; this.method = httpRequest.method; this.url = httpRequest.url; this.headers.addAll(httpRequest.headers); - headers.putAll(config.getDefaultHeaders()); } protected BaseRequest(Config config, HttpMethod method, String url) { @@ -66,27 +65,33 @@ protected BaseRequest(Config config, HttpMethod method, String url) { this.method = method; this.url = new Path(url); headers.putAll(config.getDefaultHeaders()); + this.httpRequest = this; } + @Override public R routeParam(String name, String value) { url.param(name, value); return (R)this; } + @Override public R basicAuth(String username, String password) { header("Authorization", "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes())); return (R)this; } + @Override public R accept(String value) { return header(HttpHeaders.ACCEPT, value); } + @Override public R header(String name, String value) { this.headers.add(name.trim(), value); return (R)this; } + @Override public R headers(Map headerMap) { if (headers != null) { for (Map.Entry entry : headerMap.entrySet()) { @@ -96,6 +101,7 @@ public R headers(Map headerMap) { return (R)this; } + @Override public R queryString(String name, Collection value) { for (Object cur : value) { queryString(name, cur); @@ -103,76 +109,94 @@ public R queryString(String name, Collection value) { return (R)this; } + @Override public R queryString(String name, Object value) { url.queryString(name, value); return (R)this; } + @Override public R queryString(Map parameters) { url.queryString(parameters); return (R)this; } + @Override public HttpRequest getHttpRequest() { return this.httpRequest; } + @Override public HttpResponse asString() throws UnirestException { return request(httpRequest, builder::asString); } + @Override public CompletableFuture> asStringAsync() { return requestAsync(httpRequest, builder::asString); } + @Override public CompletableFuture> asStringAsync(Callback callback) { return requestAsync(httpRequest, builder::asString, callback); } + @Override public HttpResponse asJson() throws UnirestException { return request(httpRequest, builder::asJson); } + @Override public CompletableFuture> asJsonAsync() { return requestAsync(httpRequest, builder::asJson); } + @Override public CompletableFuture> asJsonAsync(Callback callback) { return requestAsync(httpRequest, builder::asJson, callback); } + @Override public HttpResponse asObject(Class responseClass) throws UnirestException { return request(httpRequest, r -> builder.asObject(r, responseClass)); } + @Override public HttpResponse asObject(GenericType genericType) throws UnirestException { return request(httpRequest, r -> builder.asObject(r, genericType)); } + @Override public CompletableFuture> asObjectAsync(Class responseClass) { return requestAsync(httpRequest, r -> builder.asObject(r, responseClass)); } + @Override public CompletableFuture> asObjectAsync(Class responseClass, Callback callback) { return requestAsync(httpRequest, r -> builder.asObject(r, responseClass), callback); } + @Override public CompletableFuture> asObjectAsync(GenericType genericType) { return requestAsync(httpRequest, r -> builder.asObject(r, genericType)); } + @Override public CompletableFuture> asObjectAsync(GenericType genericType, Callback callback) { return requestAsync(httpRequest, r -> builder.asObject(r, genericType), callback); } + @Override public HttpResponse asBinary() throws UnirestException { return request(httpRequest, builder::asBinary); } + @Override public CompletableFuture> asBinaryAsync() { return requestAsync(httpRequest, builder::asBinary); } + @Override public CompletableFuture> asBinaryAsync(Callback callback) { return requestAsync(httpRequest, builder::asBinary, callback); } @@ -239,18 +263,22 @@ public void cancelled() { } + @Override public HttpMethod getHttpMethod() { return method; } + @Override public String getUrl() { return url.toString(); } + @Override public Headers getHeaders() { return headers; } + @Override public Body getBody() { return body; } diff --git a/src/main/java/unirest/GetRequest.java b/src/main/java/unirest/GetRequest.java index dbb041e81..0efcb1ee0 100644 --- a/src/main/java/unirest/GetRequest.java +++ b/src/main/java/unirest/GetRequest.java @@ -26,7 +26,7 @@ package unirest; -public class GetRequest extends HttpRequest { +public class GetRequest extends BaseRequest { public GetRequest(Config config, HttpMethod method, String url) { super(config, method, url); diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index 438e9e2bc..3114260d0 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -26,13 +26,65 @@ package unirest; -public abstract class HttpRequest extends BaseRequest { +import java.io.InputStream; +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +public interface HttpRequest { + R routeParam(String name, String value); - public HttpRequest(Config config, HttpMethod method, String url) { - super(config, method, url); - super.httpRequest = this; - } + R basicAuth(String username, String password); + R accept(String value); + R header(String name, String value); + + R headers(Map headerMap); + + R queryString(String name, Collection value); + + R queryString(String name, Object value); + + R queryString(Map parameters); + + HttpRequest getHttpRequest(); + + HttpResponse asString() throws UnirestException; + + CompletableFuture> asStringAsync(); + + CompletableFuture> asStringAsync(Callback callback); + + HttpResponse asJson() throws UnirestException; + + CompletableFuture> asJsonAsync(); + + CompletableFuture> asJsonAsync(Callback callback); + + HttpResponse asObject(Class responseClass) throws UnirestException; + + HttpResponse asObject(GenericType genericType) throws UnirestException; + + CompletableFuture> asObjectAsync(Class responseClass); + + CompletableFuture> asObjectAsync(Class responseClass, Callback callback); + + CompletableFuture> asObjectAsync(GenericType genericType); + + CompletableFuture> asObjectAsync(GenericType genericType, Callback callback); + + HttpResponse asBinary() throws UnirestException; + + CompletableFuture> asBinaryAsync(); + + CompletableFuture> asBinaryAsync(Callback callback); + + HttpMethod getHttpMethod(); + + String getUrl(); + + Headers getHeaders(); + + Body getBody(); } diff --git a/src/main/java/unirest/HttpRequestWithBody.java b/src/main/java/unirest/HttpRequestWithBody.java index 1441bb53a..c54849162 100644 --- a/src/main/java/unirest/HttpRequestWithBody.java +++ b/src/main/java/unirest/HttpRequestWithBody.java @@ -38,7 +38,7 @@ import java.util.Map; import java.util.Map.Entry; -public class HttpRequestWithBody extends HttpRequest { +public class HttpRequestWithBody extends BaseRequest { private final Config config; private Charset charSet = StandardCharsets.UTF_8; diff --git a/src/main/java/unirest/JsonPatchRequest.java b/src/main/java/unirest/JsonPatchRequest.java index 5d0374534..99e6925d0 100644 --- a/src/main/java/unirest/JsonPatchRequest.java +++ b/src/main/java/unirest/JsonPatchRequest.java @@ -31,7 +31,7 @@ import java.io.ByteArrayInputStream; -public class JsonPatchRequest extends HttpRequest implements Body { +public class JsonPatchRequest extends BaseRequest implements Body { public static final String CONTENT_TYPE = "application/json-patch+json"; private JsonPatch items = new JsonPatch(); diff --git a/src/main/java/unirest/MultipartBody.java b/src/main/java/unirest/MultipartBody.java index 380812e21..d95771ec9 100644 --- a/src/main/java/unirest/MultipartBody.java +++ b/src/main/java/unirest/MultipartBody.java @@ -50,7 +50,7 @@ public class MultipartBody extends BaseRequest implements Body { private HttpMultipartMode mode = HttpMultipartMode.BROWSER_COMPATIBLE; public MultipartBody(Config config, HttpRequestWithBody httpRequest) { - super(config, httpRequest); + super(httpRequest); this.httpRequestObj = httpRequest; } diff --git a/src/main/java/unirest/RequestBodyEntity.java b/src/main/java/unirest/RequestBodyEntity.java index bc5c66bde..35c128d72 100644 --- a/src/main/java/unirest/RequestBodyEntity.java +++ b/src/main/java/unirest/RequestBodyEntity.java @@ -40,7 +40,7 @@ public class RequestBodyEntity extends BaseRequest implements private Supplier body = () -> new StringEntity("", StandardCharsets.UTF_8); RequestBodyEntity(Config config, HttpRequestWithBody httpRequest) { - super(config, httpRequest); + super(httpRequest); request = httpRequest; } diff --git a/src/main/java/unirest/RequestPrep.java b/src/main/java/unirest/RequestPrep.java index ba9be135e..f64291643 100644 --- a/src/main/java/unirest/RequestPrep.java +++ b/src/main/java/unirest/RequestPrep.java @@ -80,7 +80,7 @@ private HttpRequestBase getHttpRequestBase() { } try { - HttpRequestBase reqObj = FACTORIES.get(request.getHttpMethod()).apply(request.url.toString()); + HttpRequestBase reqObj = FACTORIES.get(request.getHttpMethod()).apply(request.getUrl()); request.getHeaders().entries().forEach(reqObj::addHeader); return reqObj; }catch (RuntimeException e){ diff --git a/src/test/java/BehaviorTests/FormPostingTest.java b/src/test/java/BehaviorTests/FormPostingTest.java index 254338035..f372fb2a2 100644 --- a/src/test/java/BehaviorTests/FormPostingTest.java +++ b/src/test/java/BehaviorTests/FormPostingTest.java @@ -26,14 +26,11 @@ package BehaviorTests; -import unirest.Unirest; -import unirest.HttpRequest; +import unirest.*; import org.apache.commons.io.IOUtils; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.HttpMultipartMode; import org.junit.Test; -import unirest.MockCallback; -import unirest.TestUtil; import java.io.ByteArrayInputStream; import java.io.File; diff --git a/src/test/java/unirest/UriFormatterTest.java b/src/test/java/unirest/UriFormatterTest.java index 1858b9aa4..66acbc9c4 100644 --- a/src/test/java/unirest/UriFormatterTest.java +++ b/src/test/java/unirest/UriFormatterTest.java @@ -58,7 +58,7 @@ public void utf8Chars(){ } private void assertLinkSurvives(String s) { - assertEquals(s, new HttpRequest(new Config(), HttpMethod.GET, s){}.url.toString()); + assertEquals(s, new BaseRequest(new Config(), HttpMethod.GET, s){}.url.toString()); } } \ No newline at end of file From 981cc311dcdfb124b4066259d671897664b7b7b8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 15 Nov 2018 20:48:21 -0600 Subject: [PATCH 0248/1769] rm unused constructor --- src/main/java/unirest/HttpRequestWithBody.java | 10 +++++----- src/main/java/unirest/MultipartBody.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/unirest/HttpRequestWithBody.java b/src/main/java/unirest/HttpRequestWithBody.java index c54849162..b4808496a 100644 --- a/src/main/java/unirest/HttpRequestWithBody.java +++ b/src/main/java/unirest/HttpRequestWithBody.java @@ -49,7 +49,7 @@ public HttpRequestWithBody(Config config, HttpMethod method, String url) { } public MultipartBody field(String name, Collection value) { - MultipartBody body = new MultipartBody(config, this).field(name, value); + MultipartBody body = new MultipartBody(this).field(name, value); this.body = body; return body; } @@ -59,7 +59,7 @@ public MultipartBody field(String name, File file) { } public MultipartBody field(String name, File file, String contentType) { - MultipartBody body = new MultipartBody(config, this).field(name, file, contentType); + MultipartBody body = new MultipartBody(this).field(name, file, contentType); this.body = body; return body; } @@ -69,13 +69,13 @@ public MultipartBody field(String name, Object value) { } public MultipartBody field(String name, Object value, String contentType) { - MultipartBody body = new MultipartBody(config, this).field(name, nullToEmpty(value), contentType); + MultipartBody body = new MultipartBody(this).field(name, nullToEmpty(value), contentType); this.body = body; return body; } public MultipartBody fields(Map parameters) { - MultipartBody body = new MultipartBody(config, this); + MultipartBody body = new MultipartBody(this); if (parameters != null) { for (Entry param : parameters.entrySet()) { if (param.getValue() instanceof File) { @@ -97,7 +97,7 @@ private String nullToEmpty(Object v) { } public MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName) { - MultipartBody body = new MultipartBody(config, this).field(name, stream, contentType, fileName); + MultipartBody body = new MultipartBody(this).field(name, stream, contentType, fileName); this.body = body; return body; } diff --git a/src/main/java/unirest/MultipartBody.java b/src/main/java/unirest/MultipartBody.java index d95771ec9..5476e2165 100644 --- a/src/main/java/unirest/MultipartBody.java +++ b/src/main/java/unirest/MultipartBody.java @@ -49,7 +49,7 @@ public class MultipartBody extends BaseRequest implements Body { private HttpRequestWithBody httpRequestObj; private HttpMultipartMode mode = HttpMultipartMode.BROWSER_COMPATIBLE; - public MultipartBody(Config config, HttpRequestWithBody httpRequest) { + public MultipartBody(HttpRequestWithBody httpRequest) { super(httpRequest); this.httpRequestObj = httpRequest; } From e08b8925469ffe3185815ab95d9cd7594f9398a8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 15 Nov 2018 20:53:05 -0600 Subject: [PATCH 0249/1769] copy the body up --- src/main/java/unirest/BaseRequest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 0608ac423..de869d838 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -57,6 +57,7 @@ protected BaseRequest(BaseRequest httpRequest) { this.method = httpRequest.method; this.url = httpRequest.url; this.headers.addAll(httpRequest.headers); + this.body = httpRequest.body; } protected BaseRequest(Config config, HttpMethod method, String url) { From a68f374dbb7c7aa3f0a3c8e95d28eb6a59ac498d Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 15 Nov 2018 21:10:21 -0600 Subject: [PATCH 0250/1769] rm unneccessary param passing --- src/main/java/unirest/BaseRequest.java | 44 ++++++++++++-------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index de869d838..4baa318c0 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -129,84 +129,83 @@ public HttpRequest getHttpRequest() { @Override public HttpResponse asString() throws UnirestException { - return request(httpRequest, builder::asString); + return request(builder::asString); } @Override public CompletableFuture> asStringAsync() { - return requestAsync(httpRequest, builder::asString); + return requestAsync(builder::asString); } @Override public CompletableFuture> asStringAsync(Callback callback) { - return requestAsync(httpRequest, builder::asString, callback); + return requestAsync(builder::asString, callback); } @Override public HttpResponse asJson() throws UnirestException { - return request(httpRequest, builder::asJson); + return request(builder::asJson); } @Override public CompletableFuture> asJsonAsync() { - return requestAsync(httpRequest, builder::asJson); + return requestAsync(builder::asJson); } @Override public CompletableFuture> asJsonAsync(Callback callback) { - return requestAsync(httpRequest, builder::asJson, callback); + return requestAsync(builder::asJson, callback); } @Override public HttpResponse asObject(Class responseClass) throws UnirestException { - return request(httpRequest, r -> builder.asObject(r, responseClass)); + return request(r -> builder.asObject(r, responseClass)); } @Override public HttpResponse asObject(GenericType genericType) throws UnirestException { - return request(httpRequest, r -> builder.asObject(r, genericType)); + return request(r -> builder.asObject(r, genericType)); } @Override public CompletableFuture> asObjectAsync(Class responseClass) { - return requestAsync(httpRequest, r -> builder.asObject(r, responseClass)); + return requestAsync(r -> builder.asObject(r, responseClass)); } @Override public CompletableFuture> asObjectAsync(Class responseClass, Callback callback) { - return requestAsync(httpRequest, r -> builder.asObject(r, responseClass), callback); + return requestAsync(r -> builder.asObject(r, responseClass), callback); } @Override public CompletableFuture> asObjectAsync(GenericType genericType) { - return requestAsync(httpRequest, r -> builder.asObject(r, genericType)); + return requestAsync(r -> builder.asObject(r, genericType)); } @Override public CompletableFuture> asObjectAsync(GenericType genericType, Callback callback) { - return requestAsync(httpRequest, r -> builder.asObject(r, genericType), callback); + return requestAsync(r -> builder.asObject(r, genericType), callback); } @Override public HttpResponse asBinary() throws UnirestException { - return request(httpRequest, builder::asBinary); + return request(builder::asBinary); } @Override public CompletableFuture> asBinaryAsync() { - return requestAsync(httpRequest, builder::asBinary); + return requestAsync(builder::asBinary); } @Override public CompletableFuture> asBinaryAsync(Callback callback) { - return requestAsync(httpRequest, builder::asBinary, callback); + return requestAsync(builder::asBinary, callback); } - private HttpResponse request(HttpRequest request, - Function> transformer) { + private HttpResponse request(Function> transformer) { - HttpRequestBase requestObj = new RequestPrep(request, false).prepare(); + HttpRequestBase requestObj = new RequestPrep(httpRequest, false).prepare(); HttpClient client = config.getClient(); try { @@ -222,26 +221,23 @@ private HttpResponse request(HttpRequest request, } private CompletableFuture> requestAsync( - HttpRequest request, Function> transformer) { - return requestAsync(request, transformer, new CompletableFuture<>()); + return requestAsync(transformer, new CompletableFuture<>()); } private CompletableFuture> requestAsync( - HttpRequest request, Function> transformer, Callback callback) { - return requestAsync(request, transformer, CallbackFuture.wrap(callback)); + return requestAsync(transformer, CallbackFuture.wrap(callback)); } private CompletableFuture> requestAsync( - HttpRequest request, Function> transformer, CompletableFuture> callback) { Objects.requireNonNull(callback); - HttpUriRequest requestObj = new RequestPrep(request, true).prepare(); + HttpUriRequest requestObj = new RequestPrep(httpRequest, true).prepare(); config.getAsyncHttpClient() .execute(requestObj, new FutureCallback() { From defd6a2d1f516726e3084bd001b3266b15d99733 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 15 Nov 2018 21:17:21 -0600 Subject: [PATCH 0251/1769] convert some of the runtime exceptions to unirest exceptions --- src/main/java/unirest/Path.java | 6 +++--- src/main/java/unirest/URLParamEncoder.java | 2 +- src/test/java/BehaviorTests/PathParamTest.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/unirest/Path.java b/src/main/java/unirest/Path.java index 771b2cb21..c6079b14a 100644 --- a/src/main/java/unirest/Path.java +++ b/src/main/java/unirest/Path.java @@ -46,7 +46,7 @@ public void param(String name, String value) { count++; } if (count == 0) { - throw new RuntimeException("Can't find route parameter name \"" + name + "\""); + throw new UnirestException("Can't find route parameter name \"" + name + "\""); } this.url = url.replaceAll("\\{" + name + "\\}", URLParamEncoder.encode(value)); } @@ -64,7 +64,7 @@ public void queryString(String name, Object value) { queryString.append("=").append(URLEncoder.encode(value.toString(), "UTF-8")); } } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); + throw new UnirestException(e); } url += queryString.toString(); } @@ -75,7 +75,7 @@ public void queryString(Map parameters) { if (param.getValue() instanceof String || param.getValue() instanceof Number || param.getValue() instanceof Boolean || param.getValue() == null) { queryString(param.getKey(), param.getValue()); } else { - throw new RuntimeException("Parameter \"" + param.getKey() + + throw new UnirestException("Parameter \"" + param.getKey() + "\" can't be sent with a GET request because of type: " + param.getValue().getClass().getName()); } diff --git a/src/main/java/unirest/URLParamEncoder.java b/src/main/java/unirest/URLParamEncoder.java index 30c9f258a..98376e338 100644 --- a/src/main/java/unirest/URLParamEncoder.java +++ b/src/main/java/unirest/URLParamEncoder.java @@ -34,7 +34,7 @@ static String encode(String input) { try { return URLEncoder.encode(input, "UTF-8"); } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); + throw new UnirestException(e); } } } diff --git a/src/test/java/BehaviorTests/PathParamTest.java b/src/test/java/BehaviorTests/PathParamTest.java index b47c46abb..63896eb60 100644 --- a/src/test/java/BehaviorTests/PathParamTest.java +++ b/src/test/java/BehaviorTests/PathParamTest.java @@ -72,7 +72,7 @@ public void testMissingPathParameter() { .routeParam("method222", "get") .queryString("name", "Mark") .asBinary(), - RuntimeException.class, + UnirestException.class, "Can't find route parameter name \"method222\""); } From b6d93f816c8b3295ec7cea2d0b6b382aa6407ced Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 16 Nov 2018 06:50:36 -0600 Subject: [PATCH 0252/1769] clean up constructor --- src/main/java/unirest/HttpRequestWithBody.java | 4 ++-- src/main/java/unirest/RequestBodyEntity.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/unirest/HttpRequestWithBody.java b/src/main/java/unirest/HttpRequestWithBody.java index b4808496a..799f7bc5f 100644 --- a/src/main/java/unirest/HttpRequestWithBody.java +++ b/src/main/java/unirest/HttpRequestWithBody.java @@ -118,7 +118,7 @@ public RequestBodyEntity body(JsonNode body) { } public RequestBodyEntity body(String body) { - RequestBodyEntity b = new RequestBodyEntity(config, this).body(body); + RequestBodyEntity b = new RequestBodyEntity(this).body(body); this.body = b; return b; } @@ -128,7 +128,7 @@ public RequestBodyEntity body(Object body) { } public RequestBodyEntity body(byte[] body) { - RequestBodyEntity b = new RequestBodyEntity(config, this).body(body); + RequestBodyEntity b = new RequestBodyEntity(this).body(body); this.body = b; return b; } diff --git a/src/main/java/unirest/RequestBodyEntity.java b/src/main/java/unirest/RequestBodyEntity.java index 35c128d72..cc46b7ead 100644 --- a/src/main/java/unirest/RequestBodyEntity.java +++ b/src/main/java/unirest/RequestBodyEntity.java @@ -39,7 +39,7 @@ public class RequestBodyEntity extends BaseRequest implements private final HttpRequestWithBody request; private Supplier body = () -> new StringEntity("", StandardCharsets.UTF_8); - RequestBodyEntity(Config config, HttpRequestWithBody httpRequest) { + RequestBodyEntity(HttpRequestWithBody httpRequest) { super(httpRequest); request = httpRequest; } From faa2b05fe74b40bcfbc05d2f5bb575fb85f0a00a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 16 Nov 2018 06:56:42 -0600 Subject: [PATCH 0253/1769] extract interface for the unibody requests --- src/main/java/unirest/HttpRequestUniBody.java | 43 +++++++++++++++++++ .../java/unirest/HttpRequestWithBody.java | 16 +++---- src/main/java/unirest/RequestBodyEntity.java | 23 ++++++---- 3 files changed, 65 insertions(+), 17 deletions(-) create mode 100644 src/main/java/unirest/HttpRequestUniBody.java diff --git a/src/main/java/unirest/HttpRequestUniBody.java b/src/main/java/unirest/HttpRequestUniBody.java new file mode 100644 index 000000000..2bf170668 --- /dev/null +++ b/src/main/java/unirest/HttpRequestUniBody.java @@ -0,0 +1,43 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.apache.http.HttpEntity; + +import java.nio.charset.Charset; + +public interface HttpRequestUniBody extends HttpRequest, Body { + HttpRequestUniBody body(byte[] bodyBytes); + + HttpRequestUniBody body(String bodyAsString); + + HttpRequestUniBody body(JsonNode jsonBody); + + HttpRequestUniBody charset(Charset charset); + + HttpEntity getEntity(); +} diff --git a/src/main/java/unirest/HttpRequestWithBody.java b/src/main/java/unirest/HttpRequestWithBody.java index 799f7bc5f..6d7ad4d98 100644 --- a/src/main/java/unirest/HttpRequestWithBody.java +++ b/src/main/java/unirest/HttpRequestWithBody.java @@ -113,22 +113,22 @@ public HttpRequestWithBody charset(Charset charset) { return this; } - public RequestBodyEntity body(JsonNode body) { + public HttpRequestUniBody body(JsonNode body) { return body(body.toString()); } - public RequestBodyEntity body(String body) { - RequestBodyEntity b = new RequestBodyEntity(this).body(body); + public HttpRequestUniBody body(String body) { + HttpRequestUniBody b = new RequestBodyEntity(this).body(body); this.body = b; return b; } - public RequestBodyEntity body(Object body) { + public HttpRequestUniBody body(Object body) { return body(config.getObjectMapper().writeValue(body)); } - public RequestBodyEntity body(byte[] body) { - RequestBodyEntity b = new RequestBodyEntity(this).body(body); + public HttpRequestUniBody body(byte[] body) { + HttpRequestUniBody b = new RequestBodyEntity(this).body(body); this.body = b; return b; } @@ -139,7 +139,7 @@ public RequestBodyEntity body(byte[] body) { * @param body raw org.JSONObject * @return RequestBodyEntity instance */ - public RequestBodyEntity body(JSONObject body) { + public HttpRequestUniBody body(JSONObject body) { return body(body.toString()); } @@ -149,7 +149,7 @@ public RequestBodyEntity body(JSONObject body) { * @param body raw org.JSONArray * @return RequestBodyEntity instance */ - public RequestBodyEntity body(JSONArray body) { + public HttpRequestUniBody body(JSONArray body) { return body(body.toString()); } diff --git a/src/main/java/unirest/RequestBodyEntity.java b/src/main/java/unirest/RequestBodyEntity.java index cc46b7ead..27b2c96dd 100644 --- a/src/main/java/unirest/RequestBodyEntity.java +++ b/src/main/java/unirest/RequestBodyEntity.java @@ -34,7 +34,7 @@ import java.nio.charset.StandardCharsets; import java.util.function.Supplier; -public class RequestBodyEntity extends BaseRequest implements Body { +public class RequestBodyEntity extends BaseRequest implements HttpRequestUniBody { private final HttpRequestWithBody request; private Supplier body = () -> new StringEntity("", StandardCharsets.UTF_8); @@ -44,26 +44,31 @@ public class RequestBodyEntity extends BaseRequest implements request = httpRequest; } - public RequestBodyEntity body(byte[] bodyBytes) { + @Override + public HttpRequestUniBody body(byte[] bodyBytes) { this.body = () -> new ByteArrayEntity(bodyBytes); return this; } - public RequestBodyEntity body(String bodyAsString) { + @Override + public HttpRequestUniBody body(String bodyAsString) { this.body = () -> new StringEntity(bodyAsString, request.getCharset()); return this; } - public RequestBodyEntity body(JsonNode jsonBody) { + @Override + public HttpRequestUniBody body(JsonNode jsonBody) { return body(jsonBody.toString()); } - public HttpEntity getEntity() { - return body.get(); - } - - public RequestBodyEntity charset(Charset charset) { + @Override + public HttpRequestUniBody charset(Charset charset) { request.charset(charset); return this; } + + @Override + public HttpEntity getEntity() { + return body.get(); + } } From 0cbfd56ea8adcbb80a1755f3e4739f678597ca31 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 16 Nov 2018 07:55:41 -0600 Subject: [PATCH 0254/1769] extract interface for multipart body --- .../java/unirest/HttpRequestMultPart.java | 68 +++++++++++++++++++ .../java/unirest/HttpRequestWithBody.java | 26 +++---- src/main/java/unirest/MultipartBody.java | 54 ++++++++++----- 3 files changed, 117 insertions(+), 31 deletions(-) create mode 100644 src/main/java/unirest/HttpRequestMultPart.java diff --git a/src/main/java/unirest/HttpRequestMultPart.java b/src/main/java/unirest/HttpRequestMultPart.java new file mode 100644 index 000000000..e5ac9610c --- /dev/null +++ b/src/main/java/unirest/HttpRequestMultPart.java @@ -0,0 +1,68 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.apache.http.HttpEntity; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.mime.HttpMultipartMode; + +import java.io.File; +import java.io.InputStream; +import java.nio.charset.Charset; +import java.util.Collection; + +public interface HttpRequestMultPart extends HttpRequest, Body { + HttpRequestMultPart field(String name, String value); + + HttpRequestMultPart field(String name, String value, String contentType); + + HttpRequestMultPart field(String name, Collection collection); + + HttpRequestMultPart field(String name, InputStream value, ContentType contentType); + + HttpRequestMultPart field(String name, File file); + + HttpRequestMultPart field(String name, File file, String contentType); + + HttpRequestMultPart field(String name, InputStream stream, ContentType contentType, String fileName); + + HttpRequestMultPart field(String name, InputStream stream, String fileName); + + HttpRequestMultPart field(String name, byte[] bytes, ContentType contentType, String fileName); + + HttpRequestMultPart field(String name, byte[] bytes, String fileName); + + HttpRequestMultPart charset(Charset charset); + + HttpRequestMultPart contentType(String mimeType); + + HttpRequestMultPart mode(String value); + + HttpRequestMultPart mode(HttpMultipartMode value); + + HttpEntity getEntity(); +} diff --git a/src/main/java/unirest/HttpRequestWithBody.java b/src/main/java/unirest/HttpRequestWithBody.java index 6d7ad4d98..b8c103764 100644 --- a/src/main/java/unirest/HttpRequestWithBody.java +++ b/src/main/java/unirest/HttpRequestWithBody.java @@ -48,33 +48,33 @@ public HttpRequestWithBody(Config config, HttpMethod method, String url) { this.config = config; } - public MultipartBody field(String name, Collection value) { - MultipartBody body = new MultipartBody(this).field(name, value); + public HttpRequestMultPart field(String name, Collection value) { + HttpRequestMultPart body = new MultipartBody(this).field(name, value); this.body = body; return body; } - public MultipartBody field(String name, File file) { + public HttpRequestMultPart field(String name, File file) { return field(name, file, null); } - public MultipartBody field(String name, File file, String contentType) { - MultipartBody body = new MultipartBody(this).field(name, file, contentType); + public HttpRequestMultPart field(String name, File file, String contentType) { + HttpRequestMultPart body = new MultipartBody(this).field(name, file, contentType); this.body = body; return body; } - public MultipartBody field(String name, Object value) { + public HttpRequestMultPart field(String name, Object value) { return field(name, value, null); } - public MultipartBody field(String name, Object value, String contentType) { - MultipartBody body = new MultipartBody(this).field(name, nullToEmpty(value), contentType); + public HttpRequestMultPart field(String name, Object value, String contentType) { + HttpRequestMultPart body = new MultipartBody(this).field(name, nullToEmpty(value), contentType); this.body = body; return body; } - public MultipartBody fields(Map parameters) { + public HttpRequestMultPart fields(Map parameters) { MultipartBody body = new MultipartBody(this); if (parameters != null) { for (Entry param : parameters.entrySet()) { @@ -96,14 +96,14 @@ private String nullToEmpty(Object v) { return v.toString(); } - public MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName) { - MultipartBody body = new MultipartBody(this).field(name, stream, contentType, fileName); + public HttpRequestMultPart field(String name, InputStream stream, ContentType contentType, String fileName) { + HttpRequestMultPart body = new MultipartBody(this).field(name, stream, contentType, fileName); this.body = body; return body; } - public MultipartBody field(String name, InputStream stream, String fileName) { - MultipartBody body = field(name, stream, ContentType.APPLICATION_OCTET_STREAM, fileName); + public HttpRequestMultPart field(String name, InputStream stream, String fileName) { + HttpRequestMultPart body = field(name, stream, ContentType.APPLICATION_OCTET_STREAM, fileName); this.body = body; return body; } diff --git a/src/main/java/unirest/MultipartBody.java b/src/main/java/unirest/MultipartBody.java index 5476e2165..8e8f2e868 100644 --- a/src/main/java/unirest/MultipartBody.java +++ b/src/main/java/unirest/MultipartBody.java @@ -43,7 +43,7 @@ import java.util.Collections; import java.util.List; -public class MultipartBody extends BaseRequest implements Body { +public class MultipartBody extends BaseRequest implements HttpRequestMultPart { private List parameters = new ArrayList<>(); private HttpRequestWithBody httpRequestObj; @@ -54,98 +54,116 @@ public MultipartBody(HttpRequestWithBody httpRequest) { this.httpRequestObj = httpRequest; } - public MultipartBody field(String name, String value) { + @Override + public HttpRequestMultPart field(String name, String value) { addPart(name, value); return this; } - public MultipartBody field(String name, String value, String contentType) { + @Override + public HttpRequestMultPart field(String name, String value, String contentType) { addPart(name, value, tryParse(contentType)); return this; } - public MultipartBody field(String name, Collection collection) { + @Override + public HttpRequestMultPart field(String name, Collection collection) { for (Object current: collection) { addPart(name, current, null); } return this; } - public MultipartBody field(String name, InputStream value, ContentType contentType) { + @Override + public HttpRequestMultPart field(String name, InputStream value, ContentType contentType) { addPart(name, new InputStreamBody(value, contentType), contentType); return this; } - public MultipartBody field(String name, File file) { + @Override + public HttpRequestMultPart field(String name, File file) { addPart(name, file); return this; } - public MultipartBody field(String name, File file, String contentType) { + @Override + public HttpRequestMultPart field(String name, File file, String contentType) { addPart(name, file, tryParse(contentType)); return this; } - public MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName) { + @Override + public HttpRequestMultPart field(String name, InputStream stream, ContentType contentType, String fileName) { addPart(name, new InputStreamBody(stream, contentType, fileName), contentType); return this; } - public MultipartBody field(String name, InputStream stream, String fileName) { + @Override + public HttpRequestMultPart field(String name, InputStream stream, String fileName) { addPart(name, new InputStreamBody(stream, ContentType.APPLICATION_OCTET_STREAM, fileName), ContentType.APPLICATION_OCTET_STREAM); return this; } - public MultipartBody field(String name, byte[] bytes, ContentType contentType, String fileName) { + @Override + public HttpRequestMultPart field(String name, byte[] bytes, ContentType contentType, String fileName) { addPart(name, new ByteArrayBody(bytes, contentType, fileName), contentType); return this; } - public MultipartBody field(String name, byte[] bytes, String fileName) { + @Override + public HttpRequestMultPart field(String name, byte[] bytes, String fileName) { addPart(name, new ByteArrayBody(bytes, ContentType.APPLICATION_OCTET_STREAM, fileName), ContentType.APPLICATION_OCTET_STREAM); return this; } - public MultipartBody charset(Charset charset) { + @Override + public HttpRequestMultPart charset(Charset charset) { httpRequestObj.charset(charset); return this; } - public MultipartBody accept(String mimeType) { - httpRequestObj.accept(mimeType); + @Override + public HttpRequestMultPart contentType(String mimeType) { + httpRequestObj.header(HttpHeaders.CONTENT_TYPE, mimeType); return this; } - public MultipartBody contentType(String mimeType) { - httpRequestObj.header(HttpHeaders.CONTENT_TYPE, mimeType); + @Override + public MultipartBody accept(String mimeType) { + httpRequestObj.accept(mimeType); return this; } + @Override public MultipartBody basicAuth(String username, String password) { httpRequestObj.basicAuth(username, password); return this; } + @Override public MultipartBody header(String name, String value) { httpRequestObj.header(name, value); return this; } - public MultipartBody mode(String value) { + @Override + public HttpRequestMultPart mode(String value) { this.mode = HttpMultipartMode.valueOf(value); return this; } - public MultipartBody mode(HttpMultipartMode value) { + @Override + public HttpRequestMultPart mode(HttpMultipartMode value) { this.mode = value; return this; } + @Override public HttpEntity getEntity() { if (parameters.stream().anyMatch(FormPart::isFile)) { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); From f6f783783b10d3b7698b28284f8717c48d7dac14 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 16 Nov 2018 08:14:07 -0600 Subject: [PATCH 0255/1769] rm config as field --- src/main/java/unirest/HttpRequestWithBody.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/unirest/HttpRequestWithBody.java b/src/main/java/unirest/HttpRequestWithBody.java index b8c103764..6492a9ed4 100644 --- a/src/main/java/unirest/HttpRequestWithBody.java +++ b/src/main/java/unirest/HttpRequestWithBody.java @@ -40,12 +40,10 @@ public class HttpRequestWithBody extends BaseRequest { - private final Config config; private Charset charSet = StandardCharsets.UTF_8; public HttpRequestWithBody(Config config, HttpMethod method, String url) { super(config, method, url); - this.config = config; } public HttpRequestMultPart field(String name, Collection value) { From b2ef8693f9a3cbdd7b9558edbfeeeb2d0a9dcc29 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 16 Nov 2018 08:19:19 -0600 Subject: [PATCH 0256/1769] extract interface for HttpRequestBody --- src/main/java/unirest/HttpRequestBody.java | 45 +++++++++++++++++++ .../java/unirest/HttpRequestWithBody.java | 18 +++++++- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/main/java/unirest/HttpRequestBody.java diff --git a/src/main/java/unirest/HttpRequestBody.java b/src/main/java/unirest/HttpRequestBody.java new file mode 100644 index 000000000..bfa1365fb --- /dev/null +++ b/src/main/java/unirest/HttpRequestBody.java @@ -0,0 +1,45 @@ +package unirest; + +import org.apache.http.entity.ContentType; +import org.json.JSONArray; +import org.json.JSONObject; + +import java.io.File; +import java.io.InputStream; +import java.nio.charset.Charset; +import java.util.Collection; +import java.util.Map; + +public interface HttpRequestBody extends HttpRequest { + HttpRequestBody charset(Charset charset); + + HttpRequestMultPart field(String name, Collection value); + + HttpRequestMultPart field(String name, File file); + + HttpRequestMultPart field(String name, File file, String contentType); + + HttpRequestMultPart field(String name, Object value); + + HttpRequestMultPart field(String name, Object value, String contentType); + + HttpRequestMultPart fields(Map parameters); + + HttpRequestMultPart field(String name, InputStream stream, ContentType contentType, String fileName); + + HttpRequestMultPart field(String name, InputStream stream, String fileName); + + HttpRequestUniBody body(JsonNode body); + + HttpRequestUniBody body(String body); + + HttpRequestUniBody body(Object body); + + HttpRequestUniBody body(byte[] body); + + HttpRequestUniBody body(JSONObject body); + + HttpRequestUniBody body(JSONArray body); + + Charset getCharset(); +} diff --git a/src/main/java/unirest/HttpRequestWithBody.java b/src/main/java/unirest/HttpRequestWithBody.java index 6492a9ed4..0022ee619 100644 --- a/src/main/java/unirest/HttpRequestWithBody.java +++ b/src/main/java/unirest/HttpRequestWithBody.java @@ -38,7 +38,7 @@ import java.util.Map; import java.util.Map.Entry; -public class HttpRequestWithBody extends BaseRequest { +public class HttpRequestWithBody extends BaseRequest implements HttpRequestBody { private Charset charSet = StandardCharsets.UTF_8; @@ -46,32 +46,38 @@ public HttpRequestWithBody(Config config, HttpMethod method, String url) { super(config, method, url); } + @Override public HttpRequestMultPart field(String name, Collection value) { HttpRequestMultPart body = new MultipartBody(this).field(name, value); this.body = body; return body; } + @Override public HttpRequestMultPart field(String name, File file) { return field(name, file, null); } + @Override public HttpRequestMultPart field(String name, File file, String contentType) { HttpRequestMultPart body = new MultipartBody(this).field(name, file, contentType); this.body = body; return body; } + @Override public HttpRequestMultPart field(String name, Object value) { return field(name, value, null); } + @Override public HttpRequestMultPart field(String name, Object value, String contentType) { HttpRequestMultPart body = new MultipartBody(this).field(name, nullToEmpty(value), contentType); this.body = body; return body; } + @Override public HttpRequestMultPart fields(Map parameters) { MultipartBody body = new MultipartBody(this); if (parameters != null) { @@ -94,37 +100,44 @@ private String nullToEmpty(Object v) { return v.toString(); } + @Override public HttpRequestMultPart field(String name, InputStream stream, ContentType contentType, String fileName) { HttpRequestMultPart body = new MultipartBody(this).field(name, stream, contentType, fileName); this.body = body; return body; } + @Override public HttpRequestMultPart field(String name, InputStream stream, String fileName) { HttpRequestMultPart body = field(name, stream, ContentType.APPLICATION_OCTET_STREAM, fileName); this.body = body; return body; } + @Override public HttpRequestWithBody charset(Charset charset) { this.charSet = charset; return this; } + @Override public HttpRequestUniBody body(JsonNode body) { return body(body.toString()); } + @Override public HttpRequestUniBody body(String body) { HttpRequestUniBody b = new RequestBodyEntity(this).body(body); this.body = b; return b; } + @Override public HttpRequestUniBody body(Object body) { return body(config.getObjectMapper().writeValue(body)); } + @Override public HttpRequestUniBody body(byte[] body) { HttpRequestUniBody b = new RequestBodyEntity(this).body(body); this.body = b; @@ -137,6 +150,7 @@ public HttpRequestUniBody body(byte[] body) { * @param body raw org.JSONObject * @return RequestBodyEntity instance */ + @Override public HttpRequestUniBody body(JSONObject body) { return body(body.toString()); } @@ -147,10 +161,12 @@ public HttpRequestUniBody body(JSONObject body) { * @param body raw org.JSONArray * @return RequestBodyEntity instance */ + @Override public HttpRequestUniBody body(JSONArray body) { return body(body.toString()); } + @Override public Charset getCharset() { return charSet; } From e24039277246171a2de285765d4834d0df280159 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 16 Nov 2018 08:23:46 -0600 Subject: [PATCH 0257/1769] realign to use only interfaces --- src/main/java/unirest/BaseRequest.java | 2 +- .../{GetRequest.java => BasicRequest.java} | 7 +--- src/main/java/unirest/HttpRequest.java | 2 +- src/main/java/unirest/HttpRequestBody.java | 28 +++++++++++++++- .../java/unirest/HttpRequestMultPart.java | 2 +- src/main/java/unirest/HttpRequestNoBody.java | 33 +++++++++++++++++++ src/main/java/unirest/HttpRequestUniBody.java | 2 +- .../java/unirest/HttpRequestWithBody.java | 2 +- src/main/java/unirest/MultipartBody.java | 2 +- src/main/java/unirest/RequestBodyEntity.java | 2 +- src/main/java/unirest/Unirest.java | 14 ++++---- src/main/java/unirest/UnirestInstance.java | 18 +++++----- src/test/java/BehaviorTests/HeaderTest.java | 7 ++-- 13 files changed, 86 insertions(+), 35 deletions(-) rename src/main/java/unirest/{GetRequest.java => BasicRequest.java} (89%) create mode 100644 src/main/java/unirest/HttpRequestNoBody.java diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 4baa318c0..b7664d470 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -40,7 +40,7 @@ import java.util.concurrent.CompletableFuture; import java.util.function.Function; -public abstract class BaseRequest implements HttpRequest { +public abstract class BaseRequest implements HttpRequest { protected Body body; protected Headers headers = new Headers(); diff --git a/src/main/java/unirest/GetRequest.java b/src/main/java/unirest/BasicRequest.java similarity index 89% rename from src/main/java/unirest/GetRequest.java rename to src/main/java/unirest/BasicRequest.java index 0efcb1ee0..e4fe170d7 100644 --- a/src/main/java/unirest/GetRequest.java +++ b/src/main/java/unirest/BasicRequest.java @@ -26,10 +26,5 @@ package unirest; -public class GetRequest extends BaseRequest { - - public GetRequest(Config config, HttpMethod method, String url) { - super(config, method, url); - } - +public interface BasicRequest extends HttpRequest { } diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index 3114260d0..d36132984 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -31,7 +31,7 @@ import java.util.Map; import java.util.concurrent.CompletableFuture; -public interface HttpRequest { +public interface HttpRequest { R routeParam(String name, String value); R basicAuth(String username, String password); diff --git a/src/main/java/unirest/HttpRequestBody.java b/src/main/java/unirest/HttpRequestBody.java index bfa1365fb..2747a0b46 100644 --- a/src/main/java/unirest/HttpRequestBody.java +++ b/src/main/java/unirest/HttpRequestBody.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import org.apache.http.entity.ContentType; @@ -10,7 +36,7 @@ import java.util.Collection; import java.util.Map; -public interface HttpRequestBody extends HttpRequest { +public interface HttpRequestBody extends HttpRequest { HttpRequestBody charset(Charset charset); HttpRequestMultPart field(String name, Collection value); diff --git a/src/main/java/unirest/HttpRequestMultPart.java b/src/main/java/unirest/HttpRequestMultPart.java index e5ac9610c..f367be066 100644 --- a/src/main/java/unirest/HttpRequestMultPart.java +++ b/src/main/java/unirest/HttpRequestMultPart.java @@ -35,7 +35,7 @@ import java.nio.charset.Charset; import java.util.Collection; -public interface HttpRequestMultPart extends HttpRequest, Body { +public interface HttpRequestMultPart extends HttpRequest, Body { HttpRequestMultPart field(String name, String value); HttpRequestMultPart field(String name, String value, String contentType); diff --git a/src/main/java/unirest/HttpRequestNoBody.java b/src/main/java/unirest/HttpRequestNoBody.java new file mode 100644 index 000000000..dfcb1a3cd --- /dev/null +++ b/src/main/java/unirest/HttpRequestNoBody.java @@ -0,0 +1,33 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +public class HttpRequestNoBody extends BaseRequest implements BasicRequest { + public HttpRequestNoBody(Config config, HttpMethod method, String url) { + super(config, method, url); + } +} diff --git a/src/main/java/unirest/HttpRequestUniBody.java b/src/main/java/unirest/HttpRequestUniBody.java index 2bf170668..9d1c69091 100644 --- a/src/main/java/unirest/HttpRequestUniBody.java +++ b/src/main/java/unirest/HttpRequestUniBody.java @@ -30,7 +30,7 @@ import java.nio.charset.Charset; -public interface HttpRequestUniBody extends HttpRequest, Body { +public interface HttpRequestUniBody extends HttpRequest, Body { HttpRequestUniBody body(byte[] bodyBytes); HttpRequestUniBody body(String bodyAsString); diff --git a/src/main/java/unirest/HttpRequestWithBody.java b/src/main/java/unirest/HttpRequestWithBody.java index 0022ee619..cd927a4f3 100644 --- a/src/main/java/unirest/HttpRequestWithBody.java +++ b/src/main/java/unirest/HttpRequestWithBody.java @@ -38,7 +38,7 @@ import java.util.Map; import java.util.Map.Entry; -public class HttpRequestWithBody extends BaseRequest implements HttpRequestBody { +public class HttpRequestWithBody extends BaseRequest implements HttpRequestBody { private Charset charSet = StandardCharsets.UTF_8; diff --git a/src/main/java/unirest/MultipartBody.java b/src/main/java/unirest/MultipartBody.java index 8e8f2e868..f7b16a0ea 100644 --- a/src/main/java/unirest/MultipartBody.java +++ b/src/main/java/unirest/MultipartBody.java @@ -43,7 +43,7 @@ import java.util.Collections; import java.util.List; -public class MultipartBody extends BaseRequest implements HttpRequestMultPart { +public class MultipartBody extends BaseRequest implements HttpRequestMultPart { private List parameters = new ArrayList<>(); private HttpRequestWithBody httpRequestObj; diff --git a/src/main/java/unirest/RequestBodyEntity.java b/src/main/java/unirest/RequestBodyEntity.java index 27b2c96dd..addd73ebc 100644 --- a/src/main/java/unirest/RequestBodyEntity.java +++ b/src/main/java/unirest/RequestBodyEntity.java @@ -34,7 +34,7 @@ import java.nio.charset.StandardCharsets; import java.util.function.Supplier; -public class RequestBodyEntity extends BaseRequest implements HttpRequestUniBody { +public class RequestBodyEntity extends BaseRequest implements HttpRequestUniBody { private final HttpRequestWithBody request; private Supplier body = () -> new StringEntity("", StandardCharsets.UTF_8); diff --git a/src/main/java/unirest/Unirest.java b/src/main/java/unirest/Unirest.java index 7e171cc99..f9d984e66 100644 --- a/src/main/java/unirest/Unirest.java +++ b/src/main/java/unirest/Unirest.java @@ -53,31 +53,31 @@ public static void shutDown(boolean clearOptions) { primaryInstance.shutDown(clearOptions); } - public static GetRequest get(String url) { + public static BasicRequest get(String url) { return primaryInstance.get(url); } - public static GetRequest head(String url) { + public static BasicRequest head(String url) { return primaryInstance.head(url); } - public static HttpRequestWithBody options(String url) { + public static HttpRequestBody options(String url) { return primaryInstance.options(url); } - public static HttpRequestWithBody post(String url) { + public static HttpRequestBody post(String url) { return primaryInstance.post(url); } - public static HttpRequestWithBody delete(String url) { + public static HttpRequestBody delete(String url) { return primaryInstance.delete(url); } - public static HttpRequestWithBody patch(String url) { + public static HttpRequestBody patch(String url) { return primaryInstance.patch(url); } - public static HttpRequestWithBody put(String url) { + public static HttpRequestBody put(String url) { return primaryInstance.put(url); } diff --git a/src/main/java/unirest/UnirestInstance.java b/src/main/java/unirest/UnirestInstance.java index 1de4025b4..bd5f45d91 100644 --- a/src/main/java/unirest/UnirestInstance.java +++ b/src/main/java/unirest/UnirestInstance.java @@ -57,31 +57,31 @@ public void shutDown(boolean clearOptions) { config.shutDown(clearOptions); } - public GetRequest get(String url) { - return new GetRequest(config, HttpMethod.GET, url); + public BasicRequest get(String url) { + return new HttpRequestNoBody(config, HttpMethod.GET, url); } - public GetRequest head(String url) { - return new GetRequest(config, HttpMethod.HEAD, url); + public BasicRequest head(String url) { + return new HttpRequestNoBody(config, HttpMethod.HEAD, url); } - public HttpRequestWithBody options(String url) { + public HttpRequestBody options(String url) { return new HttpRequestWithBody(config, HttpMethod.OPTIONS, url); } - public HttpRequestWithBody post(String url) { + public HttpRequestBody post(String url) { return new HttpRequestWithBody(config, HttpMethod.POST, url); } - public HttpRequestWithBody delete(String url) { + public HttpRequestBody delete(String url) { return new HttpRequestWithBody(config, HttpMethod.DELETE, url); } - public HttpRequestWithBody patch(String url) { + public HttpRequestBody patch(String url) { return new HttpRequestWithBody(config, HttpMethod.PATCH, url); } - public HttpRequestWithBody put(String url) { + public HttpRequestBody put(String url) { return new HttpRequestWithBody(config, HttpMethod.PUT, url); } diff --git a/src/test/java/BehaviorTests/HeaderTest.java b/src/test/java/BehaviorTests/HeaderTest.java index 1ea99035a..b40236167 100644 --- a/src/test/java/BehaviorTests/HeaderTest.java +++ b/src/test/java/BehaviorTests/HeaderTest.java @@ -28,10 +28,7 @@ import org.junit.Ignore; import org.junit.Test; -import unirest.GetRequest; -import unirest.HttpResponse; -import unirest.JsonNode; -import unirest.Unirest; +import unirest.*; import static org.junit.Assert.assertEquals; import static unirest.TestUtil.assertBasicAuth; @@ -94,7 +91,7 @@ public void testDefaultHeaders() { @Test public void testCaseInsensitiveHeaders() { - GetRequest request = Unirest.get(MockServer.GET) + BasicRequest request = Unirest.get(MockServer.GET) .header("Name", "Marco"); assertEquals(1, request.getHeaders().size()); From c9ce9ba09ce1ad055f07a9523646685923132a88 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 16 Nov 2018 08:50:00 -0600 Subject: [PATCH 0258/1769] options cant have a body per http spec --- src/main/java/unirest/Unirest.java | 2 +- src/main/java/unirest/UnirestInstance.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/unirest/Unirest.java b/src/main/java/unirest/Unirest.java index f9d984e66..c7dc28354 100644 --- a/src/main/java/unirest/Unirest.java +++ b/src/main/java/unirest/Unirest.java @@ -61,7 +61,7 @@ public static BasicRequest head(String url) { return primaryInstance.head(url); } - public static HttpRequestBody options(String url) { + public static BasicRequest options(String url) { return primaryInstance.options(url); } diff --git a/src/main/java/unirest/UnirestInstance.java b/src/main/java/unirest/UnirestInstance.java index bd5f45d91..fa8870e06 100644 --- a/src/main/java/unirest/UnirestInstance.java +++ b/src/main/java/unirest/UnirestInstance.java @@ -65,8 +65,8 @@ public BasicRequest head(String url) { return new HttpRequestNoBody(config, HttpMethod.HEAD, url); } - public HttpRequestBody options(String url) { - return new HttpRequestWithBody(config, HttpMethod.OPTIONS, url); + public BasicRequest options(String url) { + return new HttpRequestNoBody(config, HttpMethod.OPTIONS, url); } public HttpRequestBody post(String url) { From 6960b6f143063379cbf00eb6bdb529d50ae3b314 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 16 Nov 2018 09:52:55 -0600 Subject: [PATCH 0259/1769] lets use the original names of the public interfaces so as not to break EVERYTHING --- .../{BasicRequest.java => GetRequest.java} | 2 +- src/main/java/unirest/HttpRequestBody.java | 172 ++++++++++++--- .../java/unirest/HttpRequestMultPart.java | 68 ------ .../java/unirest/HttpRequestMultiPart.java | 197 ++++++++++++++++++ src/main/java/unirest/HttpRequestNoBody.java | 2 +- src/main/java/unirest/HttpRequestUniBody.java | 43 +++- .../java/unirest/HttpRequestWithBody.java | 172 +++------------ src/main/java/unirest/MultipartBody.java | 191 +++-------------- src/main/java/unirest/RequestBodyEntity.java | 43 +--- src/main/java/unirest/Unirest.java | 14 +- src/main/java/unirest/UnirestInstance.java | 22 +- src/test/java/BehaviorTests/HeaderTest.java | 2 +- 12 files changed, 464 insertions(+), 464 deletions(-) rename src/main/java/unirest/{BasicRequest.java => GetRequest.java} (95%) delete mode 100644 src/main/java/unirest/HttpRequestMultPart.java create mode 100644 src/main/java/unirest/HttpRequestMultiPart.java diff --git a/src/main/java/unirest/BasicRequest.java b/src/main/java/unirest/GetRequest.java similarity index 95% rename from src/main/java/unirest/BasicRequest.java rename to src/main/java/unirest/GetRequest.java index e4fe170d7..9458de2a3 100644 --- a/src/main/java/unirest/BasicRequest.java +++ b/src/main/java/unirest/GetRequest.java @@ -26,5 +26,5 @@ package unirest; -public interface BasicRequest extends HttpRequest { +public interface GetRequest extends HttpRequest { } diff --git a/src/main/java/unirest/HttpRequestBody.java b/src/main/java/unirest/HttpRequestBody.java index 2747a0b46..b663b42e6 100644 --- a/src/main/java/unirest/HttpRequestBody.java +++ b/src/main/java/unirest/HttpRequestBody.java @@ -33,39 +33,145 @@ import java.io.File; import java.io.InputStream; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Map; - -public interface HttpRequestBody extends HttpRequest { - HttpRequestBody charset(Charset charset); - - HttpRequestMultPart field(String name, Collection value); - - HttpRequestMultPart field(String name, File file); - - HttpRequestMultPart field(String name, File file, String contentType); - - HttpRequestMultPart field(String name, Object value); - - HttpRequestMultPart field(String name, Object value, String contentType); - - HttpRequestMultPart fields(Map parameters); - - HttpRequestMultPart field(String name, InputStream stream, ContentType contentType, String fileName); - - HttpRequestMultPart field(String name, InputStream stream, String fileName); - - HttpRequestUniBody body(JsonNode body); - - HttpRequestUniBody body(String body); - - HttpRequestUniBody body(Object body); - - HttpRequestUniBody body(byte[] body); - - HttpRequestUniBody body(JSONObject body); - - HttpRequestUniBody body(JSONArray body); - - Charset getCharset(); +import java.util.Map.Entry; + +public class HttpRequestBody extends BaseRequest implements HttpRequestWithBody { + + private Charset charSet = StandardCharsets.UTF_8; + + public HttpRequestBody(Config config, HttpMethod method, String url) { + super(config, method, url); + } + + @Override + public MultipartBody field(String name, Collection value) { + MultipartBody body = new HttpRequestMultiPart(this).field(name, value); + this.body = body; + return body; + } + + @Override + public MultipartBody field(String name, File file) { + return field(name, file, null); + } + + @Override + public MultipartBody field(String name, File file, String contentType) { + MultipartBody body = new HttpRequestMultiPart(this).field(name, file, contentType); + this.body = body; + return body; + } + + @Override + public MultipartBody field(String name, Object value) { + return field(name, value, null); + } + + @Override + public MultipartBody field(String name, Object value, String contentType) { + MultipartBody body = new HttpRequestMultiPart(this).field(name, nullToEmpty(value), contentType); + this.body = body; + return body; + } + + @Override + public MultipartBody fields(Map parameters) { + HttpRequestMultiPart body = new HttpRequestMultiPart(this); + if (parameters != null) { + for (Entry param : parameters.entrySet()) { + if (param.getValue() instanceof File) { + body.field(param.getKey(), (File) param.getValue()); + } else { + body.field(param.getKey(), nullToEmpty(param.getValue())); + } + } + } + this.body = body; + return body; + } + + private String nullToEmpty(Object v) { + if(v == null){ + return ""; + } + return v.toString(); + } + + @Override + public MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName) { + MultipartBody body = new HttpRequestMultiPart(this).field(name, stream, contentType, fileName); + this.body = body; + return body; + } + + @Override + public MultipartBody field(String name, InputStream stream, String fileName) { + MultipartBody body = field(name, stream, ContentType.APPLICATION_OCTET_STREAM, fileName); + this.body = body; + return body; + } + + @Override + public HttpRequestBody charset(Charset charset) { + this.charSet = charset; + return this; + } + + @Override + public RequestBodyEntity body(JsonNode body) { + return body(body.toString()); + } + + @Override + public RequestBodyEntity body(String body) { + RequestBodyEntity b = new HttpRequestUniBody(this).body(body); + this.body = b; + return b; + } + + @Override + public RequestBodyEntity body(Object body) { + return body(config.getObjectMapper().writeValue(body)); + } + + @Override + public RequestBodyEntity body(byte[] body) { + RequestBodyEntity b = new HttpRequestUniBody(this).body(body); + this.body = b; + return b; + } + + /** + * Sugar method for body operation + * + * @param body raw org.JSONObject + * @return RequestBodyEntity instance + */ + @Override + public RequestBodyEntity body(JSONObject body) { + return body(body.toString()); + } + + /** + * Sugar method for body operation + * + * @param body raw org.JSONArray + * @return RequestBodyEntity instance + */ + @Override + public RequestBodyEntity body(JSONArray body) { + return body(body.toString()); + } + + @Override + public Charset getCharset() { + return charSet; + } + + void setCharset(Charset charset) { + this.charSet = charset; + } } diff --git a/src/main/java/unirest/HttpRequestMultPart.java b/src/main/java/unirest/HttpRequestMultPart.java deleted file mode 100644 index f367be066..000000000 --- a/src/main/java/unirest/HttpRequestMultPart.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package unirest; - -import org.apache.http.HttpEntity; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.mime.HttpMultipartMode; - -import java.io.File; -import java.io.InputStream; -import java.nio.charset.Charset; -import java.util.Collection; - -public interface HttpRequestMultPart extends HttpRequest, Body { - HttpRequestMultPart field(String name, String value); - - HttpRequestMultPart field(String name, String value, String contentType); - - HttpRequestMultPart field(String name, Collection collection); - - HttpRequestMultPart field(String name, InputStream value, ContentType contentType); - - HttpRequestMultPart field(String name, File file); - - HttpRequestMultPart field(String name, File file, String contentType); - - HttpRequestMultPart field(String name, InputStream stream, ContentType contentType, String fileName); - - HttpRequestMultPart field(String name, InputStream stream, String fileName); - - HttpRequestMultPart field(String name, byte[] bytes, ContentType contentType, String fileName); - - HttpRequestMultPart field(String name, byte[] bytes, String fileName); - - HttpRequestMultPart charset(Charset charset); - - HttpRequestMultPart contentType(String mimeType); - - HttpRequestMultPart mode(String value); - - HttpRequestMultPart mode(HttpMultipartMode value); - - HttpEntity getEntity(); -} diff --git a/src/main/java/unirest/HttpRequestMultiPart.java b/src/main/java/unirest/HttpRequestMultiPart.java new file mode 100644 index 000000000..41b5db52d --- /dev/null +++ b/src/main/java/unirest/HttpRequestMultiPart.java @@ -0,0 +1,197 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpHeaders; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.mime.HttpMultipartMode; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.entity.mime.content.ByteArrayBody; +import org.apache.http.entity.mime.content.InputStreamBody; + +import java.io.File; +import java.io.InputStream; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +public class HttpRequestMultiPart extends BaseRequest implements MultipartBody { + private List parameters = new ArrayList<>(); + + private HttpRequestBody httpRequestObj; + private HttpMultipartMode mode = HttpMultipartMode.BROWSER_COMPATIBLE; + + public HttpRequestMultiPart(HttpRequestBody httpRequest) { + super(httpRequest); + this.httpRequestObj = httpRequest; + } + + @Override + public MultipartBody field(String name, String value) { + addPart(name, value); + return this; + } + + @Override + public MultipartBody field(String name, String value, String contentType) { + addPart(name, value, tryParse(contentType)); + return this; + } + + @Override + public MultipartBody field(String name, Collection collection) { + for (Object current: collection) { + addPart(name, current, null); + } + return this; + } + + @Override + public MultipartBody field(String name, InputStream value, ContentType contentType) { + addPart(name, new InputStreamBody(value, contentType), contentType); + return this; + } + + @Override + public MultipartBody field(String name, File file) { + addPart(name, file); + return this; + } + + @Override + public MultipartBody field(String name, File file, String contentType) { + addPart(name, file, tryParse(contentType)); + + return this; + } + + @Override + public MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName) { + addPart(name, new InputStreamBody(stream, contentType, fileName), contentType); + + return this; + } + + @Override + public MultipartBody field(String name, InputStream stream, String fileName) { + addPart(name, new InputStreamBody(stream, ContentType.APPLICATION_OCTET_STREAM, fileName), ContentType.APPLICATION_OCTET_STREAM); + + return this; + } + + @Override + public MultipartBody field(String name, byte[] bytes, ContentType contentType, String fileName) { + addPart(name, new ByteArrayBody(bytes, contentType, fileName), contentType); + + return this; + } + + @Override + public MultipartBody field(String name, byte[] bytes, String fileName) { + addPart(name, new ByteArrayBody(bytes, ContentType.APPLICATION_OCTET_STREAM, fileName), ContentType.APPLICATION_OCTET_STREAM); + + return this; + } + + @Override + public MultipartBody charset(Charset charset) { + httpRequestObj.charset(charset); + return this; + } + + @Override + public MultipartBody contentType(String mimeType) { + httpRequestObj.header(HttpHeaders.CONTENT_TYPE, mimeType); + return this; + } + + @Override + public MultipartBody accept(String mimeType) { + httpRequestObj.accept(mimeType); + return this; + } + + @Override + public MultipartBody basicAuth(String username, String password) { + httpRequestObj.basicAuth(username, password); + return this; + } + + @Override + public MultipartBody header(String name, String value) { + httpRequestObj.header(name, value); + return this; + } + + @Override + public MultipartBody mode(String value) { + this.mode = HttpMultipartMode.valueOf(value); + return this; + } + + @Override + public MultipartBody mode(HttpMultipartMode value) { + this.mode = value; + return this; + } + + @Override + public HttpEntity getEntity() { + if (parameters.stream().anyMatch(FormPart::isFile)) { + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + builder.setCharset(httpRequestObj.getCharset()); + builder.setMode(mode); + for (FormPart key : parameters) { + builder.addPart(key.getName(), key.toApachePart()); + } + return builder.build(); + } else { + return new UrlEncodedFormEntity(MapUtil.getList(parameters), httpRequestObj.getCharset()); + } + } + + private void addPart(String name, Object value, ContentType type) { + parameters.add(new FormPart(name, value, type)); + Collections.sort(parameters); + } + + private void addPart(String name, Object value) { + addPart(name, value, null); + } + + private ContentType tryParse(String contentType) { + if (contentType != null && contentType.length() > 0) { + return ContentType.parse(contentType); + } else { + return null; + } + } +} diff --git a/src/main/java/unirest/HttpRequestNoBody.java b/src/main/java/unirest/HttpRequestNoBody.java index dfcb1a3cd..2ebed6481 100644 --- a/src/main/java/unirest/HttpRequestNoBody.java +++ b/src/main/java/unirest/HttpRequestNoBody.java @@ -26,7 +26,7 @@ package unirest; -public class HttpRequestNoBody extends BaseRequest implements BasicRequest { +public class HttpRequestNoBody extends BaseRequest implements GetRequest { public HttpRequestNoBody(Config config, HttpMethod method, String url) { super(config, method, url); } diff --git a/src/main/java/unirest/HttpRequestUniBody.java b/src/main/java/unirest/HttpRequestUniBody.java index 9d1c69091..f594fb869 100644 --- a/src/main/java/unirest/HttpRequestUniBody.java +++ b/src/main/java/unirest/HttpRequestUniBody.java @@ -27,17 +27,48 @@ package unirest; import org.apache.http.HttpEntity; +import org.apache.http.entity.ByteArrayEntity; +import org.apache.http.entity.StringEntity; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.util.function.Supplier; -public interface HttpRequestUniBody extends HttpRequest, Body { - HttpRequestUniBody body(byte[] bodyBytes); +public class HttpRequestUniBody extends BaseRequest implements RequestBodyEntity { - HttpRequestUniBody body(String bodyAsString); + private final HttpRequestBody request; + private Supplier body = () -> new StringEntity("", StandardCharsets.UTF_8); - HttpRequestUniBody body(JsonNode jsonBody); + HttpRequestUniBody(HttpRequestBody httpRequest) { + super(httpRequest); + request = httpRequest; + } - HttpRequestUniBody charset(Charset charset); + @Override + public RequestBodyEntity body(byte[] bodyBytes) { + this.body = () -> new ByteArrayEntity(bodyBytes); + return this; + } - HttpEntity getEntity(); + @Override + public RequestBodyEntity body(String bodyAsString) { + this.body = () -> new StringEntity(bodyAsString, request.getCharset()); + return this; + } + + @Override + public RequestBodyEntity body(JsonNode jsonBody) { + return body(jsonBody.toString()); + } + + @Override + public RequestBodyEntity charset(Charset charset) { + request.charset(charset); + return this; + } + + @Override + public HttpEntity getEntity() { + return body.get(); + } } diff --git a/src/main/java/unirest/HttpRequestWithBody.java b/src/main/java/unirest/HttpRequestWithBody.java index cd927a4f3..5c63331f2 100644 --- a/src/main/java/unirest/HttpRequestWithBody.java +++ b/src/main/java/unirest/HttpRequestWithBody.java @@ -33,145 +33,39 @@ import java.io.File; import java.io.InputStream; import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Map; -import java.util.Map.Entry; - -public class HttpRequestWithBody extends BaseRequest implements HttpRequestBody { - - private Charset charSet = StandardCharsets.UTF_8; - - public HttpRequestWithBody(Config config, HttpMethod method, String url) { - super(config, method, url); - } - - @Override - public HttpRequestMultPart field(String name, Collection value) { - HttpRequestMultPart body = new MultipartBody(this).field(name, value); - this.body = body; - return body; - } - - @Override - public HttpRequestMultPart field(String name, File file) { - return field(name, file, null); - } - - @Override - public HttpRequestMultPart field(String name, File file, String contentType) { - HttpRequestMultPart body = new MultipartBody(this).field(name, file, contentType); - this.body = body; - return body; - } - - @Override - public HttpRequestMultPart field(String name, Object value) { - return field(name, value, null); - } - - @Override - public HttpRequestMultPart field(String name, Object value, String contentType) { - HttpRequestMultPart body = new MultipartBody(this).field(name, nullToEmpty(value), contentType); - this.body = body; - return body; - } - - @Override - public HttpRequestMultPart fields(Map parameters) { - MultipartBody body = new MultipartBody(this); - if (parameters != null) { - for (Entry param : parameters.entrySet()) { - if (param.getValue() instanceof File) { - body.field(param.getKey(), (File) param.getValue()); - } else { - body.field(param.getKey(), nullToEmpty(param.getValue())); - } - } - } - this.body = body; - return body; - } - - private String nullToEmpty(Object v) { - if(v == null){ - return ""; - } - return v.toString(); - } - - @Override - public HttpRequestMultPart field(String name, InputStream stream, ContentType contentType, String fileName) { - HttpRequestMultPart body = new MultipartBody(this).field(name, stream, contentType, fileName); - this.body = body; - return body; - } - - @Override - public HttpRequestMultPart field(String name, InputStream stream, String fileName) { - HttpRequestMultPart body = field(name, stream, ContentType.APPLICATION_OCTET_STREAM, fileName); - this.body = body; - return body; - } - - @Override - public HttpRequestWithBody charset(Charset charset) { - this.charSet = charset; - return this; - } - - @Override - public HttpRequestUniBody body(JsonNode body) { - return body(body.toString()); - } - - @Override - public HttpRequestUniBody body(String body) { - HttpRequestUniBody b = new RequestBodyEntity(this).body(body); - this.body = b; - return b; - } - - @Override - public HttpRequestUniBody body(Object body) { - return body(config.getObjectMapper().writeValue(body)); - } - - @Override - public HttpRequestUniBody body(byte[] body) { - HttpRequestUniBody b = new RequestBodyEntity(this).body(body); - this.body = b; - return b; - } - - /** - * Sugar method for body operation - * - * @param body raw org.JSONObject - * @return RequestBodyEntity instance - */ - @Override - public HttpRequestUniBody body(JSONObject body) { - return body(body.toString()); - } - - /** - * Sugar method for body operation - * - * @param body raw org.JSONArray - * @return RequestBodyEntity instance - */ - @Override - public HttpRequestUniBody body(JSONArray body) { - return body(body.toString()); - } - - @Override - public Charset getCharset() { - return charSet; - } - - void setCharset(Charset charset) { - this.charSet = charset; - } + +public interface HttpRequestWithBody extends HttpRequest { + HttpRequestWithBody charset(Charset charset); + + MultipartBody field(String name, Collection value); + + MultipartBody field(String name, File file); + + MultipartBody field(String name, File file, String contentType); + + MultipartBody field(String name, Object value); + + MultipartBody field(String name, Object value, String contentType); + + MultipartBody fields(Map parameters); + + MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName); + + MultipartBody field(String name, InputStream stream, String fileName); + + RequestBodyEntity body(JsonNode body); + + RequestBodyEntity body(String body); + + RequestBodyEntity body(Object body); + + RequestBodyEntity body(byte[] body); + + RequestBodyEntity body(JSONObject body); + + RequestBodyEntity body(JSONArray body); + + Charset getCharset(); } diff --git a/src/main/java/unirest/MultipartBody.java b/src/main/java/unirest/MultipartBody.java index f7b16a0ea..cc6b9e7fe 100644 --- a/src/main/java/unirest/MultipartBody.java +++ b/src/main/java/unirest/MultipartBody.java @@ -27,171 +27,42 @@ package unirest; import org.apache.http.HttpEntity; -import org.apache.http.HttpHeaders; -import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.HttpMultipartMode; -import org.apache.http.entity.mime.MultipartEntityBuilder; -import org.apache.http.entity.mime.content.ByteArrayBody; -import org.apache.http.entity.mime.content.InputStreamBody; import java.io.File; import java.io.InputStream; import java.nio.charset.Charset; -import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; -import java.util.List; - -public class MultipartBody extends BaseRequest implements HttpRequestMultPart { - private List parameters = new ArrayList<>(); - - private HttpRequestWithBody httpRequestObj; - private HttpMultipartMode mode = HttpMultipartMode.BROWSER_COMPATIBLE; - - public MultipartBody(HttpRequestWithBody httpRequest) { - super(httpRequest); - this.httpRequestObj = httpRequest; - } - - @Override - public HttpRequestMultPart field(String name, String value) { - addPart(name, value); - return this; - } - - @Override - public HttpRequestMultPart field(String name, String value, String contentType) { - addPart(name, value, tryParse(contentType)); - return this; - } - - @Override - public HttpRequestMultPart field(String name, Collection collection) { - for (Object current: collection) { - addPart(name, current, null); - } - return this; - } - - @Override - public HttpRequestMultPart field(String name, InputStream value, ContentType contentType) { - addPart(name, new InputStreamBody(value, contentType), contentType); - return this; - } - - @Override - public HttpRequestMultPart field(String name, File file) { - addPart(name, file); - return this; - } - - @Override - public HttpRequestMultPart field(String name, File file, String contentType) { - addPart(name, file, tryParse(contentType)); - - return this; - } - - @Override - public HttpRequestMultPart field(String name, InputStream stream, ContentType contentType, String fileName) { - addPart(name, new InputStreamBody(stream, contentType, fileName), contentType); - - return this; - } - - @Override - public HttpRequestMultPart field(String name, InputStream stream, String fileName) { - addPart(name, new InputStreamBody(stream, ContentType.APPLICATION_OCTET_STREAM, fileName), ContentType.APPLICATION_OCTET_STREAM); - - return this; - } - - @Override - public HttpRequestMultPart field(String name, byte[] bytes, ContentType contentType, String fileName) { - addPart(name, new ByteArrayBody(bytes, contentType, fileName), contentType); - - return this; - } - - @Override - public HttpRequestMultPart field(String name, byte[] bytes, String fileName) { - addPart(name, new ByteArrayBody(bytes, ContentType.APPLICATION_OCTET_STREAM, fileName), ContentType.APPLICATION_OCTET_STREAM); - - return this; - } - - @Override - public HttpRequestMultPart charset(Charset charset) { - httpRequestObj.charset(charset); - return this; - } - - @Override - public HttpRequestMultPart contentType(String mimeType) { - httpRequestObj.header(HttpHeaders.CONTENT_TYPE, mimeType); - return this; - } - - @Override - public MultipartBody accept(String mimeType) { - httpRequestObj.accept(mimeType); - return this; - } - - @Override - public MultipartBody basicAuth(String username, String password) { - httpRequestObj.basicAuth(username, password); - return this; - } - - @Override - public MultipartBody header(String name, String value) { - httpRequestObj.header(name, value); - return this; - } - - @Override - public HttpRequestMultPart mode(String value) { - this.mode = HttpMultipartMode.valueOf(value); - return this; - } - - @Override - public HttpRequestMultPart mode(HttpMultipartMode value) { - this.mode = value; - return this; - } - - @Override - public HttpEntity getEntity() { - if (parameters.stream().anyMatch(FormPart::isFile)) { - MultipartEntityBuilder builder = MultipartEntityBuilder.create(); - builder.setCharset(httpRequestObj.getCharset()); - builder.setMode(mode); - for (FormPart key : parameters) { - builder.addPart(key.getName(), key.toApachePart()); - } - return builder.build(); - } else { - return new UrlEncodedFormEntity(MapUtil.getList(parameters), httpRequestObj.getCharset()); - } - } - - private void addPart(String name, Object value, ContentType type) { - parameters.add(new FormPart(name, value, type)); - Collections.sort(parameters); - } - - private void addPart(String name, Object value) { - addPart(name, value, null); - } - - private ContentType tryParse(String contentType) { - if (contentType != null && contentType.length() > 0) { - return ContentType.parse(contentType); - } else { - return null; - } - } + +public interface MultipartBody extends HttpRequest, Body { + MultipartBody field(String name, String value); + + MultipartBody field(String name, String value, String contentType); + + MultipartBody field(String name, Collection collection); + + MultipartBody field(String name, InputStream value, ContentType contentType); + + MultipartBody field(String name, File file); + + MultipartBody field(String name, File file, String contentType); + + MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName); + + MultipartBody field(String name, InputStream stream, String fileName); + + MultipartBody field(String name, byte[] bytes, ContentType contentType, String fileName); + + MultipartBody field(String name, byte[] bytes, String fileName); + + MultipartBody charset(Charset charset); + + MultipartBody contentType(String mimeType); + + MultipartBody mode(String value); + + MultipartBody mode(HttpMultipartMode value); + + HttpEntity getEntity(); } diff --git a/src/main/java/unirest/RequestBodyEntity.java b/src/main/java/unirest/RequestBodyEntity.java index addd73ebc..b032d1acd 100644 --- a/src/main/java/unirest/RequestBodyEntity.java +++ b/src/main/java/unirest/RequestBodyEntity.java @@ -27,48 +27,17 @@ package unirest; import org.apache.http.HttpEntity; -import org.apache.http.entity.ByteArrayEntity; -import org.apache.http.entity.StringEntity; import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.function.Supplier; -public class RequestBodyEntity extends BaseRequest implements HttpRequestUniBody { +public interface RequestBodyEntity extends HttpRequest, Body { + RequestBodyEntity body(byte[] bodyBytes); - private final HttpRequestWithBody request; - private Supplier body = () -> new StringEntity("", StandardCharsets.UTF_8); + RequestBodyEntity body(String bodyAsString); - RequestBodyEntity(HttpRequestWithBody httpRequest) { - super(httpRequest); - request = httpRequest; - } + RequestBodyEntity body(JsonNode jsonBody); - @Override - public HttpRequestUniBody body(byte[] bodyBytes) { - this.body = () -> new ByteArrayEntity(bodyBytes); - return this; - } + RequestBodyEntity charset(Charset charset); - @Override - public HttpRequestUniBody body(String bodyAsString) { - this.body = () -> new StringEntity(bodyAsString, request.getCharset()); - return this; - } - - @Override - public HttpRequestUniBody body(JsonNode jsonBody) { - return body(jsonBody.toString()); - } - - @Override - public HttpRequestUniBody charset(Charset charset) { - request.charset(charset); - return this; - } - - @Override - public HttpEntity getEntity() { - return body.get(); - } + HttpEntity getEntity(); } diff --git a/src/main/java/unirest/Unirest.java b/src/main/java/unirest/Unirest.java index c7dc28354..a828d9fdb 100644 --- a/src/main/java/unirest/Unirest.java +++ b/src/main/java/unirest/Unirest.java @@ -53,31 +53,31 @@ public static void shutDown(boolean clearOptions) { primaryInstance.shutDown(clearOptions); } - public static BasicRequest get(String url) { + public static GetRequest get(String url) { return primaryInstance.get(url); } - public static BasicRequest head(String url) { + public static GetRequest head(String url) { return primaryInstance.head(url); } - public static BasicRequest options(String url) { + public static GetRequest options(String url) { return primaryInstance.options(url); } - public static HttpRequestBody post(String url) { + public static HttpRequestWithBody post(String url) { return primaryInstance.post(url); } - public static HttpRequestBody delete(String url) { + public static HttpRequestWithBody delete(String url) { return primaryInstance.delete(url); } - public static HttpRequestBody patch(String url) { + public static HttpRequestWithBody patch(String url) { return primaryInstance.patch(url); } - public static HttpRequestBody put(String url) { + public static HttpRequestWithBody put(String url) { return primaryInstance.put(url); } diff --git a/src/main/java/unirest/UnirestInstance.java b/src/main/java/unirest/UnirestInstance.java index fa8870e06..ff2b2276a 100644 --- a/src/main/java/unirest/UnirestInstance.java +++ b/src/main/java/unirest/UnirestInstance.java @@ -57,32 +57,32 @@ public void shutDown(boolean clearOptions) { config.shutDown(clearOptions); } - public BasicRequest get(String url) { + public GetRequest get(String url) { return new HttpRequestNoBody(config, HttpMethod.GET, url); } - public BasicRequest head(String url) { + public GetRequest head(String url) { return new HttpRequestNoBody(config, HttpMethod.HEAD, url); } - public BasicRequest options(String url) { + public GetRequest options(String url) { return new HttpRequestNoBody(config, HttpMethod.OPTIONS, url); } - public HttpRequestBody post(String url) { - return new HttpRequestWithBody(config, HttpMethod.POST, url); + public HttpRequestWithBody post(String url) { + return new HttpRequestBody(config, HttpMethod.POST, url); } - public HttpRequestBody delete(String url) { - return new HttpRequestWithBody(config, HttpMethod.DELETE, url); + public HttpRequestWithBody delete(String url) { + return new HttpRequestBody(config, HttpMethod.DELETE, url); } - public HttpRequestBody patch(String url) { - return new HttpRequestWithBody(config, HttpMethod.PATCH, url); + public HttpRequestWithBody patch(String url) { + return new HttpRequestBody(config, HttpMethod.PATCH, url); } - public HttpRequestBody put(String url) { - return new HttpRequestWithBody(config, HttpMethod.PUT, url); + public HttpRequestWithBody put(String url) { + return new HttpRequestBody(config, HttpMethod.PUT, url); } public JsonPatchRequest jsonPatch(String url) { diff --git a/src/test/java/BehaviorTests/HeaderTest.java b/src/test/java/BehaviorTests/HeaderTest.java index b40236167..73fe74784 100644 --- a/src/test/java/BehaviorTests/HeaderTest.java +++ b/src/test/java/BehaviorTests/HeaderTest.java @@ -91,7 +91,7 @@ public void testDefaultHeaders() { @Test public void testCaseInsensitiveHeaders() { - BasicRequest request = Unirest.get(MockServer.GET) + GetRequest request = Unirest.get(MockServer.GET) .header("Name", "Marco"); assertEquals(1, request.getHeaders().size()); From 73a8da877e8d5d1574d19f99668041f5a377c2f5 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 16 Nov 2018 09:54:56 -0600 Subject: [PATCH 0260/1769] extract interface for json patch --- .../java/unirest/HttpRequestJsonPatch.java | 90 +++++++++++++++++++ src/main/java/unirest/JsonPatchRequest.java | 59 ++---------- src/main/java/unirest/UnirestInstance.java | 2 +- 3 files changed, 100 insertions(+), 51 deletions(-) create mode 100644 src/main/java/unirest/HttpRequestJsonPatch.java diff --git a/src/main/java/unirest/HttpRequestJsonPatch.java b/src/main/java/unirest/HttpRequestJsonPatch.java new file mode 100644 index 000000000..0dc866cd8 --- /dev/null +++ b/src/main/java/unirest/HttpRequestJsonPatch.java @@ -0,0 +1,90 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.apache.http.HttpEntity; +import org.apache.http.entity.BasicHttpEntity; + +import java.io.ByteArrayInputStream; + +public class HttpRequestJsonPatch extends BaseRequest implements JsonPatchRequest { + + private JsonPatch items = new JsonPatch(); + + public HttpRequestJsonPatch(Config config, String url) { + super(config, HttpMethod.PATCH, url); + header("Content-Type", CONTENT_TYPE); + } + + @Override + public JsonPatchRequest add(String path, Object value) { + items.add(path, value); + return this; + } + + @Override + public JsonPatchRequest remove(String path) { + items.remove(path); + return this; + } + + @Override + public JsonPatchRequest replace(String path, Object value) { + items.replace(path, value); + return this; + } + + @Override + public JsonPatchRequest test(String path, Object value) { + items.test(path, value); + return this; + } + + @Override + public JsonPatchRequest move(String from, String path) { + items.move(from, path); + return this; + } + + @Override + public JsonPatchRequest copy(String from, String path) { + items.copy(from, path); + return this; + } + + @Override + public Body getBody() { + return this; + } + + @Override + public HttpEntity getEntity() { + BasicHttpEntity e = new BasicHttpEntity(); + e.setContent(new ByteArrayInputStream(items.toString().getBytes())); + return e; + } +} \ No newline at end of file diff --git a/src/main/java/unirest/JsonPatchRequest.java b/src/main/java/unirest/JsonPatchRequest.java index 99e6925d0..b94109bc4 100644 --- a/src/main/java/unirest/JsonPatchRequest.java +++ b/src/main/java/unirest/JsonPatchRequest.java @@ -26,59 +26,18 @@ package unirest; -import org.apache.http.HttpEntity; -import org.apache.http.entity.BasicHttpEntity; +public interface JsonPatchRequest extends HttpRequest, Body { + String CONTENT_TYPE = "application/json-patch+json"; -import java.io.ByteArrayInputStream; + JsonPatchRequest add(String path, Object value); -public class JsonPatchRequest extends BaseRequest implements Body { - public static final String CONTENT_TYPE = "application/json-patch+json"; - private JsonPatch items = new JsonPatch(); + JsonPatchRequest remove(String path); - public JsonPatchRequest(Config config, String url) { - super(config, HttpMethod.PATCH, url); - header("Content-Type", CONTENT_TYPE); - } + JsonPatchRequest replace(String path, Object value); - public JsonPatchRequest add(String path, Object value) { - items.add(path, value); - return this; - } + JsonPatchRequest test(String path, Object value); - public JsonPatchRequest remove(String path) { - items.remove(path); - return this; - } + JsonPatchRequest move(String from, String path); - public JsonPatchRequest replace(String path, Object value) { - items.replace(path, value); - return this; - } - - public JsonPatchRequest test(String path, Object value) { - items.test(path, value); - return this; - } - - public JsonPatchRequest move(String from, String path) { - items.move(from, path); - return this; - } - - public JsonPatchRequest copy(String from, String path) { - items.copy(from, path); - return this; - } - - @Override - public Body getBody() { - return this; - } - - @Override - public HttpEntity getEntity() { - BasicHttpEntity e = new BasicHttpEntity(); - e.setContent(new ByteArrayInputStream(items.toString().getBytes())); - return e; - } -} \ No newline at end of file + JsonPatchRequest copy(String from, String path); +} diff --git a/src/main/java/unirest/UnirestInstance.java b/src/main/java/unirest/UnirestInstance.java index ff2b2276a..3b5044193 100644 --- a/src/main/java/unirest/UnirestInstance.java +++ b/src/main/java/unirest/UnirestInstance.java @@ -86,7 +86,7 @@ public HttpRequestWithBody put(String url) { } public JsonPatchRequest jsonPatch(String url) { - return new JsonPatchRequest(config, url); + return new HttpRequestJsonPatch(config, url); } public boolean isRunning() { From 27743b09a68d8103a1483760641864513c7cdde7 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 16 Nov 2018 10:03:19 -0600 Subject: [PATCH 0261/1769] all the implimentations are internal --- src/main/java/unirest/BaseRequest.java | 10 +++++----- src/main/java/unirest/HttpRequestBody.java | 2 +- src/main/java/unirest/HttpRequestJsonPatch.java | 4 ++-- src/main/java/unirest/HttpRequestMultiPart.java | 2 +- src/main/java/unirest/HttpRequestNoBody.java | 2 +- src/main/java/unirest/HttpRequestUniBody.java | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index b7664d470..805007385 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -40,17 +40,17 @@ import java.util.concurrent.CompletableFuture; import java.util.function.Function; -public abstract class BaseRequest implements HttpRequest { +abstract class BaseRequest implements HttpRequest { protected Body body; protected Headers headers = new Headers(); - protected final ResponseBuilder builder; protected final Config config; protected HttpMethod method; protected Path url; - protected HttpRequest httpRequest; + private HttpRequest httpRequest; + private final ResponseBuilder builder; - protected BaseRequest(BaseRequest httpRequest) { + BaseRequest(BaseRequest httpRequest) { this.config = httpRequest.config; this.httpRequest = httpRequest; this.builder = httpRequest.builder; @@ -60,7 +60,7 @@ protected BaseRequest(BaseRequest httpRequest) { this.body = httpRequest.body; } - protected BaseRequest(Config config, HttpMethod method, String url) { + BaseRequest(Config config, HttpMethod method, String url) { this.config = config; this.builder = new ResponseBuilder(config); this.method = method; diff --git a/src/main/java/unirest/HttpRequestBody.java b/src/main/java/unirest/HttpRequestBody.java index b663b42e6..162c0486a 100644 --- a/src/main/java/unirest/HttpRequestBody.java +++ b/src/main/java/unirest/HttpRequestBody.java @@ -38,7 +38,7 @@ import java.util.Map; import java.util.Map.Entry; -public class HttpRequestBody extends BaseRequest implements HttpRequestWithBody { +class HttpRequestBody extends BaseRequest implements HttpRequestWithBody { private Charset charSet = StandardCharsets.UTF_8; diff --git a/src/main/java/unirest/HttpRequestJsonPatch.java b/src/main/java/unirest/HttpRequestJsonPatch.java index 0dc866cd8..f0f5037a8 100644 --- a/src/main/java/unirest/HttpRequestJsonPatch.java +++ b/src/main/java/unirest/HttpRequestJsonPatch.java @@ -31,11 +31,11 @@ import java.io.ByteArrayInputStream; -public class HttpRequestJsonPatch extends BaseRequest implements JsonPatchRequest { +class HttpRequestJsonPatch extends BaseRequest implements JsonPatchRequest { private JsonPatch items = new JsonPatch(); - public HttpRequestJsonPatch(Config config, String url) { + HttpRequestJsonPatch(Config config, String url) { super(config, HttpMethod.PATCH, url); header("Content-Type", CONTENT_TYPE); } diff --git a/src/main/java/unirest/HttpRequestMultiPart.java b/src/main/java/unirest/HttpRequestMultiPart.java index 41b5db52d..36efe9b44 100644 --- a/src/main/java/unirest/HttpRequestMultiPart.java +++ b/src/main/java/unirest/HttpRequestMultiPart.java @@ -43,7 +43,7 @@ import java.util.Collections; import java.util.List; -public class HttpRequestMultiPart extends BaseRequest implements MultipartBody { +class HttpRequestMultiPart extends BaseRequest implements MultipartBody { private List parameters = new ArrayList<>(); private HttpRequestBody httpRequestObj; diff --git a/src/main/java/unirest/HttpRequestNoBody.java b/src/main/java/unirest/HttpRequestNoBody.java index 2ebed6481..c429c9661 100644 --- a/src/main/java/unirest/HttpRequestNoBody.java +++ b/src/main/java/unirest/HttpRequestNoBody.java @@ -26,7 +26,7 @@ package unirest; -public class HttpRequestNoBody extends BaseRequest implements GetRequest { +class HttpRequestNoBody extends BaseRequest implements GetRequest { public HttpRequestNoBody(Config config, HttpMethod method, String url) { super(config, method, url); } diff --git a/src/main/java/unirest/HttpRequestUniBody.java b/src/main/java/unirest/HttpRequestUniBody.java index f594fb869..0c1940970 100644 --- a/src/main/java/unirest/HttpRequestUniBody.java +++ b/src/main/java/unirest/HttpRequestUniBody.java @@ -34,7 +34,7 @@ import java.nio.charset.StandardCharsets; import java.util.function.Supplier; -public class HttpRequestUniBody extends BaseRequest implements RequestBodyEntity { +class HttpRequestUniBody extends BaseRequest implements RequestBodyEntity { private final HttpRequestBody request; private Supplier body = () -> new StringEntity("", StandardCharsets.UTF_8); From d3702343170974df6300dde77672b38a65214db2 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 16 Nov 2018 10:53:38 -0600 Subject: [PATCH 0262/1769] stop having a weird reference to self and bodies --- src/main/java/unirest/BaseRequest.java | 13 +++---- src/main/java/unirest/HttpRequestBody.java | 29 ++++----------- .../java/unirest/HttpRequestMultiPart.java | 35 ++++++------------- src/main/java/unirest/HttpRequestUniBody.java | 13 ++++--- src/main/java/unirest/MultipartBody.java | 3 -- src/main/java/unirest/RequestBodyEntity.java | 3 -- 6 files changed, 31 insertions(+), 65 deletions(-) diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 805007385..3a5f2dd6c 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -42,22 +42,18 @@ abstract class BaseRequest implements HttpRequest { - protected Body body; protected Headers headers = new Headers(); protected final Config config; protected HttpMethod method; protected Path url; - private HttpRequest httpRequest; private final ResponseBuilder builder; BaseRequest(BaseRequest httpRequest) { this.config = httpRequest.config; - this.httpRequest = httpRequest; this.builder = httpRequest.builder; this.method = httpRequest.method; this.url = httpRequest.url; this.headers.addAll(httpRequest.headers); - this.body = httpRequest.body; } BaseRequest(Config config, HttpMethod method, String url) { @@ -66,7 +62,6 @@ abstract class BaseRequest implements HttpRequest { this.method = method; this.url = new Path(url); headers.putAll(config.getDefaultHeaders()); - this.httpRequest = this; } @Override @@ -124,7 +119,7 @@ public R queryString(Map parameters) { @Override public HttpRequest getHttpRequest() { - return this.httpRequest; + return this; } @Override @@ -205,7 +200,7 @@ public CompletableFuture> asBinaryAsync(Callback HttpResponse request(Function> transformer) { - HttpRequestBase requestObj = new RequestPrep(httpRequest, false).prepare(); + HttpRequestBase requestObj = new RequestPrep(this, false).prepare(); HttpClient client = config.getClient(); try { @@ -237,7 +232,7 @@ private CompletableFuture> requestAsync( Objects.requireNonNull(callback); - HttpUriRequest requestObj = new RequestPrep(httpRequest, true).prepare(); + HttpUriRequest requestObj = new RequestPrep(this, true).prepare(); config.getAsyncHttpClient() .execute(requestObj, new FutureCallback() { @@ -277,6 +272,6 @@ public Headers getHeaders() { @Override public Body getBody() { - return body; + return null; } } diff --git a/src/main/java/unirest/HttpRequestBody.java b/src/main/java/unirest/HttpRequestBody.java index 162c0486a..098ca7698 100644 --- a/src/main/java/unirest/HttpRequestBody.java +++ b/src/main/java/unirest/HttpRequestBody.java @@ -48,9 +48,7 @@ public HttpRequestBody(Config config, HttpMethod method, String url) { @Override public MultipartBody field(String name, Collection value) { - MultipartBody body = new HttpRequestMultiPart(this).field(name, value); - this.body = body; - return body; + return new HttpRequestMultiPart(this).field(name, value); } @Override @@ -60,9 +58,7 @@ public MultipartBody field(String name, File file) { @Override public MultipartBody field(String name, File file, String contentType) { - MultipartBody body = new HttpRequestMultiPart(this).field(name, file, contentType); - this.body = body; - return body; + return new HttpRequestMultiPart(this).field(name, file, contentType); } @Override @@ -72,9 +68,7 @@ public MultipartBody field(String name, Object value) { @Override public MultipartBody field(String name, Object value, String contentType) { - MultipartBody body = new HttpRequestMultiPart(this).field(name, nullToEmpty(value), contentType); - this.body = body; - return body; + return new HttpRequestMultiPart(this).field(name, nullToEmpty(value), contentType); } @Override @@ -89,7 +83,6 @@ public MultipartBody fields(Map parameters) { } } } - this.body = body; return body; } @@ -102,16 +95,12 @@ private String nullToEmpty(Object v) { @Override public MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName) { - MultipartBody body = new HttpRequestMultiPart(this).field(name, stream, contentType, fileName); - this.body = body; - return body; + return new HttpRequestMultiPart(this).field(name, stream, contentType, fileName); } @Override public MultipartBody field(String name, InputStream stream, String fileName) { - MultipartBody body = field(name, stream, ContentType.APPLICATION_OCTET_STREAM, fileName); - this.body = body; - return body; + return field(name, stream, ContentType.APPLICATION_OCTET_STREAM, fileName); } @Override @@ -127,9 +116,7 @@ public RequestBodyEntity body(JsonNode body) { @Override public RequestBodyEntity body(String body) { - RequestBodyEntity b = new HttpRequestUniBody(this).body(body); - this.body = b; - return b; + return new HttpRequestUniBody(this).body(body); } @Override @@ -139,9 +126,7 @@ public RequestBodyEntity body(Object body) { @Override public RequestBodyEntity body(byte[] body) { - RequestBodyEntity b = new HttpRequestUniBody(this).body(body); - this.body = b; - return b; + return new HttpRequestUniBody(this).body(body); } /** diff --git a/src/main/java/unirest/HttpRequestMultiPart.java b/src/main/java/unirest/HttpRequestMultiPart.java index 36efe9b44..c46852a56 100644 --- a/src/main/java/unirest/HttpRequestMultiPart.java +++ b/src/main/java/unirest/HttpRequestMultiPart.java @@ -46,12 +46,12 @@ class HttpRequestMultiPart extends BaseRequest implements MultipartBody { private List parameters = new ArrayList<>(); - private HttpRequestBody httpRequestObj; private HttpMultipartMode mode = HttpMultipartMode.BROWSER_COMPATIBLE; + private Charset charSet; public HttpRequestMultiPart(HttpRequestBody httpRequest) { super(httpRequest); - this.httpRequestObj = httpRequest; + this.charSet = httpRequest.getCharset(); } @Override @@ -123,31 +123,13 @@ public MultipartBody field(String name, byte[] bytes, String fileName) { @Override public MultipartBody charset(Charset charset) { - httpRequestObj.charset(charset); + this.charSet = charset; return this; } @Override public MultipartBody contentType(String mimeType) { - httpRequestObj.header(HttpHeaders.CONTENT_TYPE, mimeType); - return this; - } - - @Override - public MultipartBody accept(String mimeType) { - httpRequestObj.accept(mimeType); - return this; - } - - @Override - public MultipartBody basicAuth(String username, String password) { - httpRequestObj.basicAuth(username, password); - return this; - } - - @Override - public MultipartBody header(String name, String value) { - httpRequestObj.header(name, value); + header(HttpHeaders.CONTENT_TYPE, mimeType); return this; } @@ -167,17 +149,22 @@ public MultipartBody mode(HttpMultipartMode value) { public HttpEntity getEntity() { if (parameters.stream().anyMatch(FormPart::isFile)) { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); - builder.setCharset(httpRequestObj.getCharset()); + builder.setCharset(charSet); builder.setMode(mode); for (FormPart key : parameters) { builder.addPart(key.getName(), key.toApachePart()); } return builder.build(); } else { - return new UrlEncodedFormEntity(MapUtil.getList(parameters), httpRequestObj.getCharset()); + return new UrlEncodedFormEntity(MapUtil.getList(parameters), charSet); } } + @Override + public Body getBody() { + return this; + } + private void addPart(String name, Object value, ContentType type) { parameters.add(new FormPart(name, value, type)); Collections.sort(parameters); diff --git a/src/main/java/unirest/HttpRequestUniBody.java b/src/main/java/unirest/HttpRequestUniBody.java index 0c1940970..8508b8590 100644 --- a/src/main/java/unirest/HttpRequestUniBody.java +++ b/src/main/java/unirest/HttpRequestUniBody.java @@ -36,12 +36,12 @@ class HttpRequestUniBody extends BaseRequest implements RequestBodyEntity { - private final HttpRequestBody request; private Supplier body = () -> new StringEntity("", StandardCharsets.UTF_8); + private Charset charSet; HttpRequestUniBody(HttpRequestBody httpRequest) { super(httpRequest); - request = httpRequest; + this.charSet = httpRequest.getCharset(); } @Override @@ -52,7 +52,7 @@ public RequestBodyEntity body(byte[] bodyBytes) { @Override public RequestBodyEntity body(String bodyAsString) { - this.body = () -> new StringEntity(bodyAsString, request.getCharset()); + this.body = () -> new StringEntity(bodyAsString, charSet); return this; } @@ -63,7 +63,7 @@ public RequestBodyEntity body(JsonNode jsonBody) { @Override public RequestBodyEntity charset(Charset charset) { - request.charset(charset); + this.charSet = charset; return this; } @@ -71,4 +71,9 @@ public RequestBodyEntity charset(Charset charset) { public HttpEntity getEntity() { return body.get(); } + + @Override + public Body getBody() { + return this; + } } diff --git a/src/main/java/unirest/MultipartBody.java b/src/main/java/unirest/MultipartBody.java index cc6b9e7fe..b24883e66 100644 --- a/src/main/java/unirest/MultipartBody.java +++ b/src/main/java/unirest/MultipartBody.java @@ -26,7 +26,6 @@ package unirest; -import org.apache.http.HttpEntity; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.HttpMultipartMode; @@ -63,6 +62,4 @@ public interface MultipartBody extends HttpRequest, Body { MultipartBody mode(String value); MultipartBody mode(HttpMultipartMode value); - - HttpEntity getEntity(); } diff --git a/src/main/java/unirest/RequestBodyEntity.java b/src/main/java/unirest/RequestBodyEntity.java index b032d1acd..6cd62bc03 100644 --- a/src/main/java/unirest/RequestBodyEntity.java +++ b/src/main/java/unirest/RequestBodyEntity.java @@ -26,8 +26,6 @@ package unirest; -import org.apache.http.HttpEntity; - import java.nio.charset.Charset; public interface RequestBodyEntity extends HttpRequest, Body { @@ -39,5 +37,4 @@ public interface RequestBodyEntity extends HttpRequest, Body RequestBodyEntity charset(Charset charset); - HttpEntity getEntity(); } From c93ef4a05918661ad731072ca57f1bf4c64202cc Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 16 Nov 2018 20:40:04 -0600 Subject: [PATCH 0263/1769] move map method down --- src/main/java/unirest/HttpRequestBody.java | 22 ++----------------- .../java/unirest/HttpRequestMultiPart.java | 20 +++++++++++++---- src/main/java/unirest/Util.java | 7 ++++++ 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/main/java/unirest/HttpRequestBody.java b/src/main/java/unirest/HttpRequestBody.java index 098ca7698..e691a938c 100644 --- a/src/main/java/unirest/HttpRequestBody.java +++ b/src/main/java/unirest/HttpRequestBody.java @@ -36,7 +36,6 @@ import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Map; -import java.util.Map.Entry; class HttpRequestBody extends BaseRequest implements HttpRequestWithBody { @@ -68,29 +67,12 @@ public MultipartBody field(String name, Object value) { @Override public MultipartBody field(String name, Object value, String contentType) { - return new HttpRequestMultiPart(this).field(name, nullToEmpty(value), contentType); + return new HttpRequestMultiPart(this).field(name, Util.nullToEmpty(value), contentType); } @Override public MultipartBody fields(Map parameters) { - HttpRequestMultiPart body = new HttpRequestMultiPart(this); - if (parameters != null) { - for (Entry param : parameters.entrySet()) { - if (param.getValue() instanceof File) { - body.field(param.getKey(), (File) param.getValue()); - } else { - body.field(param.getKey(), nullToEmpty(param.getValue())); - } - } - } - return body; - } - - private String nullToEmpty(Object v) { - if(v == null){ - return ""; - } - return v.toString(); + return new HttpRequestMultiPart(this).fields(parameters); } @Override diff --git a/src/main/java/unirest/HttpRequestMultiPart.java b/src/main/java/unirest/HttpRequestMultiPart.java index c46852a56..06eadf130 100644 --- a/src/main/java/unirest/HttpRequestMultiPart.java +++ b/src/main/java/unirest/HttpRequestMultiPart.java @@ -38,10 +38,9 @@ import java.io.File; import java.io.InputStream; import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import java.util.*; + +import static unirest.Util.nullToEmpty; class HttpRequestMultiPart extends BaseRequest implements MultipartBody { private List parameters = new ArrayList<>(); @@ -145,6 +144,19 @@ public MultipartBody mode(HttpMultipartMode value) { return this; } + public MultipartBody fields(Map fields) { + if (fields != null) { + for (Map.Entry param : fields.entrySet()) { + if (param.getValue() instanceof File) { + field(param.getKey(), (File) param.getValue()); + } else { + field(param.getKey(), nullToEmpty(param.getValue())); + } + } + } + return this; + } + @Override public HttpEntity getEntity() { if (parameters.stream().anyMatch(FormPart::isFile)) { diff --git a/src/main/java/unirest/Util.java b/src/main/java/unirest/Util.java index b9b23c030..423977d5c 100644 --- a/src/main/java/unirest/Util.java +++ b/src/main/java/unirest/Util.java @@ -62,6 +62,13 @@ static String nullToEmpty(String value) { return value; } + public static String nullToEmpty(Object v) { + if(v == null){ + return ""; + } + return v.toString(); + } + @FunctionalInterface public interface ExConsumer{ From ff51d3c3a1e833c55df94c84c9c18e1cb3bbe208 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 17 Nov 2018 09:53:12 -0600 Subject: [PATCH 0264/1769] add the ability to pass in a object mapper at any time and override the config --- src/main/java/unirest/BaseRequest.java | 96 +++++++++--- src/main/java/unirest/HttpRequest.java | 2 + src/main/java/unirest/ResponseBuilder.java | 95 ------------ src/test/java/BehaviorTests/AsObjectTest.java | 33 ++++ .../java/unirest/ResponseBuilderTest.java | 145 ------------------ 5 files changed, 109 insertions(+), 262 deletions(-) delete mode 100644 src/main/java/unirest/ResponseBuilder.java delete mode 100644 src/test/java/unirest/ResponseBuilderTest.java diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 3a5f2dd6c..ae9cbfe34 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -33,24 +33,23 @@ import org.apache.http.concurrent.FutureCallback; import java.io.InputStream; -import java.util.Base64; -import java.util.Collection; -import java.util.Map; -import java.util.Objects; +import java.io.UnsupportedEncodingException; +import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.function.Function; +import static unirest.BodyData.from; + abstract class BaseRequest implements HttpRequest { protected Headers headers = new Headers(); protected final Config config; protected HttpMethod method; protected Path url; - private final ResponseBuilder builder; + private Optional objectMapper = Optional.empty(); BaseRequest(BaseRequest httpRequest) { this.config = httpRequest.config; - this.builder = httpRequest.builder; this.method = httpRequest.method; this.url = httpRequest.url; this.headers.addAll(httpRequest.headers); @@ -58,7 +57,6 @@ abstract class BaseRequest implements HttpRequest { BaseRequest(Config config, HttpMethod method, String url) { this.config = config; - this.builder = new ResponseBuilder(config); this.method = method; this.url = new Path(url); headers.putAll(config.getDefaultHeaders()); @@ -117,6 +115,13 @@ public R queryString(Map parameters) { return (R)this; } + @Override + public R withObjectMapper(ObjectMapper mapper) { + Objects.requireNonNull(mapper, "ObjectMapper may not be null"); + this.objectMapper = Optional.of(mapper); + return (R)this; + } + @Override public HttpRequest getHttpRequest() { return this; @@ -124,77 +129,77 @@ public HttpRequest getHttpRequest() { @Override public HttpResponse asString() throws UnirestException { - return request(builder::asString); + return request(this::asString); } @Override public CompletableFuture> asStringAsync() { - return requestAsync(builder::asString); + return requestAsync(this::asString); } @Override public CompletableFuture> asStringAsync(Callback callback) { - return requestAsync(builder::asString, callback); + return requestAsync(this::asString, callback); } @Override public HttpResponse asJson() throws UnirestException { - return request(builder::asJson); + return request(this::asJson); } @Override public CompletableFuture> asJsonAsync() { - return requestAsync(builder::asJson); + return requestAsync(this::asJson); } @Override public CompletableFuture> asJsonAsync(Callback callback) { - return requestAsync(builder::asJson, callback); + return requestAsync(this::asJson, callback); } @Override public HttpResponse asObject(Class responseClass) throws UnirestException { - return request(r -> builder.asObject(r, responseClass)); + return request(r -> this.asObject(r, responseClass)); } @Override public HttpResponse asObject(GenericType genericType) throws UnirestException { - return request(r -> builder.asObject(r, genericType)); + return request(r -> this.asObject(r, genericType)); } @Override public CompletableFuture> asObjectAsync(Class responseClass) { - return requestAsync(r -> builder.asObject(r, responseClass)); + return requestAsync(r -> this.asObject(r, responseClass)); } @Override public CompletableFuture> asObjectAsync(Class responseClass, Callback callback) { - return requestAsync(r -> builder.asObject(r, responseClass), callback); + return requestAsync(r -> this.asObject(r, responseClass), callback); } @Override public CompletableFuture> asObjectAsync(GenericType genericType) { - return requestAsync(r -> builder.asObject(r, genericType)); + return requestAsync(r -> this.asObject(r, genericType)); } @Override public CompletableFuture> asObjectAsync(GenericType genericType, Callback callback) { - return requestAsync(r -> builder.asObject(r, genericType), callback); + return requestAsync(r -> this.asObject(r, genericType), callback); } @Override public HttpResponse asBinary() throws UnirestException { - return request(builder::asBinary); + return request(this::asBinary); } @Override public CompletableFuture> asBinaryAsync() { - return requestAsync(builder::asBinary); + return requestAsync(this::asBinary); } @Override public CompletableFuture> asBinaryAsync(Callback callback) { - return requestAsync(builder::asBinary, callback); + return requestAsync(this::asBinary, callback); } @@ -274,4 +279,51 @@ public Headers getHeaders() { public Body getBody() { return null; } + + private HttpResponse asJson(org.apache.http.HttpResponse response) { + return new HttpResponseImpl<>(response, from(response.getEntity(), b -> toJson(b))); + } + + private HttpResponse asBinary(org.apache.http.HttpResponse response){ + return new HttpResponseImpl<>(response, from(response.getEntity(), BodyData::getRawInput)); + } + + private HttpResponse asObject(org.apache.http.HttpResponse response, Class aClass) { + return new HttpResponseImpl<>(response, from(response.getEntity(), b -> toObject(b, aClass))); + } + + private HttpResponse asObject(org.apache.http.HttpResponse response, GenericType genericType) { + return new HttpResponseImpl<>(response, from(response.getEntity(), b -> toObject(b, genericType))); + } + + private HttpResponse asString(org.apache.http.HttpResponse response) { + return new HttpResponseImpl<>(response, from(response.getEntity(), this::toString)); + } + + private T toObject(BodyData b, GenericType genericType) { + ObjectMapper o = getObjectMapper(); + return o.readValue(toString(b), genericType); + } + + private T toObject(BodyData b, Class aClass) { + ObjectMapper o = getObjectMapper(); + return o.readValue(toString(b), aClass); + } + + private String toString(BodyData b) { + try { + return new String(b.getRawBytes(), b.getCharset()); + } catch (UnsupportedEncodingException e) { + throw new UnirestException(e); + } + } + + private JsonNode toJson(BodyData b) { + String jsonString = toString(b); + return new JsonNode(jsonString); + } + + private ObjectMapper getObjectMapper() { + return objectMapper.orElseGet(config::getObjectMapper); + } } diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index d36132984..5f8028ec6 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -48,6 +48,8 @@ public interface HttpRequest { R queryString(Map parameters); + R withObjectMapper(ObjectMapper mapper); + HttpRequest getHttpRequest(); HttpResponse asString() throws UnirestException; diff --git a/src/main/java/unirest/ResponseBuilder.java b/src/main/java/unirest/ResponseBuilder.java deleted file mode 100644 index f9b082c01..000000000 --- a/src/main/java/unirest/ResponseBuilder.java +++ /dev/null @@ -1,95 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package unirest; - -import java.io.InputStream; -import java.io.UnsupportedEncodingException; - -import static unirest.BodyData.from; - - -class ResponseBuilder { - - private final Config config; - - public ResponseBuilder(Config config) { - this.config = config; - } - - public HttpResponse asJson(org.apache.http.HttpResponse response) { - return new HttpResponseImpl<>(response, from(response.getEntity(), b -> toJson(b))); - } - - public HttpResponse asBinary(org.apache.http.HttpResponse response){ - return new HttpResponseImpl<>(response, from(response.getEntity(), BodyData::getRawInput)); - } - - public HttpResponse asObject(org.apache.http.HttpResponse response, Class aClass) { - return new HttpResponseImpl<>(response, from(response.getEntity(), b -> toObject(b, aClass))); - } - - public HttpResponse asObject(org.apache.http.HttpResponse response, GenericType genericType) { - return new HttpResponseImpl<>(response, from(response.getEntity(), b -> toObject(b, genericType))); - } - - public HttpResponse asString(org.apache.http.HttpResponse response) { - return new HttpResponseImpl<>(response, from(response.getEntity(), this::toString)); - } - - private T toObject(BodyData b, GenericType genericType) { - ObjectMapper o = getObjectMapper(); - return o.readValue(toString(b), genericType); - } - - private T toObject(BodyData b, Class aClass) { - ObjectMapper o = getObjectMapper(); - return o.readValue(toString(b), aClass); - } - - private String toString(BodyData b) { - try { - return new String(b.getRawBytes(), b.getCharset()); - } catch (UnsupportedEncodingException e) { - throw new ParsingException(e); - } - } - - private JsonNode toJson(BodyData b) { - String jsonString = toString(b); - return new JsonNode(jsonString); - } - - private ObjectMapper getObjectMapper() { - return config.getObjectMapper(); - } - - public static class ParsingException extends RuntimeException { - public ParsingException(Exception e){ - super(e); - } - } -} diff --git a/src/test/java/BehaviorTests/AsObjectTest.java b/src/test/java/BehaviorTests/AsObjectTest.java index 7fc18bee3..ef626af6c 100644 --- a/src/test/java/BehaviorTests/AsObjectTest.java +++ b/src/test/java/BehaviorTests/AsObjectTest.java @@ -26,9 +26,14 @@ package BehaviorTests; +import com.google.gson.Gson; +import unirest.JacksonObjectMapper; +import unirest.ObjectMapper; import unirest.Unirest; import org.junit.Test; +import static junit.framework.TestCase.assertTrue; + public class AsObjectTest extends BddTest { @Test public void canGetObjectResponse() { @@ -61,4 +66,32 @@ public void canGetObjectResponseAsyncWithCallback() { assertAsync(); } + + @Test + public void canPassAnObjectMapperAsPartOfARequest(){ + TestingMapper mapper = new TestingMapper(); + Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .withObjectMapper(mapper) + .asObject(RequestCapture.class) + .getBody() + .assertParam("foo", "bar"); + + assertTrue(mapper.wasCalled); + } + + public static class TestingMapper implements ObjectMapper { + public boolean wasCalled; + + @Override + public T readValue(String value, Class valueType) { + this.wasCalled = true; + return new JacksonObjectMapper().readValue(value, valueType); + } + + @Override + public String writeValue(Object value) { + return new Gson().toJson(value); + } + } } diff --git a/src/test/java/unirest/ResponseBuilderTest.java b/src/test/java/unirest/ResponseBuilderTest.java deleted file mode 100644 index 04472f774..000000000 --- a/src/test/java/unirest/ResponseBuilderTest.java +++ /dev/null @@ -1,145 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package unirest; - -import BehaviorTests.Foo; -import org.apache.http.ProtocolVersion; -import org.apache.http.message.BasicStatusLine; -import org.junit.Before; -import org.junit.Test; - -import java.io.InputStream; - -import static org.hamcrest.CoreMatchers.hasItem; -import static org.junit.Assert.*; -import static unirest.TestUtil.assertException; -import static unirest.TestUtil.toJson; - -public class ResponseBuilderTest { - private Config config; - private ResponseBuilder builder; - private MockApacheResponse response; - - @Before - public void setUp() { - response = new MockApacheResponse(); - config = new Config().setObjectMapper(new JacksonObjectMapper()); - builder = new ResponseBuilder(config); - } - - @Test - public void willStartOffWithHeaders() { - response.addHeader("foo", "bar"); - response.addHeader("foo", "baz"); - response.addHeader("qux", "zip"); - - HttpResponse r = builder.asBinary(response); - - assertThat(r.getHeaders().get("foo"), hasItem("bar")); - assertThat(r.getHeaders().get("qux"), hasItem("zip")); - } - - @Test - public void willPassInStatusCode() { - response.setStatusLine(new BasicStatusLine(new ProtocolVersion("http", 1, 2), - 418, "I am a teapot")); - - HttpResponse r = builder.asBinary(response); - - assertEquals(418, r.getStatus()); - assertEquals("I am a teapot", r.getStatusText()); - } - - @Test - public void canGetBinaryResponse() { - response.setBody("I like cheese"); - - HttpResponse r = builder.asBinary(response); - - assertEquals("I like cheese", TestUtil.toString(r.getBody())); - } - - @Test - public void canGetObjectMappedResponse() { - response.setBody(toJson(new Foo("I like cheese"))); - - HttpResponse r = builder.asObject(response, Foo.class); - - assertEquals("I like cheese", r.getBody().bar); - } - - @Test - public void willThrowErrorIfNoObjectMapperIsConfigured(){ - config.setObjectMapper(null); - - response.setBody(toJson(new Foo("I like cheese"))); - - assertException(() -> builder.asObject(response, Foo.class), - UnirestException.class, - "No Object Mapper Configured. Please config one with Unirest.config().setObjectMapper"); - } - - @Test - public void ifObjectMapperHasProblemParsingReturnTheError(){ - response.setBody("I like cheese"); - - HttpResponse foo = builder.asObject(response, Foo.class); - - assertEquals("com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'I': was expecting 'null', 'true', 'false' or NaN\n" + - " at [Source: (String)\"I like cheese\"; line: 1, column: 2]", - foo.getParsingError().get().getMessage()); - } - - @Test - public void canGetStringResponse() { - response.setBody("I like cheese"); - - HttpResponse r = builder.asString(response); - - assertEquals("I like cheese", r.getBody()); - } - - @Test - public void canGetJsonResponse() { - response.setBody("{\"foo\": \"I like cheese\"}"); - - HttpResponse r = builder.asJson(response); - - assertEquals("I like cheese", r.getBody().getObject().get("foo")); - } - - @Test - public void willNotBlowUpOnError() { - response.setBody("I like cheese"); - - HttpResponse r = builder.asJson(response); - - assertNull(r.getBody()); - assertEquals("org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]", - r.getParsingError().get().getMessage()); - } -} \ No newline at end of file From 2280171d787278e3b6d6d2004eae00b5be1a37d8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 17 Nov 2018 10:01:34 -0600 Subject: [PATCH 0265/1769] just a little clean up --- src/main/java/unirest/BaseRequest.java | 38 ++++++++------------------ src/main/java/unirest/Path.java | 7 +++++ 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index ae9cbfe34..bf7d716fd 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -42,11 +42,11 @@ abstract class BaseRequest implements HttpRequest { + private Optional objectMapper = Optional.empty(); protected Headers headers = new Headers(); protected final Config config; protected HttpMethod method; protected Path url; - private Optional objectMapper = Optional.empty(); BaseRequest(BaseRequest httpRequest) { this.config = httpRequest.config; @@ -97,9 +97,7 @@ public R headers(Map headerMap) { @Override public R queryString(String name, Collection value) { - for (Object cur : value) { - queryString(name, cur); - } + url.queryString(name, value); return (R)this; } @@ -134,12 +132,12 @@ public HttpResponse asString() throws UnirestException { @Override public CompletableFuture> asStringAsync() { - return requestAsync(this::asString); + return requestAsync(this::asString, new CompletableFuture<>()); } @Override public CompletableFuture> asStringAsync(Callback callback) { - return requestAsync(this::asString, callback); + return requestAsync(this::asString, CallbackFuture.wrap(callback)); } @Override @@ -149,12 +147,12 @@ public HttpResponse asJson() throws UnirestException { @Override public CompletableFuture> asJsonAsync() { - return requestAsync(this::asJson); + return requestAsync(this::asJson, new CompletableFuture<>()); } @Override public CompletableFuture> asJsonAsync(Callback callback) { - return requestAsync(this::asJson, callback); + return requestAsync(this::asJson, CallbackFuture.wrap(callback)); } @Override @@ -169,22 +167,22 @@ public HttpResponse asObject(GenericType genericType) throws UnirestEx @Override public CompletableFuture> asObjectAsync(Class responseClass) { - return requestAsync(r -> this.asObject(r, responseClass)); + return requestAsync(r -> this.asObject(r, responseClass), new CompletableFuture<>()); } @Override public CompletableFuture> asObjectAsync(Class responseClass, Callback callback) { - return requestAsync(r -> this.asObject(r, responseClass), callback); + return requestAsync(r -> this.asObject(r, responseClass), CallbackFuture.wrap(callback)); } @Override public CompletableFuture> asObjectAsync(GenericType genericType) { - return requestAsync(r -> this.asObject(r, genericType)); + return requestAsync(r -> this.asObject(r, genericType), new CompletableFuture<>()); } @Override public CompletableFuture> asObjectAsync(GenericType genericType, Callback callback) { - return requestAsync(r -> this.asObject(r, genericType), callback); + return requestAsync(r -> this.asObject(r, genericType), CallbackFuture.wrap(callback)); } @Override @@ -194,15 +192,14 @@ public HttpResponse asBinary() throws UnirestException { @Override public CompletableFuture> asBinaryAsync() { - return requestAsync(this::asBinary); + return requestAsync(this::asBinary, new CompletableFuture<>()); } @Override public CompletableFuture> asBinaryAsync(Callback callback) { - return requestAsync(this::asBinary, callback); + return requestAsync(this::asBinary, CallbackFuture.wrap(callback)); } - private HttpResponse request(Function> transformer) { HttpRequestBase requestObj = new RequestPrep(this, false).prepare(); @@ -220,17 +217,6 @@ private HttpResponse request(Function CompletableFuture> requestAsync( - Function> transformer) { - return requestAsync(transformer, new CompletableFuture<>()); - } - - private CompletableFuture> requestAsync( - Function> transformer, - Callback callback) { - return requestAsync(transformer, CallbackFuture.wrap(callback)); - } - private CompletableFuture> requestAsync( Function> transformer, CompletableFuture> callback) { diff --git a/src/main/java/unirest/Path.java b/src/main/java/unirest/Path.java index c6079b14a..5c1e7fa2f 100644 --- a/src/main/java/unirest/Path.java +++ b/src/main/java/unirest/Path.java @@ -28,6 +28,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.util.Collection; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -51,6 +52,12 @@ public void param(String name, String value) { this.url = url.replaceAll("\\{" + name + "\\}", URLParamEncoder.encode(value)); } + public void queryString(String name, Collection value){ + for (Object cur : value) { + queryString(name, cur); + } + } + public void queryString(String name, Object value) { StringBuilder queryString = new StringBuilder(); if (url.contains("?")) { From af5cf79dd9063f65ab10930db1920d5c16f2d9cd Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 17 Nov 2018 15:14:48 -0600 Subject: [PATCH 0266/1769] clean up utils --- src/main/java/unirest/Headers.java | 4 +- src/main/java/unirest/HttpDeleteWithBody.java | 11 +---- src/main/java/unirest/HttpPatchWithBody.java | 13 +----- .../java/unirest/HttpRequestMultiPart.java | 2 +- src/main/java/unirest/MapUtil.java | 44 ------------------- src/main/java/unirest/Path.java | 2 +- src/main/java/unirest/URLParamEncoder.java | 40 ----------------- src/main/java/unirest/Util.java | 31 +++++++++---- 8 files changed, 30 insertions(+), 117 deletions(-) delete mode 100644 src/main/java/unirest/MapUtil.java delete mode 100644 src/main/java/unirest/URLParamEncoder.java diff --git a/src/main/java/unirest/Headers.java b/src/main/java/unirest/Headers.java index b0c88cbfe..dd7c73c6d 100644 --- a/src/main/java/unirest/Headers.java +++ b/src/main/java/unirest/Headers.java @@ -32,6 +32,8 @@ import java.util.*; import java.util.stream.Stream; +import static unirest.Util.nullToEmpty; + public class Headers extends TreeMap> { private static final long serialVersionUID = 71310341388734766L; @@ -55,7 +57,7 @@ public String getFirst(Object key) { public void add(String name, String value) { if(Objects.nonNull(name)){ - computeIfAbsent(name, k -> new ArrayList<>()).add(Util.nullToEmpty(value)); + computeIfAbsent(name, k -> new ArrayList<>()).add(nullToEmpty(value)); } } diff --git a/src/main/java/unirest/HttpDeleteWithBody.java b/src/main/java/unirest/HttpDeleteWithBody.java index ef5e6c96c..01a7c9950 100644 --- a/src/main/java/unirest/HttpDeleteWithBody.java +++ b/src/main/java/unirest/HttpDeleteWithBody.java @@ -30,7 +30,7 @@ import java.net.URI; -public class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase { +class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase { public static final String METHOD_NAME = "DELETE"; public String getMethod() { @@ -41,13 +41,4 @@ public HttpDeleteWithBody(final String uri) { super(); setURI(URI.create(uri)); } - - public HttpDeleteWithBody(final URI uri) { - super(); - setURI(uri); - } - - public HttpDeleteWithBody() { - super(); - } } diff --git a/src/main/java/unirest/HttpPatchWithBody.java b/src/main/java/unirest/HttpPatchWithBody.java index 810c8fa3b..8ae807a74 100644 --- a/src/main/java/unirest/HttpPatchWithBody.java +++ b/src/main/java/unirest/HttpPatchWithBody.java @@ -31,23 +31,14 @@ import java.net.URI; class HttpPatchWithBody extends HttpEntityEnclosingRequestBase { - public static final String METHOD_NAME = "PATCH"; + private static final String METHOD_NAME = "PATCH"; public String getMethod() { return METHOD_NAME; } - public HttpPatchWithBody(final String uri) { + HttpPatchWithBody(final String uri) { super(); setURI(URI.create(uri)); } - - public HttpPatchWithBody(final URI uri) { - super(); - setURI(uri); - } - - public HttpPatchWithBody() { - super(); - } } diff --git a/src/main/java/unirest/HttpRequestMultiPart.java b/src/main/java/unirest/HttpRequestMultiPart.java index 06eadf130..7d07c7108 100644 --- a/src/main/java/unirest/HttpRequestMultiPart.java +++ b/src/main/java/unirest/HttpRequestMultiPart.java @@ -168,7 +168,7 @@ public HttpEntity getEntity() { } return builder.build(); } else { - return new UrlEncodedFormEntity(MapUtil.getList(parameters), charSet); + return new UrlEncodedFormEntity(Util.getList(parameters), charSet); } } diff --git a/src/main/java/unirest/MapUtil.java b/src/main/java/unirest/MapUtil.java deleted file mode 100644 index c126cee7b..000000000 --- a/src/main/java/unirest/MapUtil.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package unirest; - -import org.apache.http.NameValuePair; -import org.apache.http.message.BasicNameValuePair; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -class MapUtil { - static List getList(Collection parameters) { - List result = new ArrayList<>(); - for (FormPart entry : parameters) { - result.add(new BasicNameValuePair(entry.getName(), entry.getValue().toString())); - } - return result; - } -} diff --git a/src/main/java/unirest/Path.java b/src/main/java/unirest/Path.java index 5c1e7fa2f..8edfa1805 100644 --- a/src/main/java/unirest/Path.java +++ b/src/main/java/unirest/Path.java @@ -49,7 +49,7 @@ public void param(String name, String value) { if (count == 0) { throw new UnirestException("Can't find route parameter name \"" + name + "\""); } - this.url = url.replaceAll("\\{" + name + "\\}", URLParamEncoder.encode(value)); + this.url = url.replaceAll("\\{" + name + "\\}", Util.encode(value)); } public void queryString(String name, Collection value){ diff --git a/src/main/java/unirest/URLParamEncoder.java b/src/main/java/unirest/URLParamEncoder.java deleted file mode 100644 index 98376e338..000000000 --- a/src/main/java/unirest/URLParamEncoder.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package unirest; - -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; - -class URLParamEncoder { - static String encode(String input) { - try { - return URLEncoder.encode(input, "UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new UnirestException(e); - } - } -} diff --git a/src/main/java/unirest/Util.java b/src/main/java/unirest/Util.java index 423977d5c..795d34895 100644 --- a/src/main/java/unirest/Util.java +++ b/src/main/java/unirest/Util.java @@ -26,8 +26,12 @@ package unirest; -import java.util.Objects; -import java.util.Optional; +import org.apache.http.NameValuePair; +import org.apache.http.message.BasicNameValuePair; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.*; import java.util.stream.Stream; class Util { @@ -55,18 +59,27 @@ static Optional tryDo(T c, ExConsumer consumer) { } } - static String nullToEmpty(String value) { - if(value == null){ + static String nullToEmpty(Object v) { + if(v == null){ return ""; } - return value; + return String.valueOf(v); } - public static String nullToEmpty(Object v) { - if(v == null){ - return ""; + static String encode(String input) { + try { + return URLEncoder.encode(input, "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new UnirestException(e); + } + } + + static List getList(Collection parameters) { + List result = new ArrayList<>(); + for (FormPart entry : parameters) { + result.add(new BasicNameValuePair(entry.getName(), entry.getValue().toString())); } - return v.toString(); + return result; } From 007b37dfa297cf3b6de61bde34ec5e59a76f635a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 17 Nov 2018 17:23:33 -0600 Subject: [PATCH 0267/1769] allow the resetting of a config in order to change client aspects --- src/main/java/unirest/Config.java | 24 +++++++++++++++--------- src/test/java/unirest/ConfigTest.java | 17 +++++++++++++++++ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java index 62ab5ca5b..5b67d2040 100644 --- a/src/main/java/unirest/Config.java +++ b/src/main/java/unirest/Config.java @@ -120,6 +120,7 @@ public Config asyncClient(AsyncConfig value) { * @param value Proxy settings object. */ public Config proxy(HttpHost value) { + validateClientsNotRunning(); this.proxy = value; return this; } @@ -140,7 +141,7 @@ public Config setObjectMapper(ObjectMapper om) { * @param inMillies The timeout until a connection with the server is established (in milliseconds). Default is 10000. Set to zero to disable the timeout. */ public Config connectTimeout(int inMillies) { - validateNotCustomClient(); + validateClientsNotRunning(); this.connectionTimeout = inMillies; return this; } @@ -151,7 +152,7 @@ public Config connectTimeout(int inMillies) { * @param inMillies The timeout to receive data (in milliseconds). Default is 60000. Set to zero to disable the timeout. */ public Config socketTimeout(int inMillies) { - validateNotCustomClient(); + validateClientsNotRunning(); this.socketTimeout = inMillies; return this; } @@ -163,7 +164,7 @@ public Config socketTimeout(int inMillies) { * @param perRoute Defines a connection limit per one HTTP route (this can be considered a per target host limit). Default is 20. */ public Config concurrency(int total, int perRoute) { - validateNotCustomClient(); + validateClientsNotRunning(); this.maxTotal = total; this.maxPerRoute = perRoute; return this; @@ -195,7 +196,7 @@ public Config setDefaultHeader(String name, String value) { * @param interceptor The addInterceptor */ public Config addInterceptor(HttpRequestInterceptor interceptor) { - validateNotCustomClient(); + validateClientsNotRunning(); interceptors.add(interceptor); return this; } @@ -206,7 +207,7 @@ public Config addInterceptor(HttpRequestInterceptor interceptor) { * @param enable The name of the header. */ public Config followRedirects(boolean enable) { - validateNotCustomClient(); + validateClientsNotRunning(); this.followRedirects = enable; return this; } @@ -217,7 +218,7 @@ public Config followRedirects(boolean enable) { * @param enable The name of the header. */ public Config enableCookieManagement(boolean enable) { - validateNotCustomClient(); + validateClientsNotRunning(); this.cookieManagement = enable; return this; } @@ -269,11 +270,11 @@ ObjectMapper getObjectMapper() { return objectMapper.orElseThrow(() -> new UnirestException("No Object Mapper Configured. Please config one with Unirest.config().setObjectMapper")); } - private void validateNotCustomClient() { + private void validateClientsNotRunning() { if (client.isPresent() || asyncClient.isPresent()) { throw new UnirestConfigException( - "You can't set custom client settings when providing custom client implementations. " + - "Set the timeouts directly in your custom client configuration instead." + "Http Clients are already build in order to build a new config execute Unirest.config().reset() before changing settings. \n" + + "This should be done rarely." ); } } @@ -318,4 +319,9 @@ public boolean isRunning() { public static Stream collectExceptions(Optional... ex) { return Stream.of(ex).flatMap(Util::stream); } + + public Config reset() { + shutDown(false); + return this; + } } diff --git a/src/test/java/unirest/ConfigTest.java b/src/test/java/unirest/ConfigTest.java index ea8c8501e..d2461a0fe 100644 --- a/src/test/java/unirest/ConfigTest.java +++ b/src/test/java/unirest/ConfigTest.java @@ -26,12 +26,15 @@ package unirest; +import org.apache.http.client.HttpClient; +import org.apache.http.nio.client.HttpAsyncClient; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.runners.MockitoJUnitRunner; import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; @RunWith(MockitoJUnitRunner.class) public class ConfigTest { @@ -58,4 +61,18 @@ public void shouldKeepMaxTotalDefault(){ public void shouldKeepMaxPerRouteDefault(){ assertEquals(Config.DEFAULT_MAX_PER_ROUTE, config.getMaxPerRoutes()); } + + @Test + public void onceTheConfigIsRunningYouCannotChangeConfig(){ + config.httpClient(mock(HttpClient.class)); + config.asyncClient(mock(HttpAsyncClient.class)); + + TestUtil.assertException(() -> config.socketTimeout(533), + UnirestConfigException.class, + "Http Clients are already build in order to build a new config execute Unirest.config().reset() " + + "before changing settings. \n" + + "This should be done rarely."); + + config.reset().socketTimeout(533); + } } \ No newline at end of file From 6c6779fa0b17b7382e05def87a244ccf39cd69e2 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 17 Nov 2018 17:39:52 -0600 Subject: [PATCH 0268/1769] add 3.0 section to changelog --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 743588a74..7dedad707 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +## 3.0.0 +* This is a **major** release with several **breaking changes** which (other than the namespace change) should ONLY impact you if you are using some of Unirests more advanced features or custom configurations. +* The namespace has been shortened to just **unirest** (inspired by Java Spark) +* The configuration system has been completely redone. Previously it was scattered across several classes and was entirely static. The new system has instances and supports multiple configurations. See the UPGRADE_GUIDE.md for details. + * Start accessing the config with ```Unirest.config()``` +* Almost everything is now fronted by interfaces, this makes testing easier. +* Unirest itself can now be accessed as a interface with UnirestInstance +* ObjectMappers can be passed in as part of the builder. +* option no longer supports body (per http spec) +* Accept and ContentType are now 1st class headers in the builder (```Unirest.get(path).accept("application/json")```) +* Major internal fixes so that which builder operations were available when is consistent. + ## 2.5.01 * Fix Issue #41: possible init error in HttpClient under heavy load From 57769dd514434a8a440de687ac1bd895feede8ad Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 18 Nov 2018 07:53:06 -0600 Subject: [PATCH 0269/1769] update config --- UPGRADE_GUIDE.md | 61 +++++++++++++++++++ src/main/java/unirest/Unirest.java | 6 +- .../java/BehaviorTests/LifeCycleTest.java | 4 +- src/test/java/unirest/ConfigTest.java | 3 +- 4 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 UPGRADE_GUIDE.md diff --git a/UPGRADE_GUIDE.md b/UPGRADE_GUIDE.md new file mode 100644 index 000000000..2caa62085 --- /dev/null +++ b/UPGRADE_GUIDE.md @@ -0,0 +1,61 @@ +## Upgrading to Open Uirest 3.0 from previous versions + +### Package +Inspired by the "Java Spark" project, all classes are now in the ```unirest``` package. This project only has 45 files, it really doesn't need anything more complicated than that. + +### Configuration +Previous versions of unirest had configuration split across several different places. Sometimes it was done on ```Unirest```, sometimes it was done on ```Option```, sometimes it was somewhere else. +All configuration is now done through ```Unirest.config()``` + +#### Unirest.config() +Unirest config allows easy access to build a configuration just like you would build a request: + +```java + Unirest.config() + .socketTimeout(500) + .connectTimeout(1000) + .concurrency(10, 5) + .proxy(new HttpHost("https://proxy")) + .setDefaultHeader("Accept", "application/json") + .followRedirects(false) + .enableCookieManagement(false) + .addInterceptor(new MyCustomInterceptor()); +``` + +##### Changing the config +Changing Unirest's config should ideally be done once, or rarely. There are several background threads spawned by both Unirest itself and Apache HttpAsyncClient. Once Unirest has been activated configuration options that are involved in creating the client cannot be changed without an explicit shutdown or reset. + +```Java + Unirest.config() + .reset() + .connectTimeout(5000) +``` + +##### Setting custom Apache Client +You can set your own custom Apache HttpClient and HttpAsyncClient. Note that Unirest settings like timeouts or interceptors are not applied to custom clients. + +```java + Unirest.config() + .httpClient(myClient) + .asyncClient(myAsyncClient) +``` + +#### Multiple Configuration Instances +As usual, Unirest maintains a primary single instance. Sometimes you might want different configurations for different systems. You might also want an instance rather than a static context for testing purposes. + +```java + + // this returns the same instance used by Unirest.get("http://somewhere/") + UnirestInstance unirest = Unirest.primaryInstance(); + // It can be configured and used just like the static context + unirest.config().connectTimeout(5000); + String result = unirest.get("http://foo").asString().getBody(); + + // You can also get a whole new instance + UnirestInstance unirest = Unirest.spawnInstance(); +``` + +**WARNING!** If you get a new instance of unirest YOU are responsible for shutting it down when the JVM shuts down. It is not tracked or shut down by ```Unirest.shutDown();``` + + + diff --git a/src/main/java/unirest/Unirest.java b/src/main/java/unirest/Unirest.java index a828d9fdb..1ab979e75 100644 --- a/src/main/java/unirest/Unirest.java +++ b/src/main/java/unirest/Unirest.java @@ -89,7 +89,11 @@ public static boolean isRunning() { return primaryInstance.isRunning(); } - public static UnirestInstance getInstance() { + public static UnirestInstance spawnInstance() { + return new UnirestInstance(new Config()); + } + + public static UnirestInstance primaryInstance() { return primaryInstance; } } diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index 044fa3f89..42dda0c99 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -152,6 +152,8 @@ public void willReinitIfLibraryIsUsedAfterShutdown() { @Test public void canGetTheCommonInstanceOfUnirest(){ - assertSame(Unirest.getInstance(), Unirest.getInstance()); + assertSame(Unirest.primaryInstance(), Unirest.primaryInstance()); + assertNotSame(Unirest.primaryInstance(), Unirest.spawnInstance()); + assertNotSame(Unirest.spawnInstance(), Unirest.spawnInstance()); } } diff --git a/src/test/java/unirest/ConfigTest.java b/src/test/java/unirest/ConfigTest.java index d2461a0fe..9fdc12788 100644 --- a/src/test/java/unirest/ConfigTest.java +++ b/src/test/java/unirest/ConfigTest.java @@ -26,6 +26,7 @@ package unirest; +import org.apache.http.HttpHost; import org.apache.http.client.HttpClient; import org.apache.http.nio.client.HttpAsyncClient; import org.junit.Test; @@ -73,6 +74,6 @@ public void onceTheConfigIsRunningYouCannotChangeConfig(){ "before changing settings. \n" + "This should be done rarely."); - config.reset().socketTimeout(533); + Unirest.shutDown(); } } \ No newline at end of file From ab592cfc1cb37614a95a792616a3bd9562d5d6a6 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 18 Nov 2018 17:25:27 -0600 Subject: [PATCH 0270/1769] update readme --- README.md | 74 +++++++++++++++++++------------------------------------ 1 file changed, 26 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 741e4986b..25ad5ddac 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,9 @@ [![DepShield Badge](https://depshield.sonatype.org/badges/OpenUnirest/unirest-java/depshield.svg)](https://depshield.github.io) ## About This Repository -This repo is an updated, maintained, and independenct fork of the original Mashape/Kong Unirest-Java project. That project is no longer being maintained so this project was set up to keep it alive. - -There are several such forks in the world. The guiding principals of this project is: - * ***Maintain backwards compatibity whenever possible with the original project***: Other than a namespace change your code should work exactly like it did before for the vast majority of use cases. - * ***Security Patches are a Top Priority!*** - * ***Move the project forward into modern Java***: This project does require Java 8 as a minimum. - +This repo is an updated, maintained, and independent fork of the original Mashape/Kong Unirest-Java project. That project is no longer being maintained so this project was set up to keep it alive. +##### See the [UPGRADE_GUIDE](UPGRADE_GUIDE.md) for differences between this library and last kong release. ## Install With [Maven](https://mvnrepository.com/artifact/io.github.openunirest/unirest-java) ``` @@ -92,7 +87,7 @@ For example, serializing Json from\to Object using the popular Jackson ObjectMap ```java // Only one time -Unirest.setObjectMapper(new JacksonObjectMapper()); +Unirest.config().setObjectMapper(new JacksonObjectMapper()); // Response to Object Book book = Unirest.get("http://httpbin.org/books/1") @@ -191,60 +186,43 @@ Authenticating the request with basic authentication can be done by calling the .asJson(); ``` -# Advanced Configuration - -You can set some advanced configuration to tune Unirest-Java: -### Custom HTTP clients -You can explicitly set your own `HttpClient` and `HttpAsyncClient` implementations by using the following methods: +##### Changing the config +Changing Unirest's config should ideally be done once, or rarely. There are several background threads spawned by both Unirest itself and Apache HttpAsyncClient. Once Unirest has been activated configuration options that are involved in creating the client cannot be changed without an explicit shutdown or reset. -```java -Unirest.setHttpClient(httpClient); -Unirest.setAsyncHttpClient(asyncHttpClient); +```Java + Unirest.config() + .reset() + .connectTimeout(5000) ``` -### Timeouts - -You can set custom connection and socket timeout values (in **milliseconds**): - -```java -Unirest.setTimeouts(long connectionTimeout, long socketTimeout); -``` - -By default the connection timeout (the time it takes to connect to a server) is `10000`, and the socket timeout (the time it takes to receive data) is `60000`. You can set any of these timeouts to zero to disable the timeout. -### Default Request Headers - -You can set default headers that will be sent on every request: +##### Setting custom Apache Client +You can set your own custom Apache HttpClient and HttpAsyncClient. Note that Unirest settings like timeouts or interceptors are not applied to custom clients. ```java -Unirest.setDefaultHeader("Header1", "Value1"); -Unirest.setDefaultHeader("Header2", "Value2"); + Unirest.config() + .httpClient(myClient) + .asyncClient(myAsyncClient) ``` -You can clear the default headers anytime with: +#### Multiple Configuration Instances +As usual, Unirest maintains a primary single instance. Sometimes you might want different configurations for different systems. You might also want an instance rather than a static context for testing purposes. ```java -Unirest.clearDefaultHeaders(); -``` - -### Concurrency -You can set custom concurrency levels if you need to tune the performance of the syncronous or asyncronous client: - -```java -Unirest.setConcurrency(int maxTotal, int maxPerRoute); + // this returns the same instance used by Unirest.get("http://somewhere/") + UnirestInstance unirest = Unirest.primaryInstance(); + // It can be configured and used just like the static context + unirest.config().connectTimeout(5000); + String result = unirest.get("http://foo").asString().getBody(); + + // You can also get a whole new instance + UnirestInstance unirest = Unirest.spawnInstance(); ``` -By default the maxTotal (overall connection limit in the pool) is `200`, and the maxPerRoute (connection limit per target host) is `20`. +**WARNING!** If you get a new instance of unirest YOU are responsible for shutting it down when the JVM shuts down. It is not tracked or shut down by ```Unirest.shutDown();``` -### Proxy - -You can set a proxy by invoking: - -```java -Unirest.setProxy(new HttpHost("127.0.0.1", 8000)); -``` # Exiting an application @@ -254,6 +232,6 @@ Unirest starts a background event loop and your Java application won't be able t Unirest.shutdown(); ``` -Once shutdown, you can call `Options.init()` to re-initialize Unirest. +Once shutdown, using Unirest again will re-init the system From 477e17b5ecf1d5df8be18151c3a1e4ce67761c09 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 18 Nov 2018 17:26:12 -0600 Subject: [PATCH 0271/1769] update pom for major release. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 77fe2ae4d..b9c74bb26 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.5.02-SNAPSHOT + 3.0.00-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ From 0dba9e405ca2b255f4c3a3e856518fe67df59171 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 18 Nov 2018 17:29:13 -0600 Subject: [PATCH 0272/1769] update readme more --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 25ad5ddac..dd448c137 100644 --- a/README.md +++ b/README.md @@ -186,7 +186,24 @@ Authenticating the request with basic authentication can be done by calling the .asJson(); ``` +# Configuration +Previous versions of unirest had configuration split across several different places. Sometimes it was done on ```Unirest```, sometimes it was done on ```Option```, sometimes it was somewhere else. +All configuration is now done through ```Unirest.config()``` +#### Unirest.config() +Unirest config allows easy access to build a configuration just like you would build a request: + +```java + Unirest.config() + .socketTimeout(500) + .connectTimeout(1000) + .concurrency(10, 5) + .proxy(new HttpHost("https://proxy")) + .setDefaultHeader("Accept", "application/json") + .followRedirects(false) + .enableCookieManagement(false) + .addInterceptor(new MyCustomInterceptor()); +``` ##### Changing the config Changing Unirest's config should ideally be done once, or rarely. There are several background threads spawned by both Unirest itself and Apache HttpAsyncClient. Once Unirest has been activated configuration options that are involved in creating the client cannot be changed without an explicit shutdown or reset. @@ -224,6 +241,8 @@ As usual, Unirest maintains a primary single instance. Sometimes you might want **WARNING!** If you get a new instance of unirest YOU are responsible for shutting it down when the JVM shuts down. It is not tracked or shut down by ```Unirest.shutDown();``` + + # Exiting an application Unirest starts a background event loop and your Java application won't be able to exit until you manually shutdown all the threads by invoking: From 72c2521e875de03d5c7a14f3625b035780c153bd Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 18 Nov 2018 17:31:18 -0600 Subject: [PATCH 0273/1769] delete the old docs --- docs/.gitignore | 1 - docs/README.md | 69 ----- docs/favicon.ico | Bin 1150 -> 0 bytes docs/img/arc-enable.png | Bin 26473 -> 0 bytes docs/img/logo.png | Bin 68851 -> 0 bytes docs/index.html | 329 ----------------------- docs/styles/fonts.css | 158 ----------- docs/styles/homepage.css | 338 ------------------------ docs/styles/library.css | 543 -------------------------------------- docs/styles/normalize.css | 27 -- 10 files changed, 1465 deletions(-) delete mode 100644 docs/.gitignore delete mode 100644 docs/README.md delete mode 100644 docs/favicon.ico delete mode 100644 docs/img/arc-enable.png delete mode 100644 docs/img/logo.png delete mode 100644 docs/index.html delete mode 100644 docs/styles/fonts.css delete mode 100644 docs/styles/homepage.css delete mode 100644 docs/styles/library.css delete mode 100644 docs/styles/normalize.css diff --git a/docs/.gitignore b/docs/.gitignore deleted file mode 100644 index e43b0f988..000000000 --- a/docs/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.DS_Store diff --git a/docs/README.md b/docs/README.md deleted file mode 100644 index e945eefe6..000000000 --- a/docs/README.md +++ /dev/null @@ -1,69 +0,0 @@ -# [Unirest.io](http://unirest.io) - - -We released our newest open source project, which we called unicorn, unfortunately that was also the name of two other open source projects. We really dropped the ball and have been working hard to clean up the mess. We would like to apologize to anyone in the Ruby or Python community who was confused or annoyed. Hopefully you can look past our mistake and see the value in this project. - -So, we have decided on a new name, Unirest, which we think is a great fit for the project. We also made a [new website](http://unirest.io), updated our docs and [marketplace](http://mashape.com) which autogenerates unirest code snippets and have the open source API gateway [Kong](http://github.com/mahsape/kong) - -### What problem does Unirest solve? - -We’ve noticed that a lot of people have trouble wrapping their head around using public and private APIs. With API keys, varying endpoint architecture, differing response types, etc… there is a lot to think about. - -Unirest tries to simplify the process of consuming APIs by abstracting a lot of the boilerplate and focusing on the core REST verbs that we all know and love (GET, POST, PUT, UPDATE, DELETE). Similarly its methods and response structures are the same in all the supported languages. It works for all REST APIs, available both on our own mashape API marketplace and abroad. - -We truly believe that APIs are changing the way we make software and by extension the world at large. Never has so much power been in the hands of a solo developer with an idea. Our hope is that the developer community that we love will find this project helpful and build a ton of great stuff on top of it. - -### Let's see some code - -The following code submits a post request to [httpbin.org](http://httpbin.org) - -#### Java -```java -HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") - .header("accept", "application/json") - .field("parameter", "value") - .field("foo", "bar") - .asJson(); -``` - - -#### PHP -```php -$response = Unirest\Request::post("http://httpbin.org/post", - array( "Accept" => "application/json" ), - array( - "parameter" => 23, - "foo" => "bar" - ) -); -``` - -#### Ruby -```ruby -response = Unirest::post "http://httpbin.org/post", - { "Accept" => "application/json" }, - { - :parameter => 23, - :foo => "bar" - } -``` - -#### Python -```python -response = unirest.post("http://httpbin.org/post", - { "Accept": "application/json" }, - { "parameter": 23, "foo": "bar" } -) -``` - -#### Objective-C -```objective-c -NSDictionary* headers = [NSDictionary dictionaryWithObjectsAndKeys:@"application/json", @"accept", nil]; -NSDictionary* parameters = [NSDictionary dictionaryWithObjectsAndKeys:@"value", @"parameter", @"bar", @"foo", nil]; - -HttpJsonResponse* response = [[Unirest post:^(MultipartRequest* request) { - [request setUrl:@"http://httpbin.org/post"]; - [request setHeaders:headers]; - [request setParameters:parameters]; -}] asJson]; -``` diff --git a/docs/favicon.ico b/docs/favicon.ico deleted file mode 100644 index b1d136402a51aa2df9a84cec1f6285d0d46c0259..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1150 zcmb7^%WoT16vhXMKcFjC;Jh4r?6Dok&-gv|*q-rY#*f$`Ng)X|fh>3k6;O*nRYR2p zC>v1eizq3T8dM?FMY@2LfCNSSDX1GnyP#!}A19MtcihpP$C>Zk`GN=PCnak(gpynA+({aspW8&fmr#@blHc}%rIKh~wFRWY;@4YkUd z%#f0=OebPf3s~elDU3jxgfCBJ%0i#E7);ON_#9p@F5!fGnDGYsNC{&shZ(G5h5Hz) zK`KyY`b8hQmZKT6na`c3J2PZHIbqm*uApHom+Q#`t)C({PTo2>{YV90@Zkh;#gXEJ5)6r z-CM_+nqwI6@bmsJ?!H&Hu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5-u8;R%>&R&szqO|#*~f8@67+@H6Lm&2TqA~EW2btL zRQwOLT%S76mc#BJM!{HNniXjwWHWB8FixVd{Ti+d17qVfa=j3?+b@+1o3HV}Q77)4^`iA{72Li8i@c#!*YQ!&sr!lzo)+ cFk$@v0S - - - - Unirest for Java - Simplified, lightweight HTTP Request Library - - - - - - - - - - - - -

-Unirest for Java -

- -

- -

Open Unirest is a lightweight Java HTTP library

- -

Do yourself a favor, and start making HTTP requests like this:

- -
Unirest.post("http://httpbin.org/post")
-  .queryString("name", "Mark")
-  .field("last", "Polo")
-  .asJson()
- -

License | -version | -Gitter

- -

-Features

- -
    -
  • Make GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS requests
  • -
  • Both syncronous and asynchronous (non-blocking) requests
  • -
  • It supports form parameters, file uploads and custom body entities
  • -
  • Easily add route parameters without ugly string concatenations
  • -
  • Supports gzip
  • -
  • Supports Basic Authentication natively
  • -
  • Customizable timeout, concurrency levels and proxy settings
  • -
  • Customizable default headers for every request (DRY)
  • -
  • Customizable HttpClient and HttpAsyncClient implementation
  • -
  • Automatic JSON parsing into a native object for JSON responses
  • -
  • Customizable binding, with mapping from response body to java Object
  • -
- -

-Installing

- -

Is easy as pie. Kidding. It's about as easy as doing these little steps:

- -

-With Maven

- -

You can use Maven by including the library:

- -
<dependency>
-    <groupId>com.mashape.unirest</groupId>
-    <artifactId>unirest-java</artifactId>
-    <version>1.4.9</version>
-</dependency>
- -

-Without Maven

- -

-Creating Request

- -

So you're probably wondering how using Unirest makes creating requests in Java easier, here is a basic POST request that will explain everything:

- -
HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post")
-  .header("accept", "application/json")
-  .queryString("apiKey", "123")
-  .field("parameter", "value")
-  .field("foo", "bar")
-  .asJson();
- -

Requests are made when as[Type]() is invoked, possible types include Json, Binary, String, Object.

- -

If the request supports and it is of type HttpRequestWithBody, a body it can be passed along with .body(String|JsonNode|Object). For using .body(Object) some pre-configuration is needed (see below).

- -

If you already have a map of parameters or do not wish to use seperate field methods for each one there is a .fields(Map<String, Object> fields) method that will serialize each key - value to form parameters on your request.

- -

.headers(Map<String, String> headers) is also supported in replacement of multiple header methods.

- -

-Serialization

- -

Before an asObject(Class) or a .body(Object) invokation, is necessary to provide a custom implementation of the ObjectMapper interface. -This should be done only the first time, as the instance of the ObjectMapper will be shared globally.

- -

For example, serializing Json from\to Object using the popular Jackson ObjectMapper takes only few lines of code.

- -
// Only one time
-Unirest.setObjectMapper(new ObjectMapper() {
-    private com.fasterxml.jackson.databind.ObjectMapper jacksonObjectMapper
-                = new com.fasterxml.jackson.databind.ObjectMapper();
-
-    public <T> T readValue(String value, Class<T> valueType) {
-        try {
-            return jacksonObjectMapper.readValue(value, valueType);
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    public String writeValue(Object value) {
-        try {
-            return jacksonObjectMapper.writeValueAsString(value);
-        } catch (JsonProcessingException e) {
-            throw new RuntimeException(e);
-        }
-    }
-});
-
-// Response to Object
-HttpResponse<Book> bookResponse = Unirest.get("http://httpbin.org/books/1").asObject(Book.class);
-Book bookObject = bookResponse.getBody();
-
-HttpResponse<Author> authorResponse = Unirest.get("http://httpbin.org/books/{id}/author")
-    .routeParam("id", bookObject.getId())
-    .asObject(Author.class);
-
-Author authorObject = authorResponse.getBody();
-
-// Object to Json
-HttpResponse<JsonNode> postResponse = Unirest.post("http://httpbin.org/authors/post")
-        .header("accept", "application/json")
-        .header("Content-Type", "application/json")
-        .body(authorObject)
-        .asJson();
- -

-Route Parameters

- -

Sometimes you want to add dynamic parameters in the URL, you can easily do that by adding a placeholder in the URL, and then by setting the route parameters with the routeParam function, like:

- -
Unirest.get("http://httpbin.org/{method}")
-  .routeParam("method", "get")
-  .queryString("name", "Mark")
-  .asJson();
- -

In the example above the final URL will be http://httpbin.org/get - Basically the placeholder {method} will be replaced with get.

- -

The placeholder's format is as easy as: {custom_name}

- -

-Asynchronous Requests

- -

Sometimes, well most of the time, you want your application to be asynchronous and not block, Unirest supports this in Java using anonymous callbacks, or direct method placement:

- -
Future<HttpResponse<JsonNode>> future = Unirest.post("http://httpbin.org/post")
-  .header("accept", "application/json")
-  .field("param1", "value1")
-  .field("param2", "value2")
-  .asJsonAsync(new Callback<JsonNode>() {
-
-    public void failed(UnirestException e) {
-        System.out.println("The request has failed");
-    }
-
-    public void completed(HttpResponse<JsonNode> response) {
-         int code = response.getStatus();
-         Map<String, String> headers = response.getHeaders();
-         JsonNode body = response.getBody();
-         InputStream rawBody = response.getRawBody();
-    }
-
-    public void cancelled() {
-        System.out.println("The request has been cancelled");
-    }
-
-});
- -

-File Uploads

- -

Creating multipart requests with Java is trivial, simply pass along a File or an InputStream Object as a field:

- -
HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post")
-  .header("accept", "application/json")
-  .field("parameter", "value")
-  .field("file", new File("/tmp/file"))
-  .asJson();
- -

-Custom Entity Body

- -
HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post")
-  .header("accept", "application/json")
-  .body("{\"parameter\":\"value\", \"foo\":\"bar\"}")
-  .asJson();
- -

-Byte Stream as Entity Body

- -
final InputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI()));
-final byte[] bytes = new byte[stream.available()];
-stream.read(bytes);
-stream.close();
-final HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post")
-  .field("name", "Mark")
-  .field("file", bytes, "image.jpg")
-  .asJson();
- -

-InputStream as Entity Body

- -
HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post")
-  .field("name", "Mark")
-  .field("file", new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())), ContentType.APPLICATION_OCTET_STREAM, "image.jpg")
-  .asJson();
- -

-Basic Authentication

- -

Authenticating the request with basic authentication can be done by calling the basicAuth(username, password) function:

- -
HttpResponse<JsonNode> response = Unirest.get("http://httpbin.org/headers").basicAuth("username", "password").asJson();
- -

-Request

- -

The Java Unirest library follows the builder style conventions. You start building your request by creating a HttpRequest object using one of the following:

- -
GetRequest request = Unirest.get(String url);
-GetRequest request = Unirest.head(String url);
-HttpRequestWithBody request = Unirest.post(String url);
-HttpRequestWithBody request = Unirest.put(String url);
-HttpRequestWithBody request = Unirest.patch(String url);
-HttpRequestWithBody request = Unirest.options(String url);
-HttpRequestWithBody request = Unirest.delete(String url);
- -

-Response

- -

Upon recieving a response Unirest returns the result in the form of an Object, this object should always have the same keys for each language regarding to the response details.

- -
    -
  • -.getStatus() - HTTP Response Status Code (Example: 200)
  • -
  • -.getStatusText() - HTTP Response Status Text (Example: "OK")
  • -
  • -.getHeaders() - HTTP Response Headers
  • -
  • -.getBody() - Parsed response body where applicable, for example JSON responses are parsed to Objects / Associative Arrays.
  • -
  • -.getRawBody() - Un-parsed response body
  • -
- -

-Advanced Configuration

- -

You can set some advanced configuration to tune Unirest-Java:

- -

-Custom HTTP clients

- -

You can explicitly set your own HttpClient and HttpAsyncClient implementations by using the following methods:

- -
Unirest.setHttpClient(httpClient);
-Unirest.setAsyncHttpClient(asyncHttpClient);
- -

-Timeouts

- -

You can set custom connection and socket timeout values (in milliseconds):

- -
Unirest.setTimeouts(long connectionTimeout, long socketTimeout);
- -

By default the connection timeout (the time it takes to connect to a server) is 10000, and the socket timeout (the time it takes to receive data) is 60000. You can set any of these timeouts to zero to disable the timeout.

- -

-Default Request Headers

- -

You can set default headers that will be sent on every request:

- -
Unirest.setDefaultHeader("Header1", "Value1");
-Unirest.setDefaultHeader("Header2", "Value2");
- -

You can clear the default headers anytime with:

- -
Unirest.clearDefaultHeaders();
- -

-Concurrency

- -

You can set custom concurrency levels if you need to tune the performance of the syncronous or asyncronous client:

- -
Unirest.setConcurrency(int maxTotal, int maxPerRoute);
- -

By default the maxTotal (overall connection limit in the pool) is 200, and the maxPerRoute (connection limit per target host) is 20.

- -

-Proxy

- -

You can set a proxy by invoking:

- -
Unirest.setProxy(new HttpHost("127.0.0.1", 8000));
- -

-Exiting an application

- -

Unirest starts a background event loop and your Java application won't be able to exit until you manually shutdown all the threads by invoking:

- -
Unirest.shutdown();
- -
- -

Made with ♥ from the Mashape team

-
- - - - - - \ No newline at end of file diff --git a/docs/styles/fonts.css b/docs/styles/fonts.css deleted file mode 100644 index abf68bd76..000000000 --- a/docs/styles/fonts.css +++ /dev/null @@ -1,158 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -@font-face { - font-family: 'Open Sans'; - font-style: normal; - font-weight: 300; - src: local('Open Sans Light'), local('OpenSans-Light'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/DXI1ORHCpsQm3Vp6mXoaTaRDOzjiPcYnFooOUGCOsRk.woff) format('woff'); -} -@font-face { - font-family: 'Open Sans'; - font-style: normal; - font-weight: 400; - src: local('Open Sans'), local('OpenSans'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/cJZKeOuBrn4kERxqtaUH3bO3LdcAZYWl9Si6vvxL-qU.woff) format('woff'); -} -@font-face { - font-family: 'Open Sans'; - font-style: normal; - font-weight: 600; - src: local('Open Sans Semibold'), local('OpenSans-Semibold'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/MTP_ySUJH_bn48VBG8sNSqRDOzjiPcYnFooOUGCOsRk.woff) format('woff'); -} -@font-face { - font-family: 'Open Sans'; - font-style: normal; - font-weight: 700; - src: local('Open Sans Bold'), local('OpenSans-Bold'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/k3k702ZOKiLJc3WVjuplzKRDOzjiPcYnFooOUGCOsRk.woff) format('woff'); -} -@font-face { - font-family: 'Open Sans'; - font-style: italic; - font-weight: 300; - src: local('Open Sans Light Italic'), local('OpenSansLight-Italic'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/PRmiXeptR36kaC0GEAetxvR_54zmj3SbGZQh3vCOwvY.woff) format('woff'); -} -@font-face { - font-family: 'Open Sans'; - font-style: italic; - font-weight: 400; - src: local('Open Sans Italic'), local('OpenSans-Italic'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/xjAJXh38I15wypJXxuGMBrrIa-7acMAeDBVuclsi6Gc.woff) format('woff'); -} -@font-face { - font-family: 'Open Sans'; - font-style: italic; - font-weight: 600; - src: local('Open Sans Semibold Italic'), local('OpenSans-SemiboldItalic'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/PRmiXeptR36kaC0GEAetxuw_rQOTGi-AJs5XCWaKIhU.woff) format('woff'); -} -@font-face { - font-family: 'Open Sans'; - font-style: italic; - font-weight: 700; - src: local('Open Sans Bold Italic'), local('OpenSans-BoldItalic'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/PRmiXeptR36kaC0GEAetxhbnBKKEOwRKgsHDreGcocg.woff) format('woff'); -} -@font-face { - font-family: 'Source Code Pro'; - font-style: normal; - font-weight: 300; - src: local('Source Code Pro Light'), local('SourceCodePro-Light'), url(http://themes.googleusercontent.com/static/fonts/sourcecodepro/v3/leqv3v-yTsJNC7nFznSMqcVNtom4QlEDNJaqqqzqdSs.woff) format('woff'); -} -@font-face { - font-family: 'Source Code Pro'; - font-style: normal; - font-weight: 400; - src: local('Source Code Pro'), local('SourceCodePro-Regular'), url(http://themes.googleusercontent.com/static/fonts/sourcecodepro/v3/mrl8jkM18OlOQN8JLgasD9Hq-FFgoDNV3GTKpHwuvtI.woff) format('woff'); -} -@font-face { - font-family: 'Source Code Pro'; - font-style: normal; - font-weight: 500; - src: local('Source Code Pro Medium'), local('SourceCodePro-Medium'), url(http://themes.googleusercontent.com/static/fonts/sourcecodepro/v3/leqv3v-yTsJNC7nFznSMqbIHYkLmgtPJP77jcqN9P08.woff) format('woff'); -} -@font-face { - font-family: 'Source Code Pro'; - font-style: normal; - font-weight: 600; - src: local('Source Code Pro Semibold'), local('SourceCodePro-Semibold'), url(http://themes.googleusercontent.com/static/fonts/sourcecodepro/v3/leqv3v-yTsJNC7nFznSMqSmgpmuQqK2I-L2S9cF65Ek.woff) format('woff'); -} -@font-face { - font-family: 'Source Code Pro'; - font-style: normal; - font-weight: 700; - src: local('Source Code Pro Bold'), local('SourceCodePro-Bold'), url(http://themes.googleusercontent.com/static/fonts/sourcecodepro/v3/leqv3v-yTsJNC7nFznSMqYqjGYJUyOXcBwUQbRaNH6c.woff) format('woff'); -} -@font-face { - font-family: 'Titillium Web'; - font-style: normal; - font-weight: 200; - src: local('Titillium WebThin'), local('TitilliumWeb-Thin'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v1/anMUvcNT0H1YN4FII8wpr-K9kSItTeDn2USN0q77Oh4.woff) format('woff'); -} -@font-face { - font-family: 'Titillium Web'; - font-style: normal; - font-weight: 300; - src: local('Titillium WebLight'), local('TitilliumWeb-Light'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v1/anMUvcNT0H1YN4FII8wpr1uKlGE8-OjkUKWan_M3D6s.woff) format('woff'); -} -@font-face { - font-family: 'Titillium Web'; - font-style: normal; - font-weight: 400; - src: local('Titillium Web'), local('TitilliumWeb-Regular'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v1/7XUFZ5tgS-tD6QamInJTcZ_o9VAbKgK36i-4snuAuCM.woff) format('woff'); -} -@font-face { - font-family: 'Titillium Web'; - font-style: normal; - font-weight: 600; - src: local('Titillium WebSemiBold'), local('TitilliumWeb-SemiBold'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v1/anMUvcNT0H1YN4FII8wprx3QmhlKDgQgT1VN2Ed1WFo.woff) format('woff'); -} -@font-face { - font-family: 'Titillium Web'; - font-style: normal; - font-weight: 700; - src: local('Titillium WebBold'), local('TitilliumWeb-Bold'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v1/anMUvcNT0H1YN4FII8wpr_5rZpfU3XI-FvUPGDRT0xY.woff) format('woff'); -} -@font-face { - font-family: 'Titillium Web'; - font-style: italic; - font-weight: 200; - src: local('Titillium WebThin Italic'), local('TitilliumWeb-ThinItalic'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v1/RZunN20OBmkvrU7sA4GPPvTdIrrWFKtkerHRAIjOAnE.woff) format('woff'); -} -@font-face { - font-family: 'Titillium Web'; - font-style: italic; - font-weight: 300; - src: local('Titillium WebLight Italic'), local('TitilliumWeb-LightItalic'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v1/RZunN20OBmkvrU7sA4GPPiKuKXcI2mpaPB3p6hsA39k.woff) format('woff'); -} -@font-face { - font-family: 'Titillium Web'; - font-style: italic; - font-weight: 400; - src: local('Titillium WebItalic'), local('TitilliumWeb-Italic'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v1/r9OmwyQxrgzUAhaLET_KO8-iP4m4uFrmmLLVBqy34EU.woff) format('woff'); -} -@font-face { - font-family: 'Titillium Web'; - font-style: italic; - font-weight: 600; - src: local('Titillium WebSemiBold Italic'), local('TitilliumWeb-SemiBoldItalic'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v1/RZunN20OBmkvrU7sA4GPPnV4MzQw1VeMlPUyFyGfvRM.woff) format('woff'); -} \ No newline at end of file diff --git a/docs/styles/homepage.css b/docs/styles/homepage.css deleted file mode 100644 index 0141ca1f8..000000000 --- a/docs/styles/homepage.css +++ /dev/null @@ -1,338 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -@import url('fonts.css'); -@import url('normalize.css'); - -body, html { - font-family: 'Open Sans', 'Helvetica'; - padding: 0px; - margin: 0px; -} - -pre, code { - font-family: 'Source Code Pro'; -} - -h1 { - font-weight: 400; -} - -h1, h2 { - margin: 0; -} - -p { - -webkit-hyphens: auto; - -moz-hyphens: auto; - hyphens: auto; - margin-bottom: 1.5em; - margin-top: 2em; - color: hsl(217, 18%, 65%); - text-align: center; -} - -p a { - color: hsl(200, 100%, 50%); -} - -p a:hover { - color: #97A3B6; - border-bottom-color: #97A3B6; - transition: all .3s ease-in; -} - -nav { - font-family: 'Open Sans'; - position: fixed; - z-index: 1; - top: 0; - left: 0; - width: 100%; - display: block; - padding: 20px; - margin: 0; - background: white; - box-shadow: 0 -1px 5px hsla(0, 0%, 0%, 0.5); -} - -nav .right { - display: inline-block; - float: right; - padding: 0 40px; -} - -nav a { - font-size: 14px; - font-weight: 600; - color: #97A3B6; - border: 0px; - transition: all .3s ease-in; - padding: 0 20px 0 0; - display: inline-block; - text-decoration: none; -} - -nav a:hover { - color: #0D131A; - text-decoration: none; - border: 0px; -} - -header { - margin-top: 80px; - margin-bottom: 60px; -} - -header h1 { - display: block; - font-size: 128pt; - font-family: 'Titillium Web'; - text-align: center; - padding: 2% 0 0; - line-height: 96pt; -} - -header h2 { - display: block; - font-size: 28pt; - font-weight: 300; - font-family: 'Titillium Web'; - text-align: center; - padding: 20px 0 0 0; - color: hsl(212, 10%, 49%); -} - - .button-list { - max-width: 860px; - margin: 2% auto 0; - display: block; - text-align: center; - padding: 0 0 10px; -} - - .button-list h4 { - color: white; - display: block; - font-family: 'Titillium Web'; - font-size: 16pt; - font-weight: 300; - line-height: 64pt; -} - - .button-list .group { - display: block; - clear: both; -} - -.button { - position: relative; - top: 0; - display: inline-block; - width: auto; - margin: 0 0px 10px; - padding: 0 49px 5px; - font-family: "Open Sans", sans-serif; - font-size: 14px; - line-height: 35px; - font-weight: 600; - color: hsl(212, 33%, 8%); - background-color: hsl(212, 13%, 88%); - border-radius: 6px; - -moz-border-radius: 6px; - -webkit-border-radius: 6px; - -o-border-radius: 6px; - -webkit-transition: all .3s ease-out; - -moz-transition: all .3s ease-out; - -o-transition: all .3s ease-out; - text-decoration: none; - cursor: pointer; - white-space: nowrap; - text-decoration: none; -} - -.button.active { - color: white; -} - -.button.green { - background-color: #6F9507; -} - -.button.red { - background-color: #E74C3C; -} - -.button.blue { - background-color: #23AFC8; -} - -.button.orange { - background-color: #E76F00; -} - -.button.yellow { - background-color: #F3CF3F; -} - -.button.teal { - background-color: #29BB9C; -} - -.button.node-green { - background-color: #8CC84B; -} - -.button.pinterest-red { - background-color: #CC2127; -} - -.button.youtube-red { - background-color: #A40F09; -} - -.button.twitter-blue { - background-color: #4AC6EC; -} - -.button.forrst-green { - background-color: #359053; -} - -.button.facebook-blue { - background-color: #3A5899; -} - -.button:hover { - text-decoration: none; - color: white; -} - -.button.hover-green:hover, .button.hover-green.active { - background-color: #6F9507; -} - -.button.hover-red:hover, .button.hover-red.active { - background-color: #E74C3C; -} - -.button.hover-blue:hover, .button.hover-blue.active { - background-color: #23AFC8; -} - -.button.hover-orange:hover, .button.hover-orange.active { - background-color: #E76F00; -} - -.button.hover-yellow:hover, .button.hover-yellow.active { - background-color: #F3CF3F; -} - -.button.hover-teal:hover, .button.hover-teal.active { - background-color: #29BB9C; -} - -.button.hover-node-green:hover, .button.hover-node-green.active { - background-color: #8CC84B; -} - -.button.hover-pinterest-red:hover, .button.hover-pinterest-red.active { - background-color: #CC2127; -} - -.button.hover-twitter-blue:hover, .button.hover-twitter-blue.active { - background-color: #4AC6EC; -} - -.button.hover-youtube-red:hover, .button.hover-youtube-red.active { - background-color: #A40F09; -} - -.button.hover-forrst-green:hover, .button.hover-forrst-green.active { - background-color: #359053; -} - -.button.hover-facebook-blue:hover, .button.hover-facebook-blue.active { - background-color: #3A5899; -} - -.button:active { - padding-bottom: 0; - box-shadow: 0 1px 5px hsla(0, 0%, 0%, 0.2) inset; - -moz-box-shadow: 0 1px 5px hsla(0, 0%, 0%, 0.2) inset; - -webkit-box-shadow: 0 1px 5px hsla(0, 0%, 0%, 0.2) inset; - -o-box-shadow: 0 1px 5px hsla(0, 0%, 0%, 0.2) inset; -} - -.button-list .button { - box-sizing: border-box; - width: 23.8%; - padding: 0; - height: 100px; - margin: 2px 2px 4px; - text-align: center; - line-height: 100px; -} - -.plug { - font-size: .9em; - margin: 30px auto; -} - -@media (max-width: 700px) { - .button-list .button { - width: 45%; - } -} - -@media (max-width: 640px) { - header h1 { - font-size: 96pt; - } - - header h2 { - font-size: 24pt; - } -} - -@media (max-width: 460px) { - nav a { - font-size: 12px; - padding: 0 5px 0 0; - } - - header h1 { - font-size: 72pt; - } - - header h2 { - font-size: 18pt; - } - - header .button-list .button { - width: 90%; - } -} \ No newline at end of file diff --git a/docs/styles/library.css b/docs/styles/library.css deleted file mode 100644 index f0d39d8db..000000000 --- a/docs/styles/library.css +++ /dev/null @@ -1,543 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -@import url('fonts.css'); -@import url('normalize.css'); - -body, html { - font-family: 'Open Sans', 'Helvetica'; - padding: 0px; - margin: 0px; - height: 100%; - - color: hsl(212, 33%, 11%); -} - -a, a:hover { - color: hsl(200, 100%, 50%); - text-decoration: none; - border-bottom: 1px solid hsl(200, 100%, 50%); - transition: all .3s ease-in; -} - -a ~ img { - border-bottom: 0px; -} - -a:hover { - color: #97A3B6; - border-bottom: 1px solid #97A3B6; -} - -pre, code { - font-family: 'Source Code Pro'; -} - -.documentation { - padding-bottom: 80px; -} - -.social { - position: relative; - top: 30px; - float: right; -} - -.center { - text-align: center; - margin: 20px auto; -} - -nav { - font-family: 'Open Sans'; - position: fixed; - z-index: 1; - top: 0; - left: 0; - width: 100%; - display: block; - padding: 20px; - margin: 0; - background: white; - box-shadow: 0 -1px 5px hsla(0, 0%, 0%, 0.5); -} - -nav .right { - display: inline-block; - float: right; - padding: 0 40px; -} - -nav .right a { - color: hsl(200, 100%, 50%); -} - -nav .right a span { - color: hsl(217, 18%, 65%); -} - -nav a { - font-size: 14px; - font-weight: 600; - color: #97A3B6; - border: 0px; - transition: all .3s ease-in; - padding: 0 20px 0 0; - display: inline-block; -} - -nav a:hover { - color: #0D131A; - text-decoration: none; - border: 0px; -} - -nav iframe { - margin-bottom: -5px; - margin-left: 10px; -} - -article { - max-width: 944px; - margin: auto; -} - -h1 { - font-weight: 300; -} - -h2, h3 , h4 { - font-weight: 400; -} - -h1, h2, h3, h4, h5, h6 { - font-family: 'Titillium Web'; -} - -h1, h2, h3, h4, h5, h6, p, ul, ol, table { - min-width: 460px; - max-width: 860px; - margin: 0 auto; - padding-left: 20px; - padding-right: 20px; -} - -body { - font-size: 100%; - line-height: 1.5; -} - -h1 { - font-size: 3.4285714285714284em; - line-height: 1.3125em; - margin-top: 1.5em; -} - -h2 { - font-size: 2.2857142857142856em; - line-height: 1.96875em; -} - -h3 { - font-size: 1.7142857142857142em; - line-height: 1.75em; -} - -h4 { - font-size: 1.5em; - line-height: 2em; - margin-top: 2em; -} - -h5 { - font-size: 1.2857142857142858em; - line-height: 2.3333333333333335em; -} - -h6 { - font-size: 1.1428571428571428em; - line-height: 2.625em; -} - -.documentation > h1:first-of-type { - margin-top: 2em; - margin-bottom: .5em; -} - -hr { - border-top: 1px solid hsl(0, 0%, 93%); - border-bottom: none; - margin: 30px auto; - max-width: 860px; -} - -p { - -webkit-hyphens: auto; - -moz-hyphens: auto; - hyphens: auto; - margin-bottom: 1.5em; -} - -p + hr { - margin-bottom: 1.2em; -} - -.highlight, pre code { - display: block; - min-width: 460px; - max-width: 860px; - margin: 0 auto; - background: #0F161E; - border-radius: 6px; - padding: 20px; -} - -.highlight pre { - margin: 0 2px; -} - -.highlight pre span { - display: inline-block; -} - -p, ol, ul, blockquote, pre, code, .highlight, table { - line-height: 18px; - margin-bottom 18px; - /* 1.5em provides good vertical spacing ( = 150% of the font-size) */ - line-height: 1.5em; - margin-bottom: 1.5em; -} - -li { - margin-bottom: .2em; -} - -p, ul, ol { - color: hsl(212, 33%, 11%); - list-style: none; -} - -code { - color: hsl(333, 100%, 50%); -} - -table thead tr th { - text-align: left; -} - -table tr td { - border-top: 1px solid hsl(0, 0%, 93%); - padding: 10px 5px; - vertical-align: top; -} - -.highlight { - color: hsl(0, 100%, 100%); -} - -.highlight .c { - color: #192532; - font-style: italic; -} - -.highlight .err { - color: hsl(0, 100%, 80%); -} - -.highlight .k { - color: hsl(33, 82%, 71%); -} - -.highlight .cm { - color: #999988; - font-style: italic; -} - -.highlight .cp { - color: #999999; - font-weight: bold; -} - -.highlight .c1 { - color: hsl(35, 8%, 44%); - font-style: italic; -} - -.highlight .cs { - color: #999999; - font-weight: bold; - font-style: italic; -} - -.highlight .gd { - color: #000000; - background-color: #ffdddd; -} - -.highlight .gd .x { - color: #000000; - background-color: #ffaaaa; -} - -.highlight .ge { - font-style: italic; -} - -.highlight .gr { - color: #aa0000; -} - -.highlight .gh { - color: #999999; -} - -.highlight .gi { - color: #000000; - background-color: #ddffdd; -} - -.highlight .gi .x { - color: #000000; - background-color: #aaffaa; -} - -.highlight .go { - color: #888888; -} - -.highlight .gp { - color: #555555; -} - -.highlight .gs { - font-weight: bold; -} - -.highlight .gu { - color: #800080; - font-weight: bold; -} - -.highlight .gt { - color: #aa0000; -} - -.highlight .kc { - font-weight: bold; -} - -.highlight .kd { - color: hsl(180, 61%, 41%); -} - -.highlight .kn { -} - -.highlight .kp { - font-weight: bold; -} - -.highlight .kr { - font-weight: bold; -} - -.highlight .kt { - color: hsl(33, 82%, 71%); -} - -.highlight .m { - color: #009999; -} - -.highlight .s { - color: hsl(41, 93%, 60%); -} - -.highlight .n { - color: hsl(33, 82%, 71%); -} - -.highlight .na { - color: white; -} - -.highlight .nc { - color: #445588; - font-weight: bold; -} - -.highlight .no { - color: hsl(180, 61%, 41%); -} - -.highlight .ni { - color: #800080; -} - -.highlight .ne { - color: #990000; - font-weight: bold; -} - -.highlight .nf { - color: hsl(11, 83%, 70%); -} - -.highlight .nn { - color: hsl(0, 0%, 80%); -} - -.highlight .nt { - color: hsl(33, 82%, 71%); -} - -.highlight .nv { - color: hsl(180, 61%, 41%); -} - -.highlight .ow { - font-weight: bold; -} - -.highlight .w { - color: #bbbbbb; -} - -.highlight .mf { - color: #009999; -} - -.highlight .mh { - color: #009999; -} - -.highlight .mi { - color: hsl(41, 93%, 60%); -} - -.highlight .mo { - color: #009999; -} - -.highlight .sb { - color: hsl(41, 93%, 60%); -} - -.highlight .sc { - color: hsl(41, 93%, 60%); -} - -.highlight .sd { - color: hsl(41, 93%, 60%); -} - -.highlight .s2 { - color: hsl(41, 93%, 60%); -} - -.highlight .se { - color: hsl(41, 93%, 60%); -} - -.highlight .sh { - color: hsl(41, 93%, 60%); -} - -.highlight .si { - color: hsl(41, 93%, 60%); -} - -.highlight .sx { - color: hsl(41, 93%, 60%); -} - -.highlight .sr { - color: #009926; -} - -.highlight .s1 { - color: hsl(41, 93%, 60%); -} - -.highlight .bp { - color: #999999; -} - -.highlight .vc { - color: #008080; -} - -.highlight .vg { - color: #008080; -} - -.highlight .vi { - color: #008080; -} - -.highlight .il { - color: #009999; -} - -.highlight .gc { - color: #999; - background-color: #EAF2F5; -} - -.type-csharp .highlight .k { - color: #0000FF; -} - -.type-csharp .highlight .kt { - color: #0000FF; -} - -.type-csharp .highlight .nf { - color: #000000; - font-weight: normal; -} - -.type-csharp .highlight .nc { - color: #2B91AF; -} - -.type-csharp .highlight .nn { - color: #000000; -} - -.type-csharp .highlight .s { - color: #A31515; -} - -.type-csharp .highlight .sc { - color: #A31515; -} - -@media (max-width: 860px) { - .highlight, pre code { - border-radius: 0; - } -} diff --git a/docs/styles/normalize.css b/docs/styles/normalize.css deleted file mode 100644 index a5ffe0cca..000000000 --- a/docs/styles/normalize.css +++ /dev/null @@ -1,27 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -/*! normalize.css v2.0.1 | MIT License | git.io/normalize */article,aside,details,figcaption,figure,footer,header,hgroup,nav,section,summary{display:block}audio,canvas,video{display:inline-block}audio:not([controls]){display:none;height:0}[hidden]{display:none}html{font-family:sans-serif;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}body{margin:0}a:focus{outline:thin dotted}a:active,a:hover{outline:0}h1{font-size:2em}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}dfn{font-style:italic}mark{background:#ff0;color:#000}code,kbd,pre,samp{font-family:monospace,serif;font-size:1em}pre{white-space:pre;white-space:pre-wrap;word-wrap:break-word}q{quotes:"\201C" "\201D" "\2018" "\2019"}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:0}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:.35em .625em .75em}legend{border:0;padding:0}button,input,select,textarea{font-family:inherit;font-size:100%;margin:0}button,input{line-height:normal}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}button[disabled],input[disabled]{cursor:default}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}textarea{overflow:auto;vertical-align:top}table{border-collapse:collapse;border-spacing:0} \ No newline at end of file From 20d0b411bbc2bee74918f20103e26135dbe971e8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 19 Nov 2018 06:51:14 -0600 Subject: [PATCH 0274/1769] clean up some more acess --- src/main/java/unirest/BodyData.java | 2 +- src/main/java/unirest/FormPart.java | 12 ++++-------- src/main/java/unirest/Headers.java | 2 +- src/main/java/unirest/HttpDeleteWithBody.java | 4 ++-- src/main/java/unirest/HttpRequestMultiPart.java | 2 +- src/main/java/unirest/HttpRequestNoBody.java | 2 +- src/main/java/unirest/HttpResponse.java | 4 ++++ src/main/java/unirest/HttpResponseImpl.java | 6 +----- src/main/java/unirest/Path.java | 4 ++-- 9 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/main/java/unirest/BodyData.java b/src/main/java/unirest/BodyData.java index 3ea967239..01726503a 100644 --- a/src/main/java/unirest/BodyData.java +++ b/src/main/java/unirest/BodyData.java @@ -37,7 +37,7 @@ import static unirest.ResponseUtils.getRawBody; @Deprecated // use at your own risk -public class BodyData { +class BodyData { public static BodyData from(HttpEntity e, Function, T> transformer) { if(Objects.isNull(e)){ diff --git a/src/main/java/unirest/FormPart.java b/src/main/java/unirest/FormPart.java index 585de25ae..4d95514ce 100644 --- a/src/main/java/unirest/FormPart.java +++ b/src/main/java/unirest/FormPart.java @@ -32,16 +32,12 @@ import java.io.File; import java.nio.charset.StandardCharsets; -public final class FormPart implements Comparable { +class FormPart implements Comparable { private final String name; private final Object value; private final ContentType contentType; - public FormPart(String name, Object value){ - this(name, value, null); - } - - public FormPart(String name, Object value, ContentType contentType) { + FormPart(String name, Object value, ContentType contentType) { this.name = name; this.value = value; this.contentType = contentType; @@ -51,7 +47,7 @@ public Object getValue() { return value; } - public ContentType getContentType() { + private ContentType getContentType() { if(contentType == null){ if(isFile()){ return ContentType.APPLICATION_OCTET_STREAM; @@ -61,7 +57,7 @@ public ContentType getContentType() { return contentType; } - public ContentBody toApachePart() { + ContentBody toApachePart() { if (value instanceof File) { File file = (File) value; return new FileBody(file, getContentType(), file.getName()); diff --git a/src/main/java/unirest/Headers.java b/src/main/java/unirest/Headers.java index dd7c73c6d..f1429d5be 100644 --- a/src/main/java/unirest/Headers.java +++ b/src/main/java/unirest/Headers.java @@ -61,7 +61,7 @@ public void add(String name, String value) { } } - public Stream
entries() { + Stream
entries() { return entrySet().stream().flatMap(this::toEntries); } diff --git a/src/main/java/unirest/HttpDeleteWithBody.java b/src/main/java/unirest/HttpDeleteWithBody.java index 01a7c9950..116d3e33a 100644 --- a/src/main/java/unirest/HttpDeleteWithBody.java +++ b/src/main/java/unirest/HttpDeleteWithBody.java @@ -31,13 +31,13 @@ import java.net.URI; class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase { - public static final String METHOD_NAME = "DELETE"; + private static final String METHOD_NAME = "DELETE"; public String getMethod() { return METHOD_NAME; } - public HttpDeleteWithBody(final String uri) { + HttpDeleteWithBody(final String uri) { super(); setURI(URI.create(uri)); } diff --git a/src/main/java/unirest/HttpRequestMultiPart.java b/src/main/java/unirest/HttpRequestMultiPart.java index 7d07c7108..693d84845 100644 --- a/src/main/java/unirest/HttpRequestMultiPart.java +++ b/src/main/java/unirest/HttpRequestMultiPart.java @@ -48,7 +48,7 @@ class HttpRequestMultiPart extends BaseRequest implements Multipa private HttpMultipartMode mode = HttpMultipartMode.BROWSER_COMPATIBLE; private Charset charSet; - public HttpRequestMultiPart(HttpRequestBody httpRequest) { + HttpRequestMultiPart(HttpRequestBody httpRequest) { super(httpRequest); this.charSet = httpRequest.getCharset(); } diff --git a/src/main/java/unirest/HttpRequestNoBody.java b/src/main/java/unirest/HttpRequestNoBody.java index c429c9661..48bddb4d3 100644 --- a/src/main/java/unirest/HttpRequestNoBody.java +++ b/src/main/java/unirest/HttpRequestNoBody.java @@ -27,7 +27,7 @@ package unirest; class HttpRequestNoBody extends BaseRequest implements GetRequest { - public HttpRequestNoBody(Config config, HttpMethod method, String url) { + HttpRequestNoBody(Config config, HttpMethod method, String url) { super(config, method, url); } } diff --git a/src/main/java/unirest/HttpResponse.java b/src/main/java/unirest/HttpResponse.java index 9f4813eb0..0ec7476d7 100644 --- a/src/main/java/unirest/HttpResponse.java +++ b/src/main/java/unirest/HttpResponse.java @@ -35,6 +35,10 @@ public interface HttpResponse { String getStatusText(); + /** + * @return Response Headers (map) with same case as server response. + * For instance use getHeaders().getFirst("Location") and not getHeaders().getFirst("location") to get first header "Location" + */ Headers getHeaders(); InputStream getRawBody(); diff --git a/src/main/java/unirest/HttpResponseImpl.java b/src/main/java/unirest/HttpResponseImpl.java index 695be1890..3d518314c 100644 --- a/src/main/java/unirest/HttpResponseImpl.java +++ b/src/main/java/unirest/HttpResponseImpl.java @@ -71,11 +71,7 @@ public int getStatus() { public String getStatusText() { return statusText; } - - /** - * @return Response Headers (map) with same case as server response. - * For instance use getHeaders().getFirst("Location") and not getHeaders().getFirst("location") to get first header "Location" - */ + @Override public Headers getHeaders() { return headers; diff --git a/src/main/java/unirest/Path.java b/src/main/java/unirest/Path.java index 8edfa1805..87162b371 100644 --- a/src/main/java/unirest/Path.java +++ b/src/main/java/unirest/Path.java @@ -33,10 +33,10 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -public class Path { +class Path { private String url; - public Path(String url) { + Path(String url) { this.url = url; } From ea74b3db922e8ea980c8051fdf19eabdef01337d Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 19 Nov 2018 11:07:06 -0600 Subject: [PATCH 0275/1769] tests showing setting a custom client --- pom.xml | 9 ++++- src/test/java/BehaviorTests/BddTest.java | 6 ++++ .../java/BehaviorTests/LifeCycleTest.java | 34 +++++++++++++++++-- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 5f3c46ff6..75ec05f1c 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 io.github.openunirest unirest-java @@ -319,5 +320,11 @@ 2.8.1 test + + com.github.paweladamski + HttpClientMock + 1.0.4 + test + diff --git a/src/test/java/BehaviorTests/BddTest.java b/src/test/java/BehaviorTests/BddTest.java index 01db4610d..8fcd41313 100644 --- a/src/test/java/BehaviorTests/BddTest.java +++ b/src/test/java/BehaviorTests/BddTest.java @@ -2,6 +2,7 @@ import io.github.openunirest.http.*; import io.github.openunirest.http.options.Options; +import org.junit.After; import org.junit.Before; import util.TestUtil; @@ -29,6 +30,11 @@ public void setUp() { status = false; } + @After + public void tearDown() { + Unirest.shutdown(true); + } + public void assertAsync() { try { lock.await(5, TimeUnit.SECONDS); diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index 50f1681f5..922b28f70 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -1,5 +1,7 @@ package BehaviorTests; +import com.github.paweladamski.httpclientmock.HttpClientMock; +import io.github.openunirest.http.HttpResponse; import io.github.openunirest.http.Unirest; import io.github.openunirest.http.async.utils.AsyncIdleConnectionMonitorThread; import io.github.openunirest.http.options.Options; @@ -10,13 +12,41 @@ import java.io.IOException; +import static io.github.openunirest.http.Unirest.get; import static io.github.openunirest.http.options.Option.*; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.*; public class LifeCycleTest extends BddTest { + @Test + public void settingACustomClient() { + HttpClientMock httpClientMock = new HttpClientMock(); + httpClientMock.onGet("http://localhost/getme").doReturn(202, "Howdy Ho!"); + + Unirest.setHttpClient(httpClientMock); + HttpResponse result = Unirest.get("http://localhost/getme").asString(); + + assertEquals(202, result.getStatus()); + assertEquals("Howdy Ho!", result.getBody()); + } + + @Test + public void settingClientAfterClientHasAlreadyBeenSet() { + HttpClientMock httpClientMock = new HttpClientMock(); + httpClientMock.onGet("http://localhost/getme").doReturn(202, "Howdy Ho!"); + + assertEquals(200, Unirest.get(MockServer.GET).asString().getStatus()); + + Unirest.setHttpClient(httpClientMock); + HttpResponse result = Unirest.get("http://localhost/getme").asString(); + + assertEquals(202, result.getStatus()); + assertEquals("Howdy Ho!", result.getBody()); + } + @Test public void testShutdown() throws IOException { CloseableHttpClient httpc = mock(CloseableHttpClient.class); @@ -62,7 +92,7 @@ public void willNotShutdownInactiveAsyncClient() throws IOException { @Test public void canDetectIfSystemIsRunning() { - Unirest.get(MockServer.GET).asBinary(); + get(MockServer.GET).asBinary(); assertTrue(Unirest.isRunning()); Unirest.shutdown(); @@ -77,7 +107,7 @@ public void willReinitIfLibraryIsUsedAfterShutdown() { Unirest.shutdown(); assertFalse(Unirest.isRunning()); - Unirest.get(MockServer.GET).asBinary(); + get(MockServer.GET).asBinary(); assertTrue(Unirest.isRunning()); } } From c599b31069fa5a367abba36ce776e54a5da8362a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 19 Nov 2018 12:48:36 -0600 Subject: [PATCH 0276/1769] test the monitor thread before starting --- CHANGELOG.md | 3 +++ .../http/async/utils/AsyncIdleConnectionMonitorThread.java | 5 +++++ .../java/io/github/openunirest/request/HttpClientHelper.java | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 743588a74..0cafab07a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.5.02 +* Another fix for #41. Double check the monitor to make sure it has not already started. + ## 2.5.01 * Fix Issue #41: possible init error in HttpClient under heavy load diff --git a/src/main/java/io/github/openunirest/http/async/utils/AsyncIdleConnectionMonitorThread.java b/src/main/java/io/github/openunirest/http/async/utils/AsyncIdleConnectionMonitorThread.java index aaa6e447d..c6f85769f 100644 --- a/src/main/java/io/github/openunirest/http/async/utils/AsyncIdleConnectionMonitorThread.java +++ b/src/main/java/io/github/openunirest/http/async/utils/AsyncIdleConnectionMonitorThread.java @@ -32,4 +32,9 @@ public void run() { } } + public synchronized void tryStart() { + if(!super.isAlive()){ + super.start(); + } + } } diff --git a/src/main/java/io/github/openunirest/request/HttpClientHelper.java b/src/main/java/io/github/openunirest/request/HttpClientHelper.java index 95ba48d70..9740648ff 100644 --- a/src/main/java/io/github/openunirest/request/HttpClientHelper.java +++ b/src/main/java/io/github/openunirest/request/HttpClientHelper.java @@ -88,7 +88,7 @@ private static synchronized void tryStart(CloseableHttpAsyncClient asyncHttpClie if (!asyncHttpClient.isRunning()) { asyncHttpClient.start(); AsyncIdleConnectionMonitorThread asyncIdleConnectionMonitorThread = (AsyncIdleConnectionMonitorThread) Options.getOption(Option.ASYNC_MONITOR); - asyncIdleConnectionMonitorThread.start(); + asyncIdleConnectionMonitorThread.tryStart(); } } } From e4d6c2f12974a3d5c13fc5105529067b94410508 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 19 Nov 2018 12:51:14 -0600 Subject: [PATCH 0277/1769] [maven-release-plugin] prepare release v2.5.02 --- pom.xml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 75ec05f1c..2b1e99929 100644 --- a/pom.xml +++ b/pom.xml @@ -1,11 +1,10 @@ - + 4.0.0 io.github.openunirest unirest-java jar - 2.5.02-SNAPSHOT + 2.5.02 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -22,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.5.02 From f23b6c8a6b569d8eec0a8f7deac6003f278900f7 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 19 Nov 2018 12:51:20 -0600 Subject: [PATCH 0278/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 2b1e99929..0ee8a5664 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.5.02 + 2.5.03-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.5.02 + HEAD From 411bcbf78348d50d1f7306ad488a6e63b22a4f38 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 19 Nov 2018 21:14:06 -0600 Subject: [PATCH 0279/1769] add tests for setting a custom client --- pom.xml | 6 +++++ .../java/BehaviorTests/LifeCycleTest.java | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/pom.xml b/pom.xml index b9c74bb26..fb9201abf 100644 --- a/pom.xml +++ b/pom.xml @@ -349,5 +349,11 @@ 2.8.1 test + + com.github.paweladamski + HttpClientMock + 1.0.4 + test + diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index 42dda0c99..acc949b8a 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -26,6 +26,7 @@ package BehaviorTests; +import com.github.paweladamski.httpclientmock.HttpClientMock; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; import org.junit.runner.RunWith; @@ -57,6 +58,27 @@ public class LifeCycleTest extends BddTest { @Mock private PoolingNHttpClientConnectionManager manager; + @Test + public void settingACustomClient() { + HttpClientMock httpClientMock = new HttpClientMock(); + httpClientMock.onGet("http://localhost/getme").doReturn(202, "Howdy Ho!"); + Unirest.config().httpClient(httpClientMock); + HttpResponse result = Unirest.get("http://localhost/getme").asString(); + assertEquals(202, result.getStatus()); + assertEquals("Howdy Ho!", result.getBody()); + } + + @Test + public void settingClientAfterClientHasAlreadyBeenSet() { + HttpClientMock httpClientMock = new HttpClientMock(); + httpClientMock.onGet("http://localhost/getme").doReturn(202, "Howdy Ho!"); + assertEquals(200, Unirest.get(MockServer.GET).asString().getStatus()); + Unirest.config().httpClient(httpClientMock); + HttpResponse result = Unirest.get("http://localhost/getme").asString(); + assertEquals(202, result.getStatus()); + assertEquals("Howdy Ho!", result.getBody()); + } + @Test public void testShutdown() throws IOException { when(asyncClient.isRunning()).thenReturn(true); From 55fd46a3038540bb4c708dd905f4a8651041c090 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 19 Nov 2018 21:22:19 -0600 Subject: [PATCH 0280/1769] add more protection for client building --- .../java/unirest/AsyncIdleConnectionMonitorThread.java | 6 ++++++ src/main/java/unirest/ClientFactory.java | 2 +- src/main/java/unirest/Config.java | 8 +++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java b/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java index f0a34e8b6..2a6b41035 100644 --- a/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java +++ b/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java @@ -58,4 +58,10 @@ public void run() { } } + public synchronized void tryStart() { + if(!super.isAlive()){ + super.start(); + } + } + } diff --git a/src/main/java/unirest/ClientFactory.java b/src/main/java/unirest/ClientFactory.java index 42f1965c1..1e7e43b00 100644 --- a/src/main/java/unirest/ClientFactory.java +++ b/src/main/java/unirest/ClientFactory.java @@ -67,7 +67,7 @@ public AsyncConfig buildAsyncClient() { CloseableHttpAsyncClient build = ab.build(); build.start(); AsyncIdleConnectionMonitorThread syncMonitor = new AsyncIdleConnectionMonitorThread(manager); - syncMonitor.start(); + syncMonitor.tryStart(); return new AsyncConfig(build, manager, syncMonitor); } catch (IOReactorException e) { diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java index 5b67d2040..d58eae7ae 100644 --- a/src/main/java/unirest/Config.java +++ b/src/main/java/unirest/Config.java @@ -281,11 +281,17 @@ private void validateClientsNotRunning() { public HttpClient getClient() { if (!client.isPresent()) { - client = Optional.of(factory.buildHttpClient()); + buildClient(); } return client.get().getClient(); } + private synchronized void buildClient() { + if (!client.isPresent()) { + client = Optional.of(factory.buildHttpClient()); + } + } + public HttpAsyncClient getAsyncHttpClient() { if (!asyncClient.isPresent()) { buildAsyncClient(); From fc9602f79846aa03d11db1f9735e647f21fb006a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 21 Nov 2018 20:42:38 -0600 Subject: [PATCH 0281/1769] if any client is set mark it as warmed up --- .../io/github/openunirest/http/options/Options.java | 7 +++++++ src/test/java/BehaviorTests/LifeCycleTest.java | 10 +++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/options/Options.java b/src/main/java/io/github/openunirest/http/options/Options.java index 5f24412da..5d51c82c0 100644 --- a/src/main/java/io/github/openunirest/http/options/Options.java +++ b/src/main/java/io/github/openunirest/http/options/Options.java @@ -46,9 +46,16 @@ private static void setIfAbsent(Option option, Object value) { public static void setOption(Option option, Object value) { validateOption(option); + warmUpifClient(option); options.put(option, value); } + private static void warmUpifClient(Option option) { + if(option == Option.HTTPCLIENT || option == Option.ASYNCHTTPCLIENT){ + isRunning = true; + } + } + private static void validateOption(Option option) { if ((option == Option.CONNECTION_TIMEOUT || option == Option.SOCKET_TIMEOUT) && customClientSet) { throw new RuntimeException( diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index 922b28f70..5bdf6cfbd 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -8,19 +8,23 @@ import io.github.openunirest.http.utils.SyncIdleConnectionMonitorThread; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; +import org.junit.Before; import org.junit.Test; import java.io.IOException; import static io.github.openunirest.http.Unirest.get; import static io.github.openunirest.http.options.Option.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import static org.mockito.Mockito.*; public class LifeCycleTest extends BddTest { + @Before + public void setUp() { + MockServer.reset(); + } + @Test public void settingACustomClient() { HttpClientMock httpClientMock = new HttpClientMock(); From 9c402547655c7b2a12e0bb475e990dc8776f6644 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 22 Nov 2018 07:54:13 -0600 Subject: [PATCH 0282/1769] avoid needing to do a init and let custom clients get set. Closes #42 --- .../io/github/openunirest/http/Unirest.java | 1 - .../openunirest/http/options/Option.java | 1 + .../openunirest/http/options/Options.java | 498 +++++++++--------- src/test/java/BehaviorTests/BddTest.java | 2 +- .../java/BehaviorTests/LifeCycleTest.java | 14 +- .../java/BehaviorTests/RequestCapture.java | 4 + .../openunirest/http/options/OptionsTest.java | 4 +- 7 files changed, 274 insertions(+), 250 deletions(-) diff --git a/src/main/java/io/github/openunirest/http/Unirest.java b/src/main/java/io/github/openunirest/http/Unirest.java index ae20e586a..885e2d224 100644 --- a/src/main/java/io/github/openunirest/http/Unirest.java +++ b/src/main/java/io/github/openunirest/http/Unirest.java @@ -47,7 +47,6 @@ public class Unirest { */ public static void setHttpClient(HttpClient httpClient) { Options.setOption(Option.HTTPCLIENT, httpClient); - Options.customClientSet(); } /** diff --git a/src/main/java/io/github/openunirest/http/options/Option.java b/src/main/java/io/github/openunirest/http/options/Option.java index 5f8504b59..79f9a066d 100644 --- a/src/main/java/io/github/openunirest/http/options/Option.java +++ b/src/main/java/io/github/openunirest/http/options/Option.java @@ -7,6 +7,7 @@ public enum Option { SOCKET_TIMEOUT, DEFAULT_HEADERS, SYNC_MONITOR(false), + CONNECTION_MONITOR(false), ASYNC_MONITOR(false), MAX_TOTAL, MAX_PER_ROUTE, diff --git a/src/main/java/io/github/openunirest/http/options/Options.java b/src/main/java/io/github/openunirest/http/options/Options.java index 5d51c82c0..530cffb77 100644 --- a/src/main/java/io/github/openunirest/http/options/Options.java +++ b/src/main/java/io/github/openunirest/http/options/Options.java @@ -19,246 +19,264 @@ import java.io.IOException; import java.util.*; -import static io.github.openunirest.http.options.Option.COOKIE_MANAGEMENT; -import static io.github.openunirest.http.options.Option.FOLLOW_REDIRECTS; +import static io.github.openunirest.http.options.Option.*; public class Options { - public static final int MAX_TOTAL = 200; - public static final int MAX_PER_ROUTE = 20; - public static final int CONNECTION_TIMEOUT = 10000; - public static final int SOCKET_TIMEOUT = 60000; - - private static boolean customClientSet = false; - private static boolean isRunning = false; - private static Map options = new HashMap<>(); - private static PoolingHttpClientConnectionManager syncConnectionManager; - private static SyncIdleConnectionMonitorThread defaultSyncMonitor; - private static List interceptors = new ArrayList<>(); - - public static void customClientSet() { - customClientSet = true; - } - - private static void setIfAbsent(Option option, Object value) { - validateOption(option); - options.putIfAbsent(option, value); - } - - public static void setOption(Option option, Object value) { - validateOption(option); - warmUpifClient(option); - options.put(option, value); - } - - private static void warmUpifClient(Option option) { - if(option == Option.HTTPCLIENT || option == Option.ASYNCHTTPCLIENT){ - isRunning = true; - } - } - - private static void validateOption(Option option) { - if ((option == Option.CONNECTION_TIMEOUT || option == Option.SOCKET_TIMEOUT) && customClientSet) { - throw new RuntimeException( - "You can't set custom timeouts when providing custom client implementations. " + - "Set the timeouts directly in your custom client configuration instead." - ); - } - } - - public static Object getOption(Option option) { - warmUp(); - return options.get(option); - } - - private static void warmUp() { - if(!isRunning()){ - init(); - } - } - - private static T getOptionOrDefault(Option option, T defaultValue){ - warmUp(); - return (T)options.computeIfAbsent(option, o -> defaultValue); - } - - private static void createMonitors() { - syncConnectionManager = new PoolingHttpClientConnectionManager(); - defaultSyncMonitor = new SyncIdleConnectionMonitorThread(syncConnectionManager); - defaultSyncMonitor.start(); - setOption(Option.SYNC_MONITOR, defaultSyncMonitor); - isRunning = true; - } - - - public static void refresh() { - if(syncConnectionManager == null){ - createMonitors(); - } - RequestConfig clientConfig = getRequestConfig(); - - Integer maxTotal = getOptionOrDefault(Option.MAX_TOTAL, MAX_TOTAL); - Integer maxPerRoute = getOptionOrDefault(Option.MAX_PER_ROUTE, MAX_PER_ROUTE); - syncConnectionManager.setMaxTotal(maxTotal); - syncConnectionManager.setDefaultMaxPerRoute(maxPerRoute); - - buildHttpClient(clientConfig); - - PoolingNHttpClientConnectionManager asyncConnectionManager; - try { - asyncConnectionManager = new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor()); - asyncConnectionManager.setMaxTotal(maxTotal); - asyncConnectionManager.setDefaultMaxPerRoute(maxPerRoute); - } catch (IOReactorException e) { - throw new RuntimeException(e); - } - - CloseableHttpAsyncClient asyncClient = buildAsyncClient(clientConfig, asyncConnectionManager); - - setOption(Option.ASYNCHTTPCLIENT, asyncClient); - setOption(Option.ASYNC_MONITOR, new AsyncIdleConnectionMonitorThread(asyncConnectionManager)); - } - - private static CloseableHttpAsyncClient buildAsyncClient(RequestConfig clientConfig, PoolingNHttpClientConnectionManager asyncConnectionManager) { - HttpAsyncClientBuilder ab = HttpAsyncClientBuilder.create() - .setDefaultRequestConfig(clientConfig) - .setConnectionManager(asyncConnectionManager) - .useSystemProperties(); - if(shouldDisableRedirects()){ - ab.setRedirectStrategy(new NoRedirects()); - } - if(shouldDisableCookieManagement()){ - ab.disableCookieManagement(); - } - interceptors.stream().forEach(i -> ab.addInterceptorFirst(i)); - return ab.build(); - } - - private static void buildHttpClient(RequestConfig clientConfig) { - // Create clients - HttpClientBuilder cb = HttpClientBuilder.create() - .setDefaultRequestConfig(clientConfig) - .setConnectionManager(syncConnectionManager) - .useSystemProperties(); - if(shouldDisableRedirects()){ - cb.disableRedirectHandling(); - } - if(shouldDisableCookieManagement()){ - cb.disableCookieManagement(); - } - interceptors.stream().forEach(i -> cb.addInterceptorFirst(i)); - CloseableHttpClient build = cb.build(); - - setOption(Option.HTTPCLIENT, build); - } - - private static boolean shouldDisableCookieManagement() { - return !(Boolean)options.getOrDefault(COOKIE_MANAGEMENT, true); - } - - private static boolean shouldDisableRedirects() { - return !(Boolean)options.getOrDefault(FOLLOW_REDIRECTS, true); - } - - private static RequestConfig getRequestConfig() { - Integer connectionTimeout = getOptionOrDefault(Option.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT); - Integer socketTimeout = getOptionOrDefault(Option.SOCKET_TIMEOUT, SOCKET_TIMEOUT); - HttpHost proxy = (HttpHost) Options.getOption(Option.PROXY); - return RequestConfig.custom() - .setConnectTimeout(connectionTimeout) - .setSocketTimeout(socketTimeout) - .setConnectionRequestTimeout(socketTimeout) - .setProxy(proxy) - .build(); - } - - public static void init() { - createMonitors(); - setDefaults(); - refresh(); - } - - private static void setDefaults() { - customClientSet = false; - setIfAbsent(Option.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT); - setIfAbsent(Option.SOCKET_TIMEOUT, SOCKET_TIMEOUT); - setIfAbsent(Option.MAX_TOTAL, MAX_TOTAL); - setIfAbsent(Option.MAX_PER_ROUTE, MAX_PER_ROUTE); - setIfAbsent(Option.SYNC_MONITOR, defaultSyncMonitor); - } - - public static Optional tryGet(Option option, Class as) { - Object o = getOption(option); - if(Objects.isNull(o) || !as.isAssignableFrom(o.getClass())){ - return Optional.empty(); - } - return Optional.of((T) o); - } - - public static void removeOption(Option objectMapper) { - options.remove(objectMapper); - } - - public static boolean isRunning() { - return isRunning; - } - - public static void shutDown(){ - shutDown(true); - } - - public static void shutDown(boolean clearOptions) { - tryGet(Option.HTTPCLIENT, - CloseableHttpClient.class) - .ifPresent(Options::closeIt); - options.remove(Option.HTTPCLIENT); - - tryGet(Option.SYNC_MONITOR, - SyncIdleConnectionMonitorThread.class) - .ifPresent(Thread::interrupt); - options.remove(Option.SYNC_MONITOR); - - tryGet(Option.ASYNCHTTPCLIENT, - CloseableHttpAsyncClient.class) - .filter(CloseableHttpAsyncClient::isRunning) - .ifPresent(Options::closeIt); - options.remove(Option.ASYNCHTTPCLIENT); - - tryGet(Option.ASYNC_MONITOR, - AsyncIdleConnectionMonitorThread.class) - .ifPresent(Thread::interrupt); - options.remove(Option.ASYNC_MONITOR); - - if(clearOptions){ - options.clear(); - interceptors.clear(); - } - isRunning = false; - } - - public static void closeIt(Closeable c) { - try { - c.close(); - }catch (IOException e){ - throw new UnirestException(e); - } - } - - public static void addInterceptor(HttpRequestInterceptor interceptor) { - interceptors.add(interceptor); - refresh(); - } - - public static void followRedirects(boolean enable) { - options.put(FOLLOW_REDIRECTS, enable); - refresh(); - } - - public static void enableCookieManagement(boolean enable){ - options.put(COOKIE_MANAGEMENT, enable); - refresh(); - } - - public static List getInterceptors() { - return interceptors; - } + public static final int MAX_TOTAL = 200; + public static final int MAX_PER_ROUTE = 20; + public static final int CONNECTION_TIMEOUT = 10000; + public static final int SOCKET_TIMEOUT = 60000; + + private static boolean customClientSet = false; + private static boolean customAsyncClientSet = false; + private static Map options = new HashMap<>(); + private static List interceptors = new ArrayList<>(); + + static { + setDefaults(); + } + + public static void customClientSet() { + customClientSet = true; + } + + private static void setIfAbsent(Option option, Object value) { + validateOption(option); + options.putIfAbsent(option, value); + } + + public static void setOption(Option option, Object value) { + validateOption(option); + flagClients(option); + options.put(option, value); + } + + private static void flagClients(Option option) { + if(option == Option.HTTPCLIENT){ + customClientSet = true; + } else if (option == Option.ASYNCHTTPCLIENT){ + customAsyncClientSet = true; + } + } + + private static void warmUpifClient(Option option) { + if (isOptionNotSet(option, Option.HTTPCLIENT)) { + customClientSet = false; + buildHttpClient(); + } else if (isOptionNotSet(option, Option.ASYNCHTTPCLIENT)) { + customAsyncClientSet = false; + buildAsyncClient(); + } + } + + private static boolean isOptionNotSet(Option o, Option expected){ + return o == expected && options.get(o) == null; + } + + private static void validateOption(Option option) { + if ((option == Option.CONNECTION_TIMEOUT || option == Option.SOCKET_TIMEOUT) && customClientSet) { + throw new RuntimeException( + "You can't set custom timeouts when providing custom client implementations. " + + "Set the timeouts directly in your custom client configuration instead." + ); + } + } + + public static Object getOption(Option option) { + warmUpifClient(option); + return options.get(option); + } + + + private static T getOptionOrDefault(Option option, T defaultValue) { + return (T) options.computeIfAbsent(option, o -> defaultValue); + } + + + public static void refresh() { + if (!customClientSet) { + buildHttpClient(); + } + if (!customAsyncClientSet) { + buildAsyncClient(); + } + } + + private static synchronized CloseableHttpAsyncClient buildAsyncClient() { + PoolingNHttpClientConnectionManager asyncConnectionManager; + try { + asyncConnectionManager = new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor()); + asyncConnectionManager.setMaxTotal(getOptionOrDefault(Option.MAX_TOTAL, MAX_TOTAL)); + asyncConnectionManager.setDefaultMaxPerRoute(getOptionOrDefault(Option.MAX_PER_ROUTE, MAX_PER_ROUTE)); + } catch (IOReactorException e) { + throw new RuntimeException(e); + } + + HttpAsyncClientBuilder ab = HttpAsyncClientBuilder.create() + .setDefaultRequestConfig(getRequestConfig()) + .setConnectionManager(asyncConnectionManager) + .useSystemProperties(); + if (shouldDisableRedirects()) { + ab.setRedirectStrategy(new NoRedirects()); + } + if (shouldDisableCookieManagement()) { + ab.disableCookieManagement(); + } + interceptors.stream().forEach(i -> ab.addInterceptorFirst(i)); + CloseableHttpAsyncClient build = ab.build(); + + options.put(Option.ASYNCHTTPCLIENT, build); + options.put(Option.ASYNC_MONITOR, new AsyncIdleConnectionMonitorThread(asyncConnectionManager)); + return build; + } + + private static synchronized void buildHttpClient() { + PoolingHttpClientConnectionManager syncman = getSyncMonitor(); + + // Create clients + HttpClientBuilder cb = HttpClientBuilder.create() + .setDefaultRequestConfig(getRequestConfig()) + .setConnectionManager(syncman) + .useSystemProperties(); + if (shouldDisableRedirects()) { + cb.disableRedirectHandling(); + } + if (shouldDisableCookieManagement()) { + cb.disableCookieManagement(); + } + interceptors.stream().forEach(i -> cb.addInterceptorFirst(i)); + CloseableHttpClient build = cb.build(); + + options.put(Option.HTTPCLIENT, build); + } + + private static PoolingHttpClientConnectionManager getSyncMonitor() { + PoolingHttpClientConnectionManager conman = (PoolingHttpClientConnectionManager)options.get(CONNECTION_MONITOR); + if(conman != null){ + return conman; + } + + conman = new PoolingHttpClientConnectionManager(); + conman.setMaxTotal(getOptionOrDefault(Option.MAX_TOTAL, MAX_TOTAL)); + conman.setDefaultMaxPerRoute(getOptionOrDefault(Option.MAX_PER_ROUTE, MAX_PER_ROUTE)); + + SyncIdleConnectionMonitorThread defaultSyncMonitor = new SyncIdleConnectionMonitorThread(conman); + defaultSyncMonitor.start(); + options.put(Option.SYNC_MONITOR, defaultSyncMonitor); + options.put(Option.CONNECTION_MONITOR, conman); + return conman; + } + + private static boolean shouldDisableCookieManagement() { + return !(Boolean) options.getOrDefault(COOKIE_MANAGEMENT, true); + } + + private static boolean shouldDisableRedirects() { + return !(Boolean) options.getOrDefault(FOLLOW_REDIRECTS, true); + } + + private static RequestConfig getRequestConfig() { + Integer connectionTimeout = getOptionOrDefault(Option.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT); + Integer socketTimeout = getOptionOrDefault(Option.SOCKET_TIMEOUT, SOCKET_TIMEOUT); + HttpHost proxy = (HttpHost) Options.getOption(Option.PROXY); + return RequestConfig.custom() + .setConnectTimeout(connectionTimeout) + .setSocketTimeout(socketTimeout) + .setConnectionRequestTimeout(socketTimeout) + .setProxy(proxy) + .build(); + } + + @Deprecated + public static void init() { + setDefaults(); + refresh(); + } + + private static void setDefaults() { + customClientSet = false; + customAsyncClientSet = false; + setIfAbsent(Option.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT); + setIfAbsent(Option.SOCKET_TIMEOUT, SOCKET_TIMEOUT); + setIfAbsent(Option.MAX_TOTAL, MAX_TOTAL); + setIfAbsent(Option.MAX_PER_ROUTE, MAX_PER_ROUTE); + } + + public static Optional tryGet(Option option, Class as) { + Object o = getOption(option); + if (Objects.isNull(o) || !as.isAssignableFrom(o.getClass())) { + return Optional.empty(); + } + return Optional.of((T) o); + } + + public static void removeOption(Option objectMapper) { + options.remove(objectMapper); + } + + public static boolean isRunning() { + return options.get(HTTPCLIENT) != null || options.get(ASYNCHTTPCLIENT) != null; + } + + public static void shutDown() { + shutDown(true); + } + + public static void shutDown(boolean clearOptions) { + tryGet(Option.HTTPCLIENT, + CloseableHttpClient.class) + .ifPresent(Options::closeIt); + options.remove(Option.HTTPCLIENT); + + tryGet(Option.SYNC_MONITOR, + SyncIdleConnectionMonitorThread.class) + .ifPresent(Thread::interrupt); + options.remove(Option.SYNC_MONITOR); + + tryGet(Option.ASYNCHTTPCLIENT, + CloseableHttpAsyncClient.class) + .filter(CloseableHttpAsyncClient::isRunning) + .ifPresent(Options::closeIt); + options.remove(Option.ASYNCHTTPCLIENT); + + tryGet(Option.ASYNC_MONITOR, + AsyncIdleConnectionMonitorThread.class) + .ifPresent(Thread::interrupt); + options.remove(Option.ASYNC_MONITOR); + + if (clearOptions) { + options.clear(); + interceptors.clear(); + setDefaults(); + } + customAsyncClientSet = false; + customClientSet = false; + } + + public static void closeIt(Closeable c) { + try { + c.close(); + } catch (IOException e) { + throw new UnirestException(e); + } + } + + public static void addInterceptor(HttpRequestInterceptor interceptor) { + interceptors.add(interceptor); + refresh(); + } + + public static void followRedirects(boolean enable) { + options.put(FOLLOW_REDIRECTS, enable); + refresh(); + } + + public static void enableCookieManagement(boolean enable) { + options.put(COOKIE_MANAGEMENT, enable); + refresh(); + } + + public static List getInterceptors() { + return interceptors; + } } diff --git a/src/test/java/BehaviorTests/BddTest.java b/src/test/java/BehaviorTests/BddTest.java index 8fcd41313..620857f3e 100644 --- a/src/test/java/BehaviorTests/BddTest.java +++ b/src/test/java/BehaviorTests/BddTest.java @@ -24,7 +24,7 @@ public class BddTest { public void setUp() { //TestUtil.debugApache(); MockServer.reset(); - Options.init(); + Unirest.shutdown(); Unirest.setObjectMapper(objectMapper); lock = new CountDownLatch(1); status = false; diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index 5bdf6cfbd..d8f2baf3b 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -12,6 +12,7 @@ import org.junit.Test; import java.io.IOException; +import java.util.concurrent.ExecutionException; import static io.github.openunirest.http.Unirest.get; import static io.github.openunirest.http.options.Option.*; @@ -20,13 +21,8 @@ public class LifeCycleTest extends BddTest { - @Before - public void setUp() { - MockServer.reset(); - } - @Test - public void settingACustomClient() { + public void settingACustomClient() throws ExecutionException, InterruptedException { HttpClientMock httpClientMock = new HttpClientMock(); httpClientMock.onGet("http://localhost/getme").doReturn(202, "Howdy Ho!"); @@ -35,6 +31,12 @@ public void settingACustomClient() { assertEquals(202, result.getStatus()); assertEquals("Howdy Ho!", result.getBody()); + + Unirest.get(MockServer.GET) + .asObjectAsync(RequestCapture.class) + .get() + .getBody() + .assertOk(); } @Test diff --git a/src/test/java/BehaviorTests/RequestCapture.java b/src/test/java/BehaviorTests/RequestCapture.java index f2b6c7a6a..4714a6b79 100644 --- a/src/test/java/BehaviorTests/RequestCapture.java +++ b/src/test/java/BehaviorTests/RequestCapture.java @@ -193,6 +193,10 @@ public void setPatch(JsonPatch patch) { this.jsonPatches = patch; } + public void assertOk() { + assertTrue(url.length() > 0); + } + public static class File { public String fileName; public String type; diff --git a/src/test/java/io/github/openunirest/http/options/OptionsTest.java b/src/test/java/io/github/openunirest/http/options/OptionsTest.java index 0bcd1d33d..6c205b50e 100644 --- a/src/test/java/io/github/openunirest/http/options/OptionsTest.java +++ b/src/test/java/io/github/openunirest/http/options/OptionsTest.java @@ -26,12 +26,12 @@ public void before(){ @Test public void shouldKeepConnectionTimeOutDefault(){ - assertOpDefault(Options.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT, 4L); + assertOpDefault(Options.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT, 4); } @Test public void shouldKeepSocketTimeoutDefault(){ - assertOpDefault(Options.SOCKET_TIMEOUT, Option.SOCKET_TIMEOUT, 4L); + assertOpDefault(Options.SOCKET_TIMEOUT, Option.SOCKET_TIMEOUT, 4); } @Test From 5724aac5a9f48dfb335c850513b698ea1b66134a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 22 Nov 2018 07:55:56 -0600 Subject: [PATCH 0283/1769] [maven-release-plugin] prepare release v2.5.03 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 0ee8a5664..33ce52432 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.5.03-SNAPSHOT + 2.5.03 unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v2.5.03 From dc3ec0da6b5e988ea89d210fd7a12bafd0c7f41b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 22 Nov 2018 07:56:03 -0600 Subject: [PATCH 0284/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 33ce52432..318370aad 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest unirest-java jar - 2.5.03 + 2.5.04-SNAPSHOT unirest-java Simplified, lightweight HTTP client library http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v2.5.03 + HEAD From 46f86b51f6548cb2a005fa2b809d9b7454e89cf7 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 22 Nov 2018 08:09:19 -0600 Subject: [PATCH 0285/1769] bring back this useful test from the old options --- src/test/java/BehaviorTests/LifeCycleTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index acc949b8a..3d2833a98 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -38,7 +38,11 @@ import org.junit.Test; import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.util.stream.IntStream; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.Matchers.lessThan; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -178,4 +182,11 @@ public void canGetTheCommonInstanceOfUnirest(){ assertNotSame(Unirest.primaryInstance(), Unirest.spawnInstance()); assertNotSame(Unirest.spawnInstance(), Unirest.spawnInstance()); } + + @Test + public void shouldReuseThreadPool() { + int startingCount = ManagementFactory.getThreadMXBean().getThreadCount(); + IntStream.range(0,100).forEach(i -> Unirest.config().reset()); + assertThat(ManagementFactory.getThreadMXBean().getThreadCount(), is(lessThan(startingCount + 10))); + } } From 8e248460f5e07d45c5fc560b0640d05361e7553f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 22 Nov 2018 08:39:38 -0600 Subject: [PATCH 0286/1769] update docs --- checkstyle.xml | 2 +- src/main/java/unirest/AsyncConfig.java | 2 +- src/main/java/unirest/ClientConfig.java | 2 +- src/main/java/unirest/Config.java | 131 ++++++++++++++------- src/main/java/unirest/Unirest.java | 65 +++++++++- src/main/java/unirest/UnirestInstance.java | 46 ++++++++ src/main/java/unirest/Util.java | 4 + 7 files changed, 202 insertions(+), 50 deletions(-) diff --git a/checkstyle.xml b/checkstyle.xml index 520740440..57b7f5bc3 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -62,7 +62,7 @@ - + diff --git a/src/main/java/unirest/AsyncConfig.java b/src/main/java/unirest/AsyncConfig.java index 26535d035..451bd6f47 100644 --- a/src/main/java/unirest/AsyncConfig.java +++ b/src/main/java/unirest/AsyncConfig.java @@ -54,7 +54,7 @@ public HttpAsyncClient getClient() { } public Stream close() { - return Config.collectExceptions(Util.tryCast(client, CloseableHttpAsyncClient.class) + return Util.collectExceptions(Util.tryCast(client, CloseableHttpAsyncClient.class) .filter(c -> c.isRunning()) .map(c -> Util.tryDo(c, d -> d.close())) .filter(c -> c.isPresent()) diff --git a/src/main/java/unirest/ClientConfig.java b/src/main/java/unirest/ClientConfig.java index 762358490..b61dba79a 100644 --- a/src/main/java/unirest/ClientConfig.java +++ b/src/main/java/unirest/ClientConfig.java @@ -62,7 +62,7 @@ public SyncIdleConnectionMonitorThread getSyncMonitor() { } public Stream close() { - return Config.collectExceptions(Util.tryCast(client, CloseableHttpClient.class) + return Util.collectExceptions(Util.tryCast(client, CloseableHttpClient.class) .map(c -> Util.tryDo(c, Closeable::close)) .filter(Optional::isPresent) .map(Optional::get), diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java index d58eae7ae..ffab23812 100644 --- a/src/main/java/unirest/Config.java +++ b/src/main/java/unirest/Config.java @@ -78,6 +78,7 @@ public Config(){ * Set the HttpClient implementation to use for every synchronous request * * @param httpClient Custom httpClient implementation + * @return this config object */ public Config httpClient(HttpClient httpClient) { client = Optional.of(new ClientConfig(httpClient, null, null)); @@ -88,6 +89,7 @@ public Config httpClient(HttpClient httpClient) { * Set the HttpClient implementation to use for every synchronous request * * @param httpClient Custom httpClient implementation + * @return this config object */ public Config httpClient(ClientConfig httpClient) { client = Optional.of(httpClient); @@ -98,6 +100,7 @@ public Config httpClient(ClientConfig httpClient) { * Set the asynchronous AbstractHttpAsyncClient implementation to use for every asynchronous request * * @param value Custom CloseableHttpAsyncClient implementation + * @return this config object */ public Config asyncClient(HttpAsyncClient value) { this.asyncClient = Optional.of(new AsyncConfig(value, null, null)); @@ -108,6 +111,7 @@ public Config asyncClient(HttpAsyncClient value) { * Set the full async configuration including monitors. These will be shutDown on a Unirest.shudown() * * @param value Custom AsyncConfig class. The actual AsyncHttpClient is required. + * @return this config object */ public Config asyncClient(AsyncConfig value) { asyncClient = Optional.of(value); @@ -118,6 +122,7 @@ public Config asyncClient(AsyncConfig value) { * Set a proxy * * @param value Proxy settings object. + * @return this config object */ public Config proxy(HttpHost value) { validateClientsNotRunning(); @@ -129,6 +134,7 @@ public Config proxy(HttpHost value) { * Set the ObjectMapper implementation to use for Response to Object binding * * @param om Custom implementation of ObjectMapper interface + * @return this config object */ public Config setObjectMapper(ObjectMapper om) { this.objectMapper = Optional.ofNullable(om); @@ -139,6 +145,7 @@ public Config setObjectMapper(ObjectMapper om) { * Set the connection timeout * * @param inMillies The timeout until a connection with the server is established (in milliseconds). Default is 10000. Set to zero to disable the timeout. + * @return this config object */ public Config connectTimeout(int inMillies) { validateClientsNotRunning(); @@ -150,6 +157,7 @@ public Config connectTimeout(int inMillies) { * Set the socket timeout * * @param inMillies The timeout to receive data (in milliseconds). Default is 60000. Set to zero to disable the timeout. + * @return this config object */ public Config socketTimeout(int inMillies) { validateClientsNotRunning(); @@ -162,6 +170,7 @@ public Config socketTimeout(int inMillies) { * * @param total Defines the overall connection limit for a connection pool. Default is 200. * @param perRoute Defines a connection limit per one HTTP route (this can be considered a per target host limit). Default is 20. + * @return this config object */ public Config concurrency(int total, int perRoute) { validateClientsNotRunning(); @@ -172,6 +181,7 @@ public Config concurrency(int total, int perRoute) { /** * Clear default headers + * @return this config object */ public Config clearDefaultHeaders() { defaultHeaders.clear(); @@ -183,6 +193,7 @@ public Config clearDefaultHeaders() { * * @param name The name of the header. * @param value The value of the header. + * @return this config object */ public Config setDefaultHeader(String name, String value) { defaultHeaders.add(name, value); @@ -194,6 +205,7 @@ public Config setDefaultHeader(String name, String value) { * https://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/HttpRequestInterceptor.html * * @param interceptor The addInterceptor + * @return this config object */ public Config addInterceptor(HttpRequestInterceptor interceptor) { validateClientsNotRunning(); @@ -205,6 +217,7 @@ public Config addInterceptor(HttpRequestInterceptor interceptor) { * Allow the client to follow redirects. Defaults to TRUE * * @param enable The name of the header. + * @return this config object */ public Config followRedirects(boolean enable) { validateClientsNotRunning(); @@ -216,6 +229,7 @@ public Config followRedirects(boolean enable) { * Allow the client to manage cookies. Defaults to TRUE * * @param enable The name of the header. + * @return this config object */ public Config enableCookieManagement(boolean enable) { validateClientsNotRunning(); @@ -223,6 +237,40 @@ public Config enableCookieManagement(boolean enable) { return this; } + /** + * Return default headers that are added to every request + * + * @return Headers + */ + public Headers getDefaultHeaders() { + return defaultHeaders; + } + + /** + * Does the config have currently running clients? Find out here. + * + * @return boolean + */ + public boolean isRunning() { + return client.isPresent() || asyncClient.isPresent(); + } + + /** + * Shutdown the current config and re-init. + * + * @return this config + */ + public Config reset() { + shutDown(false); + return this; + } + + /** + * Shut down the configuration and its clients. + * The config can be re-initialized with its settings + * + * @param clearOptions should the current non-client settings be retained. + */ public void shutDown(boolean clearOptions) { List ex = Stream.concat( client.map(ClientConfig::close).orElseGet(Stream::empty), @@ -241,6 +289,45 @@ public void shutDown(boolean clearOptions) { } } + /** + * Return the current HttpClient. One will be build if it does + * not yet exist. + * + * @return Apache HttpClient + */ + public HttpClient getClient() { + if (!client.isPresent()) { + buildClient(); + } + return client.get().getClient(); + } + + private synchronized void buildClient() { + if (!client.isPresent()) { + client = Optional.of(factory.buildHttpClient()); + } + } + + /** + * Return the current HttpAsyncClient. One will be build if it does + * not yet exist. + * + * @return Apache HttpAsyncClient + */ + public HttpAsyncClient getAsyncHttpClient() { + if (!asyncClient.isPresent()) { + buildAsyncClient(); + } + return asyncClient.get().getClient(); + } + + private synchronized void buildAsyncClient() { + if (!asyncClient.isPresent()) { + AsyncConfig value = factory.buildAsyncClient(); + asyncClient = Optional.of(value); + } + } + // Accessors for unirest. boolean getEnabledCookieManagement() { return cookieManagement; @@ -279,33 +366,6 @@ private void validateClientsNotRunning() { } } - public HttpClient getClient() { - if (!client.isPresent()) { - buildClient(); - } - return client.get().getClient(); - } - - private synchronized void buildClient() { - if (!client.isPresent()) { - client = Optional.of(factory.buildHttpClient()); - } - } - - public HttpAsyncClient getAsyncHttpClient() { - if (!asyncClient.isPresent()) { - buildAsyncClient(); - } - return asyncClient.get().getClient(); - } - - private synchronized void buildAsyncClient() { - if (!asyncClient.isPresent()) { - AsyncConfig value = factory.buildAsyncClient(); - asyncClient = Optional.of(value); - } - } - List getInterceptors() { return interceptors; } @@ -313,21 +373,4 @@ List getInterceptors() { HttpHost getProxy() { return proxy; } - - public Headers getDefaultHeaders() { - return defaultHeaders; - } - - public boolean isRunning() { - return client.isPresent() || asyncClient.isPresent(); - } - - public static Stream collectExceptions(Optional... ex) { - return Stream.of(ex).flatMap(Util::stream); - } - - public Config reset() { - shutDown(false); - return this; - } } diff --git a/src/main/java/unirest/Unirest.java b/src/main/java/unirest/Unirest.java index 1ab979e75..22f6509cb 100644 --- a/src/main/java/unirest/Unirest.java +++ b/src/main/java/unirest/Unirest.java @@ -32,8 +32,9 @@ public class Unirest { /** * Access the default configuration for the primary Unirest instance. + * @return the config object of the primary instance */ - public static Config config(){ + public static Config config() { return primaryInstance.config(); } @@ -42,7 +43,7 @@ public static Config config(){ * This will also clear any options returning Unirest to a default state */ public static void shutDown() { - shutDown(true); + shutDown(true); } /** @@ -50,49 +51,107 @@ public static void shutDown() { * @param clearOptions indicates if options should be cleared. Note that the HttpClient, AsyncClient and thread monitors will not be retained after shutDown. */ public static void shutDown(boolean clearOptions) { - primaryInstance.shutDown(clearOptions); + primaryInstance.shutDown(clearOptions); } + /** + * Start a GET HttpRequest which does not support a body from the primary config + * @param url the endpoint to access. Can include placeholders for path params using curly braces {} + * @return A HttpRequest builder + */ public static GetRequest get(String url) { return primaryInstance.get(url); } + /** + * Start a HEAD HttpRequest which does not support a body from the primary config + * @param url the endpoint to access. Can include placeholders for path params using curly braces {} + * @return A HttpRequest builder + */ public static GetRequest head(String url) { return primaryInstance.head(url); } + /** + * Start a OPTIONS HttpRequest which does not support a body from the primary config + * @param url the endpoint to access. Can include placeholders for path params using curly braces {} + * @return A HttpRequest builder + */ public static GetRequest options(String url) { return primaryInstance.options(url); } + /** + * Start a POST HttpRequest which supports a body from the primary config + * @param url the endpoint to access. Can include placeholders for path params using curly braces {} + * @return A HttpRequest builder + */ public static HttpRequestWithBody post(String url) { return primaryInstance.post(url); } + /** + * Start a DELETE HttpRequest which supports a body from the primary config + * @param url the endpoint to access. Can include placeholders for path params using curly braces {} + * @return A HttpRequest builder + */ public static HttpRequestWithBody delete(String url) { return primaryInstance.delete(url); } + /** + * Start a PATCH HttpRequest which supports a body from the primary config + * @param url the endpoint to access. Can include placeholders for path params using curly braces {} + * @return A HttpRequest builder + */ public static HttpRequestWithBody patch(String url) { return primaryInstance.patch(url); } + /** + * Start a PUT HttpRequest which supports a body from the primary config + * @param url the endpoint to access. Can include placeholders for path params using curly braces {} + * @return A HttpRequest builder + */ public static HttpRequestWithBody put(String url) { return primaryInstance.put(url); } + /** + * Start a PATCH HttpRequest which supports a JSON Patch builder. + * this supports RFC-6902 https://tools.ietf.org/html/rfc6902 + * @param url the endpoint to access. Can include placeholders for path params using curly braces {} + * @return A HttpRequest builder + */ public static JsonPatchRequest jsonPatch(String url) { return primaryInstance.jsonPatch(url); } + /** + * Does the config have currently running clients? Find out here. + * + * @return boolean + */ public static boolean isRunning() { return primaryInstance.isRunning(); } + /** + * Spawn a new Unirest Instance with a new config. + * Don't forget to shut it down when your done. + * It will not be tracked and shutdown with Unirest.shutDown() + * + * @return a new UnirestInstance + */ public static UnirestInstance spawnInstance() { return new UnirestInstance(new Config()); } + /** + * return the primary UnirestInstance. + * + * @return a new UnirestInstance + */ public static UnirestInstance primaryInstance() { return primaryInstance; } diff --git a/src/main/java/unirest/UnirestInstance.java b/src/main/java/unirest/UnirestInstance.java index 3b5044193..93e6b7ea4 100644 --- a/src/main/java/unirest/UnirestInstance.java +++ b/src/main/java/unirest/UnirestInstance.java @@ -57,38 +57,84 @@ public void shutDown(boolean clearOptions) { config.shutDown(clearOptions); } + /** + * Start a GET HttpRequest which does not support a body from the primary config + * @param url the endpoint to access. Can include placeholders for path params using curly braces {} + * @return A HttpRequest builder + */ public GetRequest get(String url) { return new HttpRequestNoBody(config, HttpMethod.GET, url); } + /** + * Start a HEAD HttpRequest which does not support a body from the primary config + * @param url the endpoint to access. Can include placeholders for path params using curly braces {} + * @return A HttpRequest builder + */ public GetRequest head(String url) { return new HttpRequestNoBody(config, HttpMethod.HEAD, url); } + /** + * Start a OPTIONS HttpRequest which does not support a body from the primary config + * @param url the endpoint to access. Can include placeholders for path params using curly braces {} + * @return A HttpRequest builder + */ public GetRequest options(String url) { return new HttpRequestNoBody(config, HttpMethod.OPTIONS, url); } + /** + * Start a POST HttpRequest which supports a body from the primary config + * @param url the endpoint to access. Can include placeholders for path params using curly braces {} + * @return A HttpRequest builder + */ public HttpRequestWithBody post(String url) { return new HttpRequestBody(config, HttpMethod.POST, url); } + /** + * Start a DELETE HttpRequest which supports a body from the primary config + * @param url the endpoint to access. Can include placeholders for path params using curly braces {} + * @return A HttpRequest builder + */ public HttpRequestWithBody delete(String url) { return new HttpRequestBody(config, HttpMethod.DELETE, url); } + /** + * Start a PATCH HttpRequest which supports a body from the primary config + * @param url the endpoint to access. Can include placeholders for path params using curly braces {} + * @return A HttpRequest builder + */ public HttpRequestWithBody patch(String url) { return new HttpRequestBody(config, HttpMethod.PATCH, url); } + /** + * Start a PUT HttpRequest which supports a body from the primary config + * @param url the endpoint to access. Can include placeholders for path params using curly braces {} + * @return A HttpRequest builder + */ public HttpRequestWithBody put(String url) { return new HttpRequestBody(config, HttpMethod.PUT, url); } + /** + * Start a PATCH HttpRequest which supports a JSON Patch builder. + * this supports RFC-6902 https://tools.ietf.org/html/rfc6902 + * @param url the endpoint to access. Can include placeholders for path params using curly braces {} + * @return A HttpRequest builder + */ public JsonPatchRequest jsonPatch(String url) { return new HttpRequestJsonPatch(config, url); } + /** + * Does the config have currently running clients? Find out here. + * + * @return boolean + */ public boolean isRunning() { return config.isRunning(); } diff --git a/src/main/java/unirest/Util.java b/src/main/java/unirest/Util.java index 795d34895..5bdbd1383 100644 --- a/src/main/java/unirest/Util.java +++ b/src/main/java/unirest/Util.java @@ -82,6 +82,10 @@ static List getList(Collection parameters) { return result; } + static Stream collectExceptions(Optional... ex) { + return Stream.of(ex).flatMap(Util::stream); + } + @FunctionalInterface public interface ExConsumer{ From fbaafe294b08dff882be9b933127b4196f11454c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 22 Nov 2018 11:24:53 -0600 Subject: [PATCH 0287/1769] change the artifact id because this is in no way backwards compatible with the old version --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index fb9201abf..af583a72e 100644 --- a/pom.xml +++ b/pom.xml @@ -2,11 +2,11 @@ 4.0.0 io.github.openunirest - unirest-java + open-unirest-java jar 3.0.00-SNAPSHOT unirest-java - Simplified, lightweight HTTP client library + Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ From ad933d74a437246d606a4fd7157e7392ed5a52c0 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 22 Nov 2018 11:30:56 -0600 Subject: [PATCH 0288/1769] [maven-release-plugin] prepare release v3.0.00 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index af583a72e..19c573a93 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.0.00-SNAPSHOT + 3.0.00 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.0.00 From 18a0e91ad1ff02a6312235312ab1fbd6d3a9de5e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 22 Nov 2018 11:31:06 -0600 Subject: [PATCH 0289/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 19c573a93..980360ab2 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.0.00 + 3.0.01-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.0.00 + HEAD From 832d4ddee3c450d578c3ed0b9030bcd2a450bc9b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 22 Nov 2018 11:38:02 -0600 Subject: [PATCH 0290/1769] update readme --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index dd448c137..5b868ee9d 100644 --- a/README.md +++ b/README.md @@ -9,15 +9,19 @@ This repo is an updated, maintained, and independent fork of the original Mashap ##### See the [UPGRADE_GUIDE](UPGRADE_GUIDE.md) for differences between this library and last kong release. -## Install With [Maven](https://mvnrepository.com/artifact/io.github.openunirest/unirest-java) +## Install With [Maven](https://mvnrepository.com/artifact/io.github.openunirest/open-unirest-java) ``` io.github.openunirest - unirest-java - 2.5.01 + open-unirest-java + 3.0.00 ``` +#### Note on 2.x +Because 3.0 made several very not backwards compatible changes the artifactID was changed. The 2.0 line is still available [Here](https://mvnrepository.com/artifact/io.github.openunirest/unirest-java). Security patches and major defects will still be patched on it until 2020. + + ## Features * Make `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `HEAD`, `OPTIONS` requests From 6aa134f6a29aaae97d7b23ef33705b45a5e34086 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 22 Nov 2018 11:42:08 -0600 Subject: [PATCH 0291/1769] update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7dedad707..1a2148b81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,12 @@ * Accept and ContentType are now 1st class headers in the builder (```Unirest.get(path).accept("application/json")```) * Major internal fixes so that which builder operations were available when is consistent. +## 2.5.03 +* Lazy init the HttpClients so they don't get in the way of setting custom clients. + +## 2.5.02 +* More safety for issue #41 + ## 2.5.01 * Fix Issue #41: possible init error in HttpClient under heavy load From 78bf1463b8ef63852304cef08c19ab291708ca92 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 23 Nov 2018 07:42:01 -0600 Subject: [PATCH 0292/1769] Update UPGRADE_GUIDE.md --- UPGRADE_GUIDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UPGRADE_GUIDE.md b/UPGRADE_GUIDE.md index 2caa62085..f75bdfc41 100644 --- a/UPGRADE_GUIDE.md +++ b/UPGRADE_GUIDE.md @@ -1,4 +1,4 @@ -## Upgrading to Open Uirest 3.0 from previous versions +## Upgrading to Open Unirest 3.0 from previous versions ### Package Inspired by the "Java Spark" project, all classes are now in the ```unirest``` package. This project only has 45 files, it really doesn't need anything more complicated than that. From a6a9580b58aec6e968afe9a68ea2409f40f42314 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 23 Nov 2018 07:30:03 -0600 Subject: [PATCH 0293/1769] get the clients in the test to test for thread leaks --- src/test/java/BehaviorTests/LifeCycleTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index 3d2833a98..38aba664e 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -186,7 +186,10 @@ public void canGetTheCommonInstanceOfUnirest(){ @Test public void shouldReuseThreadPool() { int startingCount = ManagementFactory.getThreadMXBean().getThreadCount(); - IntStream.range(0,100).forEach(i -> Unirest.config().reset()); + IntStream.range(0,100).forEach(i -> { + Unirest.config().reset().getClient(); + Unirest.config().getAsyncHttpClient(); + }); assertThat(ManagementFactory.getThreadMXBean().getThreadCount(), is(lessThan(startingCount + 10))); } } From a19f7edd05f0c58813bc5f8673875f3ab76a6eff Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 25 Nov 2018 07:42:47 -0600 Subject: [PATCH 0294/1769] make a janky proxy server so testing different proxy configs is possible --- src/main/java/unirest/Callback.java | 1 - src/test/java/BehaviorTests/JankyProxy.java | 151 ++++++++++++++++++ src/test/java/BehaviorTests/MockServer.java | 13 ++ src/test/java/BehaviorTests/ProxyTest.java | 59 +++++++ .../java/BehaviorTests/RequestCapture.java | 18 +++ 5 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 src/test/java/BehaviorTests/JankyProxy.java create mode 100644 src/test/java/BehaviorTests/ProxyTest.java diff --git a/src/main/java/unirest/Callback.java b/src/main/java/unirest/Callback.java index cd57bf9d8..ad22d6c77 100644 --- a/src/main/java/unirest/Callback.java +++ b/src/main/java/unirest/Callback.java @@ -27,7 +27,6 @@ package unirest; public interface Callback { - void completed(HttpResponse response); default void failed(UnirestException e){} diff --git a/src/test/java/BehaviorTests/JankyProxy.java b/src/test/java/BehaviorTests/JankyProxy.java new file mode 100644 index 000000000..017a59ba9 --- /dev/null +++ b/src/test/java/BehaviorTests/JankyProxy.java @@ -0,0 +1,151 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package BehaviorTests; + +import java.io.*; +import java.net.*; +/** + * + * @author jcgonzalez.com + * + */ +public class JankyProxy { + public static ThreadProxy thread; + public static void runServer(String host, int remoteport, int localport) { + try { + // and the local port that we listen for connections on + // Print a start-up message + System.out.println("Starting proxy for " + host + ":" + remoteport + + " on port " + localport); + ServerSocket server = new ServerSocket(localport); + thread = new ThreadProxy(server, host, remoteport); + } catch (Exception e) { + System.err.println(e); + System.err.println("Usage: java ProxyMultiThread " + + " "); + } + } + + public static boolean wasUsed(){ + return thread.wasUsedForClientToServer; + } + + public static void shutdown(){ + if(thread != null){ + try { + thread.interrupt(); + }catch (Exception e){ + e.printStackTrace(); + } + } + } +} +/** + * Handles a socket connection to the proxy server from the client and uses 2 + * threads to proxy between server and client + * + * @author jcgonzalez.com + * + */ +class ThreadProxy extends Thread { + private Socket sClient; + private ServerSocket socket; + private final String SERVER_URL; + private final int SERVER_PORT; + public boolean wasUsedForClientToServer; + + ThreadProxy(ServerSocket socket, String ServerUrl, int ServerPort) { + this.SERVER_URL = ServerUrl; + this.SERVER_PORT = ServerPort; + this.socket = socket; + this.start(); + } + @Override + public void run() { + try { + sClient = socket.accept(); + final byte[] request = new byte[1024]; + byte[] reply = new byte[4096]; + final InputStream inFromClient = sClient.getInputStream(); + final OutputStream outToClient = sClient.getOutputStream(); + Socket client = null, server = null; + // connects a socket to the server + try { + server = new Socket(SERVER_URL, SERVER_PORT); + } catch (IOException e) { + PrintWriter out = new PrintWriter(new OutputStreamWriter(outToClient)); + out.flush(); + System.out.println("SERVER_URL = " + SERVER_URL + " : " + SERVER_PORT); + throw new RuntimeException(e); + } + // a new thread to manage streams from server to client (DOWNLOAD) + final InputStream inFromServer = server.getInputStream(); + final OutputStream outToServer = server.getOutputStream(); + // a new thread for uploading to the server + new Thread(() -> { + int bytes_read; + try { + while ((bytes_read = inFromClient.read(request)) != -1) { + outToServer.write(request, 0, bytes_read); + outToServer.flush(); + wasUsedForClientToServer = true; + } + } catch (IOException e) { + } + try { + outToServer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + }).start(); + // current thread manages streams from server to client (DOWNLOAD) + int bytes_read; + try { + while ((bytes_read = inFromServer.read(reply)) != -1) { + outToClient.write(reply, 0, bytes_read); + outToClient.flush(); + //TODO CREATE YOUR LOGIC HERE + } + } catch (IOException e) { + // e.printStackTrace(); + } finally { + try { + if (server != null) + server.close(); + if (client != null) + client.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + outToClient.close(); + sClient.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/test/java/BehaviorTests/MockServer.java b/src/test/java/BehaviorTests/MockServer.java index 03712ac6b..b6a9b643b 100644 --- a/src/test/java/BehaviorTests/MockServer.java +++ b/src/test/java/BehaviorTests/MockServer.java @@ -69,6 +69,7 @@ public class MockServer { public static final int PORT = 4567; public static final String HOST = "http://localhost:" + PORT; public static final String REDIRECT = HOST + "/redirect"; + public static final String PROXY = "localhost:4567"; public static final String POST = HOST + "/post"; public static final String GET = HOST + "/get"; public static final String DELETE = HOST + "/delete"; @@ -100,6 +101,7 @@ public static void reset(){ head("/get", MockServer::jsonResponse); put("/post", MockServer::jsonResponse); get("/get/:p/passed", MockServer::jsonResponse); + get("/proxy", MockServer::proxiedResponse); Runtime.getRuntime().addShutdownHook(new Thread(Spark::stop)); try { new CountDownLatch(1).await(2, TimeUnit.SECONDS); @@ -123,6 +125,17 @@ private static Object gzipResponse(Request request, Response response) { return jsonResponse(request, response); } + private static Object proxiedResponse(Request req, Response res) { + res.cookie("JSESSIONID", "ABC123"); + if(responseBody != null){ + return responseBody; + } + RequestCapture value = new RequestCapture(req); + value.writeBody(req); + value.setIsProxied(true); + return om.writeValue(value); + } + private static Object jsonResponse(Request req, Response res) { res.cookie("JSESSIONID", "ABC123"); if(responseBody != null){ diff --git a/src/test/java/BehaviorTests/ProxyTest.java b/src/test/java/BehaviorTests/ProxyTest.java new file mode 100644 index 000000000..e43297715 --- /dev/null +++ b/src/test/java/BehaviorTests/ProxyTest.java @@ -0,0 +1,59 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package BehaviorTests; + +import org.apache.http.HttpHost; +import org.junit.After; +import org.junit.Test; +import unirest.Unirest; + +import java.io.IOException; + +import static org.junit.Assert.assertTrue; + +public class ProxyTest extends BddTest { + + @After @Override + public void tearDown() { + super.tearDown(); + Unirest.shutDown(true); + } + + @Test + public void canUseNonAuthProxy() { + JankyProxy.runServer("localhost", 4567, 7777); + + Unirest.config().proxy(new HttpHost("localhost", 7777)); + + Unirest.get(MockServer.GET) + .asObject(RequestCapture.class) + .getBody() + .assertStatus(200); + + assertTrue(JankyProxy.wasUsed()); + } +} diff --git a/src/test/java/BehaviorTests/RequestCapture.java b/src/test/java/BehaviorTests/RequestCapture.java index b98ced36d..39a5de6da 100644 --- a/src/test/java/BehaviorTests/RequestCapture.java +++ b/src/test/java/BehaviorTests/RequestCapture.java @@ -64,6 +64,9 @@ public class RequestCapture { public String param; public String contentType; public JsonPatch jsonPatches; + public Integer status; + private boolean isProxied; + public RequestCapture() { } @@ -76,6 +79,7 @@ public RequestCapture(Request req) { writeQuery(req); param = req.params("p"); contentType = req.contentType(); + status = 200; } public void writeBody(Request req) { @@ -222,6 +226,20 @@ public void setPatch(JsonPatch patch) { this.jsonPatches = patch; } + public RequestCapture assertStatus(Integer i) { + assertEquals(i, status); + return this; + } + + public void setIsProxied(boolean b) { + this.isProxied = b; + } + + public RequestCapture assertIsProxied(boolean b) { + assertEquals(b, isProxied); + return this; + } + public static class File { public String fileName; public String type; From bcc7e45ad3fbb0f3d218d492c60c39059e8d67b6 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 25 Nov 2018 07:46:46 -0600 Subject: [PATCH 0295/1769] simple method for adding a proxy --- src/main/java/unirest/Config.java | 14 +++++++++++++- src/main/java/unirest/UnirestInstance.java | 1 + src/test/java/BehaviorTests/JankyProxy.java | 11 ++++++++++- src/test/java/BehaviorTests/ProxyTest.java | 17 +++++++++++++++-- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java index ffab23812..a0751ba36 100644 --- a/src/main/java/unirest/Config.java +++ b/src/main/java/unirest/Config.java @@ -130,6 +130,18 @@ public Config proxy(HttpHost value) { return this; } + /** + * Set a proxy + * + * @param host the hostname of the proxy server. + * @param port the port of the proxy server + * @return this config object + */ + public Config proxy(String host, int port) { + return proxy(new HttpHost(host, port)); + } + + /** * Set the ObjectMapper implementation to use for Response to Object binding * @@ -327,8 +339,8 @@ private synchronized void buildAsyncClient() { asyncClient = Optional.of(value); } } - // Accessors for unirest. + boolean getEnabledCookieManagement() { return cookieManagement; } diff --git a/src/main/java/unirest/UnirestInstance.java b/src/main/java/unirest/UnirestInstance.java index 93e6b7ea4..977d7f29b 100644 --- a/src/main/java/unirest/UnirestInstance.java +++ b/src/main/java/unirest/UnirestInstance.java @@ -35,6 +35,7 @@ public UnirestInstance(Config config){ } /** * Access the default configuration for the primary Unirest instance. + * @return the instance's config */ public Config config() { return config; diff --git a/src/test/java/BehaviorTests/JankyProxy.java b/src/test/java/BehaviorTests/JankyProxy.java index 017a59ba9..1ab676bc2 100644 --- a/src/test/java/BehaviorTests/JankyProxy.java +++ b/src/test/java/BehaviorTests/JankyProxy.java @@ -57,7 +57,7 @@ public static boolean wasUsed(){ public static void shutdown(){ if(thread != null){ try { - thread.interrupt(); + thread.shutdown(); }catch (Exception e){ e.printStackTrace(); } @@ -148,4 +148,13 @@ public void run() { e.printStackTrace(); } } + + public void shutdown() { + try { + socket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + interrupt(); + } } \ No newline at end of file diff --git a/src/test/java/BehaviorTests/ProxyTest.java b/src/test/java/BehaviorTests/ProxyTest.java index e43297715..464dcea9d 100644 --- a/src/test/java/BehaviorTests/ProxyTest.java +++ b/src/test/java/BehaviorTests/ProxyTest.java @@ -31,8 +31,6 @@ import org.junit.Test; import unirest.Unirest; -import java.io.IOException; - import static org.junit.Assert.assertTrue; public class ProxyTest extends BddTest { @@ -41,6 +39,7 @@ public class ProxyTest extends BddTest { public void tearDown() { super.tearDown(); Unirest.shutDown(true); + JankyProxy.shutdown(); } @Test @@ -56,4 +55,18 @@ public void canUseNonAuthProxy() { assertTrue(JankyProxy.wasUsed()); } + + @Test + public void canUseNonAuthProxyWithEasyMethod() { + JankyProxy.runServer("localhost", 4567, 7777); + + Unirest.config().proxy("localhost", 7777); + + Unirest.get(MockServer.GET) + .asObject(RequestCapture.class) + .getBody() + .assertStatus(200); + + assertTrue(JankyProxy.wasUsed()); + } } From a8c12f6a34052c80a4bd5f681bc29da9d48a8f05 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 25 Nov 2018 14:33:37 -0600 Subject: [PATCH 0296/1769] Closes #21 add a autenticated proxy. Disable the proxy tests because the Janky proxy server is too janky for TravisCI --- checkstyle.xml | 3 ++- src/main/java/unirest/ClientFactory.java | 1 + src/main/java/unirest/Config.java | 27 +++++++++++++++++++++- src/test/java/BehaviorTests/ProxyTest.java | 25 ++++++++++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/checkstyle.xml b/checkstyle.xml index 57b7f5bc3..0f2aa22d2 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -62,7 +62,8 @@ - + + diff --git a/src/main/java/unirest/ClientFactory.java b/src/main/java/unirest/ClientFactory.java index 1e7e43b00..86d248153 100644 --- a/src/main/java/unirest/ClientFactory.java +++ b/src/main/java/unirest/ClientFactory.java @@ -82,6 +82,7 @@ public ClientConfig buildHttpClient() { HttpClientBuilder cb = HttpClientBuilder.create() .setDefaultRequestConfig(getRequestConfig()) + .setDefaultCredentialsProvider(config.getProxyCreds()) .setConnectionManager(manager) .useSystemProperties(); diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java index a0751ba36..bf9aa5d56 100644 --- a/src/main/java/unirest/Config.java +++ b/src/main/java/unirest/Config.java @@ -28,7 +28,11 @@ import org.apache.http.HttpHost; import org.apache.http.HttpRequestInterceptor; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; import org.apache.http.client.HttpClient; +import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.nio.client.HttpAsyncClient; import java.util.*; @@ -49,8 +53,9 @@ public class Config { private Optional objectMapper = Optional.empty(); private List interceptors = new ArrayList<>(); - private HttpHost proxy; private Headers defaultHeaders; + private HttpHost proxy; + private CredentialsProvider proxyCreds; private int connectionTimeout; private int socketTimeout; private int maxTotal; @@ -58,6 +63,7 @@ public class Config { private boolean followRedirects; private boolean cookieManagement; + private void setDefaults(){ interceptors.clear(); proxy = null; @@ -141,6 +147,21 @@ public Config proxy(String host, int port) { return proxy(new HttpHost(host, port)); } + /** + * Set an authenticated proxy + * + * @param host the hostname of the proxy server. + * @param port the port of the proxy server + * @param username username for authenticated proxy + * @param password password for authenticated proxy + * @return this config object + */ + public Config proxy(String host, int port, String username, String password) { + proxyCreds = new BasicCredentialsProvider(); + proxyCreds.setCredentials(new AuthScope(host, port), + new UsernamePasswordCredentials(username, password)); + return proxy(new HttpHost(host, port)); + } /** * Set the ObjectMapper implementation to use for Response to Object binding @@ -385,4 +406,8 @@ List getInterceptors() { HttpHost getProxy() { return proxy; } + + CredentialsProvider getProxyCreds(){ + return proxyCreds; + } } diff --git a/src/test/java/BehaviorTests/ProxyTest.java b/src/test/java/BehaviorTests/ProxyTest.java index 464dcea9d..3bb6bd252 100644 --- a/src/test/java/BehaviorTests/ProxyTest.java +++ b/src/test/java/BehaviorTests/ProxyTest.java @@ -28,11 +28,14 @@ import org.apache.http.HttpHost; import org.junit.After; +import org.junit.Ignore; import org.junit.Test; +import unirest.HttpResponse; import unirest.Unirest; import static org.junit.Assert.assertTrue; +@Ignore public class ProxyTest extends BddTest { @After @Override @@ -69,4 +72,26 @@ public void canUseNonAuthProxyWithEasyMethod() { assertTrue(JankyProxy.wasUsed()); } + + @Test + public void canSetAuthenticatedProxy(){ + JankyProxy.runServer("localhost", 4567, 7777); + + Unirest.config().proxy("localhost", 7777, "username", "password1!"); + + Unirest.get(MockServer.GET) + .asObject(RequestCapture.class) + .getBody() + .assertStatus(200); + + assertTrue(JankyProxy.wasUsed()); + } + + @Test @Ignore + public void callSomethingRealThroughARealProxy() { + Unirest.config().proxy("proxyv.local.com",81, "myuser","pass1!"); + HttpResponse r = Unirest.get("https://twitter.com/ryber").asString(); + System.out.println("status = " + r.getStatus()); + System.out.println("body= " + r.getBody()); + } } From f92d1268957b1847cbab0ffa94bc186877b73226 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 25 Nov 2018 14:38:20 -0600 Subject: [PATCH 0297/1769] [maven-release-plugin] prepare release v3.0.01 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 980360ab2..87db3b3a6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.0.01-SNAPSHOT + 3.0.01 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.0.01 From 72d34587853d5490b8356947ee5c12d76bc463bb Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 25 Nov 2018 14:38:28 -0600 Subject: [PATCH 0298/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 87db3b3a6..4f75920aa 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.0.01 + 3.0.02-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.0.01 + HEAD From 498a2e45dbb6b428f8049ee88205bf9335d1f887 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 25 Nov 2018 14:42:41 -0600 Subject: [PATCH 0299/1769] update docs --- CHANGELOG.md | 6 +++++- README.md | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a2148b81..abf1aefc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ -## 3.0.0 +## 3.0.01 +* Support for authenticated proxies with ```Unirest.config().proxy("proxy.server.host", 80, "username","password")``` + +## 3.0.00 * This is a **major** release with several **breaking changes** which (other than the namespace change) should ONLY impact you if you are using some of Unirests more advanced features or custom configurations. +* The maven artifact has changed to ```open-unirest-java``` * The namespace has been shortened to just **unirest** (inspired by Java Spark) * The configuration system has been completely redone. Previously it was scattered across several classes and was entirely static. The new system has instances and supports multiple configurations. See the UPGRADE_GUIDE.md for details. * Start accessing the config with ```Unirest.config()``` diff --git a/README.md b/README.md index 5b868ee9d..f869514bd 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This repo is an updated, maintained, and independent fork of the original Mashap io.github.openunirest open-unirest-java - 3.0.00 + 3.0.01 ``` From 92e30004ee4a689a843f4fb6bc78f1a48b9972f3 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 25 Nov 2018 14:45:57 -0600 Subject: [PATCH 0300/1769] add the authenticated proxy to the async client --- CHANGELOG.md | 3 +++ README.md | 2 +- src/main/java/unirest/ClientFactory.java | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abf1aefc2..3a807610b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 3.0.02 +* Add support for the authenticated proxies to the async client + ## 3.0.01 * Support for authenticated proxies with ```Unirest.config().proxy("proxy.server.host", 80, "username","password")``` diff --git a/README.md b/README.md index f869514bd..542d9ea51 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This repo is an updated, maintained, and independent fork of the original Mashap io.github.openunirest open-unirest-java - 3.0.01 + 3.0.02 ``` diff --git a/src/main/java/unirest/ClientFactory.java b/src/main/java/unirest/ClientFactory.java index 86d248153..b80712882 100644 --- a/src/main/java/unirest/ClientFactory.java +++ b/src/main/java/unirest/ClientFactory.java @@ -54,6 +54,7 @@ public AsyncConfig buildAsyncClient() { HttpAsyncClientBuilder ab = HttpAsyncClientBuilder.create() .setDefaultRequestConfig(getRequestConfig()) .setConnectionManager(manager) + .setDefaultCredentialsProvider(config.getProxyCreds()) .useSystemProperties(); if (shouldDisableRedirects()) { From 164e2cb22acfbe6e32d07996691e7acc7af7bdc4 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 25 Nov 2018 14:49:05 -0600 Subject: [PATCH 0301/1769] [maven-release-plugin] prepare release v3.0.02 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 4f75920aa..866fd3044 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.0.02-SNAPSHOT + 3.0.02 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.0.02 From 90ca45a5b1a52bc1e28f81114874bade7c7922ef Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 25 Nov 2018 14:49:14 -0600 Subject: [PATCH 0302/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 866fd3044..5af98bb27 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.0.02 + 3.0.03-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.0.02 + HEAD From 61125f927b6d66256bab0a4f02a02bbc6579e4d8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 25 Nov 2018 21:01:52 -0600 Subject: [PATCH 0303/1769] closes #14. Expose using system properties --- src/main/java/unirest/ClientFactory.java | 6 ++++++ src/main/java/unirest/Config.java | 16 ++++++++++++++++ src/test/java/BehaviorTests/ProxyTest.java | 18 ++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/src/main/java/unirest/ClientFactory.java b/src/main/java/unirest/ClientFactory.java index b80712882..ca4779004 100644 --- a/src/main/java/unirest/ClientFactory.java +++ b/src/main/java/unirest/ClientFactory.java @@ -57,6 +57,9 @@ public AsyncConfig buildAsyncClient() { .setDefaultCredentialsProvider(config.getProxyCreds()) .useSystemProperties(); + if(config.useSystemProperties()){ + ab.useSystemProperties(); + } if (shouldDisableRedirects()) { ab.setRedirectStrategy(new NoRedirects()); } @@ -87,6 +90,9 @@ public ClientConfig buildHttpClient() { .setConnectionManager(manager) .useSystemProperties(); + if(config.useSystemProperties()){ + cb.useSystemProperties(); + } if (shouldDisableRedirects()) { cb.disableRedirectHandling(); } diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java index bf9aa5d56..3be095782 100644 --- a/src/main/java/unirest/Config.java +++ b/src/main/java/unirest/Config.java @@ -62,6 +62,7 @@ public class Config { private int maxPerRoute; private boolean followRedirects; private boolean cookieManagement; + private boolean useSystemProperties; private void setDefaults(){ @@ -270,6 +271,17 @@ public Config enableCookieManagement(boolean enable) { return this; } + /** + * Tell the HttpClients to use the system properties for things like proxies + * + * @param value a bool is its true or not. + * @return this config object + */ + public Config useSystemProperties(boolean value) { + this.useSystemProperties = value; + return this; + } + /** * Return default headers that are added to every request * @@ -410,4 +422,8 @@ HttpHost getProxy() { CredentialsProvider getProxyCreds(){ return proxyCreds; } + + boolean useSystemProperties(){ + return this.useSystemProperties; + } } diff --git a/src/test/java/BehaviorTests/ProxyTest.java b/src/test/java/BehaviorTests/ProxyTest.java index 3bb6bd252..e7d6dbb71 100644 --- a/src/test/java/BehaviorTests/ProxyTest.java +++ b/src/test/java/BehaviorTests/ProxyTest.java @@ -87,6 +87,24 @@ public void canSetAuthenticatedProxy(){ assertTrue(JankyProxy.wasUsed()); } + @Test + @Ignore // there is some weird conflict between jetty and unirest here + public void canFlagTheClientsToUseSystemProperties(){ + JankyProxy.runServer("localhost", 4567, 7777); + + System.setProperty("http.proxyHost", "localhost"); + System.setProperty("http.proxyPort", "7777"); + + Unirest.config().useSystemProperties(true); + + Unirest.get(MockServer.GET) + .asObject(RequestCapture.class) + .getBody() + .assertStatus(200); + + assertTrue(JankyProxy.wasUsed()); + } + @Test @Ignore public void callSomethingRealThroughARealProxy() { Unirest.config().proxy("proxyv.local.com",81, "myuser","pass1!"); From 287de0bbae004683ce99288c5bb5ea59970474d0 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 25 Nov 2018 21:05:49 -0600 Subject: [PATCH 0304/1769] [maven-release-plugin] prepare release v3.0.03 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 5af98bb27..80e50f1bf 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.0.03-SNAPSHOT + 3.0.03 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.0.03 From 2c7411a8ad1c8eec535be3ec32d6e734f1b5c833 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 25 Nov 2018 21:06:05 -0600 Subject: [PATCH 0305/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 80e50f1bf..3168a28d2 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.0.03 + 3.0.04-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.0.03 + HEAD From f3590d61509d369279940290dbf8340163e3ff42 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 25 Nov 2018 21:18:30 -0600 Subject: [PATCH 0306/1769] add a test for other varients of CharSequence as params --- src/test/java/BehaviorTests/QueryStringTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/java/BehaviorTests/QueryStringTest.java b/src/test/java/BehaviorTests/QueryStringTest.java index 0644fc7f6..c9ea2fd4f 100644 --- a/src/test/java/BehaviorTests/QueryStringTest.java +++ b/src/test/java/BehaviorTests/QueryStringTest.java @@ -59,6 +59,15 @@ public void canPassQueryParamsDirectlyOnUriOrWithMethod() { .assertParam("name", "mark2"); } + @Test + public void canPassInACharSequence() { + Unirest.get(MockServer.GET) + .queryString("foo", new StringBuilder("bar")) + .asObject(RequestCapture.class) + .getBody() + .assertParam("foo", "bar"); + } + @Test public void multipleParams() { Unirest.get(MockServer.GET + "?name=ringo") From 8d3748c5f9a7ac6640fab575a83efd43d1d95ec5 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 26 Nov 2018 08:02:44 -0600 Subject: [PATCH 0307/1769] update docs --- CHANGELOG.md | 5 +++++ README.md | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a807610b..ab36359aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.0.03 +* Support Java system properties for proxies via ```Unirest.config().useSystemProperties(true);``` + * https://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html + + ## 3.0.02 * Add support for the authenticated proxies to the async client diff --git a/README.md b/README.md index 542d9ea51..07574ebf6 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This repo is an updated, maintained, and independent fork of the original Mashap io.github.openunirest open-unirest-java - 3.0.02 + 3.0.03 ``` From abcf98e75f3eb615d620f83bffb7c701ab218312 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 26 Nov 2018 14:40:05 -0600 Subject: [PATCH 0308/1769] do not rethrow unirest exceptions on parse --- src/main/java/unirest/BodyData.java | 2 - src/test/java/BehaviorTests/AsObjectTest.java | 39 +++++++++++++++++-- .../java/unirest/JacksonObjectMapper.java | 6 +-- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/main/java/unirest/BodyData.java b/src/main/java/unirest/BodyData.java index 01726503a..c36a7d704 100644 --- a/src/main/java/unirest/BodyData.java +++ b/src/main/java/unirest/BodyData.java @@ -89,8 +89,6 @@ public RuntimeException getParseEx() { private void transformBody(Function, T> transformer) { try { this.transFormedBody = transformer.apply(this); - }catch (UnirestException e){ - throw e; }catch (RuntimeException e){ parseEx = e; } diff --git a/src/test/java/BehaviorTests/AsObjectTest.java b/src/test/java/BehaviorTests/AsObjectTest.java index ef626af6c..52dafb7cf 100644 --- a/src/test/java/BehaviorTests/AsObjectTest.java +++ b/src/test/java/BehaviorTests/AsObjectTest.java @@ -27,11 +27,11 @@ package BehaviorTests; import com.google.gson.Gson; -import unirest.JacksonObjectMapper; -import unirest.ObjectMapper; -import unirest.Unirest; +import unirest.*; import org.junit.Test; +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertNull; import static junit.framework.TestCase.assertTrue; public class AsObjectTest extends BddTest { @@ -80,6 +80,39 @@ public void canPassAnObjectMapperAsPartOfARequest(){ assertTrue(mapper.wasCalled); } + @Test + public void ifTheObjectMapperFailsReturnEmptyAndAddToParsingError() { + HttpResponse request = Unirest.get(MockServer.INVALID_REQUEST) + .asObject(RequestCapture.class); + + assertNull(request.getBody()); + assertTrue(request.getParsingError().isPresent()); + assertEquals("com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'You': was expecting ('true', 'false' or 'null')\n" + + " at [Source: (String)\"You did something bad\"; line: 1, column: 4]", request.getParsingError().get().getMessage()); + } + + @Test + public void ifTheObjectMapperFailsReturnEmptyAndAddToParsingErrorObGenericTypes() { + HttpResponse request = Unirest.get(MockServer.INVALID_REQUEST) + .asObject(new GenericType() {}); + + assertNull(request.getBody()); + assertTrue(request.getParsingError().isPresent()); + assertEquals("com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'You': was expecting ('true', 'false' or 'null')\n" + + " at [Source: (String)\"You did something bad\"; line: 1, column: 4]", request.getParsingError().get().getMessage()); + } + + @Test + public void unirestExceptionsAreAlsoParseExceptions() { + HttpResponse request = Unirest.get(MockServer.INVALID_REQUEST) + .asObject(new GenericType() {}); + + assertNull(request.getBody()); + assertTrue(request.getParsingError().isPresent()); + assertEquals("com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'You': was expecting ('true', 'false' or 'null')\n" + + " at [Source: (String)\"You did something bad\"; line: 1, column: 4]", request.getParsingError().get().getMessage()); + } + public static class TestingMapper implements ObjectMapper { public boolean wasCalled; diff --git a/src/test/java/unirest/JacksonObjectMapper.java b/src/test/java/unirest/JacksonObjectMapper.java index b2d36e572..8566c175e 100644 --- a/src/test/java/unirest/JacksonObjectMapper.java +++ b/src/test/java/unirest/JacksonObjectMapper.java @@ -63,7 +63,7 @@ public T readValue(String value, Class valueType) { try { return om.readValue(value, valueType); } catch (IOException e) { - throw new RuntimeException(e); + throw new UnirestException(e); } } @@ -72,7 +72,7 @@ public T readValue(String value, GenericType genericType) { try { return om.readValue(value, om.constructType(genericType.getType())); } catch (IOException e) { - throw new RuntimeException(e); + throw new UnirestException(e); } } @@ -81,7 +81,7 @@ public String writeValue(Object value) { try { return om.writeValueAsString(value); } catch (JsonProcessingException e) { - throw new RuntimeException(e); + throw new UnirestException(e); } } From de2c0760855c59532b733b8f5c38c08b6edc8d1e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 26 Nov 2018 14:42:35 -0600 Subject: [PATCH 0309/1769] [maven-release-plugin] prepare release v3.0.04 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3168a28d2..8a802e5e7 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.0.04-SNAPSHOT + 3.0.04 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.0.04 From e5b28f249dc71f8261defc491445e5694a1c0d52 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 26 Nov 2018 14:42:41 -0600 Subject: [PATCH 0310/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 8a802e5e7..245e91929 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.0.04 + 3.0.05-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.0.04 + HEAD From 5a5c82ac1c176c8b3d4c7938973c9ca21322081b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 26 Nov 2018 14:47:40 -0600 Subject: [PATCH 0311/1769] update docs --- CHANGELOG.md | 4 +++- README.md | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab36359aa..870410cc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,10 @@ +## 3.0.04 +* Parsing handler should capture unirest exceptions just like other exceptions. + ## 3.0.03 * Support Java system properties for proxies via ```Unirest.config().useSystemProperties(true);``` * https://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html - ## 3.0.02 * Add support for the authenticated proxies to the async client diff --git a/README.md b/README.md index 07574ebf6..83e7d160e 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This repo is an updated, maintained, and independent fork of the original Mashap io.github.openunirest open-unirest-java - 3.0.03 + 3.0.04 ``` From 54cd4a66c28781b652d48428adc0b66da401e0ba Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 26 Nov 2018 20:13:30 -0600 Subject: [PATCH 0312/1769] document what happens when no body is returned --- src/main/java/unirest/HttpResponseImpl.java | 18 +++++++++--------- src/test/java/BehaviorTests/AsBinaryTest.java | 12 ++++++++++++ src/test/java/BehaviorTests/AsJsonTest.java | 10 ++++++++++ src/test/java/BehaviorTests/AsObjectTest.java | 10 ++++++++++ src/test/java/BehaviorTests/AsStringTest.java | 10 ++++++++++ src/test/java/BehaviorTests/MockServer.java | 7 +++++++ 6 files changed, 58 insertions(+), 9 deletions(-) diff --git a/src/main/java/unirest/HttpResponseImpl.java b/src/main/java/unirest/HttpResponseImpl.java index 3d518314c..2315d64ff 100644 --- a/src/main/java/unirest/HttpResponseImpl.java +++ b/src/main/java/unirest/HttpResponseImpl.java @@ -34,21 +34,14 @@ class HttpResponseImpl implements HttpResponse { + private Optional parsingError = Optional.empty(); private final Headers headers; - private final int statusCode; private final String statusText; + private final int statusCode; private InputStream rawBody; - private Optional parsingError = Optional.empty(); private T body; - private HttpResponseImpl(org.apache.http.HttpResponse response){ - headers = new Headers(response.getAllHeaders()); - StatusLine statusLine = response.getStatusLine(); - this.statusCode = statusLine.getStatusCode(); - this.statusText = statusLine.getReasonPhrase(); - } - public HttpResponseImpl(org.apache.http.HttpResponse response, BodyData data){ this(response); this.rawBody = data.getRawInput(); @@ -62,6 +55,13 @@ public HttpResponseImpl(org.apache.http.HttpResponse response, T body, InputStre this.rawBody = is; } + private HttpResponseImpl(org.apache.http.HttpResponse response){ + headers = new Headers(response.getAllHeaders()); + StatusLine statusLine = response.getStatusLine(); + this.statusCode = statusLine.getStatusCode(); + this.statusText = statusLine.getReasonPhrase(); + } + @Override public int getStatus() { return statusCode; diff --git a/src/test/java/BehaviorTests/AsBinaryTest.java b/src/test/java/BehaviorTests/AsBinaryTest.java index 4496e05c9..aa559dbb2 100644 --- a/src/test/java/BehaviorTests/AsBinaryTest.java +++ b/src/test/java/BehaviorTests/AsBinaryTest.java @@ -31,10 +31,22 @@ import org.junit.Test; import unirest.TestUtil; +import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.concurrent.CompletableFuture; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + public class AsBinaryTest extends BddTest { + @Test + public void whenNoBodyIsReturned() { + HttpResponse i = Unirest.get(MockServer.NOBODY).asBinary(); + + assertEquals(200, i.getStatus()); + assertEquals("", TestUtil.toString(i.getBody())); + } + @Test public void canGetBinaryResponse() { HttpResponse i = Unirest.get(MockServer.GET) diff --git a/src/test/java/BehaviorTests/AsJsonTest.java b/src/test/java/BehaviorTests/AsJsonTest.java index 3f00e3e9e..9f2ba0628 100644 --- a/src/test/java/BehaviorTests/AsJsonTest.java +++ b/src/test/java/BehaviorTests/AsJsonTest.java @@ -33,12 +33,22 @@ import unirest.MockCallback; import unirest.TestUtil; +import java.io.InputStream; import java.util.concurrent.CompletableFuture; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; public class AsJsonTest extends BddTest { + + @Test + public void whenNoBodyIsReturned() { + HttpResponse i = Unirest.get(MockServer.NOBODY).asJson(); + + assertEquals(200, i.getStatus()); + assertEquals("{}", i.getBody().toString()); + } + @Test public void canGetBinaryResponse() { HttpResponse i = Unirest.get(MockServer.GET) diff --git a/src/test/java/BehaviorTests/AsObjectTest.java b/src/test/java/BehaviorTests/AsObjectTest.java index 52dafb7cf..d7ae0f3ba 100644 --- a/src/test/java/BehaviorTests/AsObjectTest.java +++ b/src/test/java/BehaviorTests/AsObjectTest.java @@ -27,6 +27,7 @@ package BehaviorTests; import com.google.gson.Gson; +import org.junit.Assert; import unirest.*; import org.junit.Test; @@ -35,6 +36,15 @@ import static junit.framework.TestCase.assertTrue; public class AsObjectTest extends BddTest { + + @Test + public void whenNoBodyIsReturned() { + HttpResponse i = Unirest.get(MockServer.NOBODY).asObject(RequestCapture.class); + + Assert.assertEquals(200, i.getStatus()); + Assert.assertEquals(null, i.getBody()); + } + @Test public void canGetObjectResponse() { Unirest.get(MockServer.GET) diff --git a/src/test/java/BehaviorTests/AsStringTest.java b/src/test/java/BehaviorTests/AsStringTest.java index ec49f4519..cefcb35eb 100644 --- a/src/test/java/BehaviorTests/AsStringTest.java +++ b/src/test/java/BehaviorTests/AsStringTest.java @@ -27,14 +27,24 @@ package BehaviorTests; import unirest.HttpResponse; +import unirest.JsonNode; import unirest.Unirest; import org.junit.Test; import unirest.TestUtil; import java.util.concurrent.CompletableFuture; +import static org.junit.Assert.assertEquals; + public class AsStringTest extends BddTest { + @Test + public void whenNoBodyIsReturned() { + HttpResponse i = Unirest.get(MockServer.NOBODY).asString(); + + assertEquals(200, i.getStatus()); + assertEquals("", i.getBody()); + } @Test public void canGetBinaryResponse() { diff --git a/src/test/java/BehaviorTests/MockServer.java b/src/test/java/BehaviorTests/MockServer.java index b6a9b643b..8cac453d6 100644 --- a/src/test/java/BehaviorTests/MockServer.java +++ b/src/test/java/BehaviorTests/MockServer.java @@ -69,6 +69,7 @@ public class MockServer { public static final int PORT = 4567; public static final String HOST = "http://localhost:" + PORT; public static final String REDIRECT = HOST + "/redirect"; + public static final String NOBODY = HOST + "/nobody"; public static final String PROXY = "localhost:4567"; public static final String POST = HOST + "/post"; public static final String GET = HOST + "/get"; @@ -98,6 +99,7 @@ public static void reset(){ patch("/patch", MockServer::jsonResponse); get("/invalid", MockServer::inValid); options("/get", MockServer::jsonResponse); + get("/nobody", MockServer::nobody); head("/get", MockServer::jsonResponse); put("/post", MockServer::jsonResponse); get("/get/:p/passed", MockServer::jsonResponse); @@ -110,6 +112,11 @@ public static void reset(){ } } + private static Object nobody(Request request, Response response) { + Spark.halt(200); + return null; + } + private static Object redirect(Request request, Response response) { response.redirect("/get", 301); return null; From 475efcd3a45e1104ec4ca3d5754556b50954786b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 26 Nov 2018 20:18:08 -0600 Subject: [PATCH 0313/1769] rename response --- src/main/java/unirest/BaseRequest.java | 10 +++++----- .../unirest/{HttpResponseImpl.java => Response.java} | 8 ++++---- src/test/java/unirest/HttpResponseTest.java | 7 ++----- 3 files changed, 11 insertions(+), 14 deletions(-) rename src/main/java/unirest/{HttpResponseImpl.java => Response.java} (90%) diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index bf7d716fd..857d2d72d 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -267,23 +267,23 @@ public Body getBody() { } private HttpResponse asJson(org.apache.http.HttpResponse response) { - return new HttpResponseImpl<>(response, from(response.getEntity(), b -> toJson(b))); + return new Response<>(response, from(response.getEntity(), b -> toJson(b))); } private HttpResponse asBinary(org.apache.http.HttpResponse response){ - return new HttpResponseImpl<>(response, from(response.getEntity(), BodyData::getRawInput)); + return new Response<>(response, from(response.getEntity(), BodyData::getRawInput)); } private HttpResponse asObject(org.apache.http.HttpResponse response, Class aClass) { - return new HttpResponseImpl<>(response, from(response.getEntity(), b -> toObject(b, aClass))); + return new Response<>(response, from(response.getEntity(), b -> toObject(b, aClass))); } private HttpResponse asObject(org.apache.http.HttpResponse response, GenericType genericType) { - return new HttpResponseImpl<>(response, from(response.getEntity(), b -> toObject(b, genericType))); + return new Response<>(response, from(response.getEntity(), b -> toObject(b, genericType))); } private HttpResponse asString(org.apache.http.HttpResponse response) { - return new HttpResponseImpl<>(response, from(response.getEntity(), this::toString)); + return new Response<>(response, from(response.getEntity(), this::toString)); } private T toObject(BodyData b, GenericType genericType) { diff --git a/src/main/java/unirest/HttpResponseImpl.java b/src/main/java/unirest/Response.java similarity index 90% rename from src/main/java/unirest/HttpResponseImpl.java rename to src/main/java/unirest/Response.java index 2315d64ff..19e143bf0 100644 --- a/src/main/java/unirest/HttpResponseImpl.java +++ b/src/main/java/unirest/Response.java @@ -32,7 +32,7 @@ import java.util.Optional; import java.util.function.Function; -class HttpResponseImpl implements HttpResponse { +class Response implements HttpResponse { private Optional parsingError = Optional.empty(); private final Headers headers; @@ -42,20 +42,20 @@ class HttpResponseImpl implements HttpResponse { private InputStream rawBody; private T body; - public HttpResponseImpl(org.apache.http.HttpResponse response, BodyData data){ + public Response(org.apache.http.HttpResponse response, BodyData data){ this(response); this.rawBody = data.getRawInput(); this.body = data.getTransFormedBody(); this.parsingError = Optional.ofNullable(data.getParseEx()); } - public HttpResponseImpl(org.apache.http.HttpResponse response, T body, InputStream is){ + public Response(org.apache.http.HttpResponse response, T body, InputStream is){ this(response); this.body = body; this.rawBody = is; } - private HttpResponseImpl(org.apache.http.HttpResponse response){ + private Response(org.apache.http.HttpResponse response){ headers = new Headers(response.getAllHeaders()); StatusLine statusLine = response.getStatusLine(); this.statusCode = statusLine.getStatusCode(); diff --git a/src/test/java/unirest/HttpResponseTest.java b/src/test/java/unirest/HttpResponseTest.java index 95320032a..c5094dce4 100644 --- a/src/test/java/unirest/HttpResponseTest.java +++ b/src/test/java/unirest/HttpResponseTest.java @@ -26,10 +26,7 @@ package unirest; -import unirest.MockApacheResponse; import org.junit.Test; -import unirest.HttpResponseImpl; -import unirest.TestUtil; import static org.junit.Assert.assertEquals; import static unirest.TestUtil.emptyInput; @@ -39,14 +36,14 @@ public class HttpResponseTest { @Test public void canMapBody() { MockApacheResponse r = new MockApacheResponse(); - Integer v = new HttpResponseImpl<>(r, "42", emptyInput()).mapBody(Integer::valueOf); + Integer v = new Response<>(r, "42", emptyInput()).mapBody(Integer::valueOf); assertEquals(new Integer(42), v); } @Test public void canMapRawBody() { MockApacheResponse r = new MockApacheResponse(); - Integer v = new HttpResponseImpl<>(r, "42", TestUtil.toInputStream("42")) + Integer v = new Response<>(r, "42", TestUtil.toInputStream("42")) .mapRawBody(i -> Integer.valueOf(TestUtil.toString(i))); assertEquals(new Integer(42), v); From 25f42297b7d6d7473b4a582e2f938a0537c65727 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 27 Nov 2018 19:49:53 -0600 Subject: [PATCH 0314/1769] start to simplify the responses into sinple classes rather than all this weird componsition --- src/main/java/unirest/BaseRequest.java | 40 +++++------ src/main/java/unirest/ResponseBase.java | 83 +++++++++++++++++++++++ src/main/java/unirest/StringResponse.java | 69 +++++++++++++++++++ 3 files changed, 170 insertions(+), 22 deletions(-) create mode 100644 src/main/java/unirest/ResponseBase.java create mode 100644 src/main/java/unirest/StringResponse.java diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 857d2d72d..a0ffcbc87 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -127,17 +127,17 @@ public HttpRequest getHttpRequest() { @Override public HttpResponse asString() throws UnirestException { - return request(this::asString); + return request(StringResponse::new); } @Override public CompletableFuture> asStringAsync() { - return requestAsync(this::asString, new CompletableFuture<>()); + return requestAsync(StringResponse::new, new CompletableFuture<>()); } @Override public CompletableFuture> asStringAsync(Callback callback) { - return requestAsync(this::asString, CallbackFuture.wrap(callback)); + return requestAsync(StringResponse::new, CallbackFuture.wrap(callback)); } @Override @@ -200,23 +200,6 @@ public CompletableFuture> asBinaryAsync(Callback HttpResponse request(Function> transformer) { - - HttpRequestBase requestObj = new RequestPrep(this, false).prepare(); - HttpClient client = config.getClient(); - - try { - org.apache.http.HttpResponse execute = client.execute(requestObj); - HttpResponse httpResponse = transformer.apply(execute); - requestObj.releaseConnection(); - return httpResponse; - } catch (Exception e) { - throw new UnirestException(e); - } finally { - requestObj.releaseConnection(); - } - } - private CompletableFuture> requestAsync( Function> transformer, CompletableFuture> callback) { @@ -282,8 +265,21 @@ private HttpResponse asObject(org.apache.http.HttpResponse response, Gene return new Response<>(response, from(response.getEntity(), b -> toObject(b, genericType))); } - private HttpResponse asString(org.apache.http.HttpResponse response) { - return new Response<>(response, from(response.getEntity(), this::toString)); + private HttpResponse request(Function> transformer) { + + HttpRequestBase requestObj = new RequestPrep(this, false).prepare(); + HttpClient client = config.getClient(); + + try { + org.apache.http.HttpResponse execute = client.execute(requestObj); + HttpResponse httpResponse = transformer.apply(execute); + requestObj.releaseConnection(); + return httpResponse; + } catch (Exception e) { + throw new UnirestException(e); + } finally { + requestObj.releaseConnection(); + } } private T toObject(BodyData b, GenericType genericType) { diff --git a/src/main/java/unirest/ResponseBase.java b/src/main/java/unirest/ResponseBase.java new file mode 100644 index 000000000..8dcd4970e --- /dev/null +++ b/src/main/java/unirest/ResponseBase.java @@ -0,0 +1,83 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.apache.http.StatusLine; + +import java.io.InputStream; +import java.util.Optional; +import java.util.function.Function; + +abstract class ResponseBase implements HttpResponse { + + private final Headers headers; + private final String statusText; + private final int statusCode; + + protected ResponseBase(org.apache.http.HttpResponse response){ + headers = new Headers(response.getAllHeaders()); + StatusLine statusLine = response.getStatusLine(); + this.statusCode = statusLine.getStatusCode(); + this.statusText = statusLine.getReasonPhrase(); + } + + @Override + public int getStatus() { + return statusCode; + } + + @Override + public String getStatusText() { + return statusText; + } + + @Override + public Headers getHeaders() { + return headers; + } + + @Override + public abstract InputStream getRawBody(); + + @Override + public abstract T getBody(); + + @Override + public Optional getParsingError() { + return Optional.empty(); + } + + @Override + public V mapBody(Function func){ + return func.apply(getBody()); + } + + @Override + public V mapRawBody(Function func) { + return func.apply(getRawBody()); + } +} diff --git a/src/main/java/unirest/StringResponse.java b/src/main/java/unirest/StringResponse.java new file mode 100644 index 000000000..5077cb178 --- /dev/null +++ b/src/main/java/unirest/StringResponse.java @@ -0,0 +1,69 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; + +import static unirest.ResponseUtils.getCharSet; + +public class StringResponse extends ResponseBase { + private String body; + + public StringResponse(HttpResponse response) { + super(response); + HttpEntity entity = response.getEntity(); + if(Objects.nonNull(entity)){ + body = toString(entity); + } else { + body = ""; + } + } + + private String toString(HttpEntity b) { + try { + return new String(ResponseUtils.getRawBody(b), getCharSet(b)); + } catch (IOException e) { + throw new UnirestException(e); + } + } + + @Override + public InputStream getRawBody() { + return new ByteArrayInputStream(body.getBytes()); + } + + @Override + public String getBody() { + return body; + } +} From b7b1b51682ee9df5a009a591aeb604968d5b38fc Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 28 Nov 2018 07:54:38 -0600 Subject: [PATCH 0315/1769] Change the binary response to not read the apache inputstream and just return it. This means that a streaming response can be handled by the customer. --- src/main/java/unirest/BaseRequest.java | 10 +-- src/main/java/unirest/BinaryResponse.java | 64 +++++++++++++++++++ src/test/java/BehaviorTests/AsBinaryTest.java | 5 +- 3 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 src/main/java/unirest/BinaryResponse.java diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index a0ffcbc87..e438b6420 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -187,17 +187,17 @@ public CompletableFuture> asObjectAsync(GenericType gener @Override public HttpResponse asBinary() throws UnirestException { - return request(this::asBinary); + return request(response -> new BinaryResponse(response)); } @Override public CompletableFuture> asBinaryAsync() { - return requestAsync(this::asBinary, new CompletableFuture<>()); + return requestAsync(response -> new BinaryResponse(response), new CompletableFuture<>()); } @Override public CompletableFuture> asBinaryAsync(Callback callback) { - return requestAsync(this::asBinary, CallbackFuture.wrap(callback)); + return requestAsync(response -> new BinaryResponse(response), CallbackFuture.wrap(callback)); } private CompletableFuture> requestAsync( @@ -253,10 +253,6 @@ private HttpResponse asJson(org.apache.http.HttpResponse response) { return new Response<>(response, from(response.getEntity(), b -> toJson(b))); } - private HttpResponse asBinary(org.apache.http.HttpResponse response){ - return new Response<>(response, from(response.getEntity(), BodyData::getRawInput)); - } - private HttpResponse asObject(org.apache.http.HttpResponse response, Class aClass) { return new Response<>(response, from(response.getEntity(), b -> toObject(b, aClass))); } diff --git a/src/main/java/unirest/BinaryResponse.java b/src/main/java/unirest/BinaryResponse.java new file mode 100644 index 000000000..336b66545 --- /dev/null +++ b/src/main/java/unirest/BinaryResponse.java @@ -0,0 +1,64 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Optional; + +public class BinaryResponse extends ResponseBase { + + private Optional body; + + protected BinaryResponse(HttpResponse response) { + super(response); + body = Optional.ofNullable(response.getEntity()); + } + + @Override + public InputStream getRawBody() { + return body.map(this::tryGet) + .orElse(new ByteArrayInputStream(new byte[0])); + } + + @Override + public InputStream getBody() { + return getRawBody(); + } + + private InputStream tryGet(HttpEntity e) { + try { + return e.getContent(); + } catch (IOException e1) { + throw new UnirestException(e1); + } + } +} diff --git a/src/test/java/BehaviorTests/AsBinaryTest.java b/src/test/java/BehaviorTests/AsBinaryTest.java index aa559dbb2..b75cadfc9 100644 --- a/src/test/java/BehaviorTests/AsBinaryTest.java +++ b/src/test/java/BehaviorTests/AsBinaryTest.java @@ -32,6 +32,7 @@ import unirest.TestUtil; import java.io.ByteArrayInputStream; +import java.io.IOException; import java.io.InputStream; import java.util.concurrent.CompletableFuture; @@ -40,11 +41,11 @@ public class AsBinaryTest extends BddTest { @Test - public void whenNoBodyIsReturned() { + public void whenNoBodyIsReturned() throws IOException { HttpResponse i = Unirest.get(MockServer.NOBODY).asBinary(); assertEquals(200, i.getStatus()); - assertEquals("", TestUtil.toString(i.getBody())); + assertEquals(0, i.getBody().available()); } @Test From 8f56a6a6fb704551b67ae1ee099331cb325fa399 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 28 Nov 2018 18:41:48 -0600 Subject: [PATCH 0316/1769] use entity utils for string reading --- src/main/java/unirest/StringResponse.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/unirest/StringResponse.java b/src/main/java/unirest/StringResponse.java index 5077cb178..f8b0d6306 100644 --- a/src/main/java/unirest/StringResponse.java +++ b/src/main/java/unirest/StringResponse.java @@ -28,6 +28,7 @@ import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; +import org.apache.http.util.EntityUtils; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -51,7 +52,7 @@ public StringResponse(HttpResponse response) { private String toString(HttpEntity b) { try { - return new String(ResponseUtils.getRawBody(b), getCharSet(b)); + return EntityUtils.toString(b); } catch (IOException e) { throw new UnirestException(e); } From 9917ab024cd20fb47fb46b94c6ff01ade196210a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 28 Nov 2018 19:58:23 -0600 Subject: [PATCH 0317/1769] switch to use apache toString for the entity --- src/main/java/unirest/StringResponse.java | 1 - src/test/java/BehaviorTests/AsStringTest.java | 11 +++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/unirest/StringResponse.java b/src/main/java/unirest/StringResponse.java index f8b0d6306..79e67f980 100644 --- a/src/main/java/unirest/StringResponse.java +++ b/src/main/java/unirest/StringResponse.java @@ -35,7 +35,6 @@ import java.io.InputStream; import java.util.Objects; -import static unirest.ResponseUtils.getCharSet; public class StringResponse extends ResponseBase { private String body; diff --git a/src/test/java/BehaviorTests/AsStringTest.java b/src/test/java/BehaviorTests/AsStringTest.java index cefcb35eb..86af7fc77 100644 --- a/src/test/java/BehaviorTests/AsStringTest.java +++ b/src/test/java/BehaviorTests/AsStringTest.java @@ -46,6 +46,17 @@ public void whenNoBodyIsReturned() { assertEquals("", i.getBody()); } + @Test + public void canParseGzippedStringResponse() { + HttpResponse i = Unirest.get(MockServer.GZIP) + .queryString("foo", "bar") + .asString(); + + RequestCapture cap = TestUtil.readValue(i.getBody(), RequestCapture.class); + assertEquals(200, i.getStatus()); + cap.assertParam("foo", "bar"); + } + @Test public void canGetBinaryResponse() { HttpResponse i = Unirest.get(MockServer.GET) From 892a6bbc12193174299432ae79c4229d17be4e3b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 28 Nov 2018 20:08:34 -0600 Subject: [PATCH 0318/1769] copy the stream in the constructor --- src/main/java/unirest/BinaryResponse.java | 32 ++++++++++++----------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/java/unirest/BinaryResponse.java b/src/main/java/unirest/BinaryResponse.java index 336b66545..8de6e68be 100644 --- a/src/main/java/unirest/BinaryResponse.java +++ b/src/main/java/unirest/BinaryResponse.java @@ -26,39 +26,41 @@ package unirest; -import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; +import org.apache.http.util.EntityUtils; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.util.Optional; +import java.util.Objects; public class BinaryResponse extends ResponseBase { - private Optional body; + private InputStream body; protected BinaryResponse(HttpResponse response) { super(response); - body = Optional.ofNullable(response.getEntity()); + body = new ByteArrayInputStream(getBody(response)); + } + + private byte[] getBody(HttpResponse response) { + if (Objects.isNull(response.getEntity())) { + return new byte[0]; + } + try { + return EntityUtils.toByteArray(response.getEntity()); + } catch (IOException e) { + throw new UnirestException(e); + } } @Override public InputStream getRawBody() { - return body.map(this::tryGet) - .orElse(new ByteArrayInputStream(new byte[0])); + return body; } @Override public InputStream getBody() { - return getRawBody(); - } - - private InputStream tryGet(HttpEntity e) { - try { - return e.getContent(); - } catch (IOException e1) { - throw new UnirestException(e1); - } + return body; } } From c297106e2a95d67ba43cbc21546627092e97c12a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 28 Nov 2018 20:13:03 -0600 Subject: [PATCH 0319/1769] rename baseresponse --- .../java/unirest/{ResponseBase.java => BaseResponse.java} | 4 ++-- src/main/java/unirest/BinaryResponse.java | 2 +- src/main/java/unirest/StringResponse.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename src/main/java/unirest/{ResponseBase.java => BaseResponse.java} (95%) diff --git a/src/main/java/unirest/ResponseBase.java b/src/main/java/unirest/BaseResponse.java similarity index 95% rename from src/main/java/unirest/ResponseBase.java rename to src/main/java/unirest/BaseResponse.java index 8dcd4970e..8756b770c 100644 --- a/src/main/java/unirest/ResponseBase.java +++ b/src/main/java/unirest/BaseResponse.java @@ -32,13 +32,13 @@ import java.util.Optional; import java.util.function.Function; -abstract class ResponseBase implements HttpResponse { +abstract class BaseResponse implements HttpResponse { private final Headers headers; private final String statusText; private final int statusCode; - protected ResponseBase(org.apache.http.HttpResponse response){ + protected BaseResponse(org.apache.http.HttpResponse response){ headers = new Headers(response.getAllHeaders()); StatusLine statusLine = response.getStatusLine(); this.statusCode = statusLine.getStatusCode(); diff --git a/src/main/java/unirest/BinaryResponse.java b/src/main/java/unirest/BinaryResponse.java index 8de6e68be..90a4dc523 100644 --- a/src/main/java/unirest/BinaryResponse.java +++ b/src/main/java/unirest/BinaryResponse.java @@ -34,7 +34,7 @@ import java.io.InputStream; import java.util.Objects; -public class BinaryResponse extends ResponseBase { +public class BinaryResponse extends BaseResponse { private InputStream body; diff --git a/src/main/java/unirest/StringResponse.java b/src/main/java/unirest/StringResponse.java index 79e67f980..c5d2c41d3 100644 --- a/src/main/java/unirest/StringResponse.java +++ b/src/main/java/unirest/StringResponse.java @@ -36,7 +36,7 @@ import java.util.Objects; -public class StringResponse extends ResponseBase { +public class StringResponse extends BaseResponse { private String body; public StringResponse(HttpResponse response) { From 3b45f65c83f8a6cedee3c78daa538d5c62f8affd Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 28 Nov 2018 20:44:40 -0600 Subject: [PATCH 0320/1769] add jsonresponse --- src/main/java/unirest/BaseRequest.java | 15 +---- src/main/java/unirest/BaseResponse.java | 7 ++- src/main/java/unirest/JsonResponse.java | 82 +++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 13 deletions(-) create mode 100644 src/main/java/unirest/JsonResponse.java diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index e438b6420..2b7c15e1a 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -142,17 +142,17 @@ public CompletableFuture> asStringAsync(Callback ca @Override public HttpResponse asJson() throws UnirestException { - return request(this::asJson); + return request(response -> new JsonResponse(response)); } @Override public CompletableFuture> asJsonAsync() { - return requestAsync(this::asJson, new CompletableFuture<>()); + return requestAsync(response -> new JsonResponse(response), new CompletableFuture<>()); } @Override public CompletableFuture> asJsonAsync(Callback callback) { - return requestAsync(this::asJson, CallbackFuture.wrap(callback)); + return requestAsync(response -> new JsonResponse(response), CallbackFuture.wrap(callback)); } @Override @@ -249,10 +249,6 @@ public Body getBody() { return null; } - private HttpResponse asJson(org.apache.http.HttpResponse response) { - return new Response<>(response, from(response.getEntity(), b -> toJson(b))); - } - private HttpResponse asObject(org.apache.http.HttpResponse response, Class aClass) { return new Response<>(response, from(response.getEntity(), b -> toObject(b, aClass))); } @@ -296,11 +292,6 @@ private String toString(BodyData b) { } } - private JsonNode toJson(BodyData b) { - String jsonString = toString(b); - return new JsonNode(jsonString); - } - private ObjectMapper getObjectMapper() { return objectMapper.orElseGet(config::getObjectMapper); } diff --git a/src/main/java/unirest/BaseResponse.java b/src/main/java/unirest/BaseResponse.java index 8756b770c..4b1ed5164 100644 --- a/src/main/java/unirest/BaseResponse.java +++ b/src/main/java/unirest/BaseResponse.java @@ -37,6 +37,7 @@ abstract class BaseResponse implements HttpResponse { private final Headers headers; private final String statusText; private final int statusCode; + private Optional parsingerror = Optional.empty(); protected BaseResponse(org.apache.http.HttpResponse response){ headers = new Headers(response.getAllHeaders()); @@ -68,7 +69,7 @@ public Headers getHeaders() { @Override public Optional getParsingError() { - return Optional.empty(); + return parsingerror; } @Override @@ -80,4 +81,8 @@ public V mapBody(Function func){ public V mapRawBody(Function func) { return func.apply(getRawBody()); } + + protected void setParsingException(RuntimeException e) { + parsingerror = Optional.of(e); + } } diff --git a/src/main/java/unirest/JsonResponse.java b/src/main/java/unirest/JsonResponse.java new file mode 100644 index 000000000..1c5db0bbf --- /dev/null +++ b/src/main/java/unirest/JsonResponse.java @@ -0,0 +1,82 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.util.EntityUtils; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; + +public class JsonResponse extends BaseResponse { + private JsonNode node; + private InputStream errorStream; + + protected JsonResponse(HttpResponse response) { + super(response); + node = getNode(response.getEntity()); + } + + private JsonNode getNode(HttpEntity entity) { + if(Objects.isNull(entity)){ + return new JsonNode(null); + } else { + try { + String json = EntityUtils.toString(entity); + return toJsonNode(json); + } catch (IOException e) { + throw new UnirestException(e); + } + } + } + + private JsonNode toJsonNode(String json) { + try { + return new JsonNode(json); + }catch (RuntimeException e){ + super.setParsingException(e); + errorStream = new ByteArrayInputStream(json.getBytes()); + return null; + } + } + + @Override + public InputStream getRawBody() { + if(errorStream != null){ + return errorStream; + } + return new ByteArrayInputStream(node.toString().getBytes()); + } + + @Override + public JsonNode getBody() { + return node; + } +} From da2f13d304b6457fc8643c5cee2355dd669d5ce6 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 30 Nov 2018 20:20:06 -0600 Subject: [PATCH 0321/1769] add ObjectResponse go back to old way of parsing InputStream because HttpAsyncClient sucks --- src/main/java/unirest/BaseRequest.java | 41 ++---------- src/main/java/unirest/ObjectResponse.java | 81 +++++++++++++++++++++++ src/main/java/unirest/StringResponse.java | 12 +--- src/main/java/unirest/Util.java | 11 +++ 4 files changed, 99 insertions(+), 46 deletions(-) create mode 100644 src/main/java/unirest/ObjectResponse.java diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 2b7c15e1a..607db9f32 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -33,13 +33,10 @@ import org.apache.http.concurrent.FutureCallback; import java.io.InputStream; -import java.io.UnsupportedEncodingException; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.function.Function; -import static unirest.BodyData.from; - abstract class BaseRequest implements HttpRequest { private Optional objectMapper = Optional.empty(); @@ -157,32 +154,32 @@ public CompletableFuture> asJsonAsync(Callback @Override public HttpResponse asObject(Class responseClass) throws UnirestException { - return request(r -> this.asObject(r, responseClass)); + return request(r -> new ObjectResponse(getObjectMapper(), r, responseClass)); } @Override public HttpResponse asObject(GenericType genericType) throws UnirestException { - return request(r -> this.asObject(r, genericType)); + return request(r -> new ObjectResponse(getObjectMapper(), r, genericType)); } @Override public CompletableFuture> asObjectAsync(Class responseClass) { - return requestAsync(r -> this.asObject(r, responseClass), new CompletableFuture<>()); + return requestAsync(r -> new ObjectResponse(getObjectMapper(), r, responseClass), new CompletableFuture<>()); } @Override public CompletableFuture> asObjectAsync(Class responseClass, Callback callback) { - return requestAsync(r -> this.asObject(r, responseClass), CallbackFuture.wrap(callback)); + return requestAsync(r -> new ObjectResponse(getObjectMapper(), r, responseClass), CallbackFuture.wrap(callback)); } @Override public CompletableFuture> asObjectAsync(GenericType genericType) { - return requestAsync(r -> this.asObject(r, genericType), new CompletableFuture<>()); + return requestAsync(r -> new ObjectResponse(getObjectMapper(), r, genericType), new CompletableFuture<>()); } @Override public CompletableFuture> asObjectAsync(GenericType genericType, Callback callback) { - return requestAsync(r -> this.asObject(r, genericType), CallbackFuture.wrap(callback)); + return requestAsync(r -> new ObjectResponse(getObjectMapper(), r, genericType), CallbackFuture.wrap(callback)); } @Override @@ -249,14 +246,6 @@ public Body getBody() { return null; } - private HttpResponse asObject(org.apache.http.HttpResponse response, Class aClass) { - return new Response<>(response, from(response.getEntity(), b -> toObject(b, aClass))); - } - - private HttpResponse asObject(org.apache.http.HttpResponse response, GenericType genericType) { - return new Response<>(response, from(response.getEntity(), b -> toObject(b, genericType))); - } - private HttpResponse request(Function> transformer) { HttpRequestBase requestObj = new RequestPrep(this, false).prepare(); @@ -274,24 +263,6 @@ private HttpResponse request(Function T toObject(BodyData b, GenericType genericType) { - ObjectMapper o = getObjectMapper(); - return o.readValue(toString(b), genericType); - } - - private T toObject(BodyData b, Class aClass) { - ObjectMapper o = getObjectMapper(); - return o.readValue(toString(b), aClass); - } - - private String toString(BodyData b) { - try { - return new String(b.getRawBytes(), b.getCharset()); - } catch (UnsupportedEncodingException e) { - throw new UnirestException(e); - } - } - private ObjectMapper getObjectMapper() { return objectMapper.orElseGet(config::getObjectMapper); } diff --git a/src/main/java/unirest/ObjectResponse.java b/src/main/java/unirest/ObjectResponse.java new file mode 100644 index 000000000..f75a99adc --- /dev/null +++ b/src/main/java/unirest/ObjectResponse.java @@ -0,0 +1,81 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.Objects; +import java.util.function.Function; + +import static unirest.Util.readString; + +class ObjectResponse extends BaseResponse { + + private final T body; + private final ObjectMapper om; + + ObjectResponse(ObjectMapper om, HttpResponse response, Class to) { + super(response); + this.om = om; + this.body = getBody(response, e -> om.readValue(readString(e), to)); + } + + ObjectResponse(ObjectMapper om, HttpResponse response, GenericType to){ + super(response); + this.om = om; + this.body = getBody(response, e -> om.readValue(readString(e), to)); + } + + private T getBody(HttpResponse response, Function func){ + if(!Objects.isNull(response.getEntity())) { + try { + return func.apply(response.getEntity()); + }catch (RuntimeException e){ + setParsingException(e); + return null; + } + } else { + return null; + } + } + + @Override + public InputStream getRawBody() { + if(body == null){ + return new ByteArrayInputStream(new byte[0]); + } + return new ByteArrayInputStream(om.writeValue(body).getBytes()); + } + + @Override + public T getBody() { + return body; + } +} diff --git a/src/main/java/unirest/StringResponse.java b/src/main/java/unirest/StringResponse.java index c5d2c41d3..0254a1e79 100644 --- a/src/main/java/unirest/StringResponse.java +++ b/src/main/java/unirest/StringResponse.java @@ -28,10 +28,8 @@ import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; -import org.apache.http.util.EntityUtils; import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.InputStream; import java.util.Objects; @@ -43,20 +41,12 @@ public StringResponse(HttpResponse response) { super(response); HttpEntity entity = response.getEntity(); if(Objects.nonNull(entity)){ - body = toString(entity); + body = Util.readString(entity); } else { body = ""; } } - private String toString(HttpEntity b) { - try { - return EntityUtils.toString(b); - } catch (IOException e) { - throw new UnirestException(e); - } - } - @Override public InputStream getRawBody() { return new ByteArrayInputStream(body.getBytes()); diff --git a/src/main/java/unirest/Util.java b/src/main/java/unirest/Util.java index 5bdbd1383..c70533efa 100644 --- a/src/main/java/unirest/Util.java +++ b/src/main/java/unirest/Util.java @@ -26,9 +26,11 @@ package unirest; +import org.apache.http.HttpEntity; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; +import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.*; @@ -86,6 +88,15 @@ static Stream collectExceptions(Optional... ex) { return Stream.of(ex).flatMap(Util::stream); } + public static String readString(HttpEntity b) { + try { + String charSet = ResponseUtils.getCharSet(b); + return new String(ResponseUtils.getRawBody(b), charSet); + } catch (IOException e) { + throw new UnirestException(e); + } + } + @FunctionalInterface public interface ExConsumer{ From d69dd4c4e8b045a3e3878d68c6fb0439a6c23f87 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 30 Nov 2018 20:21:27 -0600 Subject: [PATCH 0322/1769] clean up stuff --- src/main/java/unirest/BaseRequest.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 607db9f32..5786fd6f0 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -139,17 +139,17 @@ public CompletableFuture> asStringAsync(Callback ca @Override public HttpResponse asJson() throws UnirestException { - return request(response -> new JsonResponse(response)); + return request(JsonResponse::new); } @Override public CompletableFuture> asJsonAsync() { - return requestAsync(response -> new JsonResponse(response), new CompletableFuture<>()); + return requestAsync(JsonResponse::new, new CompletableFuture<>()); } @Override public CompletableFuture> asJsonAsync(Callback callback) { - return requestAsync(response -> new JsonResponse(response), CallbackFuture.wrap(callback)); + return requestAsync(JsonResponse::new, CallbackFuture.wrap(callback)); } @Override @@ -169,32 +169,32 @@ public CompletableFuture> asObjectAsync(Class r @Override public CompletableFuture> asObjectAsync(Class responseClass, Callback callback) { - return requestAsync(r -> new ObjectResponse(getObjectMapper(), r, responseClass), CallbackFuture.wrap(callback)); + return requestAsync(r -> new ObjectResponse<>(getObjectMapper(), r, responseClass), CallbackFuture.wrap(callback)); } @Override public CompletableFuture> asObjectAsync(GenericType genericType) { - return requestAsync(r -> new ObjectResponse(getObjectMapper(), r, genericType), new CompletableFuture<>()); + return requestAsync(r -> new ObjectResponse<>(getObjectMapper(), r, genericType), new CompletableFuture<>()); } @Override public CompletableFuture> asObjectAsync(GenericType genericType, Callback callback) { - return requestAsync(r -> new ObjectResponse(getObjectMapper(), r, genericType), CallbackFuture.wrap(callback)); + return requestAsync(r -> new ObjectResponse<>(getObjectMapper(), r, genericType), CallbackFuture.wrap(callback)); } @Override public HttpResponse asBinary() throws UnirestException { - return request(response -> new BinaryResponse(response)); + return request(BinaryResponse::new); } @Override public CompletableFuture> asBinaryAsync() { - return requestAsync(response -> new BinaryResponse(response), new CompletableFuture<>()); + return requestAsync(BinaryResponse::new, new CompletableFuture<>()); } @Override public CompletableFuture> asBinaryAsync(Callback callback) { - return requestAsync(response -> new BinaryResponse(response), CallbackFuture.wrap(callback)); + return requestAsync(BinaryResponse::new, CallbackFuture.wrap(callback)); } private CompletableFuture> requestAsync( From 75765595445cc41c7734ab1c240e1fef772b1317 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 30 Nov 2018 20:51:19 -0600 Subject: [PATCH 0323/1769] rm BodyData --- src/main/java/unirest/BodyData.java | 96 ----------------------------- src/main/java/unirest/Response.java | 11 +--- 2 files changed, 2 insertions(+), 105 deletions(-) delete mode 100644 src/main/java/unirest/BodyData.java diff --git a/src/main/java/unirest/BodyData.java b/src/main/java/unirest/BodyData.java deleted file mode 100644 index c36a7d704..000000000 --- a/src/main/java/unirest/BodyData.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package unirest; - -import org.apache.http.HttpEntity; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.Objects; -import java.util.function.Function; - -import static unirest.ResponseUtils.getCharSet; -import static unirest.ResponseUtils.getRawBody; - -@Deprecated // use at your own risk -class BodyData { - - public static BodyData from(HttpEntity e, Function, T> transformer) { - if(Objects.isNull(e)){ - return new BodyData<>(); - } - BodyData d = new BodyData(e); - d.transformBody(transformer); - return d; - } - - private final String charset; - private final byte[] rawBytes; - private T transFormedBody; - private RuntimeException parseEx; - - private BodyData() { - charset = null; - rawBytes = null; - } - - private BodyData(HttpEntity entity) { - this.charset = getCharSet(entity); - this.rawBytes = getRawBody(entity); - } - - public String getCharset() { - return charset; - } - - public byte[] getRawBytes() { - return rawBytes; - } - - public InputStream getRawInput() { - if(rawBytes == null){ - return new ByteArrayInputStream(new byte[]{}); - } - return new ByteArrayInputStream(rawBytes); - } - - public T getTransFormedBody() { - return transFormedBody; - } - - public RuntimeException getParseEx() { - return parseEx; - } - - private void transformBody(Function, T> transformer) { - try { - this.transFormedBody = transformer.apply(this); - }catch (RuntimeException e){ - parseEx = e; - } - } -} diff --git a/src/main/java/unirest/Response.java b/src/main/java/unirest/Response.java index 19e143bf0..291b86162 100644 --- a/src/main/java/unirest/Response.java +++ b/src/main/java/unirest/Response.java @@ -41,15 +41,8 @@ class Response implements HttpResponse { private InputStream rawBody; private T body; - - public Response(org.apache.http.HttpResponse response, BodyData data){ - this(response); - this.rawBody = data.getRawInput(); - this.body = data.getTransFormedBody(); - this.parsingError = Optional.ofNullable(data.getParseEx()); - } - - public Response(org.apache.http.HttpResponse response, T body, InputStream is){ + + Response(org.apache.http.HttpResponse response, T body, InputStream is){ this(response); this.body = body; this.rawBody = is; From f946b8fc066b15bcb238126d1476ea4a3dbd08db Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 1 Dec 2018 14:15:51 -0600 Subject: [PATCH 0324/1769] deprecate some public methods that expose apache. --- src/main/java/unirest/Body.java | 1 + src/main/java/unirest/Headers.java | 1 + src/main/java/unirest/MultipartBody.java | 11 +++++++---- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/unirest/Body.java b/src/main/java/unirest/Body.java index ee967fb36..137381efb 100644 --- a/src/main/java/unirest/Body.java +++ b/src/main/java/unirest/Body.java @@ -30,6 +30,7 @@ public interface Body { + @Deprecated // In version 4 Apache classes will be abstracted out HttpEntity getEntity(); } diff --git a/src/main/java/unirest/Headers.java b/src/main/java/unirest/Headers.java index f1429d5be..51a03c4a1 100644 --- a/src/main/java/unirest/Headers.java +++ b/src/main/java/unirest/Headers.java @@ -42,6 +42,7 @@ public Headers() { super(String.CASE_INSENSITIVE_ORDER); } + @Deprecated // In version 4 Apache classes will be abstracted out public Headers(Header[] pairs) { for (Header header : pairs) { add(header.getName(), header.getValue()); diff --git a/src/main/java/unirest/MultipartBody.java b/src/main/java/unirest/MultipartBody.java index b24883e66..739695e44 100644 --- a/src/main/java/unirest/MultipartBody.java +++ b/src/main/java/unirest/MultipartBody.java @@ -41,18 +41,21 @@ public interface MultipartBody extends HttpRequest, Body { MultipartBody field(String name, Collection collection); - MultipartBody field(String name, InputStream value, ContentType contentType); - MultipartBody field(String name, File file); MultipartBody field(String name, File file, String contentType); - MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName); + @Deprecated // In version 4 Apache classes will be abstracted out + MultipartBody field(String name, InputStream value, ContentType contentType); - MultipartBody field(String name, InputStream stream, String fileName); + @Deprecated // In version 4 Apache classes will be abstracted out + MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName); + @Deprecated // In version 4 Apache classes will be abstracted out MultipartBody field(String name, byte[] bytes, ContentType contentType, String fileName); + MultipartBody field(String name, InputStream stream, String fileName); + MultipartBody field(String name, byte[] bytes, String fileName); MultipartBody charset(Charset charset); From 69a85a0261c185f0f05e81c354c374861860ad8f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 2 Dec 2018 09:45:27 -0600 Subject: [PATCH 0325/1769] add functional methods to map to objects off of the raw response --- src/main/java/unirest/ApacheResponse.java | 75 ++++++++++++++++ src/main/java/unirest/BaseRequest.java | 19 +++++ src/main/java/unirest/BasicResponse.java | 48 +++++++++++ src/main/java/unirest/HttpRequest.java | 7 ++ src/main/java/unirest/HttpResponse.java | 4 + src/main/java/unirest/RawResponse.java | 42 +++++++++ src/main/java/unirest/Util.java | 6 ++ .../BehaviorTests/ObjectFunctionalTest.java | 85 +++++++++++++++++++ 8 files changed, 286 insertions(+) create mode 100644 src/main/java/unirest/ApacheResponse.java create mode 100644 src/main/java/unirest/BasicResponse.java create mode 100644 src/main/java/unirest/RawResponse.java create mode 100644 src/test/java/BehaviorTests/ObjectFunctionalTest.java diff --git a/src/main/java/unirest/ApacheResponse.java b/src/main/java/unirest/ApacheResponse.java new file mode 100644 index 000000000..f9d8600b5 --- /dev/null +++ b/src/main/java/unirest/ApacheResponse.java @@ -0,0 +1,75 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +class ApacheResponse implements RawResponse { + private final HttpResponse r; + + public ApacheResponse(HttpResponse r){ + this.r = r; + } + + @Override + public int getStatus(){ + return r.getStatusLine().getStatusCode(); + } + + @Override + public String getStatusText(){ + return r.getStatusLine().getReasonPhrase(); + } + + @Override + public Headers getHeaders(){ + return new Headers(r.getAllHeaders()); + } + + @Override + public InputStream getContent(){ + try { + HttpEntity entity = r.getEntity(); + if(entity != null) { + return entity.getContent(); + } + return Util.emptyStream(); + } catch (IOException e) { + throw new UnirestException(e); + } + } + + @Override + public InputStreamReader getContentReader(){ + return new InputStreamReader(getContent()); + } +} diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 5786fd6f0..0eeb252a4 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -162,11 +162,26 @@ public HttpResponse asObject(GenericType genericType) throws UnirestEx return request(r -> new ObjectResponse(getObjectMapper(), r, genericType)); } + @Override + public HttpResponse asObject(Function function) { + return request(funcResponse(function)); + } + + @Override + public CompletableFuture> asObjectAsync(Function function) { + return requestAsync(funcResponse(function), new CompletableFuture<>()); + } + @Override public CompletableFuture> asObjectAsync(Class responseClass) { return requestAsync(r -> new ObjectResponse(getObjectMapper(), r, responseClass), new CompletableFuture<>()); } + @Override + public CompletableFuture> asObjectAsync(Function function, Callback callback) { + return requestAsync(funcResponse(function), CallbackFuture.wrap(callback)); + } + @Override public CompletableFuture> asObjectAsync(Class responseClass, Callback callback) { return requestAsync(r -> new ObjectResponse<>(getObjectMapper(), r, responseClass), CallbackFuture.wrap(callback)); @@ -182,6 +197,10 @@ public CompletableFuture> asObjectAsync(GenericType gener return requestAsync(r -> new ObjectResponse<>(getObjectMapper(), r, genericType), CallbackFuture.wrap(callback)); } + private Function> funcResponse(Function function) { + return r -> new BasicResponse<>(r, function.apply(new ApacheResponse(r))); + } + @Override public HttpResponse asBinary() throws UnirestException { return request(BinaryResponse::new); diff --git a/src/main/java/unirest/BasicResponse.java b/src/main/java/unirest/BasicResponse.java new file mode 100644 index 000000000..ec4abf74c --- /dev/null +++ b/src/main/java/unirest/BasicResponse.java @@ -0,0 +1,48 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import java.io.InputStream; + +class BasicResponse extends BaseResponse { + private final T body; + + public BasicResponse(org.apache.http.HttpResponse httpResponse, T body) { + super(httpResponse); + this.body = body; + } + + @Override + public InputStream getRawBody() { + return null; + } + + @Override + public T getBody() { + return body; + } +} diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index 5f8028ec6..d5e72bfdf 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -30,6 +30,7 @@ import java.util.Collection; import java.util.Map; import java.util.concurrent.CompletableFuture; +import java.util.function.Function; public interface HttpRequest { R routeParam(String name, String value); @@ -70,12 +71,18 @@ public interface HttpRequest { CompletableFuture> asObjectAsync(Class responseClass); + CompletableFuture> asObjectAsync(Function function, Callback callback); + CompletableFuture> asObjectAsync(Class responseClass, Callback callback); CompletableFuture> asObjectAsync(GenericType genericType); CompletableFuture> asObjectAsync(GenericType genericType, Callback callback); + HttpResponse asObject(Function function); + + CompletableFuture> asObjectAsync(Function function); + HttpResponse asBinary() throws UnirestException; CompletableFuture> asBinaryAsync(); diff --git a/src/main/java/unirest/HttpResponse.java b/src/main/java/unirest/HttpResponse.java index 0ec7476d7..5e9ab7398 100644 --- a/src/main/java/unirest/HttpResponse.java +++ b/src/main/java/unirest/HttpResponse.java @@ -41,6 +41,10 @@ public interface HttpResponse { */ Headers getHeaders(); + // This method is a lie. You never get the real raw response from it + // you only get a copy, or worse, the body transformed BACK to a stream + // If you want to use raw content use the new functional methods + @Deprecated InputStream getRawBody(); T getBody(); diff --git a/src/main/java/unirest/RawResponse.java b/src/main/java/unirest/RawResponse.java new file mode 100644 index 000000000..b797a36bf --- /dev/null +++ b/src/main/java/unirest/RawResponse.java @@ -0,0 +1,42 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import java.io.InputStream; +import java.io.InputStreamReader; + +public interface RawResponse { + int getStatus(); + + String getStatusText(); + + Headers getHeaders(); + + InputStream getContent(); + + InputStreamReader getContentReader(); +} diff --git a/src/main/java/unirest/Util.java b/src/main/java/unirest/Util.java index c70533efa..f4092e14e 100644 --- a/src/main/java/unirest/Util.java +++ b/src/main/java/unirest/Util.java @@ -30,7 +30,9 @@ import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.*; @@ -97,6 +99,10 @@ public static String readString(HttpEntity b) { } } + public static InputStream emptyStream() { + return new ByteArrayInputStream(new byte[0]); + } + @FunctionalInterface public interface ExConsumer{ diff --git a/src/test/java/BehaviorTests/ObjectFunctionalTest.java b/src/test/java/BehaviorTests/ObjectFunctionalTest.java new file mode 100644 index 000000000..02d4e3a0f --- /dev/null +++ b/src/test/java/BehaviorTests/ObjectFunctionalTest.java @@ -0,0 +1,85 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package BehaviorTests; + +import com.google.common.collect.ImmutableMap; +import com.google.gson.Gson; +import org.junit.Test; +import unirest.Unirest; + +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +import static com.google.common.collect.ImmutableMap.of; +import static org.junit.Assert.assertEquals; + +public class ObjectFunctionalTest extends BddTest { + private Gson gson = new Gson(); + + @Test + public void canUseAFunctionToTransform() { + MockServer.setJsonAsResponse(of("foo", "bar")); + + Map r = Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asObject(i -> gson.fromJson(i.getContentReader(), HashMap.class)) + .getBody(); + + assertEquals("bar", r.get("foo")); + } + + @Test + public void canUseAFunctionToTransformAsync() throws Exception { + MockServer.setJsonAsResponse(of("foo", "bar")); + + Map r = Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asObjectAsync(i -> gson.fromJson(i.getContentReader(), HashMap.class)) + .get() + .getBody(); + + assertEquals("bar", r.get("foo")); + } + + @Test + public void canUseAFunctionToTransformAsyncWithCallback() throws Exception { + MockServer.setJsonAsResponse(of("foo", "bar")); + + Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asObjectAsync(i -> gson.fromJson(i.getContentReader(), HashMap.class), + r -> { + HashMap map = r.getBody(); + assertEquals("bar", map.get("foo")); + asyncSuccess(); + }); + + assertAsync(); + } +} From 1a0c12b17b0db847e27b7a23a05b6e68cdd9f5cb Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 2 Dec 2018 10:20:09 -0600 Subject: [PATCH 0326/1769] add consumer methods --- checkstyle.xml | 2 +- src/main/java/unirest/BaseRequest.java | 18 +++++ src/main/java/unirest/HttpRequest.java | 5 ++ src/main/java/unirest/HttpResponse.java | 1 + .../java/BehaviorTests/ConsumerTests.java | 67 +++++++++++++++++++ 5 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 src/test/java/BehaviorTests/ConsumerTests.java diff --git a/checkstyle.xml b/checkstyle.xml index 0f2aa22d2..0de24996d 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -145,7 +145,7 @@ - + diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 0eeb252a4..b8266b0a5 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -35,6 +35,7 @@ import java.io.InputStream; import java.util.*; import java.util.concurrent.CompletableFuture; +import java.util.function.Consumer; import java.util.function.Function; abstract class BaseRequest implements HttpRequest { @@ -216,6 +217,23 @@ public CompletableFuture> asBinaryAsync(Callback consumer) { + request(getConsumer(consumer)); + } + + @Override + public void thenConsumeAsync(Consumer consumer) { + requestAsync(getConsumer(consumer), new CompletableFuture<>()); + } + + private Function> getConsumer(Consumer consumer) { + return r -> { + consumer.accept(new ApacheResponse(r)); + return null; + }; + } + private CompletableFuture> requestAsync( Function> transformer, CompletableFuture> callback) { diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index d5e72bfdf..841b65176 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -30,6 +30,7 @@ import java.util.Collection; import java.util.Map; import java.util.concurrent.CompletableFuture; +import java.util.function.Consumer; import java.util.function.Function; public interface HttpRequest { @@ -89,6 +90,10 @@ public interface HttpRequest { CompletableFuture> asBinaryAsync(Callback callback); + void thenConsume(Consumer consumer); + + void thenConsumeAsync(Consumer consumer); + HttpMethod getHttpMethod(); String getUrl(); diff --git a/src/main/java/unirest/HttpResponse.java b/src/main/java/unirest/HttpResponse.java index 5e9ab7398..2cfaf195b 100644 --- a/src/main/java/unirest/HttpResponse.java +++ b/src/main/java/unirest/HttpResponse.java @@ -31,6 +31,7 @@ import java.util.function.Function; public interface HttpResponse { + int getStatus(); String getStatusText(); diff --git a/src/test/java/BehaviorTests/ConsumerTests.java b/src/test/java/BehaviorTests/ConsumerTests.java new file mode 100644 index 000000000..12d692794 --- /dev/null +++ b/src/test/java/BehaviorTests/ConsumerTests.java @@ -0,0 +1,67 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package BehaviorTests; + +import org.junit.After; +import org.junit.Test; +import unirest.Unirest; + +import static org.junit.Assert.assertEquals; + +public class ConsumerTests extends BddTest { + + private int status; + + @Override + @After + public void tearDown() { + super.tearDown(); + status = 0; + } + + @Test + public void canSimplyConsumeAResponse() { + Unirest.get(MockServer.GET) + .thenConsume(r -> status = r.getStatus()); + + assertEquals(200, status); + } + + @Test + public void canSimplyConsumeAResponseAsync() { + Unirest.get(MockServer.GET) + .thenConsumeAsync(r -> status = r.getStatus()); + + long time = System.currentTimeMillis(); + while(System.currentTimeMillis() - time < 5000){ + if(status != 0){ + break; + } + } + assertEquals(200, status); + } +} From 4a00815561281d6dd2db702a61e4d0c801179a04 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 2 Dec 2018 10:30:21 -0600 Subject: [PATCH 0327/1769] add some docs --- src/main/java/unirest/HttpResponse.java | 39 +++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/main/java/unirest/HttpResponse.java b/src/main/java/unirest/HttpResponse.java index 2cfaf195b..81fe0f805 100644 --- a/src/main/java/unirest/HttpResponse.java +++ b/src/main/java/unirest/HttpResponse.java @@ -30,10 +30,19 @@ import java.util.Optional; import java.util.function.Function; +/** + * @param a Http Response holding a specific type of body. + */ public interface HttpResponse { + /** + * @return the HTTP status code. + */ int getStatus(); + /** + * @return status text + */ String getStatusText(); /** @@ -42,17 +51,41 @@ public interface HttpResponse { */ Headers getHeaders(); - // This method is a lie. You never get the real raw response from it - // you only get a copy, or worse, the body transformed BACK to a stream - // If you want to use raw content use the new functional methods + /** + * This method is a lie. You never get the real raw response from it + * you only get a copy, or worse, the body transformed BACK to a stream + * If you want to use raw content use the new functional methods + * @return a copy of the input stream + * */ @Deprecated InputStream getRawBody(); + /** + * @return the body + */ T getBody(); + /** + * If the transformation to the body failed by an exception it will be kept here + * @return a possible RuntimeException. Checked exceptions are wrapped in a UnirestException + */ Optional getParsingError(); + /** + * @param func a function to transform a body type to something else. + * @param The return type of the function + * @return + */ V mapBody(Function func); + /** + * This method is a lie. You never get the real raw response from it + * you only get a copy, or worse, the body transformed BACK to a stream + * If you want to use raw content use the new functional methods + * @param func a function to map a inputstream to a new body + * @param the return type + * @return the return type + */ + @Deprecated V mapRawBody(Function func); } From b90a5f1d9aa8867171aa8c3a0e73002b9ec93291 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 2 Dec 2018 10:56:29 -0600 Subject: [PATCH 0328/1769] add some more docs --- src/main/java/unirest/BaseRequest.java | 5 - src/main/java/unirest/HttpRequest.java | 114 ++++++++++++++++-- .../java/BehaviorTests/FormPostingTest.java | 3 +- 3 files changed, 105 insertions(+), 17 deletions(-) diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index b8266b0a5..ab369d3dc 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -118,11 +118,6 @@ public R withObjectMapper(ObjectMapper mapper) { return (R)this; } - @Override - public HttpRequest getHttpRequest() { - return this; - } - @Override public HttpResponse asString() throws UnirestException { return request(StringResponse::new); diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index 841b65176..109f642b9 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -34,41 +34,135 @@ import java.util.function.Function; public interface HttpRequest { + /** + * add a route param that replaces the matching {name} + * For example routeParam("name", "fred") will replace {name} in + * https://localhost/users/{user} + * to + * https://localhost/users/fred + * + * @param name the name of the param (do not include curly braces {} + * @param value the value to replace the placeholder with + * @return this request builder + */ R routeParam(String name, String value); + /** + * Basic auth credentials + * @param username the username + * @param password the password + * @return this request builder + */ R basicAuth(String username, String password); + /** + * The Accept heder to send (e.g. application/json + * @param value a valid mime type for the Accept header + * @return this request builder + */ R accept(String value); + /** + * Add a http header + * @param name name of the header + * @param value value for the header + * @return this request builder + */ R header(String name, String value); + /** + * Add headers as a map + * @param headerMap a map of headers + * @return this request builder + */ R headers(Map headerMap); - R queryString(String name, Collection value); - + /** + * add a query param to the url. The value will be URL-Encoded + * @param name the name of the param + * @param value the value of the param + * @return this request builder + */ R queryString(String name, Object value); + /** + * Add multiple param with the same param name. + * queryString("name", Arrays.asList("bob", "linda")) will result in + * ?name=bob&name=linda + * @param name the name of the param + * @param value a collection of values + * @return this request builder + */ + R queryString(String name, Collection value); + + /** + * Add query params as a map of name value pairs + * @param parameters a map of params + * @return this request builder + */ R queryString(Map parameters); + /** + * Pass a ObjectMapper for the request. This will override any globally + * configured ObjectMapper + * @param mapper the ObjectMapper + * @return this request builder + */ R withObjectMapper(ObjectMapper mapper); - HttpRequest getHttpRequest(); - - HttpResponse asString() throws UnirestException; + /** + * Executes the request and returns the response with the body mapped into a String + * @return response + */ + HttpResponse asString(); + /** + * Executes the request asynchronously and returns the response with the body mapped into a String + * @return a CompletableFuture of a response + */ CompletableFuture> asStringAsync(); + /** + * Executes the request asynchronously and returns the response with the body mapped into a String + * @param callback a callback handler + * @return a CompletableFuture of a response + */ CompletableFuture> asStringAsync(Callback callback); - HttpResponse asJson() throws UnirestException; + /** + * Executes the request and returns the response with the body mapped into a JsonNode + * @return response + */ + HttpResponse asJson(); + /** + * Executes the request asynchronously and returns the response with the body mapped into a JsonNode + * @return a CompletableFuture of a response + */ CompletableFuture> asJsonAsync(); + /** + * Executes the request asynchronously and returns the response with the body mapped into a JsonNode + * @param callback a callback handler + * @return a CompletableFuture of a response + */ CompletableFuture> asJsonAsync(Callback callback); - HttpResponse asObject(Class responseClass) throws UnirestException; - - HttpResponse asObject(GenericType genericType) throws UnirestException; + /** + * Executes the request and returns the response with the body mapped into T by a supplied ObjectMapper + * @param responseClass the class to return. This will be passed to the ObjectMapper + * @param the return type + * @return a response + */ + HttpResponse asObject(Class responseClass); + + /** + * Executes the request and returns the response with the body mapped into T by a supplied ObjectMapper + * @param genericType the genertic type to return. This will be passed to the ObjectMapper + * @param the return type + * @return a response + */ + HttpResponse asObject(GenericType genericType); CompletableFuture> asObjectAsync(Class responseClass); @@ -84,7 +178,7 @@ public interface HttpRequest { CompletableFuture> asObjectAsync(Function function); - HttpResponse asBinary() throws UnirestException; + HttpResponse asBinary(); CompletableFuture> asBinaryAsync(); diff --git a/src/test/java/BehaviorTests/FormPostingTest.java b/src/test/java/BehaviorTests/FormPostingTest.java index f372fb2a2..ca0edf659 100644 --- a/src/test/java/BehaviorTests/FormPostingTest.java +++ b/src/test/java/BehaviorTests/FormPostingTest.java @@ -256,8 +256,7 @@ public void testPostProvidesSortedParams() throws Exception { HttpRequest httpRequest = Unirest.post("test") .field("z", "Z") .field("y", "Y") - .field("x", "X") - .getHttpRequest(); + .field("x", "X"); InputStream content = httpRequest.getBody().getEntity().getContent(); String body = IOUtils.toString(content, "UTF-8"); From df9185f5a126b86b7b473fb363c919edd71971fc Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 2 Dec 2018 13:08:53 -0600 Subject: [PATCH 0329/1769] rm the function call with the callback because its kind of pointless. Update more docs --- src/main/java/unirest/BaseRequest.java | 5 ----- src/main/java/unirest/HttpRequest.java | 12 ++++++++---- .../java/BehaviorTests/ObjectFunctionalTest.java | 16 ---------------- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index ab369d3dc..2ac0b3341 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -173,11 +173,6 @@ public CompletableFuture> asObjectAsync(Class r return requestAsync(r -> new ObjectResponse(getObjectMapper(), r, responseClass), new CompletableFuture<>()); } - @Override - public CompletableFuture> asObjectAsync(Function function, Callback callback) { - return requestAsync(funcResponse(function), CallbackFuture.wrap(callback)); - } - @Override public CompletableFuture> asObjectAsync(Class responseClass, Callback callback) { return requestAsync(r -> new ObjectResponse<>(getObjectMapper(), r, responseClass), CallbackFuture.wrap(callback)); diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index 109f642b9..59adbaa24 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -149,7 +149,7 @@ public interface HttpRequest { CompletableFuture> asJsonAsync(Callback callback); /** - * Executes the request and returns the response with the body mapped into T by a supplied ObjectMapper + * Executes the request and returns the response with the body mapped into T by a configured ObjectMapper * @param responseClass the class to return. This will be passed to the ObjectMapper * @param the return type * @return a response @@ -157,17 +157,21 @@ public interface HttpRequest { HttpResponse asObject(Class responseClass); /** - * Executes the request and returns the response with the body mapped into T by a supplied ObjectMapper + * Executes the request and returns the response with the body mapped into T by a configured ObjectMapper * @param genericType the genertic type to return. This will be passed to the ObjectMapper * @param the return type * @return a response */ HttpResponse asObject(GenericType genericType); + /** + * Executes the request asynchronously and returns response with the body mapped into T by a configured ObjectMapper + * @param responseClass the class type to map to + * @param the return type + * @return a CompletableFuture of a response + */ CompletableFuture> asObjectAsync(Class responseClass); - CompletableFuture> asObjectAsync(Function function, Callback callback); - CompletableFuture> asObjectAsync(Class responseClass, Callback callback); CompletableFuture> asObjectAsync(GenericType genericType); diff --git a/src/test/java/BehaviorTests/ObjectFunctionalTest.java b/src/test/java/BehaviorTests/ObjectFunctionalTest.java index 02d4e3a0f..b619d2fc8 100644 --- a/src/test/java/BehaviorTests/ObjectFunctionalTest.java +++ b/src/test/java/BehaviorTests/ObjectFunctionalTest.java @@ -66,20 +66,4 @@ public void canUseAFunctionToTransformAsync() throws Exception { assertEquals("bar", r.get("foo")); } - - @Test - public void canUseAFunctionToTransformAsyncWithCallback() throws Exception { - MockServer.setJsonAsResponse(of("foo", "bar")); - - Unirest.get(MockServer.GET) - .queryString("foo", "bar") - .asObjectAsync(i -> gson.fromJson(i.getContentReader(), HashMap.class), - r -> { - HashMap map = r.getBody(); - assertEquals("bar", map.get("foo")); - asyncSuccess(); - }); - - assertAsync(); - } } From dd2e36d8bb90c3afafd1b4cf75563d853fc66aff Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 2 Dec 2018 13:54:00 -0600 Subject: [PATCH 0330/1769] more docs --- src/main/java/unirest/HttpRequest.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index 59adbaa24..b708bbba0 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -164,6 +164,16 @@ public interface HttpRequest { */ HttpResponse asObject(GenericType genericType); + /** + * Execute the request and pass the raw response to a function for mapping. + * This is raw response contains the original InputStream and is suitable for + * reading large responses. + * @param function the function to map the response into a object of T + * @param The type of the response mapping + * @return A HttpResponse containing T as the body + */ + HttpResponse asObject(Function function); + /** * Executes the request asynchronously and returns response with the body mapped into T by a configured ObjectMapper * @param responseClass the class type to map to @@ -178,8 +188,6 @@ public interface HttpRequest { CompletableFuture> asObjectAsync(GenericType genericType, Callback callback); - HttpResponse asObject(Function function); - CompletableFuture> asObjectAsync(Function function); HttpResponse asBinary(); From 877455fd6f173e5efb60981d0741b5943631de56 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 2 Dec 2018 16:05:08 -0600 Subject: [PATCH 0331/1769] More Java doc --- src/main/java/unirest/HttpRequest.java | 69 +++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index b708bbba0..49a9a0a66 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -166,7 +166,7 @@ public interface HttpRequest { /** * Execute the request and pass the raw response to a function for mapping. - * This is raw response contains the original InputStream and is suitable for + * This raw response contains the original InputStream and is suitable for * reading large responses. * @param function the function to map the response into a object of T * @param The type of the response mapping @@ -182,29 +182,96 @@ public interface HttpRequest { */ CompletableFuture> asObjectAsync(Class responseClass); + /** + * Executes the request asynchronously, mapping to a type via the configured object mapper and then passed to a callback handler. + * @param responseClass the type for the ObjectMapper to map to + * @param callback a callback for handling the body post mapping + * @param the return type + * @return a CompletableFuture of a HttpResponse containing the body of T + */ CompletableFuture> asObjectAsync(Class responseClass, Callback callback); + /** + * Executes the request asynchronously, and use a GenericType with the ObjectMapper + * @param genericType the generic type containing the type + * @param the type of the response + * @return a CompletableFuture of a HttpResponse containing the body of T + */ CompletableFuture> asObjectAsync(GenericType genericType); + /** + * Executes the request asynchronously, and use a GenericType with the ObjectMapper + * @param genericType the generic type containing the type + * @param callback a callback for handling the body post mapping + * @param the type of the response + * @return a CompletableFuture of a HttpResponse containing the body of T + */ CompletableFuture> asObjectAsync(GenericType genericType, Callback callback); + /** + * Executes the request asynchronously, and pass the raw response to a function for mapping. + * This raw response contains the original InputStream and is suitable for + * reading large responses + * @param function a function to map the raw request into a object + * @param the type of the response + * @return a CompletableFuture of a HttpResponse containing the body of T + */ CompletableFuture> asObjectAsync(Function function); + /** + * Executes the request and returns a copy of the original InputStream + * @return a HttpResponse with a InputStream + */ HttpResponse asBinary(); + /** + * Executes the request asynchronously and returns a copy of the original InputStream + * @return a CompletableFuture of a HttpResponse with a InputStream + */ CompletableFuture> asBinaryAsync(); + /** + * Executes the request asynchronously and returns a copy of the original InputStream which is passed to a callback + * @param callback the callback + * @return a CompletableFuture of a HttpResponse with a InputStream + */ CompletableFuture> asBinaryAsync(Callback callback); + /** + * Execute the request asynchronously and pass the raw response to a consumer. + * This raw response contains the original InputStream and is suitable for + * reading large responses + * @param consumer a consumer function + */ void thenConsume(Consumer consumer); + /** + * Execute the request and pass the raw response to a consumer. + * This raw response contains the original InputStream and is suitable for + * reading large responses + * @param consumer a consumer function + */ void thenConsumeAsync(Consumer consumer); + /** + * @return The HTTP method of the request + */ HttpMethod getHttpMethod(); + /** + * @return The current URL string for the request + */ String getUrl(); + /** + * @return the current headers for the request + */ Headers getHeaders(); + /** + * Deprecated because it exposes Apache + * @return The current body object. + */ + @Deprecated Body getBody(); } From ee06d501357c386fd429026586e61b9c3adbd579 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 2 Dec 2018 18:47:01 -0600 Subject: [PATCH 0332/1769] final docs --- README.md | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 83e7d160e..34d742b76 100644 --- a/README.md +++ b/README.md @@ -134,12 +134,33 @@ CompletableFuture> future = Unirest.post("http://httpbin. .field("param2", "value2") .asJsonAsync(response -> { int code = response.getStatus(); - Map headers = response.getHeaders(); JsonNode body = response.getBody(); - InputStream rawBody = response.getRawBody(); }); ``` +## Custom mappings and handling large responses +Most response methods (```asString```, ```asJson```, and even ```asBinary```) read the entire +response stream into memory. In order to read the original stream and handle large responses you +can use several functional methods like: + +```java + Map r = Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asObject(i -> new Gson().fromJson(i.getContentReader(), HashMap.class)) + .getBody(); + +``` + +or consumers: + +```java + + Unirest.get(MockServer.GET) + .thenConsumeAsync(r -> { + // something like writing a file to disk + }); +``` + ## File Uploads Creating `multipart` requests with Java is trivial, simply pass along a `File` or an InputStream Object as a field: @@ -160,28 +181,6 @@ HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") .asJson(); ``` -## Byte Stream as Entity Body - -```java -final InputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())); -final byte[] bytes = new byte[stream.available()]; -stream.read(bytes); -stream.close(); -final HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") - .field("name", "Mark") - .field("file", bytes, "image.jpg") - .asJson(); -``` - -## InputStream as Entity Body - -```java -HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") - .field("name", "Mark") - .field("file", new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())), ContentType.APPLICATION_OCTET_STREAM, "image.jpg") - .asJson(); -``` - ## Basic Authentication Authenticating the request with basic authentication can be done by calling the `basicAuth(username, password)` function: ```java From bec7c402d2fae3513b3cfc4b879ad56ac984c0d8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 2 Dec 2018 18:47:51 -0600 Subject: [PATCH 0333/1769] bump minor --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 245e91929..b0d5c975b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.0.05-SNAPSHOT + 3.1.00-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ From 2c216c600012373d4008183c555fee18fd7bbe5d Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 2 Dec 2018 18:51:07 -0600 Subject: [PATCH 0334/1769] moar doc updates --- CHANGELOG.md | 4 ++++ README.md | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 870410cc1..183c59ce2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.1.00 +* Deprecate methods that expose Apache. In the 4 line we will start supporting other clients. Primarily the java one supplied in Java9 (apache will still exist for 8-) +* Add several functional methods for dealing with the raw response before the connection is closed. This is nice for large responses. + ## 3.0.04 * Parsing handler should capture unirest exceptions just like other exceptions. diff --git a/README.md b/README.md index 34d742b76..e9c1f3c75 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This repo is an updated, maintained, and independent fork of the original Mashap io.github.openunirest open-unirest-java - 3.0.04 + 3.1.00 ``` From 58278025df1d031bb2165cc3fbb1199fd877099b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 2 Dec 2018 18:52:52 -0600 Subject: [PATCH 0335/1769] [maven-release-plugin] prepare release v3.1.00 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b0d5c975b..eed60b6e5 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.1.00-SNAPSHOT + 3.1.00 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.1.00 From 357d60730267011ba9259b710ff5ee5a9e2dcf2f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 2 Dec 2018 18:53:04 -0600 Subject: [PATCH 0336/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index eed60b6e5..d6a271e8b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.1.00 + 3.1.01-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.1.00 + HEAD From d5dd9eee308832d178cefc6bb4ea4696d4afc5cd Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 7 Dec 2018 18:42:26 -0600 Subject: [PATCH 0337/1769] addresses #41 maybe. Attempts to restart the reactor if if looks like its down --- src/main/java/unirest/Config.java | 14 ++++++-- src/test/java/BehaviorTests/DefectTest.java | 28 ++++++++++++++++ src/test/java/unirest/ConfigTest.java | 37 ++++++++++++++++++++- src/test/java/unirest/UtilTest.java | 17 ++++++++-- 4 files changed, 91 insertions(+), 5 deletions(-) diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java index 3be095782..c7d3c1dd7 100644 --- a/src/main/java/unirest/Config.java +++ b/src/main/java/unirest/Config.java @@ -33,12 +33,15 @@ import org.apache.http.client.CredentialsProvider; import org.apache.http.client.HttpClient; import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.apache.http.nio.client.HttpAsyncClient; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; +import static unirest.Util.tryCast; + public class Config { public static final int DEFAULT_CONNECTION_TIMEOUT = 10000; public static final int DEFAULT_MAX_CONNECTIONS = 200; @@ -360,14 +363,21 @@ private synchronized void buildClient() { * @return Apache HttpAsyncClient */ public HttpAsyncClient getAsyncHttpClient() { - if (!asyncClient.isPresent()) { + if (!asyncClientIsReady()) { buildAsyncClient(); } return asyncClient.get().getClient(); } + private boolean asyncClientIsReady() { + return asyncClient.isPresent() && + tryCast(asyncClient.get().getClient(), CloseableHttpAsyncClient.class) + .map(CloseableHttpAsyncClient::isRunning) + .orElse(true); + } + private synchronized void buildAsyncClient() { - if (!asyncClient.isPresent()) { + if (!asyncClientIsReady()) { AsyncConfig value = factory.buildAsyncClient(); asyncClient = Optional.of(value); } diff --git a/src/test/java/BehaviorTests/DefectTest.java b/src/test/java/BehaviorTests/DefectTest.java index 907a85fc7..b0365eeb7 100644 --- a/src/test/java/BehaviorTests/DefectTest.java +++ b/src/test/java/BehaviorTests/DefectTest.java @@ -26,11 +26,18 @@ package BehaviorTests; +import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; +import org.apache.http.nio.client.HttpAsyncClient; import unirest.Unirest; import org.junit.Test; +import java.io.IOException; import java.util.HashMap; import java.util.Map; +import java.util.stream.IntStream; + +import static junit.framework.TestCase.assertNotSame; +import static junit.framework.TestCase.assertSame; public class DefectTest extends BddTest { @@ -57,4 +64,25 @@ public void nullAndObjectValuesInMap() { .assertParam("baz", "qux") .assertQueryString("foo&baz=qux"); } + + + @Test + public void issue_41_IllegalThreadStateExceptionUnderHighLoad() throws IOException { + Unirest.get(MockServer.GET).asStringAsync(); + + HttpAsyncClient first = Unirest.config().getAsyncHttpClient(); + IntStream.range(1, 50).forEach(i ->{ + assertSame(first, Unirest.config().getAsyncHttpClient()); + }); + + ((CloseableHttpAsyncClient)Unirest.config().getAsyncHttpClient()).close(); + Unirest.get(MockServer.GET).asStringAsync(); + + HttpAsyncClient second = Unirest.config().getAsyncHttpClient(); + assertNotSame(first, second); + + IntStream.range(1, 50).forEach(i ->{ + assertSame(second, Unirest.config().getAsyncHttpClient()); + }); + } } diff --git a/src/test/java/unirest/ConfigTest.java b/src/test/java/unirest/ConfigTest.java index 9fdc12788..abff081aa 100644 --- a/src/test/java/unirest/ConfigTest.java +++ b/src/test/java/unirest/ConfigTest.java @@ -26,8 +26,8 @@ package unirest; -import org.apache.http.HttpHost; import org.apache.http.client.HttpClient; +import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.apache.http.nio.client.HttpAsyncClient; import org.junit.Test; import org.junit.runner.RunWith; @@ -36,6 +36,7 @@ import static org.junit.Assert.*; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class ConfigTest { @@ -76,4 +77,38 @@ public void onceTheConfigIsRunningYouCannotChangeConfig(){ Unirest.shutDown(); } + + @Test + public void willNotRebuildIfNotClosableAsyncClient() { + HttpAsyncClient c = mock(HttpAsyncClient.class); + config.asyncClient(c); + + assertSame(c, config.getAsyncHttpClient()); + assertSame(c, config.getAsyncHttpClient()); + } + + @Test + public void willRebuildIfEmpty() { + assertSame(config.getAsyncHttpClient(), config.getAsyncHttpClient()); + } + + @Test + public void willRebuildIfClosableAndStopped() { + CloseableHttpAsyncClient c = mock(CloseableHttpAsyncClient.class); + when(c.isRunning()).thenReturn(false); + + config.asyncClient(c); + + assertNotSame(c, config.getAsyncHttpClient()); + } + + @Test + public void willNotRebuildIfRunning() { + CloseableHttpAsyncClient c = mock(CloseableHttpAsyncClient.class); + when(c.isRunning()).thenReturn(true); + + config.asyncClient(c); + + assertSame(c, config.getAsyncHttpClient()); + } } \ No newline at end of file diff --git a/src/test/java/unirest/UtilTest.java b/src/test/java/unirest/UtilTest.java index 31e251221..29f6697f0 100644 --- a/src/test/java/unirest/UtilTest.java +++ b/src/test/java/unirest/UtilTest.java @@ -26,6 +26,9 @@ package unirest; +import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; +import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; +import org.apache.http.nio.client.HttpAsyncClient; import org.junit.Test; import static org.junit.Assert.*; @@ -34,12 +37,22 @@ public class UtilTest { @Test public void canCast() { - Object foo = new Foo(); + Object foo = new Foo(){}; assertEquals(foo, Util.tryCast(foo, Foo.class).get()); assertEquals(false, Util.tryCast("foo", Foo.class).isPresent()); assertEquals(false, Util.tryCast(null, Foo.class).isPresent()); + assertEquals(true, Util.tryCast(new Bar(), Foo.class).isPresent()); } - public class Foo {} + @Test + public void canCastAAsyncClient() { + HttpAsyncClient build = HttpAsyncClientBuilder.create().build(); + + assertEquals(true, Util.tryCast(build, CloseableHttpAsyncClient.class).isPresent()); + } + + public abstract class Foo {} + + public class Bar extends Foo {} } \ No newline at end of file From a14c6965a3df6ca3654e7e96edf4af15bfe8d0ca Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 7 Dec 2018 19:30:59 -0600 Subject: [PATCH 0338/1769] [maven-release-plugin] prepare release v3.1.01 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d6a271e8b..e25017220 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.1.01-SNAPSHOT + 3.1.01 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.1.01 From 7cf89b38f92ca2982a47856104ff66fe04967b9e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 7 Dec 2018 19:31:20 -0600 Subject: [PATCH 0339/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e25017220..c27505201 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.1.01 + 3.1.02-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.1.01 + HEAD From 64a1aeb2d6ecc406dd20db45b739a3a5856e74fd Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 8 Dec 2018 09:58:41 -0600 Subject: [PATCH 0340/1769] update docs --- CHANGELOG.md | 3 +++ README.md | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 183c59ce2..8e21d6166 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 3.1.01 +* Detect if the async client has stopped for some reason and construct a new one. This one may be different from the one that was originally configured so we need to add a way to configure a supplier for clients rather than a direct client. + ## 3.1.00 * Deprecate methods that expose Apache. In the 4 line we will start supporting other clients. Primarily the java one supplied in Java9 (apache will still exist for 8-) * Add several functional methods for dealing with the raw response before the connection is closed. This is nice for large responses. diff --git a/README.md b/README.md index e9c1f3c75..6586c1dc9 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This repo is an updated, maintained, and independent fork of the original Mashap io.github.openunirest open-unirest-java - 3.1.00 + 3.1.01 ``` From 9cf3a9b180e52f6532a2772d4627904a322005a4 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 8 Dec 2018 16:09:46 -0600 Subject: [PATCH 0341/1769] make sure all newly created clients are on --- src/main/java/unirest/ClientFactory.java | 31 +++++++----------------- src/main/java/unirest/Config.java | 28 +++++++++++++++------ src/test/java/unirest/ConfigTest.java | 16 ++++++++++++ 3 files changed, 46 insertions(+), 29 deletions(-) diff --git a/src/main/java/unirest/ClientFactory.java b/src/main/java/unirest/ClientFactory.java index ca4779004..752db07fd 100644 --- a/src/main/java/unirest/ClientFactory.java +++ b/src/main/java/unirest/ClientFactory.java @@ -38,13 +38,8 @@ class ClientFactory { - private final Config config; - public ClientFactory(Config config) { - this.config = config; - } - - public AsyncConfig buildAsyncClient() { + public AsyncConfig buildAsyncClient(Config config) { try { PoolingNHttpClientConnectionManager manager = new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor()); @@ -52,7 +47,7 @@ public AsyncConfig buildAsyncClient() { manager.setDefaultMaxPerRoute(config.getMaxPerRoutes()); HttpAsyncClientBuilder ab = HttpAsyncClientBuilder.create() - .setDefaultRequestConfig(getRequestConfig()) + .setDefaultRequestConfig(getRequestConfig(config)) .setConnectionManager(manager) .setDefaultCredentialsProvider(config.getProxyCreds()) .useSystemProperties(); @@ -60,10 +55,10 @@ public AsyncConfig buildAsyncClient() { if(config.useSystemProperties()){ ab.useSystemProperties(); } - if (shouldDisableRedirects()) { + if (!config.getFollowRedirects()) { ab.setRedirectStrategy(new NoRedirects()); } - if (shouldDisableCookieManagement()) { + if (!config.getEnabledCookieManagement()) { ab.disableCookieManagement(); } config.getInterceptors().forEach(ab::addInterceptorFirst); @@ -79,13 +74,13 @@ public AsyncConfig buildAsyncClient() { } } - public ClientConfig buildHttpClient() { + public ClientConfig buildHttpClient(Config config) { PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(); SyncIdleConnectionMonitorThread syncMonitor = new SyncIdleConnectionMonitorThread(manager); syncMonitor.start(); HttpClientBuilder cb = HttpClientBuilder.create() - .setDefaultRequestConfig(getRequestConfig()) + .setDefaultRequestConfig(getRequestConfig(config)) .setDefaultCredentialsProvider(config.getProxyCreds()) .setConnectionManager(manager) .useSystemProperties(); @@ -93,10 +88,10 @@ public ClientConfig buildHttpClient() { if(config.useSystemProperties()){ cb.useSystemProperties(); } - if (shouldDisableRedirects()) { + if (!config.getFollowRedirects()) { cb.disableRedirectHandling(); } - if (shouldDisableCookieManagement()) { + if (!config.getEnabledCookieManagement()) { cb.disableCookieManagement(); } config.getInterceptors().stream().forEach(cb::addInterceptorFirst); @@ -104,15 +99,7 @@ public ClientConfig buildHttpClient() { return new ClientConfig(cb.build(), manager, syncMonitor); } - private boolean shouldDisableCookieManagement() { - return !config.getEnabledCookieManagement(); - } - - private boolean shouldDisableRedirects() { - return !config.getFollowRedirects(); - } - - private RequestConfig getRequestConfig() { + private RequestConfig getRequestConfig(Config config) { Integer connectionTimeout = config.getConnectionTimeout(); Integer socketTimeout = config.getSocketTimeout(); HttpHost proxy = config.getProxy(); diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java index c7d3c1dd7..bb463b285 100644 --- a/src/main/java/unirest/Config.java +++ b/src/main/java/unirest/Config.java @@ -49,7 +49,7 @@ public class Config { public static final int DEFAULT_CONNECT_TIMEOUT = 10000; public static final int DEFAULT_SOCKET_TIMEOUT = 60000; - private ClientFactory factory = new ClientFactory(this); + private ClientFactory factory; private Optional client = Optional.empty(); private Optional asyncClient = Optional.empty(); @@ -67,6 +67,14 @@ public class Config { private boolean cookieManagement; private boolean useSystemProperties; + public Config(){ + this(new ClientFactory()); + } + + Config(ClientFactory clientFactory){ + this.factory = clientFactory; + setDefaults(); + } private void setDefaults(){ interceptors.clear(); @@ -80,10 +88,6 @@ private void setDefaults(){ cookieManagement = true; } - public Config(){ - setDefaults(); - } - /** * Set the HttpClient implementation to use for every synchronous request * @@ -352,7 +356,7 @@ public HttpClient getClient() { private synchronized void buildClient() { if (!client.isPresent()) { - client = Optional.of(factory.buildHttpClient()); + client = Optional.of(factory.buildHttpClient(this)); } } @@ -378,10 +382,20 @@ private boolean asyncClientIsReady() { private synchronized void buildAsyncClient() { if (!asyncClientIsReady()) { - AsyncConfig value = factory.buildAsyncClient(); + AsyncConfig value = factory.buildAsyncClient(this); + verifyIsOn(value); asyncClient = Optional.of(value); } } + + private void verifyIsOn(AsyncConfig value) { + Boolean isOn = tryCast(value.getClient(), CloseableHttpAsyncClient.class) + .map(CloseableHttpAsyncClient::isRunning) + .orElse(true); + if(!isOn){ + throw new UnirestConfigException("Attempted to get a new async client but it was not started. Please ensure it is"); + } + } // Accessors for unirest. boolean getEnabledCookieManagement() { diff --git a/src/test/java/unirest/ConfigTest.java b/src/test/java/unirest/ConfigTest.java index abff081aa..dd085bd70 100644 --- a/src/test/java/unirest/ConfigTest.java +++ b/src/test/java/unirest/ConfigTest.java @@ -32,6 +32,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; +import org.mockito.Spy; import org.mockito.runners.MockitoJUnitRunner; import static org.junit.Assert.*; @@ -41,6 +42,8 @@ @RunWith(MockitoJUnitRunner.class) public class ConfigTest { + @Spy + private ClientFactory factory; @InjectMocks private Config config; @@ -102,6 +105,19 @@ public void willRebuildIfClosableAndStopped() { assertNotSame(c, config.getAsyncHttpClient()); } + @Test + public void ifTheNextAsyncClientThatIsReturnedIsAlsoOffThrowAnException(){ + CloseableHttpAsyncClient c = mock(CloseableHttpAsyncClient.class); + when(c.isRunning()).thenReturn(false); + config.asyncClient(c); + + when(factory.buildAsyncClient(config)).thenReturn(new AsyncConfig(c, null, null)); + + TestUtil.assertException(() -> config.getAsyncHttpClient(), + UnirestConfigException.class, + "Attempted to get a new async client but it was not started. Please ensure it is"); + } + @Test public void willNotRebuildIfRunning() { CloseableHttpAsyncClient c = mock(CloseableHttpAsyncClient.class); From 990eab74cbec2598c14274acc6251c1b96e6ce50 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 8 Dec 2018 16:16:44 -0600 Subject: [PATCH 0342/1769] rename the configs to be clients. We will move all Apache code into these to make way for other implimentations --- .../{AsyncConfig.java => AsyncClient.java} | 4 ++-- .../{ClientConfig.java => Client.java} | 8 +++---- src/main/java/unirest/ClientFactory.java | 8 +++---- src/main/java/unirest/Config.java | 22 ++++++++++--------- .../java/BehaviorTests/LifeCycleTest.java | 12 +++++----- src/test/java/unirest/ConfigTest.java | 2 +- 6 files changed, 29 insertions(+), 27 deletions(-) rename src/main/java/unirest/{AsyncConfig.java => AsyncClient.java} (97%) rename src/main/java/unirest/{ClientConfig.java => Client.java} (92%) diff --git a/src/main/java/unirest/AsyncConfig.java b/src/main/java/unirest/AsyncClient.java similarity index 97% rename from src/main/java/unirest/AsyncConfig.java rename to src/main/java/unirest/AsyncClient.java index 451bd6f47..4c02cecb8 100644 --- a/src/main/java/unirest/AsyncConfig.java +++ b/src/main/java/unirest/AsyncClient.java @@ -33,13 +33,13 @@ import java.util.Objects; import java.util.stream.Stream; -public class AsyncConfig { +public class AsyncClient { private final HttpAsyncClient client; private final PoolingNHttpClientConnectionManager manager; private final AsyncIdleConnectionMonitorThread syncMonitor; - public AsyncConfig(HttpAsyncClient client, + public AsyncClient(HttpAsyncClient client, PoolingNHttpClientConnectionManager manager, AsyncIdleConnectionMonitorThread syncMonitor) { this.syncMonitor = syncMonitor; diff --git a/src/main/java/unirest/ClientConfig.java b/src/main/java/unirest/Client.java similarity index 92% rename from src/main/java/unirest/ClientConfig.java rename to src/main/java/unirest/Client.java index b61dba79a..a263f2eea 100644 --- a/src/main/java/unirest/ClientConfig.java +++ b/src/main/java/unirest/Client.java @@ -35,14 +35,14 @@ import java.util.Optional; import java.util.stream.Stream; -public class ClientConfig { +public class Client { private final HttpClient client; private final PoolingHttpClientConnectionManager manager; private final SyncIdleConnectionMonitorThread syncMonitor; - public ClientConfig(HttpClient client, - PoolingHttpClientConnectionManager manager, - SyncIdleConnectionMonitorThread syncMonitor) { + public Client(HttpClient client, + PoolingHttpClientConnectionManager manager, + SyncIdleConnectionMonitorThread syncMonitor) { Objects.requireNonNull(client, "Client may not be null"); this.client = client; this.manager = manager; diff --git a/src/main/java/unirest/ClientFactory.java b/src/main/java/unirest/ClientFactory.java index 752db07fd..9f2135737 100644 --- a/src/main/java/unirest/ClientFactory.java +++ b/src/main/java/unirest/ClientFactory.java @@ -39,7 +39,7 @@ class ClientFactory { - public AsyncConfig buildAsyncClient(Config config) { + public AsyncClient buildAsyncClient(Config config) { try { PoolingNHttpClientConnectionManager manager = new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor()); @@ -67,14 +67,14 @@ public AsyncConfig buildAsyncClient(Config config) { build.start(); AsyncIdleConnectionMonitorThread syncMonitor = new AsyncIdleConnectionMonitorThread(manager); syncMonitor.tryStart(); - return new AsyncConfig(build, manager, syncMonitor); + return new AsyncClient(build, manager, syncMonitor); } catch (IOReactorException e) { throw new UnirestConfigException(e); } } - public ClientConfig buildHttpClient(Config config) { + public Client buildHttpClient(Config config) { PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(); SyncIdleConnectionMonitorThread syncMonitor = new SyncIdleConnectionMonitorThread(manager); syncMonitor.start(); @@ -96,7 +96,7 @@ public ClientConfig buildHttpClient(Config config) { } config.getInterceptors().stream().forEach(cb::addInterceptorFirst); - return new ClientConfig(cb.build(), manager, syncMonitor); + return new Client(cb.build(), manager, syncMonitor); } private RequestConfig getRequestConfig(Config config) { diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java index bb463b285..20fca568e 100644 --- a/src/main/java/unirest/Config.java +++ b/src/main/java/unirest/Config.java @@ -51,8 +51,8 @@ public class Config { private ClientFactory factory; - private Optional client = Optional.empty(); - private Optional asyncClient = Optional.empty(); + private Optional client = Optional.empty(); + private Optional asyncClient = Optional.empty(); private Optional objectMapper = Optional.empty(); private List interceptors = new ArrayList<>(); @@ -95,7 +95,7 @@ private void setDefaults(){ * @return this config object */ public Config httpClient(HttpClient httpClient) { - client = Optional.of(new ClientConfig(httpClient, null, null)); + client = Optional.of(new Client(httpClient, null, null)); return this; } @@ -105,7 +105,7 @@ public Config httpClient(HttpClient httpClient) { * @param httpClient Custom httpClient implementation * @return this config object */ - public Config httpClient(ClientConfig httpClient) { + public Config httpClient(Client httpClient) { client = Optional.of(httpClient); return this; } @@ -117,7 +117,7 @@ public Config httpClient(ClientConfig httpClient) { * @return this config object */ public Config asyncClient(HttpAsyncClient value) { - this.asyncClient = Optional.of(new AsyncConfig(value, null, null)); + this.asyncClient = Optional.of(new AsyncClient(value, null, null)); return this; } @@ -127,7 +127,7 @@ public Config asyncClient(HttpAsyncClient value) { * @param value Custom AsyncConfig class. The actual AsyncHttpClient is required. * @return this config object */ - public Config asyncClient(AsyncConfig value) { + public Config asyncClient(AsyncClient value) { asyncClient = Optional.of(value); return this; } @@ -325,8 +325,8 @@ public Config reset() { */ public void shutDown(boolean clearOptions) { List ex = Stream.concat( - client.map(ClientConfig::close).orElseGet(Stream::empty), - asyncClient.map(AsyncConfig::close).orElseGet(Stream::empty) + client.map(Client::close).orElseGet(Stream::empty), + asyncClient.map(AsyncClient::close).orElseGet(Stream::empty) ).collect(Collectors.toList()); client = Optional.empty(); @@ -382,13 +382,13 @@ private boolean asyncClientIsReady() { private synchronized void buildAsyncClient() { if (!asyncClientIsReady()) { - AsyncConfig value = factory.buildAsyncClient(this); + AsyncClient value = factory.buildAsyncClient(this); verifyIsOn(value); asyncClient = Optional.of(value); } } - private void verifyIsOn(AsyncConfig value) { + private void verifyIsOn(AsyncClient value) { Boolean isOn = tryCast(value.getClient(), CloseableHttpAsyncClient.class) .map(CloseableHttpAsyncClient::isRunning) .orElse(true); @@ -396,6 +396,8 @@ private void verifyIsOn(AsyncConfig value) { throw new UnirestConfigException("Attempted to get a new async client but it was not started. Please ensure it is"); } } + + // Accessors for unirest. boolean getEnabledCookieManagement() { diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index 38aba664e..4e360cc4f 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -88,8 +88,8 @@ public void testShutdown() throws IOException { when(asyncClient.isRunning()).thenReturn(true); Unirest.config() - .httpClient(new ClientConfig(httpc, clientManager, connMonitor)) - .asyncClient(new AsyncConfig(asyncClient, manager, asyncMonitor)); + .httpClient(new Client(httpc, clientManager, connMonitor)) + .asyncClient(new AsyncClient(asyncClient, manager, asyncMonitor)); Unirest.shutDown(); @@ -110,8 +110,8 @@ public void willPowerThroughErrors() throws IOException { doThrow(new RuntimeException("5")).when(asyncMonitor).interrupt(); Unirest.config() - .httpClient(new ClientConfig(httpc, clientManager, connMonitor)) - .asyncClient(new AsyncConfig(asyncClient, manager, asyncMonitor)); + .httpClient(new Client(httpc, clientManager, connMonitor)) + .asyncClient(new AsyncClient(asyncClient, manager, asyncMonitor)); TestUtil.assertException(Unirest::shutDown, @@ -134,8 +134,8 @@ public void doesNotBombOnNullOptions() throws IOException { when(asyncClient.isRunning()).thenReturn(true); Unirest.config() - .httpClient(new ClientConfig(httpc, null, null)) - .asyncClient(new AsyncConfig(asyncClient, null, null)); + .httpClient(new Client(httpc, null, null)) + .asyncClient(new AsyncClient(asyncClient, null, null)); Unirest.shutDown(); diff --git a/src/test/java/unirest/ConfigTest.java b/src/test/java/unirest/ConfigTest.java index dd085bd70..ff22afa9a 100644 --- a/src/test/java/unirest/ConfigTest.java +++ b/src/test/java/unirest/ConfigTest.java @@ -111,7 +111,7 @@ public void ifTheNextAsyncClientThatIsReturnedIsAlsoOffThrowAnException(){ when(c.isRunning()).thenReturn(false); config.asyncClient(c); - when(factory.buildAsyncClient(config)).thenReturn(new AsyncConfig(c, null, null)); + when(factory.buildAsyncClient(config)).thenReturn(new AsyncClient(c, null, null)); TestUtil.assertException(() -> config.getAsyncHttpClient(), UnirestConfigException.class, From 7bc721c35bf8c9ecc4bb818d80d11431afd01c1c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 8 Dec 2018 16:28:56 -0600 Subject: [PATCH 0343/1769] move the factory for the client into the Apache client --- src/main/java/unirest/BaseApacheClient.java | 45 +++++++++++++++++++ src/main/java/unirest/Client.java | 48 ++++++++++++++++----- src/main/java/unirest/ClientFactory.java | 27 ------------ src/main/java/unirest/Config.java | 4 +- 4 files changed, 85 insertions(+), 39 deletions(-) create mode 100644 src/main/java/unirest/BaseApacheClient.java diff --git a/src/main/java/unirest/BaseApacheClient.java b/src/main/java/unirest/BaseApacheClient.java new file mode 100644 index 000000000..14af6dd0a --- /dev/null +++ b/src/main/java/unirest/BaseApacheClient.java @@ -0,0 +1,45 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.apache.http.HttpHost; +import org.apache.http.client.config.RequestConfig; + +abstract class BaseApacheClient { + + protected RequestConfig getRequestConfig(Config config) { + Integer connectionTimeout = config.getConnectionTimeout(); + Integer socketTimeout = config.getSocketTimeout(); + HttpHost proxy = config.getProxy(); + return RequestConfig.custom() + .setConnectTimeout(connectionTimeout) + .setSocketTimeout(socketTimeout) + .setConnectionRequestTimeout(socketTimeout) + .setProxy(proxy) + .build(); + } +} diff --git a/src/main/java/unirest/Client.java b/src/main/java/unirest/Client.java index a263f2eea..6a687833e 100644 --- a/src/main/java/unirest/Client.java +++ b/src/main/java/unirest/Client.java @@ -28,25 +28,54 @@ import org.apache.http.client.HttpClient; import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import java.io.Closeable; -import java.util.Objects; import java.util.Optional; import java.util.stream.Stream; -public class Client { +public class Client extends BaseApacheClient { private final HttpClient client; private final PoolingHttpClientConnectionManager manager; private final SyncIdleConnectionMonitorThread syncMonitor; - public Client(HttpClient client, - PoolingHttpClientConnectionManager manager, - SyncIdleConnectionMonitorThread syncMonitor) { - Objects.requireNonNull(client, "Client may not be null"); - this.client = client; - this.manager = manager; - this.syncMonitor = syncMonitor; + public Client(Config config) { + manager = new PoolingHttpClientConnectionManager(); + syncMonitor = new SyncIdleConnectionMonitorThread(manager); + syncMonitor.start(); + + HttpClientBuilder cb = HttpClientBuilder.create() + .setDefaultRequestConfig(getRequestConfig(config)) + .setDefaultCredentialsProvider(config.getProxyCreds()) + .setConnectionManager(manager) + .useSystemProperties(); + + if(config.useSystemProperties()){ + cb.useSystemProperties(); + } + if (!config.getFollowRedirects()) { + cb.disableRedirectHandling(); + } + if (!config.getEnabledCookieManagement()) { + cb.disableCookieManagement(); + } + config.getInterceptors().stream().forEach(cb::addInterceptorFirst); + client = cb.build(); + } + + public Client(HttpClient httpClient) { + this.client = httpClient; + this.manager = null; + this.syncMonitor = null; + } + + public Client(HttpClient httpc, + PoolingHttpClientConnectionManager clientManager, + SyncIdleConnectionMonitorThread connMonitor) { + this.client = httpc; + this.manager = clientManager; + this.syncMonitor = connMonitor; } public HttpClient getClient() { @@ -69,7 +98,6 @@ public Stream close() { Util.tryDo(manager, m -> m.close()), Util.tryDo(syncMonitor, i -> i.interrupt()) ); - } } diff --git a/src/main/java/unirest/ClientFactory.java b/src/main/java/unirest/ClientFactory.java index 9f2135737..8dd2efa87 100644 --- a/src/main/java/unirest/ClientFactory.java +++ b/src/main/java/unirest/ClientFactory.java @@ -28,8 +28,6 @@ import org.apache.http.HttpHost; import org.apache.http.client.config.RequestConfig; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; @@ -74,31 +72,6 @@ public AsyncClient buildAsyncClient(Config config) { } } - public Client buildHttpClient(Config config) { - PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(); - SyncIdleConnectionMonitorThread syncMonitor = new SyncIdleConnectionMonitorThread(manager); - syncMonitor.start(); - - HttpClientBuilder cb = HttpClientBuilder.create() - .setDefaultRequestConfig(getRequestConfig(config)) - .setDefaultCredentialsProvider(config.getProxyCreds()) - .setConnectionManager(manager) - .useSystemProperties(); - - if(config.useSystemProperties()){ - cb.useSystemProperties(); - } - if (!config.getFollowRedirects()) { - cb.disableRedirectHandling(); - } - if (!config.getEnabledCookieManagement()) { - cb.disableCookieManagement(); - } - config.getInterceptors().stream().forEach(cb::addInterceptorFirst); - - return new Client(cb.build(), manager, syncMonitor); - } - private RequestConfig getRequestConfig(Config config) { Integer connectionTimeout = config.getConnectionTimeout(); Integer socketTimeout = config.getSocketTimeout(); diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java index 20fca568e..84bea5227 100644 --- a/src/main/java/unirest/Config.java +++ b/src/main/java/unirest/Config.java @@ -95,7 +95,7 @@ private void setDefaults(){ * @return this config object */ public Config httpClient(HttpClient httpClient) { - client = Optional.of(new Client(httpClient, null, null)); + client = Optional.of(new Client(httpClient)); return this; } @@ -356,7 +356,7 @@ public HttpClient getClient() { private synchronized void buildClient() { if (!client.isPresent()) { - client = Optional.of(factory.buildHttpClient(this)); + client = Optional.of(new Client(this)); } } From 4a3585c7731ae20a28d846ad9e090292953e2c2d Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 8 Dec 2018 17:22:05 -0600 Subject: [PATCH 0344/1769] move isRunning into the async client class --- ...entFactory.java => ApacheAsyncClient.java} | 61 +++++++++++++------ src/main/java/unirest/AsyncClient.java | 36 ++--------- src/main/java/unirest/Config.java | 25 ++++---- .../java/BehaviorTests/LifeCycleTest.java | 6 +- src/test/java/unirest/ConfigTest.java | 8 +-- 5 files changed, 65 insertions(+), 71 deletions(-) rename src/main/java/unirest/{ClientFactory.java => ApacheAsyncClient.java} (60%) diff --git a/src/main/java/unirest/ClientFactory.java b/src/main/java/unirest/ApacheAsyncClient.java similarity index 60% rename from src/main/java/unirest/ClientFactory.java rename to src/main/java/unirest/ApacheAsyncClient.java index 8dd2efa87..35447a720 100644 --- a/src/main/java/unirest/ClientFactory.java +++ b/src/main/java/unirest/ApacheAsyncClient.java @@ -26,21 +26,27 @@ package unirest; -import org.apache.http.HttpHost; -import org.apache.http.client.config.RequestConfig; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor; +import org.apache.http.nio.client.HttpAsyncClient; import org.apache.http.nio.reactor.IOReactorException; -class ClientFactory { +import java.util.Objects; +import java.util.stream.Stream; +import static unirest.Util.tryCast; - public AsyncClient buildAsyncClient(Config config) { +public class ApacheAsyncClient extends BaseApacheClient implements AsyncClient { + private final HttpAsyncClient client; + private final PoolingNHttpClientConnectionManager manager; + private final AsyncIdleConnectionMonitorThread syncMonitor; + + public ApacheAsyncClient(Config config) { try { - PoolingNHttpClientConnectionManager manager = new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor()); + manager = new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor()); manager.setMaxTotal(config.getMaxConnections()); manager.setDefaultMaxPerRoute(config.getMaxPerRoutes()); @@ -63,24 +69,43 @@ public AsyncClient buildAsyncClient(Config config) { CloseableHttpAsyncClient build = ab.build(); build.start(); - AsyncIdleConnectionMonitorThread syncMonitor = new AsyncIdleConnectionMonitorThread(manager); + syncMonitor = new AsyncIdleConnectionMonitorThread(manager); syncMonitor.tryStart(); - return new AsyncClient(build, manager, syncMonitor); - + client = build; } catch (IOReactorException e) { throw new UnirestConfigException(e); } } - private RequestConfig getRequestConfig(Config config) { - Integer connectionTimeout = config.getConnectionTimeout(); - Integer socketTimeout = config.getSocketTimeout(); - HttpHost proxy = config.getProxy(); - return RequestConfig.custom() - .setConnectTimeout(connectionTimeout) - .setSocketTimeout(socketTimeout) - .setConnectionRequestTimeout(socketTimeout) - .setProxy(proxy) - .build(); + public ApacheAsyncClient(HttpAsyncClient client, + PoolingNHttpClientConnectionManager manager, + AsyncIdleConnectionMonitorThread syncMonitor) { + this.syncMonitor = syncMonitor; + Objects.requireNonNull(client, "Client may not be null"); + this.client = client; + this.manager = manager; + } + + @Override + public boolean isRunning() { + return tryCast(client, CloseableHttpAsyncClient.class) + .map(CloseableHttpAsyncClient::isRunning) + .orElse(true); + } + + @Override + public HttpAsyncClient getClient() { + return client; + } + + @Override + public Stream close() { + return Util.collectExceptions(Util.tryCast(client, CloseableHttpAsyncClient.class) + .filter(c -> c.isRunning()) + .map(c -> Util.tryDo(c, d -> d.close())) + .filter(c -> c.isPresent()) + .map(c -> c.get()), + Util.tryDo(manager, m -> m.shutdown()), + Util.tryDo(syncMonitor, m -> m.interrupt())); } } diff --git a/src/main/java/unirest/AsyncClient.java b/src/main/java/unirest/AsyncClient.java index 4c02cecb8..986ad1cf4 100644 --- a/src/main/java/unirest/AsyncClient.java +++ b/src/main/java/unirest/AsyncClient.java @@ -26,40 +26,16 @@ package unirest; -import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; -import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; import org.apache.http.nio.client.HttpAsyncClient; -import java.util.Objects; import java.util.stream.Stream; -public class AsyncClient { - - private final HttpAsyncClient client; - private final PoolingNHttpClientConnectionManager manager; - private final AsyncIdleConnectionMonitorThread syncMonitor; - - public AsyncClient(HttpAsyncClient client, - PoolingNHttpClientConnectionManager manager, - AsyncIdleConnectionMonitorThread syncMonitor) { - this.syncMonitor = syncMonitor; - Objects.requireNonNull(client, "Client may not be null"); - this.client = client; - this.manager = manager; - } - - - public HttpAsyncClient getClient() { - return client; +public interface AsyncClient { + HttpAsyncClient getClient(); + default Stream close() { + return Stream.empty(); } - - public Stream close() { - return Util.collectExceptions(Util.tryCast(client, CloseableHttpAsyncClient.class) - .filter(c -> c.isRunning()) - .map(c -> Util.tryDo(c, d -> d.close())) - .filter(c -> c.isPresent()) - .map(c -> c.get()), - Util.tryDo(manager, m -> m.shutdown()), - Util.tryDo(syncMonitor, m -> m.interrupt())); + default boolean isRunning(){ + return true; } } diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java index 84bea5227..eec46bc34 100644 --- a/src/main/java/unirest/Config.java +++ b/src/main/java/unirest/Config.java @@ -37,6 +37,7 @@ import org.apache.http.nio.client.HttpAsyncClient; import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -49,8 +50,6 @@ public class Config { public static final int DEFAULT_CONNECT_TIMEOUT = 10000; public static final int DEFAULT_SOCKET_TIMEOUT = 60000; - private ClientFactory factory; - private Optional client = Optional.empty(); private Optional asyncClient = Optional.empty(); private Optional objectMapper = Optional.empty(); @@ -66,13 +65,9 @@ public class Config { private boolean followRedirects; private boolean cookieManagement; private boolean useSystemProperties; + private Function asyncBuilder = ApacheAsyncClient::new; - public Config(){ - this(new ClientFactory()); - } - - Config(ClientFactory clientFactory){ - this.factory = clientFactory; + public Config() { setDefaults(); } @@ -117,7 +112,7 @@ public Config httpClient(Client httpClient) { * @return this config object */ public Config asyncClient(HttpAsyncClient value) { - this.asyncClient = Optional.of(new AsyncClient(value, null, null)); + this.asyncClient = Optional.of(new ApacheAsyncClient(value, null, null)); return this; } @@ -132,6 +127,11 @@ public Config asyncClient(AsyncClient value) { return this; } + public Config asyncClient(Function asyncClientBuilder){ + this.asyncBuilder = asyncClientBuilder; + return this; + } + /** * Set a proxy * @@ -382,17 +382,14 @@ private boolean asyncClientIsReady() { private synchronized void buildAsyncClient() { if (!asyncClientIsReady()) { - AsyncClient value = factory.buildAsyncClient(this); + AsyncClient value = asyncBuilder.apply(this); verifyIsOn(value); asyncClient = Optional.of(value); } } private void verifyIsOn(AsyncClient value) { - Boolean isOn = tryCast(value.getClient(), CloseableHttpAsyncClient.class) - .map(CloseableHttpAsyncClient::isRunning) - .orElse(true); - if(!isOn){ + if(!value.isRunning()){ throw new UnirestConfigException("Attempted to get a new async client but it was not started. Please ensure it is"); } } diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index 4e360cc4f..c1d3aaa56 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -89,7 +89,7 @@ public void testShutdown() throws IOException { Unirest.config() .httpClient(new Client(httpc, clientManager, connMonitor)) - .asyncClient(new AsyncClient(asyncClient, manager, asyncMonitor)); + .asyncClient(new ApacheAsyncClient(asyncClient, manager, asyncMonitor)); Unirest.shutDown(); @@ -111,7 +111,7 @@ public void willPowerThroughErrors() throws IOException { Unirest.config() .httpClient(new Client(httpc, clientManager, connMonitor)) - .asyncClient(new AsyncClient(asyncClient, manager, asyncMonitor)); + .asyncClient(new ApacheAsyncClient(asyncClient, manager, asyncMonitor)); TestUtil.assertException(Unirest::shutDown, @@ -135,7 +135,7 @@ public void doesNotBombOnNullOptions() throws IOException { Unirest.config() .httpClient(new Client(httpc, null, null)) - .asyncClient(new AsyncClient(asyncClient, null, null)); + .asyncClient(new ApacheAsyncClient(asyncClient, null, null)); Unirest.shutDown(); diff --git a/src/test/java/unirest/ConfigTest.java b/src/test/java/unirest/ConfigTest.java index ff22afa9a..9b3370fd3 100644 --- a/src/test/java/unirest/ConfigTest.java +++ b/src/test/java/unirest/ConfigTest.java @@ -32,7 +32,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.Spy; import org.mockito.runners.MockitoJUnitRunner; import static org.junit.Assert.*; @@ -42,8 +41,6 @@ @RunWith(MockitoJUnitRunner.class) public class ConfigTest { - @Spy - private ClientFactory factory; @InjectMocks private Config config; @@ -107,11 +104,10 @@ public void willRebuildIfClosableAndStopped() { @Test public void ifTheNextAsyncClientThatIsReturnedIsAlsoOffThrowAnException(){ - CloseableHttpAsyncClient c = mock(CloseableHttpAsyncClient.class); + AsyncClient c = mock(AsyncClient.class); when(c.isRunning()).thenReturn(false); - config.asyncClient(c); + config.asyncClient(g -> c); - when(factory.buildAsyncClient(config)).thenReturn(new AsyncClient(c, null, null)); TestUtil.assertException(() -> config.getAsyncHttpClient(), UnirestConfigException.class, From b4d9e8c77efc72a4b86e4a47ae4c7c352d49473c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 8 Dec 2018 17:31:17 -0600 Subject: [PATCH 0345/1769] add a builder for the client --- src/main/java/unirest/ApacheClient.java | 105 ++++++++++++++++++ src/main/java/unirest/Client.java | 98 +--------------- src/main/java/unirest/Config.java | 16 ++- .../java/BehaviorTests/LifeCycleTest.java | 6 +- 4 files changed, 125 insertions(+), 100 deletions(-) create mode 100644 src/main/java/unirest/ApacheClient.java diff --git a/src/main/java/unirest/ApacheClient.java b/src/main/java/unirest/ApacheClient.java new file mode 100644 index 000000000..774923ab2 --- /dev/null +++ b/src/main/java/unirest/ApacheClient.java @@ -0,0 +1,105 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.apache.http.client.HttpClient; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; + +import java.io.Closeable; +import java.util.Optional; +import java.util.stream.Stream; + +public class ApacheClient extends BaseApacheClient implements Client { + private final HttpClient client; + private final PoolingHttpClientConnectionManager manager; + private final SyncIdleConnectionMonitorThread syncMonitor; + + public ApacheClient(Config config) { + manager = new PoolingHttpClientConnectionManager(); + syncMonitor = new SyncIdleConnectionMonitorThread(manager); + syncMonitor.start(); + + HttpClientBuilder cb = HttpClientBuilder.create() + .setDefaultRequestConfig(getRequestConfig(config)) + .setDefaultCredentialsProvider(config.getProxyCreds()) + .setConnectionManager(manager) + .useSystemProperties(); + + if(config.useSystemProperties()){ + cb.useSystemProperties(); + } + if (!config.getFollowRedirects()) { + cb.disableRedirectHandling(); + } + if (!config.getEnabledCookieManagement()) { + cb.disableCookieManagement(); + } + config.getInterceptors().stream().forEach(cb::addInterceptorFirst); + client = cb.build(); + } + + public ApacheClient(HttpClient httpClient) { + this.client = httpClient; + this.manager = null; + this.syncMonitor = null; + } + + public ApacheClient(HttpClient httpc, + PoolingHttpClientConnectionManager clientManager, + SyncIdleConnectionMonitorThread connMonitor) { + this.client = httpc; + this.manager = clientManager; + this.syncMonitor = connMonitor; + } + + @Override + public HttpClient getClient() { + return client; + } + + public PoolingHttpClientConnectionManager getManager() { + return manager; + } + + public SyncIdleConnectionMonitorThread getSyncMonitor() { + return syncMonitor; + } + + @Override + public Stream close() { + return Util.collectExceptions(Util.tryCast(client, CloseableHttpClient.class) + .map(c -> Util.tryDo(c, Closeable::close)) + .filter(Optional::isPresent) + .map(Optional::get), + Util.tryDo(manager, m -> m.close()), + Util.tryDo(syncMonitor, i -> i.interrupt()) + ); + } + +} diff --git a/src/main/java/unirest/Client.java b/src/main/java/unirest/Client.java index 6a687833e..ff807a076 100644 --- a/src/main/java/unirest/Client.java +++ b/src/main/java/unirest/Client.java @@ -1,103 +1,11 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - package unirest; import org.apache.http.client.HttpClient; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; -import java.io.Closeable; -import java.util.Optional; import java.util.stream.Stream; -public class Client extends BaseApacheClient { - private final HttpClient client; - private final PoolingHttpClientConnectionManager manager; - private final SyncIdleConnectionMonitorThread syncMonitor; - - public Client(Config config) { - manager = new PoolingHttpClientConnectionManager(); - syncMonitor = new SyncIdleConnectionMonitorThread(manager); - syncMonitor.start(); - - HttpClientBuilder cb = HttpClientBuilder.create() - .setDefaultRequestConfig(getRequestConfig(config)) - .setDefaultCredentialsProvider(config.getProxyCreds()) - .setConnectionManager(manager) - .useSystemProperties(); - - if(config.useSystemProperties()){ - cb.useSystemProperties(); - } - if (!config.getFollowRedirects()) { - cb.disableRedirectHandling(); - } - if (!config.getEnabledCookieManagement()) { - cb.disableCookieManagement(); - } - config.getInterceptors().stream().forEach(cb::addInterceptorFirst); - client = cb.build(); - } - - public Client(HttpClient httpClient) { - this.client = httpClient; - this.manager = null; - this.syncMonitor = null; - } - - public Client(HttpClient httpc, - PoolingHttpClientConnectionManager clientManager, - SyncIdleConnectionMonitorThread connMonitor) { - this.client = httpc; - this.manager = clientManager; - this.syncMonitor = connMonitor; - } - - public HttpClient getClient() { - return client; - } - - public PoolingHttpClientConnectionManager getManager() { - return manager; - } - - public SyncIdleConnectionMonitorThread getSyncMonitor() { - return syncMonitor; - } - - public Stream close() { - return Util.collectExceptions(Util.tryCast(client, CloseableHttpClient.class) - .map(c -> Util.tryDo(c, Closeable::close)) - .filter(Optional::isPresent) - .map(Optional::get), - Util.tryDo(manager, m -> m.close()), - Util.tryDo(syncMonitor, i -> i.interrupt()) - ); - } +public interface Client { + HttpClient getClient(); + Stream close(); } diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java index eec46bc34..f8554f56d 100644 --- a/src/main/java/unirest/Config.java +++ b/src/main/java/unirest/Config.java @@ -66,6 +66,7 @@ public class Config { private boolean cookieManagement; private boolean useSystemProperties; private Function asyncBuilder = ApacheAsyncClient::new; + private Function clientBuilder = ApacheClient::new; public Config() { setDefaults(); @@ -90,7 +91,7 @@ private void setDefaults(){ * @return this config object */ public Config httpClient(HttpClient httpClient) { - client = Optional.of(new Client(httpClient)); + client = Optional.of(new ApacheClient(httpClient)); return this; } @@ -105,6 +106,17 @@ public Config httpClient(Client httpClient) { return this; } + /** + * Provide a builder for a client + * + * @param httpClient Custom httpClient implementation + * @return this config object + */ + public Config httpClient(Function httpClient) { + clientBuilder = httpClient; + return this; + } + /** * Set the asynchronous AbstractHttpAsyncClient implementation to use for every asynchronous request * @@ -356,7 +368,7 @@ public HttpClient getClient() { private synchronized void buildClient() { if (!client.isPresent()) { - client = Optional.of(new Client(this)); + client = Optional.of(clientBuilder.apply(this)); } } diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index c1d3aaa56..6f2cdd5a5 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -88,7 +88,7 @@ public void testShutdown() throws IOException { when(asyncClient.isRunning()).thenReturn(true); Unirest.config() - .httpClient(new Client(httpc, clientManager, connMonitor)) + .httpClient(new ApacheClient(httpc, clientManager, connMonitor)) .asyncClient(new ApacheAsyncClient(asyncClient, manager, asyncMonitor)); Unirest.shutDown(); @@ -110,7 +110,7 @@ public void willPowerThroughErrors() throws IOException { doThrow(new RuntimeException("5")).when(asyncMonitor).interrupt(); Unirest.config() - .httpClient(new Client(httpc, clientManager, connMonitor)) + .httpClient(new ApacheClient(httpc, clientManager, connMonitor)) .asyncClient(new ApacheAsyncClient(asyncClient, manager, asyncMonitor)); @@ -134,7 +134,7 @@ public void doesNotBombOnNullOptions() throws IOException { when(asyncClient.isRunning()).thenReturn(true); Unirest.config() - .httpClient(new Client(httpc, null, null)) + .httpClient(new ApacheClient(httpc, null, null)) .asyncClient(new ApacheAsyncClient(asyncClient, null, null)); Unirest.shutDown(); From 9472ac7674afe011a89e5a9291a0486b68527c90 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 8 Dec 2018 17:37:58 -0600 Subject: [PATCH 0346/1769] use the isRunning from the async client directly --- src/main/java/unirest/Client.java | 26 ++++++++++++++++++++++++++ src/main/java/unirest/Config.java | 20 ++++++++++++-------- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/main/java/unirest/Client.java b/src/main/java/unirest/Client.java index ff807a076..ac03ff815 100644 --- a/src/main/java/unirest/Client.java +++ b/src/main/java/unirest/Client.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import org.apache.http.client.HttpClient; diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java index f8554f56d..8f563b540 100644 --- a/src/main/java/unirest/Config.java +++ b/src/main/java/unirest/Config.java @@ -33,16 +33,15 @@ import org.apache.http.client.CredentialsProvider; import org.apache.http.client.HttpClient; import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.apache.http.nio.client.HttpAsyncClient; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; -import static unirest.Util.tryCast; - public class Config { public static final int DEFAULT_CONNECTION_TIMEOUT = 10000; public static final int DEFAULT_MAX_CONNECTIONS = 200; @@ -139,6 +138,12 @@ public Config asyncClient(AsyncClient value) { return this; } + /** + * Set the full async configuration including monitors. These will be shutDown on a Unirest.shudown() + * + * @param asyncClientBuilder A builder function for creating a AsyncClient + * @return this config object + */ public Config asyncClient(Function asyncClientBuilder){ this.asyncBuilder = asyncClientBuilder; return this; @@ -386,10 +391,9 @@ public HttpAsyncClient getAsyncHttpClient() { } private boolean asyncClientIsReady() { - return asyncClient.isPresent() && - tryCast(asyncClient.get().getClient(), CloseableHttpAsyncClient.class) - .map(CloseableHttpAsyncClient::isRunning) - .orElse(true); + return asyncClient + .map(AsyncClient::isRunning) + .orElse(false); } private synchronized void buildAsyncClient() { From ac5bc12a3ea2a23b5be7f072b6d8c675014135d4 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 9 Dec 2018 10:53:25 -0600 Subject: [PATCH 0347/1769] hide apache --- src/main/java/unirest/ApacheResponse.java | 76 +++++++++++++++++++- src/main/java/unirest/BaseRequest.java | 16 ++--- src/main/java/unirest/BaseResponse.java | 11 ++- src/main/java/unirest/BasicResponse.java | 2 +- src/main/java/unirest/BinaryResponse.java | 18 +---- src/main/java/unirest/JsonResponse.java | 25 +++---- src/main/java/unirest/ObjectResponse.java | 14 ++-- src/main/java/unirest/RawResponse.java | 8 +-- src/main/java/unirest/ResponseUtils.java | 65 ++--------------- src/main/java/unirest/StringResponse.java | 11 +-- src/main/java/unirest/Util.java | 5 +- src/test/java/unirest/ResponseUtilsTest.java | 12 ++-- 12 files changed, 123 insertions(+), 140 deletions(-) diff --git a/src/main/java/unirest/ApacheResponse.java b/src/main/java/unirest/ApacheResponse.java index f9d8600b5..7753a813c 100644 --- a/src/main/java/unirest/ApacheResponse.java +++ b/src/main/java/unirest/ApacheResponse.java @@ -26,12 +26,13 @@ package unirest; +import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; +import org.apache.http.util.EntityUtils; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; +import java.io.*; +import java.util.zip.GZIPInputStream; class ApacheResponse implements RawResponse { private final HttpResponse r; @@ -68,8 +69,77 @@ public InputStream getContent(){ } } + @Override + public byte[] getContentAsBytes() { + if(!hasContent()){ + return new byte[0]; + } + try { + InputStream is = getContent(); + if (isGzipped(getEncoding())) { + is = new GZIPInputStream(getContent()); + } + return getBytes(is); + } catch (IOException e2) { + throw new UnirestException(e2); + } finally { + EntityUtils.consumeQuietly(r.getEntity()); + } + } + @Override public InputStreamReader getContentReader(){ return new InputStreamReader(getContent()); } + + @Override + public boolean hasContent() { + return r.getEntity() != null; + } + + @Override + public String getContentType() { + if(hasContent()){ + Header contentType = r.getEntity().getContentType(); + if(contentType != null){ + return contentType.getValue(); + } + } + return ""; + } + + @Override + public String getEncoding() { + if(hasContent()){ + Header contentType = r.getEntity().getContentEncoding(); + if(contentType != null){ + return contentType.getValue(); + } + } + return ""; + } + + private static byte[] getBytes(InputStream is) throws IOException { + int len; + int size = 1024; + byte[] buf; + + if (is instanceof ByteArrayInputStream) { + size = is.available(); + buf = new byte[size]; + len = is.read(buf, 0, size); + } else { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + buf = new byte[size]; + while ((len = is.read(buf, 0, size)) != -1) { + bos.write(buf, 0, len); + } + buf = bos.toByteArray(); + } + return buf; + } + + private static boolean isGzipped(String value) { + return "gzip".equalsIgnoreCase(value.toLowerCase().trim()); + } } diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 2ac0b3341..15c60d801 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -188,8 +188,8 @@ public CompletableFuture> asObjectAsync(GenericType gener return requestAsync(r -> new ObjectResponse<>(getObjectMapper(), r, genericType), CallbackFuture.wrap(callback)); } - private Function> funcResponse(Function function) { - return r -> new BasicResponse<>(r, function.apply(new ApacheResponse(r))); + private Function> funcResponse(Function function) { + return r -> new BasicResponse<>(r, function.apply(r)); } @Override @@ -217,15 +217,15 @@ public void thenConsumeAsync(Consumer consumer) { requestAsync(getConsumer(consumer), new CompletableFuture<>()); } - private Function> getConsumer(Consumer consumer) { + private Function> getConsumer(Consumer consumer) { return r -> { - consumer.accept(new ApacheResponse(r)); + consumer.accept(r); return null; }; } private CompletableFuture> requestAsync( - Function> transformer, + Function> transformer, CompletableFuture> callback) { Objects.requireNonNull(callback); @@ -236,7 +236,7 @@ private CompletableFuture> requestAsync( .execute(requestObj, new FutureCallback() { @Override public void completed(org.apache.http.HttpResponse httpResponse) { - callback.complete(transformer.apply(httpResponse)); + callback.complete(transformer.apply(new ApacheResponse(httpResponse))); } @Override @@ -273,14 +273,14 @@ public Body getBody() { return null; } - private HttpResponse request(Function> transformer) { + private HttpResponse request(Function> transformer) { HttpRequestBase requestObj = new RequestPrep(this, false).prepare(); HttpClient client = config.getClient(); try { org.apache.http.HttpResponse execute = client.execute(requestObj); - HttpResponse httpResponse = transformer.apply(execute); + HttpResponse httpResponse = transformer.apply(new ApacheResponse(execute)); requestObj.releaseConnection(); return httpResponse; } catch (Exception e) { diff --git a/src/main/java/unirest/BaseResponse.java b/src/main/java/unirest/BaseResponse.java index 4b1ed5164..06eee0c8a 100644 --- a/src/main/java/unirest/BaseResponse.java +++ b/src/main/java/unirest/BaseResponse.java @@ -26,8 +26,6 @@ package unirest; -import org.apache.http.StatusLine; - import java.io.InputStream; import java.util.Optional; import java.util.function.Function; @@ -39,11 +37,10 @@ abstract class BaseResponse implements HttpResponse { private final int statusCode; private Optional parsingerror = Optional.empty(); - protected BaseResponse(org.apache.http.HttpResponse response){ - headers = new Headers(response.getAllHeaders()); - StatusLine statusLine = response.getStatusLine(); - this.statusCode = statusLine.getStatusCode(); - this.statusText = statusLine.getReasonPhrase(); + protected BaseResponse(RawResponse response){ + headers = response.getHeaders(); + this.statusCode = response.getStatus(); + this.statusText = response.getStatusText(); } @Override diff --git a/src/main/java/unirest/BasicResponse.java b/src/main/java/unirest/BasicResponse.java index ec4abf74c..5eff192ec 100644 --- a/src/main/java/unirest/BasicResponse.java +++ b/src/main/java/unirest/BasicResponse.java @@ -31,7 +31,7 @@ class BasicResponse extends BaseResponse { private final T body; - public BasicResponse(org.apache.http.HttpResponse httpResponse, T body) { + public BasicResponse(RawResponse httpResponse, T body) { super(httpResponse); this.body = body; } diff --git a/src/main/java/unirest/BinaryResponse.java b/src/main/java/unirest/BinaryResponse.java index 90a4dc523..ec721fba3 100644 --- a/src/main/java/unirest/BinaryResponse.java +++ b/src/main/java/unirest/BinaryResponse.java @@ -26,32 +26,20 @@ package unirest; -import org.apache.http.HttpResponse; -import org.apache.http.util.EntityUtils; - import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.InputStream; -import java.util.Objects; public class BinaryResponse extends BaseResponse { private InputStream body; - protected BinaryResponse(HttpResponse response) { + protected BinaryResponse(RawResponse response) { super(response); body = new ByteArrayInputStream(getBody(response)); } - private byte[] getBody(HttpResponse response) { - if (Objects.isNull(response.getEntity())) { - return new byte[0]; - } - try { - return EntityUtils.toByteArray(response.getEntity()); - } catch (IOException e) { - throw new UnirestException(e); - } + private byte[] getBody(RawResponse response) { + return response.getContentAsBytes(); } @Override diff --git a/src/main/java/unirest/JsonResponse.java b/src/main/java/unirest/JsonResponse.java index 1c5db0bbf..9684551d9 100644 --- a/src/main/java/unirest/JsonResponse.java +++ b/src/main/java/unirest/JsonResponse.java @@ -26,12 +26,7 @@ package unirest; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.util.EntityUtils; - import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.InputStream; import java.util.Objects; @@ -39,28 +34,24 @@ public class JsonResponse extends BaseResponse { private JsonNode node; private InputStream errorStream; - protected JsonResponse(HttpResponse response) { + protected JsonResponse(RawResponse response) { super(response); - node = getNode(response.getEntity()); + node = getNode(response); } - private JsonNode getNode(HttpEntity entity) { - if(Objects.isNull(entity)){ + private JsonNode getNode(RawResponse response) { + if (Objects.isNull(response) || !response.hasContent()) { return new JsonNode(null); } else { - try { - String json = EntityUtils.toString(entity); - return toJsonNode(json); - } catch (IOException e) { - throw new UnirestException(e); - } + String json = Util.readString(response); + return toJsonNode(json); } } private JsonNode toJsonNode(String json) { try { return new JsonNode(json); - }catch (RuntimeException e){ + } catch (RuntimeException e) { super.setParsingException(e); errorStream = new ByteArrayInputStream(json.getBytes()); return null; @@ -69,7 +60,7 @@ private JsonNode toJsonNode(String json) { @Override public InputStream getRawBody() { - if(errorStream != null){ + if (errorStream != null) { return errorStream; } return new ByteArrayInputStream(node.toString().getBytes()); diff --git a/src/main/java/unirest/ObjectResponse.java b/src/main/java/unirest/ObjectResponse.java index f75a99adc..decf0c543 100644 --- a/src/main/java/unirest/ObjectResponse.java +++ b/src/main/java/unirest/ObjectResponse.java @@ -26,12 +26,8 @@ package unirest; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; - import java.io.ByteArrayInputStream; import java.io.InputStream; -import java.util.Objects; import java.util.function.Function; import static unirest.Util.readString; @@ -41,22 +37,22 @@ class ObjectResponse extends BaseResponse { private final T body; private final ObjectMapper om; - ObjectResponse(ObjectMapper om, HttpResponse response, Class to) { + ObjectResponse(ObjectMapper om, RawResponse response, Class to) { super(response); this.om = om; this.body = getBody(response, e -> om.readValue(readString(e), to)); } - ObjectResponse(ObjectMapper om, HttpResponse response, GenericType to){ + ObjectResponse(ObjectMapper om, RawResponse response, GenericType to){ super(response); this.om = om; this.body = getBody(response, e -> om.readValue(readString(e), to)); } - private T getBody(HttpResponse response, Function func){ - if(!Objects.isNull(response.getEntity())) { + private T getBody(RawResponse response, Function func){ + if(response.hasContent()) { try { - return func.apply(response.getEntity()); + return func.apply(response); }catch (RuntimeException e){ setParsingException(e); return null; diff --git a/src/main/java/unirest/RawResponse.java b/src/main/java/unirest/RawResponse.java index b797a36bf..18dc89d89 100644 --- a/src/main/java/unirest/RawResponse.java +++ b/src/main/java/unirest/RawResponse.java @@ -31,12 +31,12 @@ public interface RawResponse { int getStatus(); - String getStatusText(); - Headers getHeaders(); - InputStream getContent(); - + byte[] getContentAsBytes(); InputStreamReader getContentReader(); + boolean hasContent(); + String getContentType(); + String getEncoding(); } diff --git a/src/main/java/unirest/ResponseUtils.java b/src/main/java/unirest/ResponseUtils.java index 042b00efc..b4b71db7a 100644 --- a/src/main/java/unirest/ResponseUtils.java +++ b/src/main/java/unirest/ResponseUtils.java @@ -26,47 +26,22 @@ package unirest; -import org.apache.http.Header; -import org.apache.http.HttpEntity; -import org.apache.http.util.EntityUtils; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.zip.GZIPInputStream; class ResponseUtils { private static final Pattern CHARSET_PATTERN = Pattern.compile("(?i)\\bcharset=\\s*\"?([^\\s;\"]*)"); - static String getCharSet(HttpEntity responseEntity) { - Header contentType = responseEntity.getContentType(); - if (contentType != null) { - String responseCharset = getCharsetFromContentType(contentType.getValue()); - if (responseCharset != null && !responseCharset.trim().equals("")) { - return responseCharset; - } + static String getCharSet(RawResponse responseEntity) { + String contentType = responseEntity.getContentType(); + String responseCharset = getCharsetFromContentType(contentType); + if (responseCharset != null && !responseCharset.trim().equals("")) { + return responseCharset; } return "UTF-8"; } - static byte[] getRawBody(HttpEntity responseEntity) { - try { - InputStream is = responseEntity.getContent(); - if (isGzipped(responseEntity.getContentEncoding())) { - is = new GZIPInputStream(responseEntity.getContent()); - } - return getBytes(is); - } catch (IOException e2) { - throw new UnirestException(e2); - } finally { - EntityUtils.consumeQuietly(responseEntity); - } - } - /** * Parse out a charset from a content type header. * @@ -84,34 +59,4 @@ private static String getCharsetFromContentType(String contentType) { } return null; } - - private static byte[] getBytes(InputStream is) throws IOException { - int len; - int size = 1024; - byte[] buf; - - if (is instanceof ByteArrayInputStream) { - size = is.available(); - buf = new byte[size]; - len = is.read(buf, 0, size); - } else { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - buf = new byte[size]; - while ((len = is.read(buf, 0, size)) != -1) { - bos.write(buf, 0, len); - } - buf = bos.toByteArray(); - } - return buf; - } - - private static boolean isGzipped(Header contentEncoding) { - if (contentEncoding != null) { - String value = contentEncoding.getValue(); - if (value != null && "gzip".equals(value.toLowerCase().trim())) { - return true; - } - } - return false; - } } diff --git a/src/main/java/unirest/StringResponse.java b/src/main/java/unirest/StringResponse.java index 0254a1e79..59e491fd2 100644 --- a/src/main/java/unirest/StringResponse.java +++ b/src/main/java/unirest/StringResponse.java @@ -26,22 +26,17 @@ package unirest; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; - import java.io.ByteArrayInputStream; import java.io.InputStream; -import java.util.Objects; public class StringResponse extends BaseResponse { private String body; - public StringResponse(HttpResponse response) { + public StringResponse(RawResponse response) { super(response); - HttpEntity entity = response.getEntity(); - if(Objects.nonNull(entity)){ - body = Util.readString(entity); + if(response.hasContent()){ + body = Util.readString(response); } else { body = ""; } diff --git a/src/main/java/unirest/Util.java b/src/main/java/unirest/Util.java index f4092e14e..c33247f9d 100644 --- a/src/main/java/unirest/Util.java +++ b/src/main/java/unirest/Util.java @@ -26,7 +26,6 @@ package unirest; -import org.apache.http.HttpEntity; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; @@ -90,10 +89,10 @@ static Stream collectExceptions(Optional... ex) { return Stream.of(ex).flatMap(Util::stream); } - public static String readString(HttpEntity b) { + public static String readString(RawResponse b) { try { String charSet = ResponseUtils.getCharSet(b); - return new String(ResponseUtils.getRawBody(b), charSet); + return new String(b.getContentAsBytes(), charSet); } catch (IOException e) { throw new UnirestException(e); } diff --git a/src/test/java/unirest/ResponseUtilsTest.java b/src/test/java/unirest/ResponseUtilsTest.java index 07af4c009..53dc8a818 100644 --- a/src/test/java/unirest/ResponseUtilsTest.java +++ b/src/test/java/unirest/ResponseUtilsTest.java @@ -32,6 +32,8 @@ import unirest.ResponseUtils; import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class ResponseUtilsTest { @@ -40,7 +42,7 @@ public void getCharsetDefaults() { assertEquals("UTF-8", ResponseUtils.getCharSet(entity(null))); assertEquals("UTF-8", ResponseUtils.getCharSet(entity(""))); assertEquals("UTF-8", ResponseUtils.getCharSet(entity(" "))); - assertEquals("UTF-8", ResponseUtils.getCharSet(new BasicHttpEntity())); + assertEquals("UTF-8", ResponseUtils.getCharSet(mock(RawResponse.class))); assertEquals("UTF-8", ResponseUtils.getCharSet(entity("Content-Type: text/html;"))); assertEquals("UTF-8", ResponseUtils.getCharSet(entity("Content-Type: text/html; charset="))); } @@ -50,9 +52,9 @@ public void contentTypeWhenYouGotIt() { assertEquals("LATIN-1", ResponseUtils.getCharSet(entity("Content-Type: text/html; charset=latin-1"))); } - private HttpEntity entity(String charset) { - BasicHttpEntity e = new BasicHttpEntity(); - e.setContentType(charset); - return e; + private RawResponse entity(String charset) { + RawResponse r = mock(RawResponse.class); + when(r.getContentType()).thenReturn(charset); + return r; } } \ No newline at end of file From 6adfed4395e4bd1b4e5022f750c2a27526a6cf73 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 11 Dec 2018 08:45:39 -0600 Subject: [PATCH 0348/1769] add security enforcer --- pom.xml | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c27505201..21df43217 100644 --- a/pom.xml +++ b/pom.xml @@ -255,6 +255,49 @@ + + org.apache.maven.plugins + maven-enforcer-plugin + 1.4.1 + + + org.sonatype.ossindex.maven + ossindex-maven-enforcer-rules + 3.0.2 + + + + + vulnerability-checks + validate + + enforce + + + + + + + + + enforce-versions + + enforce + + + + + + [3.2,) + + + 1.8 + + + + + + @@ -309,7 +352,7 @@ com.google.guava guava - 24.0-jre + 27.0.1-jre test From cbcfa57f5b9060435cb5d27bcda3685f4492c27c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 11 Dec 2018 19:07:02 -0600 Subject: [PATCH 0349/1769] deprecate the binary methods because they are not suitable for streaming --- src/main/java/unirest/HttpRequest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index 49a9a0a66..3701ac8f8 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -221,20 +221,26 @@ public interface HttpRequest { /** * Executes the request and returns a copy of the original InputStream * @return a HttpResponse with a InputStream + * @Deprecated This method returns a copy of the original stream and is not suitable for streaming. Use asObject(Function<RawResponse, T> function) */ + @Deprecated HttpResponse asBinary(); /** * Executes the request asynchronously and returns a copy of the original InputStream * @return a CompletableFuture of a HttpResponse with a InputStream + * @Deprecated This method returns a copy of the original stream and is not suitable for streaming. Use asObjectAsync(Function<RawResponse, T> function) */ + @Deprecated CompletableFuture> asBinaryAsync(); /** * Executes the request asynchronously and returns a copy of the original InputStream which is passed to a callback * @param callback the callback * @return a CompletableFuture of a HttpResponse with a InputStream + * @Deprecated This method returns a copy of the original stream and is not suitable for streaming. Use asObjectAsync(Function<RawResponse, T> function) */ + @Deprecated CompletableFuture> asBinaryAsync(Callback callback); /** From 0c6d0af27971ec4ff83dcda424dbd8ee41b512bf Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 11 Dec 2018 19:19:39 -0600 Subject: [PATCH 0350/1769] deprecate the asBinary methods because they are not suitable for streaming --- src/main/java/unirest/HttpRequest.java | 6 +++--- src/main/java/unirest/HttpResponse.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index 3701ac8f8..1648768da 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -220,16 +220,16 @@ public interface HttpRequest { /** * Executes the request and returns a copy of the original InputStream + * @deprecated This method returns a copy of the original stream and is not suitable for streaming. Use asObject(Function<RawResponse, T> function) * @return a HttpResponse with a InputStream - * @Deprecated This method returns a copy of the original stream and is not suitable for streaming. Use asObject(Function<RawResponse, T> function) */ @Deprecated HttpResponse asBinary(); /** * Executes the request asynchronously and returns a copy of the original InputStream + * @deprecated This method returns a copy of the original stream and is not suitable for streaming. Use asObjectAsync(Function<RawResponse, T> function) * @return a CompletableFuture of a HttpResponse with a InputStream - * @Deprecated This method returns a copy of the original stream and is not suitable for streaming. Use asObjectAsync(Function<RawResponse, T> function) */ @Deprecated CompletableFuture> asBinaryAsync(); @@ -237,8 +237,8 @@ public interface HttpRequest { /** * Executes the request asynchronously and returns a copy of the original InputStream which is passed to a callback * @param callback the callback + * @deprecated This method returns a copy of the original stream and is not suitable for streaming. Use asObjectAsync(Function<RawResponse, T> function) * @return a CompletableFuture of a HttpResponse with a InputStream - * @Deprecated This method returns a copy of the original stream and is not suitable for streaming. Use asObjectAsync(Function<RawResponse, T> function) */ @Deprecated CompletableFuture> asBinaryAsync(Callback callback); diff --git a/src/main/java/unirest/HttpResponse.java b/src/main/java/unirest/HttpResponse.java index 81fe0f805..f59f7139b 100644 --- a/src/main/java/unirest/HttpResponse.java +++ b/src/main/java/unirest/HttpResponse.java @@ -74,7 +74,7 @@ public interface HttpResponse { /** * @param func a function to transform a body type to something else. * @param The return type of the function - * @return + * @return the return type */ V mapBody(Function func); From cdd651ca70f73137b70aeed3baf582a8b7ee1c87 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 11 Dec 2018 19:55:57 -0600 Subject: [PATCH 0351/1769] addresses #48 methods for streaming contents into a file --- src/main/java/unirest/BaseRequest.java | 6 ++++ src/main/java/unirest/FileResponse.java | 34 ++++++++++++++++++ src/main/java/unirest/HttpRequest.java | 8 +++++ src/main/java/unirest/HttpResponse.java | 1 + src/test/java/BehaviorTests/AsFileTests.java | 36 +++++++++++++++++++ .../java/unirest/JacksonObjectMapper.java | 9 +++++ 6 files changed, 94 insertions(+) create mode 100644 src/main/java/unirest/FileResponse.java create mode 100644 src/test/java/BehaviorTests/AsFileTests.java diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 15c60d801..2bfd69a8a 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -32,6 +32,7 @@ import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.concurrent.FutureCallback; +import java.io.File; import java.io.InputStream; import java.util.*; import java.util.concurrent.CompletableFuture; @@ -217,6 +218,11 @@ public void thenConsumeAsync(Consumer consumer) { requestAsync(getConsumer(consumer), new CompletableFuture<>()); } + @Override + public HttpResponse asFile(String path) { + return request(r -> new FileResponse(r, path)); + } + private Function> getConsumer(Consumer consumer) { return r -> { consumer.accept(r); diff --git a/src/main/java/unirest/FileResponse.java b/src/main/java/unirest/FileResponse.java new file mode 100644 index 000000000..3dd687d1e --- /dev/null +++ b/src/main/java/unirest/FileResponse.java @@ -0,0 +1,34 @@ +package unirest; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class FileResponse extends BaseResponse { + private File body; + + public FileResponse(RawResponse r, String path) { + super(r); + try { + Path target = Paths.get(path); + Files.copy(r.getContent(), target); + body = target.toFile(); + } catch (IOException e) { + throw new UnirestException(e); + } + } + + @Override + public InputStream getRawBody() { + return new ByteArrayInputStream(new byte[0]); + } + + @Override + public File getBody() { + return body; + } +} diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index 1648768da..8ef137d3c 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -26,6 +26,7 @@ package unirest; +import java.io.File; import java.io.InputStream; import java.util.Collection; import java.util.Map; @@ -226,6 +227,13 @@ public interface HttpRequest { @Deprecated HttpResponse asBinary(); + /** + * Executes the request and writes the contents into a file + * @param path The path to the file. + * @return a file containing the results + */ + HttpResponse asFile(String path); + /** * Executes the request asynchronously and returns a copy of the original InputStream * @deprecated This method returns a copy of the original stream and is not suitable for streaming. Use asObjectAsync(Function<RawResponse, T> function) diff --git a/src/main/java/unirest/HttpResponse.java b/src/main/java/unirest/HttpResponse.java index f59f7139b..17ef07d48 100644 --- a/src/main/java/unirest/HttpResponse.java +++ b/src/main/java/unirest/HttpResponse.java @@ -55,6 +55,7 @@ public interface HttpResponse { * This method is a lie. You never get the real raw response from it * you only get a copy, or worse, the body transformed BACK to a stream * If you want to use raw content use the new functional methods + * @deprecated this method is redundant and not the original stream. Use the functional asObject methods. * @return a copy of the input stream * */ @Deprecated diff --git a/src/test/java/BehaviorTests/AsFileTests.java b/src/test/java/BehaviorTests/AsFileTests.java new file mode 100644 index 000000000..148584051 --- /dev/null +++ b/src/test/java/BehaviorTests/AsFileTests.java @@ -0,0 +1,36 @@ +package BehaviorTests; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.Gson; +import org.junit.Test; +import unirest.JacksonObjectMapper; +import unirest.Unirest; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class AsFileTests extends BddTest { + + private Path test = Paths.get("results.json"); + private JacksonObjectMapper om = new JacksonObjectMapper(); + + @Override + public void tearDown() { + try { + Files.delete(test); + } catch (IOException e) { + + } + } + + @Test + public void canSaveContentsIntoFile() { + Unirest.get(MockServer.GET) + .asFile(test.toString()); + + om.readValue(test.toFile(), RequestCapture.class) + .assertStatus(200); + } +} diff --git a/src/test/java/unirest/JacksonObjectMapper.java b/src/test/java/unirest/JacksonObjectMapper.java index 8566c175e..1af6ae434 100644 --- a/src/test/java/unirest/JacksonObjectMapper.java +++ b/src/test/java/unirest/JacksonObjectMapper.java @@ -41,6 +41,7 @@ import org.json.JSONObject; import unirest.ObjectMapper; +import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -58,6 +59,14 @@ public JacksonObjectMapper(){ om.registerModule(simpleModule); } + public T readValue(File f, Class valueType){ + try { + return om.readValue(f, valueType); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + @Override public T readValue(String value, Class valueType) { try { From 840d0d6ac23d4775c04835b99317b75c70a091f0 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 12 Dec 2018 08:00:52 -0600 Subject: [PATCH 0352/1769] addresses issue #49 When encountering a parsing error with asObject or asJson capture the body in a UnirestParsingException --- CHANGELOG.md | 4 + src/main/java/unirest/BaseResponse.java | 8 +- src/main/java/unirest/FileResponse.java | 26 ++++++ src/main/java/unirest/HttpRequest.java | 1 + src/main/java/unirest/HttpResponse.java | 2 +- src/main/java/unirest/JsonNode.java | 80 +++++++++---------- src/main/java/unirest/JsonResponse.java | 2 +- src/main/java/unirest/ObjectResponse.java | 31 ++++--- src/main/java/unirest/Response.java | 4 +- .../java/unirest/UnirestParsingException.java | 40 ++++++++++ src/test/java/BehaviorTests/AsFileTests.java | 26 ++++++ src/test/java/BehaviorTests/AsJsonTest.java | 2 +- src/test/java/BehaviorTests/AsObjectTest.java | 10 ++- 13 files changed, 170 insertions(+), 66 deletions(-) create mode 100644 src/main/java/unirest/UnirestParsingException.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e21d6166..73b045f70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.1.02 +* When encountering a parsing error with asObject or asJson capture the body in a UnirestParsingException +* New BETA feature asFile method to stream the response into a file. + ## 3.1.01 * Detect if the async client has stopped for some reason and construct a new one. This one may be different from the one that was originally configured so we need to add a way to configure a supplier for clients rather than a direct client. diff --git a/src/main/java/unirest/BaseResponse.java b/src/main/java/unirest/BaseResponse.java index 06eee0c8a..afddaa8ca 100644 --- a/src/main/java/unirest/BaseResponse.java +++ b/src/main/java/unirest/BaseResponse.java @@ -35,7 +35,7 @@ abstract class BaseResponse implements HttpResponse { private final Headers headers; private final String statusText; private final int statusCode; - private Optional parsingerror = Optional.empty(); + private Optional parsingerror = Optional.empty(); protected BaseResponse(RawResponse response){ headers = response.getHeaders(); @@ -65,7 +65,7 @@ public Headers getHeaders() { public abstract T getBody(); @Override - public Optional getParsingError() { + public Optional getParsingError() { return parsingerror; } @@ -79,7 +79,7 @@ public V mapRawBody(Function func) { return func.apply(getRawBody()); } - protected void setParsingException(RuntimeException e) { - parsingerror = Optional.of(e); + protected void setParsingException(String originalBody, RuntimeException e) { + parsingerror = Optional.of(new UnirestParsingException(originalBody, e)); } } diff --git a/src/main/java/unirest/FileResponse.java b/src/main/java/unirest/FileResponse.java index 3dd687d1e..ee55377ae 100644 --- a/src/main/java/unirest/FileResponse.java +++ b/src/main/java/unirest/FileResponse.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package unirest; import java.io.ByteArrayInputStream; diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index 8ef137d3c..a5ef82a17 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -228,6 +228,7 @@ public interface HttpRequest { HttpResponse asBinary(); /** + * WARNING!!This is a beta feature and may change * Executes the request and writes the contents into a file * @param path The path to the file. * @return a file containing the results diff --git a/src/main/java/unirest/HttpResponse.java b/src/main/java/unirest/HttpResponse.java index 17ef07d48..4f33b1798 100644 --- a/src/main/java/unirest/HttpResponse.java +++ b/src/main/java/unirest/HttpResponse.java @@ -70,7 +70,7 @@ public interface HttpResponse { * If the transformation to the body failed by an exception it will be kept here * @return a possible RuntimeException. Checked exceptions are wrapped in a UnirestException */ - Optional getParsingError(); + Optional getParsingError(); /** * @param func a function to transform a body type to something else. diff --git a/src/main/java/unirest/JsonNode.java b/src/main/java/unirest/JsonNode.java index 1a2ea77cd..427d8cea1 100644 --- a/src/main/java/unirest/JsonNode.java +++ b/src/main/java/unirest/JsonNode.java @@ -32,52 +32,48 @@ public class JsonNode { - private JSONObject jsonObject; - private JSONArray jsonArray; + private JSONObject jsonObject; + private JSONArray jsonArray; - private boolean array; + private boolean array; - public JsonNode(String json) { - if (json == null || "".equals(json.trim())) { - jsonObject = new JSONObject(); - } else { - try { - jsonObject = new JSONObject(json); - } catch (JSONException e) { - // It may be an array - try { - jsonArray = new JSONArray(json); - array = true; - } catch (JSONException e1) { - throw new RuntimeException(e1); - } - } - } - } + public JsonNode(String json) { + if (json == null || "".equals(json.trim())) { + jsonObject = new JSONObject(); + } else { + try { + jsonObject = new JSONObject(json); + } catch (JSONException e) { + // It may be an array + jsonArray = new JSONArray(json); + array = true; + } + } + } - public JSONObject getObject() { - return this.jsonObject; - } + public JSONObject getObject() { + return this.jsonObject; + } - public JSONArray getArray() { - JSONArray result = this.jsonArray; - if (array == false) { - result = new JSONArray(); - result.put(jsonObject); - } - return result; - } + public JSONArray getArray() { + JSONArray result = this.jsonArray; + if (array == false) { + result = new JSONArray(); + result.put(jsonObject); + } + return result; + } - public boolean isArray() { - return this.array; - } + public boolean isArray() { + return this.array; + } - @Override - public String toString() { - if (isArray()) { - return jsonArray.toString(); - } else { - return jsonObject.toString(); - } - } + @Override + public String toString() { + if (isArray()) { + return jsonArray.toString(); + } else { + return jsonObject.toString(); + } + } } diff --git a/src/main/java/unirest/JsonResponse.java b/src/main/java/unirest/JsonResponse.java index 9684551d9..1ccdc3d2c 100644 --- a/src/main/java/unirest/JsonResponse.java +++ b/src/main/java/unirest/JsonResponse.java @@ -52,7 +52,7 @@ private JsonNode toJsonNode(String json) { try { return new JsonNode(json); } catch (RuntimeException e) { - super.setParsingException(e); + super.setParsingException(json, e); errorStream = new ByteArrayInputStream(json.getBytes()); return null; } diff --git a/src/main/java/unirest/ObjectResponse.java b/src/main/java/unirest/ObjectResponse.java index decf0c543..d6cca9bec 100644 --- a/src/main/java/unirest/ObjectResponse.java +++ b/src/main/java/unirest/ObjectResponse.java @@ -28,36 +28,43 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.util.Optional; import java.util.function.Function; import static unirest.Util.readString; class ObjectResponse extends BaseResponse { - private final T body; private final ObjectMapper om; ObjectResponse(ObjectMapper om, RawResponse response, Class to) { super(response); this.om = om; - this.body = getBody(response, e -> om.readValue(readString(e), to)); + this.body = readBody(response) + .map(s -> getBody(s, e -> om.readValue(e, to))) + .orElse(null); } ObjectResponse(ObjectMapper om, RawResponse response, GenericType to){ super(response); this.om = om; - this.body = getBody(response, e -> om.readValue(readString(e), to)); + this.body = readBody(response) + .map(s -> getBody(s, e -> om.readValue(e, to))) + .orElse(null); + } + + private Optional readBody(RawResponse response) { + if(!response.hasContent()){ + return Optional.empty(); + } + return Optional.of(readString(response)); } - private T getBody(RawResponse response, Function func){ - if(response.hasContent()) { - try { - return func.apply(response); - }catch (RuntimeException e){ - setParsingException(e); - return null; - } - } else { + private T getBody(String b, Function func){ + try { + return func.apply(b); + } catch (RuntimeException e) { + setParsingException(b, e); return null; } } diff --git a/src/main/java/unirest/Response.java b/src/main/java/unirest/Response.java index 291b86162..0e9e67044 100644 --- a/src/main/java/unirest/Response.java +++ b/src/main/java/unirest/Response.java @@ -34,7 +34,7 @@ class Response implements HttpResponse { - private Optional parsingError = Optional.empty(); + private Optional parsingError = Optional.empty(); private final Headers headers; private final String statusText; private final int statusCode; @@ -81,7 +81,7 @@ public T getBody() { } @Override - public Optional getParsingError() { + public Optional getParsingError() { return parsingError; } diff --git a/src/main/java/unirest/UnirestParsingException.java b/src/main/java/unirest/UnirestParsingException.java new file mode 100644 index 000000000..6721fc64e --- /dev/null +++ b/src/main/java/unirest/UnirestParsingException.java @@ -0,0 +1,40 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +public class UnirestParsingException extends UnirestException { + private final String originalBody; + + public UnirestParsingException(String originalBody, Exception e) { + super(e); + this.originalBody = originalBody; + } + + public String getOriginalBody() { + return originalBody; + } +} diff --git a/src/test/java/BehaviorTests/AsFileTests.java b/src/test/java/BehaviorTests/AsFileTests.java index 148584051..a14c246bd 100644 --- a/src/test/java/BehaviorTests/AsFileTests.java +++ b/src/test/java/BehaviorTests/AsFileTests.java @@ -1,3 +1,29 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/src/test/java/BehaviorTests/AsJsonTest.java b/src/test/java/BehaviorTests/AsJsonTest.java index 9f2ba0628..ffa4fcd06 100644 --- a/src/test/java/BehaviorTests/AsJsonTest.java +++ b/src/test/java/BehaviorTests/AsJsonTest.java @@ -85,7 +85,7 @@ public void failureToReturnValidJsonWillResultInAnEmptyNode() { assertEquals(400, response.getStatus()); assertNull(response.getBody()); - assertEquals("You did something bad", TestUtil.toString(response.getRawBody())); + assertEquals("You did something bad", response.getParsingError().get().getOriginalBody()); assertEquals("org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]", response.getParsingError().get().getMessage()); } diff --git a/src/test/java/BehaviorTests/AsObjectTest.java b/src/test/java/BehaviorTests/AsObjectTest.java index d7ae0f3ba..c2a5f2f81 100644 --- a/src/test/java/BehaviorTests/AsObjectTest.java +++ b/src/test/java/BehaviorTests/AsObjectTest.java @@ -97,8 +97,10 @@ public void ifTheObjectMapperFailsReturnEmptyAndAddToParsingError() { assertNull(request.getBody()); assertTrue(request.getParsingError().isPresent()); - assertEquals("com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'You': was expecting ('true', 'false' or 'null')\n" + + assertEquals("unirest.UnirestException: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'You': was expecting ('true', 'false' or 'null')\n" + " at [Source: (String)\"You did something bad\"; line: 1, column: 4]", request.getParsingError().get().getMessage()); + assertEquals("You did something bad", request.getParsingError().get().getOriginalBody()); + } @Test @@ -108,8 +110,9 @@ public void ifTheObjectMapperFailsReturnEmptyAndAddToParsingErrorObGenericTypes( assertNull(request.getBody()); assertTrue(request.getParsingError().isPresent()); - assertEquals("com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'You': was expecting ('true', 'false' or 'null')\n" + + assertEquals("unirest.UnirestException: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'You': was expecting ('true', 'false' or 'null')\n" + " at [Source: (String)\"You did something bad\"; line: 1, column: 4]", request.getParsingError().get().getMessage()); + assertEquals("You did something bad", request.getParsingError().get().getOriginalBody()); } @Test @@ -119,8 +122,9 @@ public void unirestExceptionsAreAlsoParseExceptions() { assertNull(request.getBody()); assertTrue(request.getParsingError().isPresent()); - assertEquals("com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'You': was expecting ('true', 'false' or 'null')\n" + + assertEquals("unirest.UnirestException: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'You': was expecting ('true', 'false' or 'null')\n" + " at [Source: (String)\"You did something bad\"; line: 1, column: 4]", request.getParsingError().get().getMessage()); + assertEquals("You did something bad", request.getParsingError().get().getOriginalBody()); } public static class TestingMapper implements ObjectMapper { From ff821f60e4363f8dc5c89d35cd8679606654c504 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 12 Dec 2018 08:02:18 -0600 Subject: [PATCH 0353/1769] [maven-release-plugin] prepare release v3.1.02 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 21df43217..33b57c86c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.1.02-SNAPSHOT + 3.1.02 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.1.02 From 552e5f041aa0f2bab6e50e1a7ab4ec53b78c878a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 12 Dec 2018 08:02:25 -0600 Subject: [PATCH 0354/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 33b57c86c..f58fd2725 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.1.02 + 3.1.03-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.1.02 + HEAD From e7e6c0f5b827737353c7dfae7a18752a377d3880 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 12 Dec 2018 12:01:54 -0600 Subject: [PATCH 0355/1769] add gzip string async request --- src/test/java/BehaviorTests/AsStringTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/BehaviorTests/AsStringTest.java b/src/test/java/BehaviorTests/AsStringTest.java index 86af7fc77..dc2dc4977 100644 --- a/src/test/java/BehaviorTests/AsStringTest.java +++ b/src/test/java/BehaviorTests/AsStringTest.java @@ -57,6 +57,17 @@ public void canParseGzippedStringResponse() { cap.assertParam("foo", "bar"); } + @Test + public void canParseGzippedResponseAsync() throws Exception { + HttpResponse i = Unirest.get(MockServer.GZIP) + .queryString("foo", "bar") + .asStringAsync().get(); + + RequestCapture cap = TestUtil.readValue(i.getBody(), RequestCapture.class); + assertEquals(200, i.getStatus()); + cap.assertParam("foo", "bar"); + } + @Test public void canGetBinaryResponse() { HttpResponse i = Unirest.get(MockServer.GET) From c3aa291ff2f42d2ace87894f46f96b53ac7108f1 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 12 Dec 2018 12:25:45 -0600 Subject: [PATCH 0356/1769] move the toString method into the raw reasponse --- src/main/java/unirest/ApacheResponse.java | 13 +++++++++++++ src/main/java/unirest/JsonResponse.java | 2 +- src/main/java/unirest/ObjectResponse.java | 3 +-- src/main/java/unirest/RawResponse.java | 1 + src/main/java/unirest/StringResponse.java | 6 +----- src/main/java/unirest/Util.java | 10 ---------- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/main/java/unirest/ApacheResponse.java b/src/main/java/unirest/ApacheResponse.java index 7753a813c..c3e4a9bb0 100644 --- a/src/main/java/unirest/ApacheResponse.java +++ b/src/main/java/unirest/ApacheResponse.java @@ -87,6 +87,19 @@ public byte[] getContentAsBytes() { } } + @Override + public String getContentAsString() { + if(!hasContent()){ + return ""; + } + try { + String charSet = ResponseUtils.getCharSet(this); + return new String(getContentAsBytes(), charSet); + } catch (IOException e) { + throw new UnirestException(e); + } + } + @Override public InputStreamReader getContentReader(){ return new InputStreamReader(getContent()); diff --git a/src/main/java/unirest/JsonResponse.java b/src/main/java/unirest/JsonResponse.java index 1ccdc3d2c..2ca59ec2d 100644 --- a/src/main/java/unirest/JsonResponse.java +++ b/src/main/java/unirest/JsonResponse.java @@ -43,7 +43,7 @@ private JsonNode getNode(RawResponse response) { if (Objects.isNull(response) || !response.hasContent()) { return new JsonNode(null); } else { - String json = Util.readString(response); + String json = response.getContentAsString(); return toJsonNode(json); } } diff --git a/src/main/java/unirest/ObjectResponse.java b/src/main/java/unirest/ObjectResponse.java index d6cca9bec..4083325bb 100644 --- a/src/main/java/unirest/ObjectResponse.java +++ b/src/main/java/unirest/ObjectResponse.java @@ -31,7 +31,6 @@ import java.util.Optional; import java.util.function.Function; -import static unirest.Util.readString; class ObjectResponse extends BaseResponse { private final T body; @@ -57,7 +56,7 @@ private Optional readBody(RawResponse response) { if(!response.hasContent()){ return Optional.empty(); } - return Optional.of(readString(response)); + return Optional.of(response.getContentAsString()); } private T getBody(String b, Function func){ diff --git a/src/main/java/unirest/RawResponse.java b/src/main/java/unirest/RawResponse.java index 18dc89d89..b0d9cebe8 100644 --- a/src/main/java/unirest/RawResponse.java +++ b/src/main/java/unirest/RawResponse.java @@ -35,6 +35,7 @@ public interface RawResponse { Headers getHeaders(); InputStream getContent(); byte[] getContentAsBytes(); + String getContentAsString(); InputStreamReader getContentReader(); boolean hasContent(); String getContentType(); diff --git a/src/main/java/unirest/StringResponse.java b/src/main/java/unirest/StringResponse.java index 59e491fd2..b6205ee23 100644 --- a/src/main/java/unirest/StringResponse.java +++ b/src/main/java/unirest/StringResponse.java @@ -35,11 +35,7 @@ public class StringResponse extends BaseResponse { public StringResponse(RawResponse response) { super(response); - if(response.hasContent()){ - body = Util.readString(response); - } else { - body = ""; - } + body = response.getContentAsString(); } @Override diff --git a/src/main/java/unirest/Util.java b/src/main/java/unirest/Util.java index c33247f9d..977063c13 100644 --- a/src/main/java/unirest/Util.java +++ b/src/main/java/unirest/Util.java @@ -30,7 +30,6 @@ import org.apache.http.message.BasicNameValuePair; import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -89,15 +88,6 @@ static Stream collectExceptions(Optional... ex) { return Stream.of(ex).flatMap(Util::stream); } - public static String readString(RawResponse b) { - try { - String charSet = ResponseUtils.getCharSet(b); - return new String(b.getContentAsBytes(), charSet); - } catch (IOException e) { - throw new UnirestException(e); - } - } - public static InputStream emptyStream() { return new ByteArrayInputStream(new byte[0]); } From fbb81eabdc15b31ab1d62830911ef2870e41e84c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 12 Dec 2018 12:27:01 -0600 Subject: [PATCH 0357/1769] inline method --- src/main/java/unirest/BinaryResponse.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/unirest/BinaryResponse.java b/src/main/java/unirest/BinaryResponse.java index ec721fba3..f2a80eead 100644 --- a/src/main/java/unirest/BinaryResponse.java +++ b/src/main/java/unirest/BinaryResponse.java @@ -35,11 +35,7 @@ public class BinaryResponse extends BaseResponse { protected BinaryResponse(RawResponse response) { super(response); - body = new ByteArrayInputStream(getBody(response)); - } - - private byte[] getBody(RawResponse response) { - return response.getContentAsBytes(); + body = new ByteArrayInputStream(response.getContentAsBytes()); } @Override From 2871307e661c3ee158824cd9aaba2fde0ffd14fb Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 12 Dec 2018 13:09:35 -0600 Subject: [PATCH 0358/1769] add test for gzipping --- src/test/java/BehaviorTests/DefectTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/BehaviorTests/DefectTest.java b/src/test/java/BehaviorTests/DefectTest.java index b0365eeb7..133a3046b 100644 --- a/src/test/java/BehaviorTests/DefectTest.java +++ b/src/test/java/BehaviorTests/DefectTest.java @@ -28,6 +28,8 @@ import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.apache.http.nio.client.HttpAsyncClient; +import org.json.JSONObject; +import org.junit.Ignore; import unirest.Unirest; import org.junit.Test; @@ -38,6 +40,7 @@ import static junit.framework.TestCase.assertNotSame; import static junit.framework.TestCase.assertSame; +import static org.junit.Assert.assertEquals; public class DefectTest extends BddTest { @@ -85,4 +88,13 @@ public void issue_41_IllegalThreadStateExceptionUnderHighLoad() throws IOExcepti assertSame(second, Unirest.config().getAsyncHttpClient()); }); } + + @Test @Ignore + public void trySomeoneElsesGZip() throws Exception { + JSONObject body = Unirest.get("http://httpbin.org/gzip") + .asJsonAsync().get().getBody().getObject(); + + assertEquals(true, body.getBoolean("gzipped")); + assertEquals("gzip", body.getJSONObject("headers").getString("Accept-Encoding")); + } } From 76fe400b42fcc67a8dc092dfeea0d75fca74560b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 12 Dec 2018 16:48:34 -0600 Subject: [PATCH 0359/1769] test if binary files can be downloaded --- src/test/java/BehaviorTests/AsFileTests.java | 20 ++++++++++++---- src/test/java/BehaviorTests/MockServer.java | 24 ++++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/test/java/BehaviorTests/AsFileTests.java b/src/test/java/BehaviorTests/AsFileTests.java index a14c246bd..005010b97 100644 --- a/src/test/java/BehaviorTests/AsFileTests.java +++ b/src/test/java/BehaviorTests/AsFileTests.java @@ -26,17 +26,18 @@ package BehaviorTests; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.gson.Gson; import org.junit.Test; import unirest.JacksonObjectMapper; import unirest.Unirest; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import static org.junit.Assert.assertTrue; + public class AsFileTests extends BddTest { private Path test = Paths.get("results.json"); @@ -46,9 +47,7 @@ public class AsFileTests extends BddTest { public void tearDown() { try { Files.delete(test); - } catch (IOException e) { - - } + } catch (Exception e) { } } @Test @@ -59,4 +58,15 @@ public void canSaveContentsIntoFile() { om.readValue(test.toFile(), RequestCapture.class) .assertStatus(200); } + + @Test + public void canDownloadABinaryFile() throws Exception { + File f1 = new File(MockServer.class.getResource("/image.jpg").toURI()); + + File f2 = Unirest.get(MockServer.BINARYFILE) + .asFile(test.toString()) + .getBody(); + + assertTrue(com.google.common.io.Files.equal(f1, f2)); + } } diff --git a/src/test/java/BehaviorTests/MockServer.java b/src/test/java/BehaviorTests/MockServer.java index 8cac453d6..9e9ebc671 100644 --- a/src/test/java/BehaviorTests/MockServer.java +++ b/src/test/java/BehaviorTests/MockServer.java @@ -52,13 +52,22 @@ a copy of this software and associated documentation files (the package BehaviorTests; +import spark.utils.IOUtils; import unirest.JacksonObjectMapper; import spark.Request; import spark.Response; import spark.Spark; +import javax.servlet.ServletOutputStream; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.net.URISyntaxException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; import static spark.Spark.*; @@ -69,6 +78,7 @@ public class MockServer { public static final int PORT = 4567; public static final String HOST = "http://localhost:" + PORT; public static final String REDIRECT = HOST + "/redirect"; + public static final String BINARYFILE = HOST + "/binary"; public static final String NOBODY = HOST + "/nobody"; public static final String PROXY = "localhost:4567"; public static final String POST = HOST + "/post"; @@ -104,6 +114,7 @@ public static void reset(){ put("/post", MockServer::jsonResponse); get("/get/:p/passed", MockServer::jsonResponse); get("/proxy", MockServer::proxiedResponse); + get("/binary", MockServer::file); Runtime.getRuntime().addShutdownHook(new Thread(Spark::stop)); try { new CountDownLatch(1).await(2, TimeUnit.SECONDS); @@ -112,6 +123,19 @@ public static void reset(){ } } + private static Object file(Request request, Response response) throws Exception { + File f = new File(MockServer.class.getResource("/image.jpg").toURI()); + response.raw().setContentType("application/octet-stream"); + response.raw().setHeader("Content-Disposition", "attachment;filename=image.jpg"); + response.status(200); + final ServletOutputStream out = response.raw().getOutputStream(); + final FileInputStream in = new FileInputStream(f); + IOUtils.copy(in, out); + out.close(); + in.close(); + return null; + } + private static Object nobody(Request request, Response response) { Spark.halt(200); return null; From 1428f2247eae19931f76f0e317b955fa9345aed0 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 12 Dec 2018 16:57:45 -0600 Subject: [PATCH 0360/1769] light test refactoring --- src/test/java/BehaviorTests/AsFileTests.java | 19 +++++++++++---- .../java/BehaviorTests/FormPostingTest.java | 23 ++++++++++--------- src/test/java/BehaviorTests/MockServer.java | 3 ++- src/test/java/unirest/TestUtil.java | 10 ++++++++ 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/test/java/BehaviorTests/AsFileTests.java b/src/test/java/BehaviorTests/AsFileTests.java index 005010b97..57804b2c7 100644 --- a/src/test/java/BehaviorTests/AsFileTests.java +++ b/src/test/java/BehaviorTests/AsFileTests.java @@ -28,14 +28,15 @@ import org.junit.Test; import unirest.JacksonObjectMapper; +import unirest.TestUtil; import unirest.Unirest; import java.io.File; -import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class AsFileTests extends BddTest { @@ -52,16 +53,23 @@ public void tearDown() { @Test public void canSaveContentsIntoFile() { - Unirest.get(MockServer.GET) - .asFile(test.toString()); + File result = Unirest.get(MockServer.GET) + .queryString("talking","heads") + .queryString("param3", "こんにちは") + .asFile(test.toString()) + .getBody(); - om.readValue(test.toFile(), RequestCapture.class) + om.readValue(result, RequestCapture.class) + .assertParam("talking", "heads") + .assertParam("param3", "こんにちは") .assertStatus(200); + + assertEquals(test.toFile().getPath(), result.getPath()); } @Test public void canDownloadABinaryFile() throws Exception { - File f1 = new File(MockServer.class.getResource("/image.jpg").toURI()); + File f1 = TestUtil.rezFile("/image.jpg"); File f2 = Unirest.get(MockServer.BINARYFILE) .asFile(test.toString()) @@ -69,4 +77,5 @@ public void canDownloadABinaryFile() throws Exception { assertTrue(com.google.common.io.Files.equal(f1, f2)); } + } diff --git a/src/test/java/BehaviorTests/FormPostingTest.java b/src/test/java/BehaviorTests/FormPostingTest.java index ca0edf659..2639d40e5 100644 --- a/src/test/java/BehaviorTests/FormPostingTest.java +++ b/src/test/java/BehaviorTests/FormPostingTest.java @@ -41,6 +41,7 @@ import java.util.Arrays; import static org.junit.Assert.assertEquals; +import static unirest.TestUtil.rezFile; public class FormPostingTest extends BddTest { @Test @@ -74,7 +75,7 @@ public void formPostAsync() { public void testMultipart() throws Exception { Unirest.post(MockServer.POST) .field("name", "Mark") - .field("file", new File(getClass().getResource("/test").toURI())) + .field("file", rezFile("/test")) .asObject(RequestCapture.class) .getBody() .assertParam("name", "Mark") @@ -87,7 +88,7 @@ public void testMultipart() throws Exception { public void testMultipartContentType() throws Exception { Unirest.post(MockServer.POST) .field("name", "Mark") - .field("file", new File(getClass().getResource("/image.jpg").toURI()), "image/jpeg") + .field("file", rezFile("/image.jpg"), "image/jpeg") .asObject(RequestCapture.class) .getBody() .assertParam("name", "Mark") @@ -97,7 +98,7 @@ public void testMultipartContentType() throws Exception { @Test public void testMultipartInputStreamContentType() throws Exception { - FileInputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())); + FileInputStream stream = new FileInputStream(rezFile("/image.jpg")); Unirest.post(MockServer.POST) .header("accept", ContentType.MULTIPART_FORM_DATA.toString()) @@ -115,7 +116,7 @@ public void testMultipartInputStreamContentType() throws Exception { public void testMultipartInputStreamContentTypeAsync() throws Exception { Unirest.post(MockServer.POST) .field("name", "Mark") - .field("file", new FileInputStream(new File(getClass().getResource("/test").toURI())), ContentType.APPLICATION_OCTET_STREAM, "test") + .field("file", new FileInputStream(rezFile("/test")), ContentType.APPLICATION_OCTET_STREAM, "test") .asJsonAsync(new MockCallback<>(this, r -> parse(r) .assertParam("name", "Mark") .getFile("test") @@ -127,7 +128,7 @@ public void testMultipartInputStreamContentTypeAsync() throws Exception { @Test public void testMultipartByteContentType() throws Exception { - final InputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())); + final InputStream stream = new FileInputStream(rezFile("/image.jpg")); final byte[] bytes = new byte[stream.available()]; stream.read(bytes); stream.close(); @@ -144,7 +145,7 @@ public void testMultipartByteContentType() throws Exception { @Test public void testMultipartByteContentTypeAsync() throws Exception { - final InputStream stream = new FileInputStream(new File(getClass().getResource("/test").toURI())); + final InputStream stream = new FileInputStream(rezFile("/test")); final byte[] bytes = new byte[stream.available()]; stream.read(bytes); stream.close(); @@ -166,7 +167,7 @@ public void testMultipartByteContentTypeAsync() throws Exception { public void testMultipartAsync() throws Exception { Unirest.post(MockServer.POST) .field("name", "Mark") - .field("file", new File(getClass().getResource("/test").toURI())) + .field("file", rezFile("/test")) .asJsonAsync(new MockCallback<>(this, r -> parse(r) .assertParam("name", "Mark") @@ -198,8 +199,8 @@ public void testAsyncCustomContentTypeAndFormParams() { public void testPostMultipleFiles()throws Exception { Unirest.post(MockServer.POST) .field("param3", "wot") - .field("file1", new File(getClass().getResource("/test").toURI())) - .field("file2", new File(getClass().getResource("/test").toURI())) + .field("file1", rezFile("/test")) + .field("file2", rezFile("/test")) .asObject(RequestCapture.class) .getBody() .assertParam("param3", "wot") @@ -233,7 +234,7 @@ public void testPostBinaryUTF8() throws Exception { Unirest.post(MockServer.POST) .header("Accept", ContentType.MULTIPART_FORM_DATA.getMimeType()) .field("param3", "こんにちは") - .field("file", new File(getClass().getResource("/test").toURI())) + .field("file", rezFile("/test")) .asObject(RequestCapture.class) .getBody() .assertParam("param3", "こんにちは") @@ -427,6 +428,6 @@ public void canSetModeToStrictForLegacySupport() { private File getImageFile() throws URISyntaxException { - return new File(getClass().getResource("/image.jpg").toURI()); + return rezFile("/image.jpg"); } } diff --git a/src/test/java/BehaviorTests/MockServer.java b/src/test/java/BehaviorTests/MockServer.java index 9e9ebc671..a9888a92f 100644 --- a/src/test/java/BehaviorTests/MockServer.java +++ b/src/test/java/BehaviorTests/MockServer.java @@ -57,6 +57,7 @@ a copy of this software and associated documentation files (the import spark.Request; import spark.Response; import spark.Spark; +import unirest.TestUtil; import javax.servlet.ServletOutputStream; import java.io.BufferedInputStream; @@ -124,7 +125,7 @@ public static void reset(){ } private static Object file(Request request, Response response) throws Exception { - File f = new File(MockServer.class.getResource("/image.jpg").toURI()); + File f = TestUtil.rezFile("/image.jpg"); response.raw().setContentType("application/octet-stream"); response.raw().setHeader("Content-Disposition", "attachment;filename=image.jpg"); response.status(200); diff --git a/src/test/java/unirest/TestUtil.java b/src/test/java/unirest/TestUtil.java index fb4adaf2f..fd052474c 100644 --- a/src/test/java/unirest/TestUtil.java +++ b/src/test/java/unirest/TestUtil.java @@ -26,6 +26,7 @@ package unirest; +import BehaviorTests.MockServer; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.guava.GuavaModule; @@ -34,6 +35,7 @@ import unirest.HttpResponse; import java.io.*; +import java.net.URISyntaxException; import java.util.Base64; import java.util.HashMap; import java.util.Map; @@ -147,4 +149,12 @@ public static void assertBasicAuth(String raw, String username, String password) public static String getResource(String resourceName) throws IOException { return Resources.toString(Resources.getResource(resourceName), Charsets.UTF_8); } + + public static File rezFile(String name) { + try { + return new File(MockServer.class.getResource(name).toURI()); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + } } From c0ba41164f96a8cd03efd40488f1443078c324ed Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 12 Dec 2018 17:17:44 -0600 Subject: [PATCH 0361/1769] add asFileAsync method --- src/main/java/unirest/BaseRequest.java | 5 +++++ src/main/java/unirest/HttpRequest.java | 8 ++++++++ src/test/java/BehaviorTests/AsFileTests.java | 17 +++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 2bfd69a8a..c2010ba8c 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -223,6 +223,11 @@ public HttpResponse asFile(String path) { return request(r -> new FileResponse(r, path)); } + @Override + public CompletableFuture> asFileAsync(String path) { + return requestAsync(r -> new FileResponse(r, path), new CompletableFuture<>()); + } + private Function> getConsumer(Consumer consumer) { return r -> { consumer.accept(r); diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index a5ef82a17..c12acce3e 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -235,6 +235,14 @@ public interface HttpRequest { */ HttpResponse asFile(String path); + /** + * WARNING!!This is a beta feature and may change + * asynchronously executes the request and writes the contents into a file + * @param path The path to the file. + * @return a file containing the results + */ + CompletableFuture> asFileAsync(String path); + /** * Executes the request asynchronously and returns a copy of the original InputStream * @deprecated This method returns a copy of the original stream and is not suitable for streaming. Use asObjectAsync(Function<RawResponse, T> function) diff --git a/src/test/java/BehaviorTests/AsFileTests.java b/src/test/java/BehaviorTests/AsFileTests.java index 57804b2c7..a437ab082 100644 --- a/src/test/java/BehaviorTests/AsFileTests.java +++ b/src/test/java/BehaviorTests/AsFileTests.java @@ -67,6 +67,23 @@ public void canSaveContentsIntoFile() { assertEquals(test.toFile().getPath(), result.getPath()); } + @Test + public void canSaveContentsIntoFileAsync() throws Exception { + File result = Unirest.get(MockServer.GET) + .queryString("talking","heads") + .queryString("param3", "こんにちは") + .asFileAsync(test.toString()) + .get() + .getBody(); + + om.readValue(result, RequestCapture.class) + .assertParam("talking", "heads") + .assertParam("param3", "こんにちは") + .assertStatus(200); + + assertEquals(test.toFile().getPath(), result.getPath()); + } + @Test public void canDownloadABinaryFile() throws Exception { File f1 = TestUtil.rezFile("/image.jpg"); From 4717e0a7426b8f7329e3c11071b8611ca1fea6ef Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 12 Dec 2018 17:30:54 -0600 Subject: [PATCH 0362/1769] add async with callback for files --- src/main/java/unirest/BaseRequest.java | 5 +++++ src/main/java/unirest/HttpRequest.java | 10 ++++++++-- src/test/java/BehaviorTests/AsFileTests.java | 18 +++++++++++++++++- src/test/java/unirest/TestUtil.java | 8 -------- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index c2010ba8c..739b926f5 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -228,6 +228,11 @@ public CompletableFuture> asFileAsync(String path) { return requestAsync(r -> new FileResponse(r, path), new CompletableFuture<>()); } + @Override + public CompletableFuture> asFileAsync(String path, Callback callback) { + return requestAsync(r -> new FileResponse(r, path), CallbackFuture.wrap(callback)); + } + private Function> getConsumer(Consumer consumer) { return r -> { consumer.accept(r); diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index c12acce3e..1f906333e 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -228,7 +228,6 @@ public interface HttpRequest { HttpResponse asBinary(); /** - * WARNING!!This is a beta feature and may change * Executes the request and writes the contents into a file * @param path The path to the file. * @return a file containing the results @@ -236,13 +235,20 @@ public interface HttpRequest { HttpResponse asFile(String path); /** - * WARNING!!This is a beta feature and may change * asynchronously executes the request and writes the contents into a file * @param path The path to the file. * @return a file containing the results */ CompletableFuture> asFileAsync(String path); + /** + * asynchronously executes the request and writes the contents into a file + * @param path The path to the file. + * @param callback a callback for handling the body post mapping + * @return a file containing the results + */ + CompletableFuture> asFileAsync(String path, Callback callback); + /** * Executes the request asynchronously and returns a copy of the original InputStream * @deprecated This method returns a copy of the original stream and is not suitable for streaming. Use asObjectAsync(Function<RawResponse, T> function) diff --git a/src/test/java/BehaviorTests/AsFileTests.java b/src/test/java/BehaviorTests/AsFileTests.java index a437ab082..db2a66e24 100644 --- a/src/test/java/BehaviorTests/AsFileTests.java +++ b/src/test/java/BehaviorTests/AsFileTests.java @@ -84,6 +84,23 @@ public void canSaveContentsIntoFileAsync() throws Exception { assertEquals(test.toFile().getPath(), result.getPath()); } + @Test + public void canSaveContentsIntoFileAsyncWithCallback() throws Exception { + Unirest.get(MockServer.GET) + .queryString("talking","heads") + .queryString("param3", "こんにちは") + .asFileAsync(test.toString(), r -> { + om.readValue(r.getBody(), RequestCapture.class) + .assertParam("talking", "heads") + .assertParam("param3", "こんにちは") + .assertStatus(200); + assertEquals(test.toFile().getPath(), r.getBody().getPath()); + asyncSuccess(); + }); + + assertAsync(); + } + @Test public void canDownloadABinaryFile() throws Exception { File f1 = TestUtil.rezFile("/image.jpg"); @@ -94,5 +111,4 @@ public void canDownloadABinaryFile() throws Exception { assertTrue(com.google.common.io.Files.equal(f1, f2)); } - } diff --git a/src/test/java/unirest/TestUtil.java b/src/test/java/unirest/TestUtil.java index fd052474c..7db3ef2e7 100644 --- a/src/test/java/unirest/TestUtil.java +++ b/src/test/java/unirest/TestUtil.java @@ -65,14 +65,6 @@ public static T readValue(InputStream i, Class clss) { } } - public static String toJson(Object o) { - try { - return om.writeValueAsString(o); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - } - public static void assertException(Runnable runnable, Class exClass, String message) { try{ runnable.run(); From f8c887083bc8a396332992362a9601b233c7ae04 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 12 Dec 2018 19:45:07 -0600 Subject: [PATCH 0363/1769] bump minor for new feature --- CHANGELOG.md | 9 +++++++++ pom.xml | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73b045f70..580a8ac7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# 3.2.00 +* Now you can stream the results into a file! + * It doesn't need to be a file either. It could be any result. Unirest will shove it in a file. +``` +File file = Unirest.get("https://someplace/file.tar.gz") + .asFile("/local/storage/file.tar.gz") + .getBody(); +``` + ## 3.1.02 * When encountering a parsing error with asObject or asJson capture the body in a UnirestParsingException * New BETA feature asFile method to stream the response into a file. diff --git a/pom.xml b/pom.xml index f58fd2725..932dc6324 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.1.03-SNAPSHOT + 3.2.00-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ From efedfbd4839700b89ed801f76e4d5cc643924f56 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 12 Dec 2018 19:47:48 -0600 Subject: [PATCH 0364/1769] [maven-release-plugin] prepare release v3.2.00 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 932dc6324..9db75bce5 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.2.00-SNAPSHOT + 3.2.00 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.2.00 From 3ebdbce596a8b84855bcf6e73d0bb557385239f8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 12 Dec 2018 19:48:30 -0600 Subject: [PATCH 0365/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 9db75bce5..3352ccaef 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.2.00 + 3.2.01-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.2.00 + HEAD From 353c0a46cf1a6e268a31726dbf937abb78c63126 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 17 Dec 2018 08:29:24 -0600 Subject: [PATCH 0366/1769] show test of multiple of the same header --- src/test/java/BehaviorTests/HeaderTest.java | 13 +++++++++++++ src/test/java/BehaviorTests/RequestCapture.java | 17 ++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/test/java/BehaviorTests/HeaderTest.java b/src/test/java/BehaviorTests/HeaderTest.java index 73fe74784..252875e75 100644 --- a/src/test/java/BehaviorTests/HeaderTest.java +++ b/src/test/java/BehaviorTests/HeaderTest.java @@ -221,4 +221,17 @@ public void doesNotCacheAuthAcrossDomains(){ String header = bin.getObject().getJSONObject("headers").getString("Authorization"); assertBasicAuth(header, "user2", "pass2"); } + + @Test + public void interactionsBetweenGlobalAndLocalHeaders() { + Unirest.config().setDefaultHeader("foo", "bar"); + + Unirest.get(MockServer.GET) + .header("foo", "qux") + .asObject(RequestCapture.class) + .getBody() + .assertHeaderSize("foo", 2) + .assertHeader("foo", "bar") + .assertHeader("foo", "qux"); + } } diff --git a/src/test/java/BehaviorTests/RequestCapture.java b/src/test/java/BehaviorTests/RequestCapture.java index 39a5de6da..d8883cc22 100644 --- a/src/test/java/BehaviorTests/RequestCapture.java +++ b/src/test/java/BehaviorTests/RequestCapture.java @@ -27,9 +27,7 @@ package BehaviorTests; import com.google.common.base.Strings; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; +import com.google.common.collect.*; import unirest.JsonPatch; import unirest.JsonPatchItem; import unirest.JsonPatchOperation; @@ -54,7 +52,7 @@ import static org.junit.Assert.*; public class RequestCapture { - public Map headers = new LinkedHashMap<>(); + public ListMultimap headers = LinkedListMultimap.create(); public List files = new ArrayList<>(); public Multimap params = HashMultimap.create(); public String body; @@ -152,12 +150,12 @@ public RequestCapture assertNoHeader(String s) { } private RequestCapture writeHeaders(Request req) { - req.headers().forEach(h -> headers.put(h, req.headers(h))); + req.headers().forEach(h -> headers.putAll(h, Collections.list(req.raw().getHeaders(h)))); return this; } public RequestCapture assertHeader(String key, String value) { - assertEquals("Expected Header Failed", value, headers.get(key)); + assertThat("Expected Header Failed", headers.get(key), hasItem(value)); return this; } @@ -187,7 +185,7 @@ public RequestCapture assertFileContent(String input, String content) { } public RequestCapture assertBasicAuth(String username, String password) { - String raw = headers.get("Authorization"); + String raw = headers.get("Authorization").get(0); TestUtil.assertBasicAuth(raw, username, password); return this; } @@ -240,6 +238,11 @@ public RequestCapture assertIsProxied(boolean b) { return this; } + public RequestCapture assertHeaderSize(String foo, int size) { + assertEquals(size, headers.get(foo).size()); + return this; + } + public static class File { public String fileName; public String type; From ab372dbc9a3bfa6603d8ced8a403a9508e20513c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 17 Dec 2018 09:30:04 -0600 Subject: [PATCH 0367/1769] closes #51 method to replace header --- src/main/java/unirest/BaseRequest.java | 12 ++++++++++++ src/main/java/unirest/HttpRequest.java | 10 +++++++++- src/test/java/BehaviorTests/HeaderTest.java | 19 +++++++++++++++++-- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 739b926f5..c84547445 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -84,6 +84,18 @@ public R header(String name, String value) { return (R)this; } + @Override + public R headerReplace(String name, String value) { + if(this.headers.containsKey(name)) { + List repl = new ArrayList<>(); + repl.add(value); + this.headers.replace(name.trim(), repl); + } else { + header(name, value); + } + return (R)this; + } + @Override public R headers(Map headerMap) { if (headers != null) { diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index 1f906333e..e92a72cf7 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -64,13 +64,21 @@ public interface HttpRequest { R accept(String value); /** - * Add a http header + * Add a http header, HTTP supports multiple of the same header. This will continue to append new values * @param name name of the header * @param value value for the header * @return this request builder */ R header(String name, String value); + /** + * Replace a header value or add it if it doesn't exist + * @param name name of the header + * @param value value for the header + * @return this request builder + */ + R headerReplace(String name, String value); + /** * Add headers as a map * @param headerMap a map of headers diff --git a/src/test/java/BehaviorTests/HeaderTest.java b/src/test/java/BehaviorTests/HeaderTest.java index 252875e75..484a81913 100644 --- a/src/test/java/BehaviorTests/HeaderTest.java +++ b/src/test/java/BehaviorTests/HeaderTest.java @@ -222,8 +222,8 @@ public void doesNotCacheAuthAcrossDomains(){ assertBasicAuth(header, "user2", "pass2"); } - @Test - public void interactionsBetweenGlobalAndLocalHeaders() { + @Test //https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2 + public void canHaveTheSameHeaderAddedTwice() { Unirest.config().setDefaultHeader("foo", "bar"); Unirest.get(MockServer.GET) @@ -234,4 +234,19 @@ public void interactionsBetweenGlobalAndLocalHeaders() { .assertHeader("foo", "bar") .assertHeader("foo", "qux"); } + + @Test + public void canReplaceAHeader() { + Unirest.config().setDefaultHeader("foo", "bar"); + + Unirest.get(MockServer.GET) + .headerReplace("foo", "qux") + .headerReplace("fruit", "mango") + .asObject(RequestCapture.class) + .getBody() + .assertHeaderSize("foo", 1) + .assertHeaderSize("fruit", 1) + .assertHeader("foo", "qux") + .assertHeader("fruit", "mango"); + } } From 06c27ceb64b647a3d2592c482580a0a3aa1735d1 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 17 Dec 2018 09:34:47 -0600 Subject: [PATCH 0368/1769] update docs --- CHANGELOG.md | 3 +++ README.md | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 580a8ac7c..8e1052538 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 3.2.01 +* add method to replace a header rather than append to it. + # 3.2.00 * Now you can stream the results into a file! * It doesn't need to be a file either. It could be any result. Unirest will shove it in a file. diff --git a/README.md b/README.md index 6586c1dc9..9c4502062 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This repo is an updated, maintained, and independent fork of the original Mashap io.github.openunirest open-unirest-java - 3.1.01 + 3.2.01 ``` From 68377b9ee923231b21ea986784e945885540c19b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 17 Dec 2018 09:37:04 -0600 Subject: [PATCH 0369/1769] [maven-release-plugin] prepare release v3.2.01 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3352ccaef..c47ccacc9 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.2.01-SNAPSHOT + 3.2.01 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.2.01 From fba61e33e9661788db434e9f3aa06bdf2a8fd2e8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 17 Dec 2018 09:37:16 -0600 Subject: [PATCH 0370/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c47ccacc9..4055815f6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.2.01 + 3.2.02-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.2.01 + HEAD From 02f75d9f595b46004d56db970faede1216d8d8c8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 17 Dec 2018 10:31:44 -0600 Subject: [PATCH 0371/1769] distinguish between adding and replacing the header. part of #51 --- src/main/java/unirest/BaseRequest.java | 8 +------ src/main/java/unirest/Config.java | 12 +++++++++++ src/main/java/unirest/Headers.java | 10 +++++++++ src/test/java/BehaviorTests/HeaderTest.java | 24 ++++++++++++++++++++- 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index c84547445..e258f4850 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -86,13 +86,7 @@ public R header(String name, String value) { @Override public R headerReplace(String name, String value) { - if(this.headers.containsKey(name)) { - List repl = new ArrayList<>(); - repl.add(value); - this.headers.replace(name.trim(), repl); - } else { - header(name, value); - } + this.headers.replace(name, value); return (R)this; } diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java index 8f563b540..8e8e279f8 100644 --- a/src/main/java/unirest/Config.java +++ b/src/main/java/unirest/Config.java @@ -254,6 +254,18 @@ public Config clearDefaultHeaders() { * @return this config object */ public Config setDefaultHeader(String name, String value) { + defaultHeaders.replace(name, value); + return this; + } + + /** + * Add default header to appear on all requests + * + * @param name The name of the header. + * @param value The value of the header. + * @return this config object + */ + public Config addDefaultHeader(String name, String value) { defaultHeaders.add(name, value); return this; } diff --git a/src/main/java/unirest/Headers.java b/src/main/java/unirest/Headers.java index 51a03c4a1..a54590b6c 100644 --- a/src/main/java/unirest/Headers.java +++ b/src/main/java/unirest/Headers.java @@ -62,6 +62,16 @@ public void add(String name, String value) { } } + public void replace(String name, String value){ + if(this.containsKey(name)) { + List repl = new ArrayList<>(); + repl.add(value); + this.replace(name.trim(), repl); + } else { + add(name, value); + } + } + Stream
entries() { return entrySet().stream().flatMap(this::toEntries); } diff --git a/src/test/java/BehaviorTests/HeaderTest.java b/src/test/java/BehaviorTests/HeaderTest.java index 484a81913..da6bf64b1 100644 --- a/src/test/java/BehaviorTests/HeaderTest.java +++ b/src/test/java/BehaviorTests/HeaderTest.java @@ -238,7 +238,6 @@ public void canHaveTheSameHeaderAddedTwice() { @Test public void canReplaceAHeader() { Unirest.config().setDefaultHeader("foo", "bar"); - Unirest.get(MockServer.GET) .headerReplace("foo", "qux") .headerReplace("fruit", "mango") @@ -249,4 +248,27 @@ public void canReplaceAHeader() { .assertHeader("foo", "qux") .assertHeader("fruit", "mango"); } + + @Test + public void setVsAddDefaultHeaders() { + Unirest.config().setDefaultHeader("foo", "bar") + .setDefaultHeader("foo", "qux") + .addDefaultHeader("fruit", "mango") + .addDefaultHeader("fruit", "orange") + .addDefaultHeader("colour","red") + .setDefaultHeader("colour","blue") + .addDefaultHeader("colour", "yellow"); + + Unirest.get(MockServer.GET) + .asObject(RequestCapture.class) + .getBody() + .assertHeaderSize("foo", 1) + .assertHeader("foo", "qux") + .assertHeaderSize("fruit", 2) + .assertHeader("fruit", "mango") + .assertHeader("fruit", "orange") + .assertHeaderSize("colour", 2) + .assertHeader("colour","blue") + .assertHeader("colour", "yellow"); + } } From 2a539752a9f61c5da8bea4bb67e011543b182b17 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 17 Dec 2018 10:34:30 -0600 Subject: [PATCH 0372/1769] [maven-release-plugin] prepare release v3.2.02 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 4055815f6..def7a5c7a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.2.02-SNAPSHOT + 3.2.02 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.2.02 From 592ee45c99966e2a0d14e7890757925a547c388f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 17 Dec 2018 10:34:37 -0600 Subject: [PATCH 0373/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index def7a5c7a..90af46039 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.2.02 + 3.2.03-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.2.02 + HEAD From 05dbe86001a9225afa2356b9f58e890353950a32 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 17 Dec 2018 10:38:41 -0600 Subject: [PATCH 0374/1769] bump docs --- CHANGELOG.md | 3 +++ README.md | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e1052538..771acf8f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 3.2.02 +* distinguish between set and add for default headers. + # 3.2.01 * add method to replace a header rather than append to it. diff --git a/README.md b/README.md index 9c4502062..bf632b3f4 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This repo is an updated, maintained, and independent fork of the original Mashap io.github.openunirest open-unirest-java - 3.2.01 + 3.2.02 ``` From 3eae69bc4b945df1fcf17ae2868f3682fa3d2813 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 17 Dec 2018 20:12:34 -0600 Subject: [PATCH 0375/1769] can add suppliers to default headers --- CHANGELOG.md | 8 +- src/main/java/unirest/ApacheResponse.java | 2 +- src/main/java/unirest/ApacheUtils.java | 40 ++++++++ src/main/java/unirest/BaseRequest.java | 2 +- src/main/java/unirest/Config.java | 14 +++ src/main/java/unirest/Headers.java | 101 +++++++++++++------- src/main/java/unirest/RequestPrep.java | 9 +- src/main/java/unirest/Response.java | 2 +- src/test/java/BehaviorTests/HeaderTest.java | 19 ++++ src/test/java/unirest/HeadersTest.java | 5 +- 10 files changed, 162 insertions(+), 40 deletions(-) create mode 100644 src/main/java/unirest/ApacheUtils.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 771acf8f7..94a7f529d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 3.2.03 +* Allow the configuration of header suppliers. +```java + Unirest.config().setDefaultHeader("trace", () -> value); +``` + # 3.2.02 * distinguish between set and add for default headers. @@ -7,7 +13,7 @@ # 3.2.00 * Now you can stream the results into a file! * It doesn't need to be a file either. It could be any result. Unirest will shove it in a file. -``` +```java File file = Unirest.get("https://someplace/file.tar.gz") .asFile("/local/storage/file.tar.gz") .getBody(); diff --git a/src/main/java/unirest/ApacheResponse.java b/src/main/java/unirest/ApacheResponse.java index c3e4a9bb0..53bd8476c 100644 --- a/src/main/java/unirest/ApacheResponse.java +++ b/src/main/java/unirest/ApacheResponse.java @@ -53,7 +53,7 @@ public String getStatusText(){ @Override public Headers getHeaders(){ - return new Headers(r.getAllHeaders()); + return ApacheUtils.extractHeader(r); } @Override diff --git a/src/main/java/unirest/ApacheUtils.java b/src/main/java/unirest/ApacheUtils.java new file mode 100644 index 000000000..71579a3b7 --- /dev/null +++ b/src/main/java/unirest/ApacheUtils.java @@ -0,0 +1,40 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.apache.http.HttpResponse; + +import java.util.stream.Collectors; +import java.util.stream.Stream; + +class ApacheUtils { + public static Headers extractHeader(HttpResponse r) { + return new Headers(Stream.of(r.getAllHeaders()) + .map(e -> new Headers.Entry(e.getName(), e.getValue())) + .collect(Collectors.toList())); + } +} diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index e258f4850..536394608 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -51,7 +51,7 @@ abstract class BaseRequest implements HttpRequest { this.config = httpRequest.config; this.method = httpRequest.method; this.url = httpRequest.url; - this.headers.addAll(httpRequest.headers); + this.headers.putAll(httpRequest.headers); } BaseRequest(Config config, HttpMethod method, String url) { diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java index 8e8e279f8..20d8b767c 100644 --- a/src/main/java/unirest/Config.java +++ b/src/main/java/unirest/Config.java @@ -39,6 +39,7 @@ import java.util.List; import java.util.Optional; import java.util.function.Function; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -258,6 +259,19 @@ public Config setDefaultHeader(String name, String value) { return this; } + /** + * Set default header to appear on all requests, value is through a Supplier + * This is useful for adding tracing elements to requests. + * + * @param name The name of the header. + * @param value a supplier that will get called as part of the request. + * @return this config object + */ + public Config setDefaultHeader(String name, Supplier value) { + defaultHeaders.add(name, value); + return this; + } + /** * Add default header to appear on all requests * diff --git a/src/main/java/unirest/Headers.java b/src/main/java/unirest/Headers.java index a54590b6c..37457cc71 100644 --- a/src/main/java/unirest/Headers.java +++ b/src/main/java/unirest/Headers.java @@ -26,62 +26,99 @@ package unirest; -import org.apache.http.Header; -import org.apache.http.message.BasicHeader; - import java.util.*; +import java.util.function.Supplier; import java.util.stream.Stream; -import static unirest.Util.nullToEmpty; +import static java.util.stream.Collectors.toList; -public class Headers extends TreeMap> { +public class Headers { private static final long serialVersionUID = 71310341388734766L; + private TreeMap> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - public Headers() { - super(String.CASE_INSENSITIVE_ORDER); - } + public Headers(){} - @Deprecated // In version 4 Apache classes will be abstracted out - public Headers(Header[] pairs) { - for (Header header : pairs) { - add(header.getName(), header.getValue()); - } + public Headers(Collection entries){ + entries.forEach(e -> add(e.name, e.value)); } - public String getFirst(Object key) { - return getOrDefault(key, Collections.emptyList()) - .stream() - .findFirst() - .orElse(null); + public void add(String name, String value) { + add(name, () -> value); } - public void add(String name, String value) { - if(Objects.nonNull(name)){ - computeIfAbsent(name, k -> new ArrayList<>()).add(nullToEmpty(value)); + public void add(String name, Supplier value) { + if(Objects.nonNull(name)) { + headers.computeIfAbsent(name, k -> new ArrayList<>()).add(new Entry(name, value)); } } public void replace(String name, String value){ - if(this.containsKey(name)) { - List repl = new ArrayList<>(); - repl.add(value); - this.replace(name.trim(), repl); + if(headers.containsKey(name)) { + List repl = new ArrayList<>(); + repl.add(new Entry(name, () -> value)); + headers.replace(name.trim(), repl); } else { add(name, value); } } - Stream
entries() { - return entrySet().stream().flatMap(this::toEntries); + public int size() { + return headers.size(); + } + + public List get(String name) { + return headers.get(name) + .stream() + .map(Entry::getValue) + .collect(toList()); + } + + public void putAll(Headers defaultHeaders) { + this.headers.putAll(defaultHeaders.headers); + } + + public boolean containsKey(String key) { + return this.headers.containsKey(key); } - private Stream
toEntries(Map.Entry> k) { - String key = k.getKey(); - return k.getValue().stream().map(e -> new BasicHeader(key, e)); + public void clear() { + this.headers.clear(); } - public void addAll(Headers headers) { - headers.entries().forEach(e -> add(e.getName(), e.getValue())); + public String getFirst(String key) { + return headers.getOrDefault(key, Collections.emptyList()) + .stream() + .map(e -> e.value) + .map(Supplier::get) + .findFirst() + .orElse(""); + } + + Stream stream() { + return this.headers.values().stream().flatMap(Collection::stream); + } + + static class Entry { + private final String name; + private final Supplier value; + + public Entry(String name, String value){ + this.name = name; + this.value = () -> value; + } + + public Entry(String name, Supplier value){ + this.name = name; + this.value = value; + } + + public String getName() { + return name; + } + + public String getValue(){ + return value.get(); + } } } diff --git a/src/main/java/unirest/RequestPrep.java b/src/main/java/unirest/RequestPrep.java index f64291643..a2d7b7e66 100644 --- a/src/main/java/unirest/RequestPrep.java +++ b/src/main/java/unirest/RequestPrep.java @@ -26,8 +26,10 @@ package unirest; +import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.client.methods.*; +import org.apache.http.message.BasicHeader; import org.apache.http.nio.entity.NByteArrayEntity; import java.io.ByteArrayOutputStream; @@ -81,13 +83,18 @@ private HttpRequestBase getHttpRequestBase() { try { HttpRequestBase reqObj = FACTORIES.get(request.getHttpMethod()).apply(request.getUrl()); - request.getHeaders().entries().forEach(reqObj::addHeader); + request.getHeaders().stream().map(this::toEntries).forEach(reqObj::addHeader); return reqObj; }catch (RuntimeException e){ throw new UnirestException(e); } } + + private Header toEntries(Headers.Entry k) { + return new BasicHeader(k.getName(), k.getValue()); + } + private void setBody(HttpRequestBase reqObj) { if (!(request.getHttpMethod() == GET || request.getHttpMethod() == HttpMethod.HEAD)) { if (request.getBody() != null) { diff --git a/src/main/java/unirest/Response.java b/src/main/java/unirest/Response.java index 0e9e67044..8f6944af8 100644 --- a/src/main/java/unirest/Response.java +++ b/src/main/java/unirest/Response.java @@ -49,7 +49,7 @@ class Response implements HttpResponse { } private Response(org.apache.http.HttpResponse response){ - headers = new Headers(response.getAllHeaders()); + headers = ApacheUtils.extractHeader(response); StatusLine statusLine = response.getStatusLine(); this.statusCode = statusLine.getStatusCode(); this.statusText = statusLine.getReasonPhrase(); diff --git a/src/test/java/BehaviorTests/HeaderTest.java b/src/test/java/BehaviorTests/HeaderTest.java index da6bf64b1..d6d3f1ef7 100644 --- a/src/test/java/BehaviorTests/HeaderTest.java +++ b/src/test/java/BehaviorTests/HeaderTest.java @@ -35,6 +35,8 @@ import static unirest.TestUtil.mapOf; public class HeaderTest extends BddTest { + private String value = "one"; + @Test public void testHeadersOnGetRequests() { Unirest.get(MockServer.GET) @@ -271,4 +273,21 @@ public void setVsAddDefaultHeaders() { .assertHeader("colour","blue") .assertHeader("colour", "yellow"); } + + @Test + public void canSetAHeaderAsASupplier() { + Unirest.config().setDefaultHeader("trace", () -> value); + + Unirest.get(MockServer.GET) + .asObject(RequestCapture.class) + .getBody() + .assertHeader("trace", "one"); + + value = "two"; + + Unirest.get(MockServer.GET) + .asObject(RequestCapture.class) + .getBody() + .assertHeader("trace", "two"); + } } diff --git a/src/test/java/unirest/HeadersTest.java b/src/test/java/unirest/HeadersTest.java index 7f35845de..706433168 100644 --- a/src/test/java/unirest/HeadersTest.java +++ b/src/test/java/unirest/HeadersTest.java @@ -26,7 +26,6 @@ package unirest; -import org.apache.http.Header; import org.junit.Test; import java.util.stream.Collectors; @@ -40,7 +39,7 @@ public void canGetApacheHeaders() { Headers headers = new Headers(); headers.add("foo","bar"); - Header h = headers.entries().findAny().get(); + Headers.Entry h = headers.stream().findAny().get(); assertEquals("foo", h.getName()); assertEquals("bar", h.getValue()); @@ -51,6 +50,6 @@ public void dontBombOnNull(){ Headers h = new Headers(); h.add(null, "foo"); - assertEquals(0, h.entries().collect(Collectors.toSet()).size()); + assertEquals(0, h.stream().collect(Collectors.toSet()).size()); } } \ No newline at end of file From 7ca5616a47f311804753eefe0750a5a3130d703c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 18 Dec 2018 21:04:52 -0600 Subject: [PATCH 0376/1769] [maven-release-plugin] prepare release v3.2.03 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 90af46039..9fbc01a95 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.2.03-SNAPSHOT + 3.2.03 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.2.03 From 7384d54292e7472d389d7d296b16ef5185b14418 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 18 Dec 2018 21:05:05 -0600 Subject: [PATCH 0377/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 9fbc01a95..dd9972e9f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.2.03 + 3.2.04-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.2.03 + HEAD From 0d7820b9d2436d849170b8167b3c50d785012cb4 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 18 Dec 2018 21:26:10 -0600 Subject: [PATCH 0378/1769] bump readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf632b3f4..5b6c256dd 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This repo is an updated, maintained, and independent fork of the original Mashap io.github.openunirest open-unirest-java - 3.2.02 + 3.2.03 ``` From a7f211a684e30d2c6ccd774282634fc287d15a55 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 25 Dec 2018 10:25:42 -0600 Subject: [PATCH 0379/1769] add ifSuccess and ifFailure methods --- CHANGELOG.md | 9 ++ src/main/java/unirest/BaseResponse.java | 21 ++++ src/main/java/unirest/HttpResponse.java | 17 ++++ src/main/java/unirest/Response.java | 97 ------------------- .../PostRequestHandlersTest.java | 86 ++++++++++++++++ src/test/java/unirest/HttpResponseTest.java | 51 ---------- 6 files changed, 133 insertions(+), 148 deletions(-) delete mode 100644 src/main/java/unirest/Response.java create mode 100644 src/test/java/BehaviorTests/PostRequestHandlersTest.java delete mode 100644 src/test/java/unirest/HttpResponseTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 94a7f529d..c2d3e30b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# 3.2.04 +* Adds chainable ifSuccess and ifFailure consumer methods to the response. Now you can handle the response like +```java + Unirest.get("https://localhost/somewhere) + .asString() + .ifSuccess(r -> log.info("Yippy!")) + .ifFailure(r -> log.error("Booo")); +``` + # 3.2.03 * Allow the configuration of header suppliers. ```java diff --git a/src/main/java/unirest/BaseResponse.java b/src/main/java/unirest/BaseResponse.java index afddaa8ca..a900be0cf 100644 --- a/src/main/java/unirest/BaseResponse.java +++ b/src/main/java/unirest/BaseResponse.java @@ -28,6 +28,7 @@ import java.io.InputStream; import java.util.Optional; +import java.util.function.Consumer; import java.util.function.Function; abstract class BaseResponse implements HttpResponse { @@ -82,4 +83,24 @@ public V mapRawBody(Function func) { protected void setParsingException(String originalBody, RuntimeException e) { parsingerror = Optional.of(new UnirestParsingException(originalBody, e)); } + + @Override + public HttpResponse ifSuccess(Consumer> consumer) { + if(isSuccess()){ + consumer.accept(this); + } + return this; + } + + @Override + public HttpResponse ifFailure(Consumer> consumer) { + if(!isSuccess()){ + consumer.accept(this); + } + return this; + } + + private boolean isSuccess() { + return getStatus() >= 200 && getStatus() < 300 && !getParsingError().isPresent(); + } } diff --git a/src/main/java/unirest/HttpResponse.java b/src/main/java/unirest/HttpResponse.java index 4f33b1798..18afccca7 100644 --- a/src/main/java/unirest/HttpResponse.java +++ b/src/main/java/unirest/HttpResponse.java @@ -28,6 +28,7 @@ import java.io.InputStream; import java.util.Optional; +import java.util.function.Consumer; import java.util.function.Function; /** @@ -89,4 +90,20 @@ public interface HttpResponse { */ @Deprecated V mapRawBody(Function func); + + /** + * If the response was a 200-series response. Invoke this consumer + * can be chained with ifFailure + * @param consumer a function to consume a HttpResponse + * @return the same response + */ + HttpResponse ifSuccess(Consumer> consumer); + + /** + * If the response was NOT a 200-series response or a mapping exception happened. Invoke this consumer + * can be chained with ifSuccess + * @param consumer a function to consume a HttpResponse + * @return the same response + */ + HttpResponse ifFailure(Consumer> consumer); } diff --git a/src/main/java/unirest/Response.java b/src/main/java/unirest/Response.java deleted file mode 100644 index 8f6944af8..000000000 --- a/src/main/java/unirest/Response.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package unirest; - -import org.apache.http.StatusLine; - -import java.io.InputStream; -import java.util.Optional; -import java.util.function.Function; - -class Response implements HttpResponse { - - private Optional parsingError = Optional.empty(); - private final Headers headers; - private final String statusText; - private final int statusCode; - - private InputStream rawBody; - private T body; - - Response(org.apache.http.HttpResponse response, T body, InputStream is){ - this(response); - this.body = body; - this.rawBody = is; - } - - private Response(org.apache.http.HttpResponse response){ - headers = ApacheUtils.extractHeader(response); - StatusLine statusLine = response.getStatusLine(); - this.statusCode = statusLine.getStatusCode(); - this.statusText = statusLine.getReasonPhrase(); - } - - @Override - public int getStatus() { - return statusCode; - } - - @Override - public String getStatusText() { - return statusText; - } - - @Override - public Headers getHeaders() { - return headers; - } - - @Override - public InputStream getRawBody() { - return rawBody; - } - - @Override - public T getBody() { - return body; - } - - @Override - public Optional getParsingError() { - return parsingError; - } - - @Override - public V mapBody(Function func){ - return func.apply(body); - } - - @Override - public V mapRawBody(Function func) { - return func.apply(rawBody); - } -} diff --git a/src/test/java/BehaviorTests/PostRequestHandlersTest.java b/src/test/java/BehaviorTests/PostRequestHandlersTest.java new file mode 100644 index 000000000..5dbbbedd2 --- /dev/null +++ b/src/test/java/BehaviorTests/PostRequestHandlersTest.java @@ -0,0 +1,86 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package BehaviorTests; + +import org.junit.After; +import org.junit.Test; +import unirest.HttpResponse; +import unirest.Unirest; + +import static org.junit.Assert.*; + +public class PostRequestHandlersTest extends BddTest { + + private HttpResponse captured; + + @Override + @After + public void tearDown() { + super.tearDown(); + captured = null; + } + + @Test + public void onSuccessDoSomething() { + Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asObject(RequestCapture.class) + .ifSuccess(r -> captured = r) + .ifFailure(r -> fail("should not have been called")); + + assertNotNull(captured); + captured.getBody().assertParam("foo", "bar"); + } + + @Test + public void onFailDoSomething() { + Unirest.get(MockServer.INVALID_REQUEST) + .queryString("foo", "bar") + .asObject(RequestCapture.class) + .ifFailure(r -> captured = r) + .ifSuccess(r -> fail("should not have been called")); + + assertNotNull(captured); + assertEquals(400, captured.getStatus()); + } + + @Test + public void itsAFailIfTheMapperFails() { + MockServer.setStringResponse("not what you expect"); + + Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asObject(RequestCapture.class) + .ifFailure(r -> captured = r) + .ifSuccess(r -> fail("should not have been called")); + + assertNotNull(captured); + assertEquals(200, captured.getStatus()); + assertTrue(captured.getParsingError().isPresent()); + assertEquals("not what you expect", captured.getParsingError().get().getOriginalBody()); + } +} diff --git a/src/test/java/unirest/HttpResponseTest.java b/src/test/java/unirest/HttpResponseTest.java deleted file mode 100644 index c5094dce4..000000000 --- a/src/test/java/unirest/HttpResponseTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package unirest; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static unirest.TestUtil.emptyInput; - -public class HttpResponseTest { - - @Test - public void canMapBody() { - MockApacheResponse r = new MockApacheResponse(); - Integer v = new Response<>(r, "42", emptyInput()).mapBody(Integer::valueOf); - assertEquals(new Integer(42), v); - } - - @Test - public void canMapRawBody() { - MockApacheResponse r = new MockApacheResponse(); - Integer v = new Response<>(r, "42", TestUtil.toInputStream("42")) - .mapRawBody(i -> Integer.valueOf(TestUtil.toString(i))); - - assertEquals(new Integer(42), v); - } -} \ No newline at end of file From 965812d80acda1695d0bec0f11327cfad89ea1f5 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 25 Dec 2018 10:28:56 -0600 Subject: [PATCH 0380/1769] fix doc --- CHANGELOG.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2d3e30b2..a0108f2aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # 3.2.04 * Adds chainable ifSuccess and ifFailure consumer methods to the response. Now you can handle the response like ```java - Unirest.get("https://localhost/somewhere) + Unirest.get("https://localhost/somewhere") .asString() .ifSuccess(r -> log.info("Yippy!")) .ifFailure(r -> log.error("Booo")); diff --git a/README.md b/README.md index 5b6c256dd..9e217a71b 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This repo is an updated, maintained, and independent fork of the original Mashap io.github.openunirest open-unirest-java - 3.2.03 + 3.2.04 ``` From 357f1dd382554b5b20f6dfb8a4fe159629311498 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 25 Dec 2018 10:30:40 -0600 Subject: [PATCH 0381/1769] [maven-release-plugin] prepare release v3.2.04 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index dd9972e9f..72be1c39c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.2.04-SNAPSHOT + 3.2.04 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.2.04 From 0de57b794cf869b4623a25fd7ff259a919509960 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 25 Dec 2018 10:30:48 -0600 Subject: [PATCH 0382/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 72be1c39c..cd75a970e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.2.04 + 3.2.05-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.2.04 + HEAD From 23e3ce5aeac361bb0a878d366551b1601d186d8a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 25 Dec 2018 10:38:40 -0600 Subject: [PATCH 0383/1769] make the versions all the same size --- CHANGELOG.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0108f2aa..46232557f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 3.2.04 +## 3.2.04 * Adds chainable ifSuccess and ifFailure consumer methods to the response. Now you can handle the response like ```java Unirest.get("https://localhost/somewhere") @@ -7,19 +7,19 @@ .ifFailure(r -> log.error("Booo")); ``` -# 3.2.03 +## 3.2.03 * Allow the configuration of header suppliers. ```java Unirest.config().setDefaultHeader("trace", () -> value); ``` -# 3.2.02 +## 3.2.02 * distinguish between set and add for default headers. -# 3.2.01 +## 3.2.01 * add method to replace a header rather than append to it. -# 3.2.00 +## 3.2.00 * Now you can stream the results into a file! * It doesn't need to be a file either. It could be any result. Unirest will shove it in a file. ```java From 6e7f7424f9cb008a7515dd2f7ed62a0cd05fd32a Mon Sep 17 00:00:00 2001 From: Steve Springett Date: Fri, 28 Dec 2018 17:07:55 -0600 Subject: [PATCH 0384/1769] Added AutoCloseable Added AutoCloseable so that shutdown will automatically be called when used with try-with-resource. --- src/main/java/unirest/UnirestInstance.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/unirest/UnirestInstance.java b/src/main/java/unirest/UnirestInstance.java index 977d7f29b..deab6c174 100644 --- a/src/main/java/unirest/UnirestInstance.java +++ b/src/main/java/unirest/UnirestInstance.java @@ -26,7 +26,7 @@ package unirest; -public class UnirestInstance { +public class UnirestInstance implements AutoCloseable { private final Config config; @@ -139,4 +139,13 @@ public JsonPatchRequest jsonPatch(String url) { public boolean isRunning() { return config.isRunning(); } + + /** + * Wraps shutdown and will automatically be called when UnirestInstance is + * used with try-with-resource. This will alleviate the need to manually + * call shutDown as it will be done automatically. + */ + public void close() { + shutDown(true); + } } From 21eec9006fcc156c519cae049ee891643935e859 Mon Sep 17 00:00:00 2001 From: Steve Springett Date: Sat, 29 Dec 2018 21:09:42 -0600 Subject: [PATCH 0385/1769] Added test to verify shutDown is called when autoclose is initiated --- src/test/java/BehaviorTests/LifeCycleTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index 6f2cdd5a5..e07923edb 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -192,4 +192,15 @@ public void shouldReuseThreadPool() { }); assertThat(ManagementFactory.getThreadMXBean().getThreadCount(), is(lessThan(startingCount + 10))); } + + @Test + public void testUnirestInstanceIsShutdownWhenClosed() { + UnirestInstance reference; + try (UnirestInstance instance = new UnirestInstance(new Config().setDefaultHeader("foo", "bar"))) { + reference = instance; + assertEquals(1, reference.config().getDefaultHeaders().size()); + assertEquals("bar", reference.config().getDefaultHeaders().get("foo").get(0)); + } + assertEquals(0, reference.config().getDefaultHeaders().size()); + } } From 74fd2002002da8d46502fdbbe71a691373d7ff6a Mon Sep 17 00:00:00 2001 From: Steve Springett Date: Sat, 29 Dec 2018 21:09:42 -0600 Subject: [PATCH 0386/1769] Revert "Added test to verify shutDown is called when autoclose is initiated" This reverts commit 21eec9006fcc156c519cae049ee891643935e859. --- src/test/java/BehaviorTests/LifeCycleTest.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index e07923edb..6f2cdd5a5 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -192,15 +192,4 @@ public void shouldReuseThreadPool() { }); assertThat(ManagementFactory.getThreadMXBean().getThreadCount(), is(lessThan(startingCount + 10))); } - - @Test - public void testUnirestInstanceIsShutdownWhenClosed() { - UnirestInstance reference; - try (UnirestInstance instance = new UnirestInstance(new Config().setDefaultHeader("foo", "bar"))) { - reference = instance; - assertEquals(1, reference.config().getDefaultHeaders().size()); - assertEquals("bar", reference.config().getDefaultHeaders().get("foo").get(0)); - } - assertEquals(0, reference.config().getDefaultHeaders().size()); - } } From ee4ae91fdb216b9a525e6008217241a713a03bbd Mon Sep 17 00:00:00 2001 From: Steve Springett Date: Sat, 29 Dec 2018 21:14:45 -0600 Subject: [PATCH 0387/1769] Added test to verify shutDown is called when autoclose is initiated --- src/test/java/BehaviorTests/LifeCycleTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index 6f2cdd5a5..e07923edb 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -192,4 +192,15 @@ public void shouldReuseThreadPool() { }); assertThat(ManagementFactory.getThreadMXBean().getThreadCount(), is(lessThan(startingCount + 10))); } + + @Test + public void testUnirestInstanceIsShutdownWhenClosed() { + UnirestInstance reference; + try (UnirestInstance instance = new UnirestInstance(new Config().setDefaultHeader("foo", "bar"))) { + reference = instance; + assertEquals(1, reference.config().getDefaultHeaders().size()); + assertEquals("bar", reference.config().getDefaultHeaders().get("foo").get(0)); + } + assertEquals(0, reference.config().getDefaultHeaders().size()); + } } From 07eb780e945a8e33b326cab89f51f2da2e579adb Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 30 Dec 2018 08:37:09 -0600 Subject: [PATCH 0388/1769] [maven-release-plugin] prepare release v3.2.05 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index cd75a970e..242b0c414 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.2.05-SNAPSHOT + 3.2.05 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.2.05 From c5e03f667bfcd0be3a43b9e4490987f60f24dd7c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 30 Dec 2018 08:37:19 -0600 Subject: [PATCH 0389/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 242b0c414..6cef4dcc2 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.2.05 + 3.2.06-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.2.05 + HEAD From 52d57620c8d58eee2fa613287ba6319b5e854398 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 30 Dec 2018 08:42:56 -0600 Subject: [PATCH 0390/1769] update docs --- CHANGELOG.md | 3 +++ README.md | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46232557f..6dbecc2f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 3.2.05 +* UnirestInstance is autoclosable + ## 3.2.04 * Adds chainable ifSuccess and ifFailure consumer methods to the response. Now you can handle the response like ```java diff --git a/README.md b/README.md index 9e217a71b..e6126d062 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This repo is an updated, maintained, and independent fork of the original Mashap io.github.openunirest open-unirest-java - 3.2.04 + 3.2.05 ``` From 0d6e7cd668617771de58e3b8fa03c14d567dcde5 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 30 Dec 2018 08:51:44 -0600 Subject: [PATCH 0391/1769] Update CONTRIBUTING.md --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ade83b9b5..4337fcd6c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,10 +1,10 @@ -# Contributing to Atom +# Contributing to Open Unirest :+1::tada: First off, thanks for taking the time to contribute! :tada::+1: ## Code of Conduct -This project and everyone participating in it is governed by the [Atom Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. +This project and everyone participating in it is governed by the [Open Unirest Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. ## How Can I Contribute? From 856df2446144fe2576182be52005711b8250b46c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 30 Dec 2018 10:12:34 -0600 Subject: [PATCH 0392/1769] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e6126d062..d779d8843 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Unirest for Java [![Build Status](https://travis-ci.org/OpenUnirest/unirest-java.svg?branch=master)](https://travis-ci.org/OpenUnirest/unirest-java) -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.openunirest/unirest-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.openunirest/unirest-java) +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.openunirest/open-unirest-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.openunirest/open-unirest-java) [![DepShield Badge](https://depshield.sonatype.org/badges/OpenUnirest/unirest-java/depshield.svg)](https://depshield.github.io) ## About This Repository From e9a2203c54f611fa5f5dee8d365d7f3260cc726b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 3 Jan 2019 20:38:47 -0600 Subject: [PATCH 0393/1769] closes #56 closes #54 expose the headers in the order they were either added or returned fromt he server --- src/main/java/unirest/Header.java | 32 +++ src/main/java/unirest/Headers.java | 54 ++--- src/main/java/unirest/RequestPrep.java | 4 +- src/test/java/BehaviorTests/MockServer.java | 18 +- src/test/java/BehaviorTests/Pair.java | 38 ++++ .../BehaviorTests/ResponseHeaderTest.java | 65 ++++++ src/test/java/unirest/HeadersTest.java | 8 +- src/test/java/unirest/MockApacheResponse.java | 194 ------------------ 8 files changed, 182 insertions(+), 231 deletions(-) create mode 100644 src/main/java/unirest/Header.java create mode 100644 src/test/java/BehaviorTests/Pair.java create mode 100644 src/test/java/BehaviorTests/ResponseHeaderTest.java delete mode 100644 src/test/java/unirest/MockApacheResponse.java diff --git a/src/main/java/unirest/Header.java b/src/main/java/unirest/Header.java new file mode 100644 index 000000000..1445e8ffa --- /dev/null +++ b/src/main/java/unirest/Header.java @@ -0,0 +1,32 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +public interface Header { + String getName(); + String getValue(); +} diff --git a/src/main/java/unirest/Headers.java b/src/main/java/unirest/Headers.java index 37457cc71..1014fa247 100644 --- a/src/main/java/unirest/Headers.java +++ b/src/main/java/unirest/Headers.java @@ -26,16 +26,19 @@ package unirest; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Objects; import java.util.function.Supplier; -import java.util.stream.Stream; import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toSet; public class Headers { private static final long serialVersionUID = 71310341388734766L; - private TreeMap> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + private List
headers = new ArrayList<>(); public Headers(){} @@ -49,37 +52,40 @@ public void add(String name, String value) { public void add(String name, Supplier value) { if(Objects.nonNull(name)) { - headers.computeIfAbsent(name, k -> new ArrayList<>()).add(new Entry(name, value)); + headers.add(new Entry(name, value)); } } public void replace(String name, String value){ - if(headers.containsKey(name)) { - List repl = new ArrayList<>(); - repl.add(new Entry(name, () -> value)); - headers.replace(name.trim(), repl); - } else { - add(name, value); - } + remove(name); + add(name, value); + } + + private void remove(String name) { + headers.removeIf(h -> isName(h, name)); } public int size() { - return headers.size(); + return headers.stream().map(Header::getName).collect(toSet()).size(); } public List get(String name) { - return headers.get(name) - .stream() - .map(Entry::getValue) + return headers.stream() + .filter(h -> isName(h, name)) + .map(Header::getValue) .collect(toList()); } + private boolean isName(Header h, String name) { + return Util.nullToEmpty(name).equalsIgnoreCase(h.getName()); + } + public void putAll(Headers defaultHeaders) { - this.headers.putAll(defaultHeaders.headers); + this.headers.addAll(defaultHeaders.headers); } public boolean containsKey(String key) { - return this.headers.containsKey(key); + return this.headers.stream().anyMatch(h -> isName(h, key)); } public void clear() { @@ -87,19 +93,19 @@ public void clear() { } public String getFirst(String key) { - return headers.getOrDefault(key, Collections.emptyList()) + return headers .stream() - .map(e -> e.value) - .map(Supplier::get) + .filter(h -> isName(h, key)) .findFirst() + .map(Header::getValue) .orElse(""); } - Stream stream() { - return this.headers.values().stream().flatMap(Collection::stream); + public List
all() { + return this.headers; } - static class Entry { + static class Entry implements Header { private final String name; private final Supplier value; @@ -113,10 +119,12 @@ public Entry(String name, Supplier value){ this.value = value; } + @Override public String getName() { return name; } + @Override public String getValue(){ return value.get(); } diff --git a/src/main/java/unirest/RequestPrep.java b/src/main/java/unirest/RequestPrep.java index a2d7b7e66..b10270574 100644 --- a/src/main/java/unirest/RequestPrep.java +++ b/src/main/java/unirest/RequestPrep.java @@ -83,7 +83,7 @@ private HttpRequestBase getHttpRequestBase() { try { HttpRequestBase reqObj = FACTORIES.get(request.getHttpMethod()).apply(request.getUrl()); - request.getHeaders().stream().map(this::toEntries).forEach(reqObj::addHeader); + request.getHeaders().all().stream().map(this::toEntries).forEach(reqObj::addHeader); return reqObj; }catch (RuntimeException e){ throw new UnirestException(e); @@ -91,7 +91,7 @@ private HttpRequestBase getHttpRequestBase() { } - private Header toEntries(Headers.Entry k) { + private Header toEntries(unirest.Header k) { return new BasicHeader(k.getName(), k.getValue()); } diff --git a/src/test/java/BehaviorTests/MockServer.java b/src/test/java/BehaviorTests/MockServer.java index a9888a92f..db0697a9d 100644 --- a/src/test/java/BehaviorTests/MockServer.java +++ b/src/test/java/BehaviorTests/MockServer.java @@ -52,28 +52,26 @@ a copy of this software and associated documentation files (the package BehaviorTests; -import spark.utils.IOUtils; -import unirest.JacksonObjectMapper; import spark.Request; import spark.Response; import spark.Spark; +import spark.utils.IOUtils; +import unirest.JacksonObjectMapper; import unirest.TestUtil; import javax.servlet.ServletOutputStream; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; -import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; import static spark.Spark.*; public class MockServer { + private static final List> responseHeaders = new ArrayList<>(); private static final JacksonObjectMapper om = new JacksonObjectMapper(); private static Object responseBody; public static final int PORT = 4567; @@ -98,6 +96,7 @@ public static void setJsonAsResponse(Object o){ public static void reset(){ responseBody = null; + responseHeaders.clear(); } static { @@ -170,6 +169,7 @@ private static Object proxiedResponse(Request req, Response res) { private static Object jsonResponse(Request req, Response res) { res.cookie("JSESSIONID", "ABC123"); + responseHeaders.forEach(h -> res.header(h.key, h.value)); if(responseBody != null){ return responseBody; } @@ -185,4 +185,8 @@ public static void shutdown() { public static void setStringResponse(String stringResponse) { MockServer.responseBody = stringResponse; } + + public static void addResponseHeader(String key, String value) { + responseHeaders.add(new Pair<>(key, value)); + } } diff --git a/src/test/java/BehaviorTests/Pair.java b/src/test/java/BehaviorTests/Pair.java new file mode 100644 index 000000000..3ea3bc75e --- /dev/null +++ b/src/test/java/BehaviorTests/Pair.java @@ -0,0 +1,38 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package BehaviorTests; + +public class Pair { + public final K key; + public final V value; + + public Pair(K key, V value){ + + this.key = key; + this.value = value; + } +} diff --git a/src/test/java/BehaviorTests/ResponseHeaderTest.java b/src/test/java/BehaviorTests/ResponseHeaderTest.java new file mode 100644 index 000000000..60f0ed394 --- /dev/null +++ b/src/test/java/BehaviorTests/ResponseHeaderTest.java @@ -0,0 +1,65 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package BehaviorTests; + +import org.junit.Test; +import unirest.Header; +import unirest.Headers; +import unirest.Unirest; + +import static org.junit.Assert.assertEquals; + +public class ResponseHeaderTest extends BddTest { + + + @Test + public void responseHeadersAreInTheSameOrderAsTheResponse() { + MockServer.addResponseHeader("zed", "oranges"); + MockServer.addResponseHeader("alpha", "apples"); + MockServer.addResponseHeader("Content", "application/xml"); + MockServer.addResponseHeader("zed", "grapes"); + + Headers h = Unirest.get(MockServer.GET).asString().getHeaders(); + + // assertHeader("Date", "Fri, 04 Jan 2019 01:46:34 GMT", h.all().get(0)); + assertHeader("Set-Cookie", "JSESSIONID=ABC123", h.all().get(1)); + assertHeader("Expires", "Thu, 01 Jan 1970 00:00:00 GMT", h.all().get(2)); + assertHeader("zed", "oranges", h.all().get(3)); + assertHeader("alpha", "apples", h.all().get(4)); + assertHeader("Content", "application/xml", h.all().get(5)); + assertHeader("zed", "grapes", h.all().get(6)); + assertHeader("Content-Type", "text/html;charset=utf-8", h.all().get(7)); + assertHeader("Transfer-Encoding", "chunked", h.all().get(8)); + assertHeader("Server", "Jetty(9.4.12.v20180830)", h.all().get(9)); + + } + + private void assertHeader(String name, String value, Header header) { + assertEquals(name, header.getName()); + assertEquals(value, header.getValue()); + } +} diff --git a/src/test/java/unirest/HeadersTest.java b/src/test/java/unirest/HeadersTest.java index 706433168..0f9802dab 100644 --- a/src/test/java/unirest/HeadersTest.java +++ b/src/test/java/unirest/HeadersTest.java @@ -28,9 +28,7 @@ import org.junit.Test; -import java.util.stream.Collectors; - -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; public class HeadersTest { @@ -39,7 +37,7 @@ public void canGetApacheHeaders() { Headers headers = new Headers(); headers.add("foo","bar"); - Headers.Entry h = headers.stream().findAny().get(); + Header h = headers.all().get(0); assertEquals("foo", h.getName()); assertEquals("bar", h.getValue()); @@ -50,6 +48,6 @@ public void dontBombOnNull(){ Headers h = new Headers(); h.add(null, "foo"); - assertEquals(0, h.stream().collect(Collectors.toSet()).size()); + assertEquals(0, h.size()); } } \ No newline at end of file diff --git a/src/test/java/unirest/MockApacheResponse.java b/src/test/java/unirest/MockApacheResponse.java deleted file mode 100644 index c32b0e2f2..000000000 --- a/src/test/java/unirest/MockApacheResponse.java +++ /dev/null @@ -1,194 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package unirest; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; -import org.apache.http.*; -import org.apache.http.HttpResponse; -import org.apache.http.entity.BasicHttpEntity; -import org.apache.http.message.BasicHeader; -import org.apache.http.message.BasicStatusLine; -import org.apache.http.params.HttpParams; - -import java.io.ByteArrayInputStream; -import java.util.Locale; -import java.util.stream.Collectors; - -public class MockApacheResponse implements HttpResponse { - private Multimap headers = HashMultimap.create(); - private StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("",1,1), 0, ""); - private BasicHttpEntity entity = make(""); - - @Override - public StatusLine getStatusLine() { - return statusLine; - } - - @Override - public void setStatusLine(StatusLine statusline) { - this.statusLine = statusline; - } - - @Override - public void setStatusLine(ProtocolVersion ver, int code) { - throw new NotImplimented(); - } - - @Override - public void setStatusLine(ProtocolVersion ver, int code, String reason) { - throw new NotImplimented(); - } - - @Override - public void setStatusCode(int code) throws IllegalStateException { - throw new NotImplimented(); - } - - @Override - public void setReasonPhrase(String reason) throws IllegalStateException { - throw new NotImplimented(); - } - - @Override - public HttpEntity getEntity() { - return entity; - } - - @Override - public void setEntity(HttpEntity entity) { - throw new NotImplimented(); - } - - @Override - public Locale getLocale() { - throw new NotImplimented(); - } - - @Override - public void setLocale(Locale loc) { - throw new NotImplimented(); - } - - @Override - public ProtocolVersion getProtocolVersion() { - throw new NotImplimented(); - } - - @Override - public boolean containsHeader(String name) { - throw new NotImplimented(); - } - - @Override - public Header[] getHeaders(String name) { - throw new NotImplimented(); - } - - @Override - public Header getFirstHeader(String name) { - throw new NotImplimented(); - } - - @Override - public Header getLastHeader(String name) { - throw new NotImplimented(); - } - - @Override - public Header[] getAllHeaders() { - return headers.entries().stream() - .map(e -> new BasicHeader(e.getKey(), e.getValue())) - .collect(Collectors.toList()) - .toArray(new Header[headers.values().size()]); - } - - @Override - public void addHeader(Header header) { - throw new NotImplimented(); - } - - @Override - public void addHeader(String name, String value) { - headers.put(name, value); - } - - @Override - public void setHeader(Header header) { - throw new NotImplimented(); - } - - @Override - public void setHeader(String name, String value) { - headers.put(name, value); - } - - @Override - public void setHeaders(Header[] headers) { - throw new NotImplimented(); - } - - @Override - public void removeHeader(Header header) { - throw new NotImplimented(); - } - - @Override - public void removeHeaders(String name) { - throw new NotImplimented(); - } - - @Override - public HeaderIterator headerIterator() { - throw new NotImplimented(); - } - - @Override - public HeaderIterator headerIterator(String name) { - throw new NotImplimented(); - } - - @Override - public HttpParams getParams() { - throw new NotImplimented(); - } - - @Override - public void setParams(HttpParams params) { - throw new NotImplimented(); - } - - public void setBody(String body) { - this.entity = make(body); - } - - public static BasicHttpEntity make(String body){ - BasicHttpEntity e = new BasicHttpEntity(); - e.setContent(new ByteArrayInputStream(body.getBytes())); - return e; - } -} From 4d7fb3755227d30331ea3e6b2368e3cc414c9649 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 3 Jan 2019 20:50:15 -0600 Subject: [PATCH 0394/1769] add doc --- src/main/java/unirest/Headers.java | 72 ++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 13 deletions(-) diff --git a/src/main/java/unirest/Headers.java b/src/main/java/unirest/Headers.java index 1014fa247..efb425d82 100644 --- a/src/main/java/unirest/Headers.java +++ b/src/main/java/unirest/Headers.java @@ -40,23 +40,39 @@ public class Headers { private static final long serialVersionUID = 71310341388734766L; private List
headers = new ArrayList<>(); - public Headers(){} + public Headers() { + } - public Headers(Collection entries){ + public Headers(Collection entries) { entries.forEach(e -> add(e.name, e.value)); } + /** + * Add a header element + * @param name the name of the header + * @param value the value for the header + */ public void add(String name, String value) { add(name, () -> value); } + /** + * Add a header element with a supplier which will be evaluated on request + * @param name the name of the header + * @param value the value for the header + */ public void add(String name, Supplier value) { - if(Objects.nonNull(name)) { + if (Objects.nonNull(name)) { headers.add(new Entry(name, value)); } } - public void replace(String name, String value){ + /** + * Replace a header value. If there are multiple instances it will overwrite all of them + * @param name the name of the header + * @param value the value for the header + */ + public void replace(String name, String value) { remove(name); add(name, value); } @@ -65,10 +81,19 @@ private void remove(String name) { headers.removeIf(h -> isName(h, name)); } + /** + * Get the number of header keys. + * @return the size of the header keys + */ public int size() { return headers.stream().map(Header::getName).collect(toSet()).size(); } + /** + * Get all the values for a header name + * @param name name of the header element + * @return a list of values + */ public List get(String name) { return headers.stream() .filter(h -> isName(h, name)) @@ -76,22 +101,34 @@ public List get(String name) { .collect(toList()); } - private boolean isName(Header h, String name) { - return Util.nullToEmpty(name).equalsIgnoreCase(h.getName()); - } - - public void putAll(Headers defaultHeaders) { - this.headers.addAll(defaultHeaders.headers); + /** + * Add a bunch of headers at once + * @param header a header + */ + public void putAll(Headers header) { + this.headers.addAll(header.headers); } + /** + * Check if a header is present + * @param key a header + */ public boolean containsKey(String key) { return this.headers.stream().anyMatch(h -> isName(h, key)); } + /** + * Clear the headers! + */ public void clear() { this.headers.clear(); } + /** + * Get the first header value for a name + * @param key the name of the header + * @return the first value + */ public String getFirst(String key) { return headers .stream() @@ -101,20 +138,29 @@ public String getFirst(String key) { .orElse(""); } + /** + * Get all of the headers + * @return all the headers, in order + */ public List
all() { return this.headers; } + private boolean isName(Header h, String name) { + return Util.nullToEmpty(name).equalsIgnoreCase(h.getName()); + } + static class Entry implements Header { + private final String name; private final Supplier value; - public Entry(String name, String value){ + public Entry(String name, String value) { this.name = name; this.value = () -> value; } - public Entry(String name, Supplier value){ + public Entry(String name, Supplier value) { this.name = name; this.value = value; } @@ -125,7 +171,7 @@ public String getName() { } @Override - public String getValue(){ + public String getValue() { return value.get(); } } From da6e157234034b1f547c9165b9374e0a06b36d18 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 3 Jan 2019 20:58:06 -0600 Subject: [PATCH 0395/1769] [maven-release-plugin] prepare release v3.2.06 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 6cef4dcc2..4479e328f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.2.06-SNAPSHOT + 3.2.06 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.2.06 From a43cc2a3dde97a20ade2938f985cbf3f43bbc3e6 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 3 Jan 2019 20:58:24 -0600 Subject: [PATCH 0396/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 4479e328f..60534b39f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.2.06 + 3.2.07-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.2.06 + HEAD From 0c75f994fae5483b99f36b032e75733da4f92f79 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 3 Jan 2019 21:03:24 -0600 Subject: [PATCH 0397/1769] update doc --- CHANGELOG.md | 3 +++ README.md | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dbecc2f1..45b43577e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 3.2.06 +* access headers in order + ## 3.2.05 * UnirestInstance is autoclosable diff --git a/README.md b/README.md index d779d8843..918b49794 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This repo is an updated, maintained, and independent fork of the original Mashap io.github.openunirest open-unirest-java - 3.2.05 + 3.2.06 ``` From 42926dd78e0792fbb3e3a36088577bd974044a64 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 4 Jan 2019 13:51:01 -0600 Subject: [PATCH 0398/1769] upgrade jackson test dependency due to security issue --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 60534b39f..22c788197 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,7 @@ UTF-8 UTF-8 - 2.9.5 + 2.9.8 From 93e3b699e2cac691339878d31f25a70bacf51b89 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 5 Jan 2019 09:49:47 -0600 Subject: [PATCH 0399/1769] inline ApacheUtils. Starting to isolate Apache --- src/main/java/unirest/ApacheResponse.java | 6 +++- src/main/java/unirest/ApacheUtils.java | 40 ----------------------- 2 files changed, 5 insertions(+), 41 deletions(-) delete mode 100644 src/main/java/unirest/ApacheUtils.java diff --git a/src/main/java/unirest/ApacheResponse.java b/src/main/java/unirest/ApacheResponse.java index 53bd8476c..32d4314ef 100644 --- a/src/main/java/unirest/ApacheResponse.java +++ b/src/main/java/unirest/ApacheResponse.java @@ -32,6 +32,8 @@ import org.apache.http.util.EntityUtils; import java.io.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; import java.util.zip.GZIPInputStream; class ApacheResponse implements RawResponse { @@ -53,7 +55,9 @@ public String getStatusText(){ @Override public Headers getHeaders(){ - return ApacheUtils.extractHeader(r); + return new Headers(Stream.of(r.getAllHeaders()) + .map(e -> new Headers.Entry(e.getName(), e.getValue())) + .collect(Collectors.toList())); } @Override diff --git a/src/main/java/unirest/ApacheUtils.java b/src/main/java/unirest/ApacheUtils.java deleted file mode 100644 index 71579a3b7..000000000 --- a/src/main/java/unirest/ApacheUtils.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package unirest; - -import org.apache.http.HttpResponse; - -import java.util.stream.Collectors; -import java.util.stream.Stream; - -class ApacheUtils { - public static Headers extractHeader(HttpResponse r) { - return new Headers(Stream.of(r.getAllHeaders()) - .map(e -> new Headers.Entry(e.getName(), e.getValue())) - .collect(Collectors.toList())); - } -} From 0da379932981f7fffc499207157ba74b55393271 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 5 Jan 2019 09:52:20 -0600 Subject: [PATCH 0400/1769] switch to forEachOrdered as just forEach is not deterministic --- src/main/java/unirest/ApacheResponse.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/unirest/ApacheResponse.java b/src/main/java/unirest/ApacheResponse.java index 32d4314ef..181a4f2ae 100644 --- a/src/main/java/unirest/ApacheResponse.java +++ b/src/main/java/unirest/ApacheResponse.java @@ -32,7 +32,6 @@ import org.apache.http.util.EntityUtils; import java.io.*; -import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.zip.GZIPInputStream; @@ -55,9 +54,10 @@ public String getStatusText(){ @Override public Headers getHeaders(){ - return new Headers(Stream.of(r.getAllHeaders()) - .map(e -> new Headers.Entry(e.getName(), e.getValue())) - .collect(Collectors.toList())); + Headers h = new Headers(); + Stream.of(r.getAllHeaders()) + .forEachOrdered(e -> h.add(e.getName(), e.getValue())); + return h; } @Override From 051737df27ee54f47ce3bf3fc4d77984436cc8d5 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 6 Jan 2019 10:22:14 -0600 Subject: [PATCH 0401/1769] move apache stuff into apache --- src/main/java/unirest/ApacheClient.java | 19 ++++++++++++++ src/main/java/unirest/BaseRequest.java | 35 ++++++------------------- src/main/java/unirest/Client.java | 3 ++- src/main/java/unirest/Config.java | 8 +++--- 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/main/java/unirest/ApacheClient.java b/src/main/java/unirest/ApacheClient.java index 774923ab2..066fa200f 100644 --- a/src/main/java/unirest/ApacheClient.java +++ b/src/main/java/unirest/ApacheClient.java @@ -27,12 +27,14 @@ package unirest; import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import java.io.Closeable; import java.util.Optional; +import java.util.function.Function; import java.util.stream.Stream; public class ApacheClient extends BaseApacheClient implements Client { @@ -78,6 +80,23 @@ public ApacheClient(HttpClient httpc, this.syncMonitor = connMonitor; } + @Override + public HttpResponse request(HttpRequest request, Function> transformer) { + + HttpRequestBase requestObj = new RequestPrep(request, false).prepare(); + + try { + org.apache.http.HttpResponse execute = client.execute(requestObj); + HttpResponse httpResponse = transformer.apply(new ApacheResponse(execute)); + requestObj.releaseConnection(); + return httpResponse; + } catch (Exception e) { + throw new UnirestException(e); + } finally { + requestObj.releaseConnection(); + } + } + @Override public HttpClient getClient() { return client; diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 536394608..f139d2356 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -27,8 +27,6 @@ package unirest; import org.apache.http.HttpHeaders; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.concurrent.FutureCallback; @@ -127,7 +125,7 @@ public R withObjectMapper(ObjectMapper mapper) { @Override public HttpResponse asString() throws UnirestException { - return request(StringResponse::new); + return config.getClient().request(this, StringResponse::new); } @Override @@ -142,7 +140,7 @@ public CompletableFuture> asStringAsync(Callback ca @Override public HttpResponse asJson() throws UnirestException { - return request(JsonResponse::new); + return config.getClient().request(this, JsonResponse::new); } @Override @@ -157,17 +155,17 @@ public CompletableFuture> asJsonAsync(Callback @Override public HttpResponse asObject(Class responseClass) throws UnirestException { - return request(r -> new ObjectResponse(getObjectMapper(), r, responseClass)); + return config.getClient().request(this, r -> new ObjectResponse(getObjectMapper(), r, responseClass)); } @Override public HttpResponse asObject(GenericType genericType) throws UnirestException { - return request(r -> new ObjectResponse(getObjectMapper(), r, genericType)); + return config.getClient().request(this, r -> new ObjectResponse(getObjectMapper(), r, genericType)); } @Override public HttpResponse asObject(Function function) { - return request(funcResponse(function)); + return config.getClient().request(this, funcResponse(function)); } @Override @@ -201,7 +199,7 @@ private Function> funcResponse(Function asBinary() throws UnirestException { - return request(BinaryResponse::new); + return config.getClient().request(this, BinaryResponse::new); } @Override @@ -216,7 +214,7 @@ public CompletableFuture> asBinaryAsync(Callback consumer) { - request(getConsumer(consumer)); + config.getClient().request(this, getConsumer(consumer)); } @Override @@ -226,7 +224,7 @@ public void thenConsumeAsync(Consumer consumer) { @Override public HttpResponse asFile(String path) { - return request(r -> new FileResponse(r, path)); + return config.getClient().request(this, r -> new FileResponse(r, path)); } @Override @@ -295,23 +293,6 @@ public Body getBody() { return null; } - private HttpResponse request(Function> transformer) { - - HttpRequestBase requestObj = new RequestPrep(this, false).prepare(); - HttpClient client = config.getClient(); - - try { - org.apache.http.HttpResponse execute = client.execute(requestObj); - HttpResponse httpResponse = transformer.apply(new ApacheResponse(execute)); - requestObj.releaseConnection(); - return httpResponse; - } catch (Exception e) { - throw new UnirestException(e); - } finally { - requestObj.releaseConnection(); - } - } - private ObjectMapper getObjectMapper() { return objectMapper.orElseGet(config::getObjectMapper); } diff --git a/src/main/java/unirest/Client.java b/src/main/java/unirest/Client.java index ac03ff815..f40d4afed 100644 --- a/src/main/java/unirest/Client.java +++ b/src/main/java/unirest/Client.java @@ -28,10 +28,11 @@ import org.apache.http.client.HttpClient; +import java.util.function.Function; import java.util.stream.Stream; public interface Client { HttpClient getClient(); - Stream close(); + HttpResponse request(HttpRequest request, Function> transformer); } diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java index 20d8b767c..ef0761ead 100644 --- a/src/main/java/unirest/Config.java +++ b/src/main/java/unirest/Config.java @@ -385,16 +385,16 @@ public void shutDown(boolean clearOptions) { } /** - * Return the current HttpClient. One will be build if it does + * Return the current Client. One will be build if it does * not yet exist. * - * @return Apache HttpClient + * @return A synchronous Client */ - public HttpClient getClient() { + public Client getClient() { if (!client.isPresent()) { buildClient(); } - return client.get().getClient(); + return client.get(); } private synchronized void buildClient() { From ca7a62debdeca0267f3e546fcc213899bc3f8727 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 12 Jan 2019 07:42:11 -0600 Subject: [PATCH 0402/1769] move async apache things into the apache config --- src/main/java/unirest/ApacheAsyncClient.java | 33 +++++++++ src/main/java/unirest/AsyncClient.java | 26 ++++++- src/main/java/unirest/BaseRequest.java | 70 +++++++------------ src/main/java/unirest/Client.java | 17 ++++- src/main/java/unirest/Config.java | 4 +- src/test/java/BehaviorTests/DefectTest.java | 10 +-- .../java/BehaviorTests/LifeCycleTest.java | 2 +- src/test/java/unirest/ClientFactoryTest.java | 2 +- src/test/java/unirest/ConfigTest.java | 12 ++-- 9 files changed, 114 insertions(+), 62 deletions(-) diff --git a/src/main/java/unirest/ApacheAsyncClient.java b/src/main/java/unirest/ApacheAsyncClient.java index 35447a720..b9046f4fa 100644 --- a/src/main/java/unirest/ApacheAsyncClient.java +++ b/src/main/java/unirest/ApacheAsyncClient.java @@ -26,6 +26,8 @@ package unirest; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.concurrent.FutureCallback; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; @@ -34,6 +36,8 @@ import org.apache.http.nio.reactor.IOReactorException; import java.util.Objects; +import java.util.concurrent.CompletableFuture; +import java.util.function.Function; import java.util.stream.Stream; import static unirest.Util.tryCast; @@ -86,6 +90,35 @@ public ApacheAsyncClient(HttpAsyncClient client, this.manager = manager; } + @Override + public CompletableFuture> request( + HttpRequest request, + Function> transformer, + CompletableFuture> callback) { + + Objects.requireNonNull(callback); + + HttpUriRequest requestObj = new RequestPrep(request, true).prepare(); + + client.execute(requestObj, new FutureCallback() { + @Override + public void completed(org.apache.http.HttpResponse httpResponse) { + callback.complete(transformer.apply(new ApacheResponse(httpResponse))); + } + + @Override + public void failed(Exception e) { + callback.completeExceptionally(e); + } + + @Override + public void cancelled() { + callback.completeExceptionally(new UnirestException("canceled")); + } + }); + return callback; + } + @Override public boolean isRunning() { return tryCast(client, CloseableHttpAsyncClient.class) diff --git a/src/main/java/unirest/AsyncClient.java b/src/main/java/unirest/AsyncClient.java index 986ad1cf4..e2bf8f991 100644 --- a/src/main/java/unirest/AsyncClient.java +++ b/src/main/java/unirest/AsyncClient.java @@ -28,14 +28,38 @@ import org.apache.http.nio.client.HttpAsyncClient; +import java.util.concurrent.CompletableFuture; +import java.util.function.Function; import java.util.stream.Stream; public interface AsyncClient { + /** + * @return the apache HttpAsyncClient. + * @deprecated Eventually the apache implementation will be hidden and other implementation wi be available + */ + @Deprecated HttpAsyncClient getClient(); + + /** + * Make a Async request + * @param request the prepared request object + * @param transformer the function to transform the response + * @param callback the CompletableFuture that will handle the eventual response + * @return a CompletableFuture of a response + */ + CompletableFuture> request(HttpRequest request, Function> transformer, CompletableFuture> callback); + + /** + * @return a stream of exceptions possibly thrown while closing all the things. + */ default Stream close() { return Stream.empty(); } - default boolean isRunning(){ + + /** + * @return is the client running? + */ + default boolean isRunning() { return true; } } diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index f139d2356..444188b9e 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -27,8 +27,6 @@ package unirest; import org.apache.http.HttpHeaders; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.concurrent.FutureCallback; import java.io.File; import java.io.InputStream; @@ -130,12 +128,14 @@ public HttpResponse asString() throws UnirestException { @Override public CompletableFuture> asStringAsync() { - return requestAsync(StringResponse::new, new CompletableFuture<>()); + + return config.getAsyncClient().request(this, StringResponse::new, new CompletableFuture<>()); } @Override public CompletableFuture> asStringAsync(Callback callback) { - return requestAsync(StringResponse::new, CallbackFuture.wrap(callback)); + + return config.getAsyncClient().request(this, StringResponse::new, CallbackFuture.wrap(callback)); } @Override @@ -145,12 +145,14 @@ public HttpResponse asJson() throws UnirestException { @Override public CompletableFuture> asJsonAsync() { - return requestAsync(JsonResponse::new, new CompletableFuture<>()); + + return config.getAsyncClient().request(this, JsonResponse::new, new CompletableFuture<>()); } @Override public CompletableFuture> asJsonAsync(Callback callback) { - return requestAsync(JsonResponse::new, CallbackFuture.wrap(callback)); + + return config.getAsyncClient().request(this, JsonResponse::new, CallbackFuture.wrap(callback)); } @Override @@ -170,27 +172,32 @@ public HttpResponse asObject(Function function) { @Override public CompletableFuture> asObjectAsync(Function function) { - return requestAsync(funcResponse(function), new CompletableFuture<>()); + + return config.getAsyncClient().request(this, funcResponse(function), new CompletableFuture<>()); } @Override public CompletableFuture> asObjectAsync(Class responseClass) { - return requestAsync(r -> new ObjectResponse(getObjectMapper(), r, responseClass), new CompletableFuture<>()); + + return config.getAsyncClient().request(this, r -> new ObjectResponse(getObjectMapper(), r, responseClass), new CompletableFuture<>()); } @Override public CompletableFuture> asObjectAsync(Class responseClass, Callback callback) { - return requestAsync(r -> new ObjectResponse<>(getObjectMapper(), r, responseClass), CallbackFuture.wrap(callback)); + + return config.getAsyncClient().request(this, r -> new ObjectResponse<>(getObjectMapper(), r, responseClass), CallbackFuture.wrap(callback)); } @Override public CompletableFuture> asObjectAsync(GenericType genericType) { - return requestAsync(r -> new ObjectResponse<>(getObjectMapper(), r, genericType), new CompletableFuture<>()); + + return config.getAsyncClient().request(this, r -> new ObjectResponse<>(getObjectMapper(), r, genericType), new CompletableFuture<>()); } @Override public CompletableFuture> asObjectAsync(GenericType genericType, Callback callback) { - return requestAsync(r -> new ObjectResponse<>(getObjectMapper(), r, genericType), CallbackFuture.wrap(callback)); + + return config.getAsyncClient().request(this, r -> new ObjectResponse<>(getObjectMapper(), r, genericType), CallbackFuture.wrap(callback)); } private Function> funcResponse(Function function) { @@ -204,12 +211,14 @@ public HttpResponse asBinary() throws UnirestException { @Override public CompletableFuture> asBinaryAsync() { - return requestAsync(BinaryResponse::new, new CompletableFuture<>()); + + return config.getAsyncClient().request(this, BinaryResponse::new, new CompletableFuture<>()); } @Override public CompletableFuture> asBinaryAsync(Callback callback) { - return requestAsync(BinaryResponse::new, CallbackFuture.wrap(callback)); + + return config.getAsyncClient().request(this, BinaryResponse::new, CallbackFuture.wrap(callback)); } @Override @@ -219,7 +228,7 @@ public void thenConsume(Consumer consumer) { @Override public void thenConsumeAsync(Consumer consumer) { - requestAsync(getConsumer(consumer), new CompletableFuture<>()); + config.getAsyncClient().request(this, getConsumer(consumer), new CompletableFuture<>()); } @Override @@ -229,12 +238,12 @@ public HttpResponse asFile(String path) { @Override public CompletableFuture> asFileAsync(String path) { - return requestAsync(r -> new FileResponse(r, path), new CompletableFuture<>()); + return config.getAsyncClient().request(this, r -> new FileResponse(r, path), new CompletableFuture<>()); } @Override public CompletableFuture> asFileAsync(String path, Callback callback) { - return requestAsync(r -> new FileResponse(r, path), CallbackFuture.wrap(callback)); + return config.getAsyncClient().request(this, r -> new FileResponse(r, path), CallbackFuture.wrap(callback)); } private Function> getConsumer(Consumer consumer) { @@ -244,35 +253,6 @@ private Function> getConsumer(Consumer CompletableFuture> requestAsync( - Function> transformer, - CompletableFuture> callback) { - - Objects.requireNonNull(callback); - - HttpUriRequest requestObj = new RequestPrep(this, true).prepare(); - - config.getAsyncHttpClient() - .execute(requestObj, new FutureCallback() { - @Override - public void completed(org.apache.http.HttpResponse httpResponse) { - callback.complete(transformer.apply(new ApacheResponse(httpResponse))); - } - - @Override - public void failed(Exception e) { - callback.completeExceptionally(e); - } - - @Override - public void cancelled() { - callback.completeExceptionally(new UnirestException("canceled")); - } - }); - return callback; - } - - @Override public HttpMethod getHttpMethod() { return method; diff --git a/src/main/java/unirest/Client.java b/src/main/java/unirest/Client.java index f40d4afed..5b285ba6a 100644 --- a/src/main/java/unirest/Client.java +++ b/src/main/java/unirest/Client.java @@ -32,7 +32,22 @@ import java.util.stream.Stream; public interface Client { + /** + * @return the apache HttpClient. + * @deprecated Eventually the apache implementation will be hidden and other implementation wi be available + */ HttpClient getClient(); - Stream close(); + + /** + * Make a request + * @param request the prepared request object + * @param transformer the function to transform the response + * @return a HttpResponse with a transformed body + */ HttpResponse request(HttpRequest request, Function> transformer); + + /** + * @return a stream of exceptions possibly thrown while closing all the things. + */ + Stream close(); } diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java index ef0761ead..85dfcd223 100644 --- a/src/main/java/unirest/Config.java +++ b/src/main/java/unirest/Config.java @@ -409,11 +409,11 @@ private synchronized void buildClient() { * * @return Apache HttpAsyncClient */ - public HttpAsyncClient getAsyncHttpClient() { + public AsyncClient getAsyncClient() { if (!asyncClientIsReady()) { buildAsyncClient(); } - return asyncClient.get().getClient(); + return asyncClient.get(); } private boolean asyncClientIsReady() { diff --git a/src/test/java/BehaviorTests/DefectTest.java b/src/test/java/BehaviorTests/DefectTest.java index 133a3046b..20c2a1079 100644 --- a/src/test/java/BehaviorTests/DefectTest.java +++ b/src/test/java/BehaviorTests/DefectTest.java @@ -73,19 +73,19 @@ public void nullAndObjectValuesInMap() { public void issue_41_IllegalThreadStateExceptionUnderHighLoad() throws IOException { Unirest.get(MockServer.GET).asStringAsync(); - HttpAsyncClient first = Unirest.config().getAsyncHttpClient(); + HttpAsyncClient first = Unirest.config().getAsyncClient().getClient(); IntStream.range(1, 50).forEach(i ->{ - assertSame(first, Unirest.config().getAsyncHttpClient()); + assertSame(first, Unirest.config().getAsyncClient().getClient()); }); - ((CloseableHttpAsyncClient)Unirest.config().getAsyncHttpClient()).close(); + ((CloseableHttpAsyncClient)Unirest.config().getAsyncClient().getClient()).close(); Unirest.get(MockServer.GET).asStringAsync(); - HttpAsyncClient second = Unirest.config().getAsyncHttpClient(); + HttpAsyncClient second = Unirest.config().getAsyncClient().getClient(); assertNotSame(first, second); IntStream.range(1, 50).forEach(i ->{ - assertSame(second, Unirest.config().getAsyncHttpClient()); + assertSame(second, Unirest.config().getAsyncClient().getClient()); }); } diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index e07923edb..b10d4f656 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -188,7 +188,7 @@ public void shouldReuseThreadPool() { int startingCount = ManagementFactory.getThreadMXBean().getThreadCount(); IntStream.range(0,100).forEach(i -> { Unirest.config().reset().getClient(); - Unirest.config().getAsyncHttpClient(); + Unirest.config().getAsyncClient(); }); assertThat(ManagementFactory.getThreadMXBean().getThreadCount(), is(lessThan(startingCount + 10))); } diff --git a/src/test/java/unirest/ClientFactoryTest.java b/src/test/java/unirest/ClientFactoryTest.java index cdec84235..305400287 100644 --- a/src/test/java/unirest/ClientFactoryTest.java +++ b/src/test/java/unirest/ClientFactoryTest.java @@ -65,7 +65,7 @@ public void canSaveSomeOptions(){ Unirest.shutDown(false); - assertNotEquals(c, Unirest.config().getAsyncHttpClient()); + assertNotEquals(c, Unirest.config().getAsyncClient()); assertEquals(i, Unirest.config().getInterceptors().get(0)); assertEquals(4000, Unirest.config().getConnectionTimeout()); } diff --git a/src/test/java/unirest/ConfigTest.java b/src/test/java/unirest/ConfigTest.java index 9b3370fd3..8b2ca9b6b 100644 --- a/src/test/java/unirest/ConfigTest.java +++ b/src/test/java/unirest/ConfigTest.java @@ -83,13 +83,13 @@ public void willNotRebuildIfNotClosableAsyncClient() { HttpAsyncClient c = mock(HttpAsyncClient.class); config.asyncClient(c); - assertSame(c, config.getAsyncHttpClient()); - assertSame(c, config.getAsyncHttpClient()); + assertSame(c, config.getAsyncClient().getClient()); + assertSame(c, config.getAsyncClient().getClient()); } @Test public void willRebuildIfEmpty() { - assertSame(config.getAsyncHttpClient(), config.getAsyncHttpClient()); + assertSame(config.getAsyncClient(), config.getAsyncClient()); } @Test @@ -99,7 +99,7 @@ public void willRebuildIfClosableAndStopped() { config.asyncClient(c); - assertNotSame(c, config.getAsyncHttpClient()); + assertNotSame(c, config.getAsyncClient()); } @Test @@ -109,7 +109,7 @@ public void ifTheNextAsyncClientThatIsReturnedIsAlsoOffThrowAnException(){ config.asyncClient(g -> c); - TestUtil.assertException(() -> config.getAsyncHttpClient(), + TestUtil.assertException(() -> config.getAsyncClient(), UnirestConfigException.class, "Attempted to get a new async client but it was not started. Please ensure it is"); } @@ -121,6 +121,6 @@ public void willNotRebuildIfRunning() { config.asyncClient(c); - assertSame(c, config.getAsyncHttpClient()); + assertSame(c, config.getAsyncClient().getClient()); } } \ No newline at end of file From 551f22f355bf139266f921ffdb28f4d640be8088 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 12 Jan 2019 08:01:03 -0600 Subject: [PATCH 0403/1769] because the client interface changed slightly but in a breaking way, bump the minor --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 22c788197..3226e2388 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.2.07-SNAPSHOT + 3.3.00-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ From 027b40d33766a395b00761ff2f00e66939c1ae60 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 12 Jan 2019 08:02:10 -0600 Subject: [PATCH 0404/1769] add unicode test --- src/test/java/BehaviorTests/AsStringTest.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/test/java/BehaviorTests/AsStringTest.java b/src/test/java/BehaviorTests/AsStringTest.java index dc2dc4977..72c23d7ef 100644 --- a/src/test/java/BehaviorTests/AsStringTest.java +++ b/src/test/java/BehaviorTests/AsStringTest.java @@ -26,11 +26,10 @@ package BehaviorTests; -import unirest.HttpResponse; -import unirest.JsonNode; -import unirest.Unirest; import org.junit.Test; +import unirest.HttpResponse; import unirest.TestUtil; +import unirest.Unirest; import java.util.concurrent.CompletableFuture; @@ -100,4 +99,11 @@ public void canGetBinaryResponseAsyncWithCallback() { assertAsync(); } + + @Test + public void unicodeResponse() { + MockServer.setStringResponse("ěščřžýáíé"); + + assertEquals("ěščřžýáíé", Unirest.get(MockServer.GET).asString().getBody()); + } } From 09b52eabf9edbb8ce7362beb7285a37defa0038a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 12 Jan 2019 09:20:15 -0600 Subject: [PATCH 0405/1769] string test async --- src/test/java/BehaviorTests/AsStringTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/java/BehaviorTests/AsStringTest.java b/src/test/java/BehaviorTests/AsStringTest.java index 72c23d7ef..d7f099073 100644 --- a/src/test/java/BehaviorTests/AsStringTest.java +++ b/src/test/java/BehaviorTests/AsStringTest.java @@ -106,4 +106,11 @@ public void unicodeResponse() { assertEquals("ěščřžýáíé", Unirest.get(MockServer.GET).asString().getBody()); } + + @Test + public void unicodeResponseAsync() throws Exception { + MockServer.setStringResponse("ěščřžýáíé"); + + assertEquals("ěščřžýáíé", Unirest.get(MockServer.GET).asStringAsync().get().getBody()); + } } From 28f0edd3af2fbd8749bcfe4f0d68fd4c6814f7eb Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 12 Jan 2019 09:22:37 -0600 Subject: [PATCH 0406/1769] do it with a callback --- src/test/java/BehaviorTests/AsStringTest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/test/java/BehaviorTests/AsStringTest.java b/src/test/java/BehaviorTests/AsStringTest.java index d7f099073..67f5419ed 100644 --- a/src/test/java/BehaviorTests/AsStringTest.java +++ b/src/test/java/BehaviorTests/AsStringTest.java @@ -111,6 +111,12 @@ public void unicodeResponse() { public void unicodeResponseAsync() throws Exception { MockServer.setStringResponse("ěščřžýáíé"); - assertEquals("ěščřžýáíé", Unirest.get(MockServer.GET).asStringAsync().get().getBody()); + Unirest.get(MockServer.GET) + .asStringAsync(r -> { + assertEquals("ěščřžýáíé", r.getBody()); + asyncSuccess(); + }); + + assertAsync(); } } From 6f74569bc22e9d878eb7f37dc87a632b6e12ba96 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 13 Jan 2019 08:26:18 -0600 Subject: [PATCH 0407/1769] closes #59 adds ability to override the expected encoding on a per request basis and also allows for changing the default expected encoding from UTF-8 --- src/main/java/unirest/ApacheAsyncClient.java | 20 +-- src/main/java/unirest/ApacheClient.java | 20 ++- src/main/java/unirest/ApacheResponse.java | 19 ++- src/main/java/unirest/BaseRequest.java | 13 +- src/main/java/unirest/Config.java | 14 ++- src/main/java/unirest/HttpRequest.java | 7 ++ src/main/java/unirest/RawResponse.java | 1 + ...esponseUtils.java => RawResponseBase.java} | 16 ++- src/main/java/unirest/StringResponse.java | 4 +- src/main/java/unirest/Util.java | 4 + src/test/java/BehaviorTests/AsStringTest.java | 21 ++++ .../java/BehaviorTests/LifeCycleTest.java | 60 --------- src/test/java/BehaviorTests/MockServer.java | 16 +-- src/test/java/unirest/ConfigTest.java | 83 ++++++++++++- src/test/java/unirest/ResponseUtilsTest.java | 115 +++++++++++++++--- src/test/resources/data/cp1250.txt | 1 + 16 files changed, 295 insertions(+), 119 deletions(-) rename src/main/java/unirest/{ResponseUtils.java => RawResponseBase.java} (85%) create mode 100644 src/test/resources/data/cp1250.txt diff --git a/src/main/java/unirest/ApacheAsyncClient.java b/src/main/java/unirest/ApacheAsyncClient.java index b9046f4fa..bdeb62d5e 100644 --- a/src/main/java/unirest/ApacheAsyncClient.java +++ b/src/main/java/unirest/ApacheAsyncClient.java @@ -42,13 +42,15 @@ import static unirest.Util.tryCast; -public class ApacheAsyncClient extends BaseApacheClient implements AsyncClient { +class ApacheAsyncClient extends BaseApacheClient implements AsyncClient { private final HttpAsyncClient client; - private final PoolingNHttpClientConnectionManager manager; private final AsyncIdleConnectionMonitorThread syncMonitor; + private final PoolingNHttpClientConnectionManager manager; + private Config config; - public ApacheAsyncClient(Config config) { + ApacheAsyncClient(Config config) { + this.config = config; try { manager = new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor()); manager.setMaxTotal(config.getMaxConnections()); @@ -81,12 +83,14 @@ public ApacheAsyncClient(Config config) { } } - public ApacheAsyncClient(HttpAsyncClient client, - PoolingNHttpClientConnectionManager manager, - AsyncIdleConnectionMonitorThread syncMonitor) { - this.syncMonitor = syncMonitor; + ApacheAsyncClient(HttpAsyncClient client, + Config config, + PoolingNHttpClientConnectionManager manager, + AsyncIdleConnectionMonitorThread monitor) { Objects.requireNonNull(client, "Client may not be null"); + this.config = config; this.client = client; + this.syncMonitor = monitor; this.manager = manager; } @@ -103,7 +107,7 @@ public CompletableFuture> request( client.execute(requestObj, new FutureCallback() { @Override public void completed(org.apache.http.HttpResponse httpResponse) { - callback.complete(transformer.apply(new ApacheResponse(httpResponse))); + callback.complete(transformer.apply(new ApacheResponse(httpResponse, config))); } @Override diff --git a/src/main/java/unirest/ApacheClient.java b/src/main/java/unirest/ApacheClient.java index 066fa200f..edf86d3eb 100644 --- a/src/main/java/unirest/ApacheClient.java +++ b/src/main/java/unirest/ApacheClient.java @@ -37,12 +37,14 @@ import java.util.function.Function; import java.util.stream.Stream; -public class ApacheClient extends BaseApacheClient implements Client { +class ApacheClient extends BaseApacheClient implements Client { private final HttpClient client; + private final Config config; private final PoolingHttpClientConnectionManager manager; private final SyncIdleConnectionMonitorThread syncMonitor; - public ApacheClient(Config config) { + ApacheClient(Config config) { + this.config = config; manager = new PoolingHttpClientConnectionManager(); syncMonitor = new SyncIdleConnectionMonitorThread(manager); syncMonitor.start(); @@ -66,20 +68,14 @@ public ApacheClient(Config config) { client = cb.build(); } - public ApacheClient(HttpClient httpClient) { + ApacheClient(HttpClient httpClient, Config config, PoolingHttpClientConnectionManager clientManager, SyncIdleConnectionMonitorThread connMonitor) { this.client = httpClient; - this.manager = null; - this.syncMonitor = null; - } - - public ApacheClient(HttpClient httpc, - PoolingHttpClientConnectionManager clientManager, - SyncIdleConnectionMonitorThread connMonitor) { - this.client = httpc; + this.config = config; this.manager = clientManager; this.syncMonitor = connMonitor; } + @Override public HttpResponse request(HttpRequest request, Function> transformer) { @@ -87,7 +83,7 @@ public HttpResponse request(HttpRequest request, Function httpResponse = transformer.apply(new ApacheResponse(execute)); + HttpResponse httpResponse = transformer.apply(new ApacheResponse(execute, config)); requestObj.releaseConnection(); return httpResponse; } catch (Exception e) { diff --git a/src/main/java/unirest/ApacheResponse.java b/src/main/java/unirest/ApacheResponse.java index 181a4f2ae..b781a32fe 100644 --- a/src/main/java/unirest/ApacheResponse.java +++ b/src/main/java/unirest/ApacheResponse.java @@ -35,10 +35,11 @@ import java.util.stream.Stream; import java.util.zip.GZIPInputStream; -class ApacheResponse implements RawResponse { +class ApacheResponse extends RawResponseBase { private final HttpResponse r; - public ApacheResponse(HttpResponse r){ + public ApacheResponse(HttpResponse r, Config config){ + super(config); this.r = r; } @@ -93,17 +94,29 @@ public byte[] getContentAsBytes() { @Override public String getContentAsString() { + return getContentAsString(null); + } + + @Override + public String getContentAsString(String charset) { if(!hasContent()){ return ""; } try { - String charSet = ResponseUtils.getCharSet(this); + String charSet = getCharset(charset); return new String(getContentAsBytes(), charSet); } catch (IOException e) { throw new UnirestException(e); } } + private String getCharset(String charset) { + if(Util.isNullOrEmpty(charset)){ + return getCharSet(); + } + return charset; + } + @Override public InputStreamReader getContentReader(){ return new InputStreamReader(getContent()); diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 444188b9e..b29a7ce1d 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -38,6 +38,7 @@ abstract class BaseRequest implements HttpRequest { private Optional objectMapper = Optional.empty(); + private String responseEncoding; protected Headers headers = new Headers(); protected final Config config; protected HttpMethod method; @@ -74,6 +75,12 @@ public R accept(String value) { return header(HttpHeaders.ACCEPT, value); } + @Override + public R responseEncoding(String encoding) { + this.responseEncoding = encoding; + return (R)this; + } + @Override public R header(String name, String value) { this.headers.add(name.trim(), value); @@ -123,19 +130,19 @@ public R withObjectMapper(ObjectMapper mapper) { @Override public HttpResponse asString() throws UnirestException { - return config.getClient().request(this, StringResponse::new); + return config.getClient().request(this, r -> new StringResponse(r, responseEncoding)); } @Override public CompletableFuture> asStringAsync() { - return config.getAsyncClient().request(this, StringResponse::new, new CompletableFuture<>()); + return config.getAsyncClient().request(this, r -> new StringResponse(r, responseEncoding), new CompletableFuture<>()); } @Override public CompletableFuture> asStringAsync(Callback callback) { - return config.getAsyncClient().request(this, StringResponse::new, CallbackFuture.wrap(callback)); + return config.getAsyncClient().request(this, r -> new StringResponse(r, responseEncoding), CallbackFuture.wrap(callback)); } @Override diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java index 85dfcd223..3a3317966 100644 --- a/src/main/java/unirest/Config.java +++ b/src/main/java/unirest/Config.java @@ -35,6 +35,7 @@ import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.nio.client.HttpAsyncClient; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -65,6 +66,7 @@ public class Config { private boolean followRedirects; private boolean cookieManagement; private boolean useSystemProperties; + private String defaultResponseEncoding = StandardCharsets.UTF_8.name(); private Function asyncBuilder = ApacheAsyncClient::new; private Function clientBuilder = ApacheClient::new; @@ -91,7 +93,7 @@ private void setDefaults(){ * @return this config object */ public Config httpClient(HttpClient httpClient) { - client = Optional.of(new ApacheClient(httpClient)); + client = Optional.of(new ApacheClient(httpClient, this, null, null)); return this; } @@ -124,7 +126,7 @@ public Config httpClient(Function httpClient) { * @return this config object */ public Config asyncClient(HttpAsyncClient value) { - this.asyncClient = Optional.of(new ApacheAsyncClient(value, null, null)); + this.asyncClient = Optional.of(new ApacheAsyncClient(value, this, null, null)); return this; } @@ -491,4 +493,12 @@ CredentialsProvider getProxyCreds(){ boolean useSystemProperties(){ return this.useSystemProperties; } + + public void setDefaultResponseEncoding(String value) { + this.defaultResponseEncoding = value; + } + + public String getDefaultResponseEncoding() { + return defaultResponseEncoding; + } } diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index e92a72cf7..ba14a30fb 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -63,6 +63,13 @@ public interface HttpRequest { */ R accept(String value); + /** + * The encoding to expect the response to be for cases where the server fails to respond with the proper encoding + * @param encoding a valid mime type for the Accept header + * @return this request builder + */ + R responseEncoding(String encoding); + /** * Add a http header, HTTP supports multiple of the same header. This will continue to append new values * @param name name of the header diff --git a/src/main/java/unirest/RawResponse.java b/src/main/java/unirest/RawResponse.java index b0d9cebe8..b36132e24 100644 --- a/src/main/java/unirest/RawResponse.java +++ b/src/main/java/unirest/RawResponse.java @@ -36,6 +36,7 @@ public interface RawResponse { InputStream getContent(); byte[] getContentAsBytes(); String getContentAsString(); + String getContentAsString(String charset); InputStreamReader getContentReader(); boolean hasContent(); String getContentType(); diff --git a/src/main/java/unirest/ResponseUtils.java b/src/main/java/unirest/RawResponseBase.java similarity index 85% rename from src/main/java/unirest/ResponseUtils.java rename to src/main/java/unirest/RawResponseBase.java index b4b71db7a..c6ff15f1c 100644 --- a/src/main/java/unirest/ResponseUtils.java +++ b/src/main/java/unirest/RawResponseBase.java @@ -29,17 +29,22 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -class ResponseUtils { +abstract class RawResponseBase implements RawResponse { private static final Pattern CHARSET_PATTERN = Pattern.compile("(?i)\\bcharset=\\s*\"?([^\\s;\"]*)"); + protected Config config; - static String getCharSet(RawResponse responseEntity) { - String contentType = responseEntity.getContentType(); + protected RawResponseBase(Config config){ + this.config = config; + } + + protected String getCharSet() { + String contentType = getContentType(); String responseCharset = getCharsetFromContentType(contentType); if (responseCharset != null && !responseCharset.trim().equals("")) { return responseCharset; } - return "UTF-8"; + return config.getDefaultResponseEncoding(); } /** @@ -48,7 +53,7 @@ static String getCharSet(RawResponse responseEntity) { * @param contentType e.g. "text/html; charset=EUC-JP" * @return "EUC-JP", or null if not found. Charset is trimmed and uppercased. */ - private static String getCharsetFromContentType(String contentType) { + private String getCharsetFromContentType(String contentType) { if (contentType == null) { return null; } @@ -59,4 +64,5 @@ private static String getCharsetFromContentType(String contentType) { } return null; } + } diff --git a/src/main/java/unirest/StringResponse.java b/src/main/java/unirest/StringResponse.java index b6205ee23..30f964ce0 100644 --- a/src/main/java/unirest/StringResponse.java +++ b/src/main/java/unirest/StringResponse.java @@ -33,9 +33,9 @@ public class StringResponse extends BaseResponse { private String body; - public StringResponse(RawResponse response) { + public StringResponse(RawResponse response, String encoding) { super(response); - body = response.getContentAsString(); + body = response.getContentAsString(encoding); } @Override diff --git a/src/main/java/unirest/Util.java b/src/main/java/unirest/Util.java index 977063c13..4fe231fac 100644 --- a/src/main/java/unirest/Util.java +++ b/src/main/java/unirest/Util.java @@ -92,6 +92,10 @@ public static InputStream emptyStream() { return new ByteArrayInputStream(new byte[0]); } + public static boolean isNullOrEmpty(String s) { + return s == null || s.trim().isEmpty(); + } + @FunctionalInterface public interface ExConsumer{ diff --git a/src/test/java/BehaviorTests/AsStringTest.java b/src/test/java/BehaviorTests/AsStringTest.java index 67f5419ed..edf7c9d38 100644 --- a/src/test/java/BehaviorTests/AsStringTest.java +++ b/src/test/java/BehaviorTests/AsStringTest.java @@ -26,11 +26,13 @@ package BehaviorTests; +import org.apache.commons.codec.binary.Hex; import org.junit.Test; import unirest.HttpResponse; import unirest.TestUtil; import unirest.Unirest; +import java.nio.charset.StandardCharsets; import java.util.concurrent.CompletableFuture; import static org.junit.Assert.assertEquals; @@ -119,4 +121,23 @@ public void unicodeResponseAsync() throws Exception { assertAsync(); } + + @Test + public void canSetExpectedCharsetOfResponse() { + HttpResponse s = Unirest.get(MockServer.WINDOWS_LATIN_1_FILE) + .responseEncoding("windows-1250") + .asString(); + + assertEquals("šžýáíé", s.getBody()); + } + + @Test + public void canSetDefaultCharsetOfResponse() { + Unirest.config().setDefaultResponseEncoding("windows-1250"); + + HttpResponse s = Unirest.get(MockServer.WINDOWS_LATIN_1_FILE) + .asString(); + + assertEquals("šžýáíé", s.getBody()); + } } diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/src/test/java/BehaviorTests/LifeCycleTest.java index b10d4f656..c202e2513 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/src/test/java/BehaviorTests/LifeCycleTest.java @@ -83,66 +83,6 @@ public void settingClientAfterClientHasAlreadyBeenSet() { assertEquals("Howdy Ho!", result.getBody()); } - @Test - public void testShutdown() throws IOException { - when(asyncClient.isRunning()).thenReturn(true); - - Unirest.config() - .httpClient(new ApacheClient(httpc, clientManager, connMonitor)) - .asyncClient(new ApacheAsyncClient(asyncClient, manager, asyncMonitor)); - - Unirest.shutDown(); - - verify(httpc).close(); - verify(clientManager).close(); - verify(connMonitor).interrupt(); - verify(asyncClient).close(); - verify(asyncMonitor).interrupt(); - } - - @Test - public void willPowerThroughErrors() throws IOException { - when(asyncClient.isRunning()).thenReturn(true); - doThrow(new IOException("1")).when(httpc).close(); - doThrow(new RuntimeException("2")).when(clientManager).close(); - doThrow(new RuntimeException("3")).when(connMonitor).interrupt(); - doThrow(new IOException("4")).when(asyncClient).close(); - doThrow(new RuntimeException("5")).when(asyncMonitor).interrupt(); - - Unirest.config() - .httpClient(new ApacheClient(httpc, clientManager, connMonitor)) - .asyncClient(new ApacheAsyncClient(asyncClient, manager, asyncMonitor)); - - - TestUtil.assertException(Unirest::shutDown, - UnirestException.class, - "java.io.IOException 1\n" + - "java.lang.RuntimeException 2\n" + - "java.lang.RuntimeException 3\n" + - "java.io.IOException 4\n" + - "java.lang.RuntimeException 5"); - - verify(httpc).close(); - verify(clientManager).close(); - verify(connMonitor).interrupt(); - verify(asyncClient).close(); - verify(asyncMonitor).interrupt(); - } - - @Test - public void doesNotBombOnNullOptions() throws IOException { - when(asyncClient.isRunning()).thenReturn(true); - - Unirest.config() - .httpClient(new ApacheClient(httpc, null, null)) - .asyncClient(new ApacheAsyncClient(asyncClient, null, null)); - - Unirest.shutDown(); - - verify(httpc).close(); - verify(asyncClient).close(); - } - @Test public void willNotShutdownInactiveAsyncClient() throws IOException { CloseableHttpAsyncClient asyncClient = mock(CloseableHttpAsyncClient.class); diff --git a/src/test/java/BehaviorTests/MockServer.java b/src/test/java/BehaviorTests/MockServer.java index db0697a9d..06a238a2a 100644 --- a/src/test/java/BehaviorTests/MockServer.java +++ b/src/test/java/BehaviorTests/MockServer.java @@ -76,6 +76,7 @@ public class MockServer { private static Object responseBody; public static final int PORT = 4567; public static final String HOST = "http://localhost:" + PORT; + public static final String WINDOWS_LATIN_1_FILE = HOST + "data/cp1250.txt"; public static final String REDIRECT = HOST + "/redirect"; public static final String BINARYFILE = HOST + "/binary"; public static final String NOBODY = HOST + "/nobody"; @@ -101,15 +102,16 @@ public static void reset(){ static { port(PORT); + Spark.staticFileLocation("data"); delete("/delete", MockServer::jsonResponse); post("/post", MockServer::jsonResponse); - get("/get", MockServer::jsonResponse); - get("/gzip", MockServer::gzipResponse); - get("/redirect", MockServer::redirect); - patch("/patch", MockServer::jsonResponse); - get("/invalid", MockServer::inValid); - options("/get", MockServer::jsonResponse); - get("/nobody", MockServer::nobody); + get("/get", MockServer::jsonResponse); + get("/gzip", MockServer::gzipResponse); + get("/redirect", MockServer::redirect); + patch("/patch", MockServer::jsonResponse); + get("/invalid", MockServer::inValid); + options("/get", MockServer::jsonResponse); + get("/nobody", MockServer::nobody); head("/get", MockServer::jsonResponse); put("/post", MockServer::jsonResponse); get("/get/:p/passed", MockServer::jsonResponse); diff --git a/src/test/java/unirest/ConfigTest.java b/src/test/java/unirest/ConfigTest.java index 8b2ca9b6b..94ad29d56 100644 --- a/src/test/java/unirest/ConfigTest.java +++ b/src/test/java/unirest/ConfigTest.java @@ -27,20 +27,39 @@ package unirest; import org.apache.http.client.HttpClient; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; +import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; import org.apache.http.nio.client.HttpAsyncClient; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; +import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import java.io.IOException; + import static org.junit.Assert.*; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; +import static org.mockito.Mockito.doThrow; @RunWith(MockitoJUnitRunner.class) public class ConfigTest { + @Mock + private CloseableHttpClient httpc; + @Mock + private PoolingHttpClientConnectionManager clientManager; + @Mock + private SyncIdleConnectionMonitorThread connMonitor; + @Mock + private CloseableHttpAsyncClient asyncClient; + @Mock + private AsyncIdleConnectionMonitorThread asyncMonitor; + @Mock + private PoolingNHttpClientConnectionManager manager; + @InjectMocks private Config config; @@ -102,6 +121,66 @@ public void willRebuildIfClosableAndStopped() { assertNotSame(c, config.getAsyncClient()); } + @Test + public void testShutdown() throws IOException { + when(asyncClient.isRunning()).thenReturn(true); + + Unirest.config() + .httpClient(new ApacheClient(httpc, null, clientManager, connMonitor)) + .asyncClient(new ApacheAsyncClient(asyncClient, null, manager, asyncMonitor)); + + Unirest.shutDown(); + + verify(httpc).close(); + verify(clientManager).close(); + verify(connMonitor).interrupt(); + verify(asyncClient).close(); + verify(asyncMonitor).interrupt(); + } + + @Test + public void willPowerThroughErrors() throws IOException { + when(asyncClient.isRunning()).thenReturn(true); + doThrow(new IOException("1")).when(httpc).close(); + doThrow(new RuntimeException("2")).when(clientManager).close(); + doThrow(new RuntimeException("3")).when(connMonitor).interrupt(); + doThrow(new IOException("4")).when(asyncClient).close(); + doThrow(new RuntimeException("5")).when(asyncMonitor).interrupt(); + + Unirest.config() + .httpClient(new ApacheClient(httpc, null, clientManager, connMonitor)) + .asyncClient(new ApacheAsyncClient(asyncClient,null, manager, asyncMonitor)); + + + TestUtil.assertException(Unirest::shutDown, + UnirestException.class, + "java.io.IOException 1\n" + + "java.lang.RuntimeException 2\n" + + "java.lang.RuntimeException 3\n" + + "java.io.IOException 4\n" + + "java.lang.RuntimeException 5"); + + verify(httpc).close(); + verify(clientManager).close(); + verify(connMonitor).interrupt(); + verify(asyncClient).close(); + verify(asyncMonitor).interrupt(); + } + + @Test + public void doesNotBombOnNullOptions() throws IOException { + when(asyncClient.isRunning()).thenReturn(true); + + Unirest.config() + .httpClient(new ApacheClient(httpc, null, null, null)) + .asyncClient(new ApacheAsyncClient(asyncClient, null, null, null)); + + Unirest.shutDown(); + + verify(httpc).close(); + verify(asyncClient).close(); + } + @Test public void ifTheNextAsyncClientThatIsReturnedIsAlsoOffThrowAnException(){ AsyncClient c = mock(AsyncClient.class); diff --git a/src/test/java/unirest/ResponseUtilsTest.java b/src/test/java/unirest/ResponseUtilsTest.java index 53dc8a818..605458ba7 100644 --- a/src/test/java/unirest/ResponseUtilsTest.java +++ b/src/test/java/unirest/ResponseUtilsTest.java @@ -26,35 +26,120 @@ package unirest; -import org.apache.http.HttpEntity; -import org.apache.http.entity.BasicHttpEntity; import org.junit.Test; -import unirest.ResponseUtils; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; -import static org.junit.Assert.*; +import java.io.InputStream; +import java.io.InputStreamReader; + +import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +@RunWith(MockitoJUnitRunner.class) public class ResponseUtilsTest { + @Mock + private Config config; + @InjectMocks + TestResponse test; @Test public void getCharsetDefaults() { - assertEquals("UTF-8", ResponseUtils.getCharSet(entity(null))); - assertEquals("UTF-8", ResponseUtils.getCharSet(entity(""))); - assertEquals("UTF-8", ResponseUtils.getCharSet(entity(" "))); - assertEquals("UTF-8", ResponseUtils.getCharSet(mock(RawResponse.class))); - assertEquals("UTF-8", ResponseUtils.getCharSet(entity("Content-Type: text/html;"))); - assertEquals("UTF-8", ResponseUtils.getCharSet(entity("Content-Type: text/html; charset="))); + defaultEncoding("UTF-8"); + + assertEquals("UTF-8", getCharSet(null)); + assertEquals("UTF-8", getCharSet("")); + assertEquals("UTF-8", getCharSet(" ")); + assertEquals("UTF-8", getCharSet("Content-Type: text/html;")); + assertEquals("UTF-8", getCharSet("Content-Type: text/html; charset=")); } @Test public void contentTypeWhenYouGotIt() { - assertEquals("LATIN-1", ResponseUtils.getCharSet(entity("Content-Type: text/html; charset=latin-1"))); + assertEquals("LATIN-1", getCharSet("Content-Type: text/html; charset=latin-1")); + } + + @Test + public void changeTheDefault() { + defaultEncoding("KINGON-1"); + assertEquals("KINGON-1", getCharSet(null)); + defaultEncoding("SINDARIN-42"); + assertEquals("SINDARIN-42", getCharSet(null)); } - private RawResponse entity(String charset) { - RawResponse r = mock(RawResponse.class); - when(r.getContentType()).thenReturn(charset); - return r; + private void defaultEncoding(String t) { + when(config.getDefaultResponseEncoding()).thenReturn(t); + } + + private String getCharSet(String content) { + test.type = content; + return test.getCharSet(); + } + + public static class TestResponse extends RawResponseBase { + + public String type; + + protected TestResponse(Config config) { + super(config); + } + + @Override + public int getStatus() { + return 0; + } + + @Override + public String getStatusText() { + return null; + } + + @Override + public Headers getHeaders() { + return null; + } + + @Override + public InputStream getContent() { + return null; + } + + @Override + public byte[] getContentAsBytes() { + return new byte[0]; + } + + @Override + public String getContentAsString() { + return null; + } + + @Override + public String getContentAsString(String charset) { + return null; + } + + @Override + public InputStreamReader getContentReader() { + return null; + } + + @Override + public boolean hasContent() { + return false; + } + + @Override + public String getContentType() { + return type; + } + + @Override + public String getEncoding() { + return null; + } } } \ No newline at end of file diff --git a/src/test/resources/data/cp1250.txt b/src/test/resources/data/cp1250.txt new file mode 100644 index 000000000..36be2aa8b --- /dev/null +++ b/src/test/resources/data/cp1250.txt @@ -0,0 +1 @@ +šžýáíé \ No newline at end of file From cf2d6bc23b033215ad48e137e1b1f16c55bf2681 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 13 Jan 2019 08:47:36 -0600 Subject: [PATCH 0408/1769] update changelog --- CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45b43577e..75762e161 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,20 @@ +## 3.3.00 +* Slight breaking change with regard to accessing Apache specific classes via the config + * getClient and getAsyncClient return the Unirest containers for clients. You can still get to the Apache client through that for now but this is also deprecated. Eventually Unirest will make Apache just one of several modules. + * Apache client wrappers are now package local. +* Add support for overriding the default expected encoding both on a per-request basis and as a default int he config. +```java +// Changing the default from UTF-8 for all requests +// Unirest will still honor content-encoding if defined in the response headers +Unirest.config().setDefaultResponseEncoding("windows-1250"); + +// Changing the default on a request. +// This will explicitly be used EVEN IF the headers define something else. +Unirest.get("http://some.file.with.windows.encoding/file.txt") + .responseEncoding("windows-1250") + .asString(); +``` + ## 3.2.06 * access headers in order From b183af44dc610b77fc48f28a324caae64c4087c2 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 13 Jan 2019 08:48:43 -0600 Subject: [PATCH 0409/1769] [maven-release-plugin] prepare release v3.3.00 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3226e2388..77e782950 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.3.00-SNAPSHOT + 3.3.00 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.3.00 From a4dc257452204161dc084e83933413d803942d7a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 13 Jan 2019 08:48:51 -0600 Subject: [PATCH 0410/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 77e782950..54be921b1 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.3.00 + 3.3.01-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.3.00 + HEAD From bd4cc00d875d52898e6de2ffe27f07705d43b9e8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 13 Jan 2019 12:39:13 -0600 Subject: [PATCH 0411/1769] introduce a const class of headers --- src/main/java/unirest/BaseRequest.java | 4 +- src/main/java/unirest/HeaderNames.java | 204 +++++++++++++++++++++++++ 2 files changed, 205 insertions(+), 3 deletions(-) create mode 100644 src/main/java/unirest/HeaderNames.java diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index b29a7ce1d..727ca197b 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -26,8 +26,6 @@ package unirest; -import org.apache.http.HttpHeaders; - import java.io.File; import java.io.InputStream; import java.util.*; @@ -72,7 +70,7 @@ public R basicAuth(String username, String password) { @Override public R accept(String value) { - return header(HttpHeaders.ACCEPT, value); + return header(HeaderNames.ACCEPT, value); } @Override diff --git a/src/main/java/unirest/HeaderNames.java b/src/main/java/unirest/HeaderNames.java new file mode 100644 index 000000000..567c2b7ae --- /dev/null +++ b/src/main/java/unirest/HeaderNames.java @@ -0,0 +1,204 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +/** + * Constants enumerating the HTTP headers. All headers defined in RFC1945 (HTTP/1.0), RFC2616 (HTTP/1.1), and RFC2518 + * (WebDAV) are listed. + * + * @since 4.1 + */ +public class HeaderNames { + + private HeaderNames(){} + + /** RFC 2616 (HTTP/1.1) Section 14.1 */ + public static final String ACCEPT = "Accept"; + + /** RFC 2616 (HTTP/1.1) Section 14.2 */ + public static final String ACCEPT_CHARSET = "Accept-Charset"; + + /** RFC 2616 (HTTP/1.1) Section 14.3 */ + public static final String ACCEPT_ENCODING = "Accept-Encoding"; + + /** RFC 2616 (HTTP/1.1) Section 14.4 */ + public static final String ACCEPT_LANGUAGE = "Accept-Language"; + + /** RFC 2616 (HTTP/1.1) Section 14.5 */ + public static final String ACCEPT_RANGES = "Accept-Ranges"; + + /** RFC 2616 (HTTP/1.1) Section 14.6 */ + public static final String AGE = "Age"; + + /** RFC 1945 (HTTP/1.0) Section 10.1, RFC 2616 (HTTP/1.1) Section 14.7 */ + public static final String ALLOW = "Allow"; + + /** RFC 1945 (HTTP/1.0) Section 10.2, RFC 2616 (HTTP/1.1) Section 14.8 */ + public static final String AUTHORIZATION = "Authorization"; + + /** RFC 2616 (HTTP/1.1) Section 14.9 */ + public static final String CACHE_CONTROL = "Cache-Control"; + + /** RFC 2616 (HTTP/1.1) Section 14.10 */ + public static final String CONNECTION = "Connection"; + + /** RFC 1945 (HTTP/1.0) Section 10.3, RFC 2616 (HTTP/1.1) Section 14.11 */ + public static final String CONTENT_ENCODING = "Content-Encoding"; + + /** RFC 2616 (HTTP/1.1) Section 14.12 */ + public static final String CONTENT_LANGUAGE = "Content-Language"; + + /** RFC 1945 (HTTP/1.0) Section 10.4, RFC 2616 (HTTP/1.1) Section 14.13 */ + public static final String CONTENT_LENGTH = "Content-Length"; + + /** RFC 2616 (HTTP/1.1) Section 14.14 */ + public static final String CONTENT_LOCATION = "Content-Location"; + + /** RFC 2616 (HTTP/1.1) Section 14.15 */ + public static final String CONTENT_MD5 = "Content-MD5"; + + /** RFC 2616 (HTTP/1.1) Section 14.16 */ + public static final String CONTENT_RANGE = "Content-Range"; + + /** RFC 1945 (HTTP/1.0) Section 10.5, RFC 2616 (HTTP/1.1) Section 14.17 */ + public static final String CONTENT_TYPE = "Content-Type"; + + /** RFC 1945 (HTTP/1.0) Section 10.6, RFC 2616 (HTTP/1.1) Section 14.18 */ + public static final String DATE = "Date"; + + /** RFC 2518 (WevDAV) Section 9.1 */ + public static final String DAV = "Dav"; + + /** RFC 2518 (WevDAV) Section 9.2 */ + public static final String DEPTH = "Depth"; + + /** RFC 2518 (WevDAV) Section 9.3 */ + public static final String DESTINATION = "Destination"; + + /** RFC 2616 (HTTP/1.1) Section 14.19 */ + public static final String ETAG = "ETag"; + + /** RFC 2616 (HTTP/1.1) Section 14.20 */ + public static final String EXPECT = "Expect"; + + /** RFC 1945 (HTTP/1.0) Section 10.7, RFC 2616 (HTTP/1.1) Section 14.21 */ + public static final String EXPIRES = "Expires"; + + /** RFC 1945 (HTTP/1.0) Section 10.8, RFC 2616 (HTTP/1.1) Section 14.22 */ + public static final String FROM = "From"; + + /** RFC 2616 (HTTP/1.1) Section 14.23 */ + public static final String HOST = "Host"; + + /** RFC 2518 (WevDAV) Section 9.4 */ + public static final String IF = "If"; + + /** RFC 2616 (HTTP/1.1) Section 14.24 */ + public static final String IF_MATCH = "If-Match"; + + /** RFC 1945 (HTTP/1.0) Section 10.9, RFC 2616 (HTTP/1.1) Section 14.25 */ + public static final String IF_MODIFIED_SINCE = "If-Modified-Since"; + + /** RFC 2616 (HTTP/1.1) Section 14.26 */ + public static final String IF_NONE_MATCH = "If-None-Match"; + + /** RFC 2616 (HTTP/1.1) Section 14.27 */ + public static final String IF_RANGE = "If-Range"; + + /** RFC 2616 (HTTP/1.1) Section 14.28 */ + public static final String IF_UNMODIFIED_SINCE = "If-Unmodified-Since"; + + /** RFC 1945 (HTTP/1.0) Section 10.10, RFC 2616 (HTTP/1.1) Section 14.29 */ + public static final String LAST_MODIFIED = "Last-Modified"; + + /** RFC 1945 (HTTP/1.0) Section 10.11, RFC 2616 (HTTP/1.1) Section 14.30 */ + public static final String LOCATION = "Location"; + + /** RFC 2518 (WevDAV) Section 9.5 */ + public static final String LOCK_TOKEN = "Lock-Token"; + + /** RFC 2616 (HTTP/1.1) Section 14.31 */ + public static final String MAX_FORWARDS = "Max-Forwards"; + + /** RFC 2518 (WevDAV) Section 9.6 */ + public static final String OVERWRITE = "Overwrite"; + + /** RFC 1945 (HTTP/1.0) Section 10.12, RFC 2616 (HTTP/1.1) Section 14.32 */ + public static final String PRAGMA = "Pragma"; + + /** RFC 2616 (HTTP/1.1) Section 14.33 */ + public static final String PROXY_AUTHENTICATE = "Proxy-Authenticate"; + + /** RFC 2616 (HTTP/1.1) Section 14.34 */ + public static final String PROXY_AUTHORIZATION = "Proxy-Authorization"; + + /** RFC 2616 (HTTP/1.1) Section 14.35 */ + public static final String RANGE = "Range"; + + /** RFC 1945 (HTTP/1.0) Section 10.13, RFC 2616 (HTTP/1.1) Section 14.36 */ + public static final String REFERER = "Referer"; + + /** RFC 2616 (HTTP/1.1) Section 14.37 */ + public static final String RETRY_AFTER = "Retry-After"; + + /** RFC 1945 (HTTP/1.0) Section 10.14, RFC 2616 (HTTP/1.1) Section 14.38 */ + public static final String SERVER = "Server"; + + /** RFC 2518 (WevDAV) Section 9.7 */ + public static final String STATUS_URI = "Status-URI"; + + /** RFC 2616 (HTTP/1.1) Section 14.39 */ + public static final String TE = "TE"; + + /** RFC 2518 (WevDAV) Section 9.8 */ + public static final String TIMEOUT = "Timeout"; + + /** RFC 2616 (HTTP/1.1) Section 14.40 */ + public static final String TRAILER = "Trailer"; + + /** RFC 2616 (HTTP/1.1) Section 14.41 */ + public static final String TRANSFER_ENCODING = "Transfer-Encoding"; + + /** RFC 2616 (HTTP/1.1) Section 14.42 */ + public static final String UPGRADE = "Upgrade"; + + /** RFC 1945 (HTTP/1.0) Section 10.15, RFC 2616 (HTTP/1.1) Section 14.43 */ + public static final String USER_AGENT = "User-Agent"; + + /** RFC 2616 (HTTP/1.1) Section 14.44 */ + public static final String VARY = "Vary"; + + /** RFC 2616 (HTTP/1.1) Section 14.45 */ + public static final String VIA = "Via"; + + /** RFC 2616 (HTTP/1.1) Section 14.46 */ + public static final String WARNING = "Warning"; + + /** RFC 1945 (HTTP/1.0) Section 10.16, RFC 2616 (HTTP/1.1) Section 14.47 */ + public static final String WWW_AUTHENTICATE = "WWW-Authenticate"; + +} From 80612044a08660da5bbe2b979d2e7c37ac583ad3 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 13 Jan 2019 13:02:04 -0600 Subject: [PATCH 0412/1769] add some more docs --- src/main/java/unirest/AsyncClient.java | 1 + src/main/java/unirest/Client.java | 1 + src/main/java/unirest/Headers.java | 7 +- src/main/java/unirest/MultipartBody.java | 105 ++++++++++++++++++++++- 4 files changed, 108 insertions(+), 6 deletions(-) diff --git a/src/main/java/unirest/AsyncClient.java b/src/main/java/unirest/AsyncClient.java index e2bf8f991..b0b135d06 100644 --- a/src/main/java/unirest/AsyncClient.java +++ b/src/main/java/unirest/AsyncClient.java @@ -42,6 +42,7 @@ public interface AsyncClient { /** * Make a Async request + * @param The type of the body * @param request the prepared request object * @param transformer the function to transform the response * @param callback the CompletableFuture that will handle the eventual response diff --git a/src/main/java/unirest/Client.java b/src/main/java/unirest/Client.java index 5b285ba6a..b1724f75a 100644 --- a/src/main/java/unirest/Client.java +++ b/src/main/java/unirest/Client.java @@ -40,6 +40,7 @@ public interface Client { /** * Make a request + * @param The type of the body * @param request the prepared request object * @param transformer the function to transform the response * @return a HttpResponse with a transformed body diff --git a/src/main/java/unirest/Headers.java b/src/main/java/unirest/Headers.java index efb425d82..8f0fbd121 100644 --- a/src/main/java/unirest/Headers.java +++ b/src/main/java/unirest/Headers.java @@ -111,10 +111,11 @@ public void putAll(Headers header) { /** * Check if a header is present - * @param key a header + * @param name a header + * @return if the headers contain this name. */ - public boolean containsKey(String key) { - return this.headers.stream().anyMatch(h -> isName(h, key)); + public boolean containsKey(String name) { + return this.headers.stream().anyMatch(h -> isName(h, name)); } /** diff --git a/src/main/java/unirest/MultipartBody.java b/src/main/java/unirest/MultipartBody.java index 739695e44..d0f58e122 100644 --- a/src/main/java/unirest/MultipartBody.java +++ b/src/main/java/unirest/MultipartBody.java @@ -34,35 +34,134 @@ import java.nio.charset.Charset; import java.util.Collection; +/** + * Represents a multi-part body builder for a request. + */ public interface MultipartBody extends HttpRequest, Body { + /** + * add a simple field with a name and value + * @param name: the Name of the form field + * @param value: The string value for the field + * @return The same MultipartBody + */ MultipartBody field(String name, String value); + /** + * add a simple field with a name and value + * @param name: the Name of the form field + * @param value: The string value for the field + * @param contentType: the content type of the value + * @return The same MultipartBody + */ MultipartBody field(String name, String value, String contentType); - MultipartBody field(String name, Collection collection); - + /** + * add a simple field with a name and value + * @param name: the Name of the form field + * @param values: A collection of values for the same name. + * @return The same MultipartBody + */ + MultipartBody field(String name, Collection values); + + /** + * add a simple field with a name and value + * @param name: the Name of the form field + * @param file: A File object. + * @return The same MultipartBody + */ MultipartBody field(String name, File file); + /** + * add a simple field with a name and value + * @param name: the Name of the form field + * @param file: A File object. + * @param contentType: the content mime-type of the file + * @return The same MultipartBody + */ MultipartBody field(String name, File file, String contentType); - @Deprecated // In version 4 Apache classes will be abstracted out + /** + * add a simple field with a name and value + * @param name: the Name of the form field + * @param value: A input stream + * @param contentType: the content mime-type of the file + * @deprecated org.apache.http.entity.ContentType will be replaced by a Unirest owned class that behaves similarly + * @return The same MultipartBody + */ + @Deprecated MultipartBody field(String name, InputStream value, ContentType contentType); + /** + * add a simple field with a name and value + * @param name: the Name of the form field + * @param stream: A input stream + * @param contentType: the content mime-type of the file + * @param fileName: the name of the file which will be included in the file part header + * @deprecated org.apache.http.entity.ContentType will be replaced by a Unirest owned class that behaves similarly + * @return The same MultipartBody + */ @Deprecated // In version 4 Apache classes will be abstracted out MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName); + /** + * add a simple field with a name and value + * @param name: the Name of the form field + * @param bytes: The raw bytes for the file + * @param contentType: the content mime-type of the file + * @param fileName: the name of the file which will be included in the file part header + * @deprecated org.apache.http.entity.ContentType will be replaced by a Unirest owned class that behaves similarly + * @return The same MultipartBody + */ @Deprecated // In version 4 Apache classes will be abstracted out MultipartBody field(String name, byte[] bytes, ContentType contentType, String fileName); + /** + * add a simple field with a name and value + * @param name: the Name of the form field + * @param stream: The raw bytes for the file + * @param fileName: the name of the file which will be included in the file part header + * @return The same MultipartBody + */ MultipartBody field(String name, InputStream stream, String fileName); + /** + * add a simple field with a name and value + * @param name: the Name of the form field + * @param bytes: The raw bytes for the file + * @param fileName: the name of the file which will be included in the file part header + * @return The same MultipartBody + */ MultipartBody field(String name, byte[] bytes, String fileName); + /** + * Set the encoding of the request body + * @param charset the character set encoding of the body + * @return The same MultipartBody + */ MultipartBody charset(Charset charset); + /** + * Set the mime-type of the request body + * @param mimeType the mime type of the body + * @return The same MultipartBody + */ MultipartBody contentType(String mimeType); + /** + * Set the Apache Mode. + * @param value the string value of the mode + * @return The same MultipartBody + * @deprecated Apache will be made a module in the future. + * */ + @Deprecated MultipartBody mode(String value); + /** + * Set the Apache Mode. + * @param value the value of the mode + * @return The same MultipartBody + * @deprecated Apache will be made a module in the future. + * */ + @Deprecated MultipartBody mode(HttpMultipartMode value); } From f9bd08530f95418bf16e9c484e0aa95a5d704131 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 13 Jan 2019 13:02:40 -0600 Subject: [PATCH 0413/1769] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 918b49794..d736d56bf 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This repo is an updated, maintained, and independent fork of the original Mashap io.github.openunirest open-unirest-java - 3.2.06 + 3.3.00 ``` From 132dfc82d99ffd736d84e0183ef063e469207976 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 13 Jan 2019 13:09:58 -0600 Subject: [PATCH 0414/1769] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d736d56bf..d3781eefc 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![Build Status](https://travis-ci.org/OpenUnirest/unirest-java.svg?branch=master)](https://travis-ci.org/OpenUnirest/unirest-java) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.openunirest/open-unirest-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.openunirest/open-unirest-java) [![DepShield Badge](https://depshield.sonatype.org/badges/OpenUnirest/unirest-java/depshield.svg)](https://depshield.github.io) +[![Javadocs](http://www.javadoc.io/badge/io.github.openunirest/open-unirest-java.svg)](http://www.javadoc.io/doc/io.github.openunirest/open-unirest-java) ## About This Repository This repo is an updated, maintained, and independent fork of the original Mashape/Kong Unirest-Java project. That project is no longer being maintained so this project was set up to keep it alive. From 1c0f54fa4ad59a7565e93968f5f4fb72770acf7e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 13 Jan 2019 14:50:23 -0600 Subject: [PATCH 0415/1769] inline code in test --- src/test/java/BehaviorTests/AsStringTest.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/test/java/BehaviorTests/AsStringTest.java b/src/test/java/BehaviorTests/AsStringTest.java index edf7c9d38..fcb89fc4b 100644 --- a/src/test/java/BehaviorTests/AsStringTest.java +++ b/src/test/java/BehaviorTests/AsStringTest.java @@ -26,13 +26,11 @@ package BehaviorTests; -import org.apache.commons.codec.binary.Hex; import org.junit.Test; import unirest.HttpResponse; import unirest.TestUtil; import unirest.Unirest; -import java.nio.charset.StandardCharsets; import java.util.concurrent.CompletableFuture; import static org.junit.Assert.assertEquals; @@ -124,20 +122,16 @@ public void unicodeResponseAsync() throws Exception { @Test public void canSetExpectedCharsetOfResponse() { - HttpResponse s = Unirest.get(MockServer.WINDOWS_LATIN_1_FILE) + assertEquals("šžýáíé", Unirest.get(MockServer.WINDOWS_LATIN_1_FILE) .responseEncoding("windows-1250") - .asString(); - - assertEquals("šžýáíé", s.getBody()); + .asString().getBody()); } @Test public void canSetDefaultCharsetOfResponse() { Unirest.config().setDefaultResponseEncoding("windows-1250"); - HttpResponse s = Unirest.get(MockServer.WINDOWS_LATIN_1_FILE) - .asString(); - - assertEquals("šžýáíé", s.getBody()); + assertEquals("šžýáíé", Unirest.get(MockServer.WINDOWS_LATIN_1_FILE) + .asString().getBody()); } } From 90ac2ea4df9b2dc47ad3dcb1761d683e3e966bef Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 13 Jan 2019 14:53:46 -0600 Subject: [PATCH 0416/1769] do not allow nulls in the default encoding --- src/main/java/unirest/Config.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java index 3a3317966..ed607407c 100644 --- a/src/main/java/unirest/Config.java +++ b/src/main/java/unirest/Config.java @@ -38,6 +38,7 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.function.Function; import java.util.function.Supplier; @@ -495,6 +496,7 @@ boolean useSystemProperties(){ } public void setDefaultResponseEncoding(String value) { + Objects.requireNonNull(value, "Encoding cannot be null"); this.defaultResponseEncoding = value; } From d4113b8abe0a8b51926c2176c5ce0051eec74cd8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 13 Jan 2019 14:57:13 -0600 Subject: [PATCH 0417/1769] make the setter for default encoding follow the builder pattern --- src/main/java/unirest/Config.java | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/unirest/Config.java b/src/main/java/unirest/Config.java index ed607407c..1ddd6eb03 100644 --- a/src/main/java/unirest/Config.java +++ b/src/main/java/unirest/Config.java @@ -335,6 +335,19 @@ public Config useSystemProperties(boolean value) { return this; } + /** + * Set the default encoding that will be used for serialization into Strings. + * The default-default is UTF-8 + * + * @param value a bool is its true or not. + * @return this config object + */ + public Config setDefaultResponseEncoding(String value) { + Objects.requireNonNull(value, "Encoding cannot be null"); + this.defaultResponseEncoding = value; + return this; + } + /** * Return default headers that are added to every request * @@ -495,12 +508,7 @@ boolean useSystemProperties(){ return this.useSystemProperties; } - public void setDefaultResponseEncoding(String value) { - Objects.requireNonNull(value, "Encoding cannot be null"); - this.defaultResponseEncoding = value; - } - - public String getDefaultResponseEncoding() { + String getDefaultResponseEncoding() { return defaultResponseEncoding; } } From b4f297fedc7c9d16a95830756bae31411e1a6003 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 13 Jan 2019 17:25:39 -0600 Subject: [PATCH 0418/1769] make HttpMethod a object rather than a enum so we can support 'weird' verbs --- src/main/java/unirest/HttpMethod.java | 41 ++++++++++++++++++- .../java/unirest/JacksonObjectMapper.java | 21 ++++++++-- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/main/java/unirest/HttpMethod.java b/src/main/java/unirest/HttpMethod.java index bb0a769f4..316d177d5 100644 --- a/src/main/java/unirest/HttpMethod.java +++ b/src/main/java/unirest/HttpMethod.java @@ -26,6 +26,43 @@ package unirest; -public enum HttpMethod { - GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class HttpMethod { + private static final Map REGISTRY = new HashMap<>(); + + public static final HttpMethod GET = valueOf("GET"); + public static final HttpMethod POST = valueOf("POST"); + public static final HttpMethod PUT = valueOf("PUT"); + public static final HttpMethod DELETE = valueOf("DELETE"); + public static final HttpMethod PATCH = valueOf("PATCH"); + public static final HttpMethod HEAD = valueOf("HEAD"); + public static final HttpMethod OPTIONS = valueOf("OPTIONS"); + public static final HttpMethod TRACE = valueOf("TRACE"); + + private final String name; + + private HttpMethod(String name){ + this.name = name; + } + + public static HttpMethod valueOf(String verb){ + return REGISTRY.computeIfAbsent(verb, HttpMethod::new); + } + + public Set all(){ + return new HashSet<>(REGISTRY.values()); + } + + public String name() { + return name; + } + + @Override + public String toString() { + return name; + } } diff --git a/src/test/java/unirest/JacksonObjectMapper.java b/src/test/java/unirest/JacksonObjectMapper.java index 1af6ae434..2195b9623 100644 --- a/src/test/java/unirest/JacksonObjectMapper.java +++ b/src/test/java/unirest/JacksonObjectMapper.java @@ -35,11 +35,7 @@ import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.datatype.guava.GuavaModule; -import unirest.GenericType; -import unirest.JsonPatch; -import unirest.JsonPatchItem; import org.json.JSONObject; -import unirest.ObjectMapper; import java.io.File; import java.io.IOException; @@ -56,6 +52,8 @@ public JacksonObjectMapper(){ simpleModule.addSerializer(JsonPatch.class, new JsonPatchSerializer()); simpleModule.addDeserializer(JsonPatchItem.class, new PatchDeserializer()); simpleModule.addDeserializer(JsonPatch.class, new JsonPatchDeSerializer()); + simpleModule.addSerializer(HttpMethod.class, new HttpMethodSerializer()); + simpleModule.addDeserializer(HttpMethod.class, new HttpMethodDeSerializer()); om.registerModule(simpleModule); } @@ -131,4 +129,19 @@ public JsonPatchItem deserialize(JsonParser jsonParser, DeserializationContext d return new JsonPatchItem(new JSONObject(s)); } } + + public static class HttpMethodSerializer extends JsonSerializer { + @Override + public void serialize(HttpMethod httpMethod, JsonGenerator jgen, SerializerProvider serializerProvider) throws IOException { + jgen.writeString(httpMethod.name()); + } + } + + public static class HttpMethodDeSerializer extends JsonDeserializer { + @Override + public HttpMethod deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { + String s = jsonParser.readValueAs(String.class); + return HttpMethod.valueOf(s); + } + } } From 1a0ebb9e3bf01f909e3723c92d6141a6134da4fb Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 14 Jan 2019 07:02:45 -0600 Subject: [PATCH 0419/1769] working on issue #56. Supporting weird verbs. todo: figure out how body should be handled? --- .../java/unirest/ApacheRequestWithBody.java | 44 +++++++++++++++++++ src/main/java/unirest/RequestPrep.java | 6 ++- src/main/java/unirest/Unirest.java | 4 ++ src/main/java/unirest/UnirestInstance.java | 6 ++- src/test/java/BehaviorTests/MockServer.java | 4 +- .../java/BehaviorTests/RequestCapture.java | 4 ++ src/test/java/BehaviorTests/VerbTest.java | 9 ++++ 7 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 src/main/java/unirest/ApacheRequestWithBody.java diff --git a/src/main/java/unirest/ApacheRequestWithBody.java b/src/main/java/unirest/ApacheRequestWithBody.java new file mode 100644 index 000000000..9bf40f8dd --- /dev/null +++ b/src/main/java/unirest/ApacheRequestWithBody.java @@ -0,0 +1,44 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; + +import java.net.URI; + +public class ApacheRequestWithBody extends HttpEntityEnclosingRequestBase { + private HttpMethod method; + + public ApacheRequestWithBody(HttpMethod method, String uri){ + this.method = method; + setURI(URI.create(uri)); + } + @Override + public String getMethod() { + return method.name(); + } +} diff --git a/src/main/java/unirest/RequestPrep.java b/src/main/java/unirest/RequestPrep.java index b10270574..cc4747d55 100644 --- a/src/main/java/unirest/RequestPrep.java +++ b/src/main/java/unirest/RequestPrep.java @@ -82,7 +82,8 @@ private HttpRequestBase getHttpRequestBase() { } try { - HttpRequestBase reqObj = FACTORIES.get(request.getHttpMethod()).apply(request.getUrl()); + String url = request.getUrl(); + HttpRequestBase reqObj = FACTORIES.computeIfAbsent(request.getHttpMethod(), this::register).apply(url); request.getHeaders().all().stream().map(this::toEntries).forEach(reqObj::addHeader); return reqObj; }catch (RuntimeException e){ @@ -90,6 +91,9 @@ private HttpRequestBase getHttpRequestBase() { } } + private Function register(HttpMethod method) { + return u -> new ApacheRequestWithBody(method, u); + } private Header toEntries(unirest.Header k) { return new BasicHeader(k.getName(), k.getValue()); diff --git a/src/main/java/unirest/Unirest.java b/src/main/java/unirest/Unirest.java index 22f6509cb..e72f5a9ea 100644 --- a/src/main/java/unirest/Unirest.java +++ b/src/main/java/unirest/Unirest.java @@ -127,6 +127,10 @@ public static JsonPatchRequest jsonPatch(String url) { return primaryInstance.jsonPatch(url); } + public static HttpRequestWithBody request(String method, String url) { + return primaryInstance.request(method, url); + } + /** * Does the config have currently running clients? Find out here. * diff --git a/src/main/java/unirest/UnirestInstance.java b/src/main/java/unirest/UnirestInstance.java index deab6c174..ad6d9eb0f 100644 --- a/src/main/java/unirest/UnirestInstance.java +++ b/src/main/java/unirest/UnirestInstance.java @@ -131,6 +131,10 @@ public JsonPatchRequest jsonPatch(String url) { return new HttpRequestJsonPatch(config, url); } + public HttpRequestWithBody request(String method, String url) { + return new HttpRequestBody(config, HttpMethod.valueOf(method), url); + } + /** * Does the config have currently running clients? Find out here. * @@ -139,7 +143,7 @@ public JsonPatchRequest jsonPatch(String url) { public boolean isRunning() { return config.isRunning(); } - + /** * Wraps shutdown and will automatically be called when UnirestInstance is * used with try-with-resource. This will alleviate the need to manually diff --git a/src/test/java/BehaviorTests/MockServer.java b/src/test/java/BehaviorTests/MockServer.java index 06a238a2a..6cac93bfe 100644 --- a/src/test/java/BehaviorTests/MockServer.java +++ b/src/test/java/BehaviorTests/MockServer.java @@ -73,7 +73,7 @@ public class MockServer { private static final List> responseHeaders = new ArrayList<>(); private static final JacksonObjectMapper om = new JacksonObjectMapper(); - private static Object responseBody; + private static Object responseBody; public static final int PORT = 4567; public static final String HOST = "http://localhost:" + PORT; public static final String WINDOWS_LATIN_1_FILE = HOST + "data/cp1250.txt"; @@ -88,6 +88,7 @@ public class MockServer { public static final String PATCH = HOST + "/patch"; public static final String INVALID_REQUEST = HOST + "/invalid"; public static final String PASSED_PATH_PARAM = GET + "/{param}/passed"; + public static final String CHEESE = HOST + "/cheese"; public static final String ALTGET = "http://127.0.0.1:" + PORT + "/get"; @@ -103,6 +104,7 @@ public static void reset(){ static { port(PORT); Spark.staticFileLocation("data"); + Spark.notFound(MockServer::jsonResponse); delete("/delete", MockServer::jsonResponse); post("/post", MockServer::jsonResponse); get("/get", MockServer::jsonResponse); diff --git a/src/test/java/BehaviorTests/RequestCapture.java b/src/test/java/BehaviorTests/RequestCapture.java index d8883cc22..678e8c0d0 100644 --- a/src/test/java/BehaviorTests/RequestCapture.java +++ b/src/test/java/BehaviorTests/RequestCapture.java @@ -243,6 +243,10 @@ public RequestCapture assertHeaderSize(String foo, int size) { return this; } + public void assertBody(String o) { + assertEquals(o, body); + } + public static class File { public String fileName; public String type; diff --git a/src/test/java/BehaviorTests/VerbTest.java b/src/test/java/BehaviorTests/VerbTest.java index 0fea2fe50..7a64946a4 100644 --- a/src/test/java/BehaviorTests/VerbTest.java +++ b/src/test/java/BehaviorTests/VerbTest.java @@ -83,4 +83,13 @@ public void option() { .getBody() .asserMethod(HttpMethod.OPTIONS); } + + @Test + public void weirdVerbs() { + Unirest.request("CHEESE", MockServer.CHEESE) + .asObject(RequestCapture.class) + .getBody() + .asserMethod(HttpMethod.valueOf("CHEESE")) + .assertBody(null); + } } From 1ac319be8da1c8c8939d888b5dbe68271b1fb44f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 14 Jan 2019 07:03:41 -0600 Subject: [PATCH 0420/1769] fix test --- src/test/java/BehaviorTests/VerbTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/BehaviorTests/VerbTest.java b/src/test/java/BehaviorTests/VerbTest.java index 7a64946a4..acbc26778 100644 --- a/src/test/java/BehaviorTests/VerbTest.java +++ b/src/test/java/BehaviorTests/VerbTest.java @@ -90,6 +90,6 @@ public void weirdVerbs() { .asObject(RequestCapture.class) .getBody() .asserMethod(HttpMethod.valueOf("CHEESE")) - .assertBody(null); + .assertBody(""); } } From 31584794b2c2b7a27a72de12171c32a9ca61f1a9 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 14 Jan 2019 20:59:00 -0600 Subject: [PATCH 0421/1769] test refactoring --- src/test/java/BehaviorTests/MockServer.java | 25 +++++++++++++------ .../java/BehaviorTests/RequestCapture.java | 4 +++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/test/java/BehaviorTests/MockServer.java b/src/test/java/BehaviorTests/MockServer.java index 6cac93bfe..d95f9bd7c 100644 --- a/src/test/java/BehaviorTests/MockServer.java +++ b/src/test/java/BehaviorTests/MockServer.java @@ -104,7 +104,7 @@ public static void reset(){ static { port(PORT); Spark.staticFileLocation("data"); - Spark.notFound(MockServer::jsonResponse); + Spark.notFound(MockServer::notFound); delete("/delete", MockServer::jsonResponse); post("/post", MockServer::jsonResponse); get("/get", MockServer::jsonResponse); @@ -127,6 +127,12 @@ public static void reset(){ } } + private static Object notFound(Request req, Response res) { + RequestCapture value = getRequestCapture(req, res); + value.setStatus(404); + return om.writeValue(value); + } + private static Object file(Request request, Response response) throws Exception { File f = TestUtil.rezFile("/image.jpg"); response.raw().setContentType("application/octet-stream"); @@ -161,25 +167,28 @@ private static Object gzipResponse(Request request, Response response) { } private static Object proxiedResponse(Request req, Response res) { - res.cookie("JSESSIONID", "ABC123"); if(responseBody != null){ return responseBody; } - RequestCapture value = new RequestCapture(req); - value.writeBody(req); + RequestCapture value = getRequestCapture(req, res); value.setIsProxied(true); return om.writeValue(value); } private static Object jsonResponse(Request req, Response res) { - res.cookie("JSESSIONID", "ABC123"); - responseHeaders.forEach(h -> res.header(h.key, h.value)); if(responseBody != null){ return responseBody; } - RequestCapture value = new RequestCapture(req); + RequestCapture value = getRequestCapture(req, res); + return om.writeValue(value); + } + + private static RequestCapture getRequestCapture(Request req, Response res) { + res.cookie("JSESSIONID", "ABC123"); + responseHeaders.forEach(h -> res.header(h.key, h.value)); + RequestCapture value = new RequestCapture(req); value.writeBody(req); - return om.writeValue(value); + return value; } public static void shutdown() { diff --git a/src/test/java/BehaviorTests/RequestCapture.java b/src/test/java/BehaviorTests/RequestCapture.java index 678e8c0d0..09453ccdb 100644 --- a/src/test/java/BehaviorTests/RequestCapture.java +++ b/src/test/java/BehaviorTests/RequestCapture.java @@ -247,6 +247,10 @@ public void assertBody(String o) { assertEquals(o, body); } + public void setStatus(int i) { + this.status = i; + } + public static class File { public String fileName; public String type; From 757cdd62f73dd6f13986724c3a9180948ee55321 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 14 Jan 2019 21:31:16 -0600 Subject: [PATCH 0422/1769] update docs --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75762e161..35c77f109 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 3.3.01 +* Add the ability to make requests to non-standard web methods for things like WebDAV, SVN, or other horrible things. +```java + Unirest.request("CHEESE", "http://some.cheesy.thing") + .asString(); +``` + ## 3.3.00 * Slight breaking change with regard to accessing Apache specific classes via the config * getClient and getAsyncClient return the Unirest containers for clients. You can still get to the Apache client through that for now but this is also deprecated. Eventually Unirest will make Apache just one of several modules. From 54706d62b06b149b4d13cfa1cbf4b60f0955af25 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 14 Jan 2019 21:33:24 -0600 Subject: [PATCH 0423/1769] [maven-release-plugin] prepare release v3.3.01 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 54be921b1..074a28b10 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.3.01-SNAPSHOT + 3.3.01 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.3.01 From 4c78f725ca95411135b063209f14c0d31832864a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 14 Jan 2019 21:33:34 -0600 Subject: [PATCH 0424/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 074a28b10..8e6ee1a8e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.3.01 + 3.3.02-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.3.01 + HEAD From 728af9b7594a3d6c755a734fde32e252b3646b05 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 14 Jan 2019 21:38:33 -0600 Subject: [PATCH 0425/1769] [maven-release-plugin] prepare release v3.3.02 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 8e6ee1a8e..687cc84df 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.3.02-SNAPSHOT + 3.3.02 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.3.02 From a80b18566bd9983f504976499d5a0432c9ed084d Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 14 Jan 2019 21:38:49 -0600 Subject: [PATCH 0426/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 687cc84df..6fd33f3bc 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.3.02 + 3.3.03-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.3.02 + HEAD From 9520590169b0056c0981147e1cf4c48fbc2478f6 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 15 Jan 2019 06:38:08 -0600 Subject: [PATCH 0427/1769] docs --- CHANGELOG.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35c77f109..9b1570de9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 3.3.01 +## 3.3.02 * Add the ability to make requests to non-standard web methods for things like WebDAV, SVN, or other horrible things. ```java Unirest.request("CHEESE", "http://some.cheesy.thing") diff --git a/README.md b/README.md index d3781eefc..0c658e54c 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ This repo is an updated, maintained, and independent fork of the original Mashap io.github.openunirest open-unirest-java - 3.3.00 + 3.3.02 ``` From 7d3d67a8e4e762fafdcb9fe21e0c4688f7f2cbc2 Mon Sep 17 00:00:00 2001 From: Clemens Valiente Date: Mon, 21 Jan 2019 15:13:43 +0100 Subject: [PATCH 0428/1769] add isSuccess() method to HttpResponse interface --- src/main/java/unirest/BaseResponse.java | 3 +- src/main/java/unirest/HttpResponse.java | 5 +++ .../PostRequestHandlersTest.java | 31 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/main/java/unirest/BaseResponse.java b/src/main/java/unirest/BaseResponse.java index a900be0cf..1396f4a2d 100644 --- a/src/main/java/unirest/BaseResponse.java +++ b/src/main/java/unirest/BaseResponse.java @@ -100,7 +100,8 @@ public HttpResponse ifFailure(Consumer> consumer) { return this; } - private boolean isSuccess() { + @Override + public boolean isSuccess() { return getStatus() >= 200 && getStatus() < 300 && !getParsingError().isPresent(); } } diff --git a/src/main/java/unirest/HttpResponse.java b/src/main/java/unirest/HttpResponse.java index 18afccca7..75ed78339 100644 --- a/src/main/java/unirest/HttpResponse.java +++ b/src/main/java/unirest/HttpResponse.java @@ -106,4 +106,9 @@ public interface HttpResponse { * @return the same response */ HttpResponse ifFailure(Consumer> consumer); + + /** + * @return true if the response was a 200-series response and no mapping exception happened, else false + */ + boolean isSuccess(); } diff --git a/src/test/java/BehaviorTests/PostRequestHandlersTest.java b/src/test/java/BehaviorTests/PostRequestHandlersTest.java index 5dbbbedd2..10df1becf 100644 --- a/src/test/java/BehaviorTests/PostRequestHandlersTest.java +++ b/src/test/java/BehaviorTests/PostRequestHandlersTest.java @@ -83,4 +83,35 @@ public void itsAFailIfTheMapperFails() { assertTrue(captured.getParsingError().isPresent()); assertEquals("not what you expect", captured.getParsingError().get().getOriginalBody()); } + + + + @Test + public void onSuccessBeSuccessful() { + HttpResponse response = Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asObject(RequestCapture.class); + + assertTrue(response.isSuccess()); + } + + @Test + public void onFailBeUnsuccessful() { + HttpResponse response = Unirest.get(MockServer.INVALID_REQUEST) + .queryString("foo", "bar") + .asObject(RequestCapture.class); + + assertFalse(response.isSuccess()); + } + + @Test + public void beUnsuccessfulIfTheMapperFails() { + MockServer.setStringResponse("not what you expect"); + + HttpResponse response = Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asObject(RequestCapture.class); + + assertFalse(response.isSuccess()); + } } From 4a057c405392b93765730137c87ecd87409fe05e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 21 Jan 2019 15:27:05 -0600 Subject: [PATCH 0429/1769] [maven-release-plugin] prepare release v3.3.03 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 6fd33f3bc..27dc7d17c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.3.03-SNAPSHOT + 3.3.03 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.3.03 From 4dec26f5a435eacb37064d93aa5aafb94410bb8b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 21 Jan 2019 15:27:21 -0600 Subject: [PATCH 0430/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 27dc7d17c..0d99dc275 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.3.03 + 3.3.04-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.3.03 + HEAD From 21eaeeb015405a840977597705e5e4c3e567acd6 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 21 Jan 2019 15:32:44 -0600 Subject: [PATCH 0431/1769] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b1570de9..4feac0d53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 3.3.03 +* Pulled isSuccess() up to the response interface so it can be used and enjoyed by everyone. + ## 3.3.02 * Add the ability to make requests to non-standard web methods for things like WebDAV, SVN, or other horrible things. ```java From 1db8360e1c818fd4311c6c420b0506a0feaef32e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 21 Jan 2019 15:33:15 -0600 Subject: [PATCH 0432/1769] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c658e54c..601102464 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ This repo is an updated, maintained, and independent fork of the original Mashap io.github.openunirest open-unirest-java - 3.3.02 + 3.3.03 ``` From 38601766088e547e929797c5c533735b627da820 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 21 Jan 2019 15:39:13 -0600 Subject: [PATCH 0433/1769] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 000000000..1db1cce22 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,30 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Provide as much of a code sample as possible. Unirest is pretty small so it you should be able to mostly copy-paste into the issue +1. do **NOT** paste authentication or client keys into the issue +1. provide full stack traces if possible + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Environmental Data:** + - Java Version + - Version [e.g. 3.3.03] + +**Additional context** +Add any other context about the problem here. From 6b0e122f5c8521a4a1dd59a1c50ebdb64aa62252 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 21 Jan 2019 15:40:34 -0600 Subject: [PATCH 0434/1769] Update issue templates --- .github/ISSUE_TEMPLATE/feature_request.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 000000000..bbcbbe7d6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. From 0240d47f697bfab492f496727198898561254714 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 21 Jan 2019 15:41:03 -0600 Subject: [PATCH 0435/1769] Update issue templates --- .github/ISSUE_TEMPLATE/custom.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/custom.md diff --git a/.github/ISSUE_TEMPLATE/custom.md b/.github/ISSUE_TEMPLATE/custom.md new file mode 100644 index 000000000..48d5f81fa --- /dev/null +++ b/.github/ISSUE_TEMPLATE/custom.md @@ -0,0 +1,10 @@ +--- +name: Custom issue template +about: Describe this issue template's purpose here. +title: '' +labels: '' +assignees: '' + +--- + + From bf4e031140464930bc05f3a8e2d9f3f02a72d551 Mon Sep 17 00:00:00 2001 From: Marco Palladino Date: Fri, 8 Feb 2019 15:34:02 -0800 Subject: [PATCH 0436/1769] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 437b60779..c16530745 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +# Call for Maintainers + +We are looking for official maintainers, check out issue [#252](https://github.com/Kong/unirest-java/issues/252) + # Unirest for Java [![Build Status][travis-image]][travis-url] ![][unirest-logo] From d0668f7c7d3e563b7280f206eba4c72359c90812 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 10 Feb 2019 08:30:30 -0600 Subject: [PATCH 0437/1769] adding a way to follow paging --- src/main/java/unirest/BaseRequest.java | 15 ++++++ src/main/java/unirest/HttpRequest.java | 3 ++ src/main/java/unirest/PagedList.java | 40 ++++++++++++++ src/test/java/BehaviorTests/MockServer.java | 25 +++++++-- src/test/java/BehaviorTests/PagingTest.java | 49 +++++++++++++++++ src/test/java/unirest/PagedListTest.java | 59 +++++++++++++++++++++ 6 files changed, 187 insertions(+), 4 deletions(-) create mode 100644 src/main/java/unirest/PagedList.java create mode 100644 src/test/java/BehaviorTests/PagingTest.java create mode 100644 src/test/java/unirest/PagedListTest.java diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 727ca197b..2db8766b5 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -251,6 +251,8 @@ public CompletableFuture> asFileAsync(String path, Callback new FileResponse(r, path), CallbackFuture.wrap(callback)); } + + private Function> getConsumer(Consumer consumer) { return r -> { consumer.accept(r); @@ -281,4 +283,17 @@ public Body getBody() { private ObjectMapper getObjectMapper() { return objectMapper.orElseGet(config::getObjectMapper); } + + @Override + public PagedList asPaged(Function, String> linkExtractor, Function mappingFunction) { + PagedList all = new PagedList<>(); + String nextLink = this.getUrl(); + do { + this.url = new Path(nextLink); + HttpResponse next = mappingFunction.apply(this); + all.add(next); + nextLink = linkExtractor.apply(next); + }while (!Util.isNullOrEmpty(nextLink)); + return all; + } } diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index ba14a30fb..d6dc3d8bc 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -281,6 +281,9 @@ public interface HttpRequest { @Deprecated CompletableFuture> asBinaryAsync(Callback callback); + PagedList asPaged(Function, String> linkExtractor, + Function mappingFunction); + /** * Execute the request asynchronously and pass the raw response to a consumer. * This raw response contains the original InputStream and is suitable for diff --git a/src/main/java/unirest/PagedList.java b/src/main/java/unirest/PagedList.java new file mode 100644 index 000000000..da4cea16f --- /dev/null +++ b/src/main/java/unirest/PagedList.java @@ -0,0 +1,40 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class PagedList extends ArrayList> { + + public List getBodies() { + return stream() + .map(HttpResponse::getBody) + .collect(Collectors.toList()); + } +} diff --git a/src/test/java/BehaviorTests/MockServer.java b/src/test/java/BehaviorTests/MockServer.java index d95f9bd7c..9c368d5f0 100644 --- a/src/test/java/BehaviorTests/MockServer.java +++ b/src/test/java/BehaviorTests/MockServer.java @@ -70,16 +70,18 @@ a copy of this software and associated documentation files (the import static spark.Spark.*; public class MockServer { - - private static final List> responseHeaders = new ArrayList<>(); - private static final JacksonObjectMapper om = new JacksonObjectMapper(); - private static Object responseBody; + private static int pages = 1; + private static int onPage = 1; + private static final List> responseHeaders = new ArrayList<>(); + private static final JacksonObjectMapper om = new JacksonObjectMapper(); + private static Object responseBody; public static final int PORT = 4567; public static final String HOST = "http://localhost:" + PORT; public static final String WINDOWS_LATIN_1_FILE = HOST + "data/cp1250.txt"; public static final String REDIRECT = HOST + "/redirect"; public static final String BINARYFILE = HOST + "/binary"; public static final String NOBODY = HOST + "/nobody"; + public static final String PAGED = HOST + "/paged"; public static final String PROXY = "localhost:4567"; public static final String POST = HOST + "/post"; public static final String GET = HOST + "/get"; @@ -99,6 +101,8 @@ public static void setJsonAsResponse(Object o){ public static void reset(){ responseBody = null; responseHeaders.clear(); + pages = 1; + onPage = 1; } static { @@ -119,6 +123,7 @@ public static void reset(){ get("/get/:p/passed", MockServer::jsonResponse); get("/proxy", MockServer::proxiedResponse); get("/binary", MockServer::file); + get("/paged", MockServer::paged); Runtime.getRuntime().addShutdownHook(new Thread(Spark::stop)); try { new CountDownLatch(1).await(2, TimeUnit.SECONDS); @@ -127,6 +132,14 @@ public static void reset(){ } } + private static Object paged(Request request, Response response) { + if(pages > onPage){ + onPage++; + response.header("nextPage", PAGED + "?page=" + onPage); + } + return jsonResponse(request, response); + } + private static Object notFound(Request req, Response res) { RequestCapture value = getRequestCapture(req, res); value.setStatus(404); @@ -202,4 +215,8 @@ public static void setStringResponse(String stringResponse) { public static void addResponseHeader(String key, String value) { responseHeaders.add(new Pair<>(key, value)); } + + public static void expectedPages(int expected) { + pages = expected; + } } diff --git a/src/test/java/BehaviorTests/PagingTest.java b/src/test/java/BehaviorTests/PagingTest.java new file mode 100644 index 000000000..998bbdf3a --- /dev/null +++ b/src/test/java/BehaviorTests/PagingTest.java @@ -0,0 +1,49 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package BehaviorTests; + +import org.junit.Test; +import unirest.PagedList; +import unirest.Unirest; + +import static org.junit.Assert.assertEquals; + +public class PagingTest extends BddTest { + + @Test + public void canFollowPaging() { + MockServer.expectedPages(10); + + PagedList result = Unirest.get(MockServer.PAGED) + .asPaged( + r -> r.getHeaders().getFirst("nextPage"), + r -> r.asObject(RequestCapture.class) + ); + + assertEquals(10, result.size()); + } +} diff --git a/src/test/java/unirest/PagedListTest.java b/src/test/java/unirest/PagedListTest.java new file mode 100644 index 000000000..e793fefd5 --- /dev/null +++ b/src/test/java/unirest/PagedListTest.java @@ -0,0 +1,59 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +import static java.util.Arrays.asList; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class PagedListTest { + + @Test + public void canGetAllTheBodies() { + PagedList list = new PagedList<>(); + list.addAll(asList( + mkRequest("foo"), + mkRequest("bar"), + mkRequest("baz") + )); + + List bodies = list.getBodies(); + assertEquals(Arrays.asList("foo","bar","baz"), bodies); + } + + private HttpResponse mkRequest(String foo) { + HttpResponse r = mock(HttpResponse.class); + when(r.getBody()).thenReturn(foo); + return r; + } +} \ No newline at end of file From 5c5115efdb20f6b4580a6fd01b2538142fe325a4 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 10 Feb 2019 11:15:04 -0600 Subject: [PATCH 0438/1769] change the order of the params to match the order they are called. Added some doc --- src/main/java/unirest/BaseRequest.java | 2 +- src/main/java/unirest/HttpRequest.java | 14 +++++++++++--- src/test/java/BehaviorTests/PagingTest.java | 3 +-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 2db8766b5..10a5337e6 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -285,7 +285,7 @@ private ObjectMapper getObjectMapper() { } @Override - public PagedList asPaged(Function, String> linkExtractor, Function mappingFunction) { + public PagedList asPaged(Function mappingFunction, Function, String> linkExtractor) { PagedList all = new PagedList<>(); String nextLink = this.getUrl(); do { diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index d6dc3d8bc..ee326a6ec 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -264,6 +264,17 @@ public interface HttpRequest { */ CompletableFuture> asFileAsync(String path, Callback callback); + /** + * Allows for following paging links common in many APIs. + * Each request will result in the same request (headers, etc) but will use the "next" link provided by the extract function. + * + * @param mappingFunction a function to return the desired return type leveraging one of the as* methods (asString, asObject, etc). + * @param linkExtractor a function to extract a "next" link to follow. Retuning a null or empty string ends the paging + * @return a PagedList of your type + */ + PagedList asPaged(Function mappingFunction, + Function, String> linkExtractor); + /** * Executes the request asynchronously and returns a copy of the original InputStream * @deprecated This method returns a copy of the original stream and is not suitable for streaming. Use asObjectAsync(Function<RawResponse, T> function) @@ -281,9 +292,6 @@ public interface HttpRequest { @Deprecated CompletableFuture> asBinaryAsync(Callback callback); - PagedList asPaged(Function, String> linkExtractor, - Function mappingFunction); - /** * Execute the request asynchronously and pass the raw response to a consumer. * This raw response contains the original InputStream and is suitable for diff --git a/src/test/java/BehaviorTests/PagingTest.java b/src/test/java/BehaviorTests/PagingTest.java index 998bbdf3a..c2d1386f6 100644 --- a/src/test/java/BehaviorTests/PagingTest.java +++ b/src/test/java/BehaviorTests/PagingTest.java @@ -40,8 +40,7 @@ public void canFollowPaging() { PagedList result = Unirest.get(MockServer.PAGED) .asPaged( - r -> r.getHeaders().getFirst("nextPage"), - r -> r.asObject(RequestCapture.class) + r -> r.asObject(RequestCapture.class), r -> r.getHeaders().getFirst("nextPage") ); assertEquals(10, result.size()); From 6f9fc8874c5aed3b0a10cdf01925f7458618d70a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 10 Feb 2019 11:29:29 -0600 Subject: [PATCH 0439/1769] all new files are copyright by OpenUnirest --- build/fileHeader.txt | 3 +-- src/main/java/unirest/PagedList.java | 3 +-- src/test/java/unirest/PagedListTest.java | 5 ++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/build/fileHeader.txt b/build/fileHeader.txt index 8b23035b1..585b0d2b2 100644 --- a/build/fileHeader.txt +++ b/build/fileHeader.txt @@ -1,7 +1,6 @@ The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/PagedList.java b/src/main/java/unirest/PagedList.java index da4cea16f..3ea5e28a5 100644 --- a/src/main/java/unirest/PagedList.java +++ b/src/main/java/unirest/PagedList.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java by OpenUnirest (c) 2018. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/unirest/PagedListTest.java b/src/test/java/unirest/PagedListTest.java index e793fefd5..ff31bab6f 100644 --- a/src/test/java/unirest/PagedListTest.java +++ b/src/test/java/unirest/PagedListTest.java @@ -1,9 +1,8 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * + * Copyright for portions of OpenUnirest/uniresr-java by OpenUnirest (c) 2018. + * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including From 2b03820ee45a445c42a5c2a5773994731bb3ea2a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 10 Feb 2019 17:13:32 -0600 Subject: [PATCH 0440/1769] Revert "all new files are copyright by OpenUnirest" This reverts commit 6f9fc8874c5aed3b0a10cdf01925f7458618d70a. --- build/fileHeader.txt | 3 ++- src/main/java/unirest/PagedList.java | 3 ++- src/test/java/unirest/PagedListTest.java | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/build/fileHeader.txt b/build/fileHeader.txt index 585b0d2b2..8b23035b1 100644 --- a/build/fileHeader.txt +++ b/build/fileHeader.txt @@ -1,6 +1,7 @@ The MIT License -Copyright for portions of OpenUnirest/uniresr-java by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/PagedList.java b/src/main/java/unirest/PagedList.java index 3ea5e28a5..da4cea16f 100644 --- a/src/main/java/unirest/PagedList.java +++ b/src/main/java/unirest/PagedList.java @@ -1,7 +1,8 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/unirest/PagedListTest.java b/src/test/java/unirest/PagedListTest.java index ff31bab6f..e793fefd5 100644 --- a/src/test/java/unirest/PagedListTest.java +++ b/src/test/java/unirest/PagedListTest.java @@ -1,8 +1,9 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java by OpenUnirest (c) 2018. - * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including From eced0d37c439ff54613aa73dcf088e04cc36bef0 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 10 Feb 2019 17:14:51 -0600 Subject: [PATCH 0441/1769] Revert "Revert "all new files are copyright by OpenUnirest"" This reverts commit 2b03820ee45a445c42a5c2a5773994731bb3ea2a. --- build/fileHeader.txt | 3 +-- src/main/java/unirest/PagedList.java | 3 +-- src/test/java/unirest/PagedListTest.java | 5 ++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/build/fileHeader.txt b/build/fileHeader.txt index 8b23035b1..585b0d2b2 100644 --- a/build/fileHeader.txt +++ b/build/fileHeader.txt @@ -1,7 +1,6 @@ The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/PagedList.java b/src/main/java/unirest/PagedList.java index da4cea16f..3ea5e28a5 100644 --- a/src/main/java/unirest/PagedList.java +++ b/src/main/java/unirest/PagedList.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java by OpenUnirest (c) 2018. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/unirest/PagedListTest.java b/src/test/java/unirest/PagedListTest.java index e793fefd5..ff31bab6f 100644 --- a/src/test/java/unirest/PagedListTest.java +++ b/src/test/java/unirest/PagedListTest.java @@ -1,9 +1,8 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. - * + * Copyright for portions of OpenUnirest/uniresr-java by OpenUnirest (c) 2018. + * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including From f2d0b7a2c1df846f35f64867c17c045d08bd3018 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 11 Feb 2019 19:50:07 -0600 Subject: [PATCH 0442/1769] add functionality to the paged list --- src/main/java/unirest/PagedList.java | 27 +++++++++++++++ src/test/java/unirest/PagedListTest.java | 44 ++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/src/main/java/unirest/PagedList.java b/src/main/java/unirest/PagedList.java index 3ea5e28a5..a5f427f78 100644 --- a/src/main/java/unirest/PagedList.java +++ b/src/main/java/unirest/PagedList.java @@ -27,13 +27,40 @@ import java.util.ArrayList; import java.util.List; +import java.util.function.Consumer; import java.util.stream.Collectors; public class PagedList extends ArrayList> { + /** + * @return Returns all successful bodies + */ public List getBodies() { return stream() + .filter(HttpResponse::isSuccess) .map(HttpResponse::getBody) .collect(Collectors.toList()); } + + /** + * For each successful response If the response was a 200-series response. Invoke this consumer + * can be chained with ifFailure + * @param consumer a function to consume a HttpResponse + * @return the same paged list + */ + public PagedList ifSuccess(Consumer> consumer) { + stream().filter(HttpResponse::isSuccess).forEach(consumer); + return this; + } + + /** + * For each failed response if the response was NOT a 200-series response or a mapping exception happened. Invoke this consumer + * can be chained with ifSuccess + * @param consumer a function to consume a HttpResponse + * @return the same paged list + */ + public PagedList ifFailure(Consumer> consumer) { + stream().filter(r -> !r.isSuccess()).forEach(consumer); + return this; + } } diff --git a/src/test/java/unirest/PagedListTest.java b/src/test/java/unirest/PagedListTest.java index ff31bab6f..30a798cd3 100644 --- a/src/test/java/unirest/PagedListTest.java +++ b/src/test/java/unirest/PagedListTest.java @@ -25,8 +25,10 @@ package unirest; +import com.google.common.base.Strings; import org.junit.Test; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -50,9 +52,51 @@ public void canGetAllTheBodies() { assertEquals(Arrays.asList("foo","bar","baz"), bodies); } + @Test + public void bodiesMustBeSucessful() { + PagedList list = new PagedList<>(); + list.addAll(asList( + mkRequest("foo"), + mkRequest(null), + mkRequest("baz") + )); + + List bodies = list.getBodies(); + assertEquals(Arrays.asList("foo","baz"), bodies); + } + + @Test + public void canProcessSuccessfullResuls() { + PagedList list = new PagedList<>(); + list.addAll(asList( + mkRequest("foo"), + mkRequest(null), + mkRequest("baz") + )); + + final List processed = new ArrayList<>(); + list.ifSuccess(e -> processed.add(e.getBody())); + assertEquals(Arrays.asList("foo","baz"), processed); + } + + @Test + public void canProcessFailed() { + PagedList list = new PagedList<>(); + list.addAll(asList( + mkRequest("foo"), + mkRequest(null), + mkRequest("baz") + )); + + final List processed = new ArrayList<>(); + list.ifFailure(e -> processed.add(e.getBody())); + assertEquals(null, processed.get(0)); + } + private HttpResponse mkRequest(String foo) { HttpResponse r = mock(HttpResponse.class); when(r.getBody()).thenReturn(foo); + when(r.isSuccess()).thenReturn(!Strings.isNullOrEmpty(foo)); return r; } } \ No newline at end of file From 0d8eaf1388cb14749dd2cc92fd5258c2a9f59ea1 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 11 Feb 2019 19:52:21 -0600 Subject: [PATCH 0443/1769] Revert "Revert "Revert "all new files are copyright by OpenUnirest""" This reverts commit eced0d37c439ff54613aa73dcf088e04cc36bef0. --- build/fileHeader.txt | 3 ++- src/main/java/unirest/PagedList.java | 3 ++- src/test/java/unirest/PagedListTest.java | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/build/fileHeader.txt b/build/fileHeader.txt index 585b0d2b2..8b23035b1 100644 --- a/build/fileHeader.txt +++ b/build/fileHeader.txt @@ -1,6 +1,7 @@ The MIT License -Copyright for portions of OpenUnirest/uniresr-java by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. +All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/PagedList.java b/src/main/java/unirest/PagedList.java index a5f427f78..d42a5797b 100644 --- a/src/main/java/unirest/PagedList.java +++ b/src/main/java/unirest/PagedList.java @@ -1,7 +1,8 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/unirest/PagedListTest.java b/src/test/java/unirest/PagedListTest.java index 30a798cd3..2ebc5ff1e 100644 --- a/src/test/java/unirest/PagedListTest.java +++ b/src/test/java/unirest/PagedListTest.java @@ -1,8 +1,9 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java by OpenUnirest (c) 2018. - * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including From 03659cb114bab211db2f64225507f5e5b652c6de Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 12 Feb 2019 07:43:12 -0600 Subject: [PATCH 0444/1769] tests and documentation --- CHANGELOG.md | 10 ++++++++++ src/main/java/unirest/HttpRequest.java | 3 ++- src/test/java/BehaviorTests/PagingTest.java | 15 ++++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4feac0d53..90c15c1a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## 3.3.04 +* Add the ability to follow a paged response by providing a lambda for the response type and one for getting the next page. It will stop once the next link is null or empty +```java +PagedList result = Unirest.get("http://and.pagey") + .asPaged( + r -> r.asJson(), + r -> r.getHeaders().getFirst("nextPage") + ); +``` + ## 3.3.03 * Pulled isSuccess() up to the response interface so it can be used and enjoyed by everyone. diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index ee326a6ec..f47403c96 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -267,7 +267,8 @@ public interface HttpRequest { /** * Allows for following paging links common in many APIs. * Each request will result in the same request (headers, etc) but will use the "next" link provided by the extract function. - * + * + * @param the type of response. * @param mappingFunction a function to return the desired return type leveraging one of the as* methods (asString, asObject, etc). * @param linkExtractor a function to extract a "next" link to follow. Retuning a null or empty string ends the paging * @return a PagedList of your type diff --git a/src/test/java/BehaviorTests/PagingTest.java b/src/test/java/BehaviorTests/PagingTest.java index c2d1386f6..0627a7c42 100644 --- a/src/test/java/BehaviorTests/PagingTest.java +++ b/src/test/java/BehaviorTests/PagingTest.java @@ -40,9 +40,22 @@ public void canFollowPaging() { PagedList result = Unirest.get(MockServer.PAGED) .asPaged( - r -> r.asObject(RequestCapture.class), r -> r.getHeaders().getFirst("nextPage") + r -> r.asObject(RequestCapture.class), + r -> r.getHeaders().getFirst("nextPage") ); assertEquals(10, result.size()); } + + @Test + public void willReturnOnePageIfthereWasNoPaging() { + + PagedList result = Unirest.get(MockServer.PAGED) + .asPaged( + r -> r.asObject(RequestCapture.class), + r -> null + ); + + assertEquals(1, result.size()); + } } From bfd138944541621db95c13f3c6e6e5397b2c339c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 12 Feb 2019 07:45:09 -0600 Subject: [PATCH 0445/1769] [maven-release-plugin] prepare release v3.3.04 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 0d99dc275..8d2548c9d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.3.04-SNAPSHOT + 3.3.04 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.3.04 From 09045702fbfa2ac172f340d3c6b618e090c00b69 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 12 Feb 2019 07:45:19 -0600 Subject: [PATCH 0446/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 8d2548c9d..0ea5b6717 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.3.04 + 3.3.05-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.3.04 + HEAD From d652fdc3cb87f78b6743068595b311429e1913bb Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 18 Feb 2019 20:18:45 -0600 Subject: [PATCH 0447/1769] add a simple response type that is nothing at all. For when you dont care about bodies --- CHANGELOG.md | 12 +++- checkstyle.xml | 2 +- src/main/java/unirest/BaseRequest.java | 25 +++++-- src/main/java/unirest/Empty.java | 31 +++++++++ src/main/java/unirest/EmptyResponse.java | 45 +++++++++++++ src/main/java/unirest/HttpRequest.java | 20 ++++++ src/test/java/BehaviorTests/AsEmptyTest.java | 71 ++++++++++++++++++++ 7 files changed, 199 insertions(+), 7 deletions(-) create mode 100644 src/main/java/unirest/Empty.java create mode 100644 src/main/java/unirest/EmptyResponse.java create mode 100644 src/test/java/BehaviorTests/AsEmptyTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 90c15c1a5..1b07ba646 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ +## 3.3.05 +* Add a noop response type when you just don't care about the body. +```java + HttpResponse re = Unirest.get("http://no.body.knows").asEmpty(); +``` + ## 3.3.04 -* Add the ability to follow a paged response by providing a lambda for the response type and one for getting the next page. It will stop once the next link is null or empty +* Add the ability to follow a paged response by providing a lambda for the response type and one for getting the next page. It will stop once the next link is null or empty. +* The PagedList has handy dandy methods to pass consumers to all success and failure responses. ```java PagedList result = Unirest.get("http://and.pagey") .asPaged( @@ -8,6 +15,7 @@ PagedList result = Unirest.get("http://and.pagey") ); ``` + ## 3.3.03 * Pulled isSuccess() up to the response interface so it can be used and enjoyed by everyone. @@ -22,7 +30,7 @@ PagedList result = Unirest.get("http://and.pagey") * Slight breaking change with regard to accessing Apache specific classes via the config * getClient and getAsyncClient return the Unirest containers for clients. You can still get to the Apache client through that for now but this is also deprecated. Eventually Unirest will make Apache just one of several modules. * Apache client wrappers are now package local. -* Add support for overriding the default expected encoding both on a per-request basis and as a default int he config. +* Add support for overriding the default expected encoding both on a per-request basis and as a default in the config. ```java // Changing the default from UTF-8 for all requests // Unirest will still honor content-encoding if defined in the response headers diff --git a/checkstyle.xml b/checkstyle.xml index 0de24996d..638d89f13 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -145,7 +145,7 @@ - + diff --git a/src/main/java/unirest/BaseRequest.java b/src/main/java/unirest/BaseRequest.java index 10a5337e6..81e68d9ab 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/src/main/java/unirest/BaseRequest.java @@ -126,6 +126,23 @@ public R withObjectMapper(ObjectMapper mapper) { return (R)this; } + @Override + public HttpResponse asEmpty() { + return config.getClient().request(this, EmptyResponse::new); + } + + @Override + public CompletableFuture> asEmptyAsync() { + return config.getAsyncClient() + .request(this, EmptyResponse::new, new CompletableFuture<>()); + } + + @Override + public CompletableFuture> asEmptyAsync(Callback callback) { + return config.getAsyncClient() + .request(this, EmptyResponse::new, CallbackFuture.wrap(callback)); + } + @Override public HttpResponse asString() throws UnirestException { return config.getClient().request(this, r -> new StringResponse(r, responseEncoding)); @@ -133,14 +150,14 @@ public HttpResponse asString() throws UnirestException { @Override public CompletableFuture> asStringAsync() { - - return config.getAsyncClient().request(this, r -> new StringResponse(r, responseEncoding), new CompletableFuture<>()); + return config.getAsyncClient() + .request(this, r -> new StringResponse(r, responseEncoding), new CompletableFuture<>()); } @Override public CompletableFuture> asStringAsync(Callback callback) { - - return config.getAsyncClient().request(this, r -> new StringResponse(r, responseEncoding), CallbackFuture.wrap(callback)); + return config.getAsyncClient() + .request(this, r -> new StringResponse(r, responseEncoding), CallbackFuture.wrap(callback)); } @Override diff --git a/src/main/java/unirest/Empty.java b/src/main/java/unirest/Empty.java new file mode 100644 index 000000000..8040ad8a9 --- /dev/null +++ b/src/main/java/unirest/Empty.java @@ -0,0 +1,31 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +public class Empty { + private Empty(){} +} diff --git a/src/main/java/unirest/EmptyResponse.java b/src/main/java/unirest/EmptyResponse.java new file mode 100644 index 000000000..c9fb3a7f2 --- /dev/null +++ b/src/main/java/unirest/EmptyResponse.java @@ -0,0 +1,45 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package unirest; + +import java.io.InputStream; + +class EmptyResponse extends BaseResponse { + EmptyResponse(RawResponse response) { + super(response); + } + + @Override + public InputStream getRawBody() { + return null; + } + + @Override + public Empty getBody() { + return null; + } +} diff --git a/src/main/java/unirest/HttpRequest.java b/src/main/java/unirest/HttpRequest.java index f47403c96..ce36d08bb 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/src/main/java/unirest/HttpRequest.java @@ -293,6 +293,26 @@ PagedList asPaged(Function mappingFunction, @Deprecated CompletableFuture> asBinaryAsync(Callback callback); + /** + * Executes the request and returns the response without parsing the body + * @return the basic HttpResponse + */ + HttpResponse asEmpty(); + + /** + * Executes the request asynchronously and returns the response without parsing the body + * @return a CompletableFuture of a HttpResponse + */ + CompletableFuture> asEmptyAsync(); + + /** + * Executes the request asynchronously and returns a empty response which is passed to a callback + * @param callback the callback* Executes the request asynchronously and returns the response without parsing the body + * @return a CompletableFuture of a HttpResponse + */ + CompletableFuture> asEmptyAsync(Callback callback); + + /** * Execute the request asynchronously and pass the raw response to a consumer. * This raw response contains the original InputStream and is suitable for diff --git a/src/test/java/BehaviorTests/AsEmptyTest.java b/src/test/java/BehaviorTests/AsEmptyTest.java new file mode 100644 index 000000000..19bd53ec9 --- /dev/null +++ b/src/test/java/BehaviorTests/AsEmptyTest.java @@ -0,0 +1,71 @@ +/** + * The MIT License + * + * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. + * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package BehaviorTests; + +import org.junit.Test; +import unirest.HttpResponse; +import unirest.Unirest; + +import static junit.framework.TestCase.assertEquals; + +public class AsEmptyTest extends BddTest { + + @Test + public void canDoAEmptyRequestThatDoesNotParseBodyAtAll() { + MockServer.addResponseHeader("foo", "bar"); + HttpResponse res = Unirest.get(MockServer.GET).asEmpty(); + + assertEquals(200, res.getStatus()); + assertEquals(null, res.getBody()); + assertEquals("bar", res.getHeaders().getFirst("foo")); + } + + @Test + public void canDoEmptyAsync() throws Exception { + MockServer.addResponseHeader("foo", "bar"); + HttpResponse res = Unirest.get(MockServer.GET).asEmptyAsync().get(); + + assertEquals(200, res.getStatus()); + assertEquals(null, res.getBody()); + assertEquals("bar", res.getHeaders().getFirst("foo")); + } + + @Test + public void canDoEmptyAsyncWithCallback() { + MockServer.addResponseHeader("foo", "bar"); + + Unirest.get(MockServer.GET) + .asEmptyAsync(res -> { + assertEquals(200, res.getStatus()); + assertEquals(null, res.getBody()); + assertEquals("bar", res.getHeaders().getFirst("foo")); + asyncSuccess(); + }); + + assertAsync(); + } +} From 2c4396f3e95b36ddb8f107fe8017e36efe882fba Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 18 Feb 2019 20:45:47 -0600 Subject: [PATCH 0448/1769] [maven-release-plugin] prepare release v3.3.05 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 0ea5b6717..c06ecb4f5 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.3.05-SNAPSHOT + 3.3.05 unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - HEAD + v3.3.05 From 1e9dbccff4191e5b8fd65887ebdee2b25e8189b4 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 18 Feb 2019 20:46:00 -0600 Subject: [PATCH 0449/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c06ecb4f5..bcd44789a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.openunirest open-unirest-java jar - 3.3.05 + 3.3.06-SNAPSHOT unirest-java Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git scm:git:git@github.com:OpenUnirest/unirest-java.git - v3.3.05 + HEAD From 02619a91f8e3b59cdbd7647ce169e33dc109bc71 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 19 Feb 2019 15:39:12 -0600 Subject: [PATCH 0450/1769] move unirest into a module so we can put the other modules in here --- checkstyle.xml => build/checkstyle.xml | 0 build/fileHeader.txt | 3 +- suppressions.xml => build/suppressions.xml | 0 pom.xml | 154 ++++++------------ unirest/pom.xml | 113 +++++++++++++ .../main/java/unirest/ApacheAsyncClient.java | 3 +- .../src}/main/java/unirest/ApacheClient.java | 3 +- .../java/unirest/ApacheRequestWithBody.java | 3 +- .../main/java/unirest/ApacheResponse.java | 3 +- .../src}/main/java/unirest/AsyncClient.java | 3 +- .../AsyncIdleConnectionMonitorThread.java | 3 +- .../main/java/unirest/BaseApacheClient.java | 3 +- .../src}/main/java/unirest/BaseRequest.java | 3 +- .../src}/main/java/unirest/BaseResponse.java | 3 +- .../src}/main/java/unirest/BasicResponse.java | 3 +- .../main/java/unirest/BinaryResponse.java | 3 +- .../src}/main/java/unirest/Body.java | 3 +- .../src}/main/java/unirest/Callback.java | 3 +- .../main/java/unirest/CallbackFuture.java | 3 +- .../src}/main/java/unirest/Client.java | 3 +- .../src}/main/java/unirest/Config.java | 3 +- .../src}/main/java/unirest/Empty.java | 3 +- .../src}/main/java/unirest/EmptyResponse.java | 3 +- .../src}/main/java/unirest/FileResponse.java | 3 +- .../src}/main/java/unirest/FormPart.java | 3 +- .../src}/main/java/unirest/GenericType.java | 3 +- .../src}/main/java/unirest/GetRequest.java | 3 +- .../src}/main/java/unirest/Header.java | 3 +- .../src}/main/java/unirest/HeaderNames.java | 3 +- .../src}/main/java/unirest/Headers.java | 3 +- .../main/java/unirest/HttpDeleteWithBody.java | 3 +- .../src}/main/java/unirest/HttpMethod.java | 3 +- .../main/java/unirest/HttpPatchWithBody.java | 3 +- .../src}/main/java/unirest/HttpRequest.java | 3 +- .../main/java/unirest/HttpRequestBody.java | 3 +- .../java/unirest/HttpRequestJsonPatch.java | 3 +- .../java/unirest/HttpRequestMultiPart.java | 3 +- .../main/java/unirest/HttpRequestNoBody.java | 3 +- .../main/java/unirest/HttpRequestUniBody.java | 3 +- .../java/unirest/HttpRequestWithBody.java | 3 +- .../src}/main/java/unirest/HttpResponse.java | 3 +- .../src}/main/java/unirest/JsonNode.java | 3 +- .../src}/main/java/unirest/JsonPatch.java | 3 +- .../src}/main/java/unirest/JsonPatchItem.java | 3 +- .../main/java/unirest/JsonPatchOperation.java | 3 +- .../main/java/unirest/JsonPatchRequest.java | 3 +- .../src}/main/java/unirest/JsonResponse.java | 3 +- .../src}/main/java/unirest/MultipartBody.java | 3 +- .../src}/main/java/unirest/NoRedirects.java | 3 +- .../src}/main/java/unirest/ObjectMapper.java | 3 +- .../main/java/unirest/ObjectResponse.java | 3 +- .../src}/main/java/unirest/PagedList.java | 3 +- .../src}/main/java/unirest/Path.java | 3 +- .../src}/main/java/unirest/RawResponse.java | 3 +- .../main/java/unirest/RawResponseBase.java | 3 +- .../main/java/unirest/RequestBodyEntity.java | 3 +- .../src}/main/java/unirest/RequestPrep.java | 3 +- .../main/java/unirest/StringResponse.java | 3 +- .../SyncIdleConnectionMonitorThread.java | 3 +- .../src}/main/java/unirest/Unirest.java | 3 +- .../java/unirest/UnirestConfigException.java | 3 +- .../main/java/unirest/UnirestException.java | 3 +- .../main/java/unirest/UnirestInstance.java | 3 +- .../java/unirest/UnirestParsingException.java | 3 +- .../src}/main/java/unirest/Util.java | 3 +- .../test/java/BehaviorTests/AsBinaryTest.java | 3 +- .../test/java/BehaviorTests/AsEmptyTest.java | 3 +- .../test/java/BehaviorTests/AsFileTests.java | 3 +- .../java/BehaviorTests/AsGenericTypeTest.java | 3 +- .../test/java/BehaviorTests/AsJsonTest.java | 3 +- .../test/java/BehaviorTests/AsObjectTest.java | 3 +- .../test/java/BehaviorTests/AsStringTest.java | 3 +- .../src}/test/java/BehaviorTests/BddTest.java | 3 +- .../BehaviorTests/CallbackFutureTest.java | 3 +- .../java/BehaviorTests/ConsumerTests.java | 3 +- .../test/java/BehaviorTests/DefectTest.java | 3 +- .../src}/test/java/BehaviorTests/Foo.java | 3 +- .../java/BehaviorTests/FormPostingTest.java | 3 +- .../test/java/BehaviorTests/GZipTest.java | 3 +- .../test/java/BehaviorTests/GetResponse.java | 3 +- .../test/java/BehaviorTests/HeaderTest.java | 3 +- .../java/BehaviorTests/InterceptorTest.java | 3 +- .../test/java/BehaviorTests/JankyProxy.java | 3 +- .../java/BehaviorTests/JsonPatchTest.java | 3 +- .../java/BehaviorTests/LifeCycleTest.java | 3 +- .../test/java/BehaviorTests/MockServer.java | 3 +- .../BehaviorTests/ObjectFunctionalTest.java | 3 +- .../test/java/BehaviorTests/PagingTest.java | 3 +- .../src}/test/java/BehaviorTests/Pair.java | 3 +- .../java/BehaviorTests/PathParamTest.java | 3 +- .../PostRequestHandlersTest.java | 3 +- .../test/java/BehaviorTests/ProxyTest.java | 3 +- .../java/BehaviorTests/QueryStringTest.java | 3 +- .../java/BehaviorTests/RedirectHandling.java | 3 +- .../java/BehaviorTests/RequestCapture.java | 3 +- .../BehaviorTests/ResponseHeaderTest.java | 3 +- .../test/java/BehaviorTests/SendBodyTest.java | 3 +- .../test/java/BehaviorTests/TimeoutTests.java | 3 +- .../test/java/BehaviorTests/VerbTest.java | 3 +- .../test/java/unirest/ClientFactoryTest.java | 3 +- .../src}/test/java/unirest/ConfigTest.java | 3 +- .../test/java/unirest/GsonObjectMapper.java | 3 +- .../src}/test/java/unirest/HeadersTest.java | 3 +- .../java/unirest/JacksonObjectMapper.java | 3 +- .../java/unirest/JacksonObjectMapperTest.java | 3 +- .../src}/test/java/unirest/JsonNodeTest.java | 3 +- .../src}/test/java/unirest/MockCallback.java | 3 +- .../src}/test/java/unirest/NoopCallback.java | 3 +- .../test/java/unirest/NotImplimented.java | 3 +- .../src}/test/java/unirest/PagedListTest.java | 3 +- .../test/java/unirest/ResponseUtilsTest.java | 3 +- .../src}/test/java/unirest/TestUtil.java | 3 +- .../test/java/unirest/UriFormatterTest.java | 3 +- .../src}/test/java/unirest/UtilTest.java | 3 +- .../src}/test/resources/data/cp1250.txt | 0 {src => unirest/src}/test/resources/image.jpg | Bin {src => unirest/src}/test/resources/test | 0 .../src}/test/resources/test-json-patch.json | 0 118 files changed, 272 insertions(+), 325 deletions(-) rename checkstyle.xml => build/checkstyle.xml (100%) rename suppressions.xml => build/suppressions.xml (100%) create mode 100644 unirest/pom.xml rename {src => unirest/src}/main/java/unirest/ApacheAsyncClient.java (97%) rename {src => unirest/src}/main/java/unirest/ApacheClient.java (97%) rename {src => unirest/src}/main/java/unirest/ApacheRequestWithBody.java (92%) rename {src => unirest/src}/main/java/unirest/ApacheResponse.java (97%) rename {src => unirest/src}/main/java/unirest/AsyncClient.java (94%) rename {src => unirest/src}/main/java/unirest/AsyncIdleConnectionMonitorThread.java (93%) rename {src => unirest/src}/main/java/unirest/BaseApacheClient.java (93%) rename {src => unirest/src}/main/java/unirest/BaseRequest.java (98%) rename {src => unirest/src}/main/java/unirest/BaseResponse.java (95%) rename {src => unirest/src}/main/java/unirest/BasicResponse.java (92%) rename {src => unirest/src}/main/java/unirest/BinaryResponse.java (92%) rename {src => unirest/src}/main/java/unirest/Body.java (90%) rename {src => unirest/src}/main/java/unirest/Callback.java (90%) rename {src => unirest/src}/main/java/unirest/CallbackFuture.java (93%) rename {src => unirest/src}/main/java/unirest/Client.java (93%) rename {src => unirest/src}/main/java/unirest/Config.java (99%) rename {src => unirest/src}/main/java/unirest/Empty.java (90%) rename {src => unirest/src}/main/java/unirest/EmptyResponse.java (91%) rename {src => unirest/src}/main/java/unirest/FileResponse.java (93%) rename {src => unirest/src}/main/java/unirest/FormPart.java (95%) rename {src => unirest/src}/main/java/unirest/GenericType.java (94%) rename {src => unirest/src}/main/java/unirest/GetRequest.java (90%) rename {src => unirest/src}/main/java/unirest/Header.java (90%) rename {src => unirest/src}/main/java/unirest/HeaderNames.java (98%) rename {src => unirest/src}/main/java/unirest/Headers.java (97%) rename {src => unirest/src}/main/java/unirest/HttpDeleteWithBody.java (91%) rename {src => unirest/src}/main/java/unirest/HttpMethod.java (94%) rename {src => unirest/src}/main/java/unirest/HttpPatchWithBody.java (91%) rename {src => unirest/src}/main/java/unirest/HttpRequest.java (99%) rename {src => unirest/src}/main/java/unirest/HttpRequestBody.java (96%) rename {src => unirest/src}/main/java/unirest/HttpRequestJsonPatch.java (95%) rename {src => unirest/src}/main/java/unirest/HttpRequestMultiPart.java (97%) rename {src => unirest/src}/main/java/unirest/HttpRequestNoBody.java (91%) rename {src => unirest/src}/main/java/unirest/HttpRequestUniBody.java (94%) rename {src => unirest/src}/main/java/unirest/HttpRequestWithBody.java (94%) rename {src => unirest/src}/main/java/unirest/HttpResponse.java (96%) rename {src => unirest/src}/main/java/unirest/JsonNode.java (94%) rename {src => unirest/src}/main/java/unirest/JsonPatch.java (95%) rename {src => unirest/src}/main/java/unirest/JsonPatchItem.java (95%) rename {src => unirest/src}/main/java/unirest/JsonPatchOperation.java (92%) rename {src => unirest/src}/main/java/unirest/JsonPatchRequest.java (92%) rename {src => unirest/src}/main/java/unirest/JsonResponse.java (94%) rename {src => unirest/src}/main/java/unirest/MultipartBody.java (97%) rename {src => unirest/src}/main/java/unirest/NoRedirects.java (92%) rename {src => unirest/src}/main/java/unirest/ObjectMapper.java (91%) rename {src => unirest/src}/main/java/unirest/ObjectResponse.java (95%) rename {src => unirest/src}/main/java/unirest/PagedList.java (94%) rename {src => unirest/src}/main/java/unirest/Path.java (96%) rename {src => unirest/src}/main/java/unirest/RawResponse.java (92%) rename {src => unirest/src}/main/java/unirest/RawResponseBase.java (94%) rename {src => unirest/src}/main/java/unirest/RequestBodyEntity.java (91%) rename {src => unirest/src}/main/java/unirest/RequestPrep.java (97%) rename {src => unirest/src}/main/java/unirest/StringResponse.java (92%) rename {src => unirest/src}/main/java/unirest/SyncIdleConnectionMonitorThread.java (93%) rename {src => unirest/src}/main/java/unirest/Unirest.java (97%) rename {src => unirest/src}/main/java/unirest/UnirestConfigException.java (91%) rename {src => unirest/src}/main/java/unirest/UnirestException.java (92%) rename {src => unirest/src}/main/java/unirest/UnirestInstance.java (97%) rename {src => unirest/src}/main/java/unirest/UnirestParsingException.java (91%) rename {src => unirest/src}/main/java/unirest/Util.java (96%) rename {src => unirest/src}/test/java/BehaviorTests/AsBinaryTest.java (95%) rename {src => unirest/src}/test/java/BehaviorTests/AsEmptyTest.java (94%) rename {src => unirest/src}/test/java/BehaviorTests/AsFileTests.java (96%) rename {src => unirest/src}/test/java/BehaviorTests/AsGenericTypeTest.java (96%) rename {src => unirest/src}/test/java/BehaviorTests/AsJsonTest.java (96%) rename {src => unirest/src}/test/java/BehaviorTests/AsObjectTest.java (97%) rename {src => unirest/src}/test/java/BehaviorTests/AsStringTest.java (97%) rename {src => unirest/src}/test/java/BehaviorTests/BddTest.java (95%) rename {src => unirest/src}/test/java/BehaviorTests/CallbackFutureTest.java (94%) rename {src => unirest/src}/test/java/BehaviorTests/ConsumerTests.java (93%) rename {src => unirest/src}/test/java/BehaviorTests/DefectTest.java (96%) rename {src => unirest/src}/test/java/BehaviorTests/Foo.java (91%) rename {src => unirest/src}/test/java/BehaviorTests/FormPostingTest.java (99%) rename {src => unirest/src}/test/java/BehaviorTests/GZipTest.java (93%) rename {src => unirest/src}/test/java/BehaviorTests/GetResponse.java (91%) rename {src => unirest/src}/test/java/BehaviorTests/HeaderTest.java (98%) rename {src => unirest/src}/test/java/BehaviorTests/InterceptorTest.java (94%) rename {src => unirest/src}/test/java/BehaviorTests/JankyProxy.java (97%) rename {src => unirest/src}/test/java/BehaviorTests/JsonPatchTest.java (97%) rename {src => unirest/src}/test/java/BehaviorTests/LifeCycleTest.java (97%) rename {src => unirest/src}/test/java/BehaviorTests/MockServer.java (98%) rename {src => unirest/src}/test/java/BehaviorTests/ObjectFunctionalTest.java (94%) rename {src => unirest/src}/test/java/BehaviorTests/PagingTest.java (93%) rename {src => unirest/src}/test/java/BehaviorTests/Pair.java (91%) rename {src => unirest/src}/test/java/BehaviorTests/PathParamTest.java (96%) rename {src => unirest/src}/test/java/BehaviorTests/PostRequestHandlersTest.java (96%) rename {src => unirest/src}/test/java/BehaviorTests/ProxyTest.java (96%) rename {src => unirest/src}/test/java/BehaviorTests/QueryStringTest.java (97%) rename {src => unirest/src}/test/java/BehaviorTests/RedirectHandling.java (94%) rename {src => unirest/src}/test/java/BehaviorTests/RequestCapture.java (98%) rename {src => unirest/src}/test/java/BehaviorTests/ResponseHeaderTest.java (95%) rename {src => unirest/src}/test/java/BehaviorTests/SendBodyTest.java (97%) rename {src => unirest/src}/test/java/BehaviorTests/TimeoutTests.java (97%) rename {src => unirest/src}/test/java/BehaviorTests/VerbTest.java (95%) rename {src => unirest/src}/test/java/unirest/ClientFactoryTest.java (95%) rename {src => unirest/src}/test/java/unirest/ConfigTest.java (98%) rename {src => unirest/src}/test/java/unirest/GsonObjectMapper.java (92%) rename {src => unirest/src}/test/java/unirest/HeadersTest.java (92%) rename {src => unirest/src}/test/java/unirest/JacksonObjectMapper.java (97%) rename {src => unirest/src}/test/java/unirest/JacksonObjectMapperTest.java (94%) rename {src => unirest/src}/test/java/unirest/JsonNodeTest.java (94%) rename {src => unirest/src}/test/java/unirest/MockCallback.java (94%) rename {src => unirest/src}/test/java/unirest/NoopCallback.java (91%) rename {src => unirest/src}/test/java/unirest/NotImplimented.java (90%) rename {src => unirest/src}/test/java/unirest/PagedListTest.java (96%) rename {src => unirest/src}/test/java/unirest/ResponseUtilsTest.java (96%) rename {src => unirest/src}/test/java/unirest/TestUtil.java (97%) rename {src => unirest/src}/test/java/unirest/UriFormatterTest.java (93%) rename {src => unirest/src}/test/java/unirest/UtilTest.java (93%) rename {src => unirest/src}/test/resources/data/cp1250.txt (100%) rename {src => unirest/src}/test/resources/image.jpg (100%) rename {src => unirest/src}/test/resources/test (100%) rename {src => unirest/src}/test/resources/test-json-patch.json (100%) diff --git a/checkstyle.xml b/build/checkstyle.xml similarity index 100% rename from checkstyle.xml rename to build/checkstyle.xml diff --git a/build/fileHeader.txt b/build/fileHeader.txt index 8b23035b1..9be44eccf 100644 --- a/build/fileHeader.txt +++ b/build/fileHeader.txt @@ -1,7 +1,6 @@ The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. +Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/suppressions.xml b/build/suppressions.xml similarity index 100% rename from suppressions.xml rename to build/suppressions.xml diff --git a/pom.xml b/pom.xml index bcd44789a..be53333a6 100644 --- a/pom.xml +++ b/pom.xml @@ -1,14 +1,14 @@ - + 4.0.0 io.github.openunirest - open-unirest-java - jar + unirest-java-parent + pom 3.3.06-SNAPSHOT - unirest-java + unirest Simplified, lightweight HTTP client library. http://github.com/OpenUnirest/ - + MIT @@ -17,6 +17,16 @@ + + unirest + + + + UTF-8 + UTF-8 + 2.9.8 + + https://github.com/OpenUnirest/unirest-java scm:git:git@github.com:OpenUnirest/unirest-java.git @@ -28,8 +38,10 @@ Ryber Ryan Bergman - https://github.com/OpenUnirest - OpenUnirest + https://github.com/ryber + + Maintainer + @@ -44,12 +56,6 @@ - - UTF-8 - UTF-8 - 2.9.8 - - ossrh @@ -73,7 +79,8 @@ - + + com.mycila.maven-license-plugin @@ -140,9 +147,10 @@ - ${basedir}/checkstyle.xml - ${basedir}/suppressions.xml + build/checkstyle.xml + build/suppressions.xml true + true false @@ -301,26 +309,14 @@ + + - org.apache.httpcomponents - httpclient - 4.5.6 - - - org.apache.httpcomponents - httpmime - 4.5.6 - - - org.apache.httpcomponents - httpasyncclient - 4.1.4 - - - org.json - json - 20180813 + org.mockito + mockito-core + 2.23.4 + test junit @@ -328,75 +324,23 @@ 4.12 test - - - org.hamcrest - hamcrest-all - 1.3 - test - - - commons-io - commons-io - 2.4 - test - - - - org.mockito - mockito-all - 2.0.2-beta - test - - - - com.google.guava - guava - 27.0.1-jre - test - - - - com.fasterxml.jackson.datatype - jackson-datatype-guava - ${jackson.version} - test - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - test - - - com.sparkjava - spark-core - 2.8.0 - test - - - org.skyscreamer - jsonassert - 1.5.0 - test - - - org.slf4j - slf4j-simple - 1.7.25 - test - - - com.google.code.gson - gson - 2.8.1 - test - - - com.github.paweladamski - HttpClientMock - 1.0.4 - test - - + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.17 + + + + checkstyle + + + + + + + + \ No newline at end of file diff --git a/unirest/pom.xml b/unirest/pom.xml new file mode 100644 index 000000000..85ebbac50 --- /dev/null +++ b/unirest/pom.xml @@ -0,0 +1,113 @@ + + + 4.0.0 + + io.github.openunirest + unirest-java-parent + 3.3.06-SNAPSHOT + + + open-unirest-java + jar + + + + org.apache.httpcomponents + httpclient + 4.5.6 + + + org.apache.httpcomponents + httpmime + 4.5.6 + + + org.apache.httpcomponents + httpasyncclient + 4.1.4 + + + org.json + json + 20180813 + + + junit + junit + 4.12 + test + + + + + + org.hamcrest + hamcrest-all + 1.3 + test + + + commons-io + commons-io + 2.4 + test + + + + org.mockito + mockito-all + 2.0.2-beta + test + + + + com.google.guava + guava + 27.0.1-jre + test + + + + com.fasterxml.jackson.datatype + jackson-datatype-guava + ${jackson.version} + test + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + test + + + com.sparkjava + spark-core + 2.8.0 + test + + + org.skyscreamer + jsonassert + 1.5.0 + test + + + org.slf4j + slf4j-simple + 1.7.25 + test + + + com.google.code.gson + gson + 2.8.1 + test + + + com.github.paweladamski + HttpClientMock + 1.0.4 + test + + + diff --git a/src/main/java/unirest/ApacheAsyncClient.java b/unirest/src/main/java/unirest/ApacheAsyncClient.java similarity index 97% rename from src/main/java/unirest/ApacheAsyncClient.java rename to unirest/src/main/java/unirest/ApacheAsyncClient.java index bdeb62d5e..f4f751c8d 100644 --- a/src/main/java/unirest/ApacheAsyncClient.java +++ b/unirest/src/main/java/unirest/ApacheAsyncClient.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/ApacheClient.java b/unirest/src/main/java/unirest/ApacheClient.java similarity index 97% rename from src/main/java/unirest/ApacheClient.java rename to unirest/src/main/java/unirest/ApacheClient.java index edf86d3eb..d45a8aebf 100644 --- a/src/main/java/unirest/ApacheClient.java +++ b/unirest/src/main/java/unirest/ApacheClient.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/ApacheRequestWithBody.java b/unirest/src/main/java/unirest/ApacheRequestWithBody.java similarity index 92% rename from src/main/java/unirest/ApacheRequestWithBody.java rename to unirest/src/main/java/unirest/ApacheRequestWithBody.java index 9bf40f8dd..95fe3c2e8 100644 --- a/src/main/java/unirest/ApacheRequestWithBody.java +++ b/unirest/src/main/java/unirest/ApacheRequestWithBody.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/ApacheResponse.java b/unirest/src/main/java/unirest/ApacheResponse.java similarity index 97% rename from src/main/java/unirest/ApacheResponse.java rename to unirest/src/main/java/unirest/ApacheResponse.java index b781a32fe..08ce9f0de 100644 --- a/src/main/java/unirest/ApacheResponse.java +++ b/unirest/src/main/java/unirest/ApacheResponse.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/AsyncClient.java b/unirest/src/main/java/unirest/AsyncClient.java similarity index 94% rename from src/main/java/unirest/AsyncClient.java rename to unirest/src/main/java/unirest/AsyncClient.java index b0b135d06..89ddffab2 100644 --- a/src/main/java/unirest/AsyncClient.java +++ b/unirest/src/main/java/unirest/AsyncClient.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java b/unirest/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java similarity index 93% rename from src/main/java/unirest/AsyncIdleConnectionMonitorThread.java rename to unirest/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java index 2a6b41035..c86e97e4a 100644 --- a/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java +++ b/unirest/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/BaseApacheClient.java b/unirest/src/main/java/unirest/BaseApacheClient.java similarity index 93% rename from src/main/java/unirest/BaseApacheClient.java rename to unirest/src/main/java/unirest/BaseApacheClient.java index 14af6dd0a..dcf888e1a 100644 --- a/src/main/java/unirest/BaseApacheClient.java +++ b/unirest/src/main/java/unirest/BaseApacheClient.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/BaseRequest.java b/unirest/src/main/java/unirest/BaseRequest.java similarity index 98% rename from src/main/java/unirest/BaseRequest.java rename to unirest/src/main/java/unirest/BaseRequest.java index 81e68d9ab..f95a0a0b7 100644 --- a/src/main/java/unirest/BaseRequest.java +++ b/unirest/src/main/java/unirest/BaseRequest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/BaseResponse.java b/unirest/src/main/java/unirest/BaseResponse.java similarity index 95% rename from src/main/java/unirest/BaseResponse.java rename to unirest/src/main/java/unirest/BaseResponse.java index 1396f4a2d..70301a2b2 100644 --- a/src/main/java/unirest/BaseResponse.java +++ b/unirest/src/main/java/unirest/BaseResponse.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/BasicResponse.java b/unirest/src/main/java/unirest/BasicResponse.java similarity index 92% rename from src/main/java/unirest/BasicResponse.java rename to unirest/src/main/java/unirest/BasicResponse.java index 5eff192ec..4e164cf41 100644 --- a/src/main/java/unirest/BasicResponse.java +++ b/unirest/src/main/java/unirest/BasicResponse.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/BinaryResponse.java b/unirest/src/main/java/unirest/BinaryResponse.java similarity index 92% rename from src/main/java/unirest/BinaryResponse.java rename to unirest/src/main/java/unirest/BinaryResponse.java index f2a80eead..b8ea4cbd5 100644 --- a/src/main/java/unirest/BinaryResponse.java +++ b/unirest/src/main/java/unirest/BinaryResponse.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/Body.java b/unirest/src/main/java/unirest/Body.java similarity index 90% rename from src/main/java/unirest/Body.java rename to unirest/src/main/java/unirest/Body.java index 137381efb..a46e737b3 100644 --- a/src/main/java/unirest/Body.java +++ b/unirest/src/main/java/unirest/Body.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/Callback.java b/unirest/src/main/java/unirest/Callback.java similarity index 90% rename from src/main/java/unirest/Callback.java rename to unirest/src/main/java/unirest/Callback.java index ad22d6c77..c7768ecc1 100644 --- a/src/main/java/unirest/Callback.java +++ b/unirest/src/main/java/unirest/Callback.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/CallbackFuture.java b/unirest/src/main/java/unirest/CallbackFuture.java similarity index 93% rename from src/main/java/unirest/CallbackFuture.java rename to unirest/src/main/java/unirest/CallbackFuture.java index 24b1c2744..68281fd8a 100644 --- a/src/main/java/unirest/CallbackFuture.java +++ b/unirest/src/main/java/unirest/CallbackFuture.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/Client.java b/unirest/src/main/java/unirest/Client.java similarity index 93% rename from src/main/java/unirest/Client.java rename to unirest/src/main/java/unirest/Client.java index b1724f75a..9e3d88487 100644 --- a/src/main/java/unirest/Client.java +++ b/unirest/src/main/java/unirest/Client.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/Config.java b/unirest/src/main/java/unirest/Config.java similarity index 99% rename from src/main/java/unirest/Config.java rename to unirest/src/main/java/unirest/Config.java index 1ddd6eb03..6aedf12af 100644 --- a/src/main/java/unirest/Config.java +++ b/unirest/src/main/java/unirest/Config.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/Empty.java b/unirest/src/main/java/unirest/Empty.java similarity index 90% rename from src/main/java/unirest/Empty.java rename to unirest/src/main/java/unirest/Empty.java index 8040ad8a9..8845c1936 100644 --- a/src/main/java/unirest/Empty.java +++ b/unirest/src/main/java/unirest/Empty.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/EmptyResponse.java b/unirest/src/main/java/unirest/EmptyResponse.java similarity index 91% rename from src/main/java/unirest/EmptyResponse.java rename to unirest/src/main/java/unirest/EmptyResponse.java index c9fb3a7f2..2e8f50a0a 100644 --- a/src/main/java/unirest/EmptyResponse.java +++ b/unirest/src/main/java/unirest/EmptyResponse.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/FileResponse.java b/unirest/src/main/java/unirest/FileResponse.java similarity index 93% rename from src/main/java/unirest/FileResponse.java rename to unirest/src/main/java/unirest/FileResponse.java index ee55377ae..18e263723 100644 --- a/src/main/java/unirest/FileResponse.java +++ b/unirest/src/main/java/unirest/FileResponse.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/FormPart.java b/unirest/src/main/java/unirest/FormPart.java similarity index 95% rename from src/main/java/unirest/FormPart.java rename to unirest/src/main/java/unirest/FormPart.java index 4d95514ce..929958e8a 100644 --- a/src/main/java/unirest/FormPart.java +++ b/unirest/src/main/java/unirest/FormPart.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/GenericType.java b/unirest/src/main/java/unirest/GenericType.java similarity index 94% rename from src/main/java/unirest/GenericType.java rename to unirest/src/main/java/unirest/GenericType.java index 322b1908b..9eae27078 100644 --- a/src/main/java/unirest/GenericType.java +++ b/unirest/src/main/java/unirest/GenericType.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/GetRequest.java b/unirest/src/main/java/unirest/GetRequest.java similarity index 90% rename from src/main/java/unirest/GetRequest.java rename to unirest/src/main/java/unirest/GetRequest.java index 9458de2a3..acb18abf5 100644 --- a/src/main/java/unirest/GetRequest.java +++ b/unirest/src/main/java/unirest/GetRequest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/Header.java b/unirest/src/main/java/unirest/Header.java similarity index 90% rename from src/main/java/unirest/Header.java rename to unirest/src/main/java/unirest/Header.java index 1445e8ffa..b2183e826 100644 --- a/src/main/java/unirest/Header.java +++ b/unirest/src/main/java/unirest/Header.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/HeaderNames.java b/unirest/src/main/java/unirest/HeaderNames.java similarity index 98% rename from src/main/java/unirest/HeaderNames.java rename to unirest/src/main/java/unirest/HeaderNames.java index 567c2b7ae..78d80b61b 100644 --- a/src/main/java/unirest/HeaderNames.java +++ b/unirest/src/main/java/unirest/HeaderNames.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/Headers.java b/unirest/src/main/java/unirest/Headers.java similarity index 97% rename from src/main/java/unirest/Headers.java rename to unirest/src/main/java/unirest/Headers.java index 8f0fbd121..18e14c8e1 100644 --- a/src/main/java/unirest/Headers.java +++ b/unirest/src/main/java/unirest/Headers.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/HttpDeleteWithBody.java b/unirest/src/main/java/unirest/HttpDeleteWithBody.java similarity index 91% rename from src/main/java/unirest/HttpDeleteWithBody.java rename to unirest/src/main/java/unirest/HttpDeleteWithBody.java index 116d3e33a..1e9251112 100644 --- a/src/main/java/unirest/HttpDeleteWithBody.java +++ b/unirest/src/main/java/unirest/HttpDeleteWithBody.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/HttpMethod.java b/unirest/src/main/java/unirest/HttpMethod.java similarity index 94% rename from src/main/java/unirest/HttpMethod.java rename to unirest/src/main/java/unirest/HttpMethod.java index 316d177d5..295674977 100644 --- a/src/main/java/unirest/HttpMethod.java +++ b/unirest/src/main/java/unirest/HttpMethod.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/HttpPatchWithBody.java b/unirest/src/main/java/unirest/HttpPatchWithBody.java similarity index 91% rename from src/main/java/unirest/HttpPatchWithBody.java rename to unirest/src/main/java/unirest/HttpPatchWithBody.java index 8ae807a74..ce964428c 100644 --- a/src/main/java/unirest/HttpPatchWithBody.java +++ b/unirest/src/main/java/unirest/HttpPatchWithBody.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/HttpRequest.java b/unirest/src/main/java/unirest/HttpRequest.java similarity index 99% rename from src/main/java/unirest/HttpRequest.java rename to unirest/src/main/java/unirest/HttpRequest.java index ce36d08bb..9788dda20 100644 --- a/src/main/java/unirest/HttpRequest.java +++ b/unirest/src/main/java/unirest/HttpRequest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/HttpRequestBody.java b/unirest/src/main/java/unirest/HttpRequestBody.java similarity index 96% rename from src/main/java/unirest/HttpRequestBody.java rename to unirest/src/main/java/unirest/HttpRequestBody.java index e691a938c..f422e1815 100644 --- a/src/main/java/unirest/HttpRequestBody.java +++ b/unirest/src/main/java/unirest/HttpRequestBody.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/HttpRequestJsonPatch.java b/unirest/src/main/java/unirest/HttpRequestJsonPatch.java similarity index 95% rename from src/main/java/unirest/HttpRequestJsonPatch.java rename to unirest/src/main/java/unirest/HttpRequestJsonPatch.java index f0f5037a8..b98c1499f 100644 --- a/src/main/java/unirest/HttpRequestJsonPatch.java +++ b/unirest/src/main/java/unirest/HttpRequestJsonPatch.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/HttpRequestMultiPart.java b/unirest/src/main/java/unirest/HttpRequestMultiPart.java similarity index 97% rename from src/main/java/unirest/HttpRequestMultiPart.java rename to unirest/src/main/java/unirest/HttpRequestMultiPart.java index 693d84845..ec1e2c506 100644 --- a/src/main/java/unirest/HttpRequestMultiPart.java +++ b/unirest/src/main/java/unirest/HttpRequestMultiPart.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/HttpRequestNoBody.java b/unirest/src/main/java/unirest/HttpRequestNoBody.java similarity index 91% rename from src/main/java/unirest/HttpRequestNoBody.java rename to unirest/src/main/java/unirest/HttpRequestNoBody.java index 48bddb4d3..204a15f26 100644 --- a/src/main/java/unirest/HttpRequestNoBody.java +++ b/unirest/src/main/java/unirest/HttpRequestNoBody.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/HttpRequestUniBody.java b/unirest/src/main/java/unirest/HttpRequestUniBody.java similarity index 94% rename from src/main/java/unirest/HttpRequestUniBody.java rename to unirest/src/main/java/unirest/HttpRequestUniBody.java index 8508b8590..ca9de762d 100644 --- a/src/main/java/unirest/HttpRequestUniBody.java +++ b/unirest/src/main/java/unirest/HttpRequestUniBody.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/HttpRequestWithBody.java b/unirest/src/main/java/unirest/HttpRequestWithBody.java similarity index 94% rename from src/main/java/unirest/HttpRequestWithBody.java rename to unirest/src/main/java/unirest/HttpRequestWithBody.java index 5c63331f2..f3432ed5c 100644 --- a/src/main/java/unirest/HttpRequestWithBody.java +++ b/unirest/src/main/java/unirest/HttpRequestWithBody.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/HttpResponse.java b/unirest/src/main/java/unirest/HttpResponse.java similarity index 96% rename from src/main/java/unirest/HttpResponse.java rename to unirest/src/main/java/unirest/HttpResponse.java index 75ed78339..6dbb15dc0 100644 --- a/src/main/java/unirest/HttpResponse.java +++ b/unirest/src/main/java/unirest/HttpResponse.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/JsonNode.java b/unirest/src/main/java/unirest/JsonNode.java similarity index 94% rename from src/main/java/unirest/JsonNode.java rename to unirest/src/main/java/unirest/JsonNode.java index 427d8cea1..6581543f6 100644 --- a/src/main/java/unirest/JsonNode.java +++ b/unirest/src/main/java/unirest/JsonNode.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/JsonPatch.java b/unirest/src/main/java/unirest/JsonPatch.java similarity index 95% rename from src/main/java/unirest/JsonPatch.java rename to unirest/src/main/java/unirest/JsonPatch.java index b3b399235..796d38d21 100644 --- a/src/main/java/unirest/JsonPatch.java +++ b/unirest/src/main/java/unirest/JsonPatch.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/JsonPatchItem.java b/unirest/src/main/java/unirest/JsonPatchItem.java similarity index 95% rename from src/main/java/unirest/JsonPatchItem.java rename to unirest/src/main/java/unirest/JsonPatchItem.java index b0f672a31..65efb3360 100644 --- a/src/main/java/unirest/JsonPatchItem.java +++ b/unirest/src/main/java/unirest/JsonPatchItem.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/JsonPatchOperation.java b/unirest/src/main/java/unirest/JsonPatchOperation.java similarity index 92% rename from src/main/java/unirest/JsonPatchOperation.java rename to unirest/src/main/java/unirest/JsonPatchOperation.java index a67e5f208..ebc4cc393 100644 --- a/src/main/java/unirest/JsonPatchOperation.java +++ b/unirest/src/main/java/unirest/JsonPatchOperation.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/JsonPatchRequest.java b/unirest/src/main/java/unirest/JsonPatchRequest.java similarity index 92% rename from src/main/java/unirest/JsonPatchRequest.java rename to unirest/src/main/java/unirest/JsonPatchRequest.java index b94109bc4..873271fb0 100644 --- a/src/main/java/unirest/JsonPatchRequest.java +++ b/unirest/src/main/java/unirest/JsonPatchRequest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/JsonResponse.java b/unirest/src/main/java/unirest/JsonResponse.java similarity index 94% rename from src/main/java/unirest/JsonResponse.java rename to unirest/src/main/java/unirest/JsonResponse.java index 2ca59ec2d..18f14a696 100644 --- a/src/main/java/unirest/JsonResponse.java +++ b/unirest/src/main/java/unirest/JsonResponse.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/MultipartBody.java b/unirest/src/main/java/unirest/MultipartBody.java similarity index 97% rename from src/main/java/unirest/MultipartBody.java rename to unirest/src/main/java/unirest/MultipartBody.java index d0f58e122..daecc5649 100644 --- a/src/main/java/unirest/MultipartBody.java +++ b/unirest/src/main/java/unirest/MultipartBody.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/NoRedirects.java b/unirest/src/main/java/unirest/NoRedirects.java similarity index 92% rename from src/main/java/unirest/NoRedirects.java rename to unirest/src/main/java/unirest/NoRedirects.java index 552b316c1..f917b4d73 100644 --- a/src/main/java/unirest/NoRedirects.java +++ b/unirest/src/main/java/unirest/NoRedirects.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/ObjectMapper.java b/unirest/src/main/java/unirest/ObjectMapper.java similarity index 91% rename from src/main/java/unirest/ObjectMapper.java rename to unirest/src/main/java/unirest/ObjectMapper.java index 38a486eb7..9247b25a5 100644 --- a/src/main/java/unirest/ObjectMapper.java +++ b/unirest/src/main/java/unirest/ObjectMapper.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/ObjectResponse.java b/unirest/src/main/java/unirest/ObjectResponse.java similarity index 95% rename from src/main/java/unirest/ObjectResponse.java rename to unirest/src/main/java/unirest/ObjectResponse.java index 4083325bb..a7e8364f4 100644 --- a/src/main/java/unirest/ObjectResponse.java +++ b/unirest/src/main/java/unirest/ObjectResponse.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/PagedList.java b/unirest/src/main/java/unirest/PagedList.java similarity index 94% rename from src/main/java/unirest/PagedList.java rename to unirest/src/main/java/unirest/PagedList.java index d42a5797b..ca4b1eeb5 100644 --- a/src/main/java/unirest/PagedList.java +++ b/unirest/src/main/java/unirest/PagedList.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/Path.java b/unirest/src/main/java/unirest/Path.java similarity index 96% rename from src/main/java/unirest/Path.java rename to unirest/src/main/java/unirest/Path.java index 87162b371..0f91bd181 100644 --- a/src/main/java/unirest/Path.java +++ b/unirest/src/main/java/unirest/Path.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/RawResponse.java b/unirest/src/main/java/unirest/RawResponse.java similarity index 92% rename from src/main/java/unirest/RawResponse.java rename to unirest/src/main/java/unirest/RawResponse.java index b36132e24..bec3b14be 100644 --- a/src/main/java/unirest/RawResponse.java +++ b/unirest/src/main/java/unirest/RawResponse.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/RawResponseBase.java b/unirest/src/main/java/unirest/RawResponseBase.java similarity index 94% rename from src/main/java/unirest/RawResponseBase.java rename to unirest/src/main/java/unirest/RawResponseBase.java index c6ff15f1c..148fe2c67 100644 --- a/src/main/java/unirest/RawResponseBase.java +++ b/unirest/src/main/java/unirest/RawResponseBase.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/RequestBodyEntity.java b/unirest/src/main/java/unirest/RequestBodyEntity.java similarity index 91% rename from src/main/java/unirest/RequestBodyEntity.java rename to unirest/src/main/java/unirest/RequestBodyEntity.java index 6cd62bc03..11abfa571 100644 --- a/src/main/java/unirest/RequestBodyEntity.java +++ b/unirest/src/main/java/unirest/RequestBodyEntity.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/RequestPrep.java b/unirest/src/main/java/unirest/RequestPrep.java similarity index 97% rename from src/main/java/unirest/RequestPrep.java rename to unirest/src/main/java/unirest/RequestPrep.java index cc4747d55..e9eed7df7 100644 --- a/src/main/java/unirest/RequestPrep.java +++ b/unirest/src/main/java/unirest/RequestPrep.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/StringResponse.java b/unirest/src/main/java/unirest/StringResponse.java similarity index 92% rename from src/main/java/unirest/StringResponse.java rename to unirest/src/main/java/unirest/StringResponse.java index 30f964ce0..3647f676a 100644 --- a/src/main/java/unirest/StringResponse.java +++ b/unirest/src/main/java/unirest/StringResponse.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/SyncIdleConnectionMonitorThread.java b/unirest/src/main/java/unirest/SyncIdleConnectionMonitorThread.java similarity index 93% rename from src/main/java/unirest/SyncIdleConnectionMonitorThread.java rename to unirest/src/main/java/unirest/SyncIdleConnectionMonitorThread.java index d92b8440f..8018f080c 100644 --- a/src/main/java/unirest/SyncIdleConnectionMonitorThread.java +++ b/unirest/src/main/java/unirest/SyncIdleConnectionMonitorThread.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/Unirest.java b/unirest/src/main/java/unirest/Unirest.java similarity index 97% rename from src/main/java/unirest/Unirest.java rename to unirest/src/main/java/unirest/Unirest.java index e72f5a9ea..c47b67abd 100644 --- a/src/main/java/unirest/Unirest.java +++ b/unirest/src/main/java/unirest/Unirest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/UnirestConfigException.java b/unirest/src/main/java/unirest/UnirestConfigException.java similarity index 91% rename from src/main/java/unirest/UnirestConfigException.java rename to unirest/src/main/java/unirest/UnirestConfigException.java index 1f5f47edf..74f479ed4 100644 --- a/src/main/java/unirest/UnirestConfigException.java +++ b/unirest/src/main/java/unirest/UnirestConfigException.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/UnirestException.java b/unirest/src/main/java/unirest/UnirestException.java similarity index 92% rename from src/main/java/unirest/UnirestException.java rename to unirest/src/main/java/unirest/UnirestException.java index 50fba4f6a..cd6e03cae 100644 --- a/src/main/java/unirest/UnirestException.java +++ b/unirest/src/main/java/unirest/UnirestException.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/UnirestInstance.java b/unirest/src/main/java/unirest/UnirestInstance.java similarity index 97% rename from src/main/java/unirest/UnirestInstance.java rename to unirest/src/main/java/unirest/UnirestInstance.java index ad6d9eb0f..4d89f52b0 100644 --- a/src/main/java/unirest/UnirestInstance.java +++ b/unirest/src/main/java/unirest/UnirestInstance.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/UnirestParsingException.java b/unirest/src/main/java/unirest/UnirestParsingException.java similarity index 91% rename from src/main/java/unirest/UnirestParsingException.java rename to unirest/src/main/java/unirest/UnirestParsingException.java index 6721fc64e..92d877e47 100644 --- a/src/main/java/unirest/UnirestParsingException.java +++ b/unirest/src/main/java/unirest/UnirestParsingException.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/main/java/unirest/Util.java b/unirest/src/main/java/unirest/Util.java similarity index 96% rename from src/main/java/unirest/Util.java rename to unirest/src/main/java/unirest/Util.java index 4fe231fac..bb49f6aa6 100644 --- a/src/main/java/unirest/Util.java +++ b/unirest/src/main/java/unirest/Util.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/AsBinaryTest.java b/unirest/src/test/java/BehaviorTests/AsBinaryTest.java similarity index 95% rename from src/test/java/BehaviorTests/AsBinaryTest.java rename to unirest/src/test/java/BehaviorTests/AsBinaryTest.java index b75cadfc9..00e4c9e30 100644 --- a/src/test/java/BehaviorTests/AsBinaryTest.java +++ b/unirest/src/test/java/BehaviorTests/AsBinaryTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/AsEmptyTest.java b/unirest/src/test/java/BehaviorTests/AsEmptyTest.java similarity index 94% rename from src/test/java/BehaviorTests/AsEmptyTest.java rename to unirest/src/test/java/BehaviorTests/AsEmptyTest.java index 19bd53ec9..fc586f3cc 100644 --- a/src/test/java/BehaviorTests/AsEmptyTest.java +++ b/unirest/src/test/java/BehaviorTests/AsEmptyTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/AsFileTests.java b/unirest/src/test/java/BehaviorTests/AsFileTests.java similarity index 96% rename from src/test/java/BehaviorTests/AsFileTests.java rename to unirest/src/test/java/BehaviorTests/AsFileTests.java index db2a66e24..064b9664a 100644 --- a/src/test/java/BehaviorTests/AsFileTests.java +++ b/unirest/src/test/java/BehaviorTests/AsFileTests.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/AsGenericTypeTest.java b/unirest/src/test/java/BehaviorTests/AsGenericTypeTest.java similarity index 96% rename from src/test/java/BehaviorTests/AsGenericTypeTest.java rename to unirest/src/test/java/BehaviorTests/AsGenericTypeTest.java index 5281e87fe..6cea2f892 100644 --- a/src/test/java/BehaviorTests/AsGenericTypeTest.java +++ b/unirest/src/test/java/BehaviorTests/AsGenericTypeTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/AsJsonTest.java b/unirest/src/test/java/BehaviorTests/AsJsonTest.java similarity index 96% rename from src/test/java/BehaviorTests/AsJsonTest.java rename to unirest/src/test/java/BehaviorTests/AsJsonTest.java index ffa4fcd06..b82901e7f 100644 --- a/src/test/java/BehaviorTests/AsJsonTest.java +++ b/unirest/src/test/java/BehaviorTests/AsJsonTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/AsObjectTest.java b/unirest/src/test/java/BehaviorTests/AsObjectTest.java similarity index 97% rename from src/test/java/BehaviorTests/AsObjectTest.java rename to unirest/src/test/java/BehaviorTests/AsObjectTest.java index c2a5f2f81..8c2f8d4e9 100644 --- a/src/test/java/BehaviorTests/AsObjectTest.java +++ b/unirest/src/test/java/BehaviorTests/AsObjectTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/AsStringTest.java b/unirest/src/test/java/BehaviorTests/AsStringTest.java similarity index 97% rename from src/test/java/BehaviorTests/AsStringTest.java rename to unirest/src/test/java/BehaviorTests/AsStringTest.java index fcb89fc4b..3fd6c4f76 100644 --- a/src/test/java/BehaviorTests/AsStringTest.java +++ b/unirest/src/test/java/BehaviorTests/AsStringTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/BddTest.java b/unirest/src/test/java/BehaviorTests/BddTest.java similarity index 95% rename from src/test/java/BehaviorTests/BddTest.java rename to unirest/src/test/java/BehaviorTests/BddTest.java index 50640d836..9d84c96cd 100644 --- a/src/test/java/BehaviorTests/BddTest.java +++ b/unirest/src/test/java/BehaviorTests/BddTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/CallbackFutureTest.java b/unirest/src/test/java/BehaviorTests/CallbackFutureTest.java similarity index 94% rename from src/test/java/BehaviorTests/CallbackFutureTest.java rename to unirest/src/test/java/BehaviorTests/CallbackFutureTest.java index cc760236d..8956c619b 100644 --- a/src/test/java/BehaviorTests/CallbackFutureTest.java +++ b/unirest/src/test/java/BehaviorTests/CallbackFutureTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/ConsumerTests.java b/unirest/src/test/java/BehaviorTests/ConsumerTests.java similarity index 93% rename from src/test/java/BehaviorTests/ConsumerTests.java rename to unirest/src/test/java/BehaviorTests/ConsumerTests.java index 12d692794..8ba91690e 100644 --- a/src/test/java/BehaviorTests/ConsumerTests.java +++ b/unirest/src/test/java/BehaviorTests/ConsumerTests.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/DefectTest.java b/unirest/src/test/java/BehaviorTests/DefectTest.java similarity index 96% rename from src/test/java/BehaviorTests/DefectTest.java rename to unirest/src/test/java/BehaviorTests/DefectTest.java index 20c2a1079..5e220f6d4 100644 --- a/src/test/java/BehaviorTests/DefectTest.java +++ b/unirest/src/test/java/BehaviorTests/DefectTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/Foo.java b/unirest/src/test/java/BehaviorTests/Foo.java similarity index 91% rename from src/test/java/BehaviorTests/Foo.java rename to unirest/src/test/java/BehaviorTests/Foo.java index 7dcb38fe3..1dd0abbeb 100644 --- a/src/test/java/BehaviorTests/Foo.java +++ b/unirest/src/test/java/BehaviorTests/Foo.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/FormPostingTest.java b/unirest/src/test/java/BehaviorTests/FormPostingTest.java similarity index 99% rename from src/test/java/BehaviorTests/FormPostingTest.java rename to unirest/src/test/java/BehaviorTests/FormPostingTest.java index 2639d40e5..8fe817bdb 100644 --- a/src/test/java/BehaviorTests/FormPostingTest.java +++ b/unirest/src/test/java/BehaviorTests/FormPostingTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/GZipTest.java b/unirest/src/test/java/BehaviorTests/GZipTest.java similarity index 93% rename from src/test/java/BehaviorTests/GZipTest.java rename to unirest/src/test/java/BehaviorTests/GZipTest.java index 7f6326fc3..82751a5ea 100644 --- a/src/test/java/BehaviorTests/GZipTest.java +++ b/unirest/src/test/java/BehaviorTests/GZipTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/GetResponse.java b/unirest/src/test/java/BehaviorTests/GetResponse.java similarity index 91% rename from src/test/java/BehaviorTests/GetResponse.java rename to unirest/src/test/java/BehaviorTests/GetResponse.java index 096d34edf..645108683 100644 --- a/src/test/java/BehaviorTests/GetResponse.java +++ b/unirest/src/test/java/BehaviorTests/GetResponse.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/HeaderTest.java b/unirest/src/test/java/BehaviorTests/HeaderTest.java similarity index 98% rename from src/test/java/BehaviorTests/HeaderTest.java rename to unirest/src/test/java/BehaviorTests/HeaderTest.java index d6d3f1ef7..24160e2a1 100644 --- a/src/test/java/BehaviorTests/HeaderTest.java +++ b/unirest/src/test/java/BehaviorTests/HeaderTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/InterceptorTest.java b/unirest/src/test/java/BehaviorTests/InterceptorTest.java similarity index 94% rename from src/test/java/BehaviorTests/InterceptorTest.java rename to unirest/src/test/java/BehaviorTests/InterceptorTest.java index b08533ce5..d056793f8 100644 --- a/src/test/java/BehaviorTests/InterceptorTest.java +++ b/unirest/src/test/java/BehaviorTests/InterceptorTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/JankyProxy.java b/unirest/src/test/java/BehaviorTests/JankyProxy.java similarity index 97% rename from src/test/java/BehaviorTests/JankyProxy.java rename to unirest/src/test/java/BehaviorTests/JankyProxy.java index 1ab676bc2..4e9472e83 100644 --- a/src/test/java/BehaviorTests/JankyProxy.java +++ b/unirest/src/test/java/BehaviorTests/JankyProxy.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/JsonPatchTest.java b/unirest/src/test/java/BehaviorTests/JsonPatchTest.java similarity index 97% rename from src/test/java/BehaviorTests/JsonPatchTest.java rename to unirest/src/test/java/BehaviorTests/JsonPatchTest.java index 27d48e0b7..697a1593c 100644 --- a/src/test/java/BehaviorTests/JsonPatchTest.java +++ b/unirest/src/test/java/BehaviorTests/JsonPatchTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/LifeCycleTest.java b/unirest/src/test/java/BehaviorTests/LifeCycleTest.java similarity index 97% rename from src/test/java/BehaviorTests/LifeCycleTest.java rename to unirest/src/test/java/BehaviorTests/LifeCycleTest.java index c202e2513..c9a778333 100644 --- a/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/unirest/src/test/java/BehaviorTests/LifeCycleTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/MockServer.java b/unirest/src/test/java/BehaviorTests/MockServer.java similarity index 98% rename from src/test/java/BehaviorTests/MockServer.java rename to unirest/src/test/java/BehaviorTests/MockServer.java index 9c368d5f0..fc4ff0908 100644 --- a/src/test/java/BehaviorTests/MockServer.java +++ b/unirest/src/test/java/BehaviorTests/MockServer.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/ObjectFunctionalTest.java b/unirest/src/test/java/BehaviorTests/ObjectFunctionalTest.java similarity index 94% rename from src/test/java/BehaviorTests/ObjectFunctionalTest.java rename to unirest/src/test/java/BehaviorTests/ObjectFunctionalTest.java index b619d2fc8..418c3f2e5 100644 --- a/src/test/java/BehaviorTests/ObjectFunctionalTest.java +++ b/unirest/src/test/java/BehaviorTests/ObjectFunctionalTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/PagingTest.java b/unirest/src/test/java/BehaviorTests/PagingTest.java similarity index 93% rename from src/test/java/BehaviorTests/PagingTest.java rename to unirest/src/test/java/BehaviorTests/PagingTest.java index 0627a7c42..1b112b034 100644 --- a/src/test/java/BehaviorTests/PagingTest.java +++ b/unirest/src/test/java/BehaviorTests/PagingTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/Pair.java b/unirest/src/test/java/BehaviorTests/Pair.java similarity index 91% rename from src/test/java/BehaviorTests/Pair.java rename to unirest/src/test/java/BehaviorTests/Pair.java index 3ea3bc75e..c4b3ad4ee 100644 --- a/src/test/java/BehaviorTests/Pair.java +++ b/unirest/src/test/java/BehaviorTests/Pair.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/PathParamTest.java b/unirest/src/test/java/BehaviorTests/PathParamTest.java similarity index 96% rename from src/test/java/BehaviorTests/PathParamTest.java rename to unirest/src/test/java/BehaviorTests/PathParamTest.java index 63896eb60..043cc0cfa 100644 --- a/src/test/java/BehaviorTests/PathParamTest.java +++ b/unirest/src/test/java/BehaviorTests/PathParamTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/PostRequestHandlersTest.java b/unirest/src/test/java/BehaviorTests/PostRequestHandlersTest.java similarity index 96% rename from src/test/java/BehaviorTests/PostRequestHandlersTest.java rename to unirest/src/test/java/BehaviorTests/PostRequestHandlersTest.java index 10df1becf..7f73fe545 100644 --- a/src/test/java/BehaviorTests/PostRequestHandlersTest.java +++ b/unirest/src/test/java/BehaviorTests/PostRequestHandlersTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/ProxyTest.java b/unirest/src/test/java/BehaviorTests/ProxyTest.java similarity index 96% rename from src/test/java/BehaviorTests/ProxyTest.java rename to unirest/src/test/java/BehaviorTests/ProxyTest.java index e7d6dbb71..8d3c64a57 100644 --- a/src/test/java/BehaviorTests/ProxyTest.java +++ b/unirest/src/test/java/BehaviorTests/ProxyTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/QueryStringTest.java b/unirest/src/test/java/BehaviorTests/QueryStringTest.java similarity index 97% rename from src/test/java/BehaviorTests/QueryStringTest.java rename to unirest/src/test/java/BehaviorTests/QueryStringTest.java index c9ea2fd4f..e4f18f098 100644 --- a/src/test/java/BehaviorTests/QueryStringTest.java +++ b/unirest/src/test/java/BehaviorTests/QueryStringTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/RedirectHandling.java b/unirest/src/test/java/BehaviorTests/RedirectHandling.java similarity index 94% rename from src/test/java/BehaviorTests/RedirectHandling.java rename to unirest/src/test/java/BehaviorTests/RedirectHandling.java index 3cc69b675..1f3a578ce 100644 --- a/src/test/java/BehaviorTests/RedirectHandling.java +++ b/unirest/src/test/java/BehaviorTests/RedirectHandling.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/RequestCapture.java b/unirest/src/test/java/BehaviorTests/RequestCapture.java similarity index 98% rename from src/test/java/BehaviorTests/RequestCapture.java rename to unirest/src/test/java/BehaviorTests/RequestCapture.java index 09453ccdb..4e38514a2 100644 --- a/src/test/java/BehaviorTests/RequestCapture.java +++ b/unirest/src/test/java/BehaviorTests/RequestCapture.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/ResponseHeaderTest.java b/unirest/src/test/java/BehaviorTests/ResponseHeaderTest.java similarity index 95% rename from src/test/java/BehaviorTests/ResponseHeaderTest.java rename to unirest/src/test/java/BehaviorTests/ResponseHeaderTest.java index 60f0ed394..a56400400 100644 --- a/src/test/java/BehaviorTests/ResponseHeaderTest.java +++ b/unirest/src/test/java/BehaviorTests/ResponseHeaderTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/SendBodyTest.java b/unirest/src/test/java/BehaviorTests/SendBodyTest.java similarity index 97% rename from src/test/java/BehaviorTests/SendBodyTest.java rename to unirest/src/test/java/BehaviorTests/SendBodyTest.java index 14f1d03d6..fc3e9cb7d 100644 --- a/src/test/java/BehaviorTests/SendBodyTest.java +++ b/unirest/src/test/java/BehaviorTests/SendBodyTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/TimeoutTests.java b/unirest/src/test/java/BehaviorTests/TimeoutTests.java similarity index 97% rename from src/test/java/BehaviorTests/TimeoutTests.java rename to unirest/src/test/java/BehaviorTests/TimeoutTests.java index 2476fc861..3e2abe852 100644 --- a/src/test/java/BehaviorTests/TimeoutTests.java +++ b/unirest/src/test/java/BehaviorTests/TimeoutTests.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/BehaviorTests/VerbTest.java b/unirest/src/test/java/BehaviorTests/VerbTest.java similarity index 95% rename from src/test/java/BehaviorTests/VerbTest.java rename to unirest/src/test/java/BehaviorTests/VerbTest.java index acbc26778..b3811a205 100644 --- a/src/test/java/BehaviorTests/VerbTest.java +++ b/unirest/src/test/java/BehaviorTests/VerbTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/unirest/ClientFactoryTest.java b/unirest/src/test/java/unirest/ClientFactoryTest.java similarity index 95% rename from src/test/java/unirest/ClientFactoryTest.java rename to unirest/src/test/java/unirest/ClientFactoryTest.java index 305400287..3137245c9 100644 --- a/src/test/java/unirest/ClientFactoryTest.java +++ b/unirest/src/test/java/unirest/ClientFactoryTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/unirest/ConfigTest.java b/unirest/src/test/java/unirest/ConfigTest.java similarity index 98% rename from src/test/java/unirest/ConfigTest.java rename to unirest/src/test/java/unirest/ConfigTest.java index 94ad29d56..767b18ad1 100644 --- a/src/test/java/unirest/ConfigTest.java +++ b/unirest/src/test/java/unirest/ConfigTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/unirest/GsonObjectMapper.java b/unirest/src/test/java/unirest/GsonObjectMapper.java similarity index 92% rename from src/test/java/unirest/GsonObjectMapper.java rename to unirest/src/test/java/unirest/GsonObjectMapper.java index b3eff147d..3c610364c 100644 --- a/src/test/java/unirest/GsonObjectMapper.java +++ b/unirest/src/test/java/unirest/GsonObjectMapper.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/unirest/HeadersTest.java b/unirest/src/test/java/unirest/HeadersTest.java similarity index 92% rename from src/test/java/unirest/HeadersTest.java rename to unirest/src/test/java/unirest/HeadersTest.java index 0f9802dab..fcea390d7 100644 --- a/src/test/java/unirest/HeadersTest.java +++ b/unirest/src/test/java/unirest/HeadersTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/unirest/JacksonObjectMapper.java b/unirest/src/test/java/unirest/JacksonObjectMapper.java similarity index 97% rename from src/test/java/unirest/JacksonObjectMapper.java rename to unirest/src/test/java/unirest/JacksonObjectMapper.java index 2195b9623..35206a48d 100644 --- a/src/test/java/unirest/JacksonObjectMapper.java +++ b/unirest/src/test/java/unirest/JacksonObjectMapper.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/unirest/JacksonObjectMapperTest.java b/unirest/src/test/java/unirest/JacksonObjectMapperTest.java similarity index 94% rename from src/test/java/unirest/JacksonObjectMapperTest.java rename to unirest/src/test/java/unirest/JacksonObjectMapperTest.java index b1db84fca..cc7f974fd 100644 --- a/src/test/java/unirest/JacksonObjectMapperTest.java +++ b/unirest/src/test/java/unirest/JacksonObjectMapperTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/unirest/JsonNodeTest.java b/unirest/src/test/java/unirest/JsonNodeTest.java similarity index 94% rename from src/test/java/unirest/JsonNodeTest.java rename to unirest/src/test/java/unirest/JsonNodeTest.java index e21c99b05..70d704273 100644 --- a/src/test/java/unirest/JsonNodeTest.java +++ b/unirest/src/test/java/unirest/JsonNodeTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/unirest/MockCallback.java b/unirest/src/test/java/unirest/MockCallback.java similarity index 94% rename from src/test/java/unirest/MockCallback.java rename to unirest/src/test/java/unirest/MockCallback.java index 9ef28908c..c1c6a6cba 100644 --- a/src/test/java/unirest/MockCallback.java +++ b/unirest/src/test/java/unirest/MockCallback.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/unirest/NoopCallback.java b/unirest/src/test/java/unirest/NoopCallback.java similarity index 91% rename from src/test/java/unirest/NoopCallback.java rename to unirest/src/test/java/unirest/NoopCallback.java index cacfbc3ed..9fa308c8c 100644 --- a/src/test/java/unirest/NoopCallback.java +++ b/unirest/src/test/java/unirest/NoopCallback.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/unirest/NotImplimented.java b/unirest/src/test/java/unirest/NotImplimented.java similarity index 90% rename from src/test/java/unirest/NotImplimented.java rename to unirest/src/test/java/unirest/NotImplimented.java index 10915f499..72daaf8d7 100644 --- a/src/test/java/unirest/NotImplimented.java +++ b/unirest/src/test/java/unirest/NotImplimented.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/unirest/PagedListTest.java b/unirest/src/test/java/unirest/PagedListTest.java similarity index 96% rename from src/test/java/unirest/PagedListTest.java rename to unirest/src/test/java/unirest/PagedListTest.java index 2ebc5ff1e..d9d911f79 100644 --- a/src/test/java/unirest/PagedListTest.java +++ b/unirest/src/test/java/unirest/PagedListTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/unirest/ResponseUtilsTest.java b/unirest/src/test/java/unirest/ResponseUtilsTest.java similarity index 96% rename from src/test/java/unirest/ResponseUtilsTest.java rename to unirest/src/test/java/unirest/ResponseUtilsTest.java index 605458ba7..10c45ba27 100644 --- a/src/test/java/unirest/ResponseUtilsTest.java +++ b/unirest/src/test/java/unirest/ResponseUtilsTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/unirest/TestUtil.java b/unirest/src/test/java/unirest/TestUtil.java similarity index 97% rename from src/test/java/unirest/TestUtil.java rename to unirest/src/test/java/unirest/TestUtil.java index 7db3ef2e7..376e84384 100644 --- a/src/test/java/unirest/TestUtil.java +++ b/unirest/src/test/java/unirest/TestUtil.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/unirest/UriFormatterTest.java b/unirest/src/test/java/unirest/UriFormatterTest.java similarity index 93% rename from src/test/java/unirest/UriFormatterTest.java rename to unirest/src/test/java/unirest/UriFormatterTest.java index 66acbc9c4..344dc4943 100644 --- a/src/test/java/unirest/UriFormatterTest.java +++ b/unirest/src/test/java/unirest/UriFormatterTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/java/unirest/UtilTest.java b/unirest/src/test/java/unirest/UtilTest.java similarity index 93% rename from src/test/java/unirest/UtilTest.java rename to unirest/src/test/java/unirest/UtilTest.java index 29f6697f0..d5a480412 100644 --- a/src/test/java/unirest/UtilTest.java +++ b/unirest/src/test/java/unirest/UtilTest.java @@ -1,8 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. - * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/test/resources/data/cp1250.txt b/unirest/src/test/resources/data/cp1250.txt similarity index 100% rename from src/test/resources/data/cp1250.txt rename to unirest/src/test/resources/data/cp1250.txt diff --git a/src/test/resources/image.jpg b/unirest/src/test/resources/image.jpg similarity index 100% rename from src/test/resources/image.jpg rename to unirest/src/test/resources/image.jpg diff --git a/src/test/resources/test b/unirest/src/test/resources/test similarity index 100% rename from src/test/resources/test rename to unirest/src/test/resources/test diff --git a/src/test/resources/test-json-patch.json b/unirest/src/test/resources/test-json-patch.json similarity index 100% rename from src/test/resources/test-json-patch.json rename to unirest/src/test/resources/test-json-patch.json From abcf69f49c0c247abe191f7447f0d32ece2c6de1 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 19 Feb 2019 20:38:10 -0600 Subject: [PATCH 0451/1769] rm deprecated asBinary methods. There are better ways to deal with raw InputStreams --- .../src/main/java/unirest/BaseRequest.java | 18 ---- .../src/main/java/unirest/BinaryResponse.java | 49 ----------- .../src/main/java/unirest/HttpRequest.java | 27 ------ .../test/java/BehaviorTests/AsBinaryTest.java | 82 ------------------- .../java/BehaviorTests/LifeCycleTest.java | 6 +- .../java/BehaviorTests/PathParamTest.java | 4 +- .../java/BehaviorTests/RedirectHandling.java | 6 +- .../src/test/java/BehaviorTests/VerbTest.java | 2 +- 8 files changed, 9 insertions(+), 185 deletions(-) delete mode 100644 unirest/src/main/java/unirest/BinaryResponse.java delete mode 100644 unirest/src/test/java/BehaviorTests/AsBinaryTest.java diff --git a/unirest/src/main/java/unirest/BaseRequest.java b/unirest/src/main/java/unirest/BaseRequest.java index f95a0a0b7..3cce35232 100644 --- a/unirest/src/main/java/unirest/BaseRequest.java +++ b/unirest/src/main/java/unirest/BaseRequest.java @@ -26,7 +26,6 @@ package unirest; import java.io.File; -import java.io.InputStream; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; @@ -225,23 +224,6 @@ private Function> funcResponse(Function new BasicResponse<>(r, function.apply(r)); } - @Override - public HttpResponse asBinary() throws UnirestException { - return config.getClient().request(this, BinaryResponse::new); - } - - @Override - public CompletableFuture> asBinaryAsync() { - - return config.getAsyncClient().request(this, BinaryResponse::new, new CompletableFuture<>()); - } - - @Override - public CompletableFuture> asBinaryAsync(Callback callback) { - - return config.getAsyncClient().request(this, BinaryResponse::new, CallbackFuture.wrap(callback)); - } - @Override public void thenConsume(Consumer consumer) { config.getClient().request(this, getConsumer(consumer)); diff --git a/unirest/src/main/java/unirest/BinaryResponse.java b/unirest/src/main/java/unirest/BinaryResponse.java deleted file mode 100644 index b8ea4cbd5..000000000 --- a/unirest/src/main/java/unirest/BinaryResponse.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package unirest; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; - -public class BinaryResponse extends BaseResponse { - - private InputStream body; - - protected BinaryResponse(RawResponse response) { - super(response); - body = new ByteArrayInputStream(response.getContentAsBytes()); - } - - @Override - public InputStream getRawBody() { - return body; - } - - @Override - public InputStream getBody() { - return body; - } -} diff --git a/unirest/src/main/java/unirest/HttpRequest.java b/unirest/src/main/java/unirest/HttpRequest.java index 9788dda20..1dbd0db27 100644 --- a/unirest/src/main/java/unirest/HttpRequest.java +++ b/unirest/src/main/java/unirest/HttpRequest.java @@ -26,7 +26,6 @@ package unirest; import java.io.File; -import java.io.InputStream; import java.util.Collection; import java.util.Map; import java.util.concurrent.CompletableFuture; @@ -233,14 +232,6 @@ public interface HttpRequest { */ CompletableFuture> asObjectAsync(Function function); - /** - * Executes the request and returns a copy of the original InputStream - * @deprecated This method returns a copy of the original stream and is not suitable for streaming. Use asObject(Function<RawResponse, T> function) - * @return a HttpResponse with a InputStream - */ - @Deprecated - HttpResponse asBinary(); - /** * Executes the request and writes the contents into a file * @param path The path to the file. @@ -274,24 +265,6 @@ public interface HttpRequest { */ PagedList asPaged(Function mappingFunction, Function, String> linkExtractor); - - /** - * Executes the request asynchronously and returns a copy of the original InputStream - * @deprecated This method returns a copy of the original stream and is not suitable for streaming. Use asObjectAsync(Function<RawResponse, T> function) - * @return a CompletableFuture of a HttpResponse with a InputStream - */ - @Deprecated - CompletableFuture> asBinaryAsync(); - - /** - * Executes the request asynchronously and returns a copy of the original InputStream which is passed to a callback - * @param callback the callback - * @deprecated This method returns a copy of the original stream and is not suitable for streaming. Use asObjectAsync(Function<RawResponse, T> function) - * @return a CompletableFuture of a HttpResponse with a InputStream - */ - @Deprecated - CompletableFuture> asBinaryAsync(Callback callback); - /** * Executes the request and returns the response without parsing the body * @return the basic HttpResponse diff --git a/unirest/src/test/java/BehaviorTests/AsBinaryTest.java b/unirest/src/test/java/BehaviorTests/AsBinaryTest.java deleted file mode 100644 index 00e4c9e30..000000000 --- a/unirest/src/test/java/BehaviorTests/AsBinaryTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package BehaviorTests; - -import unirest.HttpResponse; -import unirest.Unirest; -import org.junit.Test; -import unirest.TestUtil; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.concurrent.CompletableFuture; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -public class AsBinaryTest extends BddTest { - @Test - public void whenNoBodyIsReturned() throws IOException { - HttpResponse i = Unirest.get(MockServer.NOBODY).asBinary(); - - assertEquals(200, i.getStatus()); - assertEquals(0, i.getBody().available()); - } - - @Test - public void canGetBinaryResponse() { - HttpResponse i = Unirest.get(MockServer.GET) - .queryString("foo", "bar") - .asBinary(); - - RequestCapture cap = TestUtil.readValue(i.getBody(), RequestCapture.class); - cap.assertParam("foo", "bar"); - } - - @Test - public void canGetBinaryResponseAsync() throws Exception { - CompletableFuture> r = Unirest.get(MockServer.GET) - .queryString("foo", "bar") - .asBinaryAsync(); - - RequestCapture cap = TestUtil.readValue(r.get().getBody(), RequestCapture.class); - cap.assertParam("foo", "bar"); - } - - @Test - public void canGetBinaryResponseAsyncWithCallback() { - Unirest.get(MockServer.GET) - .queryString("foo", "bar") - .asBinaryAsync(r -> { - RequestCapture cap = TestUtil.readValue(r.getBody(), RequestCapture.class); - cap.assertParam("foo", "bar"); - asyncSuccess(); - }); - - assertAsync(); - } -} diff --git a/unirest/src/test/java/BehaviorTests/LifeCycleTest.java b/unirest/src/test/java/BehaviorTests/LifeCycleTest.java index c9a778333..d74710f88 100644 --- a/unirest/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/unirest/src/test/java/BehaviorTests/LifeCycleTest.java @@ -96,13 +96,13 @@ public void willNotShutdownInactiveAsyncClient() throws IOException { @Test public void canDetectIfSystemIsRunning() { - Unirest.get(MockServer.GET).asBinary(); + Unirest.get(MockServer.GET).asEmpty(); assertTrue(Unirest.isRunning()); Unirest.shutDown(); assertFalse(Unirest.isRunning()); - Unirest.get(MockServer.GET).asBinary(); + Unirest.get(MockServer.GET).asEmpty(); assertTrue(Unirest.isRunning()); } @@ -111,7 +111,7 @@ public void willReinitIfLibraryIsUsedAfterShutdown() { Unirest.shutDown(); assertFalse(Unirest.isRunning()); - Unirest.get(MockServer.GET).asBinary(); + Unirest.get(MockServer.GET).asEmpty(); assertTrue(Unirest.isRunning()); } diff --git a/unirest/src/test/java/BehaviorTests/PathParamTest.java b/unirest/src/test/java/BehaviorTests/PathParamTest.java index 043cc0cfa..7a301e9f2 100644 --- a/unirest/src/test/java/BehaviorTests/PathParamTest.java +++ b/unirest/src/test/java/BehaviorTests/PathParamTest.java @@ -70,7 +70,7 @@ public void testMissingPathParameter() { Unirest.get(MockServer.HOST + "/{method}") .routeParam("method222", "get") .queryString("name", "Mark") - .asBinary(), + .asEmpty(), UnirestException.class, "Can't find route parameter name \"method222\""); } @@ -80,7 +80,7 @@ public void testMissingPathParameterValue() { TestUtil.assertException(() -> Unirest.get(MockServer.HOST + "/{method}") .queryString("name", "Mark") - .asBinary(), + .asEmpty(), UnirestException.class, "java.lang.IllegalArgumentException: Illegal character in path at index 22: http://localhost:4567/{method}?name=Mark"); } diff --git a/unirest/src/test/java/BehaviorTests/RedirectHandling.java b/unirest/src/test/java/BehaviorTests/RedirectHandling.java index 1f3a578ce..dc9031e2a 100644 --- a/unirest/src/test/java/BehaviorTests/RedirectHandling.java +++ b/unirest/src/test/java/BehaviorTests/RedirectHandling.java @@ -46,7 +46,7 @@ public void willFollowRedirectsByDefault() { @Test public void canDisableRedirects(){ Unirest.config().followRedirects(false); - HttpResponse response = Unirest.get(MockServer.REDIRECT).asBinary(); + HttpResponse response = Unirest.get(MockServer.REDIRECT).asEmpty(); assertEquals(301, response.getStatus()); } @@ -61,9 +61,9 @@ public void willFollowRedirectsByDefaultAsync() throws ExecutionException, Inter } @Test - public void canDisableRedirectsAsync() throws ExecutionException, InterruptedException { + public void canDisableRedirectsAsync() throws Exception { Unirest.config().followRedirects(false); - HttpResponse response = Unirest.get(MockServer.REDIRECT).asBinaryAsync().get(); + HttpResponse response = Unirest.get(MockServer.REDIRECT).asEmptyAsync().get(); assertEquals(301, response.getStatus()); } diff --git a/unirest/src/test/java/BehaviorTests/VerbTest.java b/unirest/src/test/java/BehaviorTests/VerbTest.java index b3811a205..c6666c69d 100644 --- a/unirest/src/test/java/BehaviorTests/VerbTest.java +++ b/unirest/src/test/java/BehaviorTests/VerbTest.java @@ -69,7 +69,7 @@ public void patch() { @Test public void head() { - HttpResponse response = Unirest.head(MockServer.GET).asBinary(); + HttpResponse response = Unirest.head(MockServer.GET).asEmpty(); assertEquals(200, response.getStatus()); assertEquals("text/html;charset=utf-8", response.getHeaders().getFirst("Content-Type")); From 012fdddf6259d31b94f72d6e01fef209f4377046 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 19 Feb 2019 20:45:55 -0600 Subject: [PATCH 0452/1769] fix copyright header --- build/fileHeader.txt | 2 +- unirest/src/main/java/unirest/ApacheAsyncClient.java | 2 +- unirest/src/main/java/unirest/ApacheClient.java | 2 +- unirest/src/main/java/unirest/ApacheRequestWithBody.java | 2 +- unirest/src/main/java/unirest/ApacheResponse.java | 2 +- unirest/src/main/java/unirest/AsyncClient.java | 2 +- .../src/main/java/unirest/AsyncIdleConnectionMonitorThread.java | 2 +- unirest/src/main/java/unirest/BaseApacheClient.java | 2 +- unirest/src/main/java/unirest/BaseRequest.java | 2 +- unirest/src/main/java/unirest/BaseResponse.java | 2 +- unirest/src/main/java/unirest/BasicResponse.java | 2 +- unirest/src/main/java/unirest/Body.java | 2 +- unirest/src/main/java/unirest/Callback.java | 2 +- unirest/src/main/java/unirest/CallbackFuture.java | 2 +- unirest/src/main/java/unirest/Client.java | 2 +- unirest/src/main/java/unirest/Config.java | 2 +- unirest/src/main/java/unirest/Empty.java | 2 +- unirest/src/main/java/unirest/EmptyResponse.java | 2 +- unirest/src/main/java/unirest/FileResponse.java | 2 +- unirest/src/main/java/unirest/FormPart.java | 2 +- unirest/src/main/java/unirest/GenericType.java | 2 +- unirest/src/main/java/unirest/GetRequest.java | 2 +- unirest/src/main/java/unirest/Header.java | 2 +- unirest/src/main/java/unirest/HeaderNames.java | 2 +- unirest/src/main/java/unirest/Headers.java | 2 +- unirest/src/main/java/unirest/HttpDeleteWithBody.java | 2 +- unirest/src/main/java/unirest/HttpMethod.java | 2 +- unirest/src/main/java/unirest/HttpPatchWithBody.java | 2 +- unirest/src/main/java/unirest/HttpRequest.java | 2 +- unirest/src/main/java/unirest/HttpRequestBody.java | 2 +- unirest/src/main/java/unirest/HttpRequestJsonPatch.java | 2 +- unirest/src/main/java/unirest/HttpRequestMultiPart.java | 2 +- unirest/src/main/java/unirest/HttpRequestNoBody.java | 2 +- unirest/src/main/java/unirest/HttpRequestUniBody.java | 2 +- unirest/src/main/java/unirest/HttpRequestWithBody.java | 2 +- unirest/src/main/java/unirest/HttpResponse.java | 2 +- unirest/src/main/java/unirest/JsonNode.java | 2 +- unirest/src/main/java/unirest/JsonPatch.java | 2 +- unirest/src/main/java/unirest/JsonPatchItem.java | 2 +- unirest/src/main/java/unirest/JsonPatchOperation.java | 2 +- unirest/src/main/java/unirest/JsonPatchRequest.java | 2 +- unirest/src/main/java/unirest/JsonResponse.java | 2 +- unirest/src/main/java/unirest/MultipartBody.java | 2 +- unirest/src/main/java/unirest/NoRedirects.java | 2 +- unirest/src/main/java/unirest/ObjectMapper.java | 2 +- unirest/src/main/java/unirest/ObjectResponse.java | 2 +- unirest/src/main/java/unirest/PagedList.java | 2 +- unirest/src/main/java/unirest/Path.java | 2 +- unirest/src/main/java/unirest/RawResponse.java | 2 +- unirest/src/main/java/unirest/RawResponseBase.java | 2 +- unirest/src/main/java/unirest/RequestBodyEntity.java | 2 +- unirest/src/main/java/unirest/RequestPrep.java | 2 +- unirest/src/main/java/unirest/StringResponse.java | 2 +- .../src/main/java/unirest/SyncIdleConnectionMonitorThread.java | 2 +- unirest/src/main/java/unirest/Unirest.java | 2 +- unirest/src/main/java/unirest/UnirestConfigException.java | 2 +- unirest/src/main/java/unirest/UnirestException.java | 2 +- unirest/src/main/java/unirest/UnirestInstance.java | 2 +- unirest/src/main/java/unirest/UnirestParsingException.java | 2 +- unirest/src/main/java/unirest/Util.java | 2 +- unirest/src/test/java/BehaviorTests/AsEmptyTest.java | 2 +- unirest/src/test/java/BehaviorTests/AsFileTests.java | 2 +- unirest/src/test/java/BehaviorTests/AsGenericTypeTest.java | 2 +- unirest/src/test/java/BehaviorTests/AsJsonTest.java | 2 +- unirest/src/test/java/BehaviorTests/AsObjectTest.java | 2 +- unirest/src/test/java/BehaviorTests/AsStringTest.java | 2 +- unirest/src/test/java/BehaviorTests/BddTest.java | 2 +- unirest/src/test/java/BehaviorTests/CallbackFutureTest.java | 2 +- unirest/src/test/java/BehaviorTests/ConsumerTests.java | 2 +- unirest/src/test/java/BehaviorTests/DefectTest.java | 2 +- unirest/src/test/java/BehaviorTests/Foo.java | 2 +- unirest/src/test/java/BehaviorTests/FormPostingTest.java | 2 +- unirest/src/test/java/BehaviorTests/GZipTest.java | 2 +- unirest/src/test/java/BehaviorTests/GetResponse.java | 2 +- unirest/src/test/java/BehaviorTests/HeaderTest.java | 2 +- unirest/src/test/java/BehaviorTests/InterceptorTest.java | 2 +- unirest/src/test/java/BehaviorTests/JankyProxy.java | 2 +- unirest/src/test/java/BehaviorTests/JsonPatchTest.java | 2 +- unirest/src/test/java/BehaviorTests/LifeCycleTest.java | 2 +- unirest/src/test/java/BehaviorTests/MockServer.java | 2 +- unirest/src/test/java/BehaviorTests/ObjectFunctionalTest.java | 2 +- unirest/src/test/java/BehaviorTests/PagingTest.java | 2 +- unirest/src/test/java/BehaviorTests/Pair.java | 2 +- unirest/src/test/java/BehaviorTests/PathParamTest.java | 2 +- .../src/test/java/BehaviorTests/PostRequestHandlersTest.java | 2 +- unirest/src/test/java/BehaviorTests/ProxyTest.java | 2 +- unirest/src/test/java/BehaviorTests/QueryStringTest.java | 2 +- unirest/src/test/java/BehaviorTests/RedirectHandling.java | 2 +- unirest/src/test/java/BehaviorTests/RequestCapture.java | 2 +- unirest/src/test/java/BehaviorTests/ResponseHeaderTest.java | 2 +- unirest/src/test/java/BehaviorTests/SendBodyTest.java | 2 +- unirest/src/test/java/BehaviorTests/TimeoutTests.java | 2 +- unirest/src/test/java/BehaviorTests/VerbTest.java | 2 +- unirest/src/test/java/unirest/ClientFactoryTest.java | 2 +- unirest/src/test/java/unirest/ConfigTest.java | 2 +- unirest/src/test/java/unirest/GsonObjectMapper.java | 2 +- unirest/src/test/java/unirest/HeadersTest.java | 2 +- unirest/src/test/java/unirest/JacksonObjectMapper.java | 2 +- unirest/src/test/java/unirest/JacksonObjectMapperTest.java | 2 +- unirest/src/test/java/unirest/JsonNodeTest.java | 2 +- unirest/src/test/java/unirest/MockCallback.java | 2 +- unirest/src/test/java/unirest/NoopCallback.java | 2 +- unirest/src/test/java/unirest/NotImplimented.java | 2 +- unirest/src/test/java/unirest/PagedListTest.java | 2 +- unirest/src/test/java/unirest/ResponseUtilsTest.java | 2 +- unirest/src/test/java/unirest/TestUtil.java | 2 +- unirest/src/test/java/unirest/UriFormatterTest.java | 2 +- unirest/src/test/java/unirest/UtilTest.java | 2 +- 108 files changed, 108 insertions(+), 108 deletions(-) diff --git a/build/fileHeader.txt b/build/fileHeader.txt index 9be44eccf..1e65b29ae 100644 --- a/build/fileHeader.txt +++ b/build/fileHeader.txt @@ -1,6 +1,6 @@ The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. +Copyright for portions of unirest-java are held by Kong Inc (c) 2013. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/ApacheAsyncClient.java b/unirest/src/main/java/unirest/ApacheAsyncClient.java index f4f751c8d..cb64a926a 100644 --- a/unirest/src/main/java/unirest/ApacheAsyncClient.java +++ b/unirest/src/main/java/unirest/ApacheAsyncClient.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/ApacheClient.java b/unirest/src/main/java/unirest/ApacheClient.java index d45a8aebf..d1ce70a00 100644 --- a/unirest/src/main/java/unirest/ApacheClient.java +++ b/unirest/src/main/java/unirest/ApacheClient.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/ApacheRequestWithBody.java b/unirest/src/main/java/unirest/ApacheRequestWithBody.java index 95fe3c2e8..97cd762f1 100644 --- a/unirest/src/main/java/unirest/ApacheRequestWithBody.java +++ b/unirest/src/main/java/unirest/ApacheRequestWithBody.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/ApacheResponse.java b/unirest/src/main/java/unirest/ApacheResponse.java index 08ce9f0de..eec7e2da6 100644 --- a/unirest/src/main/java/unirest/ApacheResponse.java +++ b/unirest/src/main/java/unirest/ApacheResponse.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/AsyncClient.java b/unirest/src/main/java/unirest/AsyncClient.java index 89ddffab2..5c9628dca 100644 --- a/unirest/src/main/java/unirest/AsyncClient.java +++ b/unirest/src/main/java/unirest/AsyncClient.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java b/unirest/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java index c86e97e4a..cbc58a41d 100644 --- a/unirest/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java +++ b/unirest/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/BaseApacheClient.java b/unirest/src/main/java/unirest/BaseApacheClient.java index dcf888e1a..55aefdfa3 100644 --- a/unirest/src/main/java/unirest/BaseApacheClient.java +++ b/unirest/src/main/java/unirest/BaseApacheClient.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/BaseRequest.java b/unirest/src/main/java/unirest/BaseRequest.java index 3cce35232..14e60db04 100644 --- a/unirest/src/main/java/unirest/BaseRequest.java +++ b/unirest/src/main/java/unirest/BaseRequest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/BaseResponse.java b/unirest/src/main/java/unirest/BaseResponse.java index 70301a2b2..3dc32c154 100644 --- a/unirest/src/main/java/unirest/BaseResponse.java +++ b/unirest/src/main/java/unirest/BaseResponse.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/BasicResponse.java b/unirest/src/main/java/unirest/BasicResponse.java index 4e164cf41..b0136bb10 100644 --- a/unirest/src/main/java/unirest/BasicResponse.java +++ b/unirest/src/main/java/unirest/BasicResponse.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/Body.java b/unirest/src/main/java/unirest/Body.java index a46e737b3..2336d70b1 100644 --- a/unirest/src/main/java/unirest/Body.java +++ b/unirest/src/main/java/unirest/Body.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/Callback.java b/unirest/src/main/java/unirest/Callback.java index c7768ecc1..d9058b47e 100644 --- a/unirest/src/main/java/unirest/Callback.java +++ b/unirest/src/main/java/unirest/Callback.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/CallbackFuture.java b/unirest/src/main/java/unirest/CallbackFuture.java index 68281fd8a..10b04e5bb 100644 --- a/unirest/src/main/java/unirest/CallbackFuture.java +++ b/unirest/src/main/java/unirest/CallbackFuture.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/Client.java b/unirest/src/main/java/unirest/Client.java index 9e3d88487..42ef1f50f 100644 --- a/unirest/src/main/java/unirest/Client.java +++ b/unirest/src/main/java/unirest/Client.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/Config.java b/unirest/src/main/java/unirest/Config.java index 6aedf12af..3d38065a2 100644 --- a/unirest/src/main/java/unirest/Config.java +++ b/unirest/src/main/java/unirest/Config.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/Empty.java b/unirest/src/main/java/unirest/Empty.java index 8845c1936..1e678b09d 100644 --- a/unirest/src/main/java/unirest/Empty.java +++ b/unirest/src/main/java/unirest/Empty.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/EmptyResponse.java b/unirest/src/main/java/unirest/EmptyResponse.java index 2e8f50a0a..6c2dc16d0 100644 --- a/unirest/src/main/java/unirest/EmptyResponse.java +++ b/unirest/src/main/java/unirest/EmptyResponse.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/FileResponse.java b/unirest/src/main/java/unirest/FileResponse.java index 18e263723..a1e7d7ec7 100644 --- a/unirest/src/main/java/unirest/FileResponse.java +++ b/unirest/src/main/java/unirest/FileResponse.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/FormPart.java b/unirest/src/main/java/unirest/FormPart.java index 929958e8a..ca02541cc 100644 --- a/unirest/src/main/java/unirest/FormPart.java +++ b/unirest/src/main/java/unirest/FormPart.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/GenericType.java b/unirest/src/main/java/unirest/GenericType.java index 9eae27078..90f8c8c1d 100644 --- a/unirest/src/main/java/unirest/GenericType.java +++ b/unirest/src/main/java/unirest/GenericType.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/GetRequest.java b/unirest/src/main/java/unirest/GetRequest.java index acb18abf5..aee4e8f12 100644 --- a/unirest/src/main/java/unirest/GetRequest.java +++ b/unirest/src/main/java/unirest/GetRequest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/Header.java b/unirest/src/main/java/unirest/Header.java index b2183e826..5ab661e74 100644 --- a/unirest/src/main/java/unirest/Header.java +++ b/unirest/src/main/java/unirest/Header.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/HeaderNames.java b/unirest/src/main/java/unirest/HeaderNames.java index 78d80b61b..574028c0c 100644 --- a/unirest/src/main/java/unirest/HeaderNames.java +++ b/unirest/src/main/java/unirest/HeaderNames.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/Headers.java b/unirest/src/main/java/unirest/Headers.java index 18e14c8e1..4680c2c0c 100644 --- a/unirest/src/main/java/unirest/Headers.java +++ b/unirest/src/main/java/unirest/Headers.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/HttpDeleteWithBody.java b/unirest/src/main/java/unirest/HttpDeleteWithBody.java index 1e9251112..a38ae33b1 100644 --- a/unirest/src/main/java/unirest/HttpDeleteWithBody.java +++ b/unirest/src/main/java/unirest/HttpDeleteWithBody.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/HttpMethod.java b/unirest/src/main/java/unirest/HttpMethod.java index 295674977..ccbd2f3d4 100644 --- a/unirest/src/main/java/unirest/HttpMethod.java +++ b/unirest/src/main/java/unirest/HttpMethod.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/HttpPatchWithBody.java b/unirest/src/main/java/unirest/HttpPatchWithBody.java index ce964428c..ca3f41deb 100644 --- a/unirest/src/main/java/unirest/HttpPatchWithBody.java +++ b/unirest/src/main/java/unirest/HttpPatchWithBody.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/HttpRequest.java b/unirest/src/main/java/unirest/HttpRequest.java index 1dbd0db27..5d7308922 100644 --- a/unirest/src/main/java/unirest/HttpRequest.java +++ b/unirest/src/main/java/unirest/HttpRequest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/HttpRequestBody.java b/unirest/src/main/java/unirest/HttpRequestBody.java index f422e1815..04c4a0bca 100644 --- a/unirest/src/main/java/unirest/HttpRequestBody.java +++ b/unirest/src/main/java/unirest/HttpRequestBody.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/HttpRequestJsonPatch.java b/unirest/src/main/java/unirest/HttpRequestJsonPatch.java index b98c1499f..eb190854b 100644 --- a/unirest/src/main/java/unirest/HttpRequestJsonPatch.java +++ b/unirest/src/main/java/unirest/HttpRequestJsonPatch.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/HttpRequestMultiPart.java b/unirest/src/main/java/unirest/HttpRequestMultiPart.java index ec1e2c506..552b5c3d9 100644 --- a/unirest/src/main/java/unirest/HttpRequestMultiPart.java +++ b/unirest/src/main/java/unirest/HttpRequestMultiPart.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/HttpRequestNoBody.java b/unirest/src/main/java/unirest/HttpRequestNoBody.java index 204a15f26..882ae4457 100644 --- a/unirest/src/main/java/unirest/HttpRequestNoBody.java +++ b/unirest/src/main/java/unirest/HttpRequestNoBody.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/HttpRequestUniBody.java b/unirest/src/main/java/unirest/HttpRequestUniBody.java index ca9de762d..5a6efb54b 100644 --- a/unirest/src/main/java/unirest/HttpRequestUniBody.java +++ b/unirest/src/main/java/unirest/HttpRequestUniBody.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/HttpRequestWithBody.java b/unirest/src/main/java/unirest/HttpRequestWithBody.java index f3432ed5c..3484f9bdd 100644 --- a/unirest/src/main/java/unirest/HttpRequestWithBody.java +++ b/unirest/src/main/java/unirest/HttpRequestWithBody.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/HttpResponse.java b/unirest/src/main/java/unirest/HttpResponse.java index 6dbb15dc0..a6b6f2c7d 100644 --- a/unirest/src/main/java/unirest/HttpResponse.java +++ b/unirest/src/main/java/unirest/HttpResponse.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/JsonNode.java b/unirest/src/main/java/unirest/JsonNode.java index 6581543f6..626c3743e 100644 --- a/unirest/src/main/java/unirest/JsonNode.java +++ b/unirest/src/main/java/unirest/JsonNode.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/JsonPatch.java b/unirest/src/main/java/unirest/JsonPatch.java index 796d38d21..32fd10631 100644 --- a/unirest/src/main/java/unirest/JsonPatch.java +++ b/unirest/src/main/java/unirest/JsonPatch.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/JsonPatchItem.java b/unirest/src/main/java/unirest/JsonPatchItem.java index 65efb3360..ed85efce0 100644 --- a/unirest/src/main/java/unirest/JsonPatchItem.java +++ b/unirest/src/main/java/unirest/JsonPatchItem.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/JsonPatchOperation.java b/unirest/src/main/java/unirest/JsonPatchOperation.java index ebc4cc393..fa58e5435 100644 --- a/unirest/src/main/java/unirest/JsonPatchOperation.java +++ b/unirest/src/main/java/unirest/JsonPatchOperation.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/JsonPatchRequest.java b/unirest/src/main/java/unirest/JsonPatchRequest.java index 873271fb0..5357d9968 100644 --- a/unirest/src/main/java/unirest/JsonPatchRequest.java +++ b/unirest/src/main/java/unirest/JsonPatchRequest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/JsonResponse.java b/unirest/src/main/java/unirest/JsonResponse.java index 18f14a696..b89395f2b 100644 --- a/unirest/src/main/java/unirest/JsonResponse.java +++ b/unirest/src/main/java/unirest/JsonResponse.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/MultipartBody.java b/unirest/src/main/java/unirest/MultipartBody.java index daecc5649..ff57f81f0 100644 --- a/unirest/src/main/java/unirest/MultipartBody.java +++ b/unirest/src/main/java/unirest/MultipartBody.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/NoRedirects.java b/unirest/src/main/java/unirest/NoRedirects.java index f917b4d73..6585f695c 100644 --- a/unirest/src/main/java/unirest/NoRedirects.java +++ b/unirest/src/main/java/unirest/NoRedirects.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/ObjectMapper.java b/unirest/src/main/java/unirest/ObjectMapper.java index 9247b25a5..999ab6092 100644 --- a/unirest/src/main/java/unirest/ObjectMapper.java +++ b/unirest/src/main/java/unirest/ObjectMapper.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/ObjectResponse.java b/unirest/src/main/java/unirest/ObjectResponse.java index a7e8364f4..04e1c7cd1 100644 --- a/unirest/src/main/java/unirest/ObjectResponse.java +++ b/unirest/src/main/java/unirest/ObjectResponse.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/PagedList.java b/unirest/src/main/java/unirest/PagedList.java index ca4b1eeb5..d3981a451 100644 --- a/unirest/src/main/java/unirest/PagedList.java +++ b/unirest/src/main/java/unirest/PagedList.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/Path.java b/unirest/src/main/java/unirest/Path.java index 0f91bd181..d2cfeff29 100644 --- a/unirest/src/main/java/unirest/Path.java +++ b/unirest/src/main/java/unirest/Path.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/RawResponse.java b/unirest/src/main/java/unirest/RawResponse.java index bec3b14be..01b3f7d96 100644 --- a/unirest/src/main/java/unirest/RawResponse.java +++ b/unirest/src/main/java/unirest/RawResponse.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/RawResponseBase.java b/unirest/src/main/java/unirest/RawResponseBase.java index 148fe2c67..3efe010de 100644 --- a/unirest/src/main/java/unirest/RawResponseBase.java +++ b/unirest/src/main/java/unirest/RawResponseBase.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/RequestBodyEntity.java b/unirest/src/main/java/unirest/RequestBodyEntity.java index 11abfa571..7b203d465 100644 --- a/unirest/src/main/java/unirest/RequestBodyEntity.java +++ b/unirest/src/main/java/unirest/RequestBodyEntity.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/RequestPrep.java b/unirest/src/main/java/unirest/RequestPrep.java index e9eed7df7..f546aed46 100644 --- a/unirest/src/main/java/unirest/RequestPrep.java +++ b/unirest/src/main/java/unirest/RequestPrep.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/StringResponse.java b/unirest/src/main/java/unirest/StringResponse.java index 3647f676a..141804fcf 100644 --- a/unirest/src/main/java/unirest/StringResponse.java +++ b/unirest/src/main/java/unirest/StringResponse.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/SyncIdleConnectionMonitorThread.java b/unirest/src/main/java/unirest/SyncIdleConnectionMonitorThread.java index 8018f080c..dd66df913 100644 --- a/unirest/src/main/java/unirest/SyncIdleConnectionMonitorThread.java +++ b/unirest/src/main/java/unirest/SyncIdleConnectionMonitorThread.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/Unirest.java b/unirest/src/main/java/unirest/Unirest.java index c47b67abd..db9dfe99e 100644 --- a/unirest/src/main/java/unirest/Unirest.java +++ b/unirest/src/main/java/unirest/Unirest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/UnirestConfigException.java b/unirest/src/main/java/unirest/UnirestConfigException.java index 74f479ed4..54329560c 100644 --- a/unirest/src/main/java/unirest/UnirestConfigException.java +++ b/unirest/src/main/java/unirest/UnirestConfigException.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/UnirestException.java b/unirest/src/main/java/unirest/UnirestException.java index cd6e03cae..93d0e316c 100644 --- a/unirest/src/main/java/unirest/UnirestException.java +++ b/unirest/src/main/java/unirest/UnirestException.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/UnirestInstance.java b/unirest/src/main/java/unirest/UnirestInstance.java index 4d89f52b0..4a92ea63a 100644 --- a/unirest/src/main/java/unirest/UnirestInstance.java +++ b/unirest/src/main/java/unirest/UnirestInstance.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/UnirestParsingException.java b/unirest/src/main/java/unirest/UnirestParsingException.java index 92d877e47..ce3b4f71b 100644 --- a/unirest/src/main/java/unirest/UnirestParsingException.java +++ b/unirest/src/main/java/unirest/UnirestParsingException.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/main/java/unirest/Util.java b/unirest/src/main/java/unirest/Util.java index bb49f6aa6..c466635eb 100644 --- a/unirest/src/main/java/unirest/Util.java +++ b/unirest/src/main/java/unirest/Util.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/AsEmptyTest.java b/unirest/src/test/java/BehaviorTests/AsEmptyTest.java index fc586f3cc..4f3cbae84 100644 --- a/unirest/src/test/java/BehaviorTests/AsEmptyTest.java +++ b/unirest/src/test/java/BehaviorTests/AsEmptyTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/AsFileTests.java b/unirest/src/test/java/BehaviorTests/AsFileTests.java index 064b9664a..1c2eee213 100644 --- a/unirest/src/test/java/BehaviorTests/AsFileTests.java +++ b/unirest/src/test/java/BehaviorTests/AsFileTests.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/AsGenericTypeTest.java b/unirest/src/test/java/BehaviorTests/AsGenericTypeTest.java index 6cea2f892..1a95ab141 100644 --- a/unirest/src/test/java/BehaviorTests/AsGenericTypeTest.java +++ b/unirest/src/test/java/BehaviorTests/AsGenericTypeTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/AsJsonTest.java b/unirest/src/test/java/BehaviorTests/AsJsonTest.java index b82901e7f..afa989a37 100644 --- a/unirest/src/test/java/BehaviorTests/AsJsonTest.java +++ b/unirest/src/test/java/BehaviorTests/AsJsonTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/AsObjectTest.java b/unirest/src/test/java/BehaviorTests/AsObjectTest.java index 8c2f8d4e9..f0791df4c 100644 --- a/unirest/src/test/java/BehaviorTests/AsObjectTest.java +++ b/unirest/src/test/java/BehaviorTests/AsObjectTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/AsStringTest.java b/unirest/src/test/java/BehaviorTests/AsStringTest.java index 3fd6c4f76..6f70488ad 100644 --- a/unirest/src/test/java/BehaviorTests/AsStringTest.java +++ b/unirest/src/test/java/BehaviorTests/AsStringTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/BddTest.java b/unirest/src/test/java/BehaviorTests/BddTest.java index 9d84c96cd..ae655e191 100644 --- a/unirest/src/test/java/BehaviorTests/BddTest.java +++ b/unirest/src/test/java/BehaviorTests/BddTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/CallbackFutureTest.java b/unirest/src/test/java/BehaviorTests/CallbackFutureTest.java index 8956c619b..2c48d2918 100644 --- a/unirest/src/test/java/BehaviorTests/CallbackFutureTest.java +++ b/unirest/src/test/java/BehaviorTests/CallbackFutureTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/ConsumerTests.java b/unirest/src/test/java/BehaviorTests/ConsumerTests.java index 8ba91690e..bc1344c16 100644 --- a/unirest/src/test/java/BehaviorTests/ConsumerTests.java +++ b/unirest/src/test/java/BehaviorTests/ConsumerTests.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/DefectTest.java b/unirest/src/test/java/BehaviorTests/DefectTest.java index 5e220f6d4..d115d656b 100644 --- a/unirest/src/test/java/BehaviorTests/DefectTest.java +++ b/unirest/src/test/java/BehaviorTests/DefectTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/Foo.java b/unirest/src/test/java/BehaviorTests/Foo.java index 1dd0abbeb..89acde880 100644 --- a/unirest/src/test/java/BehaviorTests/Foo.java +++ b/unirest/src/test/java/BehaviorTests/Foo.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/FormPostingTest.java b/unirest/src/test/java/BehaviorTests/FormPostingTest.java index 8fe817bdb..f2ccc44eb 100644 --- a/unirest/src/test/java/BehaviorTests/FormPostingTest.java +++ b/unirest/src/test/java/BehaviorTests/FormPostingTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/GZipTest.java b/unirest/src/test/java/BehaviorTests/GZipTest.java index 82751a5ea..8ad513477 100644 --- a/unirest/src/test/java/BehaviorTests/GZipTest.java +++ b/unirest/src/test/java/BehaviorTests/GZipTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/GetResponse.java b/unirest/src/test/java/BehaviorTests/GetResponse.java index 645108683..526c7170b 100644 --- a/unirest/src/test/java/BehaviorTests/GetResponse.java +++ b/unirest/src/test/java/BehaviorTests/GetResponse.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/HeaderTest.java b/unirest/src/test/java/BehaviorTests/HeaderTest.java index 24160e2a1..ef980f4f4 100644 --- a/unirest/src/test/java/BehaviorTests/HeaderTest.java +++ b/unirest/src/test/java/BehaviorTests/HeaderTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/InterceptorTest.java b/unirest/src/test/java/BehaviorTests/InterceptorTest.java index d056793f8..d586c1c7e 100644 --- a/unirest/src/test/java/BehaviorTests/InterceptorTest.java +++ b/unirest/src/test/java/BehaviorTests/InterceptorTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/JankyProxy.java b/unirest/src/test/java/BehaviorTests/JankyProxy.java index 4e9472e83..5fc7f3cde 100644 --- a/unirest/src/test/java/BehaviorTests/JankyProxy.java +++ b/unirest/src/test/java/BehaviorTests/JankyProxy.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/JsonPatchTest.java b/unirest/src/test/java/BehaviorTests/JsonPatchTest.java index 697a1593c..125d37f99 100644 --- a/unirest/src/test/java/BehaviorTests/JsonPatchTest.java +++ b/unirest/src/test/java/BehaviorTests/JsonPatchTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/LifeCycleTest.java b/unirest/src/test/java/BehaviorTests/LifeCycleTest.java index d74710f88..65cb14349 100644 --- a/unirest/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/unirest/src/test/java/BehaviorTests/LifeCycleTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/MockServer.java b/unirest/src/test/java/BehaviorTests/MockServer.java index fc4ff0908..49d6bd6bc 100644 --- a/unirest/src/test/java/BehaviorTests/MockServer.java +++ b/unirest/src/test/java/BehaviorTests/MockServer.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/ObjectFunctionalTest.java b/unirest/src/test/java/BehaviorTests/ObjectFunctionalTest.java index 418c3f2e5..4f5a0b9f6 100644 --- a/unirest/src/test/java/BehaviorTests/ObjectFunctionalTest.java +++ b/unirest/src/test/java/BehaviorTests/ObjectFunctionalTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/PagingTest.java b/unirest/src/test/java/BehaviorTests/PagingTest.java index 1b112b034..172fba7e6 100644 --- a/unirest/src/test/java/BehaviorTests/PagingTest.java +++ b/unirest/src/test/java/BehaviorTests/PagingTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/Pair.java b/unirest/src/test/java/BehaviorTests/Pair.java index c4b3ad4ee..103d049a6 100644 --- a/unirest/src/test/java/BehaviorTests/Pair.java +++ b/unirest/src/test/java/BehaviorTests/Pair.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/PathParamTest.java b/unirest/src/test/java/BehaviorTests/PathParamTest.java index 7a301e9f2..99ae43cb9 100644 --- a/unirest/src/test/java/BehaviorTests/PathParamTest.java +++ b/unirest/src/test/java/BehaviorTests/PathParamTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/PostRequestHandlersTest.java b/unirest/src/test/java/BehaviorTests/PostRequestHandlersTest.java index 7f73fe545..7def956bd 100644 --- a/unirest/src/test/java/BehaviorTests/PostRequestHandlersTest.java +++ b/unirest/src/test/java/BehaviorTests/PostRequestHandlersTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/ProxyTest.java b/unirest/src/test/java/BehaviorTests/ProxyTest.java index 8d3c64a57..227d1b87d 100644 --- a/unirest/src/test/java/BehaviorTests/ProxyTest.java +++ b/unirest/src/test/java/BehaviorTests/ProxyTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/QueryStringTest.java b/unirest/src/test/java/BehaviorTests/QueryStringTest.java index e4f18f098..9350ce17b 100644 --- a/unirest/src/test/java/BehaviorTests/QueryStringTest.java +++ b/unirest/src/test/java/BehaviorTests/QueryStringTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/RedirectHandling.java b/unirest/src/test/java/BehaviorTests/RedirectHandling.java index dc9031e2a..2364eb27a 100644 --- a/unirest/src/test/java/BehaviorTests/RedirectHandling.java +++ b/unirest/src/test/java/BehaviorTests/RedirectHandling.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/RequestCapture.java b/unirest/src/test/java/BehaviorTests/RequestCapture.java index 4e38514a2..c315ebabd 100644 --- a/unirest/src/test/java/BehaviorTests/RequestCapture.java +++ b/unirest/src/test/java/BehaviorTests/RequestCapture.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/ResponseHeaderTest.java b/unirest/src/test/java/BehaviorTests/ResponseHeaderTest.java index a56400400..4b72605fd 100644 --- a/unirest/src/test/java/BehaviorTests/ResponseHeaderTest.java +++ b/unirest/src/test/java/BehaviorTests/ResponseHeaderTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/SendBodyTest.java b/unirest/src/test/java/BehaviorTests/SendBodyTest.java index fc3e9cb7d..81755509f 100644 --- a/unirest/src/test/java/BehaviorTests/SendBodyTest.java +++ b/unirest/src/test/java/BehaviorTests/SendBodyTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/TimeoutTests.java b/unirest/src/test/java/BehaviorTests/TimeoutTests.java index 3e2abe852..c2546aa71 100644 --- a/unirest/src/test/java/BehaviorTests/TimeoutTests.java +++ b/unirest/src/test/java/BehaviorTests/TimeoutTests.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/BehaviorTests/VerbTest.java b/unirest/src/test/java/BehaviorTests/VerbTest.java index c6666c69d..42053e3de 100644 --- a/unirest/src/test/java/BehaviorTests/VerbTest.java +++ b/unirest/src/test/java/BehaviorTests/VerbTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/unirest/ClientFactoryTest.java b/unirest/src/test/java/unirest/ClientFactoryTest.java index 3137245c9..a9407e3a0 100644 --- a/unirest/src/test/java/unirest/ClientFactoryTest.java +++ b/unirest/src/test/java/unirest/ClientFactoryTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/unirest/ConfigTest.java b/unirest/src/test/java/unirest/ConfigTest.java index 767b18ad1..a4bb8b513 100644 --- a/unirest/src/test/java/unirest/ConfigTest.java +++ b/unirest/src/test/java/unirest/ConfigTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/unirest/GsonObjectMapper.java b/unirest/src/test/java/unirest/GsonObjectMapper.java index 3c610364c..5f1520855 100644 --- a/unirest/src/test/java/unirest/GsonObjectMapper.java +++ b/unirest/src/test/java/unirest/GsonObjectMapper.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/unirest/HeadersTest.java b/unirest/src/test/java/unirest/HeadersTest.java index fcea390d7..bdc943edf 100644 --- a/unirest/src/test/java/unirest/HeadersTest.java +++ b/unirest/src/test/java/unirest/HeadersTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/unirest/JacksonObjectMapper.java b/unirest/src/test/java/unirest/JacksonObjectMapper.java index 35206a48d..a5612690a 100644 --- a/unirest/src/test/java/unirest/JacksonObjectMapper.java +++ b/unirest/src/test/java/unirest/JacksonObjectMapper.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/unirest/JacksonObjectMapperTest.java b/unirest/src/test/java/unirest/JacksonObjectMapperTest.java index cc7f974fd..339965d89 100644 --- a/unirest/src/test/java/unirest/JacksonObjectMapperTest.java +++ b/unirest/src/test/java/unirest/JacksonObjectMapperTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/unirest/JsonNodeTest.java b/unirest/src/test/java/unirest/JsonNodeTest.java index 70d704273..368a4be7b 100644 --- a/unirest/src/test/java/unirest/JsonNodeTest.java +++ b/unirest/src/test/java/unirest/JsonNodeTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/unirest/MockCallback.java b/unirest/src/test/java/unirest/MockCallback.java index c1c6a6cba..32941cce2 100644 --- a/unirest/src/test/java/unirest/MockCallback.java +++ b/unirest/src/test/java/unirest/MockCallback.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/unirest/NoopCallback.java b/unirest/src/test/java/unirest/NoopCallback.java index 9fa308c8c..5c2756a3b 100644 --- a/unirest/src/test/java/unirest/NoopCallback.java +++ b/unirest/src/test/java/unirest/NoopCallback.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/unirest/NotImplimented.java b/unirest/src/test/java/unirest/NotImplimented.java index 72daaf8d7..9b2f6fd43 100644 --- a/unirest/src/test/java/unirest/NotImplimented.java +++ b/unirest/src/test/java/unirest/NotImplimented.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/unirest/PagedListTest.java b/unirest/src/test/java/unirest/PagedListTest.java index d9d911f79..52ecc116e 100644 --- a/unirest/src/test/java/unirest/PagedListTest.java +++ b/unirest/src/test/java/unirest/PagedListTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/unirest/ResponseUtilsTest.java b/unirest/src/test/java/unirest/ResponseUtilsTest.java index 10c45ba27..fa66f4359 100644 --- a/unirest/src/test/java/unirest/ResponseUtilsTest.java +++ b/unirest/src/test/java/unirest/ResponseUtilsTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/unirest/TestUtil.java b/unirest/src/test/java/unirest/TestUtil.java index 376e84384..2f8fb95bc 100644 --- a/unirest/src/test/java/unirest/TestUtil.java +++ b/unirest/src/test/java/unirest/TestUtil.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/unirest/UriFormatterTest.java b/unirest/src/test/java/unirest/UriFormatterTest.java index 344dc4943..80705aec3 100644 --- a/unirest/src/test/java/unirest/UriFormatterTest.java +++ b/unirest/src/test/java/unirest/UriFormatterTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/unirest/src/test/java/unirest/UtilTest.java b/unirest/src/test/java/unirest/UtilTest.java index d5a480412..a63402cf9 100644 --- a/unirest/src/test/java/unirest/UtilTest.java +++ b/unirest/src/test/java/unirest/UtilTest.java @@ -1,7 +1,7 @@ /** * The MIT License * - * Copyright for portions of OpenUnirest/uniresr-java are held by Kong Inc (c) 2013 as part of Kong/unirest-java. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the From 0c646d5e19f9b71e73b8768b096ab5da01e6be52 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 19 Feb 2019 20:48:35 -0600 Subject: [PATCH 0453/1769] move everything into a kong.unirest namespace --- .../{ => kong}/unirest/ApacheAsyncClient.java | 4 ++-- .../java/{ => kong}/unirest/ApacheClient.java | 2 +- .../unirest/ApacheRequestWithBody.java | 2 +- .../{ => kong}/unirest/ApacheResponse.java | 2 +- .../java/{ => kong}/unirest/AsyncClient.java | 2 +- .../AsyncIdleConnectionMonitorThread.java | 2 +- .../{ => kong}/unirest/BaseApacheClient.java | 2 +- .../java/{ => kong}/unirest/BaseRequest.java | 2 +- .../java/{ => kong}/unirest/BaseResponse.java | 2 +- .../{ => kong}/unirest/BasicResponse.java | 2 +- .../main/java/{ => kong}/unirest/Body.java | 2 +- .../java/{ => kong}/unirest/Callback.java | 2 +- .../{ => kong}/unirest/CallbackFuture.java | 2 +- .../main/java/{ => kong}/unirest/Client.java | 2 +- .../main/java/{ => kong}/unirest/Config.java | 2 +- .../main/java/{ => kong}/unirest/Empty.java | 2 +- .../{ => kong}/unirest/EmptyResponse.java | 2 +- .../java/{ => kong}/unirest/FileResponse.java | 2 +- .../java/{ => kong}/unirest/FormPart.java | 2 +- .../java/{ => kong}/unirest/GenericType.java | 2 +- .../java/{ => kong}/unirest/GetRequest.java | 2 +- .../main/java/{ => kong}/unirest/Header.java | 2 +- .../java/{ => kong}/unirest/HeaderNames.java | 2 +- .../main/java/{ => kong}/unirest/Headers.java | 2 +- .../unirest/HttpDeleteWithBody.java | 2 +- .../java/{ => kong}/unirest/HttpMethod.java | 2 +- .../{ => kong}/unirest/HttpPatchWithBody.java | 2 +- .../java/{ => kong}/unirest/HttpRequest.java | 2 +- .../{ => kong}/unirest/HttpRequestBody.java | 2 +- .../unirest/HttpRequestJsonPatch.java | 2 +- .../unirest/HttpRequestMultiPart.java | 6 ++--- .../{ => kong}/unirest/HttpRequestNoBody.java | 2 +- .../unirest/HttpRequestUniBody.java | 2 +- .../unirest/HttpRequestWithBody.java | 2 +- .../java/{ => kong}/unirest/HttpResponse.java | 2 +- .../java/{ => kong}/unirest/JsonNode.java | 2 +- .../java/{ => kong}/unirest/JsonPatch.java | 16 ++++++-------- .../{ => kong}/unirest/JsonPatchItem.java | 2 +- .../unirest/JsonPatchOperation.java | 2 +- .../{ => kong}/unirest/JsonPatchRequest.java | 2 +- .../java/{ => kong}/unirest/JsonResponse.java | 2 +- .../{ => kong}/unirest/MultipartBody.java | 2 +- .../java/{ => kong}/unirest/NoRedirects.java | 2 +- .../java/{ => kong}/unirest/ObjectMapper.java | 2 +- .../{ => kong}/unirest/ObjectResponse.java | 2 +- .../java/{ => kong}/unirest/PagedList.java | 2 +- .../main/java/{ => kong}/unirest/Path.java | 2 +- .../java/{ => kong}/unirest/RawResponse.java | 2 +- .../{ => kong}/unirest/RawResponseBase.java | 2 +- .../{ => kong}/unirest/RequestBodyEntity.java | 2 +- .../java/{ => kong}/unirest/RequestPrep.java | 22 +++++++++---------- .../{ => kong}/unirest/StringResponse.java | 2 +- .../SyncIdleConnectionMonitorThread.java | 2 +- .../main/java/{ => kong}/unirest/Unirest.java | 2 +- .../unirest/UnirestConfigException.java | 2 +- .../{ => kong}/unirest/UnirestException.java | 2 +- .../{ => kong}/unirest/UnirestInstance.java | 2 +- .../unirest/UnirestParsingException.java | 2 +- .../main/java/{ => kong}/unirest/Util.java | 2 +- .../test/java/BehaviorTests/AsEmptyTest.java | 4 ++-- .../test/java/BehaviorTests/AsFileTests.java | 6 ++--- .../java/BehaviorTests/AsGenericTypeTest.java | 6 ++--- .../test/java/BehaviorTests/AsJsonTest.java | 11 +++++----- .../test/java/BehaviorTests/AsObjectTest.java | 8 +++---- .../test/java/BehaviorTests/AsStringTest.java | 6 ++--- .../src/test/java/BehaviorTests/BddTest.java | 11 +++++----- .../BehaviorTests/CallbackFutureTest.java | 6 ++--- .../java/BehaviorTests/ConsumerTests.java | 2 +- .../test/java/BehaviorTests/DefectTest.java | 2 +- .../java/BehaviorTests/FormPostingTest.java | 7 ++++-- .../src/test/java/BehaviorTests/GZipTest.java | 2 +- .../test/java/BehaviorTests/HeaderTest.java | 9 +++++--- .../java/BehaviorTests/InterceptorTest.java | 2 +- .../java/BehaviorTests/JsonPatchTest.java | 6 ++--- .../java/BehaviorTests/LifeCycleTest.java | 2 +- .../test/java/BehaviorTests/MockServer.java | 4 ++-- .../BehaviorTests/ObjectFunctionalTest.java | 5 +---- .../test/java/BehaviorTests/PagingTest.java | 4 ++-- .../java/BehaviorTests/PathParamTest.java | 6 ++--- .../PostRequestHandlersTest.java | 4 ++-- .../test/java/BehaviorTests/ProxyTest.java | 4 ++-- .../java/BehaviorTests/QueryStringTest.java | 6 ++--- .../java/BehaviorTests/RedirectHandling.java | 4 ++-- .../java/BehaviorTests/RequestCapture.java | 12 +++++----- .../BehaviorTests/ResponseHeaderTest.java | 6 ++--- .../test/java/BehaviorTests/SendBodyTest.java | 10 ++++----- .../test/java/BehaviorTests/TimeoutTests.java | 6 ++--- .../src/test/java/BehaviorTests/VerbTest.java | 8 +++---- .../{ => kong}/unirest/ClientFactoryTest.java | 2 +- .../java/{ => kong}/unirest/ConfigTest.java | 2 +- .../{ => kong}/unirest/GsonObjectMapper.java | 4 +--- .../java/{ => kong}/unirest/HeadersTest.java | 2 +- .../unirest/JacksonObjectMapper.java | 2 +- .../unirest/JacksonObjectMapperTest.java | 2 +- .../java/{ => kong}/unirest/JsonNodeTest.java | 3 +-- .../java/{ => kong}/unirest/MockCallback.java | 2 +- .../java/{ => kong}/unirest/NoopCallback.java | 6 +---- .../{ => kong}/unirest/NotImplimented.java | 2 +- .../{ => kong}/unirest/PagedListTest.java | 2 +- .../{ => kong}/unirest/ResponseUtilsTest.java | 2 +- .../java/{ => kong}/unirest/TestUtil.java | 4 +--- .../{ => kong}/unirest/UriFormatterTest.java | 2 +- .../java/{ => kong}/unirest/UtilTest.java | 2 +- 103 files changed, 176 insertions(+), 190 deletions(-) rename unirest/src/main/java/{ => kong}/unirest/ApacheAsyncClient.java (98%) rename unirest/src/main/java/{ => kong}/unirest/ApacheClient.java (99%) rename unirest/src/main/java/{ => kong}/unirest/ApacheRequestWithBody.java (98%) rename unirest/src/main/java/{ => kong}/unirest/ApacheResponse.java (99%) rename unirest/src/main/java/{ => kong}/unirest/AsyncClient.java (99%) rename unirest/src/main/java/{ => kong}/unirest/AsyncIdleConnectionMonitorThread.java (98%) rename unirest/src/main/java/{ => kong}/unirest/BaseApacheClient.java (98%) rename unirest/src/main/java/{ => kong}/unirest/BaseRequest.java (99%) rename unirest/src/main/java/{ => kong}/unirest/BaseResponse.java (99%) rename unirest/src/main/java/{ => kong}/unirest/BasicResponse.java (98%) rename unirest/src/main/java/{ => kong}/unirest/Body.java (98%) rename unirest/src/main/java/{ => kong}/unirest/Callback.java (98%) rename unirest/src/main/java/{ => kong}/unirest/CallbackFuture.java (98%) rename unirest/src/main/java/{ => kong}/unirest/Client.java (98%) rename unirest/src/main/java/{ => kong}/unirest/Config.java (99%) rename unirest/src/main/java/{ => kong}/unirest/Empty.java (98%) rename unirest/src/main/java/{ => kong}/unirest/EmptyResponse.java (98%) rename unirest/src/main/java/{ => kong}/unirest/FileResponse.java (98%) rename unirest/src/main/java/{ => kong}/unirest/FormPart.java (99%) rename unirest/src/main/java/{ => kong}/unirest/GenericType.java (99%) rename unirest/src/main/java/{ => kong}/unirest/GetRequest.java (98%) rename unirest/src/main/java/{ => kong}/unirest/Header.java (98%) rename unirest/src/main/java/{ => kong}/unirest/HeaderNames.java (99%) rename unirest/src/main/java/{ => kong}/unirest/Headers.java (99%) rename unirest/src/main/java/{ => kong}/unirest/HttpDeleteWithBody.java (98%) rename unirest/src/main/java/{ => kong}/unirest/HttpMethod.java (99%) rename unirest/src/main/java/{ => kong}/unirest/HttpPatchWithBody.java (98%) rename unirest/src/main/java/{ => kong}/unirest/HttpRequest.java (99%) rename unirest/src/main/java/{ => kong}/unirest/HttpRequestBody.java (99%) rename unirest/src/main/java/{ => kong}/unirest/HttpRequestJsonPatch.java (99%) rename unirest/src/main/java/{ => kong}/unirest/HttpRequestMultiPart.java (97%) rename unirest/src/main/java/{ => kong}/unirest/HttpRequestNoBody.java (98%) rename unirest/src/main/java/{ => kong}/unirest/HttpRequestUniBody.java (99%) rename unirest/src/main/java/{ => kong}/unirest/HttpRequestWithBody.java (99%) rename unirest/src/main/java/{ => kong}/unirest/HttpResponse.java (99%) rename unirest/src/main/java/{ => kong}/unirest/JsonNode.java (99%) rename unirest/src/main/java/{ => kong}/unirest/JsonPatch.java (82%) rename unirest/src/main/java/{ => kong}/unirest/JsonPatchItem.java (99%) rename unirest/src/main/java/{ => kong}/unirest/JsonPatchOperation.java (98%) rename unirest/src/main/java/{ => kong}/unirest/JsonPatchRequest.java (98%) rename unirest/src/main/java/{ => kong}/unirest/JsonResponse.java (99%) rename unirest/src/main/java/{ => kong}/unirest/MultipartBody.java (99%) rename unirest/src/main/java/{ => kong}/unirest/NoRedirects.java (98%) rename unirest/src/main/java/{ => kong}/unirest/ObjectMapper.java (98%) rename unirest/src/main/java/{ => kong}/unirest/ObjectResponse.java (99%) rename unirest/src/main/java/{ => kong}/unirest/PagedList.java (99%) rename unirest/src/main/java/{ => kong}/unirest/Path.java (99%) rename unirest/src/main/java/{ => kong}/unirest/RawResponse.java (98%) rename unirest/src/main/java/{ => kong}/unirest/RawResponseBase.java (99%) rename unirest/src/main/java/{ => kong}/unirest/RequestBodyEntity.java (98%) rename unirest/src/main/java/{ => kong}/unirest/RequestPrep.java (87%) rename unirest/src/main/java/{ => kong}/unirest/StringResponse.java (98%) rename unirest/src/main/java/{ => kong}/unirest/SyncIdleConnectionMonitorThread.java (98%) rename unirest/src/main/java/{ => kong}/unirest/Unirest.java (99%) rename unirest/src/main/java/{ => kong}/unirest/UnirestConfigException.java (98%) rename unirest/src/main/java/{ => kong}/unirest/UnirestException.java (98%) rename unirest/src/main/java/{ => kong}/unirest/UnirestInstance.java (99%) rename unirest/src/main/java/{ => kong}/unirest/UnirestParsingException.java (98%) rename unirest/src/main/java/{ => kong}/unirest/Util.java (99%) rename unirest/src/test/java/{ => kong}/unirest/ClientFactoryTest.java (99%) rename unirest/src/test/java/{ => kong}/unirest/ConfigTest.java (99%) rename unirest/src/test/java/{ => kong}/unirest/GsonObjectMapper.java (95%) rename unirest/src/test/java/{ => kong}/unirest/HeadersTest.java (98%) rename unirest/src/test/java/{ => kong}/unirest/JacksonObjectMapper.java (99%) rename unirest/src/test/java/{ => kong}/unirest/JacksonObjectMapperTest.java (99%) rename unirest/src/test/java/{ => kong}/unirest/JsonNodeTest.java (98%) rename unirest/src/test/java/{ => kong}/unirest/MockCallback.java (99%) rename unirest/src/test/java/{ => kong}/unirest/NoopCallback.java (93%) rename unirest/src/test/java/{ => kong}/unirest/NotImplimented.java (98%) rename unirest/src/test/java/{ => kong}/unirest/PagedListTest.java (99%) rename unirest/src/test/java/{ => kong}/unirest/ResponseUtilsTest.java (99%) rename unirest/src/test/java/{ => kong}/unirest/TestUtil.java (98%) rename unirest/src/test/java/{ => kong}/unirest/UriFormatterTest.java (98%) rename unirest/src/test/java/{ => kong}/unirest/UtilTest.java (98%) diff --git a/unirest/src/main/java/unirest/ApacheAsyncClient.java b/unirest/src/main/java/kong/unirest/ApacheAsyncClient.java similarity index 98% rename from unirest/src/main/java/unirest/ApacheAsyncClient.java rename to unirest/src/main/java/kong/unirest/ApacheAsyncClient.java index cb64a926a..0cdb2cdfa 100644 --- a/unirest/src/main/java/unirest/ApacheAsyncClient.java +++ b/unirest/src/main/java/kong/unirest/ApacheAsyncClient.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.concurrent.FutureCallback; @@ -39,7 +39,7 @@ import java.util.function.Function; import java.util.stream.Stream; -import static unirest.Util.tryCast; +import static kong.unirest.Util.tryCast; class ApacheAsyncClient extends BaseApacheClient implements AsyncClient { diff --git a/unirest/src/main/java/unirest/ApacheClient.java b/unirest/src/main/java/kong/unirest/ApacheClient.java similarity index 99% rename from unirest/src/main/java/unirest/ApacheClient.java rename to unirest/src/main/java/kong/unirest/ApacheClient.java index d1ce70a00..ec4324933 100644 --- a/unirest/src/main/java/unirest/ApacheClient.java +++ b/unirest/src/main/java/kong/unirest/ApacheClient.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpRequestBase; diff --git a/unirest/src/main/java/unirest/ApacheRequestWithBody.java b/unirest/src/main/java/kong/unirest/ApacheRequestWithBody.java similarity index 98% rename from unirest/src/main/java/unirest/ApacheRequestWithBody.java rename to unirest/src/main/java/kong/unirest/ApacheRequestWithBody.java index 97cd762f1..b171ce3b2 100644 --- a/unirest/src/main/java/unirest/ApacheRequestWithBody.java +++ b/unirest/src/main/java/kong/unirest/ApacheRequestWithBody.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; diff --git a/unirest/src/main/java/unirest/ApacheResponse.java b/unirest/src/main/java/kong/unirest/ApacheResponse.java similarity index 99% rename from unirest/src/main/java/unirest/ApacheResponse.java rename to unirest/src/main/java/kong/unirest/ApacheResponse.java index eec7e2da6..d0e61b986 100644 --- a/unirest/src/main/java/unirest/ApacheResponse.java +++ b/unirest/src/main/java/kong/unirest/ApacheResponse.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.Header; import org.apache.http.HttpEntity; diff --git a/unirest/src/main/java/unirest/AsyncClient.java b/unirest/src/main/java/kong/unirest/AsyncClient.java similarity index 99% rename from unirest/src/main/java/unirest/AsyncClient.java rename to unirest/src/main/java/kong/unirest/AsyncClient.java index 5c9628dca..b930810d6 100644 --- a/unirest/src/main/java/unirest/AsyncClient.java +++ b/unirest/src/main/java/kong/unirest/AsyncClient.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.nio.client.HttpAsyncClient; diff --git a/unirest/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java b/unirest/src/main/java/kong/unirest/AsyncIdleConnectionMonitorThread.java similarity index 98% rename from unirest/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java rename to unirest/src/main/java/kong/unirest/AsyncIdleConnectionMonitorThread.java index cbc58a41d..a599d136e 100644 --- a/unirest/src/main/java/unirest/AsyncIdleConnectionMonitorThread.java +++ b/unirest/src/main/java/kong/unirest/AsyncIdleConnectionMonitorThread.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.util.concurrent.TimeUnit; diff --git a/unirest/src/main/java/unirest/BaseApacheClient.java b/unirest/src/main/java/kong/unirest/BaseApacheClient.java similarity index 98% rename from unirest/src/main/java/unirest/BaseApacheClient.java rename to unirest/src/main/java/kong/unirest/BaseApacheClient.java index 55aefdfa3..123a5b995 100644 --- a/unirest/src/main/java/unirest/BaseApacheClient.java +++ b/unirest/src/main/java/kong/unirest/BaseApacheClient.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.HttpHost; import org.apache.http.client.config.RequestConfig; diff --git a/unirest/src/main/java/unirest/BaseRequest.java b/unirest/src/main/java/kong/unirest/BaseRequest.java similarity index 99% rename from unirest/src/main/java/unirest/BaseRequest.java rename to unirest/src/main/java/kong/unirest/BaseRequest.java index 14e60db04..7e9afcbb4 100644 --- a/unirest/src/main/java/unirest/BaseRequest.java +++ b/unirest/src/main/java/kong/unirest/BaseRequest.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.io.File; import java.util.*; diff --git a/unirest/src/main/java/unirest/BaseResponse.java b/unirest/src/main/java/kong/unirest/BaseResponse.java similarity index 99% rename from unirest/src/main/java/unirest/BaseResponse.java rename to unirest/src/main/java/kong/unirest/BaseResponse.java index 3dc32c154..055f6f746 100644 --- a/unirest/src/main/java/unirest/BaseResponse.java +++ b/unirest/src/main/java/kong/unirest/BaseResponse.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.io.InputStream; import java.util.Optional; diff --git a/unirest/src/main/java/unirest/BasicResponse.java b/unirest/src/main/java/kong/unirest/BasicResponse.java similarity index 98% rename from unirest/src/main/java/unirest/BasicResponse.java rename to unirest/src/main/java/kong/unirest/BasicResponse.java index b0136bb10..b7650967f 100644 --- a/unirest/src/main/java/unirest/BasicResponse.java +++ b/unirest/src/main/java/kong/unirest/BasicResponse.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.io.InputStream; diff --git a/unirest/src/main/java/unirest/Body.java b/unirest/src/main/java/kong/unirest/Body.java similarity index 98% rename from unirest/src/main/java/unirest/Body.java rename to unirest/src/main/java/kong/unirest/Body.java index 2336d70b1..4efcb07b0 100644 --- a/unirest/src/main/java/unirest/Body.java +++ b/unirest/src/main/java/kong/unirest/Body.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.HttpEntity; diff --git a/unirest/src/main/java/unirest/Callback.java b/unirest/src/main/java/kong/unirest/Callback.java similarity index 98% rename from unirest/src/main/java/unirest/Callback.java rename to unirest/src/main/java/kong/unirest/Callback.java index d9058b47e..6b969f42d 100644 --- a/unirest/src/main/java/unirest/Callback.java +++ b/unirest/src/main/java/kong/unirest/Callback.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; public interface Callback { void completed(HttpResponse response); diff --git a/unirest/src/main/java/unirest/CallbackFuture.java b/unirest/src/main/java/kong/unirest/CallbackFuture.java similarity index 98% rename from unirest/src/main/java/unirest/CallbackFuture.java rename to unirest/src/main/java/kong/unirest/CallbackFuture.java index 10b04e5bb..dbe0d7c72 100644 --- a/unirest/src/main/java/unirest/CallbackFuture.java +++ b/unirest/src/main/java/kong/unirest/CallbackFuture.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.util.concurrent.CompletableFuture; diff --git a/unirest/src/main/java/unirest/Client.java b/unirest/src/main/java/kong/unirest/Client.java similarity index 98% rename from unirest/src/main/java/unirest/Client.java rename to unirest/src/main/java/kong/unirest/Client.java index 42ef1f50f..99dca7d23 100644 --- a/unirest/src/main/java/unirest/Client.java +++ b/unirest/src/main/java/kong/unirest/Client.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.client.HttpClient; diff --git a/unirest/src/main/java/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java similarity index 99% rename from unirest/src/main/java/unirest/Config.java rename to unirest/src/main/java/kong/unirest/Config.java index 3d38065a2..0ad3380ea 100644 --- a/unirest/src/main/java/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.HttpHost; import org.apache.http.HttpRequestInterceptor; diff --git a/unirest/src/main/java/unirest/Empty.java b/unirest/src/main/java/kong/unirest/Empty.java similarity index 98% rename from unirest/src/main/java/unirest/Empty.java rename to unirest/src/main/java/kong/unirest/Empty.java index 1e678b09d..ac0d109bd 100644 --- a/unirest/src/main/java/unirest/Empty.java +++ b/unirest/src/main/java/kong/unirest/Empty.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; public class Empty { private Empty(){} diff --git a/unirest/src/main/java/unirest/EmptyResponse.java b/unirest/src/main/java/kong/unirest/EmptyResponse.java similarity index 98% rename from unirest/src/main/java/unirest/EmptyResponse.java rename to unirest/src/main/java/kong/unirest/EmptyResponse.java index 6c2dc16d0..fceee91e2 100644 --- a/unirest/src/main/java/unirest/EmptyResponse.java +++ b/unirest/src/main/java/kong/unirest/EmptyResponse.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.io.InputStream; diff --git a/unirest/src/main/java/unirest/FileResponse.java b/unirest/src/main/java/kong/unirest/FileResponse.java similarity index 98% rename from unirest/src/main/java/unirest/FileResponse.java rename to unirest/src/main/java/kong/unirest/FileResponse.java index a1e7d7ec7..0c9de5c0f 100644 --- a/unirest/src/main/java/unirest/FileResponse.java +++ b/unirest/src/main/java/kong/unirest/FileResponse.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.io.ByteArrayInputStream; import java.io.File; diff --git a/unirest/src/main/java/unirest/FormPart.java b/unirest/src/main/java/kong/unirest/FormPart.java similarity index 99% rename from unirest/src/main/java/unirest/FormPart.java rename to unirest/src/main/java/kong/unirest/FormPart.java index ca02541cc..44c1162dd 100644 --- a/unirest/src/main/java/unirest/FormPart.java +++ b/unirest/src/main/java/kong/unirest/FormPart.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.content.*; diff --git a/unirest/src/main/java/unirest/GenericType.java b/unirest/src/main/java/kong/unirest/GenericType.java similarity index 99% rename from unirest/src/main/java/unirest/GenericType.java rename to unirest/src/main/java/kong/unirest/GenericType.java index 90f8c8c1d..bfde9a56d 100644 --- a/unirest/src/main/java/unirest/GenericType.java +++ b/unirest/src/main/java/kong/unirest/GenericType.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; diff --git a/unirest/src/main/java/unirest/GetRequest.java b/unirest/src/main/java/kong/unirest/GetRequest.java similarity index 98% rename from unirest/src/main/java/unirest/GetRequest.java rename to unirest/src/main/java/kong/unirest/GetRequest.java index aee4e8f12..b6585f9ad 100644 --- a/unirest/src/main/java/unirest/GetRequest.java +++ b/unirest/src/main/java/kong/unirest/GetRequest.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; public interface GetRequest extends HttpRequest { } diff --git a/unirest/src/main/java/unirest/Header.java b/unirest/src/main/java/kong/unirest/Header.java similarity index 98% rename from unirest/src/main/java/unirest/Header.java rename to unirest/src/main/java/kong/unirest/Header.java index 5ab661e74..7c86dff06 100644 --- a/unirest/src/main/java/unirest/Header.java +++ b/unirest/src/main/java/kong/unirest/Header.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; public interface Header { String getName(); diff --git a/unirest/src/main/java/unirest/HeaderNames.java b/unirest/src/main/java/kong/unirest/HeaderNames.java similarity index 99% rename from unirest/src/main/java/unirest/HeaderNames.java rename to unirest/src/main/java/kong/unirest/HeaderNames.java index 574028c0c..f27a66250 100644 --- a/unirest/src/main/java/unirest/HeaderNames.java +++ b/unirest/src/main/java/kong/unirest/HeaderNames.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; /** * Constants enumerating the HTTP headers. All headers defined in RFC1945 (HTTP/1.0), RFC2616 (HTTP/1.1), and RFC2518 diff --git a/unirest/src/main/java/unirest/Headers.java b/unirest/src/main/java/kong/unirest/Headers.java similarity index 99% rename from unirest/src/main/java/unirest/Headers.java rename to unirest/src/main/java/kong/unirest/Headers.java index 4680c2c0c..a935cd65f 100644 --- a/unirest/src/main/java/unirest/Headers.java +++ b/unirest/src/main/java/kong/unirest/Headers.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.util.ArrayList; import java.util.Collection; diff --git a/unirest/src/main/java/unirest/HttpDeleteWithBody.java b/unirest/src/main/java/kong/unirest/HttpDeleteWithBody.java similarity index 98% rename from unirest/src/main/java/unirest/HttpDeleteWithBody.java rename to unirest/src/main/java/kong/unirest/HttpDeleteWithBody.java index a38ae33b1..7352513fa 100644 --- a/unirest/src/main/java/unirest/HttpDeleteWithBody.java +++ b/unirest/src/main/java/kong/unirest/HttpDeleteWithBody.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; diff --git a/unirest/src/main/java/unirest/HttpMethod.java b/unirest/src/main/java/kong/unirest/HttpMethod.java similarity index 99% rename from unirest/src/main/java/unirest/HttpMethod.java rename to unirest/src/main/java/kong/unirest/HttpMethod.java index ccbd2f3d4..a1d09cbfb 100644 --- a/unirest/src/main/java/unirest/HttpMethod.java +++ b/unirest/src/main/java/kong/unirest/HttpMethod.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.util.HashMap; import java.util.HashSet; diff --git a/unirest/src/main/java/unirest/HttpPatchWithBody.java b/unirest/src/main/java/kong/unirest/HttpPatchWithBody.java similarity index 98% rename from unirest/src/main/java/unirest/HttpPatchWithBody.java rename to unirest/src/main/java/kong/unirest/HttpPatchWithBody.java index ca3f41deb..32ff72ba5 100644 --- a/unirest/src/main/java/unirest/HttpPatchWithBody.java +++ b/unirest/src/main/java/kong/unirest/HttpPatchWithBody.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; diff --git a/unirest/src/main/java/unirest/HttpRequest.java b/unirest/src/main/java/kong/unirest/HttpRequest.java similarity index 99% rename from unirest/src/main/java/unirest/HttpRequest.java rename to unirest/src/main/java/kong/unirest/HttpRequest.java index 5d7308922..7a844883b 100644 --- a/unirest/src/main/java/unirest/HttpRequest.java +++ b/unirest/src/main/java/kong/unirest/HttpRequest.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.io.File; import java.util.Collection; diff --git a/unirest/src/main/java/unirest/HttpRequestBody.java b/unirest/src/main/java/kong/unirest/HttpRequestBody.java similarity index 99% rename from unirest/src/main/java/unirest/HttpRequestBody.java rename to unirest/src/main/java/kong/unirest/HttpRequestBody.java index 04c4a0bca..205a446dc 100644 --- a/unirest/src/main/java/unirest/HttpRequestBody.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestBody.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.entity.ContentType; import org.json.JSONArray; diff --git a/unirest/src/main/java/unirest/HttpRequestJsonPatch.java b/unirest/src/main/java/kong/unirest/HttpRequestJsonPatch.java similarity index 99% rename from unirest/src/main/java/unirest/HttpRequestJsonPatch.java rename to unirest/src/main/java/kong/unirest/HttpRequestJsonPatch.java index eb190854b..a55915707 100644 --- a/unirest/src/main/java/unirest/HttpRequestJsonPatch.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestJsonPatch.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.HttpEntity; import org.apache.http.entity.BasicHttpEntity; diff --git a/unirest/src/main/java/unirest/HttpRequestMultiPart.java b/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java similarity index 97% rename from unirest/src/main/java/unirest/HttpRequestMultiPart.java rename to unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java index 552b5c3d9..725ed739d 100644 --- a/unirest/src/main/java/unirest/HttpRequestMultiPart.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.HttpEntity; import org.apache.http.HttpHeaders; @@ -39,8 +39,6 @@ import java.nio.charset.Charset; import java.util.*; -import static unirest.Util.nullToEmpty; - class HttpRequestMultiPart extends BaseRequest implements MultipartBody { private List parameters = new ArrayList<>(); @@ -149,7 +147,7 @@ public MultipartBody fields(Map fields) { if (param.getValue() instanceof File) { field(param.getKey(), (File) param.getValue()); } else { - field(param.getKey(), nullToEmpty(param.getValue())); + field(param.getKey(), Util.nullToEmpty(param.getValue())); } } } diff --git a/unirest/src/main/java/unirest/HttpRequestNoBody.java b/unirest/src/main/java/kong/unirest/HttpRequestNoBody.java similarity index 98% rename from unirest/src/main/java/unirest/HttpRequestNoBody.java rename to unirest/src/main/java/kong/unirest/HttpRequestNoBody.java index 882ae4457..b075452ce 100644 --- a/unirest/src/main/java/unirest/HttpRequestNoBody.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestNoBody.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; class HttpRequestNoBody extends BaseRequest implements GetRequest { HttpRequestNoBody(Config config, HttpMethod method, String url) { diff --git a/unirest/src/main/java/unirest/HttpRequestUniBody.java b/unirest/src/main/java/kong/unirest/HttpRequestUniBody.java similarity index 99% rename from unirest/src/main/java/unirest/HttpRequestUniBody.java rename to unirest/src/main/java/kong/unirest/HttpRequestUniBody.java index 5a6efb54b..74b4b5f1d 100644 --- a/unirest/src/main/java/unirest/HttpRequestUniBody.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestUniBody.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.HttpEntity; import org.apache.http.entity.ByteArrayEntity; diff --git a/unirest/src/main/java/unirest/HttpRequestWithBody.java b/unirest/src/main/java/kong/unirest/HttpRequestWithBody.java similarity index 99% rename from unirest/src/main/java/unirest/HttpRequestWithBody.java rename to unirest/src/main/java/kong/unirest/HttpRequestWithBody.java index 3484f9bdd..82b80573f 100644 --- a/unirest/src/main/java/unirest/HttpRequestWithBody.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestWithBody.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.entity.ContentType; import org.json.JSONArray; diff --git a/unirest/src/main/java/unirest/HttpResponse.java b/unirest/src/main/java/kong/unirest/HttpResponse.java similarity index 99% rename from unirest/src/main/java/unirest/HttpResponse.java rename to unirest/src/main/java/kong/unirest/HttpResponse.java index a6b6f2c7d..2c93ee71c 100644 --- a/unirest/src/main/java/unirest/HttpResponse.java +++ b/unirest/src/main/java/kong/unirest/HttpResponse.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.io.InputStream; import java.util.Optional; diff --git a/unirest/src/main/java/unirest/JsonNode.java b/unirest/src/main/java/kong/unirest/JsonNode.java similarity index 99% rename from unirest/src/main/java/unirest/JsonNode.java rename to unirest/src/main/java/kong/unirest/JsonNode.java index 626c3743e..8ed927414 100644 --- a/unirest/src/main/java/unirest/JsonNode.java +++ b/unirest/src/main/java/kong/unirest/JsonNode.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.json.JSONArray; import org.json.JSONException; diff --git a/unirest/src/main/java/unirest/JsonPatch.java b/unirest/src/main/java/kong/unirest/JsonPatch.java similarity index 82% rename from unirest/src/main/java/unirest/JsonPatch.java rename to unirest/src/main/java/kong/unirest/JsonPatch.java index 32fd10631..8c74568ee 100644 --- a/unirest/src/main/java/unirest/JsonPatch.java +++ b/unirest/src/main/java/kong/unirest/JsonPatch.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.json.JSONArray; import org.json.JSONObject; @@ -32,8 +32,6 @@ import java.util.Collections; import java.util.List; -import static unirest.JsonPatchOperation.*; - public class JsonPatch { private List items = new ArrayList<>(); @@ -49,27 +47,27 @@ public JsonPatch(String fromString){ } public void add(String path, Object value) { - items.add(new JsonPatchItem(add, path, value)); + items.add(new JsonPatchItem(JsonPatchOperation.add, path, value)); } public void remove(String path) { - items.add(new JsonPatchItem(remove, path)); + items.add(new JsonPatchItem(JsonPatchOperation.remove, path)); } public void replace(String path, Object value) { - items.add(new JsonPatchItem(replace, path, value)); + items.add(new JsonPatchItem(JsonPatchOperation.replace, path, value)); } public void test(String path, Object value) { - items.add(new JsonPatchItem(test, path, value)); + items.add(new JsonPatchItem(JsonPatchOperation.test, path, value)); } public void move(String from, String path) { - items.add(new JsonPatchItem(move, path, from)); + items.add(new JsonPatchItem(JsonPatchOperation.move, path, from)); } public void copy(String from, String path) { - items.add(new JsonPatchItem(copy, path, from)); + items.add(new JsonPatchItem(JsonPatchOperation.copy, path, from)); } @Override diff --git a/unirest/src/main/java/unirest/JsonPatchItem.java b/unirest/src/main/java/kong/unirest/JsonPatchItem.java similarity index 99% rename from unirest/src/main/java/unirest/JsonPatchItem.java rename to unirest/src/main/java/kong/unirest/JsonPatchItem.java index ed85efce0..b8d427132 100644 --- a/unirest/src/main/java/unirest/JsonPatchItem.java +++ b/unirest/src/main/java/kong/unirest/JsonPatchItem.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.json.JSONObject; diff --git a/unirest/src/main/java/unirest/JsonPatchOperation.java b/unirest/src/main/java/kong/unirest/JsonPatchOperation.java similarity index 98% rename from unirest/src/main/java/unirest/JsonPatchOperation.java rename to unirest/src/main/java/kong/unirest/JsonPatchOperation.java index fa58e5435..359c722c1 100644 --- a/unirest/src/main/java/unirest/JsonPatchOperation.java +++ b/unirest/src/main/java/kong/unirest/JsonPatchOperation.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; public enum JsonPatchOperation { add("value"), diff --git a/unirest/src/main/java/unirest/JsonPatchRequest.java b/unirest/src/main/java/kong/unirest/JsonPatchRequest.java similarity index 98% rename from unirest/src/main/java/unirest/JsonPatchRequest.java rename to unirest/src/main/java/kong/unirest/JsonPatchRequest.java index 5357d9968..86a1bccef 100644 --- a/unirest/src/main/java/unirest/JsonPatchRequest.java +++ b/unirest/src/main/java/kong/unirest/JsonPatchRequest.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; public interface JsonPatchRequest extends HttpRequest, Body { String CONTENT_TYPE = "application/json-patch+json"; diff --git a/unirest/src/main/java/unirest/JsonResponse.java b/unirest/src/main/java/kong/unirest/JsonResponse.java similarity index 99% rename from unirest/src/main/java/unirest/JsonResponse.java rename to unirest/src/main/java/kong/unirest/JsonResponse.java index b89395f2b..787db9acf 100644 --- a/unirest/src/main/java/unirest/JsonResponse.java +++ b/unirest/src/main/java/kong/unirest/JsonResponse.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.io.ByteArrayInputStream; import java.io.InputStream; diff --git a/unirest/src/main/java/unirest/MultipartBody.java b/unirest/src/main/java/kong/unirest/MultipartBody.java similarity index 99% rename from unirest/src/main/java/unirest/MultipartBody.java rename to unirest/src/main/java/kong/unirest/MultipartBody.java index ff57f81f0..a8501dca0 100644 --- a/unirest/src/main/java/unirest/MultipartBody.java +++ b/unirest/src/main/java/kong/unirest/MultipartBody.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.HttpMultipartMode; diff --git a/unirest/src/main/java/unirest/NoRedirects.java b/unirest/src/main/java/kong/unirest/NoRedirects.java similarity index 98% rename from unirest/src/main/java/unirest/NoRedirects.java rename to unirest/src/main/java/kong/unirest/NoRedirects.java index 6585f695c..ae7d04c73 100644 --- a/unirest/src/main/java/unirest/NoRedirects.java +++ b/unirest/src/main/java/kong/unirest/NoRedirects.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; diff --git a/unirest/src/main/java/unirest/ObjectMapper.java b/unirest/src/main/java/kong/unirest/ObjectMapper.java similarity index 98% rename from unirest/src/main/java/unirest/ObjectMapper.java rename to unirest/src/main/java/kong/unirest/ObjectMapper.java index 999ab6092..3e86d1c3f 100644 --- a/unirest/src/main/java/unirest/ObjectMapper.java +++ b/unirest/src/main/java/kong/unirest/ObjectMapper.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; public interface ObjectMapper { T readValue(String value, Class valueType); diff --git a/unirest/src/main/java/unirest/ObjectResponse.java b/unirest/src/main/java/kong/unirest/ObjectResponse.java similarity index 99% rename from unirest/src/main/java/unirest/ObjectResponse.java rename to unirest/src/main/java/kong/unirest/ObjectResponse.java index 04e1c7cd1..55a10771f 100644 --- a/unirest/src/main/java/unirest/ObjectResponse.java +++ b/unirest/src/main/java/kong/unirest/ObjectResponse.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.io.ByteArrayInputStream; import java.io.InputStream; diff --git a/unirest/src/main/java/unirest/PagedList.java b/unirest/src/main/java/kong/unirest/PagedList.java similarity index 99% rename from unirest/src/main/java/unirest/PagedList.java rename to unirest/src/main/java/kong/unirest/PagedList.java index d3981a451..0742a0155 100644 --- a/unirest/src/main/java/unirest/PagedList.java +++ b/unirest/src/main/java/kong/unirest/PagedList.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.util.ArrayList; import java.util.List; diff --git a/unirest/src/main/java/unirest/Path.java b/unirest/src/main/java/kong/unirest/Path.java similarity index 99% rename from unirest/src/main/java/unirest/Path.java rename to unirest/src/main/java/kong/unirest/Path.java index d2cfeff29..143055648 100644 --- a/unirest/src/main/java/unirest/Path.java +++ b/unirest/src/main/java/kong/unirest/Path.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; diff --git a/unirest/src/main/java/unirest/RawResponse.java b/unirest/src/main/java/kong/unirest/RawResponse.java similarity index 98% rename from unirest/src/main/java/unirest/RawResponse.java rename to unirest/src/main/java/kong/unirest/RawResponse.java index 01b3f7d96..18ba7c14d 100644 --- a/unirest/src/main/java/unirest/RawResponse.java +++ b/unirest/src/main/java/kong/unirest/RawResponse.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.io.InputStream; import java.io.InputStreamReader; diff --git a/unirest/src/main/java/unirest/RawResponseBase.java b/unirest/src/main/java/kong/unirest/RawResponseBase.java similarity index 99% rename from unirest/src/main/java/unirest/RawResponseBase.java rename to unirest/src/main/java/kong/unirest/RawResponseBase.java index 3efe010de..d9e710399 100644 --- a/unirest/src/main/java/unirest/RawResponseBase.java +++ b/unirest/src/main/java/kong/unirest/RawResponseBase.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/unirest/src/main/java/unirest/RequestBodyEntity.java b/unirest/src/main/java/kong/unirest/RequestBodyEntity.java similarity index 98% rename from unirest/src/main/java/unirest/RequestBodyEntity.java rename to unirest/src/main/java/kong/unirest/RequestBodyEntity.java index 7b203d465..8475b9b3c 100644 --- a/unirest/src/main/java/unirest/RequestBodyEntity.java +++ b/unirest/src/main/java/kong/unirest/RequestBodyEntity.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.nio.charset.Charset; diff --git a/unirest/src/main/java/unirest/RequestPrep.java b/unirest/src/main/java/kong/unirest/RequestPrep.java similarity index 87% rename from unirest/src/main/java/unirest/RequestPrep.java rename to unirest/src/main/java/kong/unirest/RequestPrep.java index f546aed46..0d9f5deeb 100644 --- a/unirest/src/main/java/unirest/RequestPrep.java +++ b/unirest/src/main/java/kong/unirest/RequestPrep.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.Header; import org.apache.http.HttpEntity; @@ -37,8 +37,6 @@ import java.util.Map; import java.util.function.Function; -import static unirest.HttpMethod.*; - class RequestPrep { private static final String CONTENT_TYPE = "content-type"; private static final String ACCEPT_ENCODING_HEADER = "accept-encoding"; @@ -50,13 +48,13 @@ class RequestPrep { static { FACTORIES = new HashMap<>(); - FACTORIES.put(GET, HttpGet::new); - FACTORIES.put(POST, HttpPost::new); - FACTORIES.put(PUT, HttpPut::new); - FACTORIES.put(DELETE, HttpDeleteWithBody::new); - FACTORIES.put(PATCH, HttpPatchWithBody::new); - FACTORIES.put(OPTIONS, HttpOptions::new); - FACTORIES.put(HEAD, HttpHead::new); + FACTORIES.put(HttpMethod.GET, HttpGet::new); + FACTORIES.put(HttpMethod.POST, HttpPost::new); + FACTORIES.put(HttpMethod.PUT, HttpPut::new); + FACTORIES.put(HttpMethod.DELETE, HttpDeleteWithBody::new); + FACTORIES.put(HttpMethod.PATCH, HttpPatchWithBody::new); + FACTORIES.put(HttpMethod.OPTIONS, HttpOptions::new); + FACTORIES.put(HttpMethod.HEAD, HttpHead::new); } RequestPrep(HttpRequest request, boolean async){ @@ -94,12 +92,12 @@ private Function register(HttpMethod method) { return u -> new ApacheRequestWithBody(method, u); } - private Header toEntries(unirest.Header k) { + private Header toEntries(kong.unirest.Header k) { return new BasicHeader(k.getName(), k.getValue()); } private void setBody(HttpRequestBase reqObj) { - if (!(request.getHttpMethod() == GET || request.getHttpMethod() == HttpMethod.HEAD)) { + if (!(request.getHttpMethod() == HttpMethod.GET || request.getHttpMethod() == HttpMethod.HEAD)) { if (request.getBody() != null) { HttpEntity entity = request.getBody().getEntity(); if (async) { diff --git a/unirest/src/main/java/unirest/StringResponse.java b/unirest/src/main/java/kong/unirest/StringResponse.java similarity index 98% rename from unirest/src/main/java/unirest/StringResponse.java rename to unirest/src/main/java/kong/unirest/StringResponse.java index 141804fcf..ed7ea5f4b 100644 --- a/unirest/src/main/java/unirest/StringResponse.java +++ b/unirest/src/main/java/kong/unirest/StringResponse.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.io.ByteArrayInputStream; import java.io.InputStream; diff --git a/unirest/src/main/java/unirest/SyncIdleConnectionMonitorThread.java b/unirest/src/main/java/kong/unirest/SyncIdleConnectionMonitorThread.java similarity index 98% rename from unirest/src/main/java/unirest/SyncIdleConnectionMonitorThread.java rename to unirest/src/main/java/kong/unirest/SyncIdleConnectionMonitorThread.java index dd66df913..f7161108e 100644 --- a/unirest/src/main/java/unirest/SyncIdleConnectionMonitorThread.java +++ b/unirest/src/main/java/kong/unirest/SyncIdleConnectionMonitorThread.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.util.concurrent.TimeUnit; diff --git a/unirest/src/main/java/unirest/Unirest.java b/unirest/src/main/java/kong/unirest/Unirest.java similarity index 99% rename from unirest/src/main/java/unirest/Unirest.java rename to unirest/src/main/java/kong/unirest/Unirest.java index db9dfe99e..0aa6537f8 100644 --- a/unirest/src/main/java/unirest/Unirest.java +++ b/unirest/src/main/java/kong/unirest/Unirest.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; public class Unirest { diff --git a/unirest/src/main/java/unirest/UnirestConfigException.java b/unirest/src/main/java/kong/unirest/UnirestConfigException.java similarity index 98% rename from unirest/src/main/java/unirest/UnirestConfigException.java rename to unirest/src/main/java/kong/unirest/UnirestConfigException.java index 54329560c..cbad99d13 100644 --- a/unirest/src/main/java/unirest/UnirestConfigException.java +++ b/unirest/src/main/java/kong/unirest/UnirestConfigException.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; public class UnirestConfigException extends UnirestException { public UnirestConfigException(Exception e){ diff --git a/unirest/src/main/java/unirest/UnirestException.java b/unirest/src/main/java/kong/unirest/UnirestException.java similarity index 98% rename from unirest/src/main/java/unirest/UnirestException.java rename to unirest/src/main/java/kong/unirest/UnirestException.java index 93d0e316c..d4f58aa0e 100644 --- a/unirest/src/main/java/unirest/UnirestException.java +++ b/unirest/src/main/java/kong/unirest/UnirestException.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import java.util.Collection; import java.util.stream.Collectors; diff --git a/unirest/src/main/java/unirest/UnirestInstance.java b/unirest/src/main/java/kong/unirest/UnirestInstance.java similarity index 99% rename from unirest/src/main/java/unirest/UnirestInstance.java rename to unirest/src/main/java/kong/unirest/UnirestInstance.java index 4a92ea63a..ccee8ea10 100644 --- a/unirest/src/main/java/unirest/UnirestInstance.java +++ b/unirest/src/main/java/kong/unirest/UnirestInstance.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; public class UnirestInstance implements AutoCloseable { diff --git a/unirest/src/main/java/unirest/UnirestParsingException.java b/unirest/src/main/java/kong/unirest/UnirestParsingException.java similarity index 98% rename from unirest/src/main/java/unirest/UnirestParsingException.java rename to unirest/src/main/java/kong/unirest/UnirestParsingException.java index ce3b4f71b..8046ed688 100644 --- a/unirest/src/main/java/unirest/UnirestParsingException.java +++ b/unirest/src/main/java/kong/unirest/UnirestParsingException.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; public class UnirestParsingException extends UnirestException { private final String originalBody; diff --git a/unirest/src/main/java/unirest/Util.java b/unirest/src/main/java/kong/unirest/Util.java similarity index 99% rename from unirest/src/main/java/unirest/Util.java rename to unirest/src/main/java/kong/unirest/Util.java index c466635eb..293a2b6c9 100644 --- a/unirest/src/main/java/unirest/Util.java +++ b/unirest/src/main/java/kong/unirest/Util.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; diff --git a/unirest/src/test/java/BehaviorTests/AsEmptyTest.java b/unirest/src/test/java/BehaviorTests/AsEmptyTest.java index 4f3cbae84..d94e399e3 100644 --- a/unirest/src/test/java/BehaviorTests/AsEmptyTest.java +++ b/unirest/src/test/java/BehaviorTests/AsEmptyTest.java @@ -26,8 +26,8 @@ package BehaviorTests; import org.junit.Test; -import unirest.HttpResponse; -import unirest.Unirest; +import kong.unirest.HttpResponse; +import kong.unirest.Unirest; import static junit.framework.TestCase.assertEquals; diff --git a/unirest/src/test/java/BehaviorTests/AsFileTests.java b/unirest/src/test/java/BehaviorTests/AsFileTests.java index 1c2eee213..3f3f5e46a 100644 --- a/unirest/src/test/java/BehaviorTests/AsFileTests.java +++ b/unirest/src/test/java/BehaviorTests/AsFileTests.java @@ -26,9 +26,9 @@ package BehaviorTests; import org.junit.Test; -import unirest.JacksonObjectMapper; -import unirest.TestUtil; -import unirest.Unirest; +import kong.unirest.JacksonObjectMapper; +import kong.unirest.TestUtil; +import kong.unirest.Unirest; import java.io.File; import java.nio.file.Files; diff --git a/unirest/src/test/java/BehaviorTests/AsGenericTypeTest.java b/unirest/src/test/java/BehaviorTests/AsGenericTypeTest.java index 1a95ab141..cadef092f 100644 --- a/unirest/src/test/java/BehaviorTests/AsGenericTypeTest.java +++ b/unirest/src/test/java/BehaviorTests/AsGenericTypeTest.java @@ -25,9 +25,9 @@ package BehaviorTests; -import unirest.GsonObjectMapper; -import unirest.Unirest; -import unirest.GenericType; +import kong.unirest.GsonObjectMapper; +import kong.unirest.Unirest; +import kong.unirest.GenericType; import org.junit.Test; import java.util.Arrays; diff --git a/unirest/src/test/java/BehaviorTests/AsJsonTest.java b/unirest/src/test/java/BehaviorTests/AsJsonTest.java index afa989a37..79b68d82f 100644 --- a/unirest/src/test/java/BehaviorTests/AsJsonTest.java +++ b/unirest/src/test/java/BehaviorTests/AsJsonTest.java @@ -25,14 +25,13 @@ package BehaviorTests; -import unirest.HttpResponse; -import unirest.JsonNode; -import unirest.Unirest; +import kong.unirest.HttpResponse; +import kong.unirest.JsonNode; +import kong.unirest.Unirest; import org.junit.Test; -import unirest.MockCallback; -import unirest.TestUtil; +import kong.unirest.MockCallback; +import kong.unirest.TestUtil; -import java.io.InputStream; import java.util.concurrent.CompletableFuture; import static org.junit.Assert.assertEquals; diff --git a/unirest/src/test/java/BehaviorTests/AsObjectTest.java b/unirest/src/test/java/BehaviorTests/AsObjectTest.java index f0791df4c..7b107af57 100644 --- a/unirest/src/test/java/BehaviorTests/AsObjectTest.java +++ b/unirest/src/test/java/BehaviorTests/AsObjectTest.java @@ -26,8 +26,8 @@ package BehaviorTests; import com.google.gson.Gson; +import kong.unirest.*; import org.junit.Assert; -import unirest.*; import org.junit.Test; import static junit.framework.TestCase.assertEquals; @@ -96,7 +96,7 @@ public void ifTheObjectMapperFailsReturnEmptyAndAddToParsingError() { assertNull(request.getBody()); assertTrue(request.getParsingError().isPresent()); - assertEquals("unirest.UnirestException: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'You': was expecting ('true', 'false' or 'null')\n" + + assertEquals("kong.unirest.UnirestException: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'You': was expecting ('true', 'false' or 'null')\n" + " at [Source: (String)\"You did something bad\"; line: 1, column: 4]", request.getParsingError().get().getMessage()); assertEquals("You did something bad", request.getParsingError().get().getOriginalBody()); @@ -109,7 +109,7 @@ public void ifTheObjectMapperFailsReturnEmptyAndAddToParsingErrorObGenericTypes( assertNull(request.getBody()); assertTrue(request.getParsingError().isPresent()); - assertEquals("unirest.UnirestException: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'You': was expecting ('true', 'false' or 'null')\n" + + assertEquals("kong.unirest.UnirestException: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'You': was expecting ('true', 'false' or 'null')\n" + " at [Source: (String)\"You did something bad\"; line: 1, column: 4]", request.getParsingError().get().getMessage()); assertEquals("You did something bad", request.getParsingError().get().getOriginalBody()); } @@ -121,7 +121,7 @@ public void unirestExceptionsAreAlsoParseExceptions() { assertNull(request.getBody()); assertTrue(request.getParsingError().isPresent()); - assertEquals("unirest.UnirestException: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'You': was expecting ('true', 'false' or 'null')\n" + + assertEquals("kong.unirest.UnirestException: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'You': was expecting ('true', 'false' or 'null')\n" + " at [Source: (String)\"You did something bad\"; line: 1, column: 4]", request.getParsingError().get().getMessage()); assertEquals("You did something bad", request.getParsingError().get().getOriginalBody()); } diff --git a/unirest/src/test/java/BehaviorTests/AsStringTest.java b/unirest/src/test/java/BehaviorTests/AsStringTest.java index 6f70488ad..54d731736 100644 --- a/unirest/src/test/java/BehaviorTests/AsStringTest.java +++ b/unirest/src/test/java/BehaviorTests/AsStringTest.java @@ -26,9 +26,9 @@ package BehaviorTests; import org.junit.Test; -import unirest.HttpResponse; -import unirest.TestUtil; -import unirest.Unirest; +import kong.unirest.HttpResponse; +import kong.unirest.TestUtil; +import kong.unirest.Unirest; import java.util.concurrent.CompletableFuture; diff --git a/unirest/src/test/java/BehaviorTests/BddTest.java b/unirest/src/test/java/BehaviorTests/BddTest.java index ae655e191..9f2cbc1f2 100644 --- a/unirest/src/test/java/BehaviorTests/BddTest.java +++ b/unirest/src/test/java/BehaviorTests/BddTest.java @@ -25,17 +25,18 @@ package BehaviorTests; +import kong.unirest.HttpResponse; +import kong.unirest.JacksonObjectMapper; +import kong.unirest.JsonNode; +import kong.unirest.Unirest; import org.junit.After; -import unirest.*; import org.junit.Before; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import static unirest.TestUtil.read; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static kong.unirest.TestUtil.read; +import static org.junit.Assert.*; public class BddTest { private JacksonObjectMapper objectMapper = new JacksonObjectMapper(); diff --git a/unirest/src/test/java/BehaviorTests/CallbackFutureTest.java b/unirest/src/test/java/BehaviorTests/CallbackFutureTest.java index 2c48d2918..9e274d283 100644 --- a/unirest/src/test/java/BehaviorTests/CallbackFutureTest.java +++ b/unirest/src/test/java/BehaviorTests/CallbackFutureTest.java @@ -25,11 +25,11 @@ package BehaviorTests; -import unirest.Unirest; -import unirest.NoopCallback; +import kong.unirest.Unirest; +import kong.unirest.NoopCallback; import org.junit.Test; -import static unirest.MockCallback.json; +import static kong.unirest.MockCallback.json; public class CallbackFutureTest extends BddTest { diff --git a/unirest/src/test/java/BehaviorTests/ConsumerTests.java b/unirest/src/test/java/BehaviorTests/ConsumerTests.java index bc1344c16..5a6a0408c 100644 --- a/unirest/src/test/java/BehaviorTests/ConsumerTests.java +++ b/unirest/src/test/java/BehaviorTests/ConsumerTests.java @@ -27,7 +27,7 @@ import org.junit.After; import org.junit.Test; -import unirest.Unirest; +import kong.unirest.Unirest; import static org.junit.Assert.assertEquals; diff --git a/unirest/src/test/java/BehaviorTests/DefectTest.java b/unirest/src/test/java/BehaviorTests/DefectTest.java index d115d656b..ad2d80c6d 100644 --- a/unirest/src/test/java/BehaviorTests/DefectTest.java +++ b/unirest/src/test/java/BehaviorTests/DefectTest.java @@ -29,7 +29,7 @@ import org.apache.http.nio.client.HttpAsyncClient; import org.json.JSONObject; import org.junit.Ignore; -import unirest.Unirest; +import kong.unirest.Unirest; import org.junit.Test; import java.io.IOException; diff --git a/unirest/src/test/java/BehaviorTests/FormPostingTest.java b/unirest/src/test/java/BehaviorTests/FormPostingTest.java index f2ccc44eb..617d9935c 100644 --- a/unirest/src/test/java/BehaviorTests/FormPostingTest.java +++ b/unirest/src/test/java/BehaviorTests/FormPostingTest.java @@ -25,7 +25,10 @@ package BehaviorTests; -import unirest.*; +import kong.unirest.HttpRequest; +import kong.unirest.MockCallback; +import kong.unirest.TestUtil; +import kong.unirest.Unirest; import org.apache.commons.io.IOUtils; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.HttpMultipartMode; @@ -40,7 +43,7 @@ import java.util.Arrays; import static org.junit.Assert.assertEquals; -import static unirest.TestUtil.rezFile; +import static kong.unirest.TestUtil.rezFile; public class FormPostingTest extends BddTest { @Test diff --git a/unirest/src/test/java/BehaviorTests/GZipTest.java b/unirest/src/test/java/BehaviorTests/GZipTest.java index 8ad513477..b57181f47 100644 --- a/unirest/src/test/java/BehaviorTests/GZipTest.java +++ b/unirest/src/test/java/BehaviorTests/GZipTest.java @@ -25,7 +25,7 @@ package BehaviorTests; -import unirest.Unirest; +import kong.unirest.Unirest; import org.junit.Test; public class GZipTest extends BddTest { diff --git a/unirest/src/test/java/BehaviorTests/HeaderTest.java b/unirest/src/test/java/BehaviorTests/HeaderTest.java index ef980f4f4..1429dd6d0 100644 --- a/unirest/src/test/java/BehaviorTests/HeaderTest.java +++ b/unirest/src/test/java/BehaviorTests/HeaderTest.java @@ -25,13 +25,16 @@ package BehaviorTests; +import kong.unirest.GetRequest; +import kong.unirest.HttpResponse; +import kong.unirest.JsonNode; +import kong.unirest.Unirest; import org.junit.Ignore; import org.junit.Test; -import unirest.*; import static org.junit.Assert.assertEquals; -import static unirest.TestUtil.assertBasicAuth; -import static unirest.TestUtil.mapOf; +import static kong.unirest.TestUtil.assertBasicAuth; +import static kong.unirest.TestUtil.mapOf; public class HeaderTest extends BddTest { private String value = "one"; diff --git a/unirest/src/test/java/BehaviorTests/InterceptorTest.java b/unirest/src/test/java/BehaviorTests/InterceptorTest.java index d586c1c7e..dabdfb315 100644 --- a/unirest/src/test/java/BehaviorTests/InterceptorTest.java +++ b/unirest/src/test/java/BehaviorTests/InterceptorTest.java @@ -25,7 +25,7 @@ package BehaviorTests; -import unirest.Unirest; +import kong.unirest.Unirest; import org.apache.http.HttpException; import org.apache.http.HttpRequest; import org.apache.http.HttpRequestInterceptor; diff --git a/unirest/src/test/java/BehaviorTests/JsonPatchTest.java b/unirest/src/test/java/BehaviorTests/JsonPatchTest.java index 125d37f99..efa0bda2c 100644 --- a/unirest/src/test/java/BehaviorTests/JsonPatchTest.java +++ b/unirest/src/test/java/BehaviorTests/JsonPatchTest.java @@ -26,16 +26,16 @@ package BehaviorTests; import com.google.common.collect.ImmutableMap; -import unirest.Unirest; +import kong.unirest.Unirest; import org.json.JSONArray; import org.json.JSONObject; import org.junit.Test; import org.skyscreamer.jsonassert.JSONAssert; -import unirest.TestUtil; +import kong.unirest.TestUtil; import java.io.IOException; -import static unirest.JsonPatchOperation.*; +import static kong.unirest.JsonPatchOperation.*; public class JsonPatchTest extends BddTest { diff --git a/unirest/src/test/java/BehaviorTests/LifeCycleTest.java b/unirest/src/test/java/BehaviorTests/LifeCycleTest.java index 65cb14349..dfba1217e 100644 --- a/unirest/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/unirest/src/test/java/BehaviorTests/LifeCycleTest.java @@ -26,12 +26,12 @@ package BehaviorTests; import com.github.paweladamski.httpclientmock.HttpClientMock; +import kong.unirest.*; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; -import unirest.*; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.junit.Test; diff --git a/unirest/src/test/java/BehaviorTests/MockServer.java b/unirest/src/test/java/BehaviorTests/MockServer.java index 49d6bd6bc..18be8ffc9 100644 --- a/unirest/src/test/java/BehaviorTests/MockServer.java +++ b/unirest/src/test/java/BehaviorTests/MockServer.java @@ -55,8 +55,8 @@ a copy of this software and associated documentation files (the import spark.Response; import spark.Spark; import spark.utils.IOUtils; -import unirest.JacksonObjectMapper; -import unirest.TestUtil; +import kong.unirest.JacksonObjectMapper; +import kong.unirest.TestUtil; import javax.servlet.ServletOutputStream; import java.io.File; diff --git a/unirest/src/test/java/BehaviorTests/ObjectFunctionalTest.java b/unirest/src/test/java/BehaviorTests/ObjectFunctionalTest.java index 4f5a0b9f6..6f4a3f48c 100644 --- a/unirest/src/test/java/BehaviorTests/ObjectFunctionalTest.java +++ b/unirest/src/test/java/BehaviorTests/ObjectFunctionalTest.java @@ -25,15 +25,12 @@ package BehaviorTests; -import com.google.common.collect.ImmutableMap; import com.google.gson.Gson; import org.junit.Test; -import unirest.Unirest; +import kong.unirest.Unirest; -import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.ExecutionException; import static com.google.common.collect.ImmutableMap.of; import static org.junit.Assert.assertEquals; diff --git a/unirest/src/test/java/BehaviorTests/PagingTest.java b/unirest/src/test/java/BehaviorTests/PagingTest.java index 172fba7e6..e7c7926fc 100644 --- a/unirest/src/test/java/BehaviorTests/PagingTest.java +++ b/unirest/src/test/java/BehaviorTests/PagingTest.java @@ -26,8 +26,8 @@ package BehaviorTests; import org.junit.Test; -import unirest.PagedList; -import unirest.Unirest; +import kong.unirest.PagedList; +import kong.unirest.Unirest; import static org.junit.Assert.assertEquals; diff --git a/unirest/src/test/java/BehaviorTests/PathParamTest.java b/unirest/src/test/java/BehaviorTests/PathParamTest.java index 99ae43cb9..b04cffb49 100644 --- a/unirest/src/test/java/BehaviorTests/PathParamTest.java +++ b/unirest/src/test/java/BehaviorTests/PathParamTest.java @@ -25,10 +25,10 @@ package BehaviorTests; -import unirest.Unirest; -import unirest.UnirestException; +import kong.unirest.Unirest; +import kong.unirest.UnirestException; import org.junit.Test; -import unirest.TestUtil; +import kong.unirest.TestUtil; public class PathParamTest extends BddTest { diff --git a/unirest/src/test/java/BehaviorTests/PostRequestHandlersTest.java b/unirest/src/test/java/BehaviorTests/PostRequestHandlersTest.java index 7def956bd..a5ea44eda 100644 --- a/unirest/src/test/java/BehaviorTests/PostRequestHandlersTest.java +++ b/unirest/src/test/java/BehaviorTests/PostRequestHandlersTest.java @@ -27,8 +27,8 @@ import org.junit.After; import org.junit.Test; -import unirest.HttpResponse; -import unirest.Unirest; +import kong.unirest.HttpResponse; +import kong.unirest.Unirest; import static org.junit.Assert.*; diff --git a/unirest/src/test/java/BehaviorTests/ProxyTest.java b/unirest/src/test/java/BehaviorTests/ProxyTest.java index 227d1b87d..c9de4aecc 100644 --- a/unirest/src/test/java/BehaviorTests/ProxyTest.java +++ b/unirest/src/test/java/BehaviorTests/ProxyTest.java @@ -29,8 +29,8 @@ import org.junit.After; import org.junit.Ignore; import org.junit.Test; -import unirest.HttpResponse; -import unirest.Unirest; +import kong.unirest.HttpResponse; +import kong.unirest.Unirest; import static org.junit.Assert.assertTrue; diff --git a/unirest/src/test/java/BehaviorTests/QueryStringTest.java b/unirest/src/test/java/BehaviorTests/QueryStringTest.java index 9350ce17b..0be9afc26 100644 --- a/unirest/src/test/java/BehaviorTests/QueryStringTest.java +++ b/unirest/src/test/java/BehaviorTests/QueryStringTest.java @@ -25,9 +25,9 @@ package BehaviorTests; -import unirest.HttpResponse; -import unirest.JsonNode; -import unirest.Unirest; +import kong.unirest.HttpResponse; +import kong.unirest.JsonNode; +import kong.unirest.Unirest; import org.junit.Test; import java.util.Arrays; diff --git a/unirest/src/test/java/BehaviorTests/RedirectHandling.java b/unirest/src/test/java/BehaviorTests/RedirectHandling.java index 2364eb27a..8fb271665 100644 --- a/unirest/src/test/java/BehaviorTests/RedirectHandling.java +++ b/unirest/src/test/java/BehaviorTests/RedirectHandling.java @@ -25,8 +25,8 @@ package BehaviorTests; -import unirest.HttpResponse; -import unirest.Unirest; +import kong.unirest.HttpResponse; +import kong.unirest.Unirest; import org.junit.Test; import java.util.concurrent.ExecutionException; diff --git a/unirest/src/test/java/BehaviorTests/RequestCapture.java b/unirest/src/test/java/BehaviorTests/RequestCapture.java index c315ebabd..f1816a6d0 100644 --- a/unirest/src/test/java/BehaviorTests/RequestCapture.java +++ b/unirest/src/test/java/BehaviorTests/RequestCapture.java @@ -27,14 +27,14 @@ import com.google.common.base.Strings; import com.google.common.collect.*; -import unirest.JsonPatch; -import unirest.JsonPatchItem; -import unirest.JsonPatchOperation; +import kong.unirest.JsonPatch; +import kong.unirest.JsonPatchItem; +import kong.unirest.JsonPatchOperation; import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.entity.ContentType; import spark.Request; -import unirest.HttpMethod; -import unirest.TestUtil; +import kong.unirest.HttpMethod; +import kong.unirest.TestUtil; import javax.servlet.MultipartConfigElement; import javax.servlet.ServletException; @@ -44,7 +44,7 @@ import java.util.*; import java.util.stream.Collectors; -import static unirest.JsonPatchRequest.CONTENT_TYPE; +import static kong.unirest.JsonPatchRequest.CONTENT_TYPE; import static java.lang.System.getProperty; import static org.hamcrest.CoreMatchers.endsWith; import static org.hamcrest.CoreMatchers.hasItem; diff --git a/unirest/src/test/java/BehaviorTests/ResponseHeaderTest.java b/unirest/src/test/java/BehaviorTests/ResponseHeaderTest.java index 4b72605fd..0fca663df 100644 --- a/unirest/src/test/java/BehaviorTests/ResponseHeaderTest.java +++ b/unirest/src/test/java/BehaviorTests/ResponseHeaderTest.java @@ -26,9 +26,9 @@ package BehaviorTests; import org.junit.Test; -import unirest.Header; -import unirest.Headers; -import unirest.Unirest; +import kong.unirest.Header; +import kong.unirest.Headers; +import kong.unirest.Unirest; import static org.junit.Assert.assertEquals; diff --git a/unirest/src/test/java/BehaviorTests/SendBodyTest.java b/unirest/src/test/java/BehaviorTests/SendBodyTest.java index 81755509f..fe4cce34b 100644 --- a/unirest/src/test/java/BehaviorTests/SendBodyTest.java +++ b/unirest/src/test/java/BehaviorTests/SendBodyTest.java @@ -25,15 +25,15 @@ package BehaviorTests; -import unirest.JsonNode; -import unirest.Unirest; -import unirest.UnirestConfigException; +import kong.unirest.JsonNode; +import kong.unirest.Unirest; +import kong.unirest.UnirestConfigException; import org.json.JSONArray; import org.json.JSONObject; import org.junit.Test; -import unirest.MockCallback; +import kong.unirest.MockCallback; -import static unirest.TestUtil.assertException; +import static kong.unirest.TestUtil.assertException; public class SendBodyTest extends BddTest { @Test diff --git a/unirest/src/test/java/BehaviorTests/TimeoutTests.java b/unirest/src/test/java/BehaviorTests/TimeoutTests.java index c2546aa71..57f88bd05 100644 --- a/unirest/src/test/java/BehaviorTests/TimeoutTests.java +++ b/unirest/src/test/java/BehaviorTests/TimeoutTests.java @@ -27,9 +27,9 @@ package BehaviorTests; -import unirest.Config; -import unirest.Unirest; -import unirest.UnirestException; +import kong.unirest.Config; +import kong.unirest.Unirest; +import kong.unirest.UnirestException; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; import org.junit.Ignore; diff --git a/unirest/src/test/java/BehaviorTests/VerbTest.java b/unirest/src/test/java/BehaviorTests/VerbTest.java index 42053e3de..c427e7522 100644 --- a/unirest/src/test/java/BehaviorTests/VerbTest.java +++ b/unirest/src/test/java/BehaviorTests/VerbTest.java @@ -25,13 +25,11 @@ package BehaviorTests; -import unirest.HttpMethod; -import unirest.HttpResponse; -import unirest.Unirest; +import kong.unirest.HttpMethod; +import kong.unirest.HttpResponse; +import kong.unirest.Unirest; import org.junit.Test; -import java.io.InputStream; - import static org.junit.Assert.assertEquals; public class VerbTest extends BddTest { diff --git a/unirest/src/test/java/unirest/ClientFactoryTest.java b/unirest/src/test/java/kong/unirest/ClientFactoryTest.java similarity index 99% rename from unirest/src/test/java/unirest/ClientFactoryTest.java rename to unirest/src/test/java/kong/unirest/ClientFactoryTest.java index a9407e3a0..07825e7d0 100644 --- a/unirest/src/test/java/unirest/ClientFactoryTest.java +++ b/unirest/src/test/java/kong/unirest/ClientFactoryTest.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.HttpRequestInterceptor; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; diff --git a/unirest/src/test/java/unirest/ConfigTest.java b/unirest/src/test/java/kong/unirest/ConfigTest.java similarity index 99% rename from unirest/src/test/java/unirest/ConfigTest.java rename to unirest/src/test/java/kong/unirest/ConfigTest.java index a4bb8b513..1ddab29ee 100644 --- a/unirest/src/test/java/unirest/ConfigTest.java +++ b/unirest/src/test/java/kong/unirest/ConfigTest.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.client.HttpClient; import org.apache.http.impl.client.CloseableHttpClient; diff --git a/unirest/src/test/java/unirest/GsonObjectMapper.java b/unirest/src/test/java/kong/unirest/GsonObjectMapper.java similarity index 95% rename from unirest/src/test/java/unirest/GsonObjectMapper.java rename to unirest/src/test/java/kong/unirest/GsonObjectMapper.java index 5f1520855..a56185163 100644 --- a/unirest/src/test/java/unirest/GsonObjectMapper.java +++ b/unirest/src/test/java/kong/unirest/GsonObjectMapper.java @@ -23,11 +23,9 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import com.google.gson.Gson; -import unirest.GenericType; -import unirest.ObjectMapper; public class GsonObjectMapper implements ObjectMapper { diff --git a/unirest/src/test/java/unirest/HeadersTest.java b/unirest/src/test/java/kong/unirest/HeadersTest.java similarity index 98% rename from unirest/src/test/java/unirest/HeadersTest.java rename to unirest/src/test/java/kong/unirest/HeadersTest.java index bdc943edf..78b7329c4 100644 --- a/unirest/src/test/java/unirest/HeadersTest.java +++ b/unirest/src/test/java/kong/unirest/HeadersTest.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.junit.Test; diff --git a/unirest/src/test/java/unirest/JacksonObjectMapper.java b/unirest/src/test/java/kong/unirest/JacksonObjectMapper.java similarity index 99% rename from unirest/src/test/java/unirest/JacksonObjectMapper.java rename to unirest/src/test/java/kong/unirest/JacksonObjectMapper.java index a5612690a..fe6f5cc8a 100644 --- a/unirest/src/test/java/unirest/JacksonObjectMapper.java +++ b/unirest/src/test/java/kong/unirest/JacksonObjectMapper.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; diff --git a/unirest/src/test/java/unirest/JacksonObjectMapperTest.java b/unirest/src/test/java/kong/unirest/JacksonObjectMapperTest.java similarity index 99% rename from unirest/src/test/java/unirest/JacksonObjectMapperTest.java rename to unirest/src/test/java/kong/unirest/JacksonObjectMapperTest.java index 339965d89..0b8ef4401 100644 --- a/unirest/src/test/java/unirest/JacksonObjectMapperTest.java +++ b/unirest/src/test/java/kong/unirest/JacksonObjectMapperTest.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import BehaviorTests.RequestCapture; import org.junit.Test; diff --git a/unirest/src/test/java/unirest/JsonNodeTest.java b/unirest/src/test/java/kong/unirest/JsonNodeTest.java similarity index 98% rename from unirest/src/test/java/unirest/JsonNodeTest.java rename to unirest/src/test/java/kong/unirest/JsonNodeTest.java index 368a4be7b..b17fea8b0 100644 --- a/unirest/src/test/java/unirest/JsonNodeTest.java +++ b/unirest/src/test/java/kong/unirest/JsonNodeTest.java @@ -23,10 +23,9 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.junit.Test; -import unirest.JsonNode; import static org.junit.Assert.*; diff --git a/unirest/src/test/java/unirest/MockCallback.java b/unirest/src/test/java/kong/unirest/MockCallback.java similarity index 99% rename from unirest/src/test/java/unirest/MockCallback.java rename to unirest/src/test/java/kong/unirest/MockCallback.java index 32941cce2..ec9b6148f 100644 --- a/unirest/src/test/java/unirest/MockCallback.java +++ b/unirest/src/test/java/kong/unirest/MockCallback.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import BehaviorTests.BddTest; diff --git a/unirest/src/test/java/unirest/NoopCallback.java b/unirest/src/test/java/kong/unirest/NoopCallback.java similarity index 93% rename from unirest/src/test/java/unirest/NoopCallback.java rename to unirest/src/test/java/kong/unirest/NoopCallback.java index 5c2756a3b..14d94dc49 100644 --- a/unirest/src/test/java/unirest/NoopCallback.java +++ b/unirest/src/test/java/kong/unirest/NoopCallback.java @@ -23,11 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; - -import unirest.HttpResponse; -import unirest.Callback; -import unirest.UnirestException; +package kong.unirest; public class NoopCallback implements Callback { @Override diff --git a/unirest/src/test/java/unirest/NotImplimented.java b/unirest/src/test/java/kong/unirest/NotImplimented.java similarity index 98% rename from unirest/src/test/java/unirest/NotImplimented.java rename to unirest/src/test/java/kong/unirest/NotImplimented.java index 9b2f6fd43..a6914f2c4 100644 --- a/unirest/src/test/java/unirest/NotImplimented.java +++ b/unirest/src/test/java/kong/unirest/NotImplimented.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; public class NotImplimented extends RuntimeException { } diff --git a/unirest/src/test/java/unirest/PagedListTest.java b/unirest/src/test/java/kong/unirest/PagedListTest.java similarity index 99% rename from unirest/src/test/java/unirest/PagedListTest.java rename to unirest/src/test/java/kong/unirest/PagedListTest.java index 52ecc116e..0df6aa0a5 100644 --- a/unirest/src/test/java/unirest/PagedListTest.java +++ b/unirest/src/test/java/kong/unirest/PagedListTest.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import com.google.common.base.Strings; import org.junit.Test; diff --git a/unirest/src/test/java/unirest/ResponseUtilsTest.java b/unirest/src/test/java/kong/unirest/ResponseUtilsTest.java similarity index 99% rename from unirest/src/test/java/unirest/ResponseUtilsTest.java rename to unirest/src/test/java/kong/unirest/ResponseUtilsTest.java index fa66f4359..983157391 100644 --- a/unirest/src/test/java/unirest/ResponseUtilsTest.java +++ b/unirest/src/test/java/kong/unirest/ResponseUtilsTest.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/unirest/src/test/java/unirest/TestUtil.java b/unirest/src/test/java/kong/unirest/TestUtil.java similarity index 98% rename from unirest/src/test/java/unirest/TestUtil.java rename to unirest/src/test/java/kong/unirest/TestUtil.java index 2f8fb95bc..241174ea3 100644 --- a/unirest/src/test/java/unirest/TestUtil.java +++ b/unirest/src/test/java/kong/unirest/TestUtil.java @@ -23,15 +23,13 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import BehaviorTests.MockServer; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.guava.GuavaModule; import com.google.common.base.Charsets; import com.google.common.io.Resources; -import unirest.HttpResponse; import java.io.*; import java.net.URISyntaxException; diff --git a/unirest/src/test/java/unirest/UriFormatterTest.java b/unirest/src/test/java/kong/unirest/UriFormatterTest.java similarity index 98% rename from unirest/src/test/java/unirest/UriFormatterTest.java rename to unirest/src/test/java/kong/unirest/UriFormatterTest.java index 80705aec3..a2bd16e9d 100644 --- a/unirest/src/test/java/unirest/UriFormatterTest.java +++ b/unirest/src/test/java/kong/unirest/UriFormatterTest.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.junit.Test; diff --git a/unirest/src/test/java/unirest/UtilTest.java b/unirest/src/test/java/kong/unirest/UtilTest.java similarity index 98% rename from unirest/src/test/java/unirest/UtilTest.java rename to unirest/src/test/java/kong/unirest/UtilTest.java index a63402cf9..4fb597bac 100644 --- a/unirest/src/test/java/unirest/UtilTest.java +++ b/unirest/src/test/java/kong/unirest/UtilTest.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package unirest; +package kong.unirest; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; From 9e22eac33b9c126974453f5a456f07f4aeaefbb8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 20 Feb 2019 20:47:20 -0600 Subject: [PATCH 0454/1769] support a simple unirest list of common mime types --- .../main/java/kong/unirest/ContentType.java | 78 +++++++++++++++++++ .../java/kong/unirest/HttpRequestBody.java | 1 - .../kong/unirest/HttpRequestMultiPart.java | 34 ++++---- .../kong/unirest/HttpRequestWithBody.java | 1 - .../main/java/kong/unirest/MultipartBody.java | 7 -- .../java/BehaviorTests/FormPostingTest.java | 6 +- .../java/BehaviorTests/RequestCapture.java | 7 +- .../java/kong/unirest/ContentTypeTest.java | 60 ++++++++++++++ 8 files changed, 160 insertions(+), 34 deletions(-) create mode 100644 unirest/src/main/java/kong/unirest/ContentType.java create mode 100644 unirest/src/test/java/kong/unirest/ContentTypeTest.java diff --git a/unirest/src/main/java/kong/unirest/ContentType.java b/unirest/src/main/java/kong/unirest/ContentType.java new file mode 100644 index 000000000..4cd818135 --- /dev/null +++ b/unirest/src/main/java/kong/unirest/ContentType.java @@ -0,0 +1,78 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +import static java.nio.charset.StandardCharsets.ISO_8859_1; + +public enum ContentType { + APPLICATION_ATOM_XML("application/atom+xml", ISO_8859_1), + APPLICATION_FORM_URLENCODED("application/x-www-form-urlencoded", ISO_8859_1), + APPLICATION_JSON("application/json", StandardCharsets.UTF_8), + APPLICATION_OCTET_STREAM("application/octet-stream"), + APPLICATION_SVG_XML("application/svg+xml", ISO_8859_1), + APPLICATION_XHTML_XML("application/xhtml+xml", ISO_8859_1), + APPLICATION_XML("application/xml", ISO_8859_1), + IMAGE_BMP("image/bmp"), + IMAGE_GIF("image/gif"), + IMAGE_JPEG("image/jpeg"), + IMAGE_PNG("image/png"), + IMAGE_SVG("image/svg+xml"), + IMAGE_TIFF("image/tiff"), + IMAGE_WEBP("image/webp"), + MULTIPART_FORM_DATA("multipart/form-data", ISO_8859_1), + TEXT_HTML("text/html", ISO_8859_1), + TEXT_PLAIN("text/plain", ISO_8859_1), + TEXT_XML("text/xml", ISO_8859_1), + WILDCARD("*/*"); + + private final String mimeType; + private final Charset encoding; + + ContentType(String mimeType){ + this(mimeType, null); + } + + ContentType(String mimeType, Charset encoding) { + this.mimeType = mimeType; + this.encoding = encoding; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(mimeType); + if(encoding != null){ + sb.append("; charset=").append(encoding); + } + return sb.toString(); + } + + public String getMimeType() { + return mimeType; + } +} diff --git a/unirest/src/main/java/kong/unirest/HttpRequestBody.java b/unirest/src/main/java/kong/unirest/HttpRequestBody.java index 205a446dc..b1221952c 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestBody.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestBody.java @@ -25,7 +25,6 @@ package kong.unirest; -import org.apache.http.entity.ContentType; import org.json.JSONArray; import org.json.JSONObject; diff --git a/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java b/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java index 725ed739d..5e8526a32 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java @@ -28,7 +28,6 @@ import org.apache.http.HttpEntity; import org.apache.http.HttpHeaders; import org.apache.http.client.entity.UrlEncodedFormEntity; -import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.HttpMultipartMode; import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.entity.mime.content.ByteArrayBody; @@ -58,21 +57,21 @@ public MultipartBody field(String name, String value) { @Override public MultipartBody field(String name, String value, String contentType) { - addPart(name, value, tryParse(contentType)); + addPart(name, value, contentType); return this; } @Override public MultipartBody field(String name, Collection collection) { for (Object current: collection) { - addPart(name, current, null); + addPart(name, current, (String)null); } return this; } @Override public MultipartBody field(String name, InputStream value, ContentType contentType) { - addPart(name, new InputStreamBody(value, contentType), contentType); + addPart(name, new InputStreamBody(value, toApache(contentType)), contentType); return this; } @@ -84,35 +83,34 @@ public MultipartBody field(String name, File file) { @Override public MultipartBody field(String name, File file, String contentType) { - addPart(name, file, tryParse(contentType)); - + addPart(name, file, contentType); return this; } @Override public MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName) { - addPart(name, new InputStreamBody(stream, contentType, fileName), contentType); + addPart(name, new InputStreamBody(stream, toApache(contentType), fileName), contentType); return this; } @Override public MultipartBody field(String name, InputStream stream, String fileName) { - addPart(name, new InputStreamBody(stream, ContentType.APPLICATION_OCTET_STREAM, fileName), ContentType.APPLICATION_OCTET_STREAM); + addPart(name, new InputStreamBody(stream, org.apache.http.entity.ContentType.APPLICATION_OCTET_STREAM, fileName), ContentType.APPLICATION_OCTET_STREAM); return this; } @Override public MultipartBody field(String name, byte[] bytes, ContentType contentType, String fileName) { - addPart(name, new ByteArrayBody(bytes, contentType, fileName), contentType); + addPart(name, new ByteArrayBody(bytes, toApache(contentType), fileName), contentType); return this; } @Override public MultipartBody field(String name, byte[] bytes, String fileName) { - addPart(name, new ByteArrayBody(bytes, ContentType.APPLICATION_OCTET_STREAM, fileName), ContentType.APPLICATION_OCTET_STREAM); + addPart(name, new ByteArrayBody(bytes, org.apache.http.entity.ContentType.APPLICATION_OCTET_STREAM, fileName), ContentType.APPLICATION_OCTET_STREAM); return this; } @@ -175,17 +173,25 @@ public Body getBody() { } private void addPart(String name, Object value, ContentType type) { - parameters.add(new FormPart(name, value, type)); + addPart(name, value, type.toString()); + } + + private void addPart(String name, Object value, String type) { + parameters.add(new FormPart(name, value, tryParse(type))); Collections.sort(parameters); } + private org.apache.http.entity.ContentType toApache(ContentType contentType) { + return org.apache.http.entity.ContentType.parse(contentType.toString()); + } + private void addPart(String name, Object value) { - addPart(name, value, null); + addPart(name, value, (String)null); } - private ContentType tryParse(String contentType) { + private org.apache.http.entity.ContentType tryParse(String contentType) { if (contentType != null && contentType.length() > 0) { - return ContentType.parse(contentType); + return org.apache.http.entity.ContentType.parse(contentType); } else { return null; } diff --git a/unirest/src/main/java/kong/unirest/HttpRequestWithBody.java b/unirest/src/main/java/kong/unirest/HttpRequestWithBody.java index 82b80573f..7446b1497 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestWithBody.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestWithBody.java @@ -25,7 +25,6 @@ package kong.unirest; -import org.apache.http.entity.ContentType; import org.json.JSONArray; import org.json.JSONObject; diff --git a/unirest/src/main/java/kong/unirest/MultipartBody.java b/unirest/src/main/java/kong/unirest/MultipartBody.java index a8501dca0..b938f8f53 100644 --- a/unirest/src/main/java/kong/unirest/MultipartBody.java +++ b/unirest/src/main/java/kong/unirest/MultipartBody.java @@ -25,7 +25,6 @@ package kong.unirest; -import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.HttpMultipartMode; import java.io.File; @@ -84,10 +83,8 @@ public interface MultipartBody extends HttpRequest, Body { * @param name: the Name of the form field * @param value: A input stream * @param contentType: the content mime-type of the file - * @deprecated org.apache.http.entity.ContentType will be replaced by a Unirest owned class that behaves similarly * @return The same MultipartBody */ - @Deprecated MultipartBody field(String name, InputStream value, ContentType contentType); /** @@ -96,10 +93,8 @@ public interface MultipartBody extends HttpRequest, Body { * @param stream: A input stream * @param contentType: the content mime-type of the file * @param fileName: the name of the file which will be included in the file part header - * @deprecated org.apache.http.entity.ContentType will be replaced by a Unirest owned class that behaves similarly * @return The same MultipartBody */ - @Deprecated // In version 4 Apache classes will be abstracted out MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName); /** @@ -108,10 +103,8 @@ public interface MultipartBody extends HttpRequest, Body { * @param bytes: The raw bytes for the file * @param contentType: the content mime-type of the file * @param fileName: the name of the file which will be included in the file part header - * @deprecated org.apache.http.entity.ContentType will be replaced by a Unirest owned class that behaves similarly * @return The same MultipartBody */ - @Deprecated // In version 4 Apache classes will be abstracted out MultipartBody field(String name, byte[] bytes, ContentType contentType, String fileName); /** diff --git a/unirest/src/test/java/BehaviorTests/FormPostingTest.java b/unirest/src/test/java/BehaviorTests/FormPostingTest.java index 617d9935c..febe64da9 100644 --- a/unirest/src/test/java/BehaviorTests/FormPostingTest.java +++ b/unirest/src/test/java/BehaviorTests/FormPostingTest.java @@ -25,12 +25,8 @@ package BehaviorTests; -import kong.unirest.HttpRequest; -import kong.unirest.MockCallback; -import kong.unirest.TestUtil; -import kong.unirest.Unirest; +import kong.unirest.*; import org.apache.commons.io.IOUtils; -import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.HttpMultipartMode; import org.junit.Test; diff --git a/unirest/src/test/java/BehaviorTests/RequestCapture.java b/unirest/src/test/java/BehaviorTests/RequestCapture.java index f1816a6d0..74976232e 100644 --- a/unirest/src/test/java/BehaviorTests/RequestCapture.java +++ b/unirest/src/test/java/BehaviorTests/RequestCapture.java @@ -27,14 +27,9 @@ import com.google.common.base.Strings; import com.google.common.collect.*; -import kong.unirest.JsonPatch; -import kong.unirest.JsonPatchItem; -import kong.unirest.JsonPatchOperation; +import kong.unirest.*; import org.apache.http.client.utils.URLEncodedUtils; -import org.apache.http.entity.ContentType; import spark.Request; -import kong.unirest.HttpMethod; -import kong.unirest.TestUtil; import javax.servlet.MultipartConfigElement; import javax.servlet.ServletException; diff --git a/unirest/src/test/java/kong/unirest/ContentTypeTest.java b/unirest/src/test/java/kong/unirest/ContentTypeTest.java new file mode 100644 index 000000000..690e42dcd --- /dev/null +++ b/unirest/src/test/java/kong/unirest/ContentTypeTest.java @@ -0,0 +1,60 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ContentTypeTest { + + @Test + public void contentTypeWithEncoding() { + verifySame(org.apache.http.entity.ContentType.APPLICATION_ATOM_XML, + ContentType.APPLICATION_ATOM_XML); + } + + @Test + public void imageTypes() { + verifySame(org.apache.http.entity.ContentType.IMAGE_GIF, + ContentType.IMAGE_GIF); + } + + @Test + public void wildCard() { + verifySame(org.apache.http.entity.ContentType.WILDCARD, + ContentType.WILDCARD); + } + + private void verifySame(org.apache.http.entity.ContentType apache, ContentType unirest) { + assertEquals( + apache.toString(), + unirest.toString() + ); + assertEquals(apache.toString(), + org.apache.http.entity.ContentType.parse(unirest.toString()).toString()); + } +} \ No newline at end of file From 475cc8645038e17a7b4a294a379f435c7f8506bc Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 20 Feb 2019 21:16:21 -0600 Subject: [PATCH 0455/1769] move all the apache things into a apache project --- .../src/main/java/kong/unirest/Config.java | 27 ++++---- .../java/kong/unirest/RawResponseBase.java | 2 +- unirest/src/main/java/kong/unirest/Util.java | 41 ++---------- .../{ => apache}/ApacheAsyncClient.java | 14 ++-- .../unirest/{ => apache}/ApacheClient.java | 9 +-- .../{ => apache}/ApacheRequestWithBody.java | 5 +- .../unirest/{ => apache}/ApacheResponse.java | 7 +- .../{ => apache}/BaseApacheClient.java | 3 +- .../{ => apache}/HttpDeleteWithBody.java | 2 +- .../{ => apache}/HttpPatchWithBody.java | 2 +- .../unirest/{ => apache}/NoRedirects.java | 2 +- .../unirest/{ => apache}/RequestPrep.java | 3 +- .../main/java/kong/unirest/apache/Util.java | 64 +++++++++++++++++++ .../test/java/kong/unirest/ConfigTest.java | 2 + .../kong/unirest/{ => apache}/UtilTest.java | 2 +- 15 files changed, 114 insertions(+), 71 deletions(-) rename unirest/src/main/java/kong/unirest/{ => apache}/ApacheAsyncClient.java (94%) rename unirest/src/main/java/kong/unirest/{ => apache}/ApacheClient.java (92%) rename unirest/src/main/java/kong/unirest/{ => apache}/ApacheRequestWithBody.java (92%) rename unirest/src/main/java/kong/unirest/{ => apache}/ApacheResponse.java (96%) rename unirest/src/main/java/kong/unirest/{ => apache}/BaseApacheClient.java (96%) rename unirest/src/main/java/kong/unirest/{ => apache}/HttpDeleteWithBody.java (98%) rename unirest/src/main/java/kong/unirest/{ => apache}/HttpPatchWithBody.java (98%) rename unirest/src/main/java/kong/unirest/{ => apache}/NoRedirects.java (98%) rename unirest/src/main/java/kong/unirest/{ => apache}/RequestPrep.java (98%) create mode 100644 unirest/src/main/java/kong/unirest/apache/Util.java rename unirest/src/test/java/kong/unirest/{ => apache}/UtilTest.java (98%) diff --git a/unirest/src/main/java/kong/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java index 0ad3380ea..44f0e90cb 100644 --- a/unirest/src/main/java/kong/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -25,6 +25,8 @@ package kong.unirest; +import kong.unirest.apache.ApacheAsyncClient; +import kong.unirest.apache.ApacheClient; import org.apache.http.HttpHost; import org.apache.http.HttpRequestInterceptor; import org.apache.http.auth.AuthScope; @@ -453,32 +455,31 @@ private void verifyIsOn(AsyncClient value) { // Accessors for unirest. - - boolean getEnabledCookieManagement() { + public boolean getEnabledCookieManagement() { return cookieManagement; } - boolean getFollowRedirects() { + public boolean getFollowRedirects() { return followRedirects; } - int getMaxConnections() { + public int getMaxConnections() { return maxTotal; } - int getMaxPerRoutes() { + public int getMaxPerRoutes() { return maxPerRoute; } - int getConnectionTimeout() { + public int getConnectionTimeout() { return connectionTimeout; } - int getSocketTimeout() { + public int getSocketTimeout() { return socketTimeout; } - ObjectMapper getObjectMapper() { + public ObjectMapper getObjectMapper() { return objectMapper.orElseThrow(() -> new UnirestException("No Object Mapper Configured. Please config one with Unirest.config().setObjectMapper")); } @@ -491,23 +492,23 @@ private void validateClientsNotRunning() { } } - List getInterceptors() { + public List getInterceptors() { return interceptors; } - HttpHost getProxy() { + public HttpHost getProxy() { return proxy; } - CredentialsProvider getProxyCreds(){ + public CredentialsProvider getProxyCreds(){ return proxyCreds; } - boolean useSystemProperties(){ + public boolean useSystemProperties(){ return this.useSystemProperties; } - String getDefaultResponseEncoding() { + public String getDefaultResponseEncoding() { return defaultResponseEncoding; } } diff --git a/unirest/src/main/java/kong/unirest/RawResponseBase.java b/unirest/src/main/java/kong/unirest/RawResponseBase.java index d9e710399..6f3ff2419 100644 --- a/unirest/src/main/java/kong/unirest/RawResponseBase.java +++ b/unirest/src/main/java/kong/unirest/RawResponseBase.java @@ -28,7 +28,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -abstract class RawResponseBase implements RawResponse { +public abstract class RawResponseBase implements RawResponse { private static final Pattern CHARSET_PATTERN = Pattern.compile("(?i)\\bcharset=\\s*\"?([^\\s;\"]*)"); protected Config config; diff --git a/unirest/src/main/java/kong/unirest/Util.java b/unirest/src/main/java/kong/unirest/Util.java index 293a2b6c9..56640a14b 100644 --- a/unirest/src/main/java/kong/unirest/Util.java +++ b/unirest/src/main/java/kong/unirest/Util.java @@ -28,11 +28,12 @@ import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; -import java.io.ByteArrayInputStream; -import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Optional; import java.util.stream.Stream; class Util { @@ -42,24 +43,6 @@ static Stream stream(Optional opt) { return opt.map(Stream::of).orElseGet(Stream::empty); } - static Optional tryCast(T original, Class too) { - if (original != null && too.isAssignableFrom(original.getClass())) { - return Optional.of((M) original); - } - return Optional.empty(); - } - - static Optional tryDo(T c, ExConsumer consumer) { - try { - if (Objects.nonNull(c)) { - consumer.accept(c); - } - return Optional.empty(); - } catch (Exception e) { - return Optional.of(e); - } - } - static String nullToEmpty(Object v) { if(v == null){ return ""; @@ -83,21 +66,7 @@ static List getList(Collection parameters) { return result; } - static Stream collectExceptions(Optional... ex) { - return Stream.of(ex).flatMap(Util::stream); - } - - public static InputStream emptyStream() { - return new ByteArrayInputStream(new byte[0]); - } - - public static boolean isNullOrEmpty(String s) { + static boolean isNullOrEmpty(String s) { return s == null || s.trim().isEmpty(); } - - - @FunctionalInterface - public interface ExConsumer{ - void accept(T t) throws Exception; - } } diff --git a/unirest/src/main/java/kong/unirest/ApacheAsyncClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java similarity index 94% rename from unirest/src/main/java/kong/unirest/ApacheAsyncClient.java rename to unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java index 0cdb2cdfa..a0a5500c7 100644 --- a/unirest/src/main/java/kong/unirest/ApacheAsyncClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java @@ -23,8 +23,9 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package kong.unirest; +package kong.unirest.apache; +import kong.unirest.*; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.concurrent.FutureCallback; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; @@ -39,16 +40,15 @@ import java.util.function.Function; import java.util.stream.Stream; -import static kong.unirest.Util.tryCast; -class ApacheAsyncClient extends BaseApacheClient implements AsyncClient { +public class ApacheAsyncClient extends BaseApacheClient implements AsyncClient { private final HttpAsyncClient client; private final AsyncIdleConnectionMonitorThread syncMonitor; private final PoolingNHttpClientConnectionManager manager; private Config config; - ApacheAsyncClient(Config config) { + public ApacheAsyncClient(Config config) { this.config = config; try { manager = new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor()); @@ -82,7 +82,7 @@ class ApacheAsyncClient extends BaseApacheClient implements AsyncClient { } } - ApacheAsyncClient(HttpAsyncClient client, + public ApacheAsyncClient(HttpAsyncClient client, Config config, PoolingNHttpClientConnectionManager manager, AsyncIdleConnectionMonitorThread monitor) { @@ -124,7 +124,7 @@ public void cancelled() { @Override public boolean isRunning() { - return tryCast(client, CloseableHttpAsyncClient.class) + return Util.tryCast(client, CloseableHttpAsyncClient.class) .map(CloseableHttpAsyncClient::isRunning) .orElse(true); } @@ -144,4 +144,6 @@ public Stream close() { Util.tryDo(manager, m -> m.shutdown()), Util.tryDo(syncMonitor, m -> m.interrupt())); } + + } diff --git a/unirest/src/main/java/kong/unirest/ApacheClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java similarity index 92% rename from unirest/src/main/java/kong/unirest/ApacheClient.java rename to unirest/src/main/java/kong/unirest/apache/ApacheClient.java index ec4324933..c3860f6b5 100644 --- a/unirest/src/main/java/kong/unirest/ApacheClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java @@ -23,8 +23,9 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package kong.unirest; +package kong.unirest.apache; +import kong.unirest.*; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.impl.client.CloseableHttpClient; @@ -36,13 +37,13 @@ import java.util.function.Function; import java.util.stream.Stream; -class ApacheClient extends BaseApacheClient implements Client { +public class ApacheClient extends BaseApacheClient implements Client { private final HttpClient client; private final Config config; private final PoolingHttpClientConnectionManager manager; private final SyncIdleConnectionMonitorThread syncMonitor; - ApacheClient(Config config) { + public ApacheClient(Config config) { this.config = config; manager = new PoolingHttpClientConnectionManager(); syncMonitor = new SyncIdleConnectionMonitorThread(manager); @@ -67,7 +68,7 @@ class ApacheClient extends BaseApacheClient implements Client { client = cb.build(); } - ApacheClient(HttpClient httpClient, Config config, PoolingHttpClientConnectionManager clientManager, SyncIdleConnectionMonitorThread connMonitor) { + public ApacheClient(HttpClient httpClient, Config config, PoolingHttpClientConnectionManager clientManager, SyncIdleConnectionMonitorThread connMonitor) { this.client = httpClient; this.config = config; this.manager = clientManager; diff --git a/unirest/src/main/java/kong/unirest/ApacheRequestWithBody.java b/unirest/src/main/java/kong/unirest/apache/ApacheRequestWithBody.java similarity index 92% rename from unirest/src/main/java/kong/unirest/ApacheRequestWithBody.java rename to unirest/src/main/java/kong/unirest/apache/ApacheRequestWithBody.java index b171ce3b2..65631b7df 100644 --- a/unirest/src/main/java/kong/unirest/ApacheRequestWithBody.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheRequestWithBody.java @@ -23,13 +23,14 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package kong.unirest; +package kong.unirest.apache; +import kong.unirest.HttpMethod; import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; import java.net.URI; -public class ApacheRequestWithBody extends HttpEntityEnclosingRequestBase { +class ApacheRequestWithBody extends HttpEntityEnclosingRequestBase { private HttpMethod method; public ApacheRequestWithBody(HttpMethod method, String uri){ diff --git a/unirest/src/main/java/kong/unirest/ApacheResponse.java b/unirest/src/main/java/kong/unirest/apache/ApacheResponse.java similarity index 96% rename from unirest/src/main/java/kong/unirest/ApacheResponse.java rename to unirest/src/main/java/kong/unirest/apache/ApacheResponse.java index d0e61b986..7fc304b82 100644 --- a/unirest/src/main/java/kong/unirest/ApacheResponse.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheResponse.java @@ -23,8 +23,9 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package kong.unirest; +package kong.unirest.apache; +import kong.unirest.*; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -67,7 +68,7 @@ public InputStream getContent(){ if(entity != null) { return entity.getContent(); } - return Util.emptyStream(); + return new ByteArrayInputStream(new byte[0]); } catch (IOException e) { throw new UnirestException(e); } @@ -110,7 +111,7 @@ public String getContentAsString(String charset) { } private String getCharset(String charset) { - if(Util.isNullOrEmpty(charset)){ + if(charset == null || charset.trim().isEmpty()){ return getCharSet(); } return charset; diff --git a/unirest/src/main/java/kong/unirest/BaseApacheClient.java b/unirest/src/main/java/kong/unirest/apache/BaseApacheClient.java similarity index 96% rename from unirest/src/main/java/kong/unirest/BaseApacheClient.java rename to unirest/src/main/java/kong/unirest/apache/BaseApacheClient.java index 123a5b995..910a63c2f 100644 --- a/unirest/src/main/java/kong/unirest/BaseApacheClient.java +++ b/unirest/src/main/java/kong/unirest/apache/BaseApacheClient.java @@ -23,8 +23,9 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package kong.unirest; +package kong.unirest.apache; +import kong.unirest.Config; import org.apache.http.HttpHost; import org.apache.http.client.config.RequestConfig; diff --git a/unirest/src/main/java/kong/unirest/HttpDeleteWithBody.java b/unirest/src/main/java/kong/unirest/apache/HttpDeleteWithBody.java similarity index 98% rename from unirest/src/main/java/kong/unirest/HttpDeleteWithBody.java rename to unirest/src/main/java/kong/unirest/apache/HttpDeleteWithBody.java index 7352513fa..71058b6a3 100644 --- a/unirest/src/main/java/kong/unirest/HttpDeleteWithBody.java +++ b/unirest/src/main/java/kong/unirest/apache/HttpDeleteWithBody.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package kong.unirest; +package kong.unirest.apache; import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; diff --git a/unirest/src/main/java/kong/unirest/HttpPatchWithBody.java b/unirest/src/main/java/kong/unirest/apache/HttpPatchWithBody.java similarity index 98% rename from unirest/src/main/java/kong/unirest/HttpPatchWithBody.java rename to unirest/src/main/java/kong/unirest/apache/HttpPatchWithBody.java index 32ff72ba5..67e6f0f41 100644 --- a/unirest/src/main/java/kong/unirest/HttpPatchWithBody.java +++ b/unirest/src/main/java/kong/unirest/apache/HttpPatchWithBody.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package kong.unirest; +package kong.unirest.apache; import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; diff --git a/unirest/src/main/java/kong/unirest/NoRedirects.java b/unirest/src/main/java/kong/unirest/apache/NoRedirects.java similarity index 98% rename from unirest/src/main/java/kong/unirest/NoRedirects.java rename to unirest/src/main/java/kong/unirest/apache/NoRedirects.java index ae7d04c73..b613d79be 100644 --- a/unirest/src/main/java/kong/unirest/NoRedirects.java +++ b/unirest/src/main/java/kong/unirest/apache/NoRedirects.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package kong.unirest; +package kong.unirest.apache; import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; diff --git a/unirest/src/main/java/kong/unirest/RequestPrep.java b/unirest/src/main/java/kong/unirest/apache/RequestPrep.java similarity index 98% rename from unirest/src/main/java/kong/unirest/RequestPrep.java rename to unirest/src/main/java/kong/unirest/apache/RequestPrep.java index 0d9f5deeb..a86728049 100644 --- a/unirest/src/main/java/kong/unirest/RequestPrep.java +++ b/unirest/src/main/java/kong/unirest/apache/RequestPrep.java @@ -23,8 +23,9 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package kong.unirest; +package kong.unirest.apache; +import kong.unirest.*; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.client.methods.*; diff --git a/unirest/src/main/java/kong/unirest/apache/Util.java b/unirest/src/main/java/kong/unirest/apache/Util.java new file mode 100644 index 000000000..f7e68c7b3 --- /dev/null +++ b/unirest/src/main/java/kong/unirest/apache/Util.java @@ -0,0 +1,64 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest.apache; + +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Stream; + +class Util { + static Optional tryCast(T original, Class too) { + if (original != null && too.isAssignableFrom(original.getClass())) { + return Optional.of((M) original); + } + return Optional.empty(); + } + + static Stream collectExceptions(Optional... ex) { + return Stream.of(ex).flatMap(Util::stream); + } + + //In Java 9 this has been added as Optional::stream. Remove this whenever we get there. + static Stream stream(Optional opt) { + return opt.map(Stream::of).orElseGet(Stream::empty); + } + + static Optional tryDo(T c, ExConsumer consumer) { + try { + if (Objects.nonNull(c)) { + consumer.accept(c); + } + return Optional.empty(); + } catch (Exception e) { + return Optional.of(e); + } + } + + @FunctionalInterface + public interface ExConsumer{ + void accept(T t) throws Exception; + } +} diff --git a/unirest/src/test/java/kong/unirest/ConfigTest.java b/unirest/src/test/java/kong/unirest/ConfigTest.java index 1ddab29ee..42c43e4b8 100644 --- a/unirest/src/test/java/kong/unirest/ConfigTest.java +++ b/unirest/src/test/java/kong/unirest/ConfigTest.java @@ -25,6 +25,8 @@ package kong.unirest; +import kong.unirest.apache.ApacheAsyncClient; +import kong.unirest.apache.ApacheClient; import org.apache.http.client.HttpClient; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; diff --git a/unirest/src/test/java/kong/unirest/UtilTest.java b/unirest/src/test/java/kong/unirest/apache/UtilTest.java similarity index 98% rename from unirest/src/test/java/kong/unirest/UtilTest.java rename to unirest/src/test/java/kong/unirest/apache/UtilTest.java index 4fb597bac..6e603b121 100644 --- a/unirest/src/test/java/kong/unirest/UtilTest.java +++ b/unirest/src/test/java/kong/unirest/apache/UtilTest.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package kong.unirest; +package kong.unirest.apache; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; From cb47c6fea130c3e0bcaada2a2fb8fe596615921e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Feb 2019 07:33:52 -0600 Subject: [PATCH 0456/1769] hide more of apache --- unirest/src/main/java/kong/unirest/AsyncClient.java | 10 ++++------ unirest/src/main/java/kong/unirest/Client.java | 7 ++----- .../{ => apache}/AsyncIdleConnectionMonitorThread.java | 2 +- .../{ => apache}/SyncIdleConnectionMonitorThread.java | 2 +- unirest/src/test/java/BehaviorTests/LifeCycleTest.java | 2 ++ unirest/src/test/java/kong/unirest/ConfigTest.java | 2 ++ 6 files changed, 12 insertions(+), 13 deletions(-) rename unirest/src/main/java/kong/unirest/{ => apache}/AsyncIdleConnectionMonitorThread.java (98%) rename unirest/src/main/java/kong/unirest/{ => apache}/SyncIdleConnectionMonitorThread.java (98%) diff --git a/unirest/src/main/java/kong/unirest/AsyncClient.java b/unirest/src/main/java/kong/unirest/AsyncClient.java index b930810d6..5dce7de34 100644 --- a/unirest/src/main/java/kong/unirest/AsyncClient.java +++ b/unirest/src/main/java/kong/unirest/AsyncClient.java @@ -25,7 +25,7 @@ package kong.unirest; -import org.apache.http.nio.client.HttpAsyncClient; + import java.util.concurrent.CompletableFuture; import java.util.function.Function; @@ -33,11 +33,9 @@ public interface AsyncClient { /** - * @return the apache HttpAsyncClient. - * @deprecated Eventually the apache implementation will be hidden and other implementation wi be available - */ - @Deprecated - HttpAsyncClient getClient(); + * @return the underlying client if this instance is wrapping another library (like Apache). + */ + T getClient(); /** * Make a Async request diff --git a/unirest/src/main/java/kong/unirest/Client.java b/unirest/src/main/java/kong/unirest/Client.java index 99dca7d23..4b4dd205d 100644 --- a/unirest/src/main/java/kong/unirest/Client.java +++ b/unirest/src/main/java/kong/unirest/Client.java @@ -25,17 +25,14 @@ package kong.unirest; -import org.apache.http.client.HttpClient; - import java.util.function.Function; import java.util.stream.Stream; public interface Client { /** - * @return the apache HttpClient. - * @deprecated Eventually the apache implementation will be hidden and other implementation wi be available + * @return the underlying client if this instance is wrapping another library (like Apache). */ - HttpClient getClient(); + Object getClient(); /** * Make a request diff --git a/unirest/src/main/java/kong/unirest/AsyncIdleConnectionMonitorThread.java b/unirest/src/main/java/kong/unirest/apache/AsyncIdleConnectionMonitorThread.java similarity index 98% rename from unirest/src/main/java/kong/unirest/AsyncIdleConnectionMonitorThread.java rename to unirest/src/main/java/kong/unirest/apache/AsyncIdleConnectionMonitorThread.java index a599d136e..60da87e44 100644 --- a/unirest/src/main/java/kong/unirest/AsyncIdleConnectionMonitorThread.java +++ b/unirest/src/main/java/kong/unirest/apache/AsyncIdleConnectionMonitorThread.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package kong.unirest; +package kong.unirest.apache; import java.util.concurrent.TimeUnit; diff --git a/unirest/src/main/java/kong/unirest/SyncIdleConnectionMonitorThread.java b/unirest/src/main/java/kong/unirest/apache/SyncIdleConnectionMonitorThread.java similarity index 98% rename from unirest/src/main/java/kong/unirest/SyncIdleConnectionMonitorThread.java rename to unirest/src/main/java/kong/unirest/apache/SyncIdleConnectionMonitorThread.java index f7161108e..61a9f049b 100644 --- a/unirest/src/main/java/kong/unirest/SyncIdleConnectionMonitorThread.java +++ b/unirest/src/main/java/kong/unirest/apache/SyncIdleConnectionMonitorThread.java @@ -23,7 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package kong.unirest; +package kong.unirest.apache; import java.util.concurrent.TimeUnit; diff --git a/unirest/src/test/java/BehaviorTests/LifeCycleTest.java b/unirest/src/test/java/BehaviorTests/LifeCycleTest.java index dfba1217e..8b68cde77 100644 --- a/unirest/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/unirest/src/test/java/BehaviorTests/LifeCycleTest.java @@ -27,6 +27,8 @@ import com.github.paweladamski.httpclientmock.HttpClientMock; import kong.unirest.*; +import kong.unirest.apache.AsyncIdleConnectionMonitorThread; +import kong.unirest.apache.SyncIdleConnectionMonitorThread; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; import org.junit.runner.RunWith; diff --git a/unirest/src/test/java/kong/unirest/ConfigTest.java b/unirest/src/test/java/kong/unirest/ConfigTest.java index 42c43e4b8..9cfb75d85 100644 --- a/unirest/src/test/java/kong/unirest/ConfigTest.java +++ b/unirest/src/test/java/kong/unirest/ConfigTest.java @@ -27,6 +27,8 @@ import kong.unirest.apache.ApacheAsyncClient; import kong.unirest.apache.ApacheClient; +import kong.unirest.apache.AsyncIdleConnectionMonitorThread; +import kong.unirest.apache.SyncIdleConnectionMonitorThread; import org.apache.http.client.HttpClient; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; From b22dd5f31de87b64652a8f255dd17713dfc810c0 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Feb 2019 11:08:07 -0600 Subject: [PATCH 0457/1769] switch the content type to be a class like the apache one --- .../main/java/kong/unirest/ContentType.java | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/unirest/src/main/java/kong/unirest/ContentType.java b/unirest/src/main/java/kong/unirest/ContentType.java index 4cd818135..3f2294d06 100644 --- a/unirest/src/main/java/kong/unirest/ContentType.java +++ b/unirest/src/main/java/kong/unirest/ContentType.java @@ -30,32 +30,37 @@ import static java.nio.charset.StandardCharsets.ISO_8859_1; -public enum ContentType { - APPLICATION_ATOM_XML("application/atom+xml", ISO_8859_1), - APPLICATION_FORM_URLENCODED("application/x-www-form-urlencoded", ISO_8859_1), - APPLICATION_JSON("application/json", StandardCharsets.UTF_8), - APPLICATION_OCTET_STREAM("application/octet-stream"), - APPLICATION_SVG_XML("application/svg+xml", ISO_8859_1), - APPLICATION_XHTML_XML("application/xhtml+xml", ISO_8859_1), - APPLICATION_XML("application/xml", ISO_8859_1), - IMAGE_BMP("image/bmp"), - IMAGE_GIF("image/gif"), - IMAGE_JPEG("image/jpeg"), - IMAGE_PNG("image/png"), - IMAGE_SVG("image/svg+xml"), - IMAGE_TIFF("image/tiff"), - IMAGE_WEBP("image/webp"), - MULTIPART_FORM_DATA("multipart/form-data", ISO_8859_1), - TEXT_HTML("text/html", ISO_8859_1), - TEXT_PLAIN("text/plain", ISO_8859_1), - TEXT_XML("text/xml", ISO_8859_1), - WILDCARD("*/*"); - +public class ContentType { + public static final ContentType APPLICATION_ATOM_XML = create("application/atom+xml", ISO_8859_1); + public static final ContentType APPLICATION_FORM_URLENCODED = create("application/x-www-form-urlencoded", ISO_8859_1); + public static final ContentType APPLICATION_JSON = create("application/json", StandardCharsets.UTF_8); + public static final ContentType APPLICATION_OCTET_STREAM = create("application/octet-stream"); + public static final ContentType APPLICATION_SVG_XML = create("application/svg+xml", ISO_8859_1); + public static final ContentType APPLICATION_XHTML_XML = create("application/xhtml+xml", ISO_8859_1); + public static final ContentType APPLICATION_XML = create("application/xml", ISO_8859_1); + public static final ContentType IMAGE_BMP = create("image/bmp"); + public static final ContentType IMAGE_GIF = create("image/gif"); + public static final ContentType IMAGE_JPEG = create("image/jpeg"); + public static final ContentType IMAGE_PNG = create("image/png"); + public static final ContentType IMAGE_SVG = create("image/svg+xml"); + public static final ContentType IMAGE_TIFF = create("image/tiff"); + public static final ContentType IMAGE_WEBP = create("image/webp"); + public static final ContentType MULTIPART_FORM_DATA = create("multipart/form-data", ISO_8859_1); + public static final ContentType TEXT_HTML = create("text/html", ISO_8859_1); + public static final ContentType TEXT_PLAIN = create("text/plain", ISO_8859_1); + public static final ContentType TEXT_XML = create("text/xml", ISO_8859_1); + public static final ContentType WILDCARD = create("*/*"); private final String mimeType; + private final Charset encoding; - ContentType(String mimeType){ - this(mimeType, null); + + public static ContentType create(String mimeType) { + return new ContentType(mimeType, null); + } + + public static ContentType create(String mimeType, Charset charset) { + return new ContentType(mimeType, charset); } ContentType(String mimeType, Charset encoding) { From a07b9f590cc101381a190c72adf5c90e29e55aeb Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Feb 2019 11:43:54 -0600 Subject: [PATCH 0458/1769] use java 8 --- .java-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .java-version diff --git a/.java-version b/.java-version new file mode 100644 index 000000000..625934097 --- /dev/null +++ b/.java-version @@ -0,0 +1 @@ +1.8 From 8e9b20dbfb75e29271ac2473fb6d4adc84205ff2 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Feb 2019 11:51:04 -0600 Subject: [PATCH 0459/1769] push apache down even more --- .../main/java/kong/unirest/ByteArrayPart.java | 51 +++++++++++++++++ .../main/java/kong/unirest/ContentType.java | 4 ++ .../src/main/java/kong/unirest/FormPart.java | 38 ++++++++----- .../kong/unirest/HttpRequestMultiPart.java | 25 ++------ .../java/kong/unirest/InputStreamPart.java | 57 +++++++++++++++++++ 5 files changed, 142 insertions(+), 33 deletions(-) create mode 100644 unirest/src/main/java/kong/unirest/ByteArrayPart.java create mode 100644 unirest/src/main/java/kong/unirest/InputStreamPart.java diff --git a/unirest/src/main/java/kong/unirest/ByteArrayPart.java b/unirest/src/main/java/kong/unirest/ByteArrayPart.java new file mode 100644 index 000000000..06abdc63b --- /dev/null +++ b/unirest/src/main/java/kong/unirest/ByteArrayPart.java @@ -0,0 +1,51 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + + +class ByteArrayPart { + private final byte[] bytes; + private final String contentType; + private final String fileName; + + ByteArrayPart(byte[] bytes, ContentType contentType, String fileName) { + this.bytes = bytes; + this.contentType = contentType.toString(); + this.fileName = fileName; + } + + public byte[] getBytes() { + return bytes; + } + + public String getContentType() { + return contentType; + } + + public String getFileName() { + return fileName; + } +} diff --git a/unirest/src/main/java/kong/unirest/ContentType.java b/unirest/src/main/java/kong/unirest/ContentType.java index 3f2294d06..1d6714329 100644 --- a/unirest/src/main/java/kong/unirest/ContentType.java +++ b/unirest/src/main/java/kong/unirest/ContentType.java @@ -80,4 +80,8 @@ public String toString() { public String getMimeType() { return mimeType; } + + public ContentType withCharset(Charset charset) { + return new ContentType(mimeType, charset); + } } diff --git a/unirest/src/main/java/kong/unirest/FormPart.java b/unirest/src/main/java/kong/unirest/FormPart.java index 44c1162dd..70ae78d3a 100644 --- a/unirest/src/main/java/kong/unirest/FormPart.java +++ b/unirest/src/main/java/kong/unirest/FormPart.java @@ -25,7 +25,7 @@ package kong.unirest; -import org.apache.http.entity.ContentType; + import org.apache.http.entity.mime.content.*; import java.io.File; @@ -34,9 +34,9 @@ class FormPart implements Comparable { private final String name; private final Object value; - private final ContentType contentType; + private final String contentType; - FormPart(String name, Object value, ContentType contentType) { + FormPart(String name, Object value, String contentType) { this.name = name; this.value = value; this.contentType = contentType; @@ -46,12 +46,12 @@ public Object getValue() { return value; } - private ContentType getContentType() { + private String getContentType() { if(contentType == null){ if(isFile()){ - return ContentType.APPLICATION_OCTET_STREAM; + return ContentType.APPLICATION_OCTET_STREAM.toString(); } - return ContentType.APPLICATION_FORM_URLENCODED.withCharset(StandardCharsets.UTF_8); + return ContentType.APPLICATION_FORM_URLENCODED.withCharset(StandardCharsets.UTF_8).toString(); } return contentType; } @@ -59,16 +59,26 @@ private ContentType getContentType() { ContentBody toApachePart() { if (value instanceof File) { File file = (File) value; - return new FileBody(file, getContentType(), file.getName()); - } else if (value instanceof InputStreamBody) { - return (ContentBody) value; - } else if (value instanceof ByteArrayBody) { - return (ContentBody) value; + return new FileBody(file, toApacheType(getContentType()), file.getName()); + } else if (value instanceof InputStreamPart) { + InputStreamPart part = (InputStreamPart)value; + return new InputStreamBody(part.getInputStream(), + toApacheType(part.getContentType()), + part.getFileName()); + } else if (value instanceof ByteArrayPart) { + ByteArrayPart part = (ByteArrayPart)value; + return new ByteArrayBody(part.getBytes(), + toApacheType(part.getContentType()), + part.getFileName()); } else { - return new StringBody(value.toString(), getContentType()); + return new StringBody(value.toString(), toApacheType(getContentType())); } } + private org.apache.http.entity.ContentType toApacheType(String type) { + return org.apache.http.entity.ContentType.parse(type); + } + public String getName() { return name == null ? "" : name; } @@ -83,7 +93,7 @@ public int compareTo(Object o) { public boolean isFile(){ return value instanceof File - || value instanceof InputStreamBody - || value instanceof ByteArrayBody; + || value instanceof InputStreamPart + || value instanceof ByteArrayPart; } } diff --git a/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java b/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java index 5e8526a32..efbbd8f76 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java @@ -30,8 +30,6 @@ import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.entity.mime.HttpMultipartMode; import org.apache.http.entity.mime.MultipartEntityBuilder; -import org.apache.http.entity.mime.content.ByteArrayBody; -import org.apache.http.entity.mime.content.InputStreamBody; import java.io.File; import java.io.InputStream; @@ -71,7 +69,7 @@ public MultipartBody field(String name, Collection collection) { @Override public MultipartBody field(String name, InputStream value, ContentType contentType) { - addPart(name, new InputStreamBody(value, toApache(contentType)), contentType); + addPart(name, new InputStreamPart(value, contentType.toString()), contentType); return this; } @@ -89,28 +87,28 @@ public MultipartBody field(String name, File file, String contentType) { @Override public MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName) { - addPart(name, new InputStreamBody(stream, toApache(contentType), fileName), contentType); + addPart(name, new InputStreamPart(stream, contentType.toString(), fileName), contentType); return this; } @Override public MultipartBody field(String name, InputStream stream, String fileName) { - addPart(name, new InputStreamBody(stream, org.apache.http.entity.ContentType.APPLICATION_OCTET_STREAM, fileName), ContentType.APPLICATION_OCTET_STREAM); + addPart(name, new InputStreamPart(stream, ContentType.APPLICATION_OCTET_STREAM.toString(), fileName), ContentType.APPLICATION_OCTET_STREAM); return this; } @Override public MultipartBody field(String name, byte[] bytes, ContentType contentType, String fileName) { - addPart(name, new ByteArrayBody(bytes, toApache(contentType), fileName), contentType); + addPart(name, new ByteArrayPart(bytes, contentType, fileName), contentType); return this; } @Override public MultipartBody field(String name, byte[] bytes, String fileName) { - addPart(name, new ByteArrayBody(bytes, org.apache.http.entity.ContentType.APPLICATION_OCTET_STREAM, fileName), ContentType.APPLICATION_OCTET_STREAM); + addPart(name, new ByteArrayPart(bytes, ContentType.APPLICATION_OCTET_STREAM, fileName), ContentType.APPLICATION_OCTET_STREAM); return this; } @@ -177,23 +175,12 @@ private void addPart(String name, Object value, ContentType type) { } private void addPart(String name, Object value, String type) { - parameters.add(new FormPart(name, value, tryParse(type))); + parameters.add(new FormPart(name, value, type)); Collections.sort(parameters); } - private org.apache.http.entity.ContentType toApache(ContentType contentType) { - return org.apache.http.entity.ContentType.parse(contentType.toString()); - } - private void addPart(String name, Object value) { addPart(name, value, (String)null); } - private org.apache.http.entity.ContentType tryParse(String contentType) { - if (contentType != null && contentType.length() > 0) { - return org.apache.http.entity.ContentType.parse(contentType); - } else { - return null; - } - } } diff --git a/unirest/src/main/java/kong/unirest/InputStreamPart.java b/unirest/src/main/java/kong/unirest/InputStreamPart.java new file mode 100644 index 000000000..508a1f28b --- /dev/null +++ b/unirest/src/main/java/kong/unirest/InputStreamPart.java @@ -0,0 +1,57 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +import java.io.InputStream; + +class InputStreamPart { + private final InputStream value; + private final String contentType; + private String fileName; + + public InputStreamPart(InputStream value, String contentType) { + this.value = value; + this.contentType = contentType; + } + + public InputStreamPart(InputStream value, String contentType, String fileName) { + this.value = value; + this.contentType = contentType; + this.fileName = fileName; + } + + public InputStream getInputStream() { + return value; + } + + public String getContentType() { + return contentType; + } + + public String getFileName() { + return fileName; + } +} From 9a12aa88a906b6c622e763f10926775d29617754 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 22 Feb 2019 13:26:57 -0600 Subject: [PATCH 0460/1769] major refactor the body parts to extract handling down into the apache module --- .../main/java/kong/unirest/BaseRequest.java | 5 - unirest/src/main/java/kong/unirest/Body.java | 23 +++- .../unirest/{FormPart.java => BodyPart.java} | 58 +++----- .../main/java/kong/unirest/ByteArrayPart.java | 23 ++-- .../src/main/java/kong/unirest/FilePart.java | 51 +++++++ .../main/java/kong/unirest/HttpRequest.java | 9 +- .../java/kong/unirest/HttpRequestBody.java | 6 + .../kong/unirest/HttpRequestJsonPatch.java | 22 +-- .../kong/unirest/HttpRequestMultiPart.java | 88 ++++++------ .../java/kong/unirest/HttpRequestNoBody.java | 7 + .../java/kong/unirest/HttpRequestUniBody.java | 39 +++--- .../java/kong/unirest/InputStreamPart.java | 30 ++-- .../main/java/kong/unirest/MultipartBody.java | 11 +- .../main/java/kong/unirest/MultipartMode.java | 35 +++++ .../src/main/java/kong/unirest/ParamPart.java | 41 ++++++ .../java/kong/unirest/RequestBodyEntity.java | 1 - .../java/kong/unirest/UniByteArrayBody.java | 37 +++++ .../main/java/kong/unirest/UnibodyString.java | 39 ++++++ unirest/src/main/java/kong/unirest/Util.java | 14 -- .../kong/unirest/apache/ApacheBodyMapper.java | 128 ++++++++++++++++++ .../java/kong/unirest/apache/RequestPrep.java | 39 +++--- .../java/BehaviorTests/FormPostingTest.java | 22 +-- .../java/BehaviorTests/RequestCapture.java | 2 +- .../java/kong/unirest/UriFormatterTest.java | 2 + 24 files changed, 520 insertions(+), 212 deletions(-) rename unirest/src/main/java/kong/unirest/{FormPart.java => BodyPart.java} (55%) create mode 100644 unirest/src/main/java/kong/unirest/FilePart.java create mode 100644 unirest/src/main/java/kong/unirest/MultipartMode.java create mode 100644 unirest/src/main/java/kong/unirest/ParamPart.java create mode 100644 unirest/src/main/java/kong/unirest/UniByteArrayBody.java create mode 100644 unirest/src/main/java/kong/unirest/UnibodyString.java create mode 100644 unirest/src/main/java/kong/unirest/apache/ApacheBodyMapper.java diff --git a/unirest/src/main/java/kong/unirest/BaseRequest.java b/unirest/src/main/java/kong/unirest/BaseRequest.java index 7e9afcbb4..66127a44f 100644 --- a/unirest/src/main/java/kong/unirest/BaseRequest.java +++ b/unirest/src/main/java/kong/unirest/BaseRequest.java @@ -273,11 +273,6 @@ public Headers getHeaders() { return headers; } - @Override - public Body getBody() { - return null; - } - private ObjectMapper getObjectMapper() { return objectMapper.orElseGet(config::getObjectMapper); } diff --git a/unirest/src/main/java/kong/unirest/Body.java b/unirest/src/main/java/kong/unirest/Body.java index 4efcb07b0..feb58874f 100644 --- a/unirest/src/main/java/kong/unirest/Body.java +++ b/unirest/src/main/java/kong/unirest/Body.java @@ -25,11 +25,28 @@ package kong.unirest; -import org.apache.http.HttpEntity; + +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.util.Collection; +import java.util.Collections; public interface Body { + boolean isMultiPart(); + + default Charset getCharset(){ + return StandardCharsets.UTF_8; + } + + default Collection multiParts(){ + return Collections.emptyList(); + } - @Deprecated // In version 4 Apache classes will be abstracted out - HttpEntity getEntity(); + default BodyPart uniPart(){ + return null; + } + default MultipartMode getMode(){ + return MultipartMode.BROWSER_COMPATIBLE; + } } diff --git a/unirest/src/main/java/kong/unirest/FormPart.java b/unirest/src/main/java/kong/unirest/BodyPart.java similarity index 55% rename from unirest/src/main/java/kong/unirest/FormPart.java rename to unirest/src/main/java/kong/unirest/BodyPart.java index 70ae78d3a..35cc47029 100644 --- a/unirest/src/main/java/kong/unirest/FormPart.java +++ b/unirest/src/main/java/kong/unirest/BodyPart.java @@ -25,28 +25,30 @@ package kong.unirest; - -import org.apache.http.entity.mime.content.*; - -import java.io.File; import java.nio.charset.StandardCharsets; -class FormPart implements Comparable { +public abstract class BodyPart implements Comparable { ; private final String name; - private final Object value; + private final T value; private final String contentType; + private final Class partType; - FormPart(String name, Object value, String contentType) { + protected BodyPart(T value, String name, String contentType) { this.name = name; this.value = value; this.contentType = contentType; + this.partType = value.getClass(); } - public Object getValue() { + public T getValue() { return value; } - private String getContentType() { + public Class getPartType(){ + return partType; + } + + public String getContentType() { if(contentType == null){ if(isFile()){ return ContentType.APPLICATION_OCTET_STREAM.toString(); @@ -56,44 +58,22 @@ private String getContentType() { return contentType; } - ContentBody toApachePart() { - if (value instanceof File) { - File file = (File) value; - return new FileBody(file, toApacheType(getContentType()), file.getName()); - } else if (value instanceof InputStreamPart) { - InputStreamPart part = (InputStreamPart)value; - return new InputStreamBody(part.getInputStream(), - toApacheType(part.getContentType()), - part.getFileName()); - } else if (value instanceof ByteArrayPart) { - ByteArrayPart part = (ByteArrayPart)value; - return new ByteArrayBody(part.getBytes(), - toApacheType(part.getContentType()), - part.getFileName()); - } else { - return new StringBody(value.toString(), toApacheType(getContentType())); - } - } - - private org.apache.http.entity.ContentType toApacheType(String type) { - return org.apache.http.entity.ContentType.parse(type); - } - public String getName() { return name == null ? "" : name; } + public String getFileName(){ + return null; + } + @Override public int compareTo(Object o) { - if(o instanceof FormPart){ - return getName().compareTo(((FormPart)o).getName()); + if(o instanceof BodyPart){ + return getName().compareTo(((BodyPart)o).getName()); } return 0; } - public boolean isFile(){ - return value instanceof File - || value instanceof InputStreamPart - || value instanceof ByteArrayPart; - } + + abstract public boolean isFile(); } diff --git a/unirest/src/main/java/kong/unirest/ByteArrayPart.java b/unirest/src/main/java/kong/unirest/ByteArrayPart.java index 06abdc63b..7d6eed2b0 100644 --- a/unirest/src/main/java/kong/unirest/ByteArrayPart.java +++ b/unirest/src/main/java/kong/unirest/ByteArrayPart.java @@ -26,26 +26,21 @@ package kong.unirest; -class ByteArrayPart { - private final byte[] bytes; - private final String contentType; +public class ByteArrayPart extends BodyPart { private final String fileName; - ByteArrayPart(byte[] bytes, ContentType contentType, String fileName) { - this.bytes = bytes; - this.contentType = contentType.toString(); + ByteArrayPart(String name, byte[] bytes, ContentType contentType, String fileName) { + super(bytes, name, contentType.toString()); this.fileName = fileName; } - public byte[] getBytes() { - return bytes; - } - - public String getContentType() { - return contentType; - } - + @Override public String getFileName() { return fileName; } + + @Override + public boolean isFile() { + return true; + } } diff --git a/unirest/src/main/java/kong/unirest/FilePart.java b/unirest/src/main/java/kong/unirest/FilePart.java new file mode 100644 index 000000000..7a7a1ae09 --- /dev/null +++ b/unirest/src/main/java/kong/unirest/FilePart.java @@ -0,0 +1,51 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +import java.io.File; + +class FilePart extends BodyPart { + private String fileName; + + public FilePart(File file, String name) { + this(file, name, null); + } + + public FilePart(File file, String name, String contentType) { + super(file, name, contentType); + this.fileName = file.getName(); + } + + @Override + public boolean isFile() { + return true; + } + + @Override + public String getFileName(){ + return null; + } +} diff --git a/unirest/src/main/java/kong/unirest/HttpRequest.java b/unirest/src/main/java/kong/unirest/HttpRequest.java index 7a844883b..f9872a03f 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequest.java +++ b/unirest/src/main/java/kong/unirest/HttpRequest.java @@ -28,6 +28,7 @@ import java.io.File; import java.util.Collection; import java.util.Map; +import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; import java.util.function.Function; @@ -317,9 +318,9 @@ PagedList asPaged(Function mappingFunction, Headers getHeaders(); /** - * Deprecated because it exposes Apache - * @return The current body object. + * @return if the request has a body it will be here. */ - @Deprecated - Body getBody(); + default Optional getBody(){ + return Optional.empty(); + } } diff --git a/unirest/src/main/java/kong/unirest/HttpRequestBody.java b/unirest/src/main/java/kong/unirest/HttpRequestBody.java index b1221952c..7357c1886 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestBody.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestBody.java @@ -34,6 +34,7 @@ import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Map; +import java.util.Optional; class HttpRequestBody extends BaseRequest implements HttpRequestWithBody { @@ -139,4 +140,9 @@ public Charset getCharset() { void setCharset(Charset charset) { this.charSet = charset; } + + @Override + public Optional getBody() { + return Optional.empty(); + } } diff --git a/unirest/src/main/java/kong/unirest/HttpRequestJsonPatch.java b/unirest/src/main/java/kong/unirest/HttpRequestJsonPatch.java index a55915707..c729907db 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestJsonPatch.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestJsonPatch.java @@ -25,10 +25,8 @@ package kong.unirest; -import org.apache.http.HttpEntity; -import org.apache.http.entity.BasicHttpEntity; - -import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; +import java.util.Optional; class HttpRequestJsonPatch extends BaseRequest implements JsonPatchRequest { @@ -76,14 +74,18 @@ public JsonPatchRequest copy(String from, String path) { } @Override - public Body getBody() { - return this; + public Optional getBody() { + return Optional.of(this); + } + + @Override + public BodyPart uniPart() { + String bodyAsString = items.toString(); + return new UnibodyString(bodyAsString, StandardCharsets.UTF_8); } @Override - public HttpEntity getEntity() { - BasicHttpEntity e = new BasicHttpEntity(); - e.setContent(new ByteArrayInputStream(items.toString().getBytes())); - return e; + public boolean isMultiPart() { + return false; } } \ No newline at end of file diff --git a/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java b/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java index efbbd8f76..8241ab44b 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java @@ -25,11 +25,7 @@ package kong.unirest; -import org.apache.http.HttpEntity; import org.apache.http.HttpHeaders; -import org.apache.http.client.entity.UrlEncodedFormEntity; -import org.apache.http.entity.mime.HttpMultipartMode; -import org.apache.http.entity.mime.MultipartEntityBuilder; import java.io.File; import java.io.InputStream; @@ -37,9 +33,9 @@ import java.util.*; class HttpRequestMultiPart extends BaseRequest implements MultipartBody { - private List parameters = new ArrayList<>(); + private List parameters = new ArrayList<>(); - private HttpMultipartMode mode = HttpMultipartMode.BROWSER_COMPATIBLE; + private MultipartMode mode = MultipartMode.BROWSER_COMPATIBLE; private Charset charSet; HttpRequestMultiPart(HttpRequestBody httpRequest) { @@ -49,67 +45,64 @@ class HttpRequestMultiPart extends BaseRequest implements Multipa @Override public MultipartBody field(String name, String value) { - addPart(name, value); + addPart(new ParamPart(name, value)); return this; } @Override public MultipartBody field(String name, String value, String contentType) { - addPart(name, value, contentType); + addPart(new ParamPart(name, value, contentType)); return this; } @Override public MultipartBody field(String name, Collection collection) { for (Object current: collection) { - addPart(name, current, (String)null); + addPart(name, current); } return this; } @Override public MultipartBody field(String name, InputStream value, ContentType contentType) { - addPart(name, new InputStreamPart(value, contentType.toString()), contentType); + addPart(new InputStreamPart(name, value, contentType.toString())); return this; } @Override public MultipartBody field(String name, File file) { - addPart(name, file); + addPart(new FilePart(file, name)); return this; } @Override public MultipartBody field(String name, File file, String contentType) { - addPart(name, file, contentType); + addPart(new FilePart(file, name, contentType)); return this; } @Override public MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName) { - addPart(name, new InputStreamPart(stream, contentType.toString(), fileName), contentType); + addPart(new InputStreamPart(name, stream, contentType.toString(), fileName)); return this; } @Override public MultipartBody field(String name, InputStream stream, String fileName) { - addPart(name, new InputStreamPart(stream, ContentType.APPLICATION_OCTET_STREAM.toString(), fileName), ContentType.APPLICATION_OCTET_STREAM); - + addPart(new InputStreamPart(name, stream, ContentType.APPLICATION_OCTET_STREAM.toString(), fileName)); return this; } @Override public MultipartBody field(String name, byte[] bytes, ContentType contentType, String fileName) { - addPart(name, new ByteArrayPart(bytes, contentType, fileName), contentType); - + addPart(new ByteArrayPart(name, bytes, contentType, fileName)); return this; } @Override public MultipartBody field(String name, byte[] bytes, String fileName) { - addPart(name, new ByteArrayPart(bytes, ContentType.APPLICATION_OCTET_STREAM, fileName), ContentType.APPLICATION_OCTET_STREAM); - + addPart(new ByteArrayPart(name, bytes, ContentType.APPLICATION_OCTET_STREAM, fileName)); return this; } @@ -125,18 +118,28 @@ public MultipartBody contentType(String mimeType) { return this; } + @Override + public Collection getParts() { + return new ArrayList<>(parameters); + } + @Override public MultipartBody mode(String value) { - this.mode = HttpMultipartMode.valueOf(value); + this.mode = MultipartMode.valueOf(value); return this; } @Override - public MultipartBody mode(HttpMultipartMode value) { + public MultipartBody mode(MultipartMode value) { this.mode = value; return this; } + @Override + public Charset getCharset() { + return this.charSet; + } + public MultipartBody fields(Map fields) { if (fields != null) { for (Map.Entry param : fields.entrySet()) { @@ -150,37 +153,38 @@ public MultipartBody fields(Map fields) { return this; } - @Override - public HttpEntity getEntity() { - if (parameters.stream().anyMatch(FormPart::isFile)) { - MultipartEntityBuilder builder = MultipartEntityBuilder.create(); - builder.setCharset(charSet); - builder.setMode(mode); - for (FormPart key : parameters) { - builder.addPart(key.getName(), key.toApachePart()); - } - return builder.build(); + private void addPart(String name, Object value) { + if(value instanceof InputStream){ + addPart(new InputStreamPart(name, (InputStream)value)); + } else if (value instanceof File) { + addPart(new FilePart((File)value, name)); } else { - return new UrlEncodedFormEntity(Util.getList(parameters), charSet); + addPart(new ParamPart(name, String.valueOf(value))); } } - @Override - public Body getBody() { - return this; + private void addPart(BodyPart value) { + parameters.add(value); + Collections.sort(parameters); } - private void addPart(String name, Object value, ContentType type) { - addPart(name, value, type.toString()); + @Override + public Optional getBody() { + return Optional.of(this); } - private void addPart(String name, Object value, String type) { - parameters.add(new FormPart(name, value, type)); - Collections.sort(parameters); + @Override + public boolean isMultiPart() { + return true; } - private void addPart(String name, Object value) { - addPart(name, value, (String)null); + @Override + public Collection multiParts() { + return new ArrayList<>(parameters); } + @Override + public MultipartMode getMode() { + return mode; + } } diff --git a/unirest/src/main/java/kong/unirest/HttpRequestNoBody.java b/unirest/src/main/java/kong/unirest/HttpRequestNoBody.java index b075452ce..3eff9cc45 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestNoBody.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestNoBody.java @@ -25,8 +25,15 @@ package kong.unirest; +import java.util.Optional; + class HttpRequestNoBody extends BaseRequest implements GetRequest { HttpRequestNoBody(Config config, HttpMethod method, String url) { super(config, method, url); } + + @Override + public Optional getBody() { + return Optional.empty(); + } } diff --git a/unirest/src/main/java/kong/unirest/HttpRequestUniBody.java b/unirest/src/main/java/kong/unirest/HttpRequestUniBody.java index 74b4b5f1d..f96862a6a 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestUniBody.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestUniBody.java @@ -25,17 +25,12 @@ package kong.unirest; -import org.apache.http.HttpEntity; -import org.apache.http.entity.ByteArrayEntity; -import org.apache.http.entity.StringEntity; - import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.function.Supplier; +import java.util.Optional; class HttpRequestUniBody extends BaseRequest implements RequestBodyEntity { - private Supplier body = () -> new StringEntity("", StandardCharsets.UTF_8); + private BodyPart body; private Charset charSet; HttpRequestUniBody(HttpRequestBody httpRequest) { @@ -44,20 +39,20 @@ class HttpRequestUniBody extends BaseRequest implements Reque } @Override - public RequestBodyEntity body(byte[] bodyBytes) { - this.body = () -> new ByteArrayEntity(bodyBytes); - return this; + public RequestBodyEntity body(JsonNode jsonBody) { + return body(jsonBody.toString()); } @Override public RequestBodyEntity body(String bodyAsString) { - this.body = () -> new StringEntity(bodyAsString, charSet); + this.body = new UnibodyString(bodyAsString, charSet); return this; } @Override - public RequestBodyEntity body(JsonNode jsonBody) { - return body(jsonBody.toString()); + public RequestBodyEntity body(byte[] bodyBytes) { + this.body = new UniByteArrayBody(bodyBytes); + return this; } @Override @@ -67,12 +62,22 @@ public RequestBodyEntity charset(Charset charset) { } @Override - public HttpEntity getEntity() { - return body.get(); + public Optional getBody() { + return Optional.of(this); } @Override - public Body getBody() { - return this; + public Charset getCharset() { + return charSet; + } + + @Override + public boolean isMultiPart() { + return false; + } + + @Override + public BodyPart uniPart() { + return body; } } diff --git a/unirest/src/main/java/kong/unirest/InputStreamPart.java b/unirest/src/main/java/kong/unirest/InputStreamPart.java index 508a1f28b..2584a13e0 100644 --- a/unirest/src/main/java/kong/unirest/InputStreamPart.java +++ b/unirest/src/main/java/kong/unirest/InputStreamPart.java @@ -27,31 +27,29 @@ import java.io.InputStream; -class InputStreamPart { - private final InputStream value; - private final String contentType; +public class InputStreamPart extends BodyPart { private String fileName; - public InputStreamPart(InputStream value, String contentType) { - this.value = value; - this.contentType = contentType; + InputStreamPart(String name, InputStream value) { + super(value, name, null); } - public InputStreamPart(InputStream value, String contentType, String fileName) { - this.value = value; - this.contentType = contentType; - this.fileName = fileName; - } - - public InputStream getInputStream() { - return value; + InputStreamPart(String name, InputStream value, String contentType) { + super(value, name, contentType); } - public String getContentType() { - return contentType; + InputStreamPart(String name, InputStream value, String contentType, String fileName) { + super(value, name, contentType); + this.fileName = fileName; } + @Override public String getFileName() { return fileName; } + + @Override + public boolean isFile() { + return true; + } } diff --git a/unirest/src/main/java/kong/unirest/MultipartBody.java b/unirest/src/main/java/kong/unirest/MultipartBody.java index b938f8f53..fa47dc6a3 100644 --- a/unirest/src/main/java/kong/unirest/MultipartBody.java +++ b/unirest/src/main/java/kong/unirest/MultipartBody.java @@ -25,8 +25,6 @@ package kong.unirest; -import org.apache.http.entity.mime.HttpMultipartMode; - import java.io.File; import java.io.InputStream; import java.nio.charset.Charset; @@ -139,21 +137,20 @@ public interface MultipartBody extends HttpRequest, Body { */ MultipartBody contentType(String mimeType); + + Collection getParts(); + /** * Set the Apache Mode. * @param value the string value of the mode * @return The same MultipartBody - * @deprecated Apache will be made a module in the future. * */ - @Deprecated MultipartBody mode(String value); /** * Set the Apache Mode. * @param value the value of the mode * @return The same MultipartBody - * @deprecated Apache will be made a module in the future. * */ - @Deprecated - MultipartBody mode(HttpMultipartMode value); + MultipartBody mode(MultipartMode value); } diff --git a/unirest/src/main/java/kong/unirest/MultipartMode.java b/unirest/src/main/java/kong/unirest/MultipartMode.java new file mode 100644 index 000000000..c289b6e47 --- /dev/null +++ b/unirest/src/main/java/kong/unirest/MultipartMode.java @@ -0,0 +1,35 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +public enum MultipartMode { + /** RFC 822, RFC 2045, RFC 2046 compliant */ + STRICT, + /** browser-compatible mode, i.e. only write Content-Disposition; use content charset */ + BROWSER_COMPATIBLE, + /** RFC 6532 compliant */ + RFC6532 +} diff --git a/unirest/src/main/java/kong/unirest/ParamPart.java b/unirest/src/main/java/kong/unirest/ParamPart.java new file mode 100644 index 000000000..2ccaac1c3 --- /dev/null +++ b/unirest/src/main/java/kong/unirest/ParamPart.java @@ -0,0 +1,41 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +public class ParamPart extends BodyPart { + ParamPart(String name, String value) { + this(name, value, null); + } + + ParamPart(String name, String value, String contentType) { + super(value, name, contentType); + } + + @Override + public boolean isFile() { + return false; + } +} diff --git a/unirest/src/main/java/kong/unirest/RequestBodyEntity.java b/unirest/src/main/java/kong/unirest/RequestBodyEntity.java index 8475b9b3c..8a82d4fc6 100644 --- a/unirest/src/main/java/kong/unirest/RequestBodyEntity.java +++ b/unirest/src/main/java/kong/unirest/RequestBodyEntity.java @@ -35,5 +35,4 @@ public interface RequestBodyEntity extends HttpRequest, Body RequestBodyEntity body(JsonNode jsonBody); RequestBodyEntity charset(Charset charset); - } diff --git a/unirest/src/main/java/kong/unirest/UniByteArrayBody.java b/unirest/src/main/java/kong/unirest/UniByteArrayBody.java new file mode 100644 index 000000000..c8f3ce06b --- /dev/null +++ b/unirest/src/main/java/kong/unirest/UniByteArrayBody.java @@ -0,0 +1,37 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +class UniByteArrayBody extends BodyPart { + UniByteArrayBody(byte[] bodyBytes) { + super(bodyBytes, null, null); + } + + @Override + public boolean isFile() { + return false; + } +} diff --git a/unirest/src/main/java/kong/unirest/UnibodyString.java b/unirest/src/main/java/kong/unirest/UnibodyString.java new file mode 100644 index 000000000..7b5c052ed --- /dev/null +++ b/unirest/src/main/java/kong/unirest/UnibodyString.java @@ -0,0 +1,39 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +import java.nio.charset.Charset; + +class UnibodyString extends BodyPart { + UnibodyString(String bodyAsString, Charset charset) { + super(bodyAsString, null, null); + } + + @Override + public boolean isFile() { + return false; + } +} diff --git a/unirest/src/main/java/kong/unirest/Util.java b/unirest/src/main/java/kong/unirest/Util.java index 56640a14b..8d4b0e277 100644 --- a/unirest/src/main/java/kong/unirest/Util.java +++ b/unirest/src/main/java/kong/unirest/Util.java @@ -25,14 +25,8 @@ package kong.unirest; -import org.apache.http.NameValuePair; -import org.apache.http.message.BasicNameValuePair; - import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; import java.util.Optional; import java.util.stream.Stream; @@ -58,14 +52,6 @@ static String encode(String input) { } } - static List getList(Collection parameters) { - List result = new ArrayList<>(); - for (FormPart entry : parameters) { - result.add(new BasicNameValuePair(entry.getName(), entry.getValue().toString())); - } - return result; - } - static boolean isNullOrEmpty(String s) { return s == null || s.trim().isEmpty(); } diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheBodyMapper.java b/unirest/src/main/java/kong/unirest/apache/ApacheBodyMapper.java new file mode 100644 index 000000000..96ae7b339 --- /dev/null +++ b/unirest/src/main/java/kong/unirest/apache/ApacheBodyMapper.java @@ -0,0 +1,128 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest.apache; + +import kong.unirest.*; +import org.apache.http.HttpEntity; +import org.apache.http.NameValuePair; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.entity.BasicHttpEntity; +import org.apache.http.entity.ByteArrayEntity; +import org.apache.http.entity.StringEntity; +import org.apache.http.entity.mime.HttpMultipartMode; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.entity.mime.content.*; +import org.apache.http.message.BasicNameValuePair; + +import java.io.File; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Optional; + +class ApacheBodyMapper { + + private final HttpRequest request; + + ApacheBodyMapper(HttpRequest request){ + this.request = request; + } + + + HttpEntity apply() { + Optional body = request.getBody(); + return body.map(this::applyBody).orElseGet(BasicHttpEntity::new); + + } + + private HttpEntity applyBody(Body o) { + if(o.isMultiPart()){ + return mapToMultipart(o); + }else { + return mapToUniBody(o); + } + } + + + private HttpEntity mapToUniBody(Body b) { + BodyPart bodyPart = b.uniPart(); + if(String.class.isAssignableFrom(bodyPart.getPartType())){ + return new StringEntity((String) bodyPart.getValue(), b.getCharset()); + } else { + return new ByteArrayEntity((byte[])bodyPart.getValue()); + } + } + + private HttpEntity mapToMultipart(Body body) { + if (body.multiParts().stream().anyMatch(BodyPart::isFile)) { + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + builder.setCharset(body.getCharset()); + builder.setMode(HttpMultipartMode.valueOf(body.getMode().name())); + for (BodyPart key : body.multiParts()) { + builder.addPart(key.getName(), apply(key)); + } + return builder.build(); + } else { + return new UrlEncodedFormEntity(getList(body.multiParts()), body.getCharset()); + } + } + + private ContentBody apply(BodyPart value) { + if (is(value, File.class)) { + File file = (File)value.getValue(); + return new FileBody(file, toApacheType(value.getContentType())); + } else if (is(value, InputStream.class)) { + InputStream part = (InputStream)value.getValue(); + return new InputStreamBody(part, + toApacheType(value.getContentType()), + value.getFileName()); + } else if (is(value, byte[].class)) { + byte[] part = (byte[])value.getValue(); + return new ByteArrayBody(part, + toApacheType(value.getContentType()), + value.getFileName()); + } else { + return new StringBody(String.valueOf(value.getValue()), toApacheType(value.getContentType())); + } + } + + private boolean is(BodyPart value, Class cls) { + return cls.isAssignableFrom(value.getPartType()); + } + + private org.apache.http.entity.ContentType toApacheType(String type) { + return org.apache.http.entity.ContentType.parse(type); + } + + static List getList(Collection parameters) { + List result = new ArrayList<>(); + for (BodyPart entry : parameters) { + result.add(new BasicNameValuePair(entry.getName(), entry.getValue().toString())); + } + return result; + } +} diff --git a/unirest/src/main/java/kong/unirest/apache/RequestPrep.java b/unirest/src/main/java/kong/unirest/apache/RequestPrep.java index a86728049..a5db126b9 100644 --- a/unirest/src/main/java/kong/unirest/apache/RequestPrep.java +++ b/unirest/src/main/java/kong/unirest/apache/RequestPrep.java @@ -58,12 +58,12 @@ class RequestPrep { FACTORIES.put(HttpMethod.HEAD, HttpHead::new); } - RequestPrep(HttpRequest request, boolean async){ + RequestPrep(HttpRequest request, boolean async) { this.request = request; this.async = async; } - HttpRequestBase prepare(){ + HttpRequestBase prepare() { HttpRequestBase reqObj = getHttpRequestBase(); setBody(reqObj); @@ -84,7 +84,7 @@ private HttpRequestBase getHttpRequestBase() { HttpRequestBase reqObj = FACTORIES.computeIfAbsent(request.getHttpMethod(), this::register).apply(url); request.getHeaders().all().stream().map(this::toEntries).forEach(reqObj::addHeader); return reqObj; - }catch (RuntimeException e){ + } catch (RuntimeException e) { throw new UnirestException(e); } } @@ -98,24 +98,23 @@ private Header toEntries(kong.unirest.Header k) { } private void setBody(HttpRequestBase reqObj) { - if (!(request.getHttpMethod() == HttpMethod.GET || request.getHttpMethod() == HttpMethod.HEAD)) { - if (request.getBody() != null) { - HttpEntity entity = request.getBody().getEntity(); - if (async) { - if (reqObj.getHeaders(CONTENT_TYPE) == null || reqObj.getHeaders(CONTENT_TYPE).length == 0) { - reqObj.setHeader(entity.getContentType()); - } - try { - ByteArrayOutputStream output = new ByteArrayOutputStream(); - entity.writeTo(output); - NByteArrayEntity en = new NByteArrayEntity(output.toByteArray()); - ((HttpEntityEnclosingRequestBase) reqObj).setEntity(en); - } catch (IOException e) { - throw new UnirestException(e); - } - } else { - ((HttpEntityEnclosingRequestBase) reqObj).setEntity(entity); + if (request.getBody().isPresent()) { + ApacheBodyMapper mapper = new ApacheBodyMapper(request); + HttpEntity entity = mapper.apply(); + if (async) { + if (reqObj.getHeaders(CONTENT_TYPE) == null || reqObj.getHeaders(CONTENT_TYPE).length == 0) { + reqObj.setHeader(entity.getContentType()); } + try { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + entity.writeTo(output); + NByteArrayEntity en = new NByteArrayEntity(output.toByteArray()); + ((HttpEntityEnclosingRequestBase) reqObj).setEntity(en); + } catch (IOException e) { + throw new UnirestException(e); + } + } else { + ((HttpEntityEnclosingRequestBase) reqObj).setEntity(entity); } } } diff --git a/unirest/src/test/java/BehaviorTests/FormPostingTest.java b/unirest/src/test/java/BehaviorTests/FormPostingTest.java index febe64da9..daadefc80 100644 --- a/unirest/src/test/java/BehaviorTests/FormPostingTest.java +++ b/unirest/src/test/java/BehaviorTests/FormPostingTest.java @@ -26,8 +26,7 @@ package BehaviorTests; import kong.unirest.*; -import org.apache.commons.io.IOUtils; -import org.apache.http.entity.mime.HttpMultipartMode; +import org.junit.Assert; import org.junit.Test; import java.io.ByteArrayInputStream; @@ -38,7 +37,6 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; -import static org.junit.Assert.assertEquals; import static kong.unirest.TestUtil.rezFile; public class FormPostingTest extends BddTest { @@ -132,11 +130,10 @@ public void testMultipartByteContentType() throws Exception { stream.close(); Unirest.post(MockServer.POST) - .field("name", "Mark") + .field("boot","boot") .field("file", bytes, "image.jpg") .asObject(RequestCapture.class) .getBody() - .assertParam("name", "Mark") .getFile("image.jpg") .assertFileType("application/octet-stream"); } @@ -249,19 +246,6 @@ public void testPostCollection() { .assertParam("name", "Tom"); } - @Test - public void testPostProvidesSortedParams() throws Exception { - // Verify that fields are encoded into the body in sorted order. - HttpRequest httpRequest = Unirest.post("test") - .field("z", "Z") - .field("y", "Y") - .field("x", "X"); - - InputStream content = httpRequest.getBody().getEntity().getContent(); - String body = IOUtils.toString(content, "UTF-8"); - assertEquals("x=X&y=Y&z=Z", body); - } - @Test public void postFileWithContentType() throws Exception { File file = getImageFile(); @@ -417,7 +401,7 @@ public void canSetModeToStrictForLegacySupport() { Unirest.post(MockServer.POST) .field("file", fileData, filename) - .mode(HttpMultipartMode.STRICT) + .mode(MultipartMode.STRICT) .asObject(RequestCapture.class) .getBody() .getFile("file???.p?f") diff --git a/unirest/src/test/java/BehaviorTests/RequestCapture.java b/unirest/src/test/java/BehaviorTests/RequestCapture.java index 74976232e..af7691fc9 100644 --- a/unirest/src/test/java/BehaviorTests/RequestCapture.java +++ b/unirest/src/test/java/BehaviorTests/RequestCapture.java @@ -48,7 +48,7 @@ public class RequestCapture { public ListMultimap headers = LinkedListMultimap.create(); public List files = new ArrayList<>(); - public Multimap params = HashMultimap.create(); + public ArrayListMultimap params = ArrayListMultimap.create(); public String body; public String url; public String queryString; diff --git a/unirest/src/test/java/kong/unirest/UriFormatterTest.java b/unirest/src/test/java/kong/unirest/UriFormatterTest.java index a2bd16e9d..a57ea68f0 100644 --- a/unirest/src/test/java/kong/unirest/UriFormatterTest.java +++ b/unirest/src/test/java/kong/unirest/UriFormatterTest.java @@ -27,6 +27,8 @@ import org.junit.Test; +import java.util.Optional; + import static org.junit.Assert.assertEquals; public class UriFormatterTest { From c810261561ab3478adff00f61aeedf2245eada48 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 22 Feb 2019 19:23:43 -0600 Subject: [PATCH 0461/1769] fix tests --- reports.sh | 26 +++++++++++++++++++ .../{AsFileTests.java => AsFileTest.java} | 2 +- .../{ConsumerTests.java => ConsumerTest.java} | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100755 reports.sh rename unirest/src/test/java/BehaviorTests/{AsFileTests.java => AsFileTest.java} (98%) rename unirest/src/test/java/BehaviorTests/{ConsumerTests.java => ConsumerTest.java} (97%) diff --git a/reports.sh b/reports.sh new file mode 100755 index 000000000..f26737a89 --- /dev/null +++ b/reports.sh @@ -0,0 +1,26 @@ +# +# The MIT License +# +# Copyright for portions of unirest-java are held by Kong Inc (c) 2013. +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +open ./unirest/target/site/jacoco/index.html \ No newline at end of file diff --git a/unirest/src/test/java/BehaviorTests/AsFileTests.java b/unirest/src/test/java/BehaviorTests/AsFileTest.java similarity index 98% rename from unirest/src/test/java/BehaviorTests/AsFileTests.java rename to unirest/src/test/java/BehaviorTests/AsFileTest.java index 3f3f5e46a..e66557f44 100644 --- a/unirest/src/test/java/BehaviorTests/AsFileTests.java +++ b/unirest/src/test/java/BehaviorTests/AsFileTest.java @@ -38,7 +38,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -public class AsFileTests extends BddTest { +public class AsFileTest extends BddTest { private Path test = Paths.get("results.json"); private JacksonObjectMapper om = new JacksonObjectMapper(); diff --git a/unirest/src/test/java/BehaviorTests/ConsumerTests.java b/unirest/src/test/java/BehaviorTests/ConsumerTest.java similarity index 97% rename from unirest/src/test/java/BehaviorTests/ConsumerTests.java rename to unirest/src/test/java/BehaviorTests/ConsumerTest.java index 5a6a0408c..3c2d4a7aa 100644 --- a/unirest/src/test/java/BehaviorTests/ConsumerTests.java +++ b/unirest/src/test/java/BehaviorTests/ConsumerTest.java @@ -31,7 +31,7 @@ import static org.junit.Assert.assertEquals; -public class ConsumerTests extends BddTest { +public class ConsumerTest extends BddTest { private int status; From d279a60233fad2833a367f423ddc8b733d175be5 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 23 Feb 2019 09:00:06 -0600 Subject: [PATCH 0462/1769] backfilling tests and doc --- .../main/java/kong/unirest/BaseRequest.java | 2 +- .../main/java/kong/unirest/JsonPatchItem.java | 4 +- .../test/java/BehaviorTests/HeaderTest.java | 10 +++ .../java/kong/unirest/JsonPatchItemTest.java | 89 +++++++++++++++++++ 4 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 unirest/src/test/java/kong/unirest/JsonPatchItemTest.java diff --git a/unirest/src/main/java/kong/unirest/BaseRequest.java b/unirest/src/main/java/kong/unirest/BaseRequest.java index 66127a44f..9e5ce5b21 100644 --- a/unirest/src/main/java/kong/unirest/BaseRequest.java +++ b/unirest/src/main/java/kong/unirest/BaseRequest.java @@ -91,7 +91,7 @@ public R headerReplace(String name, String value) { @Override public R headers(Map headerMap) { - if (headers != null) { + if (headerMap != null) { for (Map.Entry entry : headerMap.entrySet()) { header(entry.getKey(), entry.getValue()); } diff --git a/unirest/src/main/java/kong/unirest/JsonPatchItem.java b/unirest/src/main/java/kong/unirest/JsonPatchItem.java index b8d427132..9484d0558 100644 --- a/unirest/src/main/java/kong/unirest/JsonPatchItem.java +++ b/unirest/src/main/java/kong/unirest/JsonPatchItem.java @@ -40,8 +40,8 @@ public JsonPatchItem(JsonPatchOperation op, String path, Object value){ this.value = value; } - public JsonPatchItem(JsonPatchOperation remove, String path) { - this(remove, path, null); + public JsonPatchItem(JsonPatchOperation op, String path) { + this(op, path, null); } public JsonPatchItem(JSONObject row) { diff --git a/unirest/src/test/java/BehaviorTests/HeaderTest.java b/unirest/src/test/java/BehaviorTests/HeaderTest.java index 1429dd6d0..bf6b67bb3 100644 --- a/unirest/src/test/java/BehaviorTests/HeaderTest.java +++ b/unirest/src/test/java/BehaviorTests/HeaderTest.java @@ -292,4 +292,14 @@ public void canSetAHeaderAsASupplier() { .getBody() .assertHeader("trace", "two"); } + + @Test + public void nullTests() { + Unirest.get(MockServer.GET) + .header("foo","bar") + .headers(null) + .asObject(RequestCapture.class) + .getBody() + .assertHeader("foo","bar"); + } } diff --git a/unirest/src/test/java/kong/unirest/JsonPatchItemTest.java b/unirest/src/test/java/kong/unirest/JsonPatchItemTest.java new file mode 100644 index 000000000..9047f0509 --- /dev/null +++ b/unirest/src/test/java/kong/unirest/JsonPatchItemTest.java @@ -0,0 +1,89 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +import com.google.common.collect.Sets; +import org.junit.Test; + +import java.util.Set; + +import static kong.unirest.JsonPatchOperation.*; +import static org.junit.Assert.*; + +public class JsonPatchItemTest { + + @Test + public void patchOperationsAreUniqueByTheirElements() { + assertEquals( + new JsonPatchItem(add, "/foo", "bar"), + new JsonPatchItem(add, "/foo", "bar") + ); + + assertEquals( + new JsonPatchItem(remove, "/foo"), + new JsonPatchItem(remove, "/foo") + ); + + assertNotEquals( + new JsonPatchItem(add, "/foo", "bar"), + new JsonPatchItem(add, "/foo", "baz") + ); + + assertNotEquals( + new JsonPatchItem(add, "/foo", "bar"), + new JsonPatchItem(replace, "/foo", "bar") + ); + + assertNotEquals( + new JsonPatchItem(remove, "/foo"), + new JsonPatchItem(remove, "/foo", "baz") + ); + } + + @Test + public void testHash() { + Set s = Sets.newHashSet(new JsonPatchItem(add, "/foo", "bar"), + new JsonPatchItem(add, "/foo", "bar")); + + assertEquals(1, s.size()); + } + + @Test + public void edgeEquals() { + JsonPatchItem i = new JsonPatchItem(add, "/foo", "bar"); + assertTrue(i.equals(i)); + assertFalse(i.equals(null)); + assertFalse(i.equals(new Object())); + } + + @Test + public void basicTest() { + JsonPatchItem i = new JsonPatchItem(add, "/foo", "bar"); + assertEquals(add, i.getOp()); + assertEquals("/foo", i.getPath()); + assertEquals("bar", i.getValue()); + } +} \ No newline at end of file From 6e93f3ec2ae123ed971953b178c513e4f0c16a98 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 23 Feb 2019 09:32:34 -0600 Subject: [PATCH 0463/1769] change the proxy object to be a unirest one and push the apache bits into the apache module --- .../src/main/java/kong/unirest/Config.java | 23 ++----- unirest/src/main/java/kong/unirest/Proxy.java | 64 +++++++++++++++++++ .../unirest/apache/ApacheAsyncClient.java | 2 +- .../kong/unirest/apache/ApacheClient.java | 2 +- .../kong/unirest/apache/BaseApacheClient.java | 24 ++++++- .../test/java/BehaviorTests/ProxyTest.java | 3 +- .../test/java/kong/unirest/ConfigTest.java | 19 ++++++ 7 files changed, 115 insertions(+), 22 deletions(-) create mode 100644 unirest/src/main/java/kong/unirest/Proxy.java diff --git a/unirest/src/main/java/kong/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java index 44f0e90cb..3e6b504c4 100644 --- a/unirest/src/main/java/kong/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -27,13 +27,8 @@ import kong.unirest.apache.ApacheAsyncClient; import kong.unirest.apache.ApacheClient; -import org.apache.http.HttpHost; import org.apache.http.HttpRequestInterceptor; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.CredentialsProvider; import org.apache.http.client.HttpClient; -import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.nio.client.HttpAsyncClient; import java.nio.charset.StandardCharsets; @@ -59,8 +54,7 @@ public class Config { private List interceptors = new ArrayList<>(); private Headers defaultHeaders; - private HttpHost proxy; - private CredentialsProvider proxyCreds; + private Proxy proxy; private int connectionTimeout; private int socketTimeout; private int maxTotal; @@ -160,7 +154,7 @@ public Config asyncClient(Function asyncClientBuilder){ * @param value Proxy settings object. * @return this config object */ - public Config proxy(HttpHost value) { + public Config proxy(Proxy value) { validateClientsNotRunning(); this.proxy = value; return this; @@ -174,7 +168,7 @@ public Config proxy(HttpHost value) { * @return this config object */ public Config proxy(String host, int port) { - return proxy(new HttpHost(host, port)); + return proxy(new Proxy(host, port)); } /** @@ -187,10 +181,7 @@ public Config proxy(String host, int port) { * @return this config object */ public Config proxy(String host, int port, String username, String password) { - proxyCreds = new BasicCredentialsProvider(); - proxyCreds.setCredentials(new AuthScope(host, port), - new UsernamePasswordCredentials(username, password)); - return proxy(new HttpHost(host, port)); + return proxy(new Proxy(host, port, username, password)); } /** @@ -496,14 +487,10 @@ public List getInterceptors() { return interceptors; } - public HttpHost getProxy() { + public Proxy getProxy() { return proxy; } - public CredentialsProvider getProxyCreds(){ - return proxyCreds; - } - public boolean useSystemProperties(){ return this.useSystemProperties; } diff --git a/unirest/src/main/java/kong/unirest/Proxy.java b/unirest/src/main/java/kong/unirest/Proxy.java new file mode 100644 index 000000000..d3ca8f5fc --- /dev/null +++ b/unirest/src/main/java/kong/unirest/Proxy.java @@ -0,0 +1,64 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +public class Proxy { + private final String host; + private final Integer port; + private final String username; + private final String password; + + public Proxy(String host, Integer port){ + this(host, port, null, null); + } + + public Proxy(String host, Integer port, String username, String password) { + this.host = host; + this.port = port; + this.username = username; + this.password = password; + } + + public String getHost() { + return host; + } + + public Integer getPort() { + return port; + } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public boolean isAuthenticated() { + return username != null && password != null; + } +} diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java index a0a5500c7..e5e657dfc 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java @@ -58,7 +58,7 @@ public ApacheAsyncClient(Config config) { HttpAsyncClientBuilder ab = HttpAsyncClientBuilder.create() .setDefaultRequestConfig(getRequestConfig(config)) .setConnectionManager(manager) - .setDefaultCredentialsProvider(config.getProxyCreds()) + .setDefaultCredentialsProvider(toApacheCreds(config.getProxy())) .useSystemProperties(); if(config.useSystemProperties()){ diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java index c3860f6b5..ede8cb331 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java @@ -51,7 +51,7 @@ public ApacheClient(Config config) { HttpClientBuilder cb = HttpClientBuilder.create() .setDefaultRequestConfig(getRequestConfig(config)) - .setDefaultCredentialsProvider(config.getProxyCreds()) + .setDefaultCredentialsProvider(toApacheCreds(config.getProxy())) .setConnectionManager(manager) .useSystemProperties(); diff --git a/unirest/src/main/java/kong/unirest/apache/BaseApacheClient.java b/unirest/src/main/java/kong/unirest/apache/BaseApacheClient.java index 910a63c2f..c894dbff7 100644 --- a/unirest/src/main/java/kong/unirest/apache/BaseApacheClient.java +++ b/unirest/src/main/java/kong/unirest/apache/BaseApacheClient.java @@ -26,15 +26,20 @@ package kong.unirest.apache; import kong.unirest.Config; +import kong.unirest.Proxy; import org.apache.http.HttpHost; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; import org.apache.http.client.config.RequestConfig; +import org.apache.http.impl.client.BasicCredentialsProvider; abstract class BaseApacheClient { protected RequestConfig getRequestConfig(Config config) { Integer connectionTimeout = config.getConnectionTimeout(); Integer socketTimeout = config.getSocketTimeout(); - HttpHost proxy = config.getProxy(); + HttpHost proxy = toApacheProxy(config.getProxy()); return RequestConfig.custom() .setConnectTimeout(connectionTimeout) .setSocketTimeout(socketTimeout) @@ -42,4 +47,21 @@ protected RequestConfig getRequestConfig(Config config) { .setProxy(proxy) .build(); } + + private HttpHost toApacheProxy(Proxy proxy){ + if(proxy == null){ + return null; + } + return new HttpHost(proxy.getHost(), proxy.getPort()); + } + + protected CredentialsProvider toApacheCreds(Proxy proxy) { + if(proxy != null && proxy.isAuthenticated()) { + CredentialsProvider proxyCreds = new BasicCredentialsProvider(); + proxyCreds.setCredentials(new AuthScope(proxy.getHost(), proxy.getPort()), + new UsernamePasswordCredentials(proxy.getUsername(), proxy.getPassword())); + return proxyCreds; + } + return null; + } } diff --git a/unirest/src/test/java/BehaviorTests/ProxyTest.java b/unirest/src/test/java/BehaviorTests/ProxyTest.java index c9de4aecc..2ff63d5ce 100644 --- a/unirest/src/test/java/BehaviorTests/ProxyTest.java +++ b/unirest/src/test/java/BehaviorTests/ProxyTest.java @@ -25,6 +25,7 @@ package BehaviorTests; +import kong.unirest.Proxy; import org.apache.http.HttpHost; import org.junit.After; import org.junit.Ignore; @@ -48,7 +49,7 @@ public void tearDown() { public void canUseNonAuthProxy() { JankyProxy.runServer("localhost", 4567, 7777); - Unirest.config().proxy(new HttpHost("localhost", 7777)); + Unirest.config().proxy(new Proxy("localhost", 7777)); Unirest.get(MockServer.GET) .asObject(RequestCapture.class) diff --git a/unirest/src/test/java/kong/unirest/ConfigTest.java b/unirest/src/test/java/kong/unirest/ConfigTest.java index 9cfb75d85..a37c22044 100644 --- a/unirest/src/test/java/kong/unirest/ConfigTest.java +++ b/unirest/src/test/java/kong/unirest/ConfigTest.java @@ -205,4 +205,23 @@ public void willNotRebuildIfRunning() { assertSame(c, config.getAsyncClient().getClient()); } + + @Test + public void canSetProxyViaSetter() { + config.proxy(new Proxy("localhost", 8080, "ryan", "password")); + assertProxy("localhost", 8080, "ryan", "password"); + + config.proxy("local2", 8888); + assertProxy("local2", 8888, null, null); + + config.proxy("local3", 7777, "barb", "12345"); + assertProxy("local3", 7777, "barb", "12345"); + } + + private void assertProxy(String host, Integer port, String username, String password) { + assertEquals(host, config.getProxy().getHost()); + assertEquals(port, config.getProxy().getPort()); + assertEquals(username, config.getProxy().getUsername()); + assertEquals(password, config.getProxy().getPassword()); + } } \ No newline at end of file From 513de82d1b803b9f34a025dda259e60a5e9239db Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 23 Feb 2019 09:54:21 -0600 Subject: [PATCH 0464/1769] config and timeout tests that werent running --- .../src/main/java/kong/unirest/Config.java | 2 +- ...andling.java => RedirectHandlingTest.java} | 2 +- .../{TimeoutTests.java => TimeoutTest.java} | 11 +++++----- .../test/java/kong/unirest/ConfigTest.java | 21 ++++++++++++++++++- 4 files changed, 28 insertions(+), 8 deletions(-) rename unirest/src/test/java/BehaviorTests/{RedirectHandling.java => RedirectHandlingTest.java} (97%) rename unirest/src/test/java/BehaviorTests/{TimeoutTests.java => TimeoutTest.java} (94%) diff --git a/unirest/src/main/java/kong/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java index 3e6b504c4..ce7926612 100644 --- a/unirest/src/main/java/kong/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -477,7 +477,7 @@ public ObjectMapper getObjectMapper() { private void validateClientsNotRunning() { if (client.isPresent() || asyncClient.isPresent()) { throw new UnirestConfigException( - "Http Clients are already build in order to build a new config execute Unirest.config().reset() before changing settings. \n" + + "Http Clients are already built in order to build a new config execute Unirest.config().reset() before changing settings. \n" + "This should be done rarely." ); } diff --git a/unirest/src/test/java/BehaviorTests/RedirectHandling.java b/unirest/src/test/java/BehaviorTests/RedirectHandlingTest.java similarity index 97% rename from unirest/src/test/java/BehaviorTests/RedirectHandling.java rename to unirest/src/test/java/BehaviorTests/RedirectHandlingTest.java index 8fb271665..b9f21a4b7 100644 --- a/unirest/src/test/java/BehaviorTests/RedirectHandling.java +++ b/unirest/src/test/java/BehaviorTests/RedirectHandlingTest.java @@ -33,7 +33,7 @@ import static org.junit.Assert.assertEquals; -public class RedirectHandling extends BddTest { +public class RedirectHandlingTest extends BddTest { @Test public void willFollowRedirectsByDefault() { diff --git a/unirest/src/test/java/BehaviorTests/TimeoutTests.java b/unirest/src/test/java/BehaviorTests/TimeoutTest.java similarity index 94% rename from unirest/src/test/java/BehaviorTests/TimeoutTests.java rename to unirest/src/test/java/BehaviorTests/TimeoutTest.java index 57f88bd05..f1ead7328 100644 --- a/unirest/src/test/java/BehaviorTests/TimeoutTests.java +++ b/unirest/src/test/java/BehaviorTests/TimeoutTest.java @@ -45,24 +45,25 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -public class TimeoutTests extends BddTest { +public class TimeoutTest extends BddTest { @Test - public void testSetTimeouts() throws IOException { - String address = "http://" + findAvailableIpAddress() + "/"; + public void testSetTimeouts() { + String address = MockServer.GET; long start = System.currentTimeMillis(); try { - Unirest.get("http://" + address + "/").asString(); + Unirest.get(address).asString(); } catch (Exception e) { if (System.currentTimeMillis() - start > Config.DEFAULT_CONNECTION_TIMEOUT + 100) { // Add 100ms for code execution fail(); } } + Unirest.config().reset(); Unirest.config().connectTimeout(2000).socketTimeout(10000); start = System.currentTimeMillis(); try { - Unirest.get("http://" + address + "/").asString(); + Unirest.get(address).asString(); } catch (Exception e) { if (System.currentTimeMillis() - start > 2100) { // Add 100ms for code execution fail(); diff --git a/unirest/src/test/java/kong/unirest/ConfigTest.java b/unirest/src/test/java/kong/unirest/ConfigTest.java index a37c22044..f52f01020 100644 --- a/unirest/src/test/java/kong/unirest/ConfigTest.java +++ b/unirest/src/test/java/kong/unirest/ConfigTest.java @@ -93,7 +93,7 @@ public void onceTheConfigIsRunningYouCannotChangeConfig(){ TestUtil.assertException(() -> config.socketTimeout(533), UnirestConfigException.class, - "Http Clients are already build in order to build a new config execute Unirest.config().reset() " + + "Http Clients are already built in order to build a new config execute Unirest.config().reset() " + "before changing settings. \n" + "This should be done rarely."); @@ -206,6 +206,25 @@ public void willNotRebuildIfRunning() { assertSame(c, config.getAsyncClient().getClient()); } + @Test + public void provideYourOwnClientBuilder() { + Client cli = mock(Client.class); + + config.httpClient(c -> cli); + + assertSame(cli, config.getClient()); + } + + @Test + public void provideYourOwnAsyncClientBuilder() { + AsyncClient cli = mock(AsyncClient.class); + when(cli.isRunning()).thenReturn(true); + + config.asyncClient(c -> cli); + + assertSame(cli, config.getAsyncClient()); + } + @Test public void canSetProxyViaSetter() { config.proxy(new Proxy("localhost", 8080, "ryan", "password")); From 9a4b5b5e9dba5c354fb28a2834981f9e08fdee0c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 23 Feb 2019 13:08:57 -0600 Subject: [PATCH 0465/1769] more test backfill --- .../java/BehaviorTests/FormPostingTest.java | 34 +++++++++++++++---- .../java/BehaviorTests/RequestCapture.java | 6 ++++ unirest/src/test/resources/test2 | 1 + 3 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 unirest/src/test/resources/test2 diff --git a/unirest/src/test/java/BehaviorTests/FormPostingTest.java b/unirest/src/test/java/BehaviorTests/FormPostingTest.java index daadefc80..1dc4e832b 100644 --- a/unirest/src/test/java/BehaviorTests/FormPostingTest.java +++ b/unirest/src/test/java/BehaviorTests/FormPostingTest.java @@ -29,15 +29,15 @@ import org.junit.Assert; import org.junit.Test; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; +import java.io.*; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.util.Arrays; +import java.util.List; +import static java.util.Arrays.asList; import static kong.unirest.TestUtil.rezFile; +import static org.junit.Assert.assertEquals; public class FormPostingTest extends BddTest { @Test @@ -239,13 +239,34 @@ public void testPostBinaryUTF8() throws Exception { @Test public void testPostCollection() { Unirest.post(MockServer.POST) - .field("name", Arrays.asList("Mark", "Tom")) + .field("name", asList("Mark", "Tom")) .asObject(RequestCapture.class) .getBody() .assertParam("name", "Mark") .assertParam("name", "Tom"); } + @Test + public void testPostMulipleFIles() { + RequestCapture cap = Unirest.post(MockServer.POST) + .field("name", asList(rezFile("/test"), rezFile("/test2"))) + .asObject(RequestCapture.class) + .getBody(); + + cap.getFile("test").assertBody("This is a test file"); + cap.getFile("test2").assertBody("this is another test"); + } + + @Test + public void testMultipeInputStreams() throws FileNotFoundException { + Unirest.post(MockServer.POST) + .field("name", asList(new FileInputStream(rezFile("/test")), new FileInputStream(rezFile("/test2")))) + .asObject(RequestCapture.class) + .getBody() + .assertParam("name", "This is a test file") + .assertParam("name", "this is another test"); + } + @Test public void postFileWithContentType() throws Exception { File file = getImageFile(); @@ -408,8 +429,7 @@ public void canSetModeToStrictForLegacySupport() { .assertFileName("file???.p?f"); } - - private File getImageFile() throws URISyntaxException { + private File getImageFile() { return rezFile("/image.jpg"); } } diff --git a/unirest/src/test/java/BehaviorTests/RequestCapture.java b/unirest/src/test/java/BehaviorTests/RequestCapture.java index af7691fc9..f36919ad0 100644 --- a/unirest/src/test/java/BehaviorTests/RequestCapture.java +++ b/unirest/src/test/java/BehaviorTests/RequestCapture.java @@ -173,6 +173,12 @@ public File getFileByInput(String input) { .orElseThrow(() -> new RuntimeException("No File from form: " + input)); } + public List getAllFilesByInput(String input){ + return files.stream() + .filter(f -> Objects.equals(f.inputName, input)) + .collect(Collectors.toList()); + } + public RequestCapture assertFileContent(String input, String content) { assertEquals(content, getFileByInput(input).body); return this; diff --git a/unirest/src/test/resources/test2 b/unirest/src/test/resources/test2 new file mode 100644 index 000000000..9e7eb5bf8 --- /dev/null +++ b/unirest/src/test/resources/test2 @@ -0,0 +1 @@ +this is another test \ No newline at end of file From 4921928fadf403c0ae39098b6276b638c72d8249 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 23 Feb 2019 13:20:24 -0600 Subject: [PATCH 0466/1769] clean up --- .../kong/unirest/HttpRequestMultiPart.java | 5 ---- .../main/java/kong/unirest/MultipartBody.java | 3 --- .../java/BehaviorTests/FormPostingTest.java | 24 +++++++++++++++++++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java b/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java index 8241ab44b..910dc5ec2 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java @@ -118,11 +118,6 @@ public MultipartBody contentType(String mimeType) { return this; } - @Override - public Collection getParts() { - return new ArrayList<>(parameters); - } - @Override public MultipartBody mode(String value) { this.mode = MultipartMode.valueOf(value); diff --git a/unirest/src/main/java/kong/unirest/MultipartBody.java b/unirest/src/main/java/kong/unirest/MultipartBody.java index fa47dc6a3..317855d72 100644 --- a/unirest/src/main/java/kong/unirest/MultipartBody.java +++ b/unirest/src/main/java/kong/unirest/MultipartBody.java @@ -137,9 +137,6 @@ public interface MultipartBody extends HttpRequest, Body { */ MultipartBody contentType(String mimeType); - - Collection getParts(); - /** * Set the Apache Mode. * @param value the string value of the mode diff --git a/unirest/src/test/java/BehaviorTests/FormPostingTest.java b/unirest/src/test/java/BehaviorTests/FormPostingTest.java index 1dc4e832b..4f343052f 100644 --- a/unirest/src/test/java/BehaviorTests/FormPostingTest.java +++ b/unirest/src/test/java/BehaviorTests/FormPostingTest.java @@ -267,6 +267,30 @@ public void testMultipeInputStreams() throws FileNotFoundException { .assertParam("name", "this is another test"); } + @Test + public void multiPartInputStreamAsFile() throws FileNotFoundException { + Unirest.post(MockServer.POST) + .field("foo", "bar") + .field("filecontents", new FileInputStream(rezFile("/image.jpg")), "image.jpg") + .asObject(RequestCapture.class) + .getBody() + .assertParam("foo", "bar") + .getFileByInput("filecontents") + .assertFileType(ContentType.APPLICATION_OCTET_STREAM) + .assertFileName("image.jpg"); + } + + @Test + public void multiPartInputStream() throws FileNotFoundException { + Unirest.post(MockServer.POST) + .field("foo", "bar") + .field("filecontents", new FileInputStream(rezFile("/test")), ContentType.WILDCARD) + .asObject(RequestCapture.class) + .getBody() + .assertParam("foo", "bar") + .assertParam("filecontents", "This is a test file"); + } + @Test public void postFileWithContentType() throws Exception { File file = getImageFile(); From a0af99060bb2af6a9ed7051fb2e1a8754782a49c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 23 Feb 2019 16:31:45 -0600 Subject: [PATCH 0467/1769] more tests. rm superfluous methods --- .../kong/unirest/HttpRequestMultiPart.java | 6 ---- .../main/java/kong/unirest/MultipartBody.java | 7 ---- .../java/BehaviorTests/FormPostingTest.java | 35 ++++++++++++++----- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java b/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java index 910dc5ec2..674c1f6dd 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java @@ -118,12 +118,6 @@ public MultipartBody contentType(String mimeType) { return this; } - @Override - public MultipartBody mode(String value) { - this.mode = MultipartMode.valueOf(value); - return this; - } - @Override public MultipartBody mode(MultipartMode value) { this.mode = value; diff --git a/unirest/src/main/java/kong/unirest/MultipartBody.java b/unirest/src/main/java/kong/unirest/MultipartBody.java index 317855d72..462ec7366 100644 --- a/unirest/src/main/java/kong/unirest/MultipartBody.java +++ b/unirest/src/main/java/kong/unirest/MultipartBody.java @@ -137,13 +137,6 @@ public interface MultipartBody extends HttpRequest, Body { */ MultipartBody contentType(String mimeType); - /** - * Set the Apache Mode. - * @param value the string value of the mode - * @return The same MultipartBody - * */ - MultipartBody mode(String value); - /** * Set the Apache Mode. * @param value the value of the mode diff --git a/unirest/src/test/java/BehaviorTests/FormPostingTest.java b/unirest/src/test/java/BehaviorTests/FormPostingTest.java index 4f343052f..3bd86c20a 100644 --- a/unirest/src/test/java/BehaviorTests/FormPostingTest.java +++ b/unirest/src/test/java/BehaviorTests/FormPostingTest.java @@ -124,10 +124,7 @@ public void testMultipartInputStreamContentTypeAsync() throws Exception { @Test public void testMultipartByteContentType() throws Exception { - final InputStream stream = new FileInputStream(rezFile("/image.jpg")); - final byte[] bytes = new byte[stream.available()]; - stream.read(bytes); - stream.close(); + final byte[] bytes = getFileBytes("/image.jpg"); Unirest.post(MockServer.POST) .field("boot","boot") @@ -140,10 +137,7 @@ public void testMultipartByteContentType() throws Exception { @Test public void testMultipartByteContentTypeAsync() throws Exception { - final InputStream stream = new FileInputStream(rezFile("/test")); - final byte[] bytes = new byte[stream.available()]; - stream.read(bytes); - stream.close(); + final byte[] bytes = getFileBytes("/test"); Unirest.post(MockServer.POST) .field("name", "Mark") @@ -280,6 +274,19 @@ public void multiPartInputStreamAsFile() throws FileNotFoundException { .assertFileName("image.jpg"); } + @Test + public void passFileAsByteArray() { + Unirest.post(MockServer.POST) + .field("foo", "bar") + .field("filecontents", getFileBytes("/image.jpg"), ContentType.IMAGE_JPEG, "image.jpg") + .asObject(RequestCapture.class) + .getBody() + .assertParam("foo", "bar") + .getFileByInput("filecontents") + .assertFileType(ContentType.IMAGE_JPEG) + .assertFileName("image.jpg"); + } + @Test public void multiPartInputStream() throws FileNotFoundException { Unirest.post(MockServer.POST) @@ -456,4 +463,16 @@ public void canSetModeToStrictForLegacySupport() { private File getImageFile() { return rezFile("/image.jpg"); } + + private byte[] getFileBytes(String s) { + try { + final InputStream stream = new FileInputStream(rezFile(s)); + final byte[] bytes = new byte[stream.available()]; + stream.read(bytes); + stream.close(); + return bytes; + }catch (IOException e){ + throw new RuntimeException(e); + } + } } From 56d516ef8b82cb7537a2b8b20a6e7fd295c429cb Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 23 Feb 2019 16:42:08 -0600 Subject: [PATCH 0468/1769] simplify headers --- unirest/src/main/java/kong/unirest/Path.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/unirest/src/main/java/kong/unirest/Path.java b/unirest/src/main/java/kong/unirest/Path.java index 143055648..a35094580 100644 --- a/unirest/src/main/java/kong/unirest/Path.java +++ b/unirest/src/main/java/kong/unirest/Path.java @@ -65,9 +65,9 @@ public void queryString(String name, Object value) { queryString.append("?"); } try { - queryString.append(URLEncoder.encode(name)); + queryString.append(URLEncoder.encode(name, "UTF-8")); if(value != null) { - queryString.append("=").append(URLEncoder.encode(value.toString(), "UTF-8")); + queryString.append("=").append(URLEncoder.encode(String.valueOf(value), "UTF-8")); } } catch (UnsupportedEncodingException e) { throw new UnirestException(e); @@ -78,13 +78,7 @@ public void queryString(String name, Object value) { public void queryString(Map parameters) { if (parameters != null) { for (Map.Entry param : parameters.entrySet()) { - if (param.getValue() instanceof String || param.getValue() instanceof Number || param.getValue() instanceof Boolean || param.getValue() == null) { - queryString(param.getKey(), param.getValue()); - } else { - throw new UnirestException("Parameter \"" + param.getKey() + - "\" can't be sent with a GET request because of type: " - + param.getValue().getClass().getName()); - } + queryString(param.getKey(), param.getValue()); } } } From 9de1a781ac620ae49c37012e99571dd1af2ba516 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 23 Feb 2019 16:52:05 -0600 Subject: [PATCH 0469/1769] rm the old raw responses. It was always a little weird and we have better ways to get the raw response now --- .../main/java/kong/unirest/BaseResponse.java | 9 -------- .../main/java/kong/unirest/BasicResponse.java | 7 ------ .../main/java/kong/unirest/EmptyResponse.java | 7 ------ .../main/java/kong/unirest/FileResponse.java | 7 ------ .../main/java/kong/unirest/HttpResponse.java | 22 ------------------- .../main/java/kong/unirest/JsonResponse.java | 12 ---------- .../java/kong/unirest/ObjectResponse.java | 10 --------- .../java/kong/unirest/StringResponse.java | 9 -------- .../test/java/BehaviorTests/AsJsonTest.java | 2 +- .../src/test/java/BehaviorTests/BddTest.java | 11 ++++------ .../src/test/java/kong/unirest/TestUtil.java | 8 ------- 11 files changed, 5 insertions(+), 99 deletions(-) diff --git a/unirest/src/main/java/kong/unirest/BaseResponse.java b/unirest/src/main/java/kong/unirest/BaseResponse.java index 055f6f746..7d8bcb651 100644 --- a/unirest/src/main/java/kong/unirest/BaseResponse.java +++ b/unirest/src/main/java/kong/unirest/BaseResponse.java @@ -25,7 +25,6 @@ package kong.unirest; -import java.io.InputStream; import java.util.Optional; import java.util.function.Consumer; import java.util.function.Function; @@ -58,9 +57,6 @@ public Headers getHeaders() { return headers; } - @Override - public abstract InputStream getRawBody(); - @Override public abstract T getBody(); @@ -74,11 +70,6 @@ public V mapBody(Function func){ return func.apply(getBody()); } - @Override - public V mapRawBody(Function func) { - return func.apply(getRawBody()); - } - protected void setParsingException(String originalBody, RuntimeException e) { parsingerror = Optional.of(new UnirestParsingException(originalBody, e)); } diff --git a/unirest/src/main/java/kong/unirest/BasicResponse.java b/unirest/src/main/java/kong/unirest/BasicResponse.java index b7650967f..b94ce12f9 100644 --- a/unirest/src/main/java/kong/unirest/BasicResponse.java +++ b/unirest/src/main/java/kong/unirest/BasicResponse.java @@ -25,8 +25,6 @@ package kong.unirest; -import java.io.InputStream; - class BasicResponse extends BaseResponse { private final T body; @@ -35,11 +33,6 @@ public BasicResponse(RawResponse httpResponse, T body) { this.body = body; } - @Override - public InputStream getRawBody() { - return null; - } - @Override public T getBody() { return body; diff --git a/unirest/src/main/java/kong/unirest/EmptyResponse.java b/unirest/src/main/java/kong/unirest/EmptyResponse.java index fceee91e2..f7dd4f27e 100644 --- a/unirest/src/main/java/kong/unirest/EmptyResponse.java +++ b/unirest/src/main/java/kong/unirest/EmptyResponse.java @@ -25,18 +25,11 @@ package kong.unirest; -import java.io.InputStream; - class EmptyResponse extends BaseResponse { EmptyResponse(RawResponse response) { super(response); } - @Override - public InputStream getRawBody() { - return null; - } - @Override public Empty getBody() { return null; diff --git a/unirest/src/main/java/kong/unirest/FileResponse.java b/unirest/src/main/java/kong/unirest/FileResponse.java index 0c9de5c0f..6073a040c 100644 --- a/unirest/src/main/java/kong/unirest/FileResponse.java +++ b/unirest/src/main/java/kong/unirest/FileResponse.java @@ -25,10 +25,8 @@ package kong.unirest; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -47,11 +45,6 @@ public FileResponse(RawResponse r, String path) { } } - @Override - public InputStream getRawBody() { - return new ByteArrayInputStream(new byte[0]); - } - @Override public File getBody() { return body; diff --git a/unirest/src/main/java/kong/unirest/HttpResponse.java b/unirest/src/main/java/kong/unirest/HttpResponse.java index 2c93ee71c..57200bda8 100644 --- a/unirest/src/main/java/kong/unirest/HttpResponse.java +++ b/unirest/src/main/java/kong/unirest/HttpResponse.java @@ -25,7 +25,6 @@ package kong.unirest; -import java.io.InputStream; import java.util.Optional; import java.util.function.Consumer; import java.util.function.Function; @@ -51,16 +50,6 @@ public interface HttpResponse { */ Headers getHeaders(); - /** - * This method is a lie. You never get the real raw response from it - * you only get a copy, or worse, the body transformed BACK to a stream - * If you want to use raw content use the new functional methods - * @deprecated this method is redundant and not the original stream. Use the functional asObject methods. - * @return a copy of the input stream - * */ - @Deprecated - InputStream getRawBody(); - /** * @return the body */ @@ -79,17 +68,6 @@ public interface HttpResponse { */ V mapBody(Function func); - /** - * This method is a lie. You never get the real raw response from it - * you only get a copy, or worse, the body transformed BACK to a stream - * If you want to use raw content use the new functional methods - * @param func a function to map a inputstream to a new body - * @param the return type - * @return the return type - */ - @Deprecated - V mapRawBody(Function func); - /** * If the response was a 200-series response. Invoke this consumer * can be chained with ifFailure diff --git a/unirest/src/main/java/kong/unirest/JsonResponse.java b/unirest/src/main/java/kong/unirest/JsonResponse.java index 787db9acf..1f6d6c720 100644 --- a/unirest/src/main/java/kong/unirest/JsonResponse.java +++ b/unirest/src/main/java/kong/unirest/JsonResponse.java @@ -25,13 +25,10 @@ package kong.unirest; -import java.io.ByteArrayInputStream; -import java.io.InputStream; import java.util.Objects; public class JsonResponse extends BaseResponse { private JsonNode node; - private InputStream errorStream; protected JsonResponse(RawResponse response) { super(response); @@ -52,19 +49,10 @@ private JsonNode toJsonNode(String json) { return new JsonNode(json); } catch (RuntimeException e) { super.setParsingException(json, e); - errorStream = new ByteArrayInputStream(json.getBytes()); return null; } } - @Override - public InputStream getRawBody() { - if (errorStream != null) { - return errorStream; - } - return new ByteArrayInputStream(node.toString().getBytes()); - } - @Override public JsonNode getBody() { return node; diff --git a/unirest/src/main/java/kong/unirest/ObjectResponse.java b/unirest/src/main/java/kong/unirest/ObjectResponse.java index 55a10771f..034f8d77c 100644 --- a/unirest/src/main/java/kong/unirest/ObjectResponse.java +++ b/unirest/src/main/java/kong/unirest/ObjectResponse.java @@ -25,8 +25,6 @@ package kong.unirest; -import java.io.ByteArrayInputStream; -import java.io.InputStream; import java.util.Optional; import java.util.function.Function; @@ -67,14 +65,6 @@ private T getBody(String b, Function func){ } } - @Override - public InputStream getRawBody() { - if(body == null){ - return new ByteArrayInputStream(new byte[0]); - } - return new ByteArrayInputStream(om.writeValue(body).getBytes()); - } - @Override public T getBody() { return body; diff --git a/unirest/src/main/java/kong/unirest/StringResponse.java b/unirest/src/main/java/kong/unirest/StringResponse.java index ed7ea5f4b..3ac78d207 100644 --- a/unirest/src/main/java/kong/unirest/StringResponse.java +++ b/unirest/src/main/java/kong/unirest/StringResponse.java @@ -25,10 +25,6 @@ package kong.unirest; -import java.io.ByteArrayInputStream; -import java.io.InputStream; - - public class StringResponse extends BaseResponse { private String body; @@ -37,11 +33,6 @@ public StringResponse(RawResponse response, String encoding) { body = response.getContentAsString(encoding); } - @Override - public InputStream getRawBody() { - return new ByteArrayInputStream(body.getBytes()); - } - @Override public String getBody() { return body; diff --git a/unirest/src/test/java/BehaviorTests/AsJsonTest.java b/unirest/src/test/java/BehaviorTests/AsJsonTest.java index 79b68d82f..0040cf3cf 100644 --- a/unirest/src/test/java/BehaviorTests/AsJsonTest.java +++ b/unirest/src/test/java/BehaviorTests/AsJsonTest.java @@ -94,7 +94,7 @@ public void failureToReturnValidJsonWillResultInAnEmptyNodeAsync() { .asJsonAsync(new MockCallback<>(this, response -> { assertEquals(400, response.getStatus()); assertNull(response.getBody()); - assertEquals("You did something bad", TestUtil.toString(response.getRawBody())); + assertEquals(null, response.getBody()); assertEquals("org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]", response.getParsingError().get().getMessage()); diff --git a/unirest/src/test/java/BehaviorTests/BddTest.java b/unirest/src/test/java/BehaviorTests/BddTest.java index 9f2cbc1f2..6bfa81f9e 100644 --- a/unirest/src/test/java/BehaviorTests/BddTest.java +++ b/unirest/src/test/java/BehaviorTests/BddTest.java @@ -25,21 +25,18 @@ package BehaviorTests; -import kong.unirest.HttpResponse; -import kong.unirest.JacksonObjectMapper; -import kong.unirest.JsonNode; -import kong.unirest.Unirest; +import kong.unirest.*; import org.junit.After; import org.junit.Before; +import java.io.IOException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import static kong.unirest.TestUtil.read; import static org.junit.Assert.*; public class BddTest { - private JacksonObjectMapper objectMapper = new JacksonObjectMapper(); + private static JacksonObjectMapper objectMapper = new JacksonObjectMapper(); private CountDownLatch lock; private boolean status; private String fail; @@ -86,6 +83,6 @@ public void asyncFail(String message) { public static RequestCapture parse(HttpResponse response) { assertEquals(200, response.getStatus()); - return read(response, RequestCapture.class); + return objectMapper.readValue(response.getBody().toString(), RequestCapture.class); } } diff --git a/unirest/src/test/java/kong/unirest/TestUtil.java b/unirest/src/test/java/kong/unirest/TestUtil.java index 241174ea3..77a4d975b 100644 --- a/unirest/src/test/java/kong/unirest/TestUtil.java +++ b/unirest/src/test/java/kong/unirest/TestUtil.java @@ -121,14 +121,6 @@ public static T read(String o, Class as){ } } - public static T read(HttpResponse r, Class as) { - try { - return om.readValue(r.getRawBody(), as); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - public static void assertBasicAuth(String raw, String username, String password) { assertNotNull("Authorization Header Missing", raw); String credentials = raw.replace("Basic ",""); From dbde9c07c8ebd429cd7e44757d0310d53b7a6711 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 23 Feb 2019 17:02:36 -0600 Subject: [PATCH 0470/1769] rename some apache stuff so its clear what its for --- .../src/main/java/kong/unirest/apache/ApacheAsyncClient.java | 2 +- .../{HttpDeleteWithBody.java => ApacheDeleteWithBody.java} | 4 ++-- .../{NoRedirects.java => ApacheNoRedirectStrategy.java} | 2 +- .../{HttpPatchWithBody.java => ApachePatchWithBody.java} | 4 ++-- unirest/src/main/java/kong/unirest/apache/RequestPrep.java | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) rename unirest/src/main/java/kong/unirest/apache/{HttpDeleteWithBody.java => ApacheDeleteWithBody.java} (92%) rename unirest/src/main/java/kong/unirest/apache/{NoRedirects.java => ApacheNoRedirectStrategy.java} (96%) rename unirest/src/main/java/kong/unirest/apache/{HttpPatchWithBody.java => ApachePatchWithBody.java} (93%) diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java index e5e657dfc..9416643b9 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java @@ -65,7 +65,7 @@ public ApacheAsyncClient(Config config) { ab.useSystemProperties(); } if (!config.getFollowRedirects()) { - ab.setRedirectStrategy(new NoRedirects()); + ab.setRedirectStrategy(new ApacheNoRedirectStrategy()); } if (!config.getEnabledCookieManagement()) { ab.disableCookieManagement(); diff --git a/unirest/src/main/java/kong/unirest/apache/HttpDeleteWithBody.java b/unirest/src/main/java/kong/unirest/apache/ApacheDeleteWithBody.java similarity index 92% rename from unirest/src/main/java/kong/unirest/apache/HttpDeleteWithBody.java rename to unirest/src/main/java/kong/unirest/apache/ApacheDeleteWithBody.java index 71058b6a3..13cb5d246 100644 --- a/unirest/src/main/java/kong/unirest/apache/HttpDeleteWithBody.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheDeleteWithBody.java @@ -29,14 +29,14 @@ import java.net.URI; -class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase { +class ApacheDeleteWithBody extends HttpEntityEnclosingRequestBase { private static final String METHOD_NAME = "DELETE"; public String getMethod() { return METHOD_NAME; } - HttpDeleteWithBody(final String uri) { + ApacheDeleteWithBody(final String uri) { super(); setURI(URI.create(uri)); } diff --git a/unirest/src/main/java/kong/unirest/apache/NoRedirects.java b/unirest/src/main/java/kong/unirest/apache/ApacheNoRedirectStrategy.java similarity index 96% rename from unirest/src/main/java/kong/unirest/apache/NoRedirects.java rename to unirest/src/main/java/kong/unirest/apache/ApacheNoRedirectStrategy.java index b613d79be..7cc0db43f 100644 --- a/unirest/src/main/java/kong/unirest/apache/NoRedirects.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheNoRedirectStrategy.java @@ -31,7 +31,7 @@ import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.protocol.HttpContext; -class NoRedirects implements RedirectStrategy { +class ApacheNoRedirectStrategy implements RedirectStrategy { @Override public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) { return false; diff --git a/unirest/src/main/java/kong/unirest/apache/HttpPatchWithBody.java b/unirest/src/main/java/kong/unirest/apache/ApachePatchWithBody.java similarity index 93% rename from unirest/src/main/java/kong/unirest/apache/HttpPatchWithBody.java rename to unirest/src/main/java/kong/unirest/apache/ApachePatchWithBody.java index 67e6f0f41..1399c4dbf 100644 --- a/unirest/src/main/java/kong/unirest/apache/HttpPatchWithBody.java +++ b/unirest/src/main/java/kong/unirest/apache/ApachePatchWithBody.java @@ -29,14 +29,14 @@ import java.net.URI; -class HttpPatchWithBody extends HttpEntityEnclosingRequestBase { +class ApachePatchWithBody extends HttpEntityEnclosingRequestBase { private static final String METHOD_NAME = "PATCH"; public String getMethod() { return METHOD_NAME; } - HttpPatchWithBody(final String uri) { + ApachePatchWithBody(final String uri) { super(); setURI(URI.create(uri)); } diff --git a/unirest/src/main/java/kong/unirest/apache/RequestPrep.java b/unirest/src/main/java/kong/unirest/apache/RequestPrep.java index a5db126b9..64b318166 100644 --- a/unirest/src/main/java/kong/unirest/apache/RequestPrep.java +++ b/unirest/src/main/java/kong/unirest/apache/RequestPrep.java @@ -52,8 +52,8 @@ class RequestPrep { FACTORIES.put(HttpMethod.GET, HttpGet::new); FACTORIES.put(HttpMethod.POST, HttpPost::new); FACTORIES.put(HttpMethod.PUT, HttpPut::new); - FACTORIES.put(HttpMethod.DELETE, HttpDeleteWithBody::new); - FACTORIES.put(HttpMethod.PATCH, HttpPatchWithBody::new); + FACTORIES.put(HttpMethod.DELETE, ApacheDeleteWithBody::new); + FACTORIES.put(HttpMethod.PATCH, ApachePatchWithBody::new); FACTORIES.put(HttpMethod.OPTIONS, HttpOptions::new); FACTORIES.put(HttpMethod.HEAD, HttpHead::new); } From e5dd265582ac47de4d5dc75c45b3d9147392a5b9 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 23 Feb 2019 18:22:55 -0600 Subject: [PATCH 0471/1769] update upgrade guide --- UPGRADE_GUIDE.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/UPGRADE_GUIDE.md b/UPGRADE_GUIDE.md index f75bdfc41..77aab5b64 100644 --- a/UPGRADE_GUIDE.md +++ b/UPGRADE_GUIDE.md @@ -1,12 +1,21 @@ -## Upgrading to Open Unirest 3.0 from previous versions +## Upgrading to Unirest 2.0 from previous versions ### Package -Inspired by the "Java Spark" project, all classes are now in the ```unirest``` package. This project only has 45 files, it really doesn't need anything more complicated than that. +All main classes are now in the ```kong.unirest``` package. Classes related to the underlying Apache Http client that powers unirest are kept in ```kong.unirest.apache``` This project doesn't have many files, it really doesn't need anything more complicated than that. + +### Removed Methods and Java Requirements +* Java 8: Java 8 is now required for Unirest due to extensive lambda support. +* ```.asBinary()``` and ```.getRawResponse()``` methods have been removed. These have been replaced by consumer methods which allow you to read the InputStream directly and not a copy. (see ```HttpRequest::thenConsume(Consumer consumer)``` +* Removal of all Apache classes in the non-config interfaces. These have ben replaced by Unirest native interfaces. + Typically these interfaces are very similar to the older Apache classes and so updating shouldn't be a problem. + + ### Configuration -Previous versions of unirest had configuration split across several different places. Sometimes it was done on ```Unirest```, sometimes it was done on ```Option```, sometimes it was somewhere else. +Previous versions of unirest had configuration split across several different places. Sometimes it was done on ```Unirest```, sometimes it was done on ```Option```, sometimes it was somewhere else. All configuration is now done through ```Unirest.config()``` + #### Unirest.config() Unirest config allows easy access to build a configuration just like you would build a request: @@ -15,7 +24,7 @@ Unirest config allows easy access to build a configuration just like you would b .socketTimeout(500) .connectTimeout(1000) .concurrency(10, 5) - .proxy(new HttpHost("https://proxy")) + .proxy(new Proxy("https://proxy")) .setDefaultHeader("Accept", "application/json") .followRedirects(false) .enableCookieManagement(false) From 5beb2205429f3d4075f8fc3a422fc668b26a1d80 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 23 Feb 2019 18:31:19 -0600 Subject: [PATCH 0472/1769] flatten changelog for the merger --- CHANGELOG.md | 115 +++-------------------------------------------- UPGRADE_GUIDE.md | 2 +- 2 files changed, 8 insertions(+), 109 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b07ba646..dfa7c31f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,8 @@ -## 3.3.05 +## 2.0.00 * Add a noop response type when you just don't care about the body. ```java HttpResponse re = Unirest.get("http://no.body.knows").asEmpty(); ``` - -## 3.3.04 * Add the ability to follow a paged response by providing a lambda for the response type and one for getting the next page. It will stop once the next link is null or empty. * The PagedList has handy dandy methods to pass consumers to all success and failure responses. ```java @@ -14,22 +12,11 @@ PagedList result = Unirest.get("http://and.pagey") r -> r.getHeaders().getFirst("nextPage") ); ``` - - -## 3.3.03 -* Pulled isSuccess() up to the response interface so it can be used and enjoyed by everyone. - -## 3.3.02 * Add the ability to make requests to non-standard web methods for things like WebDAV, SVN, or other horrible things. ```java Unirest.request("CHEESE", "http://some.cheesy.thing") .asString(); ``` - -## 3.3.00 -* Slight breaking change with regard to accessing Apache specific classes via the config - * getClient and getAsyncClient return the Unirest containers for clients. You can still get to the Apache client through that for now but this is also deprecated. Eventually Unirest will make Apache just one of several modules. - * Apache client wrappers are now package local. * Add support for overriding the default expected encoding both on a per-request basis and as a default in the config. ```java // Changing the default from UTF-8 for all requests @@ -42,14 +29,7 @@ Unirest.get("http://some.file.with.windows.encoding/file.txt") .responseEncoding("windows-1250") .asString(); ``` - -## 3.2.06 * access headers in order - -## 3.2.05 -* UnirestInstance is autoclosable - -## 3.2.04 * Adds chainable ifSuccess and ifFailure consumer methods to the response. Now you can handle the response like ```java Unirest.get("https://localhost/somewhere") @@ -57,20 +37,11 @@ Unirest.get("http://some.file.with.windows.encoding/file.txt") .ifSuccess(r -> log.info("Yippy!")) .ifFailure(r -> log.error("Booo")); ``` - -## 3.2.03 * Allow the configuration of header suppliers. ```java Unirest.config().setDefaultHeader("trace", () -> value); ``` - -## 3.2.02 -* distinguish between set and add for default headers. - -## 3.2.01 * add method to replace a header rather than append to it. - -## 3.2.00 * Now you can stream the results into a file! * It doesn't need to be a file either. It could be any result. Unirest will shove it in a file. ```java @@ -78,35 +49,13 @@ File file = Unirest.get("https://someplace/file.tar.gz") .asFile("/local/storage/file.tar.gz") .getBody(); ``` - -## 3.1.02 * When encountering a parsing error with asObject or asJson capture the body in a UnirestParsingException -* New BETA feature asFile method to stream the response into a file. - -## 3.1.01 * Detect if the async client has stopped for some reason and construct a new one. This one may be different from the one that was originally configured so we need to add a way to configure a supplier for clients rather than a direct client. - -## 3.1.00 -* Deprecate methods that expose Apache. In the 4 line we will start supporting other clients. Primarily the java one supplied in Java9 (apache will still exist for 8-) * Add several functional methods for dealing with the raw response before the connection is closed. This is nice for large responses. - -## 3.0.04 -* Parsing handler should capture unirest exceptions just like other exceptions. - -## 3.0.03 * Support Java system properties for proxies via ```Unirest.config().useSystemProperties(true);``` * https://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html - -## 3.0.02 -* Add support for the authenticated proxies to the async client - -## 3.0.01 * Support for authenticated proxies with ```Unirest.config().proxy("proxy.server.host", 80, "username","password")``` - -## 3.0.00 -* This is a **major** release with several **breaking changes** which (other than the namespace change) should ONLY impact you if you are using some of Unirests more advanced features or custom configurations. -* The maven artifact has changed to ```open-unirest-java``` -* The namespace has been shortened to just **unirest** (inspired by Java Spark) +* The namespace has been shortened to just **kong.unirest** (inspired by Java Spark) * The configuration system has been completely redone. Previously it was scattered across several classes and was entirely static. The new system has instances and supports multiple configurations. See the UPGRADE_GUIDE.md for details. * Start accessing the config with ```Unirest.config()``` * Almost everything is now fronted by interfaces, this makes testing easier. @@ -115,29 +64,10 @@ File file = Unirest.get("https://someplace/file.tar.gz") * option no longer supports body (per http spec) * Accept and ContentType are now 1st class headers in the builder (```Unirest.get(path).accept("application/json")```) * Major internal fixes so that which builder operations were available when is consistent. - -## 2.5.03 * Lazy init the HttpClients so they don't get in the way of setting custom clients. - -## 2.5.02 -* More safety for issue #41 - -## 2.5.01 -* Fix Issue #41: possible init error in HttpClient under heavy load - -## 2.5.00 -* Extracted Interface for HttpResponse to make testing easier - -## 2.4.02 * Updated org.json dependency - -## 2.4.01 * Add async versions of generic type methods - -## 2.4.00 -* Issue #19 Add support for generic types with object mappers. - -## 2.3.00 +* Add support for generic types with object mappers. * Add support for the JSON Patch standard (RFC6902) https://tools.ietf.org/html/rfc6902 ```java Unirest.jsonPatch(MockServer.PATCH) @@ -149,54 +79,23 @@ File file = Unirest.get("https://someplace/file.tar.gz") .copy("/original/location", "/new/location") .asJson(); ``` - -## 2.2.12 * Add optional flag overload to ```Unirest.shutDown(false)```. The flag indicates if the various Options should be cleared. This only applies to options that could survive a shutdown. The HttpClients and thread monitors will still be discarded. - -## 2.2.11 * Change default MultiPart mode to BROWSER_COMPATIBLE in order to support unicode filenames. Clients wishing to use the legacy mode can set it to STRICT. This should not be a problem for most users as few servers today lack support for unicode file names. Issue #35 - -## 2.2.10 * Update Apache dependencies https://archive.apache.org/dist/httpcomponents/httpclient/RELEASE_NOTES-4.5.x.txt - -## 2.2.08 - * add an option to disable cookie management with ```Options.enableCookieManagement(false)```. - * In the future ignoring cookies will be the default. - -## 2.2.07 -* Fix init error - -## 2.2.06 +* add an option to disable cookie management with ```Options.enableCookieManagement(false)```. +* In the future ignoring cookies will be the default. * added ability to turn off redirect following with ```Options.followRedirects(boolean enable)``` (default is true) - -## 2.2.04 * Add ```.charset(Charset charset)``` to POSTS (both form and body) * Clean up some ambiguous methods in form posting. This may be a breaking change for a very small number of users. There are better methods for handling these cases. * Added the ability to add HttpRequestInterceptors to the client. Though ``` Options.addInterceptor(new TestInterceptor()); ``` - -## 2.2.03 -* Expose the ```Options.init()``` method to restore the system to a fresh start after a shutdown. * ```Unirest.shutdown()``` no longer throws a checked exception - -## 2.2.02 * Fix NPE with null bodies from HEAD requests. - -## 2.2.01 * Quitly consume and close InputStreams that may not be complete. - -## 2.2.00 * Major refactoring of how response objects are built. This internalizes HttpClientHelper which was previously public but not needed if you were using the library in in the expected way. This refactoring sets up the library for future work to extend the number of supported formats and for greater expression in the methods for those formats. * Additional of functional map methods to HttpResponse so you don't have to stop the flow for further transformations. -* Update the org.json dependency -* Fixed issue with achor hashes in URLs (#17) -* Fixed NPE in passing args as maps (#20) - -## 2.1.01 +* Fixed issue with achor hashes in URLs +* Fixed NPE in passing args as maps * JSON parsing errors no longer just throw out of ```asJson``` but are captured and can be inspected via ```HttpResponse::getParsingError```. This resolves the fact that most API's do not return valid JSON for non-200 status codes. * Return CompletableFuture rather that boring old Futures for all async methods. - - -## 2.0.02 * UnirestException is no longer checked -* Namespaces have been migrated to new **io.gitgub.openunirest** namespace * Thread leak in Options fixed diff --git a/UPGRADE_GUIDE.md b/UPGRADE_GUIDE.md index 77aab5b64..72cc2fe01 100644 --- a/UPGRADE_GUIDE.md +++ b/UPGRADE_GUIDE.md @@ -8,7 +8,7 @@ All main classes are now in the ```kong.unirest``` package. Classes related to t * ```.asBinary()``` and ```.getRawResponse()``` methods have been removed. These have been replaced by consumer methods which allow you to read the InputStream directly and not a copy. (see ```HttpRequest::thenConsume(Consumer consumer)``` * Removal of all Apache classes in the non-config interfaces. These have ben replaced by Unirest native interfaces. Typically these interfaces are very similar to the older Apache classes and so updating shouldn't be a problem. - + ### Configuration From 5583fd6484526493b3ab6f73d301de0f90a0db32 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 24 Feb 2019 07:23:58 -0600 Subject: [PATCH 0473/1769] move package to kong --- README.md | 12 ++++++------ pom.xml | 2 +- unirest/pom.xml | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8b9307602..eee44c5d1 100644 --- a/README.md +++ b/README.md @@ -8,26 +8,26 @@ We are looking for official maintainers, check out issue [#252](https://github.c # Unirest for Java [![Build Status][travis-image]][travis-url] [![Build Status](https://travis-ci.org/OpenUnirest/unirest-java.svg?branch=master)](https://travis-ci.org/OpenUnirest/unirest-java) -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.openunirest/open-unirest-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.openunirest/open-unirest-java) +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.kong/open-unirest-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.kong/open-unirest-java) [![DepShield Badge](https://depshield.sonatype.org/badges/OpenUnirest/unirest-java/depshield.svg)](https://depshield.github.io) -[![Javadocs](http://www.javadoc.io/badge/io.github.openunirest/open-unirest-java.svg)](http://www.javadoc.io/doc/io.github.openunirest/open-unirest-java) +[![Javadocs](http://www.javadoc.io/badge/com.kong/open-unirest-java.svg)](http://www.javadoc.io/doc/com.kong/open-unirest-java) ## About This Repository This repo is an updated, maintained, and independent fork of the original Mashape/Kong Unirest-Java project. That project is no longer being maintained so this project was set up to keep it alive. ##### See the [UPGRADE_GUIDE](UPGRADE_GUIDE.md) for differences between this library and last kong release. -## Install With [Maven](https://mvnrepository.com/artifact/io.github.openunirest/open-unirest-java) +## Install With [Maven](https://mvnrepository.com/artifact/com.kong/open-unirest-java) ``` - io.github.openunirest + com.kong open-unirest-java 3.3.03 ``` #### Note on 2.x -Because 3.0 made several very not backwards compatible changes the artifactID was changed. The 2.0 line is still available [Here](https://mvnrepository.com/artifact/io.github.openunirest/unirest-java). Security patches and major defects will still be patched on it until 2020. +Because 3.0 made several very not backwards compatible changes the artifactID was changed. The 2.0 line is still available [Here](https://mvnrepository.com/artifact/com.kong/unirest-java). Security patches and major defects will still be patched on it until 2020. ## Features @@ -158,7 +158,7 @@ will send a request with a body of ## Advanced Object Mapping with Jackson, GSON, JAX-B or others Before an `asObject(Class)` or a `.body(Object)` invokation, is necessary to provide a custom implementation of the `ObjectMapper` interface. This should be done only the first time, as the instance of the ObjectMapper will be shared globally. -Open Unirest offers a few plug-ins implementing popular object mappers like Jackson and Gson. See [mvn central](https://mvnrepository.com/artifact/io.github.openunirest) for details. +Open Unirest offers a few plug-ins implementing popular object mappers like Jackson and Gson. See [mvn central](https://mvnrepository.com/artifact/com.kong) for details. For example, serializing Json from\to Object using the popular Jackson ObjectMapper takes only few lines of code. diff --git a/pom.xml b/pom.xml index be53333a6..b16000b35 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - io.github.openunirest + com.kong unirest-java-parent pom 3.3.06-SNAPSHOT diff --git a/unirest/pom.xml b/unirest/pom.xml index 85ebbac50..916a94653 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -2,12 +2,12 @@ 4.0.0 - io.github.openunirest + com.kong unirest-java-parent 3.3.06-SNAPSHOT - open-unirest-java + unirest-java jar From 6a5ac6cd2c5f369d60502b22e1c608bfdb26968b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 24 Feb 2019 10:19:09 -0600 Subject: [PATCH 0474/1769] move more things to Kong --- CONTRIBUTING.md | 4 +-- LICENSE | 3 +-- README.md | 18 ++++++------- pom.xml | 8 +++--- .../test/java/BehaviorTests/MockServer.java | 25 ------------------- 5 files changed, 14 insertions(+), 44 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4337fcd6c..49eb51099 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ -# Contributing to Open Unirest +# Contributing to Unirest :+1::tada: First off, thanks for taking the time to contribute! :tada::+1: @@ -30,5 +30,5 @@ Include details about your configuration and environment: * All code should follow style guidelines enforced by the checkstyle and other static analysis. * All code should have tests. * Unit tests - * Behavioral tests (see https://github.com/OpenUnirest/unirest-java/tree/master/src/test/java/BehaviorTests) + * Behavioral tests (see https://github.com/Kong/unirest-java/tree/master/src/test/java/BehaviorTests) * You should have run verify before submitting and the PR needs to have passed TravisCI before being merged. diff --git a/LICENSE b/LICENSE index 8b23035b1..68781a6f2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,6 @@ The MIT License -Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java. -All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018. + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013-2019. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/README.md b/README.md index eee44c5d1..f2d5fcd91 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,13 @@ -<<<<<<< HEAD # Unirest for Java -======= -# Call for Maintainers We are looking for official maintainers, check out issue [#252](https://github.com/Kong/unirest-java/issues/252) # Unirest for Java [![Build Status][travis-image]][travis-url] -[![Build Status](https://travis-ci.org/OpenUnirest/unirest-java.svg?branch=master)](https://travis-ci.org/OpenUnirest/unirest-java) +[![Build Status](https://travis-ci.org/Kong/unirest-java.svg?branch=master)](https://travis-ci.org/Kong/unirest-java) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.kong/open-unirest-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.kong/open-unirest-java) -[![DepShield Badge](https://depshield.sonatype.org/badges/OpenUnirest/unirest-java/depshield.svg)](https://depshield.github.io) -[![Javadocs](http://www.javadoc.io/badge/com.kong/open-unirest-java.svg)](http://www.javadoc.io/doc/com.kong/open-unirest-java) +[![DepShield Badge](https://depshield.sonatype.org/badges/Kong/unirest-java/depshield.svg)](https://depshield.github.io) +[![Javadocs](http://www.javadoc.io/badge/com.kong/unirest-java.svg)](http://www.javadoc.io/doc/com.kong/unirest-java) ## About This Repository This repo is an updated, maintained, and independent fork of the original Mashape/Kong Unirest-Java project. That project is no longer being maintained so this project was set up to keep it alive. @@ -21,14 +18,13 @@ This repo is an updated, maintained, and independent fork of the original Mashap ``` com.kong - open-unirest-java - 3.3.03 + unirest-java + 2.0.00 ``` -#### Note on 2.x -Because 3.0 made several very not backwards compatible changes the artifactID was changed. The 2.0 line is still available [Here](https://mvnrepository.com/artifact/com.kong/unirest-java). Security patches and major defects will still be patched on it until 2020. - +#### Upgrading from Previous Versions +See the [Upgrade Guide](UPGRADE_GUIDE.md) ## Features diff --git a/pom.xml b/pom.xml index b16000b35..cdb8bf230 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ 3.3.06-SNAPSHOT unirest Simplified, lightweight HTTP client library. - http://github.com/OpenUnirest/ + http://github.com/Kong/unirest-java/ @@ -28,9 +28,9 @@ - https://github.com/OpenUnirest/unirest-java - scm:git:git@github.com:OpenUnirest/unirest-java.git - scm:git:git@github.com:OpenUnirest/unirest-java.git + https://github.com/Kong/unirest-java + scm:git:git@github.com:Kong/unirest-java.git + scm:git:git@github.com:Kong/unirest-java.git HEAD diff --git a/unirest/src/test/java/BehaviorTests/MockServer.java b/unirest/src/test/java/BehaviorTests/MockServer.java index 18be8ffc9..d63e4ccc1 100644 --- a/unirest/src/test/java/BehaviorTests/MockServer.java +++ b/unirest/src/test/java/BehaviorTests/MockServer.java @@ -23,31 +23,6 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/* -The MIT License - -Copyright (c) 2013 OpenUnirest (http://github.com/OpenUnirest) - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - package BehaviorTests; From 6f15b0b77b70567294e798fa95b2ff1307b616ac Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 3 Mar 2019 17:15:50 -0600 Subject: [PATCH 0475/1769] update group to com.konghq --- pom.xml | 2 +- unirest/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index cdb8bf230..7458f0b62 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - com.kong + com.konghq unirest-java-parent pom 3.3.06-SNAPSHOT diff --git a/unirest/pom.xml b/unirest/pom.xml index 916a94653..52b772d5a 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -2,7 +2,7 @@ 4.0.0 - com.kong + com.konghq unirest-java-parent 3.3.06-SNAPSHOT From 45bf1a4e154f6f108eaf21a65e18532cf9542be6 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 3 Mar 2019 17:20:31 -0600 Subject: [PATCH 0476/1769] reset the version to 2 --- pom.xml | 2 +- unirest/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 7458f0b62..82458371a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 3.3.06-SNAPSHOT + 2.0.00-SNAPSHOT unirest Simplified, lightweight HTTP client library. http://github.com/Kong/unirest-java/ diff --git a/unirest/pom.xml b/unirest/pom.xml index 52b772d5a..61149c788 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 3.3.06-SNAPSHOT + 2.0.00-SNAPSHOT unirest-java From 5539d78d65ccc38a180739801a4dc50b6a9dd924 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 3 Mar 2019 17:21:38 -0600 Subject: [PATCH 0477/1769] [maven-release-plugin] prepare release v2.0.00 --- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 82458371a..54b38a9ad 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.0.00-SNAPSHOT + 2.0.00 unirest Simplified, lightweight HTTP client library. http://github.com/Kong/unirest-java/ @@ -31,7 +31,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - HEAD + v2.0.00 diff --git a/unirest/pom.xml b/unirest/pom.xml index 61149c788..abc20f927 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.0.00-SNAPSHOT + 2.0.00 unirest-java From fe5cd63295f066cc67207e0901f1bb966481be3f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 3 Mar 2019 17:21:46 -0600 Subject: [PATCH 0478/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 54b38a9ad..cf66a3760 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.0.00 + 2.0.01-SNAPSHOT unirest Simplified, lightweight HTTP client library. http://github.com/Kong/unirest-java/ @@ -31,7 +31,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - v2.0.00 + HEAD diff --git a/unirest/pom.xml b/unirest/pom.xml index abc20f927..17731511d 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.0.00 + 2.0.01-SNAPSHOT unirest-java From 5981811bdceca3960c7f19ad94c9673e32c6dcc0 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 4 Mar 2019 07:43:31 -0600 Subject: [PATCH 0479/1769] ignore this test for now until we can find a surefire way to create this error --- unirest/src/test/java/BehaviorTests/CallbackFutureTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/unirest/src/test/java/BehaviorTests/CallbackFutureTest.java b/unirest/src/test/java/BehaviorTests/CallbackFutureTest.java index 9e274d283..7d81c0a10 100644 --- a/unirest/src/test/java/BehaviorTests/CallbackFutureTest.java +++ b/unirest/src/test/java/BehaviorTests/CallbackFutureTest.java @@ -27,6 +27,7 @@ import kong.unirest.Unirest; import kong.unirest.NoopCallback; +import org.junit.Ignore; import org.junit.Test; import static kong.unirest.MockCallback.json; @@ -59,7 +60,7 @@ public void onSuccessSupplyCallback() throws Exception { assertAsync(); } - @Test(timeout = 5000) + @Test(timeout = 5000) @Ignore public void onFailure() throws Exception { Unirest.get("http://localhost:0000") .asJsonAsync(json(this)) From 92b1f2f0bf196cb51c94513828df99a927030d2e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 5 Mar 2019 14:53:43 -0600 Subject: [PATCH 0480/1769] [maven-release-plugin] prepare release v2.0.01 --- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index cf66a3760..c1a7b9aa9 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.0.01-SNAPSHOT + 2.0.01 unirest Simplified, lightweight HTTP client library. http://github.com/Kong/unirest-java/ @@ -31,7 +31,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - HEAD + v2.0.01 diff --git a/unirest/pom.xml b/unirest/pom.xml index 17731511d..75f179633 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.0.01-SNAPSHOT + 2.0.01 unirest-java From 50e1531f87131afd7658f507b8c75a429fcb941c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 5 Mar 2019 14:53:49 -0600 Subject: [PATCH 0481/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index c1a7b9aa9..2b327c527 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.0.01 + 2.0.02-SNAPSHOT unirest Simplified, lightweight HTTP client library. http://github.com/Kong/unirest-java/ @@ -31,7 +31,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - v2.0.01 + HEAD diff --git a/unirest/pom.xml b/unirest/pom.xml index 75f179633..cdfe05778 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.0.01 + 2.0.02-SNAPSHOT unirest-java From a5fd40911c704d9f35172a95d6fe1bdd5cb6f6e5 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 5 Mar 2019 15:34:43 -0600 Subject: [PATCH 0482/1769] update readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f2d5fcd91..aadfbf651 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ We are looking for official maintainers, check out issue [#252](https://github.c # Unirest for Java [![Build Status][travis-image]][travis-url] [![Build Status](https://travis-ci.org/Kong/unirest-java.svg?branch=master)](https://travis-ci.org/Kong/unirest-java) -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.kong/open-unirest-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.kong/open-unirest-java) +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.kong/unirest-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.kong/unirest-java) [![DepShield Badge](https://depshield.sonatype.org/badges/Kong/unirest-java/depshield.svg)](https://depshield.github.io) [![Javadocs](http://www.javadoc.io/badge/com.kong/unirest-java.svg)](http://www.javadoc.io/doc/com.kong/unirest-java) @@ -14,12 +14,12 @@ This repo is an updated, maintained, and independent fork of the original Mashap ##### See the [UPGRADE_GUIDE](UPGRADE_GUIDE.md) for differences between this library and last kong release. -## Install With [Maven](https://mvnrepository.com/artifact/com.kong/open-unirest-java) +## Install With [Maven](https://mvnrepository.com/artifact/com.kong/unirest-java) ``` com.kong unirest-java - 2.0.00 + 2.0.01 ``` @@ -154,7 +154,7 @@ will send a request with a body of ## Advanced Object Mapping with Jackson, GSON, JAX-B or others Before an `asObject(Class)` or a `.body(Object)` invokation, is necessary to provide a custom implementation of the `ObjectMapper` interface. This should be done only the first time, as the instance of the ObjectMapper will be shared globally. -Open Unirest offers a few plug-ins implementing popular object mappers like Jackson and Gson. See [mvn central](https://mvnrepository.com/artifact/com.kong) for details. +Unirest offers a few plug-ins implementing popular object mappers like Jackson and Gson. See [mvn central](https://mvnrepository.com/artifact/com.kong) for details. For example, serializing Json from\to Object using the popular Jackson ObjectMapper takes only few lines of code. From 034c16b04bb84a799f9c1484d0e14eec9bcfd393 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 5 Mar 2019 18:32:30 -0600 Subject: [PATCH 0483/1769] Update README.md --- README.md | 58 +++---------------------------------------------------- 1 file changed, 3 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index aadfbf651..6eccddac0 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,13 @@ # Unirest for Java -We are looking for official maintainers, check out issue [#252](https://github.com/Kong/unirest-java/issues/252) - -# Unirest for Java [![Build Status][travis-image]][travis-url] - [![Build Status](https://travis-ci.org/Kong/unirest-java.svg?branch=master)](https://travis-ci.org/Kong/unirest-java) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.kong/unirest-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.kong/unirest-java) [![DepShield Badge](https://depshield.sonatype.org/badges/Kong/unirest-java/depshield.svg)](https://depshield.github.io) [![Javadocs](http://www.javadoc.io/badge/com.kong/unirest-java.svg)](http://www.javadoc.io/doc/com.kong/unirest-java) +We are looking for official maintainers, check out issue [#252](https://github.com/Kong/unirest-java/issues/252) + + ## About This Repository This repo is an updated, maintained, and independent fork of the original Mashape/Kong Unirest-Java project. That project is no longer being maintained so this project was set up to keep it alive. @@ -55,57 +54,6 @@ You can use Maven by including the library: ``` -There are dependencies for Unirest-Java, these should be already installed, and they are as follows: - -```xml - - org.apache.httpcomponents - httpclient - 4.3.6 - - - org.apache.httpcomponents - httpasyncclient - 4.0.2 - - - org.apache.httpcomponents - httpmime - 4.3.6 - - - org.json - json - 20140107 - -``` - -If you would like to run tests, also add the following dependency along with the others: - -```xml - - junit - junit - 4.12 - test - - - commons-io - commons-io - 2.4 - test - -``` - -### Without Maven - -Alternatively if you don't use Maven, you can directly include the JAR file in the classpath: http://oss.sonatype.org/content/repositories/releases/com/mashape/unirest/unirest-java/1.4.9/unirest-java-1.4.9.jar - -Don't forget to also install the dependencies ([`org.json`](http://www.json.org/java/), [`httpclient 4.3.6`](http://hc.apache.org/downloads.cgi), [`httpmime 4.3.6`](http://hc.apache.org/downloads.cgi), [`httpasyncclient 4.0.2`](http://hc.apache.org/downloads.cgi)) in the classpath too. - -There is also a way to generate a Unirest-Java JAR file that already includes the required dependencies, but you will need Maven to generate it. Follow the instructions at http://blog.mashape.com/post/69117323931/installing-unirest-java-with-the-maven-assembly-plugin ->>>>>>> bf4e031140464930bc05f3a8e2d9f3f02a72d551 - ## Creating Request So you're probably wondering how using Unirest makes creating requests in Java easier, here is a basic POST request that will explain everything: From 4f16e4c6e243ea0968473cdb54a2f5451af4ba27 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 5 Mar 2019 18:34:05 -0600 Subject: [PATCH 0484/1769] Update README.md --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 6eccddac0..a63b7ebe1 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,7 @@ # Unirest for Java [![Build Status](https://travis-ci.org/Kong/unirest-java.svg?branch=master)](https://travis-ci.org/Kong/unirest-java) -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.kong/unirest-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.kong/unirest-java) -[![DepShield Badge](https://depshield.sonatype.org/badges/Kong/unirest-java/depshield.svg)](https://depshield.github.io) -[![Javadocs](http://www.javadoc.io/badge/com.kong/unirest-java.svg)](http://www.javadoc.io/doc/com.kong/unirest-java) +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.konghq/unirest-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.kong/unirest-java) We are looking for official maintainers, check out issue [#252](https://github.com/Kong/unirest-java/issues/252) From cf86775bebc75bb42be614c8da66580d3c99eb54 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 6 Mar 2019 07:31:53 -0600 Subject: [PATCH 0485/1769] closes #158 properly handling + in path params. --- .../src/test/java/BehaviorTests/PathParamTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/unirest/src/test/java/BehaviorTests/PathParamTest.java b/unirest/src/test/java/BehaviorTests/PathParamTest.java index b04cffb49..81a646871 100644 --- a/unirest/src/test/java/BehaviorTests/PathParamTest.java +++ b/unirest/src/test/java/BehaviorTests/PathParamTest.java @@ -32,6 +32,18 @@ public class PathParamTest extends BddTest { + @Test + public void properlyDealsWithPlusInPAth() { + String param = "jack+4@email.com"; + + Unirest.get(MockServer.PASSED_PATH_PARAM) + .routeParam("param", param) + .asObject(RequestCapture.class) + .getBody() + .assertUrl("http://localhost:4567/get/jack%2B4%40email.com/passed") + .assertPathParam(param); + } + @Test public void testPathParameters() { Unirest.get(MockServer.HOST + "/{method}") From b276a587a123d024934c273c1da053ccd0c9f6a1 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 6 Mar 2019 07:48:48 -0600 Subject: [PATCH 0486/1769] closes #151 Confirm Content-Length is set on requests with bodies --- unirest/src/test/java/BehaviorTests/HeaderTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/unirest/src/test/java/BehaviorTests/HeaderTest.java b/unirest/src/test/java/BehaviorTests/HeaderTest.java index bf6b67bb3..592ff836f 100644 --- a/unirest/src/test/java/BehaviorTests/HeaderTest.java +++ b/unirest/src/test/java/BehaviorTests/HeaderTest.java @@ -39,6 +39,15 @@ public class HeaderTest extends BddTest { private String value = "one"; + @Test + public void contentLengthIsSetWithBodies() { + Unirest.post(MockServer.POST) + .body("do do do do") + .asObject(RequestCapture.class) + .getBody() + .assertHeader("Content-Length", "11"); + } + @Test public void testHeadersOnGetRequests() { Unirest.get(MockServer.GET) From 5898c653b96f849a5e0f8b9d98c0d2eb3f3599b5 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 6 Mar 2019 08:03:31 -0600 Subject: [PATCH 0487/1769] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a63b7ebe1..86f913671 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ [![Build Status](https://travis-ci.org/Kong/unirest-java.svg?branch=master)](https://travis-ci.org/Kong/unirest-java) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.konghq/unirest-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.kong/unirest-java) +[![Javadocs](http://www.javadoc.io/badge/com.konghq/unirest-java.svg)](http://www.javadoc.io/doc/com.kong/unirest-java) + We are looking for official maintainers, check out issue [#252](https://github.com/Kong/unirest-java/issues/252) From 7f5b74ff62863ea49fafec63b932e2a869cd8610 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 6 Mar 2019 08:03:43 -0600 Subject: [PATCH 0488/1769] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 86f913671..227b08d67 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.org/Kong/unirest-java.svg?branch=master)](https://travis-ci.org/Kong/unirest-java) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.konghq/unirest-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.kong/unirest-java) -[![Javadocs](http://www.javadoc.io/badge/com.konghq/unirest-java.svg)](http://www.javadoc.io/doc/com.kong/unirest-java) +[![Javadocs](http://www.javadoc.io/badge/com.konghq/unirest-java.svg)](http://www.javadoc.io/doc/com.konghq/unirest-java) We are looking for official maintainers, check out issue [#252](https://github.com/Kong/unirest-java/issues/252) From de8a0ebd1242765b43c0abfbb343dcd3ab7fdc99 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 6 Mar 2019 18:16:41 -0600 Subject: [PATCH 0489/1769] closes pr #249. Add route params as a map --- CHANGELOG.md | 9 +++++++- .../main/java/kong/unirest/BaseRequest.java | 6 +++++ .../main/java/kong/unirest/HttpRequest.java | 12 ++++++++++ unirest/src/main/java/kong/unirest/Path.java | 4 ++++ .../test/java/BehaviorTests/MockServer.java | 6 +++-- .../java/BehaviorTests/PathParamTest.java | 22 +++++++++++++++---- .../java/BehaviorTests/RequestCapture.java | 12 ++++++---- 7 files changed, 60 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfa7c31f1..a7d841d2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,11 @@ -## 2.0.00 +# 2.0.02 +* Pass route params as a map +```java +Unirest.get("http://example") + .routeParam(ImmutableMap.of("cheese", "cheddar", "age", 42)) +``` + +## 2.0.01: Legacy + Merger With OpenUnirest Fork * Add a noop response type when you just don't care about the body. ```java HttpResponse re = Unirest.get("http://no.body.knows").asEmpty(); diff --git a/unirest/src/main/java/kong/unirest/BaseRequest.java b/unirest/src/main/java/kong/unirest/BaseRequest.java index 9e5ce5b21..c225e5557 100644 --- a/unirest/src/main/java/kong/unirest/BaseRequest.java +++ b/unirest/src/main/java/kong/unirest/BaseRequest.java @@ -60,6 +60,12 @@ public R routeParam(String name, String value) { return (R)this; } + @Override + public R routeParam(Map params) { + url.param(params); + return (R)this; + } + @Override public R basicAuth(String username, String password) { header("Authorization", "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes())); diff --git a/unirest/src/main/java/kong/unirest/HttpRequest.java b/unirest/src/main/java/kong/unirest/HttpRequest.java index f9872a03f..de0502814 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequest.java +++ b/unirest/src/main/java/kong/unirest/HttpRequest.java @@ -47,6 +47,18 @@ public interface HttpRequest { */ R routeParam(String name, String value); + /** + * add a route param map that replaces the matching {name} + * For example routeParam(Map.of("name", "fred")) will replace {name} in + * https://localhost/users/{user} + * to + * https://localhost/users/fred + * + * @param params a map of path params + * @return this request builder + */ + R routeParam(Map params); + /** * Basic auth credentials * @param username the username diff --git a/unirest/src/main/java/kong/unirest/Path.java b/unirest/src/main/java/kong/unirest/Path.java index a35094580..f93d57fc2 100644 --- a/unirest/src/main/java/kong/unirest/Path.java +++ b/unirest/src/main/java/kong/unirest/Path.java @@ -39,6 +39,10 @@ class Path { this.url = url; } + public void param(Map params) { + params.forEach((key, value) -> param(key, String.valueOf(value))); + } + public void param(String name, String value) { Matcher matcher = Pattern.compile("\\{" + name + "\\}").matcher(url); int count = 0; diff --git a/unirest/src/test/java/BehaviorTests/MockServer.java b/unirest/src/test/java/BehaviorTests/MockServer.java index d63e4ccc1..587ba292d 100644 --- a/unirest/src/test/java/BehaviorTests/MockServer.java +++ b/unirest/src/test/java/BehaviorTests/MockServer.java @@ -63,7 +63,8 @@ public class MockServer { public static final String GZIP = HOST + "/gzip"; public static final String PATCH = HOST + "/patch"; public static final String INVALID_REQUEST = HOST + "/invalid"; - public static final String PASSED_PATH_PARAM = GET + "/{param}/passed"; + public static final String PASSED_PATH_PARAM = GET + "/{params}/passed"; + public static final String PASSED_PATH_PARAM_MULTI = PASSED_PATH_PARAM + "/{another}"; public static final String CHEESE = HOST + "/cheese"; public static final String ALTGET = "http://127.0.0.1:" + PORT + "/get"; @@ -94,7 +95,8 @@ public static void reset(){ get("/nobody", MockServer::nobody); head("/get", MockServer::jsonResponse); put("/post", MockServer::jsonResponse); - get("/get/:p/passed", MockServer::jsonResponse); + get("/get/:params/passed", MockServer::jsonResponse); + get("/get/:params/passed/:another", MockServer::jsonResponse); get("/proxy", MockServer::proxiedResponse); get("/binary", MockServer::file); get("/paged", MockServer::paged); diff --git a/unirest/src/test/java/BehaviorTests/PathParamTest.java b/unirest/src/test/java/BehaviorTests/PathParamTest.java index 81a646871..4715573bb 100644 --- a/unirest/src/test/java/BehaviorTests/PathParamTest.java +++ b/unirest/src/test/java/BehaviorTests/PathParamTest.java @@ -25,6 +25,7 @@ package BehaviorTests; +import com.google.common.collect.ImmutableMap; import kong.unirest.Unirest; import kong.unirest.UnirestException; import org.junit.Test; @@ -32,16 +33,29 @@ public class PathParamTest extends BddTest { + @Test + public void canAddRouteParamsAsMap() { + String param = "Hamberders"; + + Unirest.get(MockServer.PASSED_PATH_PARAM_MULTI) + .routeParam(ImmutableMap.of("params", param, "another", 42)) + .asObject(RequestCapture.class) + .getBody() + .assertUrl("http://localhost:4567/get/Hamberders/passed/42") + .assertPathParam("params", param) + .assertPathParam("another", "42"); + } + @Test public void properlyDealsWithPlusInPAth() { String param = "jack+4@email.com"; Unirest.get(MockServer.PASSED_PATH_PARAM) - .routeParam("param", param) + .routeParam("params", param) .asObject(RequestCapture.class) .getBody() .assertUrl("http://localhost:4567/get/jack%2B4%40email.com/passed") - .assertPathParam(param); + .assertPathParam("params", param); } @Test @@ -102,10 +116,10 @@ public void illigalPathParams() { String value = "/?ЊЯЯ"; Unirest.get(MockServer.PASSED_PATH_PARAM) - .routeParam("param", value) + .routeParam("params", value) .asObject(RequestCapture.class) .getBody() .assertUrl("http://localhost:4567/get/%2F%3F%D0%8A%D0%AF%D0%AF/passed") - .assertPathParam(value); + .assertPathParam("params", value); } } diff --git a/unirest/src/test/java/BehaviorTests/RequestCapture.java b/unirest/src/test/java/BehaviorTests/RequestCapture.java index f36919ad0..4ece8430d 100644 --- a/unirest/src/test/java/BehaviorTests/RequestCapture.java +++ b/unirest/src/test/java/BehaviorTests/RequestCapture.java @@ -53,7 +53,7 @@ public class RequestCapture { public String url; public String queryString; public HttpMethod method; - public String param; + public HashMap routeParams = new HashMap<>(); public String contentType; public JsonPatch jsonPatches; public Integer status; @@ -69,11 +69,15 @@ public RequestCapture(Request req) { method = HttpMethod.valueOf(req.requestMethod()); writeHeaders(req); writeQuery(req); - param = req.params("p"); + populateParams(req); contentType = req.contentType(); status = 200; } + private void populateParams(Request req) { + routeParams.putAll(req.params()); + } + public void writeBody(Request req) { if(Strings.nullToEmpty(req.contentType()).equals(CONTENT_TYPE)){ String body = req.body(); @@ -200,8 +204,8 @@ public RequestCapture asserMethod(HttpMethod get) { return this; } - public RequestCapture assertPathParam(String value) { - assertEquals(value, param); + public RequestCapture assertPathParam(String name, String value) { + assertEquals(value, routeParams.get(":" + name)); return this; } From a05ac96ea9f3da7dffaaae9e2cf7d33b93835ebe Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 6 Mar 2019 18:30:58 -0600 Subject: [PATCH 0490/1769] [maven-release-plugin] prepare release v2.0.02 --- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 2b327c527..f1a122f20 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.0.02-SNAPSHOT + 2.0.02 unirest Simplified, lightweight HTTP client library. http://github.com/Kong/unirest-java/ @@ -31,7 +31,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - HEAD + v2.0.02 diff --git a/unirest/pom.xml b/unirest/pom.xml index cdfe05778..b182c2f3f 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.0.02-SNAPSHOT + 2.0.02 unirest-java From 1f15dc6d21479c3287ebdf5f7a663fb2b2d71e2c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 6 Mar 2019 18:31:08 -0600 Subject: [PATCH 0491/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index f1a122f20..f4a3f31f1 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.0.02 + 2.0.03-SNAPSHOT unirest Simplified, lightweight HTTP client library. http://github.com/Kong/unirest-java/ @@ -31,7 +31,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - v2.0.02 + HEAD diff --git a/unirest/pom.xml b/unirest/pom.xml index b182c2f3f..2fe69ea2a 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.0.02 + 2.0.03-SNAPSHOT unirest-java From 556ccfbc1b6ce9021b370cd9ebec28fecce51462 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 7 Mar 2019 06:41:25 -0600 Subject: [PATCH 0492/1769] closes #190 make sure the GZIPInputStream gets closed --- .../kong/unirest/apache/ApacheResponse.java | 62 ++++++++++--------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheResponse.java b/unirest/src/main/java/kong/unirest/apache/ApacheResponse.java index 7fc304b82..25a9cf94f 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheResponse.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheResponse.java @@ -38,23 +38,23 @@ class ApacheResponse extends RawResponseBase { private final HttpResponse r; - public ApacheResponse(HttpResponse r, Config config){ + public ApacheResponse(HttpResponse r, Config config) { super(config); this.r = r; } @Override - public int getStatus(){ + public int getStatus() { return r.getStatusLine().getStatusCode(); } @Override - public String getStatusText(){ + public String getStatusText() { return r.getStatusLine().getReasonPhrase(); } @Override - public Headers getHeaders(){ + public Headers getHeaders() { Headers h = new Headers(); Stream.of(r.getAllHeaders()) .forEachOrdered(e -> h.add(e.getName(), e.getValue())); @@ -62,10 +62,10 @@ public Headers getHeaders(){ } @Override - public InputStream getContent(){ + public InputStream getContent() { try { HttpEntity entity = r.getEntity(); - if(entity != null) { + if (entity != null) { return entity.getContent(); } return new ByteArrayInputStream(new byte[0]); @@ -76,7 +76,7 @@ public InputStream getContent(){ @Override public byte[] getContentAsBytes() { - if(!hasContent()){ + if (!hasContent()) { return new byte[0]; } try { @@ -99,7 +99,7 @@ public String getContentAsString() { @Override public String getContentAsString(String charset) { - if(!hasContent()){ + if (!hasContent()) { return ""; } try { @@ -111,14 +111,14 @@ public String getContentAsString(String charset) { } private String getCharset(String charset) { - if(charset == null || charset.trim().isEmpty()){ + if (charset == null || charset.trim().isEmpty()) { return getCharSet(); } return charset; } @Override - public InputStreamReader getContentReader(){ + public InputStreamReader getContentReader() { return new InputStreamReader(getContent()); } @@ -129,9 +129,9 @@ public boolean hasContent() { @Override public String getContentType() { - if(hasContent()){ + if (hasContent()) { Header contentType = r.getEntity().getContentType(); - if(contentType != null){ + if (contentType != null) { return contentType.getValue(); } } @@ -140,9 +140,9 @@ public String getContentType() { @Override public String getEncoding() { - if(hasContent()){ + if (hasContent()) { Header contentType = r.getEntity().getContentEncoding(); - if(contentType != null){ + if (contentType != null) { return contentType.getValue(); } } @@ -150,23 +150,27 @@ public String getEncoding() { } private static byte[] getBytes(InputStream is) throws IOException { - int len; - int size = 1024; - byte[] buf; - - if (is instanceof ByteArrayInputStream) { - size = is.available(); - buf = new byte[size]; - len = is.read(buf, 0, size); - } else { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - buf = new byte[size]; - while ((len = is.read(buf, 0, size)) != -1) { - bos.write(buf, 0, len); + try { + int len; + int size = 1024; + byte[] buf; + + if (is instanceof ByteArrayInputStream) { + size = is.available(); + buf = new byte[size]; + len = is.read(buf, 0, size); + } else { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + buf = new byte[size]; + while ((len = is.read(buf, 0, size)) != -1) { + bos.write(buf, 0, len); + } + buf = bos.toByteArray(); } - buf = bos.toByteArray(); + return buf; + } finally { + is.close(); } - return buf; } private static boolean isGzipped(String value) { From f4341e2cb99a8d0e24df247f14c6d7675afafd9d Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 7 Mar 2019 07:02:32 -0600 Subject: [PATCH 0493/1769] closes #129 support disabling compression --- unirest/src/main/java/kong/unirest/Config.java | 10 ++++++++++ .../kong/unirest/apache/ApacheAsyncClient.java | 2 +- .../java/kong/unirest/apache/ApacheClient.java | 5 ++++- .../java/kong/unirest/apache/RequestPrep.java | 6 ++++-- .../src/test/java/BehaviorTests/GZipTest.java | 17 +++++++++++++++-- .../src/test/java/kong/unirest/ConfigTest.java | 8 ++++++++ 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/unirest/src/main/java/kong/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java index ce7926612..51a1c42bf 100644 --- a/unirest/src/main/java/kong/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -65,6 +65,7 @@ public class Config { private String defaultResponseEncoding = StandardCharsets.UTF_8.name(); private Function asyncBuilder = ApacheAsyncClient::new; private Function clientBuilder = ApacheClient::new; + private boolean requestCompressionOn = true; public Config() { setDefaults(); @@ -80,6 +81,7 @@ private void setDefaults(){ maxPerRoute = DEFAULT_MAX_PER_ROUTE; followRedirects = true; cookieManagement = true; + requestCompressionOn = true; } /** @@ -498,4 +500,12 @@ public boolean useSystemProperties(){ public String getDefaultResponseEncoding() { return defaultResponseEncoding; } + + public boolean isRequestCompressionOn() { + return requestCompressionOn; + } + + public void requestCompression(boolean value) { + this.requestCompressionOn = value; + } } diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java index 9416643b9..b5c6356f4 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java @@ -101,7 +101,7 @@ public CompletableFuture> request( Objects.requireNonNull(callback); - HttpUriRequest requestObj = new RequestPrep(request, true).prepare(); + HttpUriRequest requestObj = new RequestPrep(request, config, true).prepare(); client.execute(requestObj, new FutureCallback() { @Override diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java index ede8cb331..0724c7693 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java @@ -55,6 +55,9 @@ public ApacheClient(Config config) { .setConnectionManager(manager) .useSystemProperties(); + if(!config.isRequestCompressionOn()) { + cb.disableContentCompression(); + } if(config.useSystemProperties()){ cb.useSystemProperties(); } @@ -79,7 +82,7 @@ public ApacheClient(HttpClient httpClient, Config config, PoolingHttpClientConne @Override public HttpResponse request(HttpRequest request, Function> transformer) { - HttpRequestBase requestObj = new RequestPrep(request, false).prepare(); + HttpRequestBase requestObj = new RequestPrep(request, config, false).prepare(); try { org.apache.http.HttpResponse execute = client.execute(requestObj); diff --git a/unirest/src/main/java/kong/unirest/apache/RequestPrep.java b/unirest/src/main/java/kong/unirest/apache/RequestPrep.java index 64b318166..af4df6d5e 100644 --- a/unirest/src/main/java/kong/unirest/apache/RequestPrep.java +++ b/unirest/src/main/java/kong/unirest/apache/RequestPrep.java @@ -45,6 +45,7 @@ class RequestPrep { private static final String USER_AGENT = "unirest-java/3.0.00"; private static final Map> FACTORIES; private final HttpRequest request; + private Config config; private final boolean async; static { @@ -58,8 +59,9 @@ class RequestPrep { FACTORIES.put(HttpMethod.HEAD, HttpHead::new); } - RequestPrep(HttpRequest request, boolean async) { + RequestPrep(HttpRequest request, Config config, boolean async) { this.request = request; + this.config = config; this.async = async; } @@ -75,7 +77,7 @@ private HttpRequestBase getHttpRequestBase() { if (!request.getHeaders().containsKey(USER_AGENT_HEADER)) { request.header(USER_AGENT_HEADER, USER_AGENT); } - if (!request.getHeaders().containsKey(ACCEPT_ENCODING_HEADER)) { + if (!request.getHeaders().containsKey(ACCEPT_ENCODING_HEADER) && config.isRequestCompressionOn()) { request.header(ACCEPT_ENCODING_HEADER, "gzip"); } diff --git a/unirest/src/test/java/BehaviorTests/GZipTest.java b/unirest/src/test/java/BehaviorTests/GZipTest.java index b57181f47..34083ef28 100644 --- a/unirest/src/test/java/BehaviorTests/GZipTest.java +++ b/unirest/src/test/java/BehaviorTests/GZipTest.java @@ -35,7 +35,8 @@ public void testGzip() { .queryString("zipme", "up") .asObject(RequestCapture.class) .getBody() - .assertParam("zipme", "up"); + .assertParam("zipme", "up") + .assertHeader("Accept-Encoding","gzip"); } @Test @@ -45,6 +46,18 @@ public void testGzipAsync() throws Exception { .asObjectAsync(RequestCapture.class) .get() .getBody() - .assertParam("zipme", "up"); + .assertParam("zipme", "up") + .assertHeader("Accept-Encoding","gzip"); + } + + @Test + public void canDisableGZip() throws Exception { + Unirest.config().requestCompression(false); + + Unirest.get(MockServer.GET) + .asObjectAsync(RequestCapture.class) + .get() + .getBody() + .assertNoHeader("Accept-Encoding"); } } diff --git a/unirest/src/test/java/kong/unirest/ConfigTest.java b/unirest/src/test/java/kong/unirest/ConfigTest.java index f52f01020..2a5183ef4 100644 --- a/unirest/src/test/java/kong/unirest/ConfigTest.java +++ b/unirest/src/test/java/kong/unirest/ConfigTest.java @@ -215,6 +215,14 @@ public void provideYourOwnClientBuilder() { assertSame(cli, config.getClient()); } + @Test + public void canDisableGZipencoding() { + assertTrue(config.isRequestCompressionOn()); + config.requestCompression(false); + assertFalse(config.isRequestCompressionOn()); + + } + @Test public void provideYourOwnAsyncClientBuilder() { AsyncClient cli = mock(AsyncClient.class); From 992c7ce1757db775c5f0f4afdfde707e1dcb991d Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 7 Mar 2019 08:42:25 -0600 Subject: [PATCH 0494/1769] follow builder pattern and add doc --- unirest/src/main/java/kong/unirest/Config.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/unirest/src/main/java/kong/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java index 51a1c42bf..a7e576bf0 100644 --- a/unirest/src/main/java/kong/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -329,6 +329,18 @@ public Config useSystemProperties(boolean value) { return this; } + /** + * Turn on or off requesting all content as compressed. (GZIP encoded) + * Default is true + * + * @param value a bool is its true or not. + * @return this config object + */ + public Config requestCompression(boolean value) { + this.requestCompressionOn = value; + return this; + } + /** * Set the default encoding that will be used for serialization into Strings. * The default-default is UTF-8 @@ -504,8 +516,4 @@ public String getDefaultResponseEncoding() { public boolean isRequestCompressionOn() { return requestCompressionOn; } - - public void requestCompression(boolean value) { - this.requestCompressionOn = value; - } } From 2f552816f4c5e722f569d7ecd960afe25cde0a6a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 7 Mar 2019 08:43:42 -0600 Subject: [PATCH 0495/1769] fix javadoc warning --- unirest/src/main/java/kong/unirest/AsyncClient.java | 1 + 1 file changed, 1 insertion(+) diff --git a/unirest/src/main/java/kong/unirest/AsyncClient.java b/unirest/src/main/java/kong/unirest/AsyncClient.java index 5dce7de34..4439f6f75 100644 --- a/unirest/src/main/java/kong/unirest/AsyncClient.java +++ b/unirest/src/main/java/kong/unirest/AsyncClient.java @@ -33,6 +33,7 @@ public interface AsyncClient { /** + * @param the underlying client * @return the underlying client if this instance is wrapping another library (like Apache). */ T getClient(); From e7e7bea026b7e73ba725dbc366e457ea883d99fa Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 7 Mar 2019 12:58:03 -0600 Subject: [PATCH 0496/1769] update changelog --- CHANGELOG.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7d841d2d..79849b301 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,11 @@ -# 2.0.02 +## 2.0.03 +* Make sure the GzipInputStream gets closed. +* Support disabling compressed results which is asked for by default +```java +Unirest.config().requestCompression(false); +``` + +## 2.0.02 * Pass route params as a map ```java Unirest.get("http://example") From 1a8d63945aca4ced9880318fc23e41ca02d38d09 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 7 Mar 2019 12:59:05 -0600 Subject: [PATCH 0497/1769] [maven-release-plugin] prepare release v2.0.03 --- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index f4a3f31f1..91c6dd57a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.0.03-SNAPSHOT + 2.0.03 unirest Simplified, lightweight HTTP client library. http://github.com/Kong/unirest-java/ @@ -31,7 +31,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - HEAD + v2.0.03 diff --git a/unirest/pom.xml b/unirest/pom.xml index 2fe69ea2a..3ce2596b3 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.0.03-SNAPSHOT + 2.0.03 unirest-java From 741402664747cf8f048611f2a428dfcecc09a943 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 7 Mar 2019 12:59:12 -0600 Subject: [PATCH 0498/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 91c6dd57a..e11f344d2 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.0.03 + 2.0.04-SNAPSHOT unirest Simplified, lightweight HTTP client library. http://github.com/Kong/unirest-java/ @@ -31,7 +31,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - v2.0.03 + HEAD diff --git a/unirest/pom.xml b/unirest/pom.xml index 3ce2596b3..efb848620 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.0.03 + 2.0.04-SNAPSHOT unirest-java From d3ed1d20cdfb014e8bd6eb8acb1ba01ae4865078 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 7 Mar 2019 18:58:28 -0600 Subject: [PATCH 0499/1769] update changelog --- CHANGELOG.md | 118 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 110 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79849b301..068d9a9ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,6 @@ ```java Unirest.config().requestCompression(false); ``` - ## 2.0.02 * Pass route params as a map ```java @@ -12,11 +11,15 @@ Unirest.get("http://example") .routeParam(ImmutableMap.of("cheese", "cheddar", "age", 42)) ``` -## 2.0.01: Legacy + Merger With OpenUnirest Fork +# The following were releases from the merged OpenUnirest project + +### OpenUnirest:3.3.05 * Add a noop response type when you just don't care about the body. ```java HttpResponse re = Unirest.get("http://no.body.knows").asEmpty(); ``` + +### OpenUnirest:3.3.04 * Add the ability to follow a paged response by providing a lambda for the response type and one for getting the next page. It will stop once the next link is null or empty. * The PagedList has handy dandy methods to pass consumers to all success and failure responses. ```java @@ -26,11 +29,22 @@ PagedList result = Unirest.get("http://and.pagey") r -> r.getHeaders().getFirst("nextPage") ); ``` + + +### OpenUnirest:3.3.03 +* Pulled isSuccess() up to the response interface so it can be used and enjoyed by everyone. + +### OpenUnirest:3.3.02 * Add the ability to make requests to non-standard web methods for things like WebDAV, SVN, or other horrible things. ```java Unirest.request("CHEESE", "http://some.cheesy.thing") .asString(); ``` + +### OpenUnirest:3.3.00 +* Slight breaking change with regard to accessing Apache specific classes via the config + * getClient and getAsyncClient return the Unirest containers for clients. You can still get to the Apache client through that for now but this is also deprecated. Eventually Unirest will make Apache just one of several modules. + * Apache client wrappers are now package local. * Add support for overriding the default expected encoding both on a per-request basis and as a default in the config. ```java // Changing the default from UTF-8 for all requests @@ -43,7 +57,14 @@ Unirest.get("http://some.file.with.windows.encoding/file.txt") .responseEncoding("windows-1250") .asString(); ``` + +### OpenUnirest:3.2.06 * access headers in order + +### OpenUnirest:3.2.05 +* UnirestInstance is autoclosable + +### OpenUnirest:3.2.04 * Adds chainable ifSuccess and ifFailure consumer methods to the response. Now you can handle the response like ```java Unirest.get("https://localhost/somewhere") @@ -51,11 +72,20 @@ Unirest.get("http://some.file.with.windows.encoding/file.txt") .ifSuccess(r -> log.info("Yippy!")) .ifFailure(r -> log.error("Booo")); ``` + +### OpenUnirest:3.2.03 * Allow the configuration of header suppliers. ```java Unirest.config().setDefaultHeader("trace", () -> value); ``` + +### OpenUnirest:3.2.02 +* distinguish between set and add for default headers. + +### OpenUnirest:3.2.01 * add method to replace a header rather than append to it. + +### OpenUnirest:3.2.00 * Now you can stream the results into a file! * It doesn't need to be a file either. It could be any result. Unirest will shove it in a file. ```java @@ -63,13 +93,35 @@ File file = Unirest.get("https://someplace/file.tar.gz") .asFile("/local/storage/file.tar.gz") .getBody(); ``` + +### OpenUnirest:3.1.02 * When encountering a parsing error with asObject or asJson capture the body in a UnirestParsingException +* New BETA feature asFile method to stream the response into a file. + +### OpenUnirest:3.1.01 * Detect if the async client has stopped for some reason and construct a new one. This one may be different from the one that was originally configured so we need to add a way to configure a supplier for clients rather than a direct client. + +### OpenUnirest:3.1.00 +* Deprecate methods that expose Apache. In the 4 line we will start supporting other clients. Primarily the java one supplied in Java9 (apache will still exist for 8-) * Add several functional methods for dealing with the raw response before the connection is closed. This is nice for large responses. + +### OpenUnirest:3.0.04 +* Parsing handler should capture unirest exceptions just like other exceptions. + +### OpenUnirest:3.0.03 * Support Java system properties for proxies via ```Unirest.config().useSystemProperties(true);``` * https://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html + +### OpenUnirest:3.0.02 +* Add support for the authenticated proxies to the async client + +### OpenUnirest:3.0.01 * Support for authenticated proxies with ```Unirest.config().proxy("proxy.server.host", 80, "username","password")``` -* The namespace has been shortened to just **kong.unirest** (inspired by Java Spark) + +### OpenUnirest:3.0.00 +* This is a **major** release with several **breaking changes** which (other than the namespace change) should ONLY impact you if you are using some of Unirests more advanced features or custom configurations. +* The maven artifact has changed to ```open-unirest-java``` +* The namespace has been shortened to just **unirest** (inspired by Java Spark) * The configuration system has been completely redone. Previously it was scattered across several classes and was entirely static. The new system has instances and supports multiple configurations. See the UPGRADE_GUIDE.md for details. * Start accessing the config with ```Unirest.config()``` * Almost everything is now fronted by interfaces, this makes testing easier. @@ -78,10 +130,29 @@ File file = Unirest.get("https://someplace/file.tar.gz") * option no longer supports body (per http spec) * Accept and ContentType are now 1st class headers in the builder (```Unirest.get(path).accept("application/json")```) * Major internal fixes so that which builder operations were available when is consistent. + +### OpenUnirest:2.5.03 * Lazy init the HttpClients so they don't get in the way of setting custom clients. + +### OpenUnirest:2.5.02 +* More safety for issue #41 + +### OpenUnirest:2.5.01 +* Fix Issue #41: possible init error in HttpClient under heavy load + +### OpenUnirest:2.5.00 +* Extracted Interface for HttpResponse to make testing easier + +### OpenUnirest:2.4.02 * Updated org.json dependency + +### OpenUnirest:2.4.01 * Add async versions of generic type methods -* Add support for generic types with object mappers. + +### OpenUnirest:2.4.00 +* Issue #19 Add support for generic types with object mappers. + +### OpenUnirest:2.3.00 * Add support for the JSON Patch standard (RFC6902) https://tools.ietf.org/html/rfc6902 ```java Unirest.jsonPatch(MockServer.PATCH) @@ -93,23 +164,54 @@ File file = Unirest.get("https://someplace/file.tar.gz") .copy("/original/location", "/new/location") .asJson(); ``` + +### OpenUnirest:2.2.12 * Add optional flag overload to ```Unirest.shutDown(false)```. The flag indicates if the various Options should be cleared. This only applies to options that could survive a shutdown. The HttpClients and thread monitors will still be discarded. + +### OpenUnirest:2.2.11 * Change default MultiPart mode to BROWSER_COMPATIBLE in order to support unicode filenames. Clients wishing to use the legacy mode can set it to STRICT. This should not be a problem for most users as few servers today lack support for unicode file names. Issue #35 + +### OpenUnirest:2.2.10 * Update Apache dependencies https://archive.apache.org/dist/httpcomponents/httpclient/RELEASE_NOTES-4.5.x.txt -* add an option to disable cookie management with ```Options.enableCookieManagement(false)```. -* In the future ignoring cookies will be the default. + +### OpenUnirest:2.2.08 + * add an option to disable cookie management with ```Options.enableCookieManagement(false)```. + * In the future ignoring cookies will be the default. + +### OpenUnirest:2.2.07 +* Fix init error + +### OpenUnirest:2.2.06 * added ability to turn off redirect following with ```Options.followRedirects(boolean enable)``` (default is true) + +### OpenUnirest:2.2.04 * Add ```.charset(Charset charset)``` to POSTS (both form and body) * Clean up some ambiguous methods in form posting. This may be a breaking change for a very small number of users. There are better methods for handling these cases. * Added the ability to add HttpRequestInterceptors to the client. Though ``` Options.addInterceptor(new TestInterceptor()); ``` + +### OpenUnirest:2.2.03 +* Expose the ```Options.init()``` method to restore the system to a fresh start after a shutdown. * ```Unirest.shutdown()``` no longer throws a checked exception + +### OpenUnirest:2.2.02 * Fix NPE with null bodies from HEAD requests. + +### OpenUnirest:2.2.01 * Quitly consume and close InputStreams that may not be complete. + +### OpenUnirest:2.2.00 * Major refactoring of how response objects are built. This internalizes HttpClientHelper which was previously public but not needed if you were using the library in in the expected way. This refactoring sets up the library for future work to extend the number of supported formats and for greater expression in the methods for those formats. * Additional of functional map methods to HttpResponse so you don't have to stop the flow for further transformations. -* Fixed issue with achor hashes in URLs -* Fixed NPE in passing args as maps +* Update the org.json dependency +* Fixed issue with achor hashes in URLs (#17) +* Fixed NPE in passing args as maps (#20) + +### OpenUnirest:2.1.01 * JSON parsing errors no longer just throw out of ```asJson``` but are captured and can be inspected via ```HttpResponse::getParsingError```. This resolves the fact that most API's do not return valid JSON for non-200 status codes. * Return CompletableFuture rather that boring old Futures for all async methods. + + +### OpenUnirest:2.0.02 * UnirestException is no longer checked +* Namespaces have been migrated to new **io.gitgub.openunirest** namespace * Thread leak in Options fixed From 84b8bd778162496b89aa84d8e4306e46d5576c6b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 8 Mar 2019 06:33:45 -0600 Subject: [PATCH 0500/1769] closes #258 add documentation about the parsing exception --- README.md | 32 +++++++++++++------ .../test/java/BehaviorTests/AsJsonTest.java | 10 +++--- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 227b08d67..8f5bdd0de 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,19 @@ If you already have a map of parameters or do not wish to use seperate field met `.headers(Map headers)` is also supported in replacement of multiple header methods. +### Route Parameters +Sometimes you want to add dynamic parameters in the URL, you can easily do that by adding a placeholder in the URL, and then by setting the route parameters with the `routeParam` function, like: + +```java +Unirest.get("http://httpbin.org/{method}") + .routeParam("method", "get") + .queryString("name", "Mark") + .asJson(); +``` +In the example above the final URL will be `http://httpbin.org/get` - Basically the placeholder `{method}` will be replaced with `get`. + +The placeholder's format is as easy as: `{custom_name}` + ## JSON Patch Requests Unirest has full native support for JSON Patch requests ```java @@ -100,7 +113,7 @@ will send a request with a body of ``` ## Advanced Object Mapping with Jackson, GSON, JAX-B or others -Before an `asObject(Class)` or a `.body(Object)` invokation, is necessary to provide a custom implementation of the `ObjectMapper` interface. +Before an `asObject(Class)` or a `.body(Object)` invocation, is necessary to provide a custom implementation of the `ObjectMapper` interface. This should be done only the first time, as the instance of the ObjectMapper will be shared globally. Unirest offers a few plug-ins implementing popular object mappers like Jackson and Gson. See [mvn central](https://mvnrepository.com/artifact/com.kong) for details. @@ -128,18 +141,17 @@ Unirest.post("http://httpbin.org/authors/post") .asJson(); ``` -### Route Parameters -Sometimes you want to add dynamic parameters in the URL, you can easily do that by adding a placeholder in the URL, and then by setting the route parameters with the `routeParam` function, like: +#### Errors in Object or JSON parsing +You can't always get what you want. And sometimes results you get from web services will not map into what you expect them to. +When this happens with a ```asObject``` or ```asJson``` request the resulting body will be null, but the response object will contain a ParsingException that allows you to get the error and the original body for inspection. ```java -Unirest.get("http://httpbin.org/{method}") - .routeParam("method", "get") - .queryString("name", "Mark") - .asJson(); -``` -In the example above the final URL will be `http://httpbin.org/get` - Basically the placeholder `{method}` will be replaced with `get`. +UnirestParsingException ex = response.getParsingError().get(); -The placeholder's format is as easy as: `{custom_name}` +ex.getOriginalBody(); // Has the original body as a string. +ex.getMessage(); // Will have the parsing exception. +ex.getCause(); // of course will have the original parsing exception itself. +``` ## Asynchronous Requests Sometimes, well most of the time, you want your application to be asynchronous and not block, Unirest supports this in Java using anonymous callbacks, or direct method placement: diff --git a/unirest/src/test/java/BehaviorTests/AsJsonTest.java b/unirest/src/test/java/BehaviorTests/AsJsonTest.java index 0040cf3cf..de1f9801e 100644 --- a/unirest/src/test/java/BehaviorTests/AsJsonTest.java +++ b/unirest/src/test/java/BehaviorTests/AsJsonTest.java @@ -25,12 +25,8 @@ package BehaviorTests; -import kong.unirest.HttpResponse; -import kong.unirest.JsonNode; -import kong.unirest.Unirest; +import kong.unirest.*; import org.junit.Test; -import kong.unirest.MockCallback; -import kong.unirest.TestUtil; import java.util.concurrent.CompletableFuture; @@ -83,9 +79,11 @@ public void failureToReturnValidJsonWillResultInAnEmptyNode() { assertEquals(400, response.getStatus()); assertNull(response.getBody()); - assertEquals("You did something bad", response.getParsingError().get().getOriginalBody()); + UnirestParsingException ex = response.getParsingError().get(); + assertEquals("You did something bad", ex.getOriginalBody()); assertEquals("org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]", response.getParsingError().get().getMessage()); + } @Test From 7b51dae9927b66be194ed0361deb4b6835238911 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 9 Mar 2019 11:19:30 -0600 Subject: [PATCH 0501/1769] closes #189 enable the ability to turn off automatic retries --- README.md | 26 +++++++++++--- .../src/main/java/kong/unirest/Config.java | 36 +++++++++++++++---- .../kong/unirest/apache/ApacheClient.java | 3 ++ .../test/java/kong/unirest/ConfigTest.java | 7 ++++ 4 files changed, 61 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 8f5bdd0de..afb75ee25 100644 --- a/README.md +++ b/README.md @@ -13,12 +13,12 @@ This repo is an updated, maintained, and independent fork of the original Mashap ##### See the [UPGRADE_GUIDE](UPGRADE_GUIDE.md) for differences between this library and last kong release. -## Install With [Maven](https://mvnrepository.com/artifact/com.kong/unirest-java) +## Install With [Maven](https://mvnrepository.com/artifact/com.konghq/unirest-java) ``` - com.kong + com.konghq unirest-java - 2.0.01 + 2.0.03 ``` @@ -230,13 +230,31 @@ Unirest config allows easy access to build a configuration just like you would b .socketTimeout(500) .connectTimeout(1000) .concurrency(10, 5) - .proxy(new HttpHost("https://proxy")) + .proxy(new Proxy("https://proxy")) .setDefaultHeader("Accept", "application/json") .followRedirects(false) .enableCookieManagement(false) .addInterceptor(new MyCustomInterceptor()); ``` +#### Config Options + +| Builder Method | Impact | Default | +| ------------- | ------------- | ------------- | +| ```socketTimeout(int)``` | Sets the socket timeout for all requests in millis | 60000 | +| ```connectTimeout(int)``` | Sets the connection timeout for all requests in millis | 10000 | +| ```concurrency(int, int)``` | Sets concurrency rates; max total, max per route | 200, 20 | +| ```proxy(proxy)``` | Sets a proxy object for negotiating proxy servers. Can include auth credentials | | +| ```setDefaultHeader(String, String)``` | Sets a default header. Will overwrite if it exists | | +| ```setDefaultHeader(String, Supplier)``` | Sets a default header by supplier. Good for setting trace tokens for microservice architectures. Will overwrite if it exists | | +| ```addDefaultHeader(String, String)``` | Adds a default header. Multiple for the same name can exist | | +| ```addDefaultHeader(String, Supplier)``` | Add a default header by supplier. Good for setting trace tokens for microservice architectures. | | +| ```followRedirects(boolean)``` | toggle following redirects | true | +| ```enableCookieManagement(boolean)``` | toggle accepting and storing cookies | true | +| ```automaticRetries(boolean)``` | toggle disabling automatic retries (up to 4 times) for socket timeouts | true | + + + ##### Changing the config Changing Unirest's config should ideally be done once, or rarely. There are several background threads spawned by both Unirest itself and Apache HttpAsyncClient. Once Unirest has been activated configuration options that are involved in creating the client cannot be changed without an explicit shutdown or reset. diff --git a/unirest/src/main/java/kong/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java index a7e576bf0..db7022045 100644 --- a/unirest/src/main/java/kong/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -41,6 +41,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; + public class Config { public static final int DEFAULT_CONNECTION_TIMEOUT = 10000; public static final int DEFAULT_MAX_CONNECTIONS = 200; @@ -53,7 +54,7 @@ public class Config { private Optional objectMapper = Optional.empty(); private List interceptors = new ArrayList<>(); - private Headers defaultHeaders; + private Headers ers; private Proxy proxy; private int connectionTimeout; private int socketTimeout; @@ -66,6 +67,7 @@ public class Config { private Function asyncBuilder = ApacheAsyncClient::new; private Function clientBuilder = ApacheClient::new; private boolean requestCompressionOn = true; + private boolean automaticRetries; public Config() { setDefaults(); @@ -74,7 +76,7 @@ public Config() { private void setDefaults(){ interceptors.clear(); proxy = null; - defaultHeaders = new Headers(); + ers = new Headers(); connectionTimeout = DEFAULT_CONNECTION_TIMEOUT; socketTimeout = DEFAULT_SOCKET_TIMEOUT; maxTotal = DEFAULT_MAX_CONNECTIONS; @@ -82,6 +84,7 @@ private void setDefaults(){ followRedirects = true; cookieManagement = true; requestCompressionOn = true; + automaticRetries = true; } /** @@ -240,7 +243,7 @@ public Config concurrency(int total, int perRoute) { * @return this config object */ public Config clearDefaultHeaders() { - defaultHeaders.clear(); + ers.clear(); return this; } @@ -252,7 +255,7 @@ public Config clearDefaultHeaders() { * @return this config object */ public Config setDefaultHeader(String name, String value) { - defaultHeaders.replace(name, value); + ers.replace(name, value); return this; } @@ -265,7 +268,7 @@ public Config setDefaultHeader(String name, String value) { * @return this config object */ public Config setDefaultHeader(String name, Supplier value) { - defaultHeaders.add(name, value); + ers.add(name, value); return this; } @@ -277,7 +280,7 @@ public Config setDefaultHeader(String name, Supplier value) { * @return this config object */ public Config addDefaultHeader(String name, String value) { - defaultHeaders.add(name, value); + ers.add(name, value); return this; } @@ -341,6 +344,19 @@ public Config requestCompression(boolean value) { return this; } + /** + * Automaticly retry certain recoverable errors like socket timeouts. Up to 4 times + * Note that currently this only works on synchronous calls. + * Default is true + * + * @param value a bool is its true or not. + * @return this config object + */ + public Config automaticRetries(boolean value) { + automaticRetries = value; + return this; + } + /** * Set the default encoding that will be used for serialization into Strings. * The default-default is UTF-8 @@ -360,7 +376,7 @@ public Config setDefaultResponseEncoding(String value) { * @return Headers */ public Headers getDefaultHeaders() { - return defaultHeaders; + return ers; } /** @@ -382,6 +398,8 @@ public Config reset() { return this; } + + /** * Shut down the configuration and its clients. * The config can be re-initialized with its settings @@ -516,4 +534,8 @@ public String getDefaultResponseEncoding() { public boolean isRequestCompressionOn() { return requestCompressionOn; } + + public boolean isAutomaticRetries() { + return automaticRetries; + } } diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java index 0724c7693..353103a91 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java @@ -55,6 +55,9 @@ public ApacheClient(Config config) { .setConnectionManager(manager) .useSystemProperties(); + if(!config.isAutomaticRetries()){ + cb.disableAutomaticRetries(); + } if(!config.isRequestCompressionOn()) { cb.disableContentCompression(); } diff --git a/unirest/src/test/java/kong/unirest/ConfigTest.java b/unirest/src/test/java/kong/unirest/ConfigTest.java index 2a5183ef4..98eaca322 100644 --- a/unirest/src/test/java/kong/unirest/ConfigTest.java +++ b/unirest/src/test/java/kong/unirest/ConfigTest.java @@ -223,6 +223,13 @@ public void canDisableGZipencoding() { } + @Test + public void canDisableAuthRetry() { + assertTrue(config.isAutomaticRetries()); + config.automaticRetries(false); + assertFalse(config.isAutomaticRetries()); + } + @Test public void provideYourOwnAsyncClientBuilder() { AsyncClient cli = mock(AsyncClient.class); From 06d5f95203d63590596d147d0a45c062b98410de Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 9 Mar 2019 11:29:42 -0600 Subject: [PATCH 0502/1769] update readme --- README.md | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/README.md b/README.md index afb75ee25..f279803dc 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This repo is an updated, maintained, and independent fork of the original Mashap ##### See the [UPGRADE_GUIDE](UPGRADE_GUIDE.md) for differences between this library and last kong release. ## Install With [Maven](https://mvnrepository.com/artifact/com.konghq/unirest-java) -``` +```xml com.konghq unirest-java @@ -39,20 +39,6 @@ See the [Upgrade Guide](UPGRADE_GUIDE.md) * Automatic JSON parsing into a native object for JSON responses * Customizable binding, with mapping from response body to java Object -## Installing -Is easy as pie. Kidding. It's about as easy as doing these little steps: - -### With Maven - -You can use Maven by including the library: - -```xml - - com.mashape.unirest - unirest-java - 1.4.9 - -``` ## Creating Request So you're probably wondering how using Unirest makes creating requests in Java easier, here is a basic POST request that will explain everything: From 79599d564fab4dc0e314a8987458506bc3cac80f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 9 Mar 2019 11:33:40 -0600 Subject: [PATCH 0503/1769] more readme updates --- README.md | 71 +++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index f279803dc..975bbf779 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,6 @@ See the [Upgrade Guide](UPGRADE_GUIDE.md) * Supports Basic Authentication natively * Customizable timeout, concurrency levels and proxy settings * Customizable default headers for every request (DRY) -* Customizable `HttpClient` and `HttpAsyncClient` implementation * Automatic JSON parsing into a native object for JSON responses * Customizable binding, with mapping from response body to java Object @@ -60,7 +59,7 @@ If you already have a map of parameters or do not wish to use seperate field met `.headers(Map headers)` is also supported in replacement of multiple header methods. -### Route Parameters +#### Route Parameters Sometimes you want to add dynamic parameters in the URL, you can easily do that by adding a placeholder in the URL, and then by setting the route parameters with the `routeParam` function, like: ```java @@ -73,32 +72,7 @@ In the example above the final URL will be `http://httpbin.org/get` - Basically The placeholder's format is as easy as: `{custom_name}` -## JSON Patch Requests -Unirest has full native support for JSON Patch requests -```java - Unirest.jsonPatch(MockServer.PATCH) - .add("/fruits/-", "Apple") - .remove("/bugs") - .replace("/lastname", "Flintstone") - .test("/firstname", "Fred") - .move("/old/location", "/new/location") - .copy("/original/location", "/new/location") - .asJson(); -``` -will send a request with a body of -```json - [ - {"op":"add","path":"/fruits/-","value":"Apple"}, - {"op":"remove","path":"/bugs"}, - {"op":"replace","path":"/lastname","value":"Flintstone"}, - {"op":"test","path":"/firstname","value":"Fred"}, - {"op":"move","path":"/new/location","from":"/old/location"}, - {"op":"copy","path":"/new/location","from":"/original/location"} - ] - -``` - -## Advanced Object Mapping with Jackson, GSON, JAX-B or others +#### Advanced Object Mapping with Jackson, GSON, JAX-B or others Before an `asObject(Class)` or a `.body(Object)` invocation, is necessary to provide a custom implementation of the `ObjectMapper` interface. This should be done only the first time, as the instance of the ObjectMapper will be shared globally. Unirest offers a few plug-ins implementing popular object mappers like Jackson and Gson. See [mvn central](https://mvnrepository.com/artifact/com.kong) for details. @@ -139,7 +113,7 @@ ex.getMessage(); // Will have the parsing exception. ex.getCause(); // of course will have the original parsing exception itself. ``` -## Asynchronous Requests +#### Asynchronous Requests Sometimes, well most of the time, you want your application to be asynchronous and not block, Unirest supports this in Java using anonymous callbacks, or direct method placement: ```java @@ -153,7 +127,7 @@ CompletableFuture> future = Unirest.post("http://httpbin. }); ``` -## Custom mappings and handling large responses +#### Custom mappings and handling large responses Most response methods (```asString```, ```asJson```, and even ```asBinary```) read the entire response stream into memory. In order to read the original stream and handle large responses you can use several functional methods like: @@ -176,7 +150,7 @@ or consumers: }); ``` -## File Uploads +#### File Uploads Creating `multipart` requests with Java is trivial, simply pass along a `File` or an InputStream Object as a field: ```java @@ -187,7 +161,7 @@ HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") .asJson(); ``` -## Custom Entity Body +#### Custom Entity Body ```java HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") @@ -196,7 +170,32 @@ HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") .asJson(); ``` -## Basic Authentication +#### JSON Patch Requests +Unirest has full native support for JSON Patch requests +```java + Unirest.jsonPatch(MockServer.PATCH) + .add("/fruits/-", "Apple") + .remove("/bugs") + .replace("/lastname", "Flintstone") + .test("/firstname", "Fred") + .move("/old/location", "/new/location") + .copy("/original/location", "/new/location") + .asJson(); +``` +will send a request with a body of +```json + [ + {"op":"add","path":"/fruits/-","value":"Apple"}, + {"op":"remove","path":"/bugs"}, + {"op":"replace","path":"/lastname","value":"Flintstone"}, + {"op":"test","path":"/firstname","value":"Fred"}, + {"op":"move","path":"/new/location","from":"/old/location"}, + {"op":"copy","path":"/new/location","from":"/original/location"} + ] + +``` + +#### Basic Authentication Authenticating the request with basic authentication can be done by calling the `basicAuth(username, password)` function: ```java Unirest.get("http://httpbin.org/headers") @@ -241,7 +240,7 @@ Unirest config allows easy access to build a configuration just like you would b -##### Changing the config +#### Changing the config Changing Unirest's config should ideally be done once, or rarely. There are several background threads spawned by both Unirest itself and Apache HttpAsyncClient. Once Unirest has been activated configuration options that are involved in creating the client cannot be changed without an explicit shutdown or reset. ```Java @@ -250,7 +249,7 @@ Changing Unirest's config should ideally be done once, or rarely. There are seve .connectTimeout(5000) ``` -##### Setting custom Apache Client +#### Setting custom Apache Client You can set your own custom Apache HttpClient and HttpAsyncClient. Note that Unirest settings like timeouts or interceptors are not applied to custom clients. ```java @@ -279,7 +278,7 @@ As usual, Unirest maintains a primary single instance. Sometimes you might want -# Exiting an application +## Exiting an application Unirest starts a background event loop and your Java application won't be able to exit until you manually shutdown all the threads by invoking: From 1e9dda784763aa4979a14cca424eefe3b0c50aa8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 9 Mar 2019 14:47:57 -0600 Subject: [PATCH 0504/1769] part of #197 with great power comes great responsibility. You may now totally ignore SSL errors This is for the regular client. Next is async --- .../src/main/java/kong/unirest/Config.java | 17 ++++ .../kong/unirest/apache/ApacheClient.java | 40 ++++++++- .../BehaviorTests/DisableSecurityTest.java | 85 +++++++++++++++++++ .../src/test/java/kong/unirest/TestUtil.java | 15 ++++ 4 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 unirest/src/test/java/BehaviorTests/DisableSecurityTest.java diff --git a/unirest/src/main/java/kong/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java index db7022045..08cde6b20 100644 --- a/unirest/src/main/java/kong/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -68,6 +68,7 @@ public class Config { private Function clientBuilder = ApacheClient::new; private boolean requestCompressionOn = true; private boolean automaticRetries; + private boolean verifySsl = true; public Config() { setDefaults(); @@ -85,6 +86,7 @@ private void setDefaults(){ cookieManagement = true; requestCompressionOn = true; automaticRetries = true; + verifySsl = true; } /** @@ -321,6 +323,17 @@ public Config enableCookieManagement(boolean enable) { return this; } + /** + * Toggle verifying SSL/TLS certificates. Defaults to TRUE + * + * @param value a bool is its true or not. + * @return this config object + */ + public Config verifySsl(boolean value) { + this.verifySsl = value; + return this; + } + /** * Tell the HttpClients to use the system properties for things like proxies * @@ -538,4 +551,8 @@ public boolean isRequestCompressionOn() { public boolean isAutomaticRetries() { return automaticRetries; } + + public boolean isVerifySsl() { + return verifySsl; + } } diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java index 353103a91..942a7358e 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java @@ -28,9 +28,16 @@ import kong.unirest.*; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.config.RegistryBuilder; +import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.socket.PlainConnectionSocketFactory; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.TrustStrategy; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.ssl.SSLContextBuilder; import java.io.Closeable; import java.util.Optional; @@ -45,7 +52,7 @@ public class ApacheClient extends BaseApacheClient implements Client { public ApacheClient(Config config) { this.config = config; - manager = new PoolingHttpClientConnectionManager(); + manager = createManager(); syncMonitor = new SyncIdleConnectionMonitorThread(manager); syncMonitor.start(); @@ -55,6 +62,9 @@ public ApacheClient(Config config) { .setConnectionManager(manager) .useSystemProperties(); + if(!config.isVerifySsl()){ + disableSsl(cb); + } if(!config.isAutomaticRetries()){ cb.disableAutomaticRetries(); } @@ -74,6 +84,34 @@ public ApacheClient(Config config) { client = cb.build(); } + private PoolingHttpClientConnectionManager createManager() { + try { + if (config.isVerifySsl()) { + return new PoolingHttpClientConnectionManager(); + } + return new PoolingHttpClientConnectionManager( + RegistryBuilder.create() + .register("http", PlainConnectionSocketFactory.INSTANCE) + .register("https", new SSLConnectionSocketFactory(new SSLContextBuilder() + .loadTrustMaterial(null, (x509CertChain, authType) -> true) + .build(), + NoopHostnameVerifier.INSTANCE)) + .build() + ); + }catch (Exception e){ + throw new UnirestConfigException(e); + } + } + + private void disableSsl(HttpClientBuilder cb) { + try { + cb.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE); + cb.setSSLContext(new SSLContextBuilder().loadTrustMaterial(null, (TrustStrategy) (arg0, arg1) -> true).build()); + }catch (Exception e){ + throw new UnirestConfigException(e); + } + } + public ApacheClient(HttpClient httpClient, Config config, PoolingHttpClientConnectionManager clientManager, SyncIdleConnectionMonitorThread connMonitor) { this.client = httpClient; this.config = config; diff --git a/unirest/src/test/java/BehaviorTests/DisableSecurityTest.java b/unirest/src/test/java/BehaviorTests/DisableSecurityTest.java new file mode 100644 index 000000000..d6148e885 --- /dev/null +++ b/unirest/src/test/java/BehaviorTests/DisableSecurityTest.java @@ -0,0 +1,85 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package BehaviorTests; + +import kong.unirest.TestUtil; +import kong.unirest.Unirest; +import org.junit.Ignore; +import org.junit.Test; + +import javax.net.ssl.SSLHandshakeException; +import javax.net.ssl.SSLPeerUnverifiedException; + +import static org.junit.Assert.assertEquals; + +@Ignore // dont normally run these because they depend on badssl.com +public class DisableSecurityTest extends BddTest { + @Test + public void badName() { + fails("https://wrong.host.badssl.com/", + SSLPeerUnverifiedException.class, + "javax.net.ssl.SSLPeerUnverifiedException: " + + "Certificate for doesn't match any of the subject alternative names: " + + "[*.badssl.com, badssl.com]"); + disableSsl(); + canCall("https://wrong.host.badssl.com/"); + } + + @Test + public void expired() { + fails("https://expired.badssl.com/", + SSLHandshakeException.class, + "javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: " + + "PKIX path validation failed: java.security.cert.CertPathValidatorException: validity check failed"); + disableSsl(); + canCall("https://expired.badssl.com/"); + } + + @Test + public void selfSigned() { + fails("https://self-signed.badssl.com/", + SSLHandshakeException.class, + "javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: " + + "PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: " + + "unable to find valid certification path to requested target"); + disableSsl(); + canCall("https://self-signed.badssl.com/"); + } + + private void disableSsl() { + Unirest.config().reset().verifySsl(false); + } + + private void fails(String url, Class exClass, String error) { + TestUtil.assertExceptionUnwrapped(() -> Unirest.get(url).asEmpty(), + exClass, + error); + } + + private void canCall(String url) { + assertEquals(200, Unirest.get(url).asEmpty().getStatus()); + } +} diff --git a/unirest/src/test/java/kong/unirest/TestUtil.java b/unirest/src/test/java/kong/unirest/TestUtil.java index 77a4d975b..5771f60f4 100644 --- a/unirest/src/test/java/kong/unirest/TestUtil.java +++ b/unirest/src/test/java/kong/unirest/TestUtil.java @@ -31,6 +31,7 @@ import com.google.common.base.Charsets; import com.google.common.io.Resources; +import javax.net.ssl.SSLPeerUnverifiedException; import java.io.*; import java.net.URISyntaxException; import java.util.Base64; @@ -74,6 +75,18 @@ public static void assertException(Runnable runnable, Class } } + public static void assertExceptionUnwrapped(Runnable runnable, Class exClass, String message) { + try{ + runnable.run(); + fail("Expected exception but got none. \nExpected " + exClass); + } catch (Exception e){ + if (!e.getCause().getClass().isAssignableFrom(exClass)) { + fail("Expected wrong exception type \n Expected: " + exClass + "\n but got " + e.getCause().getClass()); + } + assertEquals("Wrong Error Message", message, e.getMessage()); + } + } + public static T readValue(String body, Class as) { try { return om.readValue(body, as); @@ -138,4 +151,6 @@ public static File rezFile(String name) { throw new RuntimeException(e); } } + + } From 358deabaa4328ccfd0ed72ff7d14fc9a448a7507 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 9 Mar 2019 15:10:42 -0600 Subject: [PATCH 0505/1769] part of #197 You may now totally ignore SSL errors when doing async --- .../unirest/apache/ApacheAsyncClient.java | 63 +++++++++++++++---- .../BehaviorTests/DisableSecurityTest.java | 46 ++++++++++++++ .../src/test/java/kong/unirest/TestUtil.java | 19 +++++- 3 files changed, 113 insertions(+), 15 deletions(-) diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java index b5c6356f4..2ace773bc 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java @@ -28,12 +28,19 @@ import kong.unirest.*; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.concurrent.FutureCallback; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.TrustStrategy; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor; import org.apache.http.nio.client.HttpAsyncClient; -import org.apache.http.nio.reactor.IOReactorException; +import org.apache.http.nio.conn.NoopIOSessionStrategy; +import org.apache.http.nio.conn.SchemeIOSessionStrategy; +import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy; +import org.apache.http.ssl.SSLContextBuilder; import java.util.Objects; import java.util.concurrent.CompletableFuture; @@ -51,7 +58,7 @@ public class ApacheAsyncClient extends BaseApacheClient implements AsyncClient { public ApacheAsyncClient(Config config) { this.config = config; try { - manager = new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor()); + manager = createConnectionManager(); manager.setMaxTotal(config.getMaxConnections()); manager.setDefaultMaxPerRoute(config.getMaxPerRoutes()); @@ -61,23 +68,53 @@ public ApacheAsyncClient(Config config) { .setDefaultCredentialsProvider(toApacheCreds(config.getProxy())) .useSystemProperties(); - if(config.useSystemProperties()){ - ab.useSystemProperties(); - } - if (!config.getFollowRedirects()) { - ab.setRedirectStrategy(new ApacheNoRedirectStrategy()); - } - if (!config.getEnabledCookieManagement()) { - ab.disableCookieManagement(); - } - config.getInterceptors().forEach(ab::addInterceptorFirst); + setOptions(ab); CloseableHttpAsyncClient build = ab.build(); build.start(); syncMonitor = new AsyncIdleConnectionMonitorThread(manager); syncMonitor.tryStart(); client = build; - } catch (IOReactorException e) { + } catch (Exception e) { + throw new UnirestConfigException(e); + } + } + + private void setOptions(HttpAsyncClientBuilder ab) { + if(!config.isVerifySsl()){ + disableSsl(ab); + } + if(config.useSystemProperties()){ + ab.useSystemProperties(); + } + if (!config.getFollowRedirects()) { + ab.setRedirectStrategy(new ApacheNoRedirectStrategy()); + } + if (!config.getEnabledCookieManagement()) { + ab.disableCookieManagement(); + } + config.getInterceptors().forEach(ab::addInterceptorFirst); + } + + private PoolingNHttpClientConnectionManager createConnectionManager() throws Exception { + if(config.isVerifySsl()) { + return new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor()); + } + Registry registry = RegistryBuilder.create() + .register("http", NoopIOSessionStrategy.INSTANCE) + .register("https", new SSLIOSessionStrategy(new SSLContextBuilder() + .loadTrustMaterial(null, (x509Certificates, s) -> true) + .build(), NoopHostnameVerifier.INSTANCE)) + .build(); + + return new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor(), registry); + } + + private void disableSsl(HttpAsyncClientBuilder ab) { + try { + ab.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE); + ab.setSSLContext(new SSLContextBuilder().loadTrustMaterial(null, (TrustStrategy) (arg0, arg1) -> true).build()); + }catch (Exception e){ throw new UnirestConfigException(e); } } diff --git a/unirest/src/test/java/BehaviorTests/DisableSecurityTest.java b/unirest/src/test/java/BehaviorTests/DisableSecurityTest.java index d6148e885..df5b43180 100644 --- a/unirest/src/test/java/BehaviorTests/DisableSecurityTest.java +++ b/unirest/src/test/java/BehaviorTests/DisableSecurityTest.java @@ -27,12 +27,15 @@ import kong.unirest.TestUtil; import kong.unirest.Unirest; +import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLPeerUnverifiedException; +import java.util.concurrent.ExecutionException; + import static org.junit.Assert.assertEquals; @Ignore // dont normally run these because they depend on badssl.com @@ -69,10 +72,45 @@ public void selfSigned() { canCall("https://self-signed.badssl.com/"); } + @Test + public void badNameAsync() { + failsAsync("https://wrong.host.badssl.com/", + SSLPeerUnverifiedException.class, + "javax.net.ssl.SSLPeerUnverifiedException: " + + "Host name 'wrong.host.badssl.com' does not match the certificate subject provided by the peer " + + "(CN=*.badssl.com, O=Lucas Garron, L=Walnut Creek, ST=California, C=US)"); + disableSsl(); + canCallAsync("https://wrong.host.badssl.com/"); + } + + @Test + public void expiredAsync() { + failsAsync("https://expired.badssl.com/", + SSLHandshakeException.class, + "javax.net.ssl.SSLHandshakeException: General SSLEngine problem"); + disableSsl(); + canCallAsync("https://expired.badssl.com/"); + } + + @Test + public void selfSignedAsync() { + failsAsync("https://self-signed.badssl.com/", + SSLHandshakeException.class, + "javax.net.ssl.SSLHandshakeException: General SSLEngine problem"); + disableSsl(); + canCallAsync("https://self-signed.badssl.com/"); + } + private void disableSsl() { Unirest.config().reset().verifySsl(false); } + private void failsAsync(String url, Class exClass, String error) { + TestUtil.assertExceptionUnwrapped(() -> Unirest.get(url).asEmptyAsync().get(), + exClass, + error); + } + private void fails(String url, Class exClass, String error) { TestUtil.assertExceptionUnwrapped(() -> Unirest.get(url).asEmpty(), exClass, @@ -82,4 +120,12 @@ private void fails(String url, Class exClass, String error) private void canCall(String url) { assertEquals(200, Unirest.get(url).asEmpty().getStatus()); } + + private void canCallAsync(String url) { + try { + assertEquals(200, Unirest.get(url).asEmptyAsync().get().getStatus()); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } } diff --git a/unirest/src/test/java/kong/unirest/TestUtil.java b/unirest/src/test/java/kong/unirest/TestUtil.java index 5771f60f4..c4866d197 100644 --- a/unirest/src/test/java/kong/unirest/TestUtil.java +++ b/unirest/src/test/java/kong/unirest/TestUtil.java @@ -63,7 +63,7 @@ public static T readValue(InputStream i, Class clss) { } } - public static void assertException(Runnable runnable, Class exClass, String message) { + public static void assertException(ExRunnable runnable, Class exClass, String message) { try{ runnable.run(); fail("Expected exception but got none. \nExpected " + exClass); @@ -75,7 +75,7 @@ public static void assertException(Runnable runnable, Class } } - public static void assertExceptionUnwrapped(Runnable runnable, Class exClass, String message) { + public static void assertExceptionUnwrapped(ExRunnable runnable, Class exClass, String message) { try{ runnable.run(); fail("Expected exception but got none. \nExpected " + exClass); @@ -152,5 +152,20 @@ public static File rezFile(String name) { } } + @FunctionalInterface + public interface ExRunnable { + /** + * When an object implementing interface Runnable is used + * to create a thread, starting the thread causes the object's + * run method to be called in that separately executing + * thread. + *

+ * The general contract of the method run is that it may + * take any action whatsoever. + * + * @see java.lang.Thread#run() + */ + public abstract void run() throws Exception; + } } From 5a6274a7ba339bae6d0487f3d87388f84cffdc04 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 9 Mar 2019 15:16:23 -0600 Subject: [PATCH 0506/1769] update docs --- CHANGELOG.md | 4 ++++ README.md | 1 + 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 068d9a9ef..e32b228c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.04 (pending) +* Disable SSL validation with ```Unirest.config().verifySsl(false)```. PLEASE DO NOT DO THIS IN PRODUCTION +* Disable Automatic retries with ```Unirest.config().automaticRetries(false)``` + ## 2.0.03 * Make sure the GzipInputStream gets closed. * Support disabling compressed results which is asked for by default diff --git a/README.md b/README.md index 975bbf779..f5eedf4da 100644 --- a/README.md +++ b/README.md @@ -237,6 +237,7 @@ Unirest config allows easy access to build a configuration just like you would b | ```followRedirects(boolean)``` | toggle following redirects | true | | ```enableCookieManagement(boolean)``` | toggle accepting and storing cookies | true | | ```automaticRetries(boolean)``` | toggle disabling automatic retries (up to 4 times) for socket timeouts | true | +| ```verifySsl(boolean)``` |toggle enforcing SSL | true | From 54e943d269ea3fc3469dc4ed561269e0ffa37bf4 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 9 Mar 2019 15:27:08 -0600 Subject: [PATCH 0507/1769] [maven-release-plugin] prepare release v2.0.04 --- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index e11f344d2..ecb6f2ec6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.0.04-SNAPSHOT + 2.0.04 unirest Simplified, lightweight HTTP client library. http://github.com/Kong/unirest-java/ @@ -31,7 +31,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - HEAD + v2.0.04 diff --git a/unirest/pom.xml b/unirest/pom.xml index efb848620..a6ba11be1 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.0.04-SNAPSHOT + 2.0.04 unirest-java From e9be551d1e931bc3b2b8df5496456cbde9b969ca Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 9 Mar 2019 15:27:20 -0600 Subject: [PATCH 0508/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index ecb6f2ec6..fb862b45a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.0.04 + 2.0.05-SNAPSHOT unirest Simplified, lightweight HTTP client library. http://github.com/Kong/unirest-java/ @@ -31,7 +31,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - v2.0.04 + HEAD diff --git a/unirest/pom.xml b/unirest/pom.xml index a6ba11be1..5f60887a5 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.0.04 + 2.0.05-SNAPSHOT unirest-java From d162d006f85533bbd512f0d1d19c45c0354f149b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 9 Mar 2019 16:01:42 -0600 Subject: [PATCH 0509/1769] update docs --- CHANGELOG.md | 2 +- README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e32b228c8..7bb0233dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 2.0.04 (pending) +## 2.0.04 * Disable SSL validation with ```Unirest.config().verifySsl(false)```. PLEASE DO NOT DO THIS IN PRODUCTION * Disable Automatic retries with ```Unirest.config().automaticRetries(false)``` diff --git a/README.md b/README.md index f5eedf4da..cbb1877c7 100644 --- a/README.md +++ b/README.md @@ -13,12 +13,12 @@ This repo is an updated, maintained, and independent fork of the original Mashap ##### See the [UPGRADE_GUIDE](UPGRADE_GUIDE.md) for differences between this library and last kong release. -## Install With [Maven](https://mvnrepository.com/artifact/com.konghq/unirest-java) +## Install With [Maven](https://mvnrepository.com/artifact/com.konghq/unirest-java)[:](https://repo.maven.apache.org/maven2/com/konghq/unirest-java/) ```xml com.konghq unirest-java - 2.0.03 + 2.0.04 ``` From 4d21d0c0b00cfea43a7561ff340ea982136b3b48 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 10 Mar 2019 08:20:45 -0500 Subject: [PATCH 0510/1769] closes #118 override socket and connection timeouts per request --- CHANGELOG.md | 3 + .../main/java/kong/unirest/BaseRequest.java | 54 ++++++++++--- .../main/java/kong/unirest/HttpRequest.java | 24 ++++++ .../unirest/apache/ApacheAsyncClient.java | 2 +- .../kong/unirest/apache/ApacheClient.java | 2 +- .../kong/unirest/apache/BaseApacheClient.java | 22 ----- .../kong/unirest/apache/RequestOptions.java | 52 ++++++++++++ .../java/kong/unirest/apache/RequestPrep.java | 11 +++ .../test/java/BehaviorTests/ProxyTest.java | 7 +- .../java/kong/unirest/BaseRequestTest.java | 81 +++++++++++++++++++ 10 files changed, 221 insertions(+), 37 deletions(-) create mode 100644 unirest/src/main/java/kong/unirest/apache/RequestOptions.java create mode 100644 unirest/src/test/java/kong/unirest/BaseRequestTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bb0233dc..1d7b06d3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.0.05 (pending) +* #118 enable overriding socket and connection timeouts per request + ## 2.0.04 * Disable SSL validation with ```Unirest.config().verifySsl(false)```. PLEASE DO NOT DO THIS IN PRODUCTION * Disable Automatic retries with ```Unirest.config().automaticRetries(false)``` diff --git a/unirest/src/main/java/kong/unirest/BaseRequest.java b/unirest/src/main/java/kong/unirest/BaseRequest.java index c225e5557..cacf9bf44 100644 --- a/unirest/src/main/java/kong/unirest/BaseRequest.java +++ b/unirest/src/main/java/kong/unirest/BaseRequest.java @@ -30,6 +30,7 @@ import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; import java.util.function.Function; +import java.util.function.Supplier; abstract class BaseRequest implements HttpRequest { @@ -39,12 +40,16 @@ abstract class BaseRequest implements HttpRequest { protected final Config config; protected HttpMethod method; protected Path url; + private Integer socketTimeout; + private Integer connectTimeout; BaseRequest(BaseRequest httpRequest) { this.config = httpRequest.config; this.method = httpRequest.method; this.url = httpRequest.url; this.headers.putAll(httpRequest.headers); + this.socketTimeout = httpRequest.socketTimeout; + this.connectTimeout = httpRequest.connectTimeout; } BaseRequest(Config config, HttpMethod method, String url) { @@ -123,6 +128,18 @@ public R queryString(Map parameters) { return (R)this; } + @Override + public R socketTimeout(int millies) { + this.socketTimeout = millies; + return (R)this; + } + + @Override + public R connectTimeout(int millies) { + this.connectTimeout = millies; + return (R)this; + } + @Override public R withObjectMapper(ObjectMapper mapper) { Objects.requireNonNull(mapper, "ObjectMapper may not be null"); @@ -255,6 +272,19 @@ public CompletableFuture> asFileAsync(String path, Callback new FileResponse(r, path), CallbackFuture.wrap(callback)); } + @Override + public PagedList asPaged(Function mappingFunction, Function, String> linkExtractor) { + PagedList all = new PagedList<>(); + String nextLink = this.getUrl(); + do { + this.url = new Path(nextLink); + HttpResponse next = mappingFunction.apply(this); + all.add(next); + nextLink = linkExtractor.apply(next); + }while (!Util.isNullOrEmpty(nextLink)); + return all; + } + private Function> getConsumer(Consumer consumer) { @@ -284,15 +314,19 @@ private ObjectMapper getObjectMapper() { } @Override - public PagedList asPaged(Function mappingFunction, Function, String> linkExtractor) { - PagedList all = new PagedList<>(); - String nextLink = this.getUrl(); - do { - this.url = new Path(nextLink); - HttpResponse next = mappingFunction.apply(this); - all.add(next); - nextLink = linkExtractor.apply(next); - }while (!Util.isNullOrEmpty(nextLink)); - return all; + public int getSocketTimeout() { + return valueOr(socketTimeout, config::getSocketTimeout); + } + + @Override + public int getConnectTimeout() { + return valueOr(connectTimeout, config::getConnectionTimeout); + } + + private T valueOr(T x, Supplier o){ + if(x != null){ + return x; + } + return o.get(); } } diff --git a/unirest/src/main/java/kong/unirest/HttpRequest.java b/unirest/src/main/java/kong/unirest/HttpRequest.java index de0502814..f99beae56 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequest.java +++ b/unirest/src/main/java/kong/unirest/HttpRequest.java @@ -137,6 +137,20 @@ public interface HttpRequest { */ R withObjectMapper(ObjectMapper mapper); + /** + * Set a socket timeout for this request + * @param millies the time in millies + * @return this request builder + */ + R socketTimeout(int millies); + + /** + * Set a connect timeout for this request + * @param millies the time in millies + * @return this request builder + */ + R connectTimeout(int millies); + /** * Executes the request and returns the response with the body mapped into a String * @return response @@ -335,4 +349,14 @@ PagedList asPaged(Function mappingFunction, default Optional getBody(){ return Optional.empty(); } + + /** + * @return socket timeout for this request + */ + int getSocketTimeout(); + + /** + * @return the connect timeout for this request + */ + int getConnectTimeout(); } diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java index 2ace773bc..e6adf43a0 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java @@ -63,7 +63,7 @@ public ApacheAsyncClient(Config config) { manager.setDefaultMaxPerRoute(config.getMaxPerRoutes()); HttpAsyncClientBuilder ab = HttpAsyncClientBuilder.create() - .setDefaultRequestConfig(getRequestConfig(config)) + .setDefaultRequestConfig(RequestOptions.toRequestConfig(config)) .setConnectionManager(manager) .setDefaultCredentialsProvider(toApacheCreds(config.getProxy())) .useSystemProperties(); diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java index 942a7358e..2e2a463e9 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java @@ -57,7 +57,7 @@ public ApacheClient(Config config) { syncMonitor.start(); HttpClientBuilder cb = HttpClientBuilder.create() - .setDefaultRequestConfig(getRequestConfig(config)) + .setDefaultRequestConfig(RequestOptions.toRequestConfig(config)) .setDefaultCredentialsProvider(toApacheCreds(config.getProxy())) .setConnectionManager(manager) .useSystemProperties(); diff --git a/unirest/src/main/java/kong/unirest/apache/BaseApacheClient.java b/unirest/src/main/java/kong/unirest/apache/BaseApacheClient.java index c894dbff7..93c989362 100644 --- a/unirest/src/main/java/kong/unirest/apache/BaseApacheClient.java +++ b/unirest/src/main/java/kong/unirest/apache/BaseApacheClient.java @@ -25,36 +25,14 @@ package kong.unirest.apache; -import kong.unirest.Config; import kong.unirest.Proxy; -import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.CredentialsProvider; -import org.apache.http.client.config.RequestConfig; import org.apache.http.impl.client.BasicCredentialsProvider; abstract class BaseApacheClient { - protected RequestConfig getRequestConfig(Config config) { - Integer connectionTimeout = config.getConnectionTimeout(); - Integer socketTimeout = config.getSocketTimeout(); - HttpHost proxy = toApacheProxy(config.getProxy()); - return RequestConfig.custom() - .setConnectTimeout(connectionTimeout) - .setSocketTimeout(socketTimeout) - .setConnectionRequestTimeout(socketTimeout) - .setProxy(proxy) - .build(); - } - - private HttpHost toApacheProxy(Proxy proxy){ - if(proxy == null){ - return null; - } - return new HttpHost(proxy.getHost(), proxy.getPort()); - } - protected CredentialsProvider toApacheCreds(Proxy proxy) { if(proxy != null && proxy.isAuthenticated()) { CredentialsProvider proxyCreds = new BasicCredentialsProvider(); diff --git a/unirest/src/main/java/kong/unirest/apache/RequestOptions.java b/unirest/src/main/java/kong/unirest/apache/RequestOptions.java new file mode 100644 index 000000000..67989281e --- /dev/null +++ b/unirest/src/main/java/kong/unirest/apache/RequestOptions.java @@ -0,0 +1,52 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest.apache; + +import kong.unirest.Config; +import kong.unirest.Proxy; +import org.apache.http.HttpHost; +import org.apache.http.client.config.RequestConfig; + +class RequestOptions { + static RequestConfig toRequestConfig(Config config) { + Integer connectionTimeout = config.getConnectionTimeout(); + Integer socketTimeout = config.getSocketTimeout(); + HttpHost proxy = toApacheProxy(config.getProxy()); + return RequestConfig.custom() + .setConnectTimeout(connectionTimeout) + .setSocketTimeout(socketTimeout) + .setConnectionRequestTimeout(socketTimeout) + .setProxy(proxy) + .build(); + } + + public static HttpHost toApacheProxy(Proxy proxy){ + if(proxy == null){ + return null; + } + return new HttpHost(proxy.getHost(), proxy.getPort()); + } +} diff --git a/unirest/src/main/java/kong/unirest/apache/RequestPrep.java b/unirest/src/main/java/kong/unirest/apache/RequestPrep.java index af4df6d5e..6e759e6b2 100644 --- a/unirest/src/main/java/kong/unirest/apache/RequestPrep.java +++ b/unirest/src/main/java/kong/unirest/apache/RequestPrep.java @@ -28,6 +28,7 @@ import kong.unirest.*; import org.apache.http.Header; import org.apache.http.HttpEntity; +import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.*; import org.apache.http.message.BasicHeader; import org.apache.http.nio.entity.NByteArrayEntity; @@ -85,12 +86,22 @@ private HttpRequestBase getHttpRequestBase() { String url = request.getUrl(); HttpRequestBase reqObj = FACTORIES.computeIfAbsent(request.getHttpMethod(), this::register).apply(url); request.getHeaders().all().stream().map(this::toEntries).forEach(reqObj::addHeader); + reqObj.setConfig(overrideConfig()); return reqObj; } catch (RuntimeException e) { throw new UnirestException(e); } } + private RequestConfig overrideConfig() { + return RequestConfig.custom() + .setConnectTimeout(request.getConnectTimeout()) + .setSocketTimeout(request.getSocketTimeout()) + .setConnectionRequestTimeout(request.getSocketTimeout()) + .setProxy(RequestOptions.toApacheProxy(config.getProxy())) + .build(); + } + private Function register(HttpMethod method) { return u -> new ApacheRequestWithBody(method, u); } diff --git a/unirest/src/test/java/BehaviorTests/ProxyTest.java b/unirest/src/test/java/BehaviorTests/ProxyTest.java index 2ff63d5ce..a6b56654d 100644 --- a/unirest/src/test/java/BehaviorTests/ProxyTest.java +++ b/unirest/src/test/java/BehaviorTests/ProxyTest.java @@ -35,7 +35,7 @@ import static org.junit.Assert.assertTrue; -@Ignore +@Ignore // The Janky Proxy is pretty janky and isn't entirely stable in CI public class ProxyTest extends BddTest { @After @Override @@ -105,9 +105,10 @@ public void canFlagTheClientsToUseSystemProperties(){ assertTrue(JankyProxy.wasUsed()); } - @Test @Ignore + @Test @Ignore // https://free-proxy-list.net/ public void callSomethingRealThroughARealProxy() { - Unirest.config().proxy("proxyv.local.com",81, "myuser","pass1!"); + Unirest.config().proxy("18.222.230.116",8080); + //Unirest.config().proxy("34.73.62.46",3128, "myuser","pass1!"); HttpResponse r = Unirest.get("https://twitter.com/ryber").asString(); System.out.println("status = " + r.getStatus()); System.out.println("body= " + r.getBody()); diff --git a/unirest/src/test/java/kong/unirest/BaseRequestTest.java b/unirest/src/test/java/kong/unirest/BaseRequestTest.java new file mode 100644 index 000000000..0ed2c8f83 --- /dev/null +++ b/unirest/src/test/java/kong/unirest/BaseRequestTest.java @@ -0,0 +1,81 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class BaseRequestTest { + + @Test + public void socketTimeoutCanOverrrideConfig() { + Config config = new Config(); + config.socketTimeout(42); + + HttpRequest request = new TestRequest(config); + + assertEquals(42, request.getSocketTimeout()); + request.socketTimeout(111); + assertEquals(111, request.getSocketTimeout()); + } + + @Test + public void connectTimeoutCanOverrrideConfig() { + Config config = new Config(); + config.connectTimeout(42); + + HttpRequest request = new TestRequest(config); + + assertEquals(42, request.getConnectTimeout()); + request.connectTimeout(111); + assertEquals(111, request.getConnectTimeout()); + } + + @Test + public void copiesSettingsFromOtherRequest() { + Config config = new Config(); + config.connectTimeout(42); + config.socketTimeout(42); + + TestRequest request = new TestRequest(config); + request.socketTimeout(111).connectTimeout(222); + + HttpRequest copy = new TestRequest(request); + assertEquals(111, copy.getSocketTimeout()); + assertEquals(222, copy.getConnectTimeout()); + } + + private class TestRequest extends BaseRequest { + TestRequest(BaseRequest httpRequest) { + super(httpRequest); + } + + TestRequest(Config config) { + super(config, HttpMethod.GET, ""); + } + } +} \ No newline at end of file From a0b81c31a4bc2ee029a726177332f12954b32a4d Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 10 Mar 2019 09:24:13 -0500 Subject: [PATCH 0511/1769] closes #72 set a proxy per request --- .../src/main/java/kong/unirest/BaseRequest.java | 13 +++++++++++++ .../src/main/java/kong/unirest/HttpRequest.java | 13 +++++++++++++ .../main/java/kong/unirest/apache/RequestPrep.java | 2 +- unirest/src/test/java/BehaviorTests/ProxyTest.java | 14 +++++++++++++- .../test/java/kong/unirest/BaseRequestTest.java | 14 ++++++++++++++ 5 files changed, 54 insertions(+), 2 deletions(-) diff --git a/unirest/src/main/java/kong/unirest/BaseRequest.java b/unirest/src/main/java/kong/unirest/BaseRequest.java index cacf9bf44..564036b47 100644 --- a/unirest/src/main/java/kong/unirest/BaseRequest.java +++ b/unirest/src/main/java/kong/unirest/BaseRequest.java @@ -42,6 +42,7 @@ abstract class BaseRequest implements HttpRequest { protected Path url; private Integer socketTimeout; private Integer connectTimeout; + private Proxy proxy; BaseRequest(BaseRequest httpRequest) { this.config = httpRequest.config; @@ -50,6 +51,7 @@ abstract class BaseRequest implements HttpRequest { this.headers.putAll(httpRequest.headers); this.socketTimeout = httpRequest.socketTimeout; this.connectTimeout = httpRequest.connectTimeout; + this.proxy = httpRequest.proxy; } BaseRequest(Config config, HttpMethod method, String url) { @@ -140,6 +142,12 @@ public R connectTimeout(int millies) { return (R)this; } + @Override + public R proxy(String host, int port) { + this.proxy = new Proxy(host, port); + return (R)this; + } + @Override public R withObjectMapper(ObjectMapper mapper) { Objects.requireNonNull(mapper, "ObjectMapper may not be null"); @@ -323,6 +331,11 @@ public int getConnectTimeout() { return valueOr(connectTimeout, config::getConnectionTimeout); } + @Override + public Proxy getProxy() { + return valueOr(proxy, config::getProxy); + } + private T valueOr(T x, Supplier o){ if(x != null){ return x; diff --git a/unirest/src/main/java/kong/unirest/HttpRequest.java b/unirest/src/main/java/kong/unirest/HttpRequest.java index f99beae56..477e5b104 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequest.java +++ b/unirest/src/main/java/kong/unirest/HttpRequest.java @@ -151,6 +151,14 @@ public interface HttpRequest { */ R connectTimeout(int millies); + /** + * Set a proxy for this request. Only basic proxies are supported. + * @param host the host url + * @param port the proxy port + * @return this request builder + */ + R proxy(String host, int port); + /** * Executes the request and returns the response with the body mapped into a String * @return response @@ -359,4 +367,9 @@ default Optional getBody(){ * @return the connect timeout for this request */ int getConnectTimeout(); + + /** + * @return the proxy for this request + */ + Proxy getProxy(); } diff --git a/unirest/src/main/java/kong/unirest/apache/RequestPrep.java b/unirest/src/main/java/kong/unirest/apache/RequestPrep.java index 6e759e6b2..d7f0f604e 100644 --- a/unirest/src/main/java/kong/unirest/apache/RequestPrep.java +++ b/unirest/src/main/java/kong/unirest/apache/RequestPrep.java @@ -98,7 +98,7 @@ private RequestConfig overrideConfig() { .setConnectTimeout(request.getConnectTimeout()) .setSocketTimeout(request.getSocketTimeout()) .setConnectionRequestTimeout(request.getSocketTimeout()) - .setProxy(RequestOptions.toApacheProxy(config.getProxy())) + .setProxy(RequestOptions.toApacheProxy(request.getProxy())) .build(); } diff --git a/unirest/src/test/java/BehaviorTests/ProxyTest.java b/unirest/src/test/java/BehaviorTests/ProxyTest.java index a6b56654d..f2a050957 100644 --- a/unirest/src/test/java/BehaviorTests/ProxyTest.java +++ b/unirest/src/test/java/BehaviorTests/ProxyTest.java @@ -26,7 +26,6 @@ package BehaviorTests; import kong.unirest.Proxy; -import org.apache.http.HttpHost; import org.junit.After; import org.junit.Ignore; import org.junit.Test; @@ -73,6 +72,19 @@ public void canUseNonAuthProxyWithEasyMethod() { assertTrue(JankyProxy.wasUsed()); } + @Test + public void canPassProxyOnRequest() { + JankyProxy.runServer("localhost", 4567, 7777); + + Unirest.get(MockServer.GET) + .proxy("localhost", 7777) + .asObject(RequestCapture.class) + .getBody() + .assertStatus(200); + + assertTrue(JankyProxy.wasUsed()); + } + @Test public void canSetAuthenticatedProxy(){ JankyProxy.runServer("localhost", 4567, 7777); diff --git a/unirest/src/test/java/kong/unirest/BaseRequestTest.java b/unirest/src/test/java/kong/unirest/BaseRequestTest.java index 0ed2c8f83..ed7e21540 100644 --- a/unirest/src/test/java/kong/unirest/BaseRequestTest.java +++ b/unirest/src/test/java/kong/unirest/BaseRequestTest.java @@ -69,6 +69,20 @@ public void copiesSettingsFromOtherRequest() { assertEquals(222, copy.getConnectTimeout()); } + @Test + public void canPassABasicProxyPerRequest() { + Config config = new Config(); + Proxy cp = new Proxy("foo", 8080, "username", "password"); + config.proxy(cp); + + HttpRequest request = new TestRequest(config); + + assertEquals(cp, request.getProxy()); + request.proxy("bar", 7979); + assertEquals("bar", request.getProxy().getHost()); + assertEquals(7979, request.getProxy().getPort().intValue()); + } + private class TestRequest extends BaseRequest { TestRequest(BaseRequest httpRequest) { super(httpRequest); From 9ae4bc10dbf17a8425216f4232698939f6f26fb5 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 10 Mar 2019 09:29:25 -0500 Subject: [PATCH 0512/1769] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d7b06d3d..4168cb86e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 2.0.05 (pending) * #118 enable overriding socket and connection timeouts per request +* #72 enable passing a proxy per request. Only works with simple proxies for now. ## 2.0.04 * Disable SSL validation with ```Unirest.config().verifySsl(false)```. PLEASE DO NOT DO THIS IN PRODUCTION From 9bb8e98e56442a383d6729de5da0d6298e9e9a92 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 10 Mar 2019 09:31:52 -0500 Subject: [PATCH 0513/1769] [maven-release-plugin] prepare release v2.0.05 --- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index fb862b45a..453fa6978 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.0.05-SNAPSHOT + 2.0.05 unirest Simplified, lightweight HTTP client library. http://github.com/Kong/unirest-java/ @@ -31,7 +31,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - HEAD + v2.0.05 diff --git a/unirest/pom.xml b/unirest/pom.xml index 5f60887a5..5497329b7 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.0.05-SNAPSHOT + 2.0.05 unirest-java From d451bf1f3d47c8a012c34fb7293009f4ee616d4d Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 10 Mar 2019 09:31:59 -0500 Subject: [PATCH 0514/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 453fa6978..9d5156f65 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.0.05 + 2.0.06-SNAPSHOT unirest Simplified, lightweight HTTP client library. http://github.com/Kong/unirest-java/ @@ -31,7 +31,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - v2.0.05 + HEAD diff --git a/unirest/pom.xml b/unirest/pom.xml index 5497329b7..2f4395799 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.0.05 + 2.0.06-SNAPSHOT unirest-java From 3d8d40cdb2c2e75e0f30671fb4d5637322e87a2e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 10 Mar 2019 10:20:43 -0500 Subject: [PATCH 0515/1769] update release info --- CHANGELOG.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4168cb86e..cdd72cbe6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 2.0.05 (pending) +## 2.0.05 * #118 enable overriding socket and connection timeouts per request * #72 enable passing a proxy per request. Only works with simple proxies for now. diff --git a/README.md b/README.md index cbb1877c7..347521178 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ This repo is an updated, maintained, and independent fork of the original Mashap com.konghq unirest-java - 2.0.04 + 2.0.05 ``` From a0aa4dcb994a1070d039622c011caa7d5ba3374d Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 10 Mar 2019 12:10:03 -0500 Subject: [PATCH 0516/1769] add json patch as content type --- unirest/src/main/java/kong/unirest/ContentType.java | 1 + 1 file changed, 1 insertion(+) diff --git a/unirest/src/main/java/kong/unirest/ContentType.java b/unirest/src/main/java/kong/unirest/ContentType.java index 1d6714329..4fb98e9c5 100644 --- a/unirest/src/main/java/kong/unirest/ContentType.java +++ b/unirest/src/main/java/kong/unirest/ContentType.java @@ -34,6 +34,7 @@ public class ContentType { public static final ContentType APPLICATION_ATOM_XML = create("application/atom+xml", ISO_8859_1); public static final ContentType APPLICATION_FORM_URLENCODED = create("application/x-www-form-urlencoded", ISO_8859_1); public static final ContentType APPLICATION_JSON = create("application/json", StandardCharsets.UTF_8); + public static final ContentType APPLICATION_JSON_PATCH = create("application/json-patch+json"); public static final ContentType APPLICATION_OCTET_STREAM = create("application/octet-stream"); public static final ContentType APPLICATION_SVG_XML = create("application/svg+xml", ISO_8859_1); public static final ContentType APPLICATION_XHTML_XML = create("application/xhtml+xml", ISO_8859_1); From 734b7160e3cd42f18b6970e4261ad1e3d535cd7f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 10 Mar 2019 12:51:08 -0500 Subject: [PATCH 0517/1769] break up the giant test --- .../java/BehaviorTests/FormPostingTest.java | 335 +---------------- .../MultiPartFormPostingTest.java | 345 ++++++++++++++++++ .../java/BehaviorTests/RequestCapture.java | 47 ++- .../BehaviorTests/UniBodyPostingTest.java | 57 +++ .../src/test/java/kong/unirest/TestUtil.java | 16 + 5 files changed, 463 insertions(+), 337 deletions(-) create mode 100644 unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java create mode 100644 unirest/src/test/java/BehaviorTests/UniBodyPostingTest.java diff --git a/unirest/src/test/java/BehaviorTests/FormPostingTest.java b/unirest/src/test/java/BehaviorTests/FormPostingTest.java index 3bd86c20a..7f854a1bf 100644 --- a/unirest/src/test/java/BehaviorTests/FormPostingTest.java +++ b/unirest/src/test/java/BehaviorTests/FormPostingTest.java @@ -26,20 +26,18 @@ package BehaviorTests; import kong.unirest.*; -import org.junit.Assert; import org.junit.Test; import java.io.*; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.List; import static java.util.Arrays.asList; import static kong.unirest.TestUtil.rezFile; import static org.junit.Assert.assertEquals; public class FormPostingTest extends BddTest { + @Test public void testFormFields() { Unirest.post(MockServer.POST) @@ -49,7 +47,8 @@ public void testFormFields() { .asObject(RequestCapture.class) .getBody() .assertParam("param1", "value1") - .assertParam("param2", "bye"); + .assertParam("param2", "bye") + .assertUrlEncodedContent(); } @Test @@ -62,112 +61,12 @@ public void formPostAsync() { RequestCapture req = parse(r); req.assertParam("param1", "value1"); req.assertParam("param2", "bye"); + req.assertUrlEncodedContent(); })); assertAsync(); } - @Test - public void testMultipart() throws Exception { - Unirest.post(MockServer.POST) - .field("name", "Mark") - .field("file", rezFile("/test")) - .asObject(RequestCapture.class) - .getBody() - .assertParam("name", "Mark") - .getFile("test") - .assertBody("This is a test file") - .assertFileType("application/octet-stream"); - } - - @Test - public void testMultipartContentType() throws Exception { - Unirest.post(MockServer.POST) - .field("name", "Mark") - .field("file", rezFile("/image.jpg"), "image/jpeg") - .asObject(RequestCapture.class) - .getBody() - .assertParam("name", "Mark") - .getFile("image.jpg") - .assertFileType("image/jpeg"); - } - - @Test - public void testMultipartInputStreamContentType() throws Exception { - FileInputStream stream = new FileInputStream(rezFile("/image.jpg")); - - Unirest.post(MockServer.POST) - .header("accept", ContentType.MULTIPART_FORM_DATA.toString()) - .field("name", "Mark") - .field("file", stream, ContentType.APPLICATION_OCTET_STREAM, "image.jpg") - .asObject(RequestCapture.class) - .getBody() - .assertHeader("Accept", ContentType.MULTIPART_FORM_DATA.toString()) - .assertParam("name", "Mark") - .getFile("image.jpg") - .assertFileType("application/octet-stream"); - } - - @Test - public void testMultipartInputStreamContentTypeAsync() throws Exception { - Unirest.post(MockServer.POST) - .field("name", "Mark") - .field("file", new FileInputStream(rezFile("/test")), ContentType.APPLICATION_OCTET_STREAM, "test") - .asJsonAsync(new MockCallback<>(this, r -> parse(r) - .assertParam("name", "Mark") - .getFile("test") - .assertFileType("application/octet-stream")) - ); - - assertAsync(); - } - - @Test - public void testMultipartByteContentType() throws Exception { - final byte[] bytes = getFileBytes("/image.jpg"); - - Unirest.post(MockServer.POST) - .field("boot","boot") - .field("file", bytes, "image.jpg") - .asObject(RequestCapture.class) - .getBody() - .getFile("image.jpg") - .assertFileType("application/octet-stream"); - } - - @Test - public void testMultipartByteContentTypeAsync() throws Exception { - final byte[] bytes = getFileBytes("/test"); - - Unirest.post(MockServer.POST) - .field("name", "Mark") - .field("file", bytes, "test") - .asJsonAsync(new MockCallback<>(this, r -> - parse(r) - .assertParam("name", "Mark") - .getFile("test") - .assertFileType("application/octet-stream")) - ); - - assertAsync(); - } - - @Test - public void testMultipartAsync() throws Exception { - Unirest.post(MockServer.POST) - .field("name", "Mark") - .field("file", rezFile("/test")) - .asJsonAsync(new MockCallback<>(this, r -> - parse(r) - .assertParam("name", "Mark") - .getFile("test") - .assertFileType("application/octet-stream") - .assertBody("This is a test file")) - ); - - assertAsync(); - } - @Test public void testAsyncCustomContentTypeAndFormParams() { Unirest.post(MockServer.POST) @@ -178,25 +77,12 @@ public void testAsyncCustomContentTypeAndFormParams() { .asJsonAsync(new MockCallback<>(this, r -> parse(r) .assertParam("name", "Mark") .assertParam("hello", "world") - .assertHeader("Content-Type", "application/x-www-form-urlencoded") + .assertContentType("application/x-www-form-urlencoded") )); assertAsync(); } - @Test - public void testPostMultipleFiles()throws Exception { - Unirest.post(MockServer.POST) - .field("param3", "wot") - .field("file1", rezFile("/test")) - .field("file2", rezFile("/test")) - .asObject(RequestCapture.class) - .getBody() - .assertParam("param3", "wot") - .assertFileContent("file1", "This is a test file") - .assertFileContent("file2", "This is a test file"); - } - @Test public void testPostArray() { Unirest.post(MockServer.POST) @@ -204,6 +90,7 @@ public void testPostArray() { .field("name", "Tom") .asObject(RequestCapture.class) .getBody() + .assertUrlEncodedContent() .assertParam("name", "Mark") .assertParam("name", "Tom"); } @@ -215,135 +102,21 @@ public void testPostUTF8() { .field("param3", "こんにちは") .asObject(RequestCapture.class) .getBody() + .assertUrlEncodedContent() .assertParam("param3", "こんにちは"); } - @Test - public void testPostBinaryUTF8() throws Exception { - Unirest.post(MockServer.POST) - .header("Accept", ContentType.MULTIPART_FORM_DATA.getMimeType()) - .field("param3", "こんにちは") - .field("file", rezFile("/test")) - .asObject(RequestCapture.class) - .getBody() - .assertParam("param3", "こんにちは") - .assertFileContent("file", "This is a test file"); - } - @Test public void testPostCollection() { Unirest.post(MockServer.POST) .field("name", asList("Mark", "Tom")) .asObject(RequestCapture.class) .getBody() + .assertUrlEncodedContent() .assertParam("name", "Mark") .assertParam("name", "Tom"); } - @Test - public void testPostMulipleFIles() { - RequestCapture cap = Unirest.post(MockServer.POST) - .field("name", asList(rezFile("/test"), rezFile("/test2"))) - .asObject(RequestCapture.class) - .getBody(); - - cap.getFile("test").assertBody("This is a test file"); - cap.getFile("test2").assertBody("this is another test"); - } - - @Test - public void testMultipeInputStreams() throws FileNotFoundException { - Unirest.post(MockServer.POST) - .field("name", asList(new FileInputStream(rezFile("/test")), new FileInputStream(rezFile("/test2")))) - .asObject(RequestCapture.class) - .getBody() - .assertParam("name", "This is a test file") - .assertParam("name", "this is another test"); - } - - @Test - public void multiPartInputStreamAsFile() throws FileNotFoundException { - Unirest.post(MockServer.POST) - .field("foo", "bar") - .field("filecontents", new FileInputStream(rezFile("/image.jpg")), "image.jpg") - .asObject(RequestCapture.class) - .getBody() - .assertParam("foo", "bar") - .getFileByInput("filecontents") - .assertFileType(ContentType.APPLICATION_OCTET_STREAM) - .assertFileName("image.jpg"); - } - - @Test - public void passFileAsByteArray() { - Unirest.post(MockServer.POST) - .field("foo", "bar") - .field("filecontents", getFileBytes("/image.jpg"), ContentType.IMAGE_JPEG, "image.jpg") - .asObject(RequestCapture.class) - .getBody() - .assertParam("foo", "bar") - .getFileByInput("filecontents") - .assertFileType(ContentType.IMAGE_JPEG) - .assertFileName("image.jpg"); - } - - @Test - public void multiPartInputStream() throws FileNotFoundException { - Unirest.post(MockServer.POST) - .field("foo", "bar") - .field("filecontents", new FileInputStream(rezFile("/test")), ContentType.WILDCARD) - .asObject(RequestCapture.class) - .getBody() - .assertParam("foo", "bar") - .assertParam("filecontents", "This is a test file"); - } - - @Test - public void postFileWithContentType() throws Exception { - File file = getImageFile(); - Unirest.post(MockServer.POST) - .field("testfile", file, ContentType.IMAGE_JPEG.getMimeType()) - .asObject(RequestCapture.class) - .getBody() - .getFile("image.jpg") - .assertFileType(ContentType.IMAGE_JPEG); - } - - @Test - public void nullFileResultsInEmptyPost() { - Unirest.post(MockServer.POST) - .field("testfile", (Object)null, ContentType.IMAGE_JPEG.getMimeType()) - .asObject(RequestCapture.class) - .getBody() - .assertParam("testfile", ""); - } - - @Test - public void postFileWithoutContentType() throws URISyntaxException { - File file = getImageFile(); - Unirest.post(MockServer.POST) - .field("testfile", file) - .asObject(RequestCapture.class) - .getBody() - .getFile("image.jpg") - .assertFileType("application/octet-stream"); - } - - @Test - public void postFieldsAsMap() throws URISyntaxException { - File file = getImageFile(); - - Unirest.post(MockServer.POST) - .fields(TestUtil.mapOf("big", "bird", "charlie", 42, "testfile", file, "gonzo", null)) - .asObject(RequestCapture.class) - .getBody() - .assertParam("big", "bird") - .assertParam("charlie", "42") - .assertParam("gonzo", "") - .getFile("image.jpg") - .assertFileType("application/octet-stream"); - } - @Test public void nullMapDoesntBomb() { Unirest.post(MockServer.POST) @@ -351,33 +124,10 @@ public void nullMapDoesntBomb() { .fields(null) .asObject(RequestCapture.class) .getBody() + .assertUrlEncodedContent() .assertParam("foo", "bar"); } - @Test - public void canPostInputStream() throws Exception { - File file = getImageFile(); - Unirest.post(MockServer.POST) - .field("testfile", new FileInputStream(file), "image.jpg") - .asObject(RequestCapture.class) - .getBody() - .getFileByInput("testfile") - .assertFileName("image.jpg") - .assertFileType("application/octet-stream"); - } - - @Test - public void canPostInputStreamWithContentType() throws Exception { - File file = getImageFile(); - Unirest.post(MockServer.POST) - .field("testfile", new FileInputStream(file), ContentType.IMAGE_JPEG, "image.jpg") - .asObject(RequestCapture.class) - .getBody() - .getFileByInput("testfile") - .assertFileName("image.jpg") - .assertFileType("image/jpeg"); - } - @Test public void testDelete() { Unirest.delete(MockServer.DELETE) @@ -385,6 +135,7 @@ public void testDelete() { .field("foo", "bar") .asObject(RequestCapture.class) .getBody() + .assertUrlEncodedContent() .assertParam("name", "mark") .assertParam("foo", "bar"); } @@ -396,6 +147,7 @@ public void testChangingEncodingToForms(){ .field("foo", "bar") .asObject(RequestCapture.class) .getBody() + .assertContentType("application/x-www-form-urlencoded; charset=US-ASCII") .assertParam("foo", "bar") .assertCharset(StandardCharsets.US_ASCII); } @@ -407,72 +159,9 @@ public void testChangingEncodingAfterMovingToForm(){ .charset(StandardCharsets.US_ASCII) .asObject(RequestCapture.class) .getBody() + .assertContentType("application/x-www-form-urlencoded; charset=US-ASCII") .assertParam("foo", "bar") .assertCharset(StandardCharsets.US_ASCII); } - @Test - public void canSetCharsetOfBody(){ - Unirest.post(MockServer.POST) - .charset(StandardCharsets.US_ASCII) - .body("foo") - .asObject(RequestCapture.class) - .getBody() - .asserBody("foo") - .assertCharset(StandardCharsets.US_ASCII); - } - - @Test - public void canSetCharsetOfBodyAfterMovingToBody(){ - Unirest.post(MockServer.POST) - .body("foo") - .charset(StandardCharsets.US_ASCII) - .asObject(RequestCapture.class) - .getBody() - .asserBody("foo") - .assertCharset(StandardCharsets.US_ASCII); - } - - @Test - public void utf8FileNames() { - InputStream fileData = new ByteArrayInputStream(new byte[] {'t', 'e', 's', 't'}); - final String filename = "fileäöü.pöf"; - - Unirest.post(MockServer.POST) - .field("file", fileData, filename) - .asObject(RequestCapture.class) - .getBody() - .getFile(filename) - .assertFileName(filename); - } - - @Test - public void canSetModeToStrictForLegacySupport() { - InputStream fileData = new ByteArrayInputStream(new byte[] {'t', 'e', 's', 't'}); - final String filename = "fileäöü.pöf"; - - Unirest.post(MockServer.POST) - .field("file", fileData, filename) - .mode(MultipartMode.STRICT) - .asObject(RequestCapture.class) - .getBody() - .getFile("file???.p?f") - .assertFileName("file???.p?f"); - } - - private File getImageFile() { - return rezFile("/image.jpg"); - } - - private byte[] getFileBytes(String s) { - try { - final InputStream stream = new FileInputStream(rezFile(s)); - final byte[] bytes = new byte[stream.available()]; - stream.read(bytes); - stream.close(); - return bytes; - }catch (IOException e){ - throw new RuntimeException(e); - } - } } diff --git a/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java b/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java new file mode 100644 index 000000000..dd0990021 --- /dev/null +++ b/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java @@ -0,0 +1,345 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package BehaviorTests; + +import kong.unirest.*; +import org.junit.Test; + +import java.io.*; +import java.net.URISyntaxException; + +import static java.util.Arrays.asList; +import static kong.unirest.TestUtil.getFileBytes; +import static kong.unirest.TestUtil.rezFile; + +public class MultiPartFormPostingTest extends BddTest { + @Test + public void testMultipart() throws Exception { + Unirest.post(MockServer.POST) + .field("name", "Mark") + .field("file", rezFile("/test")) + .asObject(RequestCapture.class) + .getBody() + .assertParam("name", "Mark") + .assertMultiPartContentType() + .getFile("test") + .assertBody("This is a test file") + .assertFileType("application/octet-stream"); + } + + @Test + public void testMultipartContentType() throws Exception { + Unirest.post(MockServer.POST) + .field("name", "Mark") + .field("file", rezFile("/image.jpg"), "image/jpeg") + .asObject(RequestCapture.class) + .getBody() + .assertMultiPartContentType() + .assertParam("name", "Mark") + .getFile("image.jpg") + .assertFileType("image/jpeg"); + } + + @Test + public void testMultipartInputStreamContentType() throws Exception { + FileInputStream stream = new FileInputStream(rezFile("/image.jpg")); + + Unirest.post(MockServer.POST) + .header("accept", ContentType.MULTIPART_FORM_DATA.toString()) + .field("name", "Mark") + .field("file", stream, ContentType.APPLICATION_OCTET_STREAM, "image.jpg") + .asObject(RequestCapture.class) + .getBody() + .assertMultiPartContentType() + .assertHeader("Accept", ContentType.MULTIPART_FORM_DATA.toString()) + .assertParam("name", "Mark") + .getFile("image.jpg") + .assertFileType("application/octet-stream"); + } + + @Test + public void testMultipartInputStreamContentTypeAsync() throws Exception { + Unirest.post(MockServer.POST) + .field("name", "Mark") + .field("file", new FileInputStream(rezFile("/test")), ContentType.APPLICATION_OCTET_STREAM, "test") + .asJsonAsync(new MockCallback<>(this, r -> parse(r) + .assertParam("name", "Mark") + .assertMultiPartContentType() + .getFile("test") + .assertFileType("application/octet-stream")) + ); + + assertAsync(); + } + + @Test + public void testMultipartByteContentType() throws Exception { + final byte[] bytes = getFileBytes("/image.jpg"); + + Unirest.post(MockServer.POST) + .field("boot","boot") + .field("file", bytes, "image.jpg") + .asObject(RequestCapture.class) + .getBody() + .assertMultiPartContentType() + .getFile("image.jpg") + .assertFileType("application/octet-stream"); + } + + @Test + public void testMultipartByteContentTypeAsync() throws Exception { + final byte[] bytes = getFileBytes("/test"); + + Unirest.post(MockServer.POST) + .field("name", "Mark") + .field("file", bytes, "test") + .asJsonAsync(new MockCallback<>(this, r -> + parse(r) + .assertParam("name", "Mark") + .assertMultiPartContentType() + .getFile("test") + .assertFileType("application/octet-stream")) + ); + + assertAsync(); + } + + + + @Test + public void testMultipartAsync() throws Exception { + Unirest.post(MockServer.POST) + .field("name", "Mark") + .field("file", rezFile("/test")) + .asJsonAsync(new MockCallback<>(this, r -> + parse(r) + .assertParam("name", "Mark") + .assertMultiPartContentType() + .getFile("test") + .assertFileType("application/octet-stream") + .assertBody("This is a test file")) + ); + + assertAsync(); + } + + @Test + public void utf8FileNames() { + InputStream fileData = new ByteArrayInputStream(new byte[] {'t', 'e', 's', 't'}); + final String filename = "fileäöü.pöf"; + + Unirest.post(MockServer.POST) + .field("file", fileData, filename) + .asObject(RequestCapture.class) + .getBody() + .assertMultiPartContentType() + .getFile(filename) + .assertFileName(filename); + } + + + + @Test + public void canSetModeToStrictForLegacySupport() { + InputStream fileData = new ByteArrayInputStream(new byte[] {'t', 'e', 's', 't'}); + final String filename = "fileäöü.pöf"; + + Unirest.post(MockServer.POST) + .field("file", fileData, filename) + .mode(MultipartMode.STRICT) + .asObject(RequestCapture.class) + .getBody() + .assertMultiPartContentType() + .getFile("file???.p?f") + .assertFileName("file???.p?f"); + } + + @Test + public void canPostInputStreamWithContentType() throws Exception { + File file = TestUtil.getImageFile(); + Unirest.post(MockServer.POST) + .field("testfile", new FileInputStream(file), ContentType.IMAGE_JPEG, "image.jpg") + .asObject(RequestCapture.class) + .getBody() + .assertMultiPartContentType() + .getFileByInput("testfile") + .assertFileName("image.jpg") + .assertFileType("image/jpeg"); + } + + @Test + public void canPostInputStream() throws Exception { + File file = TestUtil.getImageFile(); + Unirest.post(MockServer.POST) + .field("testfile", new FileInputStream(file), "image.jpg") + .asObject(RequestCapture.class) + .getBody() + .assertMultiPartContentType() + .getFileByInput("testfile") + .assertFileName("image.jpg") + .assertFileType("application/octet-stream"); + } + + @Test + public void postFieldsAsMap() throws URISyntaxException { + File file = TestUtil.getImageFile(); + + Unirest.post(MockServer.POST) + .fields(TestUtil.mapOf("big", "bird", "charlie", 42, "testfile", file, "gonzo", null)) + .asObject(RequestCapture.class) + .getBody() + .assertMultiPartContentType() + .assertParam("big", "bird") + .assertParam("charlie", "42") + .assertParam("gonzo", "") + .getFile("image.jpg") + .assertFileType("application/octet-stream"); + } + + @Test + public void postFileWithoutContentType() { + File file = TestUtil.getImageFile(); + Unirest.post(MockServer.POST) + .field("testfile", file) + .asObject(RequestCapture.class) + .getBody() + .assertMultiPartContentType() + .getFile("image.jpg") + .assertFileType("application/octet-stream"); + } + + @Test + public void postFileWithContentType() { + File file = TestUtil.getImageFile(); + Unirest.post(MockServer.POST) + .field("testfile", file, ContentType.IMAGE_JPEG.getMimeType()) + .asObject(RequestCapture.class) + .getBody() + .assertMultiPartContentType() + .getFile("image.jpg") + .assertFileType(ContentType.IMAGE_JPEG); + } + + @Test + public void multiPartInputStreamAsFile() throws FileNotFoundException { + Unirest.post(MockServer.POST) + .field("foo", "bar") + .field("filecontents", new FileInputStream(rezFile("/image.jpg")), "image.jpg") + .asObject(RequestCapture.class) + .getBody() + .assertMultiPartContentType() + .assertParam("foo", "bar") + .getFileByInput("filecontents") + .assertFileType(ContentType.APPLICATION_OCTET_STREAM) + .assertFileName("image.jpg"); + } + + @Test + public void testPostMulipleFIles() { + RequestCapture cap = Unirest.post(MockServer.POST) + .field("name", asList(rezFile("/test"), rezFile("/test2"))) + .asObject(RequestCapture.class) + .getBody() + .assertMultiPartContentType(); + + cap.getFile("test").assertBody("This is a test file"); + cap.getFile("test2").assertBody("this is another test"); + } + + @Test + public void testPostMultipleFiles()throws Exception { + Unirest.post(MockServer.POST) + .field("param3", "wot") + .field("file1", rezFile("/test")) + .field("file2", rezFile("/test")) + .asObject(RequestCapture.class) + .getBody() + .assertMultiPartContentType() + .assertParam("param3", "wot") + .assertFileContent("file1", "This is a test file") + .assertFileContent("file2", "This is a test file"); + } + + @Test + public void testPostBinaryUTF8() throws Exception { + Unirest.post(MockServer.POST) + .header("Accept", ContentType.MULTIPART_FORM_DATA.getMimeType()) + .field("param3", "こんにちは") + .field("file", rezFile("/test")) + .asObject(RequestCapture.class) + .getBody() + .assertMultiPartContentType() + .assertParam("param3", "こんにちは") + .assertFileContent("file", "This is a test file"); + } + + @Test + public void testMultipeInputStreams() throws FileNotFoundException { + Unirest.post(MockServer.POST) + .field("name", asList(new FileInputStream(rezFile("/test")), new FileInputStream(rezFile("/test2")))) + .asObject(RequestCapture.class) + .getBody() + .assertMultiPartContentType() + .assertParam("name", "This is a test file") + .assertParam("name", "this is another test"); + } + + @Test + public void multiPartInputStream() throws FileNotFoundException { + Unirest.post(MockServer.POST) + .field("foo", "bar") + .field("filecontents", new FileInputStream(rezFile("/test")), ContentType.WILDCARD) + .asObject(RequestCapture.class) + .getBody() + .assertMultiPartContentType() + .assertParam("foo", "bar") + .assertParam("filecontents", "This is a test file"); + } + + @Test + public void passFileAsByteArray() { + Unirest.post(MockServer.POST) + .field("foo", "bar") + .field("filecontents", TestUtil.getFileBytes("/image.jpg"), ContentType.IMAGE_JPEG, "image.jpg") + .asObject(RequestCapture.class) + .getBody() + .assertMultiPartContentType() + .assertParam("foo", "bar") + .getFileByInput("filecontents") + .assertFileType(ContentType.IMAGE_JPEG) + .assertFileName("image.jpg"); + } + + @Test + public void nullFileResultsInEmptyPost() { + Unirest.post(MockServer.POST) + .field("testfile", (Object)null, ContentType.IMAGE_JPEG.getMimeType()) + .asObject(RequestCapture.class) + .getBody() + .assertContentType("application/x-www-form-urlencoded; charset=UTF-8") + .assertParam("testfile", ""); + } +} diff --git a/unirest/src/test/java/BehaviorTests/RequestCapture.java b/unirest/src/test/java/BehaviorTests/RequestCapture.java index 4ece8430d..b6aee8e5f 100644 --- a/unirest/src/test/java/BehaviorTests/RequestCapture.java +++ b/unirest/src/test/java/BehaviorTests/RequestCapture.java @@ -25,6 +25,7 @@ package BehaviorTests; +import com.google.common.base.Splitter; import com.google.common.base.Strings; import com.google.common.collect.*; import kong.unirest.*; @@ -41,8 +42,7 @@ import static kong.unirest.JsonPatchRequest.CONTENT_TYPE; import static java.lang.System.getProperty; -import static org.hamcrest.CoreMatchers.endsWith; -import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; public class RequestCapture { @@ -53,7 +53,7 @@ public class RequestCapture { public String url; public String queryString; public HttpMethod method; - public HashMap routeParams = new HashMap<>(); + public HashMap routeParams = new HashMap<>(); public String contentType; public JsonPatch jsonPatches; public Integer status; @@ -79,7 +79,7 @@ private void populateParams(Request req) { } public void writeBody(Request req) { - if(Strings.nullToEmpty(req.contentType()).equals(CONTENT_TYPE)){ + if (Strings.nullToEmpty(req.contentType()).equals(CONTENT_TYPE)) { String body = req.body(); jsonPatches = new JsonPatch(body); this.body = jsonPatches.toString(); @@ -90,7 +90,7 @@ public void writeBody(Request req) { } private void parseBodyToFormParams() { - URLEncodedUtils.parse(this.body , Charset.forName("UTF-8")) + URLEncodedUtils.parse(this.body, Charset.forName("UTF-8")) .forEach(p -> { params.put(p.getName(), p.getValue()); }); @@ -107,7 +107,7 @@ public void writeMultipart(Request req) { buildFormPart(p); } } - } catch (ServletException e){ + } catch (ServletException e) { this.body = req.body(); parseBodyToFormParams(); } catch (Exception e) { @@ -153,7 +153,8 @@ private RequestCapture writeHeaders(Request req) { } public RequestCapture assertHeader(String key, String value) { - assertThat("Expected Header Failed", headers.get(key), hasItem(value)); + assertTrue("Expect Header But None Was Present", headers.containsKey(key)); + assertThat("Expected Header Value Failed", headers.get(key), hasItem(value)); return this; } @@ -177,7 +178,7 @@ public File getFileByInput(String input) { .orElseThrow(() -> new RuntimeException("No File from form: " + input)); } - public List getAllFilesByInput(String input){ + public List getAllFilesByInput(String input) { return files.stream() .filter(f -> Objects.equals(f.inputName, input)) .collect(Collectors.toList()); @@ -229,8 +230,8 @@ public void setPatch(JsonPatch patch) { } public RequestCapture assertStatus(Integer i) { - assertEquals(i, status); - return this; + assertEquals(i, status); + return this; } public void setIsProxied(boolean b) { @@ -243,8 +244,8 @@ public RequestCapture assertIsProxied(boolean b) { } public RequestCapture assertHeaderSize(String foo, int size) { - assertEquals(size, headers.get(foo).size()); - return this; + assertEquals(size, headers.get(foo).size()); + return this; } public void assertBody(String o) { @@ -255,6 +256,24 @@ public void setStatus(int i) { this.status = i; } + public RequestCapture assertContentType(String content) { + return assertHeader("Content-Type", content); + } + + public RequestCapture assertMultiPartContentType() { + List h = headers.get("Content-Type"); + assertEquals("Expected exactly 1 Content-Type header", 1, h.size()); + List parts = Splitter.on(";").trimResults().splitToList(h.get(0)); + assertEquals("multipart/form-data", parts.get(0)); + assertThat(parts.get(1), startsWith("boundary=")); + assertEquals("charset=UTF-8", parts.get(2)); + return this; + } + + public RequestCapture assertUrlEncodedContent() { + return assertContentType("application/x-www-form-urlencoded; charset=UTF-8"); + } + public static class File { public String fileName; public String type; @@ -262,12 +281,12 @@ public static class File { public String body; public String fileType; - public File assertBody(String content){ + public File assertBody(String content) { assertEquals(content, body); return this; } - public File assertFileType(String type){ + public File assertFileType(String type) { assertEquals(type, this.fileType); return this; } diff --git a/unirest/src/test/java/BehaviorTests/UniBodyPostingTest.java b/unirest/src/test/java/BehaviorTests/UniBodyPostingTest.java new file mode 100644 index 000000000..41c10dced --- /dev/null +++ b/unirest/src/test/java/BehaviorTests/UniBodyPostingTest.java @@ -0,0 +1,57 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package BehaviorTests; + +import kong.unirest.Unirest; +import org.junit.Test; + +import java.nio.charset.StandardCharsets; + +public class UniBodyPostingTest extends BddTest { + @Test + public void canSetCharsetOfBody(){ + Unirest.post(MockServer.POST) + .charset(StandardCharsets.US_ASCII) + .body("foo") + .asObject(RequestCapture.class) + .getBody() + .assertContentType("text/plain; charset=US-ASCII") + .asserBody("foo") + .assertCharset(StandardCharsets.US_ASCII); + } + + @Test + public void canSetCharsetOfBodyAfterMovingToBody(){ + Unirest.post(MockServer.POST) + .body("foo") + .charset(StandardCharsets.US_ASCII) + .asObject(RequestCapture.class) + .getBody() + .assertContentType("text/plain; charset=US-ASCII") + .asserBody("foo") + .assertCharset(StandardCharsets.US_ASCII); + } +} diff --git a/unirest/src/test/java/kong/unirest/TestUtil.java b/unirest/src/test/java/kong/unirest/TestUtil.java index c4866d197..8f245bdcf 100644 --- a/unirest/src/test/java/kong/unirest/TestUtil.java +++ b/unirest/src/test/java/kong/unirest/TestUtil.java @@ -152,6 +152,22 @@ public static File rezFile(String name) { } } + public static byte[] getFileBytes(String s) { + try { + final InputStream stream = new FileInputStream(rezFile(s)); + final byte[] bytes = new byte[stream.available()]; + stream.read(bytes); + stream.close(); + return bytes; + }catch (IOException e){ + throw new RuntimeException(e); + } + } + + public static File getImageFile() { + return rezFile("/image.jpg"); + } + @FunctionalInterface public interface ExRunnable { /** From 460cff3541f86a945b70c32de8f7049cb25c8633 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 10 Mar 2019 15:39:19 -0500 Subject: [PATCH 0518/1769] start to refactor the RequestCapture to better analyze multipart requests --- .../java/BehaviorTests/RequestCapture.java | 52 ++++++++++++++----- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/unirest/src/test/java/BehaviorTests/RequestCapture.java b/unirest/src/test/java/BehaviorTests/RequestCapture.java index b6aee8e5f..e7dc95f5c 100644 --- a/unirest/src/test/java/BehaviorTests/RequestCapture.java +++ b/unirest/src/test/java/BehaviorTests/RequestCapture.java @@ -25,6 +25,7 @@ package BehaviorTests; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.google.common.base.Splitter; import com.google.common.base.Strings; import com.google.common.collect.*; @@ -39,6 +40,7 @@ import java.nio.charset.Charset; import java.util.*; import java.util.stream.Collectors; +import java.util.stream.Stream; import static kong.unirest.JsonPatchRequest.CONTENT_TYPE; import static java.lang.System.getProperty; @@ -47,7 +49,7 @@ public class RequestCapture { public ListMultimap headers = LinkedListMultimap.create(); - public List files = new ArrayList<>(); + public List files = new ArrayList<>(); public ArrayListMultimap params = ArrayListMultimap.create(); public String body; public String url; @@ -123,16 +125,25 @@ private void buildFormPart(Part p) throws IOException { } public void buildFilePart(Part part) throws IOException { - File file = new File(); + FormPart file = new FormPart(); file.fileName = part.getSubmittedFileName(); file.type = part.getContentType(); file.inputName = part.getName(); file.fileType = part.getContentType(); file.body = TestUtil.toString(part.getInputStream()); + file.headers = extractHeaders(part); files.add(file); } + private ListMultimap extractHeaders(Part part) { + ListMultimap h = LinkedListMultimap.create(); + for(String header : part.getHeaderNames()){ + h.putAll(header, part.getHeaders(header)); + } + return h; + } + private void writeQuery(Request req) { req.queryParams().forEach(q -> params.putAll(q, Sets.newHashSet(req.queryMap(q).values()))); } @@ -163,23 +174,28 @@ public RequestCapture assertParam(String key, String value) { return this; } - public File getFile(String fileName) { - return files.stream() + public FormPart getFile(String fileName) { + return getFileStream() .filter(f -> Objects.equals(f.fileName, fileName)) .findFirst() .orElseThrow(() -> new RuntimeException("\nNo File With Name: " + fileName + "\n" - + "Found: " + files.stream().map(f -> f.fileName).collect(Collectors.joining(" ")))); + + "Found: " + getFileStream().map(f -> f.fileName).collect(Collectors.joining(" ")))); } - public File getFileByInput(String input) { + private Stream getFileStream() { return files.stream() + .filter(f -> f.isFile()); + } + + public FormPart getFileByInput(String input) { + return getFileStream() .filter(f -> Objects.equals(f.inputName, input)) .findFirst() .orElseThrow(() -> new RuntimeException("No File from form: " + input)); } - public List getAllFilesByInput(String input) { - return files.stream() + public List getAllFilesByInput(String input) { + return getFileStream() .filter(f -> Objects.equals(f.inputName, input)) .collect(Collectors.toList()); } @@ -274,30 +290,40 @@ public RequestCapture assertUrlEncodedContent() { return assertContentType("application/x-www-form-urlencoded; charset=UTF-8"); } - public static class File { + public static class FormPart { + public String contentType; + public ListMultimap headers = LinkedListMultimap.create(); + public String content; public String fileName; public String type; public String inputName; public String body; public String fileType; - public File assertBody(String content) { + + @JsonIgnore + public boolean isFile(){ + return fileName != null; + } + + public FormPart assertBody(String content) { assertEquals(content, body); return this; } - public File assertFileType(String type) { + public FormPart assertFileType(String type) { assertEquals(type, this.fileType); return this; } - public File assertFileType(ContentType imageJpeg) { + public FormPart assertFileType(ContentType imageJpeg) { return assertFileType(imageJpeg.toString()); } - public File assertFileName(String s) { + public FormPart assertFileName(String s) { assertEquals(s, fileName); return this; } } + } From b4a545dcf3d2d8b99a8b9c9b2f3544cf5dd1ac63 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 11 Mar 2019 07:33:46 -0500 Subject: [PATCH 0519/1769] add a test to inspect the raw request for multipart posts --- .../test/java/BehaviorTests/MockServer.java | 11 ++++++++++ .../MultiPartFormPostingTest.java | 20 +++++++++++++++++++ .../java/BehaviorTests/RequestCapture.java | 4 ++-- .../src/test/java/kong/unirest/TestUtil.java | 8 ++++++-- unirest/src/test/resources/rawPost.txt | 14 +++++++++++++ 5 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 unirest/src/test/resources/rawPost.txt diff --git a/unirest/src/test/java/BehaviorTests/MockServer.java b/unirest/src/test/java/BehaviorTests/MockServer.java index 587ba292d..7c1be93a2 100644 --- a/unirest/src/test/java/BehaviorTests/MockServer.java +++ b/unirest/src/test/java/BehaviorTests/MockServer.java @@ -36,6 +36,7 @@ import javax.servlet.ServletOutputStream; import java.io.File; import java.io.FileInputStream; +import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -67,6 +68,7 @@ public class MockServer { public static final String PASSED_PATH_PARAM_MULTI = PASSED_PATH_PARAM + "/{another}"; public static final String CHEESE = HOST + "/cheese"; public static final String ALTGET = "http://127.0.0.1:" + PORT + "/get"; + public static final String ECHO_RAW = HOST + "/raw"; public static void setJsonAsResponse(Object o){ @@ -100,6 +102,7 @@ public static void reset(){ get("/proxy", MockServer::proxiedResponse); get("/binary", MockServer::file); get("/paged", MockServer::paged); + post("/raw", MockServer::echo); Runtime.getRuntime().addShutdownHook(new Thread(Spark::stop)); try { new CountDownLatch(1).await(2, TimeUnit.SECONDS); @@ -108,6 +111,10 @@ public static void reset(){ } } + private static Object echo(Request request, Response response) { + return request.body(); + } + private static Object paged(Request request, Response response) { if(pages > onPage){ onPage++; @@ -195,4 +202,8 @@ public static void addResponseHeader(String key, String value) { public static void expectedPages(int expected) { pages = expected; } + + public static void main(String[] args){ + + } } diff --git a/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java b/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java index dd0990021..35473e478 100644 --- a/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java +++ b/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java @@ -34,12 +34,14 @@ import static java.util.Arrays.asList; import static kong.unirest.TestUtil.getFileBytes; import static kong.unirest.TestUtil.rezFile; +import static org.junit.Assert.assertEquals; public class MultiPartFormPostingTest extends BddTest { @Test public void testMultipart() throws Exception { Unirest.post(MockServer.POST) .field("name", "Mark") + .field("funky","bunch") .field("file", rezFile("/test")) .asObject(RequestCapture.class) .getBody() @@ -342,4 +344,22 @@ public void nullFileResultsInEmptyPost() { .assertContentType("application/x-www-form-urlencoded; charset=UTF-8") .assertParam("testfile", ""); } + + @Test + public void rawInspection() { + String body = Unirest.post(MockServer.ECHO_RAW) + .field("marky","mark") + .field("funky","bunch") + .field("file", rezFile("/test")) + .asString() + .getBody(); + + String expected = TestUtil.getResource("rawPost.txt").replaceAll("\r","").trim(); + + String id = body.substring(2, body.indexOf("\n") -1); + body = body.replaceAll(id, "IDENTIFIER").replaceAll("\r","").trim(); + + assertEquals(expected, body); + } + } diff --git a/unirest/src/test/java/BehaviorTests/RequestCapture.java b/unirest/src/test/java/BehaviorTests/RequestCapture.java index e7dc95f5c..1c6db7823 100644 --- a/unirest/src/test/java/BehaviorTests/RequestCapture.java +++ b/unirest/src/test/java/BehaviorTests/RequestCapture.java @@ -106,7 +106,7 @@ public void writeMultipart(Request req) { if (!Strings.isNullOrEmpty(p.getSubmittedFileName())) { buildFilePart(p); } else { - buildFormPart(p); + buildUrlEncodedParamPart(p); } } } catch (ServletException e) { @@ -118,7 +118,7 @@ public void writeMultipart(Request req) { } } - private void buildFormPart(Part p) throws IOException { + private void buildUrlEncodedParamPart(Part p) throws IOException { java.util.Scanner s = new Scanner(p.getInputStream()).useDelimiter("\\A"); String value = s.hasNext() ? s.next() : ""; params.put(p.getName(), value); diff --git a/unirest/src/test/java/kong/unirest/TestUtil.java b/unirest/src/test/java/kong/unirest/TestUtil.java index 8f245bdcf..e14f22d63 100644 --- a/unirest/src/test/java/kong/unirest/TestUtil.java +++ b/unirest/src/test/java/kong/unirest/TestUtil.java @@ -140,8 +140,12 @@ public static void assertBasicAuth(String raw, String username, String password) assertEquals(username + ":" + password, new String(Base64.getDecoder().decode(credentials))); } - public static String getResource(String resourceName) throws IOException { - return Resources.toString(Resources.getResource(resourceName), Charsets.UTF_8); + public static String getResource(String resourceName){ + try { + return Resources.toString(Resources.getResource(resourceName), Charsets.UTF_8); + }catch (Exception e) { + throw new RuntimeException(e); + } } public static File rezFile(String name) { diff --git a/unirest/src/test/resources/rawPost.txt b/unirest/src/test/resources/rawPost.txt new file mode 100644 index 000000000..ef3657d10 --- /dev/null +++ b/unirest/src/test/resources/rawPost.txt @@ -0,0 +1,14 @@ +--IDENTIFIER +Content-Disposition: form-data; name="file"; filename="test" +Content-Type: application/octet-stream + +This is a test file +--IDENTIFIER +Content-Disposition: form-data; name="funky" + +bunch +--IDENTIFIER +Content-Disposition: form-data; name="marky" + +mark +--IDENTIFIER-- From 38690c343ca81f6a7adfd27513fc794630fedbbc Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 11 Mar 2019 20:05:43 -0500 Subject: [PATCH 0520/1769] start to redo the docs --- README.md | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 347521178..479783541 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,6 @@ We are looking for official maintainers, check out issue [#252](https://github.com/Kong/unirest-java/issues/252) - -## About This Repository -This repo is an updated, maintained, and independent fork of the original Mashape/Kong Unirest-Java project. That project is no longer being maintained so this project was set up to keep it alive. - -##### See the [UPGRADE_GUIDE](UPGRADE_GUIDE.md) for differences between this library and last kong release. - ## Install With [Maven](https://mvnrepository.com/artifact/com.konghq/unirest-java)[:](https://repo.maven.apache.org/maven2/com/konghq/unirest-java/) ```xml @@ -22,7 +16,7 @@ This repo is an updated, maintained, and independent fork of the original Mashap ``` -#### Upgrading from Previous Versions +### Upgrading from Previous Versions See the [Upgrade Guide](UPGRADE_GUIDE.md) ## Features @@ -51,28 +45,22 @@ HttpResponse response = Unirest.post("http://httpbin.org/post") .asJson(); ``` -Requests are made when `as[Type]()` is invoked, possible types include `Json`, `Binary`, `String`, `Object`. - -If the request supports and it is of type `HttpRequestWithBody`, a body it can be passed along with `.body(String|JsonNode|Object)`. For using `.body(Object)` some pre-configuration is needed (see below). - -If you already have a map of parameters or do not wish to use seperate field methods for each one there is a `.fields(Map fields)` method that will serialize each key - value to form parameters on your request. +Requests are made when `as[Type]()` is invoked, possible types include `Json`, `String`, `Object` `Empty` and `File`. -`.headers(Map headers)` is also supported in replacement of multiple header methods. -#### Route Parameters +### Route Parameters Sometimes you want to add dynamic parameters in the URL, you can easily do that by adding a placeholder in the URL, and then by setting the route parameters with the `routeParam` function, like: ```java Unirest.get("http://httpbin.org/{method}") .routeParam("method", "get") - .queryString("name", "Mark") .asJson(); ``` In the example above the final URL will be `http://httpbin.org/get` - Basically the placeholder `{method}` will be replaced with `get`. The placeholder's format is as easy as: `{custom_name}` -#### Advanced Object Mapping with Jackson, GSON, JAX-B or others +### Advanced Object Mapping with Jackson, GSON, JAX-B or others Before an `asObject(Class)` or a `.body(Object)` invocation, is necessary to provide a custom implementation of the `ObjectMapper` interface. This should be done only the first time, as the instance of the ObjectMapper will be shared globally. Unirest offers a few plug-ins implementing popular object mappers like Jackson and Gson. See [mvn central](https://mvnrepository.com/artifact/com.kong) for details. From a25b9f85ce29a89b1957c6ed46f6d810e3599e1b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 12 Mar 2019 06:47:03 -0500 Subject: [PATCH 0521/1769] move the optional packaged jackson object mapper from OpenUnirest --- object-mapper-jackson/.travis.yml | 12 + object-mapper-jackson/CHANGELOG.md | 2 + object-mapper-jackson/README.md | 20 ++ object-mapper-jackson/checkstyle.xml | 240 +++++++++++++++++ object-mapper-jackson/deploy.sh | 5 + object-mapper-jackson/pom.xml | 244 ++++++++++++++++++ .../kong/unirest/JacksonObjectMapper.java | 70 +++++ .../kong/unirest/JacksonObjectMapperTest.java | 90 +++++++ object-mapper-jackson/suppressions.xml | 9 + 9 files changed, 692 insertions(+) create mode 100644 object-mapper-jackson/.travis.yml create mode 100644 object-mapper-jackson/CHANGELOG.md create mode 100644 object-mapper-jackson/README.md create mode 100644 object-mapper-jackson/checkstyle.xml create mode 100755 object-mapper-jackson/deploy.sh create mode 100644 object-mapper-jackson/pom.xml create mode 100644 object-mapper-jackson/src/main/java/kong/unirest/JacksonObjectMapper.java create mode 100644 object-mapper-jackson/src/test/java/kong/unirest/JacksonObjectMapperTest.java create mode 100644 object-mapper-jackson/suppressions.xml diff --git a/object-mapper-jackson/.travis.yml b/object-mapper-jackson/.travis.yml new file mode 100644 index 000000000..d34d49296 --- /dev/null +++ b/object-mapper-jackson/.travis.yml @@ -0,0 +1,12 @@ +language: java + +jdk: + - oraclejdk8 + +os: + - linux + +cache: + directories: + - .autoconf + - $HOME/.m2 diff --git a/object-mapper-jackson/CHANGELOG.md b/object-mapper-jackson/CHANGELOG.md new file mode 100644 index 000000000..9bb919baf --- /dev/null +++ b/object-mapper-jackson/CHANGELOG.md @@ -0,0 +1,2 @@ +## 2.0.00 +* init release \ No newline at end of file diff --git a/object-mapper-jackson/README.md b/object-mapper-jackson/README.md new file mode 100644 index 000000000..66a4cc5ec --- /dev/null +++ b/object-mapper-jackson/README.md @@ -0,0 +1,20 @@ +# Jackson Object Mapper for Open Unirest +[![Build Status](https://travis-ci.org/OpenUnirest/unirest-java.svg?branch=master)](https://travis-ci.org/OpenUnirest/unirest-java) + +Welcome. This is a Object Mapper for Open Unirest based on the popular Jackson JSON parser. +Use it like this: + +```java + Unirest.config().setObjectMapper(new JacksonObjectMapper()); +``` + +You may also provide it with your own com.fasterxml.jackson.databind.ObjectMapper. + +## Install With [Maven](https://mvnrepository.com/artifact/io.github.openunirest/) +``` + + io.github.openunirest + object-mappers-jackson + 3.0.01 + +``` \ No newline at end of file diff --git a/object-mapper-jackson/checkstyle.xml b/object-mapper-jackson/checkstyle.xml new file mode 100644 index 000000000..6fcfd982d --- /dev/null +++ b/object-mapper-jackson/checkstyle.xml @@ -0,0 +1,240 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/object-mapper-jackson/deploy.sh b/object-mapper-jackson/deploy.sh new file mode 100755 index 000000000..0f74788bc --- /dev/null +++ b/object-mapper-jackson/deploy.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +mvn clean verify +mvn release:prepare -DskipTests +mvn release:perform -DskipTests diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml new file mode 100644 index 000000000..5c2c8a327 --- /dev/null +++ b/object-mapper-jackson/pom.xml @@ -0,0 +1,244 @@ + + + 4.0.0 + + com.konghq + unirest-objectmapper-jackson + 2.0.00-SNAPSHOT + unirest-objectmapper-jackson + Jackson based object mapper for Open Unirest + http://github.com/OpenUnirest/ + + + + MIT + http://opensource.org/licenses/MIT + repo + + + + + https://github.com/OpenUnirest/object-mappers-jackson + scm:git:git@github.com:OpenUnirest/object-mappers-jackson.git + scm:git:git@github.com:OpenUnirest/object-mappers-jackson.git + v3.0.01 + + + + + Ryber + Ryan Bergman + https://github.com/ryber + + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + UTF-8 + UTF-8 + 2.9.8 + + + + + ossrh + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.0 + + + + Unirest + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.13 + + + com.puppycrawl.tools + checkstyle + 5.9 + + + + + compile + auto-checkstyle + + checkstyle + check + + + + + ${basedir}/checkstyle.xml + ${basedir}/suppressions.xml + true + false + + + + org.jacoco + jacoco-maven-plugin + 0.8.1 + + + default-prepare-agent + + prepare-agent + + + + default-report + + report + + + + default-check + + check + + + + + BUNDLE + + + COMPLEXITY + COVEREDRATIO + 0.60 + + + + + + + + + + org.apache.maven.plugins + maven-release-plugin + 2.5 + + maven.test.skip=true + v@{project.version} + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrh + https://oss.sonatype.org/ + true + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + true + 128m + 512m + 1.8 + 1.8 + UTF-8 + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + + + + + + + com.konghq + unirest-java + 2.0.05 + provided + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + junit + junit + 4.12 + test + + + org.skyscreamer + jsonassert + 1.5.0 + test + + + \ No newline at end of file diff --git a/object-mapper-jackson/src/main/java/kong/unirest/JacksonObjectMapper.java b/object-mapper-jackson/src/main/java/kong/unirest/JacksonObjectMapper.java new file mode 100644 index 000000000..c4bdb4355 --- /dev/null +++ b/object-mapper-jackson/src/main/java/kong/unirest/JacksonObjectMapper.java @@ -0,0 +1,70 @@ +/* +The MIT License + +Copyright for portions of unirest-java are held by Kong Inc (c) 2018. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +package kong.unirest; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; + +import java.io.IOException; + +public class JacksonObjectMapper implements ObjectMapper { + private final com.fasterxml.jackson.databind.ObjectMapper om; + + public JacksonObjectMapper() { + this(new com.fasterxml.jackson.databind.ObjectMapper()); + om.configure(JsonGenerator.Feature.IGNORE_UNKNOWN, true); + } + + public JacksonObjectMapper(com.fasterxml.jackson.databind.ObjectMapper om){ + this.om = om; + } + + @Override + public T readValue(String value, Class valueType) { + try { + return om.readValue(value, valueType); + } catch (IOException e) { + throw new UnirestException(e); + } + } + + @Override + public T readValue(String value, GenericType genericType) { + try { + return om.readValue(value, om.constructType(genericType.getType())); + } catch (IOException e) { + throw new UnirestException(e); + } + } + + @Override + public String writeValue(Object value) { + try { + return om.writeValueAsString(value); + } catch (JsonProcessingException e) { + throw new UnirestException(e); + } + } +} diff --git a/object-mapper-jackson/src/test/java/kong/unirest/JacksonObjectMapperTest.java b/object-mapper-jackson/src/test/java/kong/unirest/JacksonObjectMapperTest.java new file mode 100644 index 000000000..260a4d2ad --- /dev/null +++ b/object-mapper-jackson/src/test/java/kong/unirest/JacksonObjectMapperTest.java @@ -0,0 +1,90 @@ +/* +The MIT License + +Copyright for portions of unirest-java are held by Kong Inc (c) 2018. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +package kong.unirest; + +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +import java.util.List; + +import static org.junit.Assert.*; + +public class JacksonObjectMapperTest { + private JacksonObjectMapper om = new JacksonObjectMapper(); + + @Test + public void canWrite() { + TestMe test = new TestMe("foo", 42, new TestMe("bar", 666, null)); + + String json = om.writeValue(test); + + JSONAssert.assertEquals( + "{\"text\":\"foo\",\"nmbr\":42,\"another\":{\"text\":\"bar\",\"nmbr\":666,\"another\":null}}" + , json + , true + ); + } + + @Test + public void canRead(){ + TestMe test = om.readValue("{\"text\":\"foo\",\"nmbr\":42,\"another\":{\"text\":\"bar\",\"nmbr\":666,\"another\":null}}", + TestMe.class); + + assertEquals("foo", test.text); + assertEquals(42, test.nmbr); + assertEquals("bar", test.another.text); + assertEquals(666, test.another.nmbr); + assertEquals(null, test.another.another); + } + + @Test + public void canReadGenerics(){ + List testList = om.readValue("[{\"text\":\"foo\",\"nmbr\":42,\"another\":{\"text\":\"bar\",\"nmbr\":666,\"another\":null}}]", + new GenericType>(){}); + + TestMe test = testList.get(0); + + assertEquals("foo", test.text); + assertEquals(42, test.nmbr); + assertEquals("bar", test.another.text); + assertEquals(666, test.another.nmbr); + assertEquals(null, test.another.another); + } + + + public static class TestMe { + public String text; + public int nmbr; + public TestMe another; + + public TestMe(){} + + public TestMe(String text, Integer nmbr, TestMe another) { + this.text = text; + this.nmbr = nmbr; + this.another = another; + } + } +} \ No newline at end of file diff --git a/object-mapper-jackson/suppressions.xml b/object-mapper-jackson/suppressions.xml new file mode 100644 index 000000000..cb3791156 --- /dev/null +++ b/object-mapper-jackson/suppressions.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file From 0da7dfb5c6ca8ae64dc1576122b567ae93c7be03 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 12 Mar 2019 07:12:39 -0500 Subject: [PATCH 0522/1769] fix the pom for releases --- object-mapper-jackson/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index 5c2c8a327..73afc0337 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-objectmapper-jackson - 2.0.00-SNAPSHOT + 2.0.05-SNAPSHOT unirest-objectmapper-jackson Jackson based object mapper for Open Unirest http://github.com/OpenUnirest/ @@ -21,7 +21,7 @@ https://github.com/OpenUnirest/object-mappers-jackson scm:git:git@github.com:OpenUnirest/object-mappers-jackson.git scm:git:git@github.com:OpenUnirest/object-mappers-jackson.git - v3.0.01 + v2.0.05 @@ -159,7 +159,7 @@ 2.5 maven.test.skip=true - v@{project.version} + {project.artifactId}-v@{project.version} From cb81fa8128a068fc38a4f9dfe9125d460d700430 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 12 Mar 2019 07:23:58 -0500 Subject: [PATCH 0523/1769] fix tag --- object-mapper-jackson/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index 73afc0337..fe97e0982 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-objectmapper-jackson - 2.0.05-SNAPSHOT + 2.0.06-SNAPSHOT unirest-objectmapper-jackson Jackson based object mapper for Open Unirest http://github.com/OpenUnirest/ @@ -159,7 +159,7 @@ 2.5 maven.test.skip=true - {project.artifactId}-v@{project.version} + v@{project.version}-om-jackson From a90f7c91771ea5ff3018c803a265a84a53763444 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 13 Mar 2019 06:46:15 -0500 Subject: [PATCH 0524/1769] pull the gson mapper over from OpenUnirest --- build/fileHeader.txt | 22 -- object-mapper-gson/.gitignore | 12 + object-mapper-gson/.travis.yml | 12 + object-mapper-gson/CHANGELOG.md | 2 + object-mapper-gson/LICENSE | 22 ++ object-mapper-gson/README.md | 19 ++ object-mapper-gson/checkstyle.xml | 240 +++++++++++++++++ object-mapper-gson/deploy.sh | 5 + object-mapper-gson/pom.xml | 243 ++++++++++++++++++ .../java/kong/unirest/GsonObjectMapper.java | 54 ++++ .../kong/unirest/GsonObjectMapperTest.java | 91 +++++++ object-mapper-gson/suppressions.xml | 9 + object-mapper-jackson/README.md | 11 +- object-mapper-jackson/pom.xml | 10 +- 14 files changed, 719 insertions(+), 33 deletions(-) create mode 100644 object-mapper-gson/.gitignore create mode 100644 object-mapper-gson/.travis.yml create mode 100644 object-mapper-gson/CHANGELOG.md create mode 100644 object-mapper-gson/LICENSE create mode 100644 object-mapper-gson/README.md create mode 100644 object-mapper-gson/checkstyle.xml create mode 100755 object-mapper-gson/deploy.sh create mode 100644 object-mapper-gson/pom.xml create mode 100644 object-mapper-gson/src/main/java/kong/unirest/GsonObjectMapper.java create mode 100644 object-mapper-gson/src/test/java/kong/unirest/GsonObjectMapperTest.java create mode 100644 object-mapper-gson/suppressions.xml diff --git a/build/fileHeader.txt b/build/fileHeader.txt index 1e65b29ae..e69de29bb 100644 --- a/build/fileHeader.txt +++ b/build/fileHeader.txt @@ -1,22 +0,0 @@ -The MIT License - -Copyright for portions of unirest-java are held by Kong Inc (c) 2013. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/object-mapper-gson/.gitignore b/object-mapper-gson/.gitignore new file mode 100644 index 000000000..7baad6ab7 --- /dev/null +++ b/object-mapper-gson/.gitignore @@ -0,0 +1,12 @@ +.classpath +pom.xml.releaseBackup +.project +target +.DS_Store +.settings +release.properties +META-INF +.idea +*.iml +.gitconfig + diff --git a/object-mapper-gson/.travis.yml b/object-mapper-gson/.travis.yml new file mode 100644 index 000000000..d34d49296 --- /dev/null +++ b/object-mapper-gson/.travis.yml @@ -0,0 +1,12 @@ +language: java + +jdk: + - oraclejdk8 + +os: + - linux + +cache: + directories: + - .autoconf + - $HOME/.m2 diff --git a/object-mapper-gson/CHANGELOG.md b/object-mapper-gson/CHANGELOG.md new file mode 100644 index 000000000..6476f80d3 --- /dev/null +++ b/object-mapper-gson/CHANGELOG.md @@ -0,0 +1,2 @@ +## 1.0.00 +* init release \ No newline at end of file diff --git a/object-mapper-gson/LICENSE b/object-mapper-gson/LICENSE new file mode 100644 index 000000000..16dc2225b --- /dev/null +++ b/object-mapper-gson/LICENSE @@ -0,0 +1,22 @@ +The MIT License + +Copyright for portions of unirest-java are held by Kong Inc (c) 2018. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/object-mapper-gson/README.md b/object-mapper-gson/README.md new file mode 100644 index 000000000..70687b3a3 --- /dev/null +++ b/object-mapper-gson/README.md @@ -0,0 +1,19 @@ +# Gson Object Mapper for Unirest + +Welcome. This is a Object Mapper for Unirest based on the popular google Gson JSON parser. +Use it like this: + +```java + Unirest.config().setObjectMapper(new GsonObjectMapper()); +``` + +You may also provide it with your own Gson instance. + +## Install With [Maven](https://mvnrepository.com/artifact/com.konghq/unirest-object-mappers-gson) +``` + + com.konghq + unirest-object-mappers-gson + 2.0.00 + +``` \ No newline at end of file diff --git a/object-mapper-gson/checkstyle.xml b/object-mapper-gson/checkstyle.xml new file mode 100644 index 000000000..6fcfd982d --- /dev/null +++ b/object-mapper-gson/checkstyle.xml @@ -0,0 +1,240 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/object-mapper-gson/deploy.sh b/object-mapper-gson/deploy.sh new file mode 100755 index 000000000..0f74788bc --- /dev/null +++ b/object-mapper-gson/deploy.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +mvn clean verify +mvn release:prepare -DskipTests +mvn release:perform -DskipTests diff --git a/object-mapper-gson/pom.xml b/object-mapper-gson/pom.xml new file mode 100644 index 000000000..a1333476a --- /dev/null +++ b/object-mapper-gson/pom.xml @@ -0,0 +1,243 @@ + + + 4.0.0 + + com.konghq + unirest-object-mappers-gson + 3.0.01-SNAPSHOT + object-mappers-gson + Gson based object mapper for Unirest + http://github.com/kong/unirest-java/ + + + + MIT + http://opensource.org/licenses/MIT + repo + + + + + https://github.com/kong/unirest-java + scm:git:git@github.com:kong/unirest-java.git + scm:git:git@github.com:kong/unirest-java.git + HEAD + + + + + Ryber + Ryan Bergman + https://github.com/Ryber + + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + UTF-8 + UTF-8 + + + + + ossrh + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.0 + + + + Unirest + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.13 + + + com.puppycrawl.tools + checkstyle + 5.9 + + + + + compile + auto-checkstyle + + checkstyle + check + + + + + ${basedir}/checkstyle.xml + ${basedir}/suppressions.xml + true + false + + + + org.jacoco + jacoco-maven-plugin + 0.8.1 + + + default-prepare-agent + + prepare-agent + + + + default-report + + report + + + + default-check + + check + + + + + BUNDLE + + + COMPLEXITY + COVEREDRATIO + 0.60 + + + + + + + + + + org.apache.maven.plugins + maven-release-plugin + 2.5 + + maven.test.skip=true + v@{project.version} + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrh + https://oss.sonatype.org/ + true + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + true + 128m + 512m + 1.8 + 1.8 + UTF-8 + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + + + + + + + com.konghq + unirest-java + 2.0.05 + provided + + + com.google.code.gson + gson + 2.8.5 + + + junit + junit + 4.12 + test + + + org.skyscreamer + jsonassert + 1.5.0 + test + + + \ No newline at end of file diff --git a/object-mapper-gson/src/main/java/kong/unirest/GsonObjectMapper.java b/object-mapper-gson/src/main/java/kong/unirest/GsonObjectMapper.java new file mode 100644 index 000000000..3ec4f2e91 --- /dev/null +++ b/object-mapper-gson/src/main/java/kong/unirest/GsonObjectMapper.java @@ -0,0 +1,54 @@ +/* +The MIT License + +Copyright for portions of unirest-java are held by Kong Inc (c) 2018. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +package kong.unirest; + +import com.google.gson.Gson; + +public class GsonObjectMapper implements ObjectMapper { + private Gson om; + + public GsonObjectMapper() { + this(new Gson()); + } + + public GsonObjectMapper(Gson om) { + this.om = om; + } + + @Override + public T readValue(String value, Class valueType) { + return om.fromJson(value, valueType); + } + + @Override + public T readValue(String value, GenericType genericType) { + return om.fromJson(value, genericType.getType()); + } + + @Override + public String writeValue(Object value) { + return om.toJson(value); + } +} diff --git a/object-mapper-gson/src/test/java/kong/unirest/GsonObjectMapperTest.java b/object-mapper-gson/src/test/java/kong/unirest/GsonObjectMapperTest.java new file mode 100644 index 000000000..93293851c --- /dev/null +++ b/object-mapper-gson/src/test/java/kong/unirest/GsonObjectMapperTest.java @@ -0,0 +1,91 @@ +/* +The MIT License + +Copyright for portions of unirest-java are held by Kong Inc (c) 2018. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +package kong.unirest; + +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; + + +import java.util.List; + +import static org.junit.Assert.*; + +public class GsonObjectMapperTest { + private GsonObjectMapper om = new GsonObjectMapper(); + + @Test + public void canWrite() { + TestMe test = new TestMe("foo", 42, new TestMe("bar", 666, null)); + + String json = om.writeValue(test); + + JSONAssert.assertEquals( + "{\"text\":\"foo\",\"nmbr\":42,\"another\":{\"text\":\"bar\",\"nmbr\":666}}" + , json + , true + ); + } + + @Test + public void canRead(){ + TestMe test = om.readValue("{\"text\":\"foo\",\"nmbr\":42,\"another\":{\"text\":\"bar\",\"nmbr\":666}}", + TestMe.class); + + assertEquals("foo", test.text); + assertEquals(42, test.nmbr); + assertEquals("bar", test.another.text); + assertEquals(666, test.another.nmbr); + assertEquals(null, test.another.another); + } + + @Test + public void canReadGenerics(){ + List testList = om.readValue("[{\"text\":\"foo\",\"nmbr\":42,\"another\":{\"text\":\"bar\",\"nmbr\":666,\"another\":null}}]", + new GenericType>(){}); + + TestMe test = testList.get(0); + + assertEquals("foo", test.text); + assertEquals(42, test.nmbr); + assertEquals("bar", test.another.text); + assertEquals(666, test.another.nmbr); + assertEquals(null, test.another.another); + } + + + public static class TestMe { + public String text; + public int nmbr; + public TestMe another; + + public TestMe(){} + + public TestMe(String text, Integer nmbr, TestMe another) { + this.text = text; + this.nmbr = nmbr; + this.another = another; + } + } +} \ No newline at end of file diff --git a/object-mapper-gson/suppressions.xml b/object-mapper-gson/suppressions.xml new file mode 100644 index 000000000..cb3791156 --- /dev/null +++ b/object-mapper-gson/suppressions.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/object-mapper-jackson/README.md b/object-mapper-jackson/README.md index 66a4cc5ec..69a61654a 100644 --- a/object-mapper-jackson/README.md +++ b/object-mapper-jackson/README.md @@ -1,7 +1,6 @@ -# Jackson Object Mapper for Open Unirest -[![Build Status](https://travis-ci.org/OpenUnirest/unirest-java.svg?branch=master)](https://travis-ci.org/OpenUnirest/unirest-java) +# Jackson Object Mapper for Unirest -Welcome. This is a Object Mapper for Open Unirest based on the popular Jackson JSON parser. +Welcome. This is a Object Mapper for Unirest based on the popular Jackson JSON parser. Use it like this: ```java @@ -10,11 +9,11 @@ Use it like this: You may also provide it with your own com.fasterxml.jackson.databind.ObjectMapper. -## Install With [Maven](https://mvnrepository.com/artifact/io.github.openunirest/) +## Install With [Maven](https://mvnrepository.com/artifact/com.konghq/) ``` - io.github.openunirest - object-mappers-jackson + com.konghq + unirest-objectmapper-jackson 3.0.01 ``` \ No newline at end of file diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index fe97e0982..a79255c55 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -6,8 +6,8 @@ unirest-objectmapper-jackson 2.0.06-SNAPSHOT unirest-objectmapper-jackson - Jackson based object mapper for Open Unirest - http://github.com/OpenUnirest/ + Jackson based object mapper for Unirest + http://github.com/kong/unirest-java/ @@ -18,9 +18,9 @@ - https://github.com/OpenUnirest/object-mappers-jackson - scm:git:git@github.com:OpenUnirest/object-mappers-jackson.git - scm:git:git@github.com:OpenUnirest/object-mappers-jackson.git + https://github.com/kong/unirest-java + scm:git:git@github.com:kong/unirest-java.git + scm:git:git@github.com:kong/unirest-java.git v2.0.05 From 2e1e0ab4286b64ba76df40cad0836104d77b550e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Mar 2019 08:48:47 -0500 Subject: [PATCH 0525/1769] put the fileheader back that somehow got removed --- build/fileHeader.txt | 22 ++++++++++++++++ object-mapper-gson/deploy.sh | 25 +++++++++++++++++++ .../java/kong/unirest/GsonObjectMapper.java | 25 +++++++++++++++++++ .../kong/unirest/GsonObjectMapperTest.java | 25 +++++++++++++++++++ object-mapper-jackson/deploy.sh | 25 +++++++++++++++++++ .../kong/unirest/JacksonObjectMapper.java | 25 +++++++++++++++++++ .../kong/unirest/JacksonObjectMapperTest.java | 25 +++++++++++++++++++ 7 files changed, 172 insertions(+) diff --git a/build/fileHeader.txt b/build/fileHeader.txt index e69de29bb..ba1a912a3 100644 --- a/build/fileHeader.txt +++ b/build/fileHeader.txt @@ -0,0 +1,22 @@ +The MIT License + +Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/object-mapper-gson/deploy.sh b/object-mapper-gson/deploy.sh index 0f74788bc..843fa9fa6 100755 --- a/object-mapper-gson/deploy.sh +++ b/object-mapper-gson/deploy.sh @@ -1,4 +1,29 @@ #!/bin/bash +# +# The MIT License +# +# Copyright for portions of unirest-java are held by Kong Inc (c) 2013. +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + mvn clean verify mvn release:prepare -DskipTests diff --git a/object-mapper-gson/src/main/java/kong/unirest/GsonObjectMapper.java b/object-mapper-gson/src/main/java/kong/unirest/GsonObjectMapper.java index 3ec4f2e91..52c09de35 100644 --- a/object-mapper-gson/src/main/java/kong/unirest/GsonObjectMapper.java +++ b/object-mapper-gson/src/main/java/kong/unirest/GsonObjectMapper.java @@ -1,3 +1,28 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + /* The MIT License diff --git a/object-mapper-gson/src/test/java/kong/unirest/GsonObjectMapperTest.java b/object-mapper-gson/src/test/java/kong/unirest/GsonObjectMapperTest.java index 93293851c..e7039bf3a 100644 --- a/object-mapper-gson/src/test/java/kong/unirest/GsonObjectMapperTest.java +++ b/object-mapper-gson/src/test/java/kong/unirest/GsonObjectMapperTest.java @@ -1,3 +1,28 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + /* The MIT License diff --git a/object-mapper-jackson/deploy.sh b/object-mapper-jackson/deploy.sh index 0f74788bc..843fa9fa6 100755 --- a/object-mapper-jackson/deploy.sh +++ b/object-mapper-jackson/deploy.sh @@ -1,4 +1,29 @@ #!/bin/bash +# +# The MIT License +# +# Copyright for portions of unirest-java are held by Kong Inc (c) 2013. +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + mvn clean verify mvn release:prepare -DskipTests diff --git a/object-mapper-jackson/src/main/java/kong/unirest/JacksonObjectMapper.java b/object-mapper-jackson/src/main/java/kong/unirest/JacksonObjectMapper.java index c4bdb4355..94adb26a5 100644 --- a/object-mapper-jackson/src/main/java/kong/unirest/JacksonObjectMapper.java +++ b/object-mapper-jackson/src/main/java/kong/unirest/JacksonObjectMapper.java @@ -1,3 +1,28 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + /* The MIT License diff --git a/object-mapper-jackson/src/test/java/kong/unirest/JacksonObjectMapperTest.java b/object-mapper-jackson/src/test/java/kong/unirest/JacksonObjectMapperTest.java index 260a4d2ad..0c0697e99 100644 --- a/object-mapper-jackson/src/test/java/kong/unirest/JacksonObjectMapperTest.java +++ b/object-mapper-jackson/src/test/java/kong/unirest/JacksonObjectMapperTest.java @@ -1,3 +1,28 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + /* The MIT License From 3a34495f554a11c4dd0e486c280d8b10d305290a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Mar 2019 08:57:35 -0500 Subject: [PATCH 0526/1769] update checkstyle to avoid security issue --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 9d5156f65..c9be9a17b 100644 --- a/pom.xml +++ b/pom.xml @@ -128,12 +128,12 @@ org.apache.maven.plugins maven-checkstyle-plugin - 2.13 + 2.17 com.puppycrawl.tools checkstyle - 5.9 + 8.18 From 14dcb501b9c8c610bfb355c6ca09d7013f922797 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Mar 2019 09:02:11 -0500 Subject: [PATCH 0527/1769] addresses #259. add the ability to auto-register the client with the system shutdownhooks --- CHANGELOG.md | 3 +++ .../src/main/java/kong/unirest/Config.java | 17 +++++++++++++++++ .../unirest/apache/ApacheAsyncClient.java | 3 +++ .../kong/unirest/apache/ApacheClient.java | 9 ++++++++- .../java/BehaviorTests/LifeCycleTest.java | 19 +++++++++++++++++++ .../test/java/kong/unirest/ConfigTest.java | 7 +++++++ 6 files changed, 57 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cdd72cbe6..f2940c150 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.0.06 (pending) +* #259 optionally flag the config to auto register the clients with shutdownhooks. + ## 2.0.05 * #118 enable overriding socket and connection timeouts per request * #72 enable passing a proxy per request. Only works with simple proxies for now. diff --git a/unirest/src/main/java/kong/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java index 08cde6b20..106e07ed4 100644 --- a/unirest/src/main/java/kong/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -69,6 +69,7 @@ public class Config { private boolean requestCompressionOn = true; private boolean automaticRetries; private boolean verifySsl = true; + private boolean addShutdownHook = false; public Config() { setDefaults(); @@ -383,6 +384,18 @@ public Config setDefaultResponseEncoding(String value) { return this; } + /** + * Register the client with a system shutdown hook. Note that this creates up to two threads + * (depending on if you use both sync and async clients). default is false + * + * @param value a bool is its true or not. + * @return this config object + */ + public Config addShutdownHook(boolean value) { + this.addShutdownHook = value; + return this; + } + /** * Return default headers that are added to every request * @@ -555,4 +568,8 @@ public boolean isAutomaticRetries() { public boolean isVerifySsl() { return verifySsl; } + + public boolean shouldAddShutdownHook() { + return addShutdownHook; + } } diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java index e6adf43a0..d94cc2392 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java @@ -75,6 +75,9 @@ public ApacheAsyncClient(Config config) { syncMonitor = new AsyncIdleConnectionMonitorThread(manager); syncMonitor.tryStart(); client = build; + if(config.shouldAddShutdownHook()){ + Runtime.getRuntime().addShutdownHook(new Thread(this::close, "Unirest Apache Async Client Shutdown Hook")); + } } catch (Exception e) { throw new UnirestConfigException(e); } diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java index 2e2a463e9..03a01aaaa 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java @@ -62,6 +62,11 @@ public ApacheClient(Config config) { .setConnectionManager(manager) .useSystemProperties(); + setOptions(cb); + client = cb.build(); + } + + private void setOptions(HttpClientBuilder cb) { if(!config.isVerifySsl()){ disableSsl(cb); } @@ -81,7 +86,9 @@ public ApacheClient(Config config) { cb.disableCookieManagement(); } config.getInterceptors().stream().forEach(cb::addInterceptorFirst); - client = cb.build(); + if(config.shouldAddShutdownHook()){ + Runtime.getRuntime().addShutdownHook(new Thread(this::close, "Unirest Apache Client Shutdown Hook")); + } } private PoolingHttpClientConnectionManager createManager() { diff --git a/unirest/src/test/java/BehaviorTests/LifeCycleTest.java b/unirest/src/test/java/BehaviorTests/LifeCycleTest.java index 8b68cde77..f7adc084c 100644 --- a/unirest/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/unirest/src/test/java/BehaviorTests/LifeCycleTest.java @@ -40,8 +40,12 @@ import java.io.IOException; import java.lang.management.ManagementFactory; +import java.lang.reflect.Field; +import java.util.Map; +import java.util.Set; import java.util.stream.IntStream; +import static java.lang.Thread.getAllStackTraces; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.lessThan; import static org.junit.Assert.*; @@ -73,6 +77,21 @@ public void settingACustomClient() { assertEquals("Howdy Ho!", result.getBody()); } + @Test + public void canAddShutdownHooks() throws Exception { + Unirest.config().addShutdownHook(true).getClient(); + Unirest.config().addShutdownHook(true).getAsyncClient(); + + // oh this is so dirty and horrible. Set to @Ignore if it starts to be a problem. + Class clazz = Class.forName("java.lang.ApplicationShutdownHooks"); + Field field = clazz.getDeclaredField("hooks"); + field.setAccessible(true); + Set threads = ((Map)field.get(null)).keySet(); + + assertTrue(threads.stream().anyMatch(t -> "Unirest Apache Client Shutdown Hook".equals(t.getName()))); + assertTrue(threads.stream().anyMatch(t -> "Unirest Apache Async Client Shutdown Hook".equals(t.getName()))); + } + @Test public void settingClientAfterClientHasAlreadyBeenSet() { HttpClientMock httpClientMock = new HttpClientMock(); diff --git a/unirest/src/test/java/kong/unirest/ConfigTest.java b/unirest/src/test/java/kong/unirest/ConfigTest.java index 98eaca322..7389a5c74 100644 --- a/unirest/src/test/java/kong/unirest/ConfigTest.java +++ b/unirest/src/test/java/kong/unirest/ConfigTest.java @@ -215,6 +215,13 @@ public void provideYourOwnClientBuilder() { assertSame(cli, config.getClient()); } + @Test + public void canSignalForShutdownHook() { + assertFalse(config.shouldAddShutdownHook()); + config.addShutdownHook(true); + assertTrue(config.shouldAddShutdownHook()); + } + @Test public void canDisableGZipencoding() { assertTrue(config.isRequestCompressionOn()); From fe8ef0b9c0e2fcde167034cdf76c81639888978b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Mar 2019 10:25:59 -0500 Subject: [PATCH 0528/1769] addresses #165 and #88. force multipart --- CHANGELOG.md | 3 ++- unirest/src/main/java/kong/unirest/Body.java | 2 ++ .../src/main/java/kong/unirest/HttpRequestBody.java | 5 +++++ .../java/kong/unirest/HttpRequestJsonPatch.java | 5 +++++ .../java/kong/unirest/HttpRequestMultiPart.java | 13 ++++++++++++- .../main/java/kong/unirest/HttpRequestUniBody.java | 5 +++++ .../main/java/kong/unirest/HttpRequestWithBody.java | 6 ++++++ .../java/kong/unirest/apache/ApacheBodyMapper.java | 13 ++++++++----- .../BehaviorTests/MultiPartFormPostingTest.java | 11 +++++++++++ .../src/test/java/BehaviorTests/RequestCapture.java | 2 +- 10 files changed, 57 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2940c150..cabaa6a21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ -## 2.0.06 (pending) +## 2.1.00 (pending) * #259 optionally flag the config to auto register the clients with shutdownhooks. +* #165 allow forcing a simple url-encoded param POST/PUT to be multipart. This adds a new method to the body interface so bumping the minor. ## 2.0.05 * #118 enable overriding socket and connection timeouts per request diff --git a/unirest/src/main/java/kong/unirest/Body.java b/unirest/src/main/java/kong/unirest/Body.java index feb58874f..2ec14aa4c 100644 --- a/unirest/src/main/java/kong/unirest/Body.java +++ b/unirest/src/main/java/kong/unirest/Body.java @@ -34,6 +34,8 @@ public interface Body { boolean isMultiPart(); + boolean isEntityBody(); + default Charset getCharset(){ return StandardCharsets.UTF_8; } diff --git a/unirest/src/main/java/kong/unirest/HttpRequestBody.java b/unirest/src/main/java/kong/unirest/HttpRequestBody.java index 7357c1886..8c6920cab 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestBody.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestBody.java @@ -79,6 +79,11 @@ public MultipartBody field(String name, InputStream stream, ContentType contentT return new HttpRequestMultiPart(this).field(name, stream, contentType, fileName); } + @Override + public MultipartBody multiPartContent() { + return new HttpRequestMultiPart(this).forceMultiPart(true); + } + @Override public MultipartBody field(String name, InputStream stream, String fileName) { return field(name, stream, ContentType.APPLICATION_OCTET_STREAM, fileName); diff --git a/unirest/src/main/java/kong/unirest/HttpRequestJsonPatch.java b/unirest/src/main/java/kong/unirest/HttpRequestJsonPatch.java index c729907db..b696d7e21 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestJsonPatch.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestJsonPatch.java @@ -88,4 +88,9 @@ public BodyPart uniPart() { public boolean isMultiPart() { return false; } + + @Override + public boolean isEntityBody() { + return true; + } } \ No newline at end of file diff --git a/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java b/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java index 674c1f6dd..44369b02c 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java @@ -37,6 +37,7 @@ class HttpRequestMultiPart extends BaseRequest implements Multipa private MultipartMode mode = MultipartMode.BROWSER_COMPATIBLE; private Charset charSet; + private boolean forceMulti = false; HttpRequestMultiPart(HttpRequestBody httpRequest) { super(httpRequest); @@ -164,7 +165,12 @@ public Optional getBody() { @Override public boolean isMultiPart() { - return true; + return forceMulti || multiParts().stream().anyMatch(BodyPart::isFile); + } + + @Override + public boolean isEntityBody() { + return false; } @Override @@ -176,4 +182,9 @@ public Collection multiParts() { public MultipartMode getMode() { return mode; } + + MultipartBody forceMultiPart(boolean value) { + forceMulti = value; + return this; + } } diff --git a/unirest/src/main/java/kong/unirest/HttpRequestUniBody.java b/unirest/src/main/java/kong/unirest/HttpRequestUniBody.java index f96862a6a..f7d398bb6 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestUniBody.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestUniBody.java @@ -76,6 +76,11 @@ public boolean isMultiPart() { return false; } + @Override + public boolean isEntityBody() { + return true; + } + @Override public BodyPart uniPart() { return body; diff --git a/unirest/src/main/java/kong/unirest/HttpRequestWithBody.java b/unirest/src/main/java/kong/unirest/HttpRequestWithBody.java index 7446b1497..fb0103ef3 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestWithBody.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestWithBody.java @@ -37,6 +37,12 @@ public interface HttpRequestWithBody extends HttpRequest { HttpRequestWithBody charset(Charset charset); + /** + * Forces the request to send as multipart even if all params are simple + * @return The same MultipartBody + */ + MultipartBody multiPartContent(); + MultipartBody field(String name, Collection value); MultipartBody field(String name, File file); diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheBodyMapper.java b/unirest/src/main/java/kong/unirest/apache/ApacheBodyMapper.java index 96ae7b339..dfc1f6a02 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheBodyMapper.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheBodyMapper.java @@ -39,6 +39,7 @@ import java.io.File; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -60,17 +61,19 @@ HttpEntity apply() { } private HttpEntity applyBody(Body o) { - if(o.isMultiPart()){ - return mapToMultipart(o); - }else { + if(o.isEntityBody()){ return mapToUniBody(o); + }else { + return mapToMultipart(o); } } private HttpEntity mapToUniBody(Body b) { BodyPart bodyPart = b.uniPart(); - if(String.class.isAssignableFrom(bodyPart.getPartType())){ + if(bodyPart == null){ + return new StringEntity("", StandardCharsets.UTF_8); + } else if(String.class.isAssignableFrom(bodyPart.getPartType())){ return new StringEntity((String) bodyPart.getValue(), b.getCharset()); } else { return new ByteArrayEntity((byte[])bodyPart.getValue()); @@ -78,7 +81,7 @@ private HttpEntity mapToUniBody(Body b) { } private HttpEntity mapToMultipart(Body body) { - if (body.multiParts().stream().anyMatch(BodyPart::isFile)) { + if (body.isMultiPart()) { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setCharset(body.getCharset()); builder.setMode(HttpMultipartMode.valueOf(body.getMode().name())); diff --git a/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java b/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java index 35473e478..4b7771fd5 100644 --- a/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java +++ b/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java @@ -345,6 +345,17 @@ public void nullFileResultsInEmptyPost() { .assertParam("testfile", ""); } + @Test + public void canForceIntoMultiPart() { + Unirest.post(MockServer.POST) + .multiPartContent() + .field("foo", "bar") + .asObject(RequestCapture.class) + .getBody() + .assertMultiPartContentType() + .assertParam("foo", "bar"); + } + @Test public void rawInspection() { String body = Unirest.post(MockServer.ECHO_RAW) diff --git a/unirest/src/test/java/BehaviorTests/RequestCapture.java b/unirest/src/test/java/BehaviorTests/RequestCapture.java index 1c6db7823..5d037d521 100644 --- a/unirest/src/test/java/BehaviorTests/RequestCapture.java +++ b/unirest/src/test/java/BehaviorTests/RequestCapture.java @@ -164,7 +164,7 @@ private RequestCapture writeHeaders(Request req) { } public RequestCapture assertHeader(String key, String value) { - assertTrue("Expect Header But None Was Present", headers.containsKey(key)); + assertTrue(String.format("Expect header of '%s' but none was present", key), headers.containsKey(key)); assertThat("Expected Header Value Failed", headers.get(key), hasItem(value)); return this; } From 86ab9edadda993ded07578de014143b05361b5d6 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Mar 2019 10:28:04 -0500 Subject: [PATCH 0529/1769] bump pom --- pom.xml | 4 ++-- unirest/pom.xml | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index c9be9a17b..d93673da0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,9 +4,9 @@ com.konghq unirest-java-parent pom - 2.0.06-SNAPSHOT + 2.1.00-SNAPSHOT unirest - Simplified, lightweight HTTP client library. + Parent pom for unirest packages http://github.com/Kong/unirest-java/ diff --git a/unirest/pom.xml b/unirest/pom.xml index 2f4395799..7b3b17732 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,9 +4,10 @@ com.konghq unirest-java-parent - 2.0.06-SNAPSHOT + 2.1.00-SNAPSHOT + Simplified, lightweight HTTP client library. unirest-java jar From 72a8279dbf74830bf5863b0adf0162779b11be60 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Mar 2019 10:37:14 -0500 Subject: [PATCH 0530/1769] closes #191. fixed somewhere along the way. File size does not change --- .../MultiPartFormPostingTest.java | 18 +++++++++++++++++- .../java/BehaviorTests/RequestCapture.java | 6 ++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java b/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java index 4b7771fd5..5e8dcbefa 100644 --- a/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java +++ b/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java @@ -53,7 +53,23 @@ public void testMultipart() throws Exception { } @Test - public void testMultipartContentType() throws Exception { + public void fileSizeDoesntChange() throws Exception { + File file = rezFile("/image.jpg"); + long size = file.length(); + + RequestCapture capture = Unirest.post(MockServer.POST) + .field("file", file) + .field("file2", new FileInputStream(file), "file2.jpg") + .asObject(RequestCapture.class) + .getBody() + .assertMultiPartContentType(); + + capture.getFile("image.jpg").assertSize(size); + capture.getFile("file2.jpg").assertSize(size); + } + + @Test + public void testMultipartContentType() { Unirest.post(MockServer.POST) .field("name", "Mark") .field("file", rezFile("/image.jpg"), "image/jpeg") diff --git a/unirest/src/test/java/BehaviorTests/RequestCapture.java b/unirest/src/test/java/BehaviorTests/RequestCapture.java index 5d037d521..08096499f 100644 --- a/unirest/src/test/java/BehaviorTests/RequestCapture.java +++ b/unirest/src/test/java/BehaviorTests/RequestCapture.java @@ -130,6 +130,7 @@ public void buildFilePart(Part part) throws IOException { file.type = part.getContentType(); file.inputName = part.getName(); file.fileType = part.getContentType(); + file.size = part.getSize(); file.body = TestUtil.toString(part.getInputStream()); file.headers = extractHeaders(part); @@ -299,6 +300,7 @@ public static class FormPart { public String inputName; public String body; public String fileType; + public long size; @JsonIgnore @@ -324,6 +326,10 @@ public FormPart assertFileName(String s) { assertEquals(s, fileName); return this; } + + public void assertSize(long expected) { + assertEquals(expected, this.size); + } } } From 62424ff938f35abf3f7f84cbb0d849f686dcaf23 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Mar 2019 14:31:39 -0500 Subject: [PATCH 0531/1769] update docs --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 479783541..b8d4b9c78 100644 --- a/README.md +++ b/README.md @@ -226,6 +226,7 @@ Unirest config allows easy access to build a configuration just like you would b | ```enableCookieManagement(boolean)``` | toggle accepting and storing cookies | true | | ```automaticRetries(boolean)``` | toggle disabling automatic retries (up to 4 times) for socket timeouts | true | | ```verifySsl(boolean)``` |toggle enforcing SSL | true | +| ```addShutdownHook(boolean)``` | toggle to add the clients to the system shutdown hooks automatically | false | From 63a6a5adb8faea2ed983b0271c0e104f40a2162a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Mar 2019 14:33:43 -0500 Subject: [PATCH 0532/1769] bump checkstyle for security issue in the object mapper projects --- object-mapper-gson/pom.xml | 4 ++-- object-mapper-jackson/pom.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/object-mapper-gson/pom.xml b/object-mapper-gson/pom.xml index a1333476a..870b273b2 100644 --- a/object-mapper-gson/pom.xml +++ b/object-mapper-gson/pom.xml @@ -88,12 +88,12 @@ org.apache.maven.plugins maven-checkstyle-plugin - 2.13 + 2.17 com.puppycrawl.tools checkstyle - 5.9 + 8.18 diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index a79255c55..6666f196f 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -89,12 +89,12 @@ org.apache.maven.plugins maven-checkstyle-plugin - 2.13 + 2.17 com.puppycrawl.tools checkstyle - 5.9 + 8.18 From eb4c0bdae9f65aa45442122ca823dcf796a8686c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Mar 2019 14:35:27 -0500 Subject: [PATCH 0533/1769] fix link --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b8d4b9c78..be03af201 100644 --- a/README.md +++ b/README.md @@ -63,9 +63,9 @@ The placeholder's format is as easy as: `{custom_name}` ### Advanced Object Mapping with Jackson, GSON, JAX-B or others Before an `asObject(Class)` or a `.body(Object)` invocation, is necessary to provide a custom implementation of the `ObjectMapper` interface. This should be done only the first time, as the instance of the ObjectMapper will be shared globally. -Unirest offers a few plug-ins implementing popular object mappers like Jackson and Gson. See [mvn central](https://mvnrepository.com/artifact/com.kong) for details. - -For example, serializing Json from\to Object using the popular Jackson ObjectMapper takes only few lines of code. +Unirest offers a few plug-ins implementing popular object mappers like Jackson and Gson. See [mvn central](https://mvnrepository.com/artifact/com.konghq) for details. +nes of code. +For example, serializing Json from\to Object using the popular Jackson ObjectMapper takes only few li ```java // Only one time From 9c2a2e57bd7654fd4195be8d9ca696bb2fe4d122 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Mar 2019 16:24:34 -0500 Subject: [PATCH 0534/1769] [maven-release-plugin] prepare release v2.1.00 --- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index d93673da0..cf43825ea 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.1.00-SNAPSHOT + 2.1.00 unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -31,7 +31,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - HEAD + v2.1.00 diff --git a/unirest/pom.xml b/unirest/pom.xml index 7b3b17732..39e536d3a 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.1.00-SNAPSHOT + 2.1.00 Simplified, lightweight HTTP client library. From 4ffcdd04c2ab78291099a8183d14548cbb552887 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Mar 2019 16:24:43 -0500 Subject: [PATCH 0535/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index cf43825ea..1ef004af1 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.1.00 + 2.1.01-SNAPSHOT unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -31,7 +31,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - v2.1.00 + HEAD diff --git a/unirest/pom.xml b/unirest/pom.xml index 39e536d3a..a97e6e2a0 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.1.00 + 2.1.01-SNAPSHOT Simplified, lightweight HTTP client library. From 43ff4b12c00f6f2cc5bc3f8844e16f9e36ac6190 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 21 Mar 2019 19:49:34 -0500 Subject: [PATCH 0536/1769] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index be03af201..ebad8741f 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ We are looking for official maintainers, check out issue [#252](https://github.c com.konghq unirest-java - 2.0.05 + 2.1.00 ``` From 2c0521939d50dd30cf1573ec26e21be3ddfb02cd Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 23 Mar 2019 07:35:51 -0500 Subject: [PATCH 0537/1769] addresses #260 can config a default basicAuth --- CHANGELOG.md | 5 +++- README.md | 1 + .../main/java/kong/unirest/BaseRequest.java | 2 +- .../src/main/java/kong/unirest/Config.java | 11 +++++++ unirest/src/main/java/kong/unirest/Util.java | 5 ++++ .../test/java/BehaviorTests/HeaderTest.java | 29 +++++++++++++++++++ 6 files changed, 51 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cabaa6a21..a4a8ccf31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ -## 2.1.00 (pending) +## 2.1.01 +* #260 add option to configure a default basic auth header + +## 2.1.00 * #259 optionally flag the config to auto register the clients with shutdownhooks. * #165 allow forcing a simple url-encoded param POST/PUT to be multipart. This adds a new method to the body interface so bumping the minor. diff --git a/README.md b/README.md index ebad8741f..f94618d70 100644 --- a/README.md +++ b/README.md @@ -222,6 +222,7 @@ Unirest config allows easy access to build a configuration just like you would b | ```setDefaultHeader(String, Supplier)``` | Sets a default header by supplier. Good for setting trace tokens for microservice architectures. Will overwrite if it exists | | | ```addDefaultHeader(String, String)``` | Adds a default header. Multiple for the same name can exist | | | ```addDefaultHeader(String, Supplier)``` | Add a default header by supplier. Good for setting trace tokens for microservice architectures. | | +| ```setDefaultBasicAuth(String, String)``` | Add a default Basic Auth Header | | | ```followRedirects(boolean)``` | toggle following redirects | true | | ```enableCookieManagement(boolean)``` | toggle accepting and storing cookies | true | | ```automaticRetries(boolean)``` | toggle disabling automatic retries (up to 4 times) for socket timeouts | true | diff --git a/unirest/src/main/java/kong/unirest/BaseRequest.java b/unirest/src/main/java/kong/unirest/BaseRequest.java index 564036b47..bdc509a48 100644 --- a/unirest/src/main/java/kong/unirest/BaseRequest.java +++ b/unirest/src/main/java/kong/unirest/BaseRequest.java @@ -75,7 +75,7 @@ public R routeParam(Map params) { @Override public R basicAuth(String username, String password) { - header("Authorization", "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes())); + this.headers.replace("Authorization", Util.toBasicAuthValue(username, password)); return (R)this; } diff --git a/unirest/src/main/java/kong/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java index 106e07ed4..15f54d9e3 100644 --- a/unirest/src/main/java/kong/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -250,6 +250,17 @@ public Config clearDefaultHeaders() { return this; } + /** + * Default basic auth credentials + * @param username the username + * @param password the password + * @return this config object + */ + public Config setDefaultBasicAuth(String username, String password) { + ers.add("Authorization", Util.toBasicAuthValue(username, password)); + return this; + } + /** * Set default header to appear on all requests * diff --git a/unirest/src/main/java/kong/unirest/Util.java b/unirest/src/main/java/kong/unirest/Util.java index 8d4b0e277..b88aa6bb2 100644 --- a/unirest/src/main/java/kong/unirest/Util.java +++ b/unirest/src/main/java/kong/unirest/Util.java @@ -27,6 +27,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.util.Base64; import java.util.Optional; import java.util.stream.Stream; @@ -55,4 +56,8 @@ static String encode(String input) { static boolean isNullOrEmpty(String s) { return s == null || s.trim().isEmpty(); } + + public static String toBasicAuthValue(String username, String password) { + return "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes()); + } } diff --git a/unirest/src/test/java/BehaviorTests/HeaderTest.java b/unirest/src/test/java/BehaviorTests/HeaderTest.java index 592ff836f..3733cbff6 100644 --- a/unirest/src/test/java/BehaviorTests/HeaderTest.java +++ b/unirest/src/test/java/BehaviorTests/HeaderTest.java @@ -163,6 +163,35 @@ public void basicAuthOnPosts() { .assertBasicAuth("user", "test"); } + @Test + public void canSetDefaultBasicAuth() { + Unirest.config().setDefaultBasicAuth("user", "test"); + + Unirest.post(MockServer.POST) + .asObject(RequestCapture.class) + .getBody() + .assertHeader("Authorization", "Basic dXNlcjp0ZXN0") + .assertBasicAuth("user", "test"); + } + + @Test + public void canOverrideDefaultBasicAuth() { + Unirest.config().setDefaultBasicAuth("bob", "pass"); + + Unirest.post(MockServer.POST) + .basicAuth("user", "test") + .asObject(RequestCapture.class) + .getBody() + .assertHeader("Authorization", "Basic dXNlcjp0ZXN0") + .assertBasicAuth("user", "test"); + + Unirest.post(MockServer.POST) + .asObject(RequestCapture.class) + .getBody() + .assertHeader("Authorization", "Basic Ym9iOnBhc3M=") + .assertBasicAuth("bob", "pass"); + } + @Test public void willNotCacheBasicAuth() { Unirest.get(MockServer.GET) From 987dd3dc6f90bc08589521af9cc3d973ad4a33b4 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 23 Mar 2019 07:43:43 -0500 Subject: [PATCH 0538/1769] [maven-release-plugin] prepare release v2.1.01 --- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 1ef004af1..578eaa583 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.1.01-SNAPSHOT + 2.1.01 unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -31,7 +31,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - HEAD + v2.1.01 diff --git a/unirest/pom.xml b/unirest/pom.xml index a97e6e2a0..ef9925743 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.1.01-SNAPSHOT + 2.1.01 Simplified, lightweight HTTP client library. From 0470fc09d84e864e4c1f593a5289795ce1a23d6b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 23 Mar 2019 07:43:51 -0500 Subject: [PATCH 0539/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 578eaa583..2985b81b7 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.1.01 + 2.1.02-SNAPSHOT unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -31,7 +31,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - v2.1.01 + HEAD diff --git a/unirest/pom.xml b/unirest/pom.xml index ef9925743..155713828 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.1.01 + 2.1.02-SNAPSHOT Simplified, lightweight HTTP client library. From 0fefdf81ac15a4dda2f2c1d3432a472cdab03be9 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 23 Mar 2019 07:48:01 -0500 Subject: [PATCH 0540/1769] can only have one basic auth header on the config --- unirest/src/main/java/kong/unirest/Config.java | 16 ++++++++-------- .../src/test/java/BehaviorTests/HeaderTest.java | 1 + 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/unirest/src/main/java/kong/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java index 15f54d9e3..509889967 100644 --- a/unirest/src/main/java/kong/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -54,7 +54,7 @@ public class Config { private Optional objectMapper = Optional.empty(); private List interceptors = new ArrayList<>(); - private Headers ers; + private Headers headers; private Proxy proxy; private int connectionTimeout; private int socketTimeout; @@ -78,7 +78,7 @@ public Config() { private void setDefaults(){ interceptors.clear(); proxy = null; - ers = new Headers(); + headers = new Headers(); connectionTimeout = DEFAULT_CONNECTION_TIMEOUT; socketTimeout = DEFAULT_SOCKET_TIMEOUT; maxTotal = DEFAULT_MAX_CONNECTIONS; @@ -246,7 +246,7 @@ public Config concurrency(int total, int perRoute) { * @return this config object */ public Config clearDefaultHeaders() { - ers.clear(); + headers.clear(); return this; } @@ -257,7 +257,7 @@ public Config clearDefaultHeaders() { * @return this config object */ public Config setDefaultBasicAuth(String username, String password) { - ers.add("Authorization", Util.toBasicAuthValue(username, password)); + headers.replace("Authorization", Util.toBasicAuthValue(username, password)); return this; } @@ -269,7 +269,7 @@ public Config setDefaultBasicAuth(String username, String password) { * @return this config object */ public Config setDefaultHeader(String name, String value) { - ers.replace(name, value); + headers.replace(name, value); return this; } @@ -282,7 +282,7 @@ public Config setDefaultHeader(String name, String value) { * @return this config object */ public Config setDefaultHeader(String name, Supplier value) { - ers.add(name, value); + headers.add(name, value); return this; } @@ -294,7 +294,7 @@ public Config setDefaultHeader(String name, Supplier value) { * @return this config object */ public Config addDefaultHeader(String name, String value) { - ers.add(name, value); + headers.add(name, value); return this; } @@ -413,7 +413,7 @@ public Config addShutdownHook(boolean value) { * @return Headers */ public Headers getDefaultHeaders() { - return ers; + return headers; } /** diff --git a/unirest/src/test/java/BehaviorTests/HeaderTest.java b/unirest/src/test/java/BehaviorTests/HeaderTest.java index 3733cbff6..8d0076050 100644 --- a/unirest/src/test/java/BehaviorTests/HeaderTest.java +++ b/unirest/src/test/java/BehaviorTests/HeaderTest.java @@ -165,6 +165,7 @@ public void basicAuthOnPosts() { @Test public void canSetDefaultBasicAuth() { + Unirest.config().setDefaultBasicAuth("bob", "pass"); Unirest.config().setDefaultBasicAuth("user", "test"); Unirest.post(MockServer.POST) From fb95edf802a30c0a736ed08489dcfa0ad1975bc0 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 23 Mar 2019 11:34:10 -0500 Subject: [PATCH 0541/1769] merge the entity body tests --- .../test/java/BehaviorTests/SendBodyTest.java | 134 ------------------ .../BehaviorTests/UniBodyPostingTest.java | 103 ++++++++++++++ 2 files changed, 103 insertions(+), 134 deletions(-) delete mode 100644 unirest/src/test/java/BehaviorTests/SendBodyTest.java diff --git a/unirest/src/test/java/BehaviorTests/SendBodyTest.java b/unirest/src/test/java/BehaviorTests/SendBodyTest.java deleted file mode 100644 index fe4cce34b..000000000 --- a/unirest/src/test/java/BehaviorTests/SendBodyTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package BehaviorTests; - -import kong.unirest.JsonNode; -import kong.unirest.Unirest; -import kong.unirest.UnirestConfigException; -import org.json.JSONArray; -import org.json.JSONObject; -import org.junit.Test; -import kong.unirest.MockCallback; - -import static kong.unirest.TestUtil.assertException; - -public class SendBodyTest extends BddTest { - @Test - public void testPostRawBody() { - String sourceString = "'\"@こんにちは-test-123-" + Math.random(); - byte[] sentBytes = sourceString.getBytes(); - - Unirest.post(MockServer.POST) - .body(sentBytes) - .asObject(RequestCapture.class) - .getBody() - .asserBody(sourceString); - } - - @Test - public void testAsyncCustomContentType() { - Unirest.post(MockServer.POST) - .header("accept", "application/json") - .header("Content-Type", "application/json") - .body("{\"hello\":\"world\"}") - .asJsonAsync(new MockCallback<>(this, r -> parse(r) - .asserBody("{\"hello\":\"world\"}") - .assertHeader("Content-Type", "application/json")) - ); - - assertAsync(); - } - - - @Test - public void postAPojoObjectUsingTheMapper() { - GetResponse postResponseMock = new GetResponse(); - postResponseMock.setUrl(MockServer.POST); - - Unirest.post(postResponseMock.getUrl()) - .header("accept", "application/json") - .header("Content-Type", "application/json") - .body(postResponseMock) - .asObject(RequestCapture.class) - .getBody() - .asserBody("{\"url\":\"http://localhost:4567/post\"}"); - } - - @Test - public void testDeleteBody() { - String body = "{\"jsonString\":{\"members\":\"members1\"}}"; - Unirest.delete(MockServer.DELETE) - .body(body) - .asObject(RequestCapture.class) - .getBody() - .asserBody(body); - } - - @Test - public void postBodyAsJson() { - JSONObject body = new JSONObject(); - body.put("krusty","krab"); - - Unirest.post(MockServer.POST) - .body(body) - .asObject(RequestCapture.class) - .getBody() - .asserBody("{\"krusty\":\"krab\"}"); - } - - @Test - public void postBodyAsJsonArray() { - JSONArray body = new JSONArray(); - body.put(0, "krusty"); - body.put(1, "krab"); - - Unirest.post(MockServer.POST) - .body(body) - .asObject(RequestCapture.class) - .getBody() - .asserBody("[\"krusty\",\"krab\"]"); - } - - @Test - public void postBodyAsJsonNode() { - JsonNode body = new JsonNode("{\"krusty\":\"krab\"}"); - - Unirest.post(MockServer.POST) - .body(body) - .asObject(RequestCapture.class) - .getBody() - .asserBody("{\"krusty\":\"krab\"}"); - } - - @Test - public void cantPostObjectWithoutObjectMapper(){ - Unirest.config().setObjectMapper(null); - - assertException(() -> Unirest.post(MockServer.POST).body(new Foo("die")), - UnirestConfigException.class, - "No Object Mapper Configured. Please config one with Unirest.config().setObjectMapper"); - } -} diff --git a/unirest/src/test/java/BehaviorTests/UniBodyPostingTest.java b/unirest/src/test/java/BehaviorTests/UniBodyPostingTest.java index 41c10dced..a139dbdc7 100644 --- a/unirest/src/test/java/BehaviorTests/UniBodyPostingTest.java +++ b/unirest/src/test/java/BehaviorTests/UniBodyPostingTest.java @@ -25,11 +25,18 @@ package BehaviorTests; +import kong.unirest.JsonNode; +import kong.unirest.MockCallback; import kong.unirest.Unirest; +import kong.unirest.UnirestConfigException; +import org.json.JSONArray; +import org.json.JSONObject; import org.junit.Test; import java.nio.charset.StandardCharsets; +import static kong.unirest.TestUtil.assertException; + public class UniBodyPostingTest extends BddTest { @Test public void canSetCharsetOfBody(){ @@ -54,4 +61,100 @@ public void canSetCharsetOfBodyAfterMovingToBody(){ .asserBody("foo") .assertCharset(StandardCharsets.US_ASCII); } + + @Test + public void testPostRawBody() { + String sourceString = "'\"@こんにちは-test-123-" + Math.random(); + byte[] sentBytes = sourceString.getBytes(); + + Unirest.post(MockServer.POST) + .body(sentBytes) + .asObject(RequestCapture.class) + .getBody() + .asserBody(sourceString); + } + + @Test + public void testAsyncCustomContentType() { + Unirest.post(MockServer.POST) + .header("accept", "application/json") + .header("Content-Type", "application/json") + .body("{\"hello\":\"world\"}") + .asJsonAsync(new MockCallback<>(this, r -> parse(r) + .asserBody("{\"hello\":\"world\"}") + .assertHeader("Content-Type", "application/json")) + ); + + assertAsync(); + } + + + @Test + public void postAPojoObjectUsingTheMapper() { + GetResponse postResponseMock = new GetResponse(); + postResponseMock.setUrl(MockServer.POST); + + Unirest.post(postResponseMock.getUrl()) + .header("accept", "application/json") + .header("Content-Type", "application/json") + .body(postResponseMock) + .asObject(RequestCapture.class) + .getBody() + .asserBody("{\"url\":\"http://localhost:4567/post\"}"); + } + + @Test + public void testDeleteBody() { + String body = "{\"jsonString\":{\"members\":\"members1\"}}"; + Unirest.delete(MockServer.DELETE) + .body(body) + .asObject(RequestCapture.class) + .getBody() + .asserBody(body); + } + + @Test + public void postBodyAsJson() { + JSONObject body = new JSONObject(); + body.put("krusty","krab"); + + Unirest.post(MockServer.POST) + .body(body) + .asObject(RequestCapture.class) + .getBody() + .asserBody("{\"krusty\":\"krab\"}"); + } + + @Test + public void postBodyAsJsonArray() { + JSONArray body = new JSONArray(); + body.put(0, "krusty"); + body.put(1, "krab"); + + Unirest.post(MockServer.POST) + .body(body) + .asObject(RequestCapture.class) + .getBody() + .asserBody("[\"krusty\",\"krab\"]"); + } + + @Test + public void postBodyAsJsonNode() { + JsonNode body = new JsonNode("{\"krusty\":\"krab\"}"); + + Unirest.post(MockServer.POST) + .body(body) + .asObject(RequestCapture.class) + .getBody() + .asserBody("{\"krusty\":\"krab\"}"); + } + + @Test + public void cantPostObjectWithoutObjectMapper(){ + Unirest.config().setObjectMapper(null); + + assertException(() -> Unirest.post(MockServer.POST).body(new Foo("die")), + UnirestConfigException.class, + "No Object Mapper Configured. Please config one with Unirest.config().setObjectMapper"); + } } From d766f9e528e295ed086044081707512a66744f32 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 23 Mar 2019 08:23:00 -0500 Subject: [PATCH 0542/1769] add test certificates --- .../resources/certs/badssl.com-client.p12 | Bin 0 -> 2789 bytes .../resources/certs/badssl.com-client.pem | 64 ++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 unirest/src/test/resources/certs/badssl.com-client.p12 create mode 100644 unirest/src/test/resources/certs/badssl.com-client.pem diff --git a/unirest/src/test/resources/certs/badssl.com-client.p12 b/unirest/src/test/resources/certs/badssl.com-client.p12 new file mode 100644 index 0000000000000000000000000000000000000000..f021abaa109ba07b5e2ef4f767e8258f01015ecc GIT binary patch literal 2789 zcmY+^c{CJ^8U}Da0Nd}U{7(Zwh(e(MUf=>i5HJwO=vpAdC4MlT zot=X%ECS57kA1eHY+Px{NuI=6Nz<+xt7utjqIAlpw`z2WqK~Emyy=b|K}qx!U@mPN zqV}|Pp`}d{X~a`$Z17?_QAEgR{_^ExP@$Y={uq-fj&IRp=P=ggyrRf=q(5GzhUm6k zF}imLOKK&hmH=5LKX|Xqprn>Zx8|bz6)n5;f3X;c5A-4HBS^-w{H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HC=Cg?ar#$cALeWwuWlF3`^+ldnAulBj7Gh2%R zZpEqQ(Q@{HglsgcqXk=WU$U7BtDM2;T#PiapzCyv28acV@d?q$@wjWXz?mk0Z&5C3 zibs+qpM-tqME#2>5kiS}xIe^v())aZYG9u-he@Z$6CAMk{&Var^R|;ar4rc<4syIu z-?d5QTd`^l{&;Sk{Y6hB{_j5a@%exn`(|5kGpsSA5T3F;(U8CEJdW zWUjxqO5)G$ZA;-&kQDKaX5(WApcWM(pbh%OX9A3iC{o8x@A0=FuDYXg%(j;it}S zFEVpNMnXYz2q}Y*`mc_h0!Tp+zZ|3NL2>5YjR}I-W>dMIfhM(U7J)=aA~+#nMHrA> p7|aIZM`FHY+spu*!Y}*F4khI~9?~r?gE+Lj3Q#k%U!DI}@?WRkI70vc literal 0 HcmV?d00001 diff --git a/unirest/src/test/resources/certs/badssl.com-client.pem b/unirest/src/test/resources/certs/badssl.com-client.pem new file mode 100644 index 000000000..b71c24e1b --- /dev/null +++ b/unirest/src/test/resources/certs/badssl.com-client.pem @@ -0,0 +1,64 @@ +Bag Attributes + localKeyID: 28 D8 AB 79 A7 97 6F EE D3 6D 1D F0 B9 AC 3D 3F 36 B7 C4 DF +subject=/C=US/ST=California/L=San Francisco/O=BadSSL/CN=BadSSL Client Certificate +issuer=/C=US/ST=California/L=San Francisco/O=BadSSL/CN=BadSSL Client Root Certificate Authority +-----BEGIN CERTIFICATE----- +MIIEnTCCAoWgAwIBAgIJAPC7KMFjfslXMA0GCSqGSIb3DQEBCwUAMH4xCzAJBgNV +BAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1TYW4gRnJhbmNp +c2NvMQ8wDQYDVQQKDAZCYWRTU0wxMTAvBgNVBAMMKEJhZFNTTCBDbGllbnQgUm9v +dCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMTcxMTE2MDUzNjMzWhcNMTkxMTE2 +MDUzNjMzWjBvMQswCQYDVQQGEwJVUzETMBE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GhkjT7Qm +2EUBQNNMNXC3g/GXTdXOgqqjW5GXahI8Z6Q4OYN6xZwuEhizwKkgojwaww2YgYT9 +MJXciJZWr3QXvFdBH7m0zwpKgQ1wm6j3yeyuRphq2lEtU3OQl55A3tXtvqyMXsxk +xMCCNQdmKQt0WYmMS3Xj/AfAY2sjCWziDflvW5mGCUjSYdZ+r3JIIF4m/FNCIO1d +Ioacp9qb0qL9duFlVHtFiPgoKrEdJaNVUL7NG9ppF8pR +-----END CERTIFICATE----- +Bag Attributes + localKeyID: 28 D8 AB 79 A7 97 6F EE D3 6D 1D F0 B9 AC 3D 3F 36 B7 C4 DF +Key Attributes: +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: DES-EDE3-CBC,8906E5B87ECB8682 + +cY/EOwDILOiCPzyqZanlrhrb5h+fCnS/mHhsNme0Zyrk9udaBZKwxkPtUC6rJZ9/ +rX4HQch9tuVy992CDe1bl4l+3EfqshUhxtivG8GHiFj7TNo5Ia9LaE+KwugB2rdX +J8odwWmwE8Y9TX09WyPKHikjg2nAOgN3Gf+GeJW6fL9xcEVmIgDyX6kBusQYWIQ3 +PMYqyaBhL8UCZVRpiUINTrJXCnNAI4t6K0i4J+hjyekRnA5PQ+A/0+C9J+kQW+wj +uDWkQtyyBNsscGhXrL9ita7/UtJa+/aS99FLTnxD+fqyU4svzNIQWmZBcIxb9Lxq +LHcxNaQCtFycD1iU8Tsq9HY1apKrdPBjaaYne6qCg8nIPWpo3gWoffu+R3EfVcdZ +lNgKL3Cd1oCJy/Vcz+u0iayCPT0zfP1dLlGpL2U7L7+8pJ88FbXt/F1th9QEUp5z +dISg/6ukHyIkfXwoxYXkin9fW2clo99+fuXkJaVPEOnRmr0+kf+1S0Uw8fkete4v +f0IUxUwydxCXFN2ZFZ6o/LFLMLRfNAqGSGjqGeY1L0ILkJPo3KBqlmUhl2FIROOW +4rSrfpujjsOqlPncJ9apW04RnqhY7t0YOtp0rMK+gIDteKD+utCyh+UAetiiqTiB +ZDup/kzPNDClSDU6cgRbZUf/Nt8RiBcVeX4TfDb1eEhqV0BTHrLOBo8yp6ETDlJM +CKO5i9kb5fUaFPFD5VTc5rnY4qV/hUj/uyAVK757A+m9nn7fYOMeaRAgOEvChYSf +Qam0VPgpJxfjsaw0BFOMyfsHNJqvTbPXA+hIKD3fhP6jNcgpKTLHJp89J4XUOeIR +tvh/u7vljhVygP7ZQOpCoX1xSMdJMO7Qhrh3O/2fq/EJertJD2PQ0Zgqb8wosHn/ +Aw9VWT6849jL55Xd5l3zXmI9vU0Le4HP3NstV9jjpcp91dU9yfQpcuIo8U26u+4r +LR1VmhZJjo7FBOpyJZ1Jb3vyp+nPI+tH214DhM9LuXvMbf3ORhXTMOlqSABUmo/+ +t+QjVfcEuhFR9CTVWZUIXflJk/euvzqTQdm8iz7JuFzQOhoXjiPIq0GqtCk10SeL +zqHz1s0TZNcrZyzkmiHuWjGVwHN/XZA3dW67uj522hD7EzucKE9CoCdJ3f4JEWmS +CQwEbba6SKAR6iBlouIYLVdkOBgimGiF13rCwvdN234hQeJT8Wc87iG+uDw73PJL ++amDglATH4wIpBk4xmjh/GTRDK0yH9jp7Dv9iwShbjk0yOuoz5yDn8VPqRIREn8d +9sAaiFUUQ/9XrdlA5F+49OznClDWLKHK8sSAAFyrzvoCcqseSKbvLyrlHGT0fiot +obgDu/W+K2xEOjQeaIyVI5J1qOi6k78fyv1vutjEs6mcTRtDAIxi+V5y5lXUEj0v +OWYsbp9yb8Yq602vV8UYSROd+1xdE+7Td3ENLYE7MnVqju7a5NRfnZYgAU03NgIf +nHGFZC6/tMz/PXS+D0dqzXxwEjH5JQzGBjvSQHK09gHtCfcyshMQQWtXZGQViZX8 +QdYXiaq67nJex0DjWTt56a4EgsdYC1J28bJ3GAkrWNkDFRmlx49zvA== +-----END RSA PRIVATE KEY----- From f9ab7fb2c651e43b6e3bc0ffa5df563a159e8247 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 23 Mar 2019 09:32:26 -0500 Subject: [PATCH 0543/1769] rename test --- .../{DisableSecurityTest.java => CertificateTests.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename unirest/src/test/java/BehaviorTests/{DisableSecurityTest.java => CertificateTests.java} (98%) diff --git a/unirest/src/test/java/BehaviorTests/DisableSecurityTest.java b/unirest/src/test/java/BehaviorTests/CertificateTests.java similarity index 98% rename from unirest/src/test/java/BehaviorTests/DisableSecurityTest.java rename to unirest/src/test/java/BehaviorTests/CertificateTests.java index df5b43180..2f0e1abcf 100644 --- a/unirest/src/test/java/BehaviorTests/DisableSecurityTest.java +++ b/unirest/src/test/java/BehaviorTests/CertificateTests.java @@ -39,7 +39,7 @@ import static org.junit.Assert.assertEquals; @Ignore // dont normally run these because they depend on badssl.com -public class DisableSecurityTest extends BddTest { +public class CertificateTests extends BddTest { @Test public void badName() { fails("https://wrong.host.badssl.com/", From 1496ba891d022d903bdeb9a4228305f8be223676 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 23 Mar 2019 10:20:30 -0500 Subject: [PATCH 0544/1769] add support for client certificates --- build/suppressions.xml | 2 +- .../src/main/java/kong/unirest/Config.java | 25 +++- .../kong/unirest/apache/ApacheClient.java | 56 ++------ .../kong/unirest/apache/SecurityConfig.java | 136 ++++++++++++++++++ .../java/BehaviorTests/CertificateTests.java | 92 +++++++++++- 5 files changed, 262 insertions(+), 49 deletions(-) create mode 100644 unirest/src/main/java/kong/unirest/apache/SecurityConfig.java diff --git a/build/suppressions.xml b/build/suppressions.xml index cb3791156..dec6b7797 100644 --- a/build/suppressions.xml +++ b/build/suppressions.xml @@ -5,5 +5,5 @@ "http://www.puppycrawl.com/dtds/suppressions_1_0.dtd"> - + \ No newline at end of file diff --git a/unirest/src/main/java/kong/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java index 509889967..731018c14 100644 --- a/unirest/src/main/java/kong/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -32,6 +32,7 @@ import org.apache.http.nio.client.HttpAsyncClient; import java.nio.charset.StandardCharsets; +import java.security.KeyStore; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -70,6 +71,8 @@ public class Config { private boolean automaticRetries; private boolean verifySsl = true; private boolean addShutdownHook = false; + private KeyStore keystore; + private String keystorePassword; public Config() { setDefaults(); @@ -203,6 +206,18 @@ public Config setObjectMapper(ObjectMapper om) { return this; } + /** + * Set a custom keystore + * + * @param store the keystore to use for a custom ssl context + * @return this config object + */ + public Config clientCertificateStore(KeyStore store, String password) { + this.keystore = store; + this.keystorePassword = password; + return this; + } + /** * Set the connection timeout * @@ -513,8 +528,8 @@ private void verifyIsOn(AsyncClient value) { } } - // Accessors for unirest. + public boolean getEnabledCookieManagement() { return cookieManagement; } @@ -539,6 +554,14 @@ public int getSocketTimeout() { return socketTimeout; } + public KeyStore getKeystore() { + return this.keystore; + } + + public String getKeyStorePassword(){ + return this.keystorePassword; + } + public ObjectMapper getObjectMapper() { return objectMapper.orElseThrow(() -> new UnirestException("No Object Mapper Configured. Please config one with Unirest.config().setObjectMapper")); } diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java index 03a01aaaa..93bc1f1d5 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java @@ -28,16 +28,10 @@ import kong.unirest.*; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpRequestBase; -import org.apache.http.config.RegistryBuilder; -import org.apache.http.conn.socket.ConnectionSocketFactory; -import org.apache.http.conn.socket.PlainConnectionSocketFactory; -import org.apache.http.conn.ssl.NoopHostnameVerifier; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.conn.ssl.TrustStrategy; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; -import org.apache.http.ssl.SSLContextBuilder; import java.io.Closeable; import java.util.Optional; @@ -49,14 +43,16 @@ public class ApacheClient extends BaseApacheClient implements Client { private final Config config; private final PoolingHttpClientConnectionManager manager; private final SyncIdleConnectionMonitorThread syncMonitor; + private final SecurityConfig security; public ApacheClient(Config config) { this.config = config; - manager = createManager(); + security = new SecurityConfig(config); + manager = security.createManager(); syncMonitor = new SyncIdleConnectionMonitorThread(manager); syncMonitor.start(); - HttpClientBuilder cb = HttpClientBuilder.create() + HttpClientBuilder cb = HttpClients.custom() .setDefaultRequestConfig(RequestOptions.toRequestConfig(config)) .setDefaultCredentialsProvider(toApacheCreds(config.getProxy())) .setConnectionManager(manager) @@ -66,17 +62,16 @@ public ApacheClient(Config config) { client = cb.build(); } + private void setOptions(HttpClientBuilder cb) { - if(!config.isVerifySsl()){ - disableSsl(cb); - } - if(!config.isAutomaticRetries()){ + security.configureSecurity(cb); + if (!config.isAutomaticRetries()) { cb.disableAutomaticRetries(); } - if(!config.isRequestCompressionOn()) { + if (!config.isRequestCompressionOn()) { cb.disableContentCompression(); } - if(config.useSystemProperties()){ + if (config.useSystemProperties()) { cb.useSystemProperties(); } if (!config.getFollowRedirects()) { @@ -86,41 +81,14 @@ private void setOptions(HttpClientBuilder cb) { cb.disableCookieManagement(); } config.getInterceptors().stream().forEach(cb::addInterceptorFirst); - if(config.shouldAddShutdownHook()){ + if (config.shouldAddShutdownHook()) { Runtime.getRuntime().addShutdownHook(new Thread(this::close, "Unirest Apache Client Shutdown Hook")); } } - private PoolingHttpClientConnectionManager createManager() { - try { - if (config.isVerifySsl()) { - return new PoolingHttpClientConnectionManager(); - } - return new PoolingHttpClientConnectionManager( - RegistryBuilder.create() - .register("http", PlainConnectionSocketFactory.INSTANCE) - .register("https", new SSLConnectionSocketFactory(new SSLContextBuilder() - .loadTrustMaterial(null, (x509CertChain, authType) -> true) - .build(), - NoopHostnameVerifier.INSTANCE)) - .build() - ); - }catch (Exception e){ - throw new UnirestConfigException(e); - } - } - - private void disableSsl(HttpClientBuilder cb) { - try { - cb.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE); - cb.setSSLContext(new SSLContextBuilder().loadTrustMaterial(null, (TrustStrategy) (arg0, arg1) -> true).build()); - }catch (Exception e){ - throw new UnirestConfigException(e); - } - } - public ApacheClient(HttpClient httpClient, Config config, PoolingHttpClientConnectionManager clientManager, SyncIdleConnectionMonitorThread connMonitor) { this.client = httpClient; + this.security = new SecurityConfig(config); this.config = config; this.manager = clientManager; this.syncMonitor = connMonitor; diff --git a/unirest/src/main/java/kong/unirest/apache/SecurityConfig.java b/unirest/src/main/java/kong/unirest/apache/SecurityConfig.java new file mode 100644 index 000000000..b3313aa8c --- /dev/null +++ b/unirest/src/main/java/kong/unirest/apache/SecurityConfig.java @@ -0,0 +1,136 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest.apache; + +import kong.unirest.Config; +import kong.unirest.UnirestConfigException; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; +import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.socket.PlainConnectionSocketFactory; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.TrustStrategy; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.ssl.SSLContextBuilder; +import org.apache.http.ssl.SSLContexts; + +import javax.net.ssl.SSLContext; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.util.Optional; + +class SecurityConfig { + private final Config config; + private SSLContext sslContext; + private SSLConnectionSocketFactory sslSocketFactory; + + + public SecurityConfig(Config config) { + this.config = config; + } + + public PoolingHttpClientConnectionManager createManager() { + return buildSocketFactory() + .map(PoolingHttpClientConnectionManager::new) + .orElseGet(PoolingHttpClientConnectionManager::new); + } + + private Optional> buildSocketFactory() { + try { + if (!config.isVerifySsl()) { + return Optional.of(createDisabledSSLContext()); + } else if (config.getKeystore() != null) { + return Optional.of(createCustomSslContext()); + } + } catch (Exception e) { + throw new UnirestConfigException(e); + } + + return Optional.empty(); + + } + private Registry createCustomSslContext() { + SSLConnectionSocketFactory socketFactory = getSocketFactory(); + return RegistryBuilder.create() + .register("https", socketFactory) + .register("http", PlainConnectionSocketFactory.INSTANCE) + .build(); + } + + private SSLConnectionSocketFactory getSocketFactory() { + if(sslSocketFactory == null) { + sslSocketFactory = new SSLConnectionSocketFactory(createSslContext(), new NoopHostnameVerifier()); + } + return sslSocketFactory; + } + + private Registry createDisabledSSLContext() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException { + return RegistryBuilder.create() + .register("http", PlainConnectionSocketFactory.INSTANCE) + .register("https", new SSLConnectionSocketFactory(new SSLContextBuilder() + .loadTrustMaterial(null, (x509CertChain, authType) -> true) + .build(), + NoopHostnameVerifier.INSTANCE)) + .build(); + } + private SSLContext createSslContext() { + if(sslContext == null) { + try { + char[] pass = Optional.ofNullable(config.getKeyStorePassword()) + .map(String::toCharArray) + .orElse(null); + sslContext = SSLContexts.custom() + .loadKeyMaterial(config.getKeystore(), pass) + .build(); + } catch (Exception e) { + throw new UnirestConfigException(e); + } + } + return sslContext; + } + + public void configureSecurity(HttpClientBuilder cb) { + if(config.getKeystore() != null){ + cb.setSSLContext(createSslContext()); + cb.setSSLSocketFactory(getSocketFactory()); + } + if (!config.isVerifySsl()) { + disableSsl(cb); + } + } + + private void disableSsl(HttpClientBuilder cb) { + try { + cb.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE); + cb.setSSLContext(new SSLContextBuilder().loadTrustMaterial(null, (TrustStrategy) (arg0, arg1) -> true).build()); + } catch (Exception e) { + throw new UnirestConfigException(e); + } + } +} diff --git a/unirest/src/test/java/BehaviorTests/CertificateTests.java b/unirest/src/test/java/BehaviorTests/CertificateTests.java index 2f0e1abcf..5a6e087cc 100644 --- a/unirest/src/test/java/BehaviorTests/CertificateTests.java +++ b/unirest/src/test/java/BehaviorTests/CertificateTests.java @@ -27,19 +27,97 @@ import kong.unirest.TestUtil; import kong.unirest.Unirest; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; +import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.socket.PlainConnectionSocketFactory; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.ssl.SSLContexts; +import org.apache.http.util.EntityUtils; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; +import javax.net.ssl.SSLContext; import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLPeerUnverifiedException; -import java.util.concurrent.ExecutionException; +import java.io.InputStream; +import java.security.KeyStore; import static org.junit.Assert.assertEquals; -@Ignore // dont normally run these because they depend on badssl.com +//@Ignore // dont normally run these because they depend on badssl.com public class CertificateTests extends BddTest { + + @Test + public void canDoClientCertificates() throws Exception { + Unirest.config().clientCertificateStore(readStore(), "badssl.com"); + + Unirest.get("https://client.badssl.com/") + .asString() + .ifFailure(r -> Assert.fail(r.getStatus() + " request failed " + r.getBody())) + .ifSuccess(r -> System.out.println(" woot "));; + } + + @Test + public void rawApacheClientCert() throws Exception { + SSLContext sslContext = SSLContexts.custom() + .loadKeyMaterial(readStore(), "badssl.com".toCharArray()) // use null as second param if you don't have a separate key password + .build(); + + HttpClient httpClient = HttpClients.custom().setSSLContext(sslContext).build(); + + HttpResponse response = httpClient.execute(new HttpGet("https://client.badssl.com/")); + assertEquals(200, response.getStatusLine().getStatusCode()); + HttpEntity entity = response.getEntity(); + + System.out.println("----------------------------------------"); + System.out.println(response.getStatusLine()); + EntityUtils.consume(entity); + } + + @Test + public void rawApacheWithConnectionManager() throws Exception { + SSLContext sc = SSLContexts.custom() + .loadKeyMaterial(readStore(), "badssl.com".toCharArray()) // use null as second param if you don't have a separate key password + .build(); + + SSLConnectionSocketFactory sslSocketFactory = + new SSLConnectionSocketFactory(sc, new NoopHostnameVerifier()); + + + Registry socketFactoryRegistry = + RegistryBuilder.create() + .register("https", sslSocketFactory) + .register("http", PlainConnectionSocketFactory.INSTANCE) + .build(); + + PoolingHttpClientConnectionManager cm = + new PoolingHttpClientConnectionManager(socketFactoryRegistry); + + CloseableHttpClient httpClient = + HttpClients.custom() + .setSSLSocketFactory(sslSocketFactory) + .setConnectionManager(cm) + .build(); + + Unirest.config().httpClient(httpClient); + + Unirest.get("https://client.badssl.com/") + .asString() + .ifFailure(r -> Assert.fail(r.getStatus() + " request failed " + r.getBody())) + .ifSuccess(r -> System.out.println(" woot ")); + + } + @Test public void badName() { fails("https://wrong.host.badssl.com/", @@ -128,4 +206,12 @@ private void canCallAsync(String url) { Assert.fail(e.getMessage()); } } + + private KeyStore readStore() throws Exception { + try (InputStream keyStoreStream = this.getClass().getResourceAsStream("/certs/badssl.com-client.p12")) { + KeyStore keyStore = KeyStore.getInstance("PKCS12"); + keyStore.load(keyStoreStream, "badssl.com".toCharArray()); + return keyStore; + } + } } From 8ef6ad306345b968ef4fee7e0efd763b9c6a75e8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 24 Mar 2019 17:14:29 -0500 Subject: [PATCH 0545/1769] allow configuring by file path --- .../src/main/java/kong/unirest/Config.java | 22 +++++++++++++++++++ unirest/src/main/java/kong/unirest/Util.java | 10 +++++++++ .../java/BehaviorTests/CertificateTests.java | 12 ++++++++++ 3 files changed, 44 insertions(+) diff --git a/unirest/src/main/java/kong/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java index 731018c14..f4662173a 100644 --- a/unirest/src/main/java/kong/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -31,6 +31,7 @@ import org.apache.http.client.HttpClient; import org.apache.http.nio.client.HttpAsyncClient; +import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.security.KeyStore; import java.util.ArrayList; @@ -91,6 +92,8 @@ private void setDefaults(){ requestCompressionOn = true; automaticRetries = true; verifySsl = true; + keystore = null; + keystorePassword = null; } /** @@ -210,6 +213,7 @@ public Config setObjectMapper(ObjectMapper om) { * Set a custom keystore * * @param store the keystore to use for a custom ssl context + * @param password the password for the store * @return this config object */ public Config clientCertificateStore(KeyStore store, String password) { @@ -218,6 +222,24 @@ public Config clientCertificateStore(KeyStore store, String password) { return this; } + /** + * Set a custom keystore via a file path. Must be a valid PKCS12 file + * + * @param fileLocation the path keystore to use for a custom ssl context + * @param password the password for the store + * @return this config object + */ + public Config clientCertificateStore(String fileLocation, String password) { + try (InputStream keyStoreStream = Util.getFileInputStream(fileLocation)) { + this.keystorePassword = password; + this.keystore = KeyStore.getInstance("PKCS12"); + this.keystore.load(keyStoreStream, keystorePassword.toCharArray()); + } catch (Exception e) { + throw new UnirestConfigException(e); + } + return this; + } + /** * Set the connection timeout * diff --git a/unirest/src/main/java/kong/unirest/Util.java b/unirest/src/main/java/kong/unirest/Util.java index b88aa6bb2..ab892297c 100644 --- a/unirest/src/main/java/kong/unirest/Util.java +++ b/unirest/src/main/java/kong/unirest/Util.java @@ -25,6 +25,8 @@ package kong.unirest; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Base64; @@ -60,4 +62,12 @@ static boolean isNullOrEmpty(String s) { public static String toBasicAuthValue(String username, String password) { return "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes()); } + + static FileInputStream getFileInputStream(String location){ + try { + return new FileInputStream(location); + } catch (FileNotFoundException e) { + throw new UnirestConfigException(e); + } + } } diff --git a/unirest/src/test/java/BehaviorTests/CertificateTests.java b/unirest/src/test/java/BehaviorTests/CertificateTests.java index 5a6e087cc..994490d28 100644 --- a/unirest/src/test/java/BehaviorTests/CertificateTests.java +++ b/unirest/src/test/java/BehaviorTests/CertificateTests.java @@ -49,6 +49,8 @@ import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLPeerUnverifiedException; +import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.security.KeyStore; @@ -67,6 +69,16 @@ public void canDoClientCertificates() throws Exception { .ifSuccess(r -> System.out.println(" woot "));; } + @Test + public void canLoadKeyStoreByPath() { + Unirest.config().clientCertificateStore("src/test/resources/certs/badssl.com-client.p12", "badssl.com"); + + Unirest.get("https://client.badssl.com/") + .asString() + .ifFailure(r -> Assert.fail(r.getStatus() + " request failed " + r.getBody())) + .ifSuccess(r -> System.out.println(" woot "));; + } + @Test public void rawApacheClientCert() throws Exception { SSLContext sslContext = SSLContexts.custom() From 566128266ce29226e355f4a618253c62dfe5749b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 24 Mar 2019 17:17:38 -0500 Subject: [PATCH 0546/1769] update docs --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4a8ccf31..8a60db8e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.1.02 +* #120 support client certificates. You can pass in an entire keystore or just the path to it in the config. +* part of #260: only support a single basic auth header. + ## 2.1.01 * #260 add option to configure a default basic auth header From ff5ea3b641415660adfcabca17566f52b23e807a Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 24 Mar 2019 17:27:06 -0500 Subject: [PATCH 0547/1769] [maven-release-plugin] prepare release v2.1.02 --- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 2985b81b7..3cd32713f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.1.02-SNAPSHOT + 2.1.02 unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -31,7 +31,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - HEAD + v2.1.02 diff --git a/unirest/pom.xml b/unirest/pom.xml index 155713828..56d6681a5 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.1.02-SNAPSHOT + 2.1.02 Simplified, lightweight HTTP client library. From fc79d7a39813f45b76d8d4bba83ff55645409afa Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 24 Mar 2019 17:27:14 -0500 Subject: [PATCH 0548/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 3cd32713f..978af11be 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.1.02 + 2.1.03-SNAPSHOT unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -31,7 +31,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - v2.1.02 + HEAD diff --git a/unirest/pom.xml b/unirest/pom.xml index 56d6681a5..0ce988530 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.1.02 + 2.1.03-SNAPSHOT Simplified, lightweight HTTP client library. From b9177d188706bf3624ceed5e194f80a8cda7fe78 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 25 Mar 2019 07:04:25 -0500 Subject: [PATCH 0549/1769] update docs with client cert stuff --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f94618d70..29fad572f 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ We are looking for official maintainers, check out issue [#252](https://github.c com.konghq unirest-java - 2.1.00 + 2.1.02 ``` @@ -228,6 +228,8 @@ Unirest config allows easy access to build a configuration just like you would b | ```automaticRetries(boolean)``` | toggle disabling automatic retries (up to 4 times) for socket timeouts | true | | ```verifySsl(boolean)``` |toggle enforcing SSL | true | | ```addShutdownHook(boolean)``` | toggle to add the clients to the system shutdown hooks automatically | false | +| ```clientCertificateStore(String,String)``` | Add a PKCS12 KeyStore by path for doing client certificates | | +| ```clientCertificateStore(KeyStore,String)``` | Add a PKCS12 KeyStore for doing client certificates | | From 0b6c8133a8aa27208b2d6df6468cd33c76475824 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 25 Mar 2019 08:19:49 -0500 Subject: [PATCH 0550/1769] addresses issue #26 add file upload progress monitor --- CHANGELOG.md | 3 + unirest/src/main/java/kong/unirest/Body.java | 5 + .../kong/unirest/HttpRequestMultiPart.java | 13 +++ .../main/java/kong/unirest/MultipartBody.java | 3 + .../java/kong/unirest/ProgressMonitor.java | 31 ++++++ .../kong/unirest/apache/ApacheBodyMapper.java | 6 +- .../unirest/apache/MonitoringFileBody.java | 98 ++++++++++++++++++ .../BehaviorTests/UploadProgressTest.java | 92 ++++++++++++++++ unirest/src/test/resources/spidey.jpg | Bin 0 -> 46246 bytes 9 files changed, 248 insertions(+), 3 deletions(-) create mode 100644 unirest/src/main/java/kong/unirest/ProgressMonitor.java create mode 100644 unirest/src/main/java/kong/unirest/apache/MonitoringFileBody.java create mode 100644 unirest/src/test/java/BehaviorTests/UploadProgressTest.java create mode 100644 unirest/src/test/resources/spidey.jpg diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a60db8e7..c3d7a57db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.1.03 (pending) +* Finally address #26 You can add a file upload progress monitor + ## 2.1.02 * #120 support client certificates. You can pass in an entire keystore or just the path to it in the config. * part of #260: only support a single basic auth header. diff --git a/unirest/src/main/java/kong/unirest/Body.java b/unirest/src/main/java/kong/unirest/Body.java index 2ec14aa4c..7f62319dc 100644 --- a/unirest/src/main/java/kong/unirest/Body.java +++ b/unirest/src/main/java/kong/unirest/Body.java @@ -51,4 +51,9 @@ default BodyPart uniPart(){ default MultipartMode getMode(){ return MultipartMode.BROWSER_COMPATIBLE; } + + default ProgressMonitor getMonitor(){ + return null; + } + } diff --git a/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java b/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java index 44369b02c..460a8115b 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java @@ -38,6 +38,7 @@ class HttpRequestMultiPart extends BaseRequest implements Multipa private MultipartMode mode = MultipartMode.BROWSER_COMPATIBLE; private Charset charSet; private boolean forceMulti = false; + private ProgressMonitor monitor; HttpRequestMultiPart(HttpRequestBody httpRequest) { super(httpRequest); @@ -125,6 +126,12 @@ public MultipartBody mode(MultipartMode value) { return this; } + @Override + public MultipartBody uploadMonitor(ProgressMonitor uploadMonitor) { + this.monitor = uploadMonitor; + return this; + } + @Override public Charset getCharset() { return this.charSet; @@ -183,6 +190,12 @@ public MultipartMode getMode() { return mode; } + @Override + public ProgressMonitor getMonitor() { + return monitor; + } + + MultipartBody forceMultiPart(boolean value) { forceMulti = value; return this; diff --git a/unirest/src/main/java/kong/unirest/MultipartBody.java b/unirest/src/main/java/kong/unirest/MultipartBody.java index 462ec7366..4d34ba10c 100644 --- a/unirest/src/main/java/kong/unirest/MultipartBody.java +++ b/unirest/src/main/java/kong/unirest/MultipartBody.java @@ -143,4 +143,7 @@ public interface MultipartBody extends HttpRequest, Body { * @return The same MultipartBody * */ MultipartBody mode(MultipartMode value); + + + MultipartBody uploadMonitor(ProgressMonitor listener); } diff --git a/unirest/src/main/java/kong/unirest/ProgressMonitor.java b/unirest/src/main/java/kong/unirest/ProgressMonitor.java new file mode 100644 index 000000000..364c2762d --- /dev/null +++ b/unirest/src/main/java/kong/unirest/ProgressMonitor.java @@ -0,0 +1,31 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +@FunctionalInterface +public interface ProgressMonitor { + void accept(Long bytesWritten, Long totalBytes); +} diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheBodyMapper.java b/unirest/src/main/java/kong/unirest/apache/ApacheBodyMapper.java index dfc1f6a02..3ac4dcf55 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheBodyMapper.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheBodyMapper.java @@ -86,7 +86,7 @@ private HttpEntity mapToMultipart(Body body) { builder.setCharset(body.getCharset()); builder.setMode(HttpMultipartMode.valueOf(body.getMode().name())); for (BodyPart key : body.multiParts()) { - builder.addPart(key.getName(), apply(key)); + builder.addPart(key.getName(), apply(key, body)); } return builder.build(); } else { @@ -94,10 +94,10 @@ private HttpEntity mapToMultipart(Body body) { } } - private ContentBody apply(BodyPart value) { + private ContentBody apply(BodyPart value, Body body) { if (is(value, File.class)) { File file = (File)value.getValue(); - return new FileBody(file, toApacheType(value.getContentType())); + return new MonitoringFileBody(file, toApacheType(value.getContentType()), body.getMonitor()); } else if (is(value, InputStream.class)) { InputStream part = (InputStream)value.getValue(); return new InputStreamBody(part, diff --git a/unirest/src/main/java/kong/unirest/apache/MonitoringFileBody.java b/unirest/src/main/java/kong/unirest/apache/MonitoringFileBody.java new file mode 100644 index 000000000..35b8cb1cd --- /dev/null +++ b/unirest/src/main/java/kong/unirest/apache/MonitoringFileBody.java @@ -0,0 +1,98 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest.apache; + +import kong.unirest.ProgressMonitor; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.mime.content.FileBody; + +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Objects; + +public class MonitoringFileBody extends FileBody { + private final ProgressMonitor monitor; + private long length; + + public MonitoringFileBody(File file, ContentType contentType, ProgressMonitor monitor) { + super(file, contentType); + this.monitor = monitor; + this.length = file.length(); + } + + @Override + public void writeTo(OutputStream out) throws IOException { + if(Objects.nonNull(monitor)){ + super.writeTo(new MonitoringStream(out, length)); + } else { + super.writeTo(out); + } + } + + class MonitoringStream extends OutputStream { + + private final OutputStream out; + private volatile long written = 0; + private long length; + + public MonitoringStream(OutputStream out, long length) { + this.out = out; + this.length = length; + } + + @Override + public void write(int b) throws IOException { + out.write(b); + written++; + monitor.accept(written, length); + } + + @Override + public void write(byte[] b) throws IOException { + out.write(b); + written += b.length; + monitor.accept(written, length); + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + out.write(b, off, len); + written += len; + monitor.accept(written, length); + } + + @Override + public void flush() throws IOException { + out.flush(); + } + + @Override + public void close() throws IOException { + out.close(); + } + } +} diff --git a/unirest/src/test/java/BehaviorTests/UploadProgressTest.java b/unirest/src/test/java/BehaviorTests/UploadProgressTest.java new file mode 100644 index 000000000..a2e121c9b --- /dev/null +++ b/unirest/src/test/java/BehaviorTests/UploadProgressTest.java @@ -0,0 +1,92 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package BehaviorTests; + +import kong.unirest.Unirest; +import org.junit.Test; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import static java.util.Arrays.asList; +import static kong.unirest.TestUtil.rezFile; +import static org.junit.Assert.assertEquals; + +public class UploadProgressTest extends BddTest { + private List progress; + private long total; + private long timesCalled; + private File spidey; + + @Override + public void setUp() { + super.setUp(); + progress = new ArrayList<>(); + total = 0L; + timesCalled = 0; + spidey = rezFile("/spidey.jpg"); + } + + @Test + public void canAddUploadProgress() { + RequestCapture cap = Unirest.post(MockServer.POST) + .field("spidey", this.spidey) + .uploadMonitor((p, t) -> { + timesCalled++; + progress.add(p); + total = t; + }) + .asObject(RequestCapture.class) + .getBody(); + + assertSpideyFileUpload(cap); + } + + @Test + public void canAddUploadProgressAsync() throws Exception { + RequestCapture cap = Unirest.post(MockServer.POST) + .field("spidey", spidey) + .uploadMonitor((p, t) -> { + timesCalled++; + progress.add(p); + total = t; + }) + .asObjectAsync(RequestCapture.class) + .get() + .getBody(); + + assertSpideyFileUpload(cap); + } + + private void assertSpideyFileUpload(RequestCapture capture) { + assertEquals(12, timesCalled); + assertEquals(asList(4096L, 8192L, 12288L, 16384L, 20480L, 24576L, 28672L, + 32768L, 36864L, 40960L, 45056L, 46246L), progress); + assertEquals(spidey.length(), total); + capture.getFile("spidey.jpg").assertSize(spidey.length()); + } +} diff --git a/unirest/src/test/resources/spidey.jpg b/unirest/src/test/resources/spidey.jpg new file mode 100644 index 0000000000000000000000000000000000000000..ecc759109a4c66aeef451509822ac134e2e973ca GIT binary patch literal 46246 zcmb5VWmFx_6Fzv6-~@MfcXxu@h2Rz>xVw9TySqDF+#N#Di@R%ZcemyJ{df25*X=$d zXKJRqrl+Umsp^lVk1YVIoRq8-00II4fcUI{k5zy;;0qKqG&Izg&)t_VUtnO7;9x%s z3L+vr5*i9RIvNTZ8U{8Y4hAMZ78)8Z87@8%5eW$i1`atTIWZ+6F$wX1jX-=p3JU}K z6%OtzF(w)&@&E7g@fUyw2k{q*6bgbI0Eq?xg$D7_4?A5R!PY@cx`k6VzzvsKiRX%-1Qhx3qd)Hi-ZcG4giR&SW!?= z%5o!!0f2#2lyLX}Xe2RQ?jgK*xZNPP^eM0NU-Rqxd>46CK^ut!Od2o(EMmW0AQ&Xn z1t2sDjKZ*^=T6DhPE}mhOUS@O;44>`_vng!o<8ZhCZ`TB-VXpog{JVON>FlLbRbON ziGFF{%Lv0`umIb-1r2uyB!m#rJ8a(Qf^5=}ay><<&|K?@VM!u%+F*u-D3a(u?vP>w zCi&Xd48vzjY|$)}4AHO3@znpZjY>_MpgC9W3v5&c_a6DoJ9M|ec<0p6)U4iIQIkQ5 z<~YoFd;oMdVLL8A0IfV$2|+%K$%3vazVZuxjxS=dWtP2YX|$!3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IhOb4 zt^#f2Ql*37XamT6_g4pt8o!}F;U!M7{|i{5~Darz-9ZD5?8qHT(~~v zoxzoQU{)IiP7DSOh!L(}he01Dk_lJ2bG9bOQA%YcE?EhR+RUQ#Pwy7PA4G2E^(v~a zGX)$G%3zBaAfh6omo7M!;=K6g0Qh_^Wnvx%Gm&v*S5{Lqh<-9V3lAv}0E@E#u=&LJ6boW&#dVzm%G9s)F4vJ8kGpv0`=$hj4!&S46gcNKTJ zQPf?*uODH*=6D#sW#Vb!)*%J61bk<}EGH788AZ3qO7Qq*8-`fsX#^6+SVOEW4Zsa@ z1rZN7N&AoVW>P~bb2e7)Seup{!M!qoiyclJAwrGgQGu-5G{V4ooUZ%@guKPh7-5{j zx$X`;tspSDWlms)W+LI?@y~$Ezv99;jB)YP%zucMz^@hjjZLQ>7;03h>KmKG46Mv1 z{B7i3dGXBQ4iLlOG2twVZGCkNNjdm}wumJxqcGAnEh(BnhN_|WP(_{b7hzmhAk|^_ z7^`b2R?5wU Date: Sat, 30 Mar 2019 11:18:48 -0500 Subject: [PATCH 0551/1769] pass the name of the file into the monitor so it can do multiple files --- .../java/kong/unirest/ProgressMonitor.java | 2 +- .../unirest/apache/MonitoringFileBody.java | 8 ++- .../BehaviorTests/UploadProgressTest.java | 70 +++++++++++++------ 3 files changed, 56 insertions(+), 24 deletions(-) diff --git a/unirest/src/main/java/kong/unirest/ProgressMonitor.java b/unirest/src/main/java/kong/unirest/ProgressMonitor.java index 364c2762d..b197ce15c 100644 --- a/unirest/src/main/java/kong/unirest/ProgressMonitor.java +++ b/unirest/src/main/java/kong/unirest/ProgressMonitor.java @@ -27,5 +27,5 @@ @FunctionalInterface public interface ProgressMonitor { - void accept(Long bytesWritten, Long totalBytes); + void accept(String file, Long bytesWritten, Long totalBytes); } diff --git a/unirest/src/main/java/kong/unirest/apache/MonitoringFileBody.java b/unirest/src/main/java/kong/unirest/apache/MonitoringFileBody.java index 35b8cb1cd..3594fabf2 100644 --- a/unirest/src/main/java/kong/unirest/apache/MonitoringFileBody.java +++ b/unirest/src/main/java/kong/unirest/apache/MonitoringFileBody.java @@ -37,11 +37,13 @@ public class MonitoringFileBody extends FileBody { private final ProgressMonitor monitor; private long length; + private String name; public MonitoringFileBody(File file, ContentType contentType, ProgressMonitor monitor) { super(file, contentType); this.monitor = monitor; this.length = file.length(); + this.name = file.getName(); } @Override @@ -68,21 +70,21 @@ public MonitoringStream(OutputStream out, long length) { public void write(int b) throws IOException { out.write(b); written++; - monitor.accept(written, length); + monitor.accept(name, written, length); } @Override public void write(byte[] b) throws IOException { out.write(b); written += b.length; - monitor.accept(written, length); + monitor.accept(name, written, length); } @Override public void write(byte[] b, int off, int len) throws IOException { out.write(b, off, len); written += len; - monitor.accept(written, length); + monitor.accept(name, written, length); } @Override diff --git a/unirest/src/test/java/BehaviorTests/UploadProgressTest.java b/unirest/src/test/java/BehaviorTests/UploadProgressTest.java index a2e121c9b..552fc568a 100644 --- a/unirest/src/test/java/BehaviorTests/UploadProgressTest.java +++ b/unirest/src/test/java/BehaviorTests/UploadProgressTest.java @@ -25,29 +25,53 @@ package BehaviorTests; +import kong.unirest.ProgressMonitor; import kong.unirest.Unirest; import org.junit.Test; import java.io.File; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import static java.util.Arrays.asList; import static kong.unirest.TestUtil.rezFile; import static org.junit.Assert.assertEquals; public class UploadProgressTest extends BddTest { - private List progress; - private long total; - private long timesCalled; + private static class Monitor implements ProgressMonitor { + private Map stats = new HashMap<>(); + + @Override + public void accept(String file, Long bytesWritten, Long totalBytes) { + stats.computeIfAbsent(file, f -> new Stats()); + stats.compute(file, (f,s) -> { + s.progress.add(bytesWritten); + s.timesCalled++; + s.total = totalBytes; + return s; + }); + } + + public Stats get(String spidey) { + return stats.getOrDefault(spidey, new Stats()); + } + + static class Stats { + List progress = new ArrayList<>(); + long total; + long timesCalled; + } + } + + private Monitor monitor; private File spidey; @Override public void setUp() { super.setUp(); - progress = new ArrayList<>(); - total = 0L; - timesCalled = 0; + this.monitor = new Monitor(); spidey = rezFile("/spidey.jpg"); } @@ -55,11 +79,7 @@ public void setUp() { public void canAddUploadProgress() { RequestCapture cap = Unirest.post(MockServer.POST) .field("spidey", this.spidey) - .uploadMonitor((p, t) -> { - timesCalled++; - progress.add(p); - total = t; - }) + .uploadMonitor(monitor) .asObject(RequestCapture.class) .getBody(); @@ -70,11 +90,7 @@ public void canAddUploadProgress() { public void canAddUploadProgressAsync() throws Exception { RequestCapture cap = Unirest.post(MockServer.POST) .field("spidey", spidey) - .uploadMonitor((p, t) -> { - timesCalled++; - progress.add(p); - total = t; - }) + .uploadMonitor(monitor) .asObjectAsync(RequestCapture.class) .get() .getBody(); @@ -82,11 +98,25 @@ public void canAddUploadProgressAsync() throws Exception { assertSpideyFileUpload(cap); } + @Test + public void canKeepTrackOfMultipleFiles() { + RequestCapture cap = Unirest.post(MockServer.POST) + .field("spidey", this.spidey) + .field("other", rezFile("/test")) + .uploadMonitor(monitor) + .asObject(RequestCapture.class) + .getBody(); + + assertSpideyFileUpload(cap); + + } + private void assertSpideyFileUpload(RequestCapture capture) { - assertEquals(12, timesCalled); + Monitor.Stats stat = monitor.get(spidey.getName()); + assertEquals(12, stat.timesCalled); assertEquals(asList(4096L, 8192L, 12288L, 16384L, 20480L, 24576L, 28672L, - 32768L, 36864L, 40960L, 45056L, 46246L), progress); - assertEquals(spidey.length(), total); - capture.getFile("spidey.jpg").assertSize(spidey.length()); + 32768L, 36864L, 40960L, 45056L, 46246L), stat.progress); + assertEquals(this.spidey.length(), stat.total); + capture.getFile("spidey.jpg").assertSize(this.spidey.length()); } } From 1e2ebf49845ef428bc26dcac60071ad8b7c41c2f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 30 Mar 2019 12:53:47 -0500 Subject: [PATCH 0552/1769] refactor test a little --- .../BehaviorTests/UploadProgressTest.java | 27 +++++++++++++------ .../src/test/java/kong/unirest/TestUtil.java | 9 +++++++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/unirest/src/test/java/BehaviorTests/UploadProgressTest.java b/unirest/src/test/java/BehaviorTests/UploadProgressTest.java index 552fc568a..a7639aa86 100644 --- a/unirest/src/test/java/BehaviorTests/UploadProgressTest.java +++ b/unirest/src/test/java/BehaviorTests/UploadProgressTest.java @@ -26,6 +26,7 @@ package BehaviorTests; import kong.unirest.ProgressMonitor; +import kong.unirest.TestUtil; import kong.unirest.Unirest; import org.junit.Test; @@ -36,6 +37,7 @@ import java.util.Map; import static java.util.Arrays.asList; +import static kong.unirest.TestUtil.defaultIfNull; import static kong.unirest.TestUtil.rezFile; import static org.junit.Assert.assertEquals; @@ -45,17 +47,17 @@ private static class Monitor implements ProgressMonitor { @Override public void accept(String file, Long bytesWritten, Long totalBytes) { - stats.computeIfAbsent(file, f -> new Stats()); - stats.compute(file, (f,s) -> { - s.progress.add(bytesWritten); - s.timesCalled++; - s.total = totalBytes; - return s; + stats.compute(file, (f, s) -> { + s = defaultIfNull(s, Stats::new); + s.progress.add(bytesWritten); + s.timesCalled++; + s.total = totalBytes; + return s; }); } - public Stats get(String spidey) { - return stats.getOrDefault(spidey, new Stats()); + public Stats get(String fineName) { + return stats.getOrDefault(fineName, new Stats()); } static class Stats { @@ -108,9 +110,18 @@ public void canKeepTrackOfMultipleFiles() { .getBody(); assertSpideyFileUpload(cap); + assertOtherFileUpload(cap); } + private void assertOtherFileUpload(RequestCapture capture) { + Monitor.Stats stat = monitor.get("test"); + assertEquals(1, stat.timesCalled); + assertEquals(asList(19L), stat.progress); + assertEquals(19L, stat.total); + capture.getFile("test").assertSize(19L); + } + private void assertSpideyFileUpload(RequestCapture capture) { Monitor.Stats stat = monitor.get(spidey.getName()); assertEquals(12, stat.timesCalled); diff --git a/unirest/src/test/java/kong/unirest/TestUtil.java b/unirest/src/test/java/kong/unirest/TestUtil.java index e14f22d63..773232ba1 100644 --- a/unirest/src/test/java/kong/unirest/TestUtil.java +++ b/unirest/src/test/java/kong/unirest/TestUtil.java @@ -26,6 +26,7 @@ package kong.unirest; import BehaviorTests.MockServer; +import BehaviorTests.UploadProgressTest; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.guava.GuavaModule; import com.google.common.base.Charsets; @@ -37,6 +38,7 @@ import java.util.Base64; import java.util.HashMap; import java.util.Map; +import java.util.function.Supplier; import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; @@ -172,6 +174,13 @@ public static File getImageFile() { return rezFile("/image.jpg"); } + public static T defaultIfNull(T t, Supplier supplier) { + if(t == null){ + return supplier.get(); + } + return t; + } + @FunctionalInterface public interface ExRunnable { /** From f403034b0fbdb461359a43e91314b5b8408ed052 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 30 Mar 2019 13:05:20 -0500 Subject: [PATCH 0553/1769] update documentation --- CHANGELOG.md | 10 +++++++++- .../main/java/kong/unirest/MultipartBody.java | 7 ++++++- .../main/java/kong/unirest/ProgressMonitor.java | 17 ++++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3d7a57db..5fce3e0e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ ## 2.1.03 (pending) -* Finally address #26 You can add a file upload progress monitor +* Finally address #26 You can add a file upload progress monitor. This monitor will get called for each file in a multipart file upload by name. +``` java + Unirest.post("http://someplace") + .field("myFile", new File("/file/somthing.tar") + .uploadMonitor((name, bytesWritten, totalBytes) -> { + // draw a upload progress bar or something + }) + .asEmpty() +``` ## 2.1.02 * #120 support client certificates. You can pass in an entire keystore or just the path to it in the config. diff --git a/unirest/src/main/java/kong/unirest/MultipartBody.java b/unirest/src/main/java/kong/unirest/MultipartBody.java index 4d34ba10c..0132c7c79 100644 --- a/unirest/src/main/java/kong/unirest/MultipartBody.java +++ b/unirest/src/main/java/kong/unirest/MultipartBody.java @@ -145,5 +145,10 @@ public interface MultipartBody extends HttpRequest, Body { MultipartBody mode(MultipartMode value); - MultipartBody uploadMonitor(ProgressMonitor listener); + /** + * Set a file Progress upload monitor suitable for drawing progress bars and whatnot. + * @param monitor a monitor + * @return The same MultipartBody + * */ + MultipartBody uploadMonitor(ProgressMonitor monitor); } diff --git a/unirest/src/main/java/kong/unirest/ProgressMonitor.java b/unirest/src/main/java/kong/unirest/ProgressMonitor.java index b197ce15c..95dab9266 100644 --- a/unirest/src/main/java/kong/unirest/ProgressMonitor.java +++ b/unirest/src/main/java/kong/unirest/ProgressMonitor.java @@ -25,7 +25,22 @@ package kong.unirest; +/** + * A ProgressMonitor is a functional interface which can be passed to unirest for the purposes of + * monitoring file uploads. A common use case is for drawing upload progress bars. + * If the upload contains multiple files each one is called individually and the file name is provided. + * + * note that you will not receive a total for ALL files together at once. + * If you wanted this you could keep track of the total bytes of files you planned to upload and then + * have your ProgressMonitor aggregate the results. + */ @FunctionalInterface public interface ProgressMonitor { - void accept(String file, Long bytesWritten, Long totalBytes); + /** + * Accept stats about the current file upload chunk for a file. + * @param fileName the name of the file in question + * @param bytesWritten the number of bytes that have been uploaded so far + * @param totalBytes the total bytes that will be uploaded. + * */ + void accept(String fileName, Long bytesWritten, Long totalBytes); } From 3eefe6663a675cd1a5235e379abdb483fd77679f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 30 Mar 2019 13:08:32 -0500 Subject: [PATCH 0554/1769] a little prefactoring --- .../kong/unirest/apache/ApacheBodyMapper.java | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheBodyMapper.java b/unirest/src/main/java/kong/unirest/apache/ApacheBodyMapper.java index 3ac4dcf55..bc116c310 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheBodyMapper.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheBodyMapper.java @@ -53,7 +53,6 @@ class ApacheBodyMapper { this.request = request; } - HttpEntity apply() { Optional body = request.getBody(); return body.map(this::applyBody).orElseGet(BasicHttpEntity::new); @@ -67,8 +66,7 @@ private HttpEntity applyBody(Body o) { return mapToMultipart(o); } } - - + private HttpEntity mapToUniBody(Body b) { BodyPart bodyPart = b.uniPart(); if(bodyPart == null){ @@ -96,23 +94,39 @@ private HttpEntity mapToMultipart(Body body) { private ContentBody apply(BodyPart value, Body body) { if (is(value, File.class)) { - File file = (File)value.getValue(); - return new MonitoringFileBody(file, toApacheType(value.getContentType()), body.getMonitor()); + return toFileBody(value, body); } else if (is(value, InputStream.class)) { - InputStream part = (InputStream)value.getValue(); - return new InputStreamBody(part, - toApacheType(value.getContentType()), - value.getFileName()); + return toInputStreamBody(value); } else if (is(value, byte[].class)) { - byte[] part = (byte[])value.getValue(); - return new ByteArrayBody(part, - toApacheType(value.getContentType()), - value.getFileName()); + return toByteArrayBody(value); } else { - return new StringBody(String.valueOf(value.getValue()), toApacheType(value.getContentType())); + return toStringBody(value); } } + private ContentBody toFileBody(BodyPart value, Body body) { + File file = (File)value.getValue(); + return new MonitoringFileBody(file, toApacheType(value.getContentType()), body.getMonitor()); + } + + private ContentBody toInputStreamBody(BodyPart value) { + InputStream part = (InputStream)value.getValue(); + return new InputStreamBody(part, + toApacheType(value.getContentType()), + value.getFileName()); + } + + private ContentBody toByteArrayBody(BodyPart value) { + byte[] part = (byte[])value.getValue(); + return new ByteArrayBody(part, + toApacheType(value.getContentType()), + value.getFileName()); + } + + private ContentBody toStringBody(BodyPart value) { + return new StringBody(String.valueOf(value.getValue()), toApacheType(value.getContentType())); + } + private boolean is(BodyPart value, Class cls) { return cls.isAssignableFrom(value.getPartType()); } From 6748dd93811146b8fed33cc49b07eb1c4f78a7e4 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 30 Mar 2019 14:41:26 -0500 Subject: [PATCH 0555/1769] monitor the uploading of imput streams. Fixed an error with passing FileInputStreams where it gets turned into a string --- .../java/kong/unirest/HttpRequestBody.java | 2 +- .../kong/unirest/HttpRequestMultiPart.java | 17 ++-- .../java/kong/unirest/ProgressMonitor.java | 7 +- .../kong/unirest/apache/ApacheBodyMapper.java | 14 ++-- .../unirest/apache/MonitoringFileBody.java | 49 +----------- .../kong/unirest/apache/MonitoringStream.java | 80 +++++++++++++++++++ .../unirest/apache/MonitoringStreamBody.java | 68 ++++++++++++++++ .../main/java/kong/unirest/apache/Util.java | 4 + .../BehaviorTests/UploadProgressTest.java | 48 +++++++---- 9 files changed, 214 insertions(+), 75 deletions(-) create mode 100644 unirest/src/main/java/kong/unirest/apache/MonitoringStream.java create mode 100644 unirest/src/main/java/kong/unirest/apache/MonitoringStreamBody.java diff --git a/unirest/src/main/java/kong/unirest/HttpRequestBody.java b/unirest/src/main/java/kong/unirest/HttpRequestBody.java index 8c6920cab..8f11d217f 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestBody.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestBody.java @@ -66,7 +66,7 @@ public MultipartBody field(String name, Object value) { @Override public MultipartBody field(String name, Object value, String contentType) { - return new HttpRequestMultiPart(this).field(name, Util.nullToEmpty(value), contentType); + return new HttpRequestMultiPart(this).field(name, value, contentType); } @Override diff --git a/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java b/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java index 460a8115b..29d4987c1 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java @@ -53,14 +53,14 @@ public MultipartBody field(String name, String value) { @Override public MultipartBody field(String name, String value, String contentType) { - addPart(new ParamPart(name, value, contentType)); + addPart(name, value, contentType); return this; } @Override public MultipartBody field(String name, Collection collection) { for (Object current: collection) { - addPart(name, current); + addPart(name, current, null); } return this; } @@ -150,13 +150,18 @@ public MultipartBody fields(Map fields) { return this; } - private void addPart(String name, Object value) { + public MultipartBody field(String name, Object value, String contentType) { + addPart(name, value, contentType); + return this; + } + + private void addPart(String name, Object value, String contentType) { if(value instanceof InputStream){ - addPart(new InputStreamPart(name, (InputStream)value)); + addPart(new InputStreamPart(name, (InputStream)value, contentType)); } else if (value instanceof File) { - addPart(new FilePart((File)value, name)); + addPart(new FilePart((File)value, name, contentType)); } else { - addPart(new ParamPart(name, String.valueOf(value))); + addPart(new ParamPart(name, Util.nullToEmpty(value), contentType)); } } diff --git a/unirest/src/main/java/kong/unirest/ProgressMonitor.java b/unirest/src/main/java/kong/unirest/ProgressMonitor.java index 95dab9266..7b6b31e5b 100644 --- a/unirest/src/main/java/kong/unirest/ProgressMonitor.java +++ b/unirest/src/main/java/kong/unirest/ProgressMonitor.java @@ -38,9 +38,10 @@ public interface ProgressMonitor { /** * Accept stats about the current file upload chunk for a file. - * @param fileName the name of the file in question + * @param field the field name + * @param fileName the name of the file in question if available (InputStreams and byte arrays may not have file names) * @param bytesWritten the number of bytes that have been uploaded so far - * @param totalBytes the total bytes that will be uploaded. + * @param totalBytes the total bytes that will be uploaded. Note this this may be an estimate if an InputStream was used * */ - void accept(String fileName, Long bytesWritten, Long totalBytes); + void accept(String field, String fileName, Long bytesWritten, Long totalBytes); } diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheBodyMapper.java b/unirest/src/main/java/kong/unirest/apache/ApacheBodyMapper.java index bc116c310..6062e1c47 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheBodyMapper.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheBodyMapper.java @@ -96,7 +96,7 @@ private ContentBody apply(BodyPart value, Body body) { if (is(value, File.class)) { return toFileBody(value, body); } else if (is(value, InputStream.class)) { - return toInputStreamBody(value); + return toInputStreamBody(value, body); } else if (is(value, byte[].class)) { return toByteArrayBody(value); } else { @@ -106,16 +106,20 @@ private ContentBody apply(BodyPart value, Body body) { private ContentBody toFileBody(BodyPart value, Body body) { File file = (File)value.getValue(); - return new MonitoringFileBody(file, toApacheType(value.getContentType()), body.getMonitor()); + return new MonitoringFileBody(value.getName(), file, toApacheType(value.getContentType()), body.getMonitor()); } - private ContentBody toInputStreamBody(BodyPart value) { + private ContentBody toInputStreamBody(BodyPart value, Body body) { InputStream part = (InputStream)value.getValue(); - return new InputStreamBody(part, + return new MonitoringStreamBody(part, toApacheType(value.getContentType()), - value.getFileName()); + value.getFileName(), + value.getName(), + body.getMonitor()); } + + private ContentBody toByteArrayBody(BodyPart value) { byte[] part = (byte[])value.getValue(); return new ByteArrayBody(part, diff --git a/unirest/src/main/java/kong/unirest/apache/MonitoringFileBody.java b/unirest/src/main/java/kong/unirest/apache/MonitoringFileBody.java index 3594fabf2..d8fd19b13 100644 --- a/unirest/src/main/java/kong/unirest/apache/MonitoringFileBody.java +++ b/unirest/src/main/java/kong/unirest/apache/MonitoringFileBody.java @@ -35,12 +35,14 @@ import java.util.Objects; public class MonitoringFileBody extends FileBody { + private final String field; private final ProgressMonitor monitor; private long length; private String name; - public MonitoringFileBody(File file, ContentType contentType, ProgressMonitor monitor) { + public MonitoringFileBody(String field, File file, ContentType contentType, ProgressMonitor monitor) { super(file, contentType); + this.field = field; this.monitor = monitor; this.length = file.length(); this.name = file.getName(); @@ -49,52 +51,9 @@ public MonitoringFileBody(File file, ContentType contentType, ProgressMonitor mo @Override public void writeTo(OutputStream out) throws IOException { if(Objects.nonNull(monitor)){ - super.writeTo(new MonitoringStream(out, length)); + super.writeTo(new MonitoringStream(out, length, field, name, monitor)); } else { super.writeTo(out); } } - - class MonitoringStream extends OutputStream { - - private final OutputStream out; - private volatile long written = 0; - private long length; - - public MonitoringStream(OutputStream out, long length) { - this.out = out; - this.length = length; - } - - @Override - public void write(int b) throws IOException { - out.write(b); - written++; - monitor.accept(name, written, length); - } - - @Override - public void write(byte[] b) throws IOException { - out.write(b); - written += b.length; - monitor.accept(name, written, length); - } - - @Override - public void write(byte[] b, int off, int len) throws IOException { - out.write(b, off, len); - written += len; - monitor.accept(name, written, length); - } - - @Override - public void flush() throws IOException { - out.flush(); - } - - @Override - public void close() throws IOException { - out.close(); - } - } } diff --git a/unirest/src/main/java/kong/unirest/apache/MonitoringStream.java b/unirest/src/main/java/kong/unirest/apache/MonitoringStream.java new file mode 100644 index 000000000..76e95de6a --- /dev/null +++ b/unirest/src/main/java/kong/unirest/apache/MonitoringStream.java @@ -0,0 +1,80 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest.apache; + +import kong.unirest.ProgressMonitor; + +import java.io.IOException; +import java.io.OutputStream; + +class MonitoringStream extends OutputStream { + + private final OutputStream out; + private volatile long written = 0; + private long length; + private String fieldName; + private String fileName; + private ProgressMonitor monitor; + + public MonitoringStream(OutputStream out, long length, String fieldName, String fileName, ProgressMonitor monitor) { + this.out = out; + this.length = length; + this.fieldName = fieldName; + this.fileName = fileName; + this.monitor = monitor; + } + + @Override + public void write(int b) throws IOException { + out.write(b); + written++; + monitor.accept(fieldName, fileName, written, length); + } + + @Override + public void write(byte[] b) throws IOException { + out.write(b); + written += b.length; + monitor.accept(fieldName, fileName, written, length); + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + out.write(b, off, len); + written += len; + monitor.accept(fieldName, fileName, written, length); + } + + @Override + public void flush() throws IOException { + out.flush(); + } + + @Override + public void close() throws IOException { + out.close(); + } +} diff --git a/unirest/src/main/java/kong/unirest/apache/MonitoringStreamBody.java b/unirest/src/main/java/kong/unirest/apache/MonitoringStreamBody.java new file mode 100644 index 000000000..a26c3957e --- /dev/null +++ b/unirest/src/main/java/kong/unirest/apache/MonitoringStreamBody.java @@ -0,0 +1,68 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest.apache; + +import kong.unirest.ProgressMonitor; +import kong.unirest.UnirestException; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.mime.content.InputStreamBody; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Objects; + +class MonitoringStreamBody extends InputStreamBody { + private final ProgressMonitor monitor; + private final long length; + private final String name; + private final String fileName; + + public MonitoringStreamBody(InputStream in, + ContentType contentType, + String fileName, + String fieldName, + ProgressMonitor monitor) { + super(in, contentType, fileName); + this.fileName = fileName; + try { + this.monitor = monitor; + this.name = fieldName; + this.length = in.available(); + }catch (IOException e){ + throw new UnirestException(e); + } + } + + @Override + public void writeTo(OutputStream out) throws IOException { + if(Objects.nonNull(monitor)){ + super.writeTo(new MonitoringStream(out, length, name, fileName, monitor)); + } else { + super.writeTo(out); + } + } +} diff --git a/unirest/src/main/java/kong/unirest/apache/Util.java b/unirest/src/main/java/kong/unirest/apache/Util.java index f7e68c7b3..96c7daedf 100644 --- a/unirest/src/main/java/kong/unirest/apache/Util.java +++ b/unirest/src/main/java/kong/unirest/apache/Util.java @@ -61,4 +61,8 @@ static Optional tryDo(T c, ExConsumer consumer) { public interface ExConsumer{ void accept(T t) throws Exception; } + + static boolean isNullOrEmpty(String s) { + return s == null || s.trim().isEmpty(); + } } diff --git a/unirest/src/test/java/BehaviorTests/UploadProgressTest.java b/unirest/src/test/java/BehaviorTests/UploadProgressTest.java index a7639aa86..980d6aa2f 100644 --- a/unirest/src/test/java/BehaviorTests/UploadProgressTest.java +++ b/unirest/src/test/java/BehaviorTests/UploadProgressTest.java @@ -25,16 +25,18 @@ package BehaviorTests; +import com.google.common.base.Strings; import kong.unirest.ProgressMonitor; -import kong.unirest.TestUtil; import kong.unirest.Unirest; import org.junit.Test; import java.io.File; +import java.io.FileInputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Stream; import static java.util.Arrays.asList; import static kong.unirest.TestUtil.defaultIfNull; @@ -46,8 +48,9 @@ private static class Monitor implements ProgressMonitor { private Map stats = new HashMap<>(); @Override - public void accept(String file, Long bytesWritten, Long totalBytes) { - stats.compute(file, (f, s) -> { + public void accept(String field, String file, Long bytesWritten, Long totalBytes) { + String key = firstNotEmpty(file, field); + stats.compute(key, (f, s) -> { s = defaultIfNull(s, Stats::new); s.progress.add(bytesWritten); s.timesCalled++; @@ -56,6 +59,13 @@ public void accept(String file, Long bytesWritten, Long totalBytes) { }); } + private String firstNotEmpty(String... s) { + return Stream.of(s) + .filter(string -> !Strings.isNullOrEmpty(string)) + .findFirst() + .orElse(""); + } + public Stats get(String fineName) { return stats.getOrDefault(fineName, new Stats()); } @@ -79,55 +89,63 @@ public void setUp() { @Test public void canAddUploadProgress() { - RequestCapture cap = Unirest.post(MockServer.POST) + Unirest.post(MockServer.POST) .field("spidey", this.spidey) .uploadMonitor(monitor) .asObject(RequestCapture.class) .getBody(); - assertSpideyFileUpload(cap); + assertSpideyFileUpload("spidey.jpg"); } @Test public void canAddUploadProgressAsync() throws Exception { - RequestCapture cap = Unirest.post(MockServer.POST) + Unirest.post(MockServer.POST) .field("spidey", spidey) .uploadMonitor(monitor) .asObjectAsync(RequestCapture.class) .get() .getBody(); - assertSpideyFileUpload(cap); + assertSpideyFileUpload("spidey.jpg"); } @Test public void canKeepTrackOfMultipleFiles() { - RequestCapture cap = Unirest.post(MockServer.POST) + Unirest.post(MockServer.POST) .field("spidey", this.spidey) .field("other", rezFile("/test")) .uploadMonitor(monitor) .asObject(RequestCapture.class) .getBody(); - assertSpideyFileUpload(cap); - assertOtherFileUpload(cap); + assertSpideyFileUpload("spidey.jpg"); + assertOtherFileUpload(); + } + + @Test + public void canMonitorIfPassedAsInputStream() throws Exception { + Unirest.post(MockServer.POST) + .field("spidey", new FileInputStream(spidey)) + .uploadMonitor(monitor) + .asObject(RequestCapture.class) + .getBody(); + assertSpideyFileUpload("spidey"); } - private void assertOtherFileUpload(RequestCapture capture) { + private void assertOtherFileUpload() { Monitor.Stats stat = monitor.get("test"); assertEquals(1, stat.timesCalled); assertEquals(asList(19L), stat.progress); assertEquals(19L, stat.total); - capture.getFile("test").assertSize(19L); } - private void assertSpideyFileUpload(RequestCapture capture) { - Monitor.Stats stat = monitor.get(spidey.getName()); + private void assertSpideyFileUpload(String name) { + Monitor.Stats stat = monitor.get(name); assertEquals(12, stat.timesCalled); assertEquals(asList(4096L, 8192L, 12288L, 16384L, 20480L, 24576L, 28672L, 32768L, 36864L, 40960L, 45056L, 46246L), stat.progress); assertEquals(this.spidey.length(), stat.total); - capture.getFile("spidey.jpg").assertSize(this.spidey.length()); } } From 71fd02d730c6be7942a35c19a51127cc153348d8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 30 Mar 2019 14:52:45 -0500 Subject: [PATCH 0556/1769] update docs --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fce3e0e1..aa90c1916 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ }) .asEmpty() ``` +* Fix an issue where when using generic methods that take object, passing in complex objects like InputStreams would not get send as the correct type. ## 2.1.02 * #120 support client certificates. You can pass in an entire keystore or just the path to it in the config. From dea74f705eaf97e22504d872f36ffeefc3970f3c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 30 Mar 2019 15:08:23 -0500 Subject: [PATCH 0557/1769] backfill missing test --- .../java/BehaviorTests/MultiPartFormPostingTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java b/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java index 5e8dcbefa..3c0036645 100644 --- a/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java +++ b/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java @@ -81,6 +81,17 @@ public void testMultipartContentType() { .assertFileType("image/jpeg"); } + @Test + public void canSendRawInputStreamsWithoutAFileName() throws Exception { + FileInputStream stream = new FileInputStream(rezFile("/test")); + + Unirest.post(MockServer.POST) + .field("file", stream) + .asObject(RequestCapture.class) + .getBody() + .assertParam("file", "This is a test file"); + } + @Test public void testMultipartInputStreamContentType() throws Exception { FileInputStream stream = new FileInputStream(rezFile("/image.jpg")); From cf1d52c366a72203417b94e5c5ddf84297f4be98 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 30 Mar 2019 15:12:21 -0500 Subject: [PATCH 0558/1769] [maven-release-plugin] prepare release v2.1.03 --- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 978af11be..50e4ce8ae 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.1.03-SNAPSHOT + 2.1.03 unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -31,7 +31,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - HEAD + v2.1.03 diff --git a/unirest/pom.xml b/unirest/pom.xml index 0ce988530..a7295cf58 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.1.03-SNAPSHOT + 2.1.03 Simplified, lightweight HTTP client library. From 79dcbabc97f636dfbec33821050433e94e10fbfe Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 30 Mar 2019 15:12:29 -0500 Subject: [PATCH 0559/1769] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 50e4ce8ae..3811867d1 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.1.03 + 2.1.04-SNAPSHOT unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -31,7 +31,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - v2.1.03 + HEAD diff --git a/unirest/pom.xml b/unirest/pom.xml index a7295cf58..8429a1a44 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.1.03 + 2.1.04-SNAPSHOT Simplified, lightweight HTTP client library. From 38e95c6136f388d5709b6c7a4735377776d7ec31 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 30 Mar 2019 15:14:55 -0500 Subject: [PATCH 0560/1769] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa90c1916..fdf811a52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ``` java Unirest.post("http://someplace") .field("myFile", new File("/file/somthing.tar") - .uploadMonitor((name, bytesWritten, totalBytes) -> { + .uploadMonitor((fieldName, fileName, bytesWritten, totalBytes) -> { // draw a upload progress bar or something }) .asEmpty() From 61b4edb47e8cb6aab5d69745577c55a45b847d26 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 30 Mar 2019 15:23:55 -0500 Subject: [PATCH 0561/1769] simplify test --- .../test/java/BehaviorTests/UploadProgressTest.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/unirest/src/test/java/BehaviorTests/UploadProgressTest.java b/unirest/src/test/java/BehaviorTests/UploadProgressTest.java index 980d6aa2f..e0fbe6a67 100644 --- a/unirest/src/test/java/BehaviorTests/UploadProgressTest.java +++ b/unirest/src/test/java/BehaviorTests/UploadProgressTest.java @@ -92,8 +92,7 @@ public void canAddUploadProgress() { Unirest.post(MockServer.POST) .field("spidey", this.spidey) .uploadMonitor(monitor) - .asObject(RequestCapture.class) - .getBody(); + .asEmpty(); assertSpideyFileUpload("spidey.jpg"); } @@ -103,9 +102,7 @@ public void canAddUploadProgressAsync() throws Exception { Unirest.post(MockServer.POST) .field("spidey", spidey) .uploadMonitor(monitor) - .asObjectAsync(RequestCapture.class) - .get() - .getBody(); + .asEmpty(); assertSpideyFileUpload("spidey.jpg"); } @@ -116,8 +113,7 @@ public void canKeepTrackOfMultipleFiles() { .field("spidey", this.spidey) .field("other", rezFile("/test")) .uploadMonitor(monitor) - .asObject(RequestCapture.class) - .getBody(); + .asEmpty(); assertSpideyFileUpload("spidey.jpg"); assertOtherFileUpload(); @@ -128,8 +124,7 @@ public void canMonitorIfPassedAsInputStream() throws Exception { Unirest.post(MockServer.POST) .field("spidey", new FileInputStream(spidey)) .uploadMonitor(monitor) - .asObject(RequestCapture.class) - .getBody(); + .asEmpty(); assertSpideyFileUpload("spidey"); } From 329fa487aee5e24d4807dc31ac8a4e9f46365f44 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 30 Mar 2019 15:39:35 -0500 Subject: [PATCH 0562/1769] backfill some tests --- .../BehaviorTests/MultiPartFormPostingTest.java | 13 +++++++++++++ .../src/test/java/BehaviorTests/RequestCapture.java | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java b/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java index 3c0036645..d88c19f09 100644 --- a/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java +++ b/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java @@ -92,6 +92,19 @@ public void canSendRawInputStreamsWithoutAFileName() throws Exception { .assertParam("file", "This is a test file"); } + @Test + public void multipleFiles_sameField() { + RequestCapture body = Unirest.post(MockServer.POST) + .field("file", rezFile("/image.jpg")) + .field("file", rezFile("/spidey.jpg")) + .asObject(RequestCapture.class) + .getBody(); + + body.getFile("image.jpg").exists(); + body.getFile("spidey.jpg").exists(); + assertEquals(2, body.getAllFilesByInput("file").size()); + } + @Test public void testMultipartInputStreamContentType() throws Exception { FileInputStream stream = new FileInputStream(rezFile("/image.jpg")); diff --git a/unirest/src/test/java/BehaviorTests/RequestCapture.java b/unirest/src/test/java/BehaviorTests/RequestCapture.java index 08096499f..b0e4b13b4 100644 --- a/unirest/src/test/java/BehaviorTests/RequestCapture.java +++ b/unirest/src/test/java/BehaviorTests/RequestCapture.java @@ -330,6 +330,10 @@ public FormPart assertFileName(String s) { public void assertSize(long expected) { assertEquals(expected, this.size); } + + public void exists() { + assertTrue(this.size > 0); + } } } From ba34a13c17ef6abcbca4f2ef2a3b59526639c581 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 31 Mar 2019 07:47:34 -0500 Subject: [PATCH 0563/1769] update readme --- CHANGELOG.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdf811a52..8e09ecfd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 2.1.03 (pending) +## 2.1.03 * Finally address #26 You can add a file upload progress monitor. This monitor will get called for each file in a multipart file upload by name. ``` java Unirest.post("http://someplace") diff --git a/README.md b/README.md index 29fad572f..91885aa37 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ We are looking for official maintainers, check out issue [#252](https://github.c com.konghq unirest-java - 2.1.02 + 2.1.03 ``` From c28ac79afb859522e98f4ca54f2abddc46d5f238 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 6 Apr 2019 09:30:26 -0500 Subject: [PATCH 0564/1769] add some tests for turning cookies on and off --- .../src/main/java/kong/unirest/Config.java | 1 + .../test/java/BehaviorTests/CookieTest.java | 52 +++++++++++++++++++ .../test/java/BehaviorTests/MockServer.java | 10 +++- .../java/BehaviorTests/RequestCapture.java | 13 +++++ .../BehaviorTests/ResponseHeaderTest.java | 1 + 5 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 unirest/src/test/java/BehaviorTests/CookieTest.java diff --git a/unirest/src/main/java/kong/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java index f4662173a..deec4c9f7 100644 --- a/unirest/src/main/java/kong/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -74,6 +74,7 @@ public class Config { private boolean addShutdownHook = false; private KeyStore keystore; private String keystorePassword; + private String cookieSpec; public Config() { setDefaults(); diff --git a/unirest/src/test/java/BehaviorTests/CookieTest.java b/unirest/src/test/java/BehaviorTests/CookieTest.java new file mode 100644 index 000000000..ee53bacad --- /dev/null +++ b/unirest/src/test/java/BehaviorTests/CookieTest.java @@ -0,0 +1,52 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package BehaviorTests; + +import kong.unirest.Unirest; +import org.junit.Test; + +public class CookieTest extends BddTest { + @Test + public void willManageCookiesByDefault() { + MockServer.expectCookie("JSESSIONID", "ABC123"); + Unirest.get(MockServer.GET).asEmpty(); + Unirest.get(MockServer.GET) + .asObject(RequestCapture.class) + .getBody() + .assertCookie("JSESSIONID", "ABC123"); + } + + @Test + public void canTurnOffCookieManagement() { + Unirest.config().enableCookieManagement(false); + MockServer.expectCookie("JSESSIONID", "ABC123"); + Unirest.get(MockServer.GET).asEmpty(); + Unirest.get(MockServer.GET) + .asObject(RequestCapture.class) + .getBody() + .assertNoCookie("JSESSIONID"); + } +} diff --git a/unirest/src/test/java/BehaviorTests/MockServer.java b/unirest/src/test/java/BehaviorTests/MockServer.java index 7c1be93a2..036d50c14 100644 --- a/unirest/src/test/java/BehaviorTests/MockServer.java +++ b/unirest/src/test/java/BehaviorTests/MockServer.java @@ -26,6 +26,7 @@ package BehaviorTests; +import kong.unirest.Headers; import spark.Request; import spark.Response; import spark.Spark; @@ -48,6 +49,8 @@ public class MockServer { private static int pages = 1; private static int onPage = 1; private static final List> responseHeaders = new ArrayList<>(); + private static final List> cookies = new ArrayList<>(); + private static final JacksonObjectMapper om = new JacksonObjectMapper(); private static Object responseBody; public static final int PORT = 4567; @@ -78,6 +81,7 @@ public static void setJsonAsResponse(Object o){ public static void reset(){ responseBody = null; responseHeaders.clear(); + cookies.clear(); pages = 1; onPage = 1; } @@ -180,7 +184,7 @@ private static Object jsonResponse(Request req, Response res) { } private static RequestCapture getRequestCapture(Request req, Response res) { - res.cookie("JSESSIONID", "ABC123"); + cookies.forEach(c -> res.cookie(c.key, c.value)); responseHeaders.forEach(h -> res.header(h.key, h.value)); RequestCapture value = new RequestCapture(req); value.writeBody(req); @@ -206,4 +210,8 @@ public static void expectedPages(int expected) { public static void main(String[] args){ } + + public static void expectCookie(String name, String value) { + cookies.add(new Pair<>(name, value)); + } } diff --git a/unirest/src/test/java/BehaviorTests/RequestCapture.java b/unirest/src/test/java/BehaviorTests/RequestCapture.java index b0e4b13b4..bf2194634 100644 --- a/unirest/src/test/java/BehaviorTests/RequestCapture.java +++ b/unirest/src/test/java/BehaviorTests/RequestCapture.java @@ -35,6 +35,7 @@ import javax.servlet.MultipartConfigElement; import javax.servlet.ServletException; +import javax.servlet.http.Cookie; import javax.servlet.http.Part; import java.io.IOException; import java.nio.charset.Charset; @@ -60,6 +61,7 @@ public class RequestCapture { public JsonPatch jsonPatches; public Integer status; private boolean isProxied; + public HashMap cookies = new HashMap<>(); public RequestCapture() { @@ -72,6 +74,7 @@ public RequestCapture(Request req) { writeHeaders(req); writeQuery(req); populateParams(req); + cookies.putAll(req.cookies()); contentType = req.contentType(); status = 200; } @@ -291,6 +294,16 @@ public RequestCapture assertUrlEncodedContent() { return assertContentType("application/x-www-form-urlencoded; charset=UTF-8"); } + public void assertCookie(String name, String value) { + String c = cookies.get(name); + assertNotNull("expected a cookie to be passed to the server but got none. Name: " + name, c); + assertEquals(value, c); + } + + public void assertNoCookie(String name) { + assertNull("Cookie should not have been passed but it was! ", cookies.get(name)); + } + public static class FormPart { public String contentType; public ListMultimap headers = LinkedListMultimap.create(); diff --git a/unirest/src/test/java/BehaviorTests/ResponseHeaderTest.java b/unirest/src/test/java/BehaviorTests/ResponseHeaderTest.java index 0fca663df..0bf3d61b8 100644 --- a/unirest/src/test/java/BehaviorTests/ResponseHeaderTest.java +++ b/unirest/src/test/java/BehaviorTests/ResponseHeaderTest.java @@ -41,6 +41,7 @@ public void responseHeadersAreInTheSameOrderAsTheResponse() { MockServer.addResponseHeader("alpha", "apples"); MockServer.addResponseHeader("Content", "application/xml"); MockServer.addResponseHeader("zed", "grapes"); + MockServer.expectCookie("JSESSIONID", "ABC123"); Headers h = Unirest.get(MockServer.GET).asString().getHeaders(); From c4ef7610cf25a4cbf2ff63ebbf41e6c3628f2697 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 6 Apr 2019 09:44:34 -0500 Subject: [PATCH 0565/1769] make it so you can execute just the child module --- pom.xml | 3 ++- unirest/pom.xml | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3811867d1..6e7ac9147 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,7 @@ UTF-8 UTF-8 2.9.8 + ${project.basedir} @@ -88,7 +89,7 @@ 1.8.0 -

build/fileHeader.txt
+
${main.dir}/build/fileHeader.txt
true **/*.html diff --git a/unirest/pom.xml b/unirest/pom.xml index 8429a1a44..9c6cfe0ce 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -11,6 +11,10 @@ unirest-java jar + + ${project.parent.basedir} + + org.apache.httpcomponents From ae0e37ef80950639c8d917cab383da6d81b3d964 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 6 Apr 2019 09:05:16 -0500 Subject: [PATCH 0566/1769] add the object mappers into the parent and lock step them --- CHANGELOG.md | 5 + object-mapper-gson/pom.xml | 230 ++-------------------------------- object-mapper-jackson/pom.xml | 227 ++------------------------------- pom.xml | 10 +- unirest/pom.xml | 2 +- 5 files changed, 33 insertions(+), 441 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e09ecfd3..88242ea5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.2.00 (pending) +* Introduce default implementations of popular object mappers + * Jackson + * GSON + ## 2.1.03 * Finally address #26 You can add a file upload progress monitor. This monitor will get called for each file in a multipart file upload by name. ``` java diff --git a/object-mapper-gson/pom.xml b/object-mapper-gson/pom.xml index 870b273b2..b5db14af6 100644 --- a/object-mapper-gson/pom.xml +++ b/object-mapper-gson/pom.xml @@ -2,224 +2,26 @@ 4.0.0 - com.konghq + + com.konghq + unirest-java-parent + 2.2.00-SNAPSHOT + + unirest-object-mappers-gson - 3.0.01-SNAPSHOT - object-mappers-gson + unirest-objectmappers-gson Gson based object mapper for Unirest - http://github.com/kong/unirest-java/ - - - - MIT - http://opensource.org/licenses/MIT - repo - - - - - https://github.com/kong/unirest-java - scm:git:git@github.com:kong/unirest-java.git - scm:git:git@github.com:kong/unirest-java.git - HEAD - - - - - Ryber - Ryan Bergman - https://github.com/Ryber - - - - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - + jar - UTF-8 - UTF-8 + ${project.parent.basedir} - - - ossrh - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - sign-artifacts - verify - - sign - - - - - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.1.0 - - - - Unirest - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 2.17 - - - com.puppycrawl.tools - checkstyle - 8.18 - - - - - compile - auto-checkstyle - - checkstyle - check - - - - - ${basedir}/checkstyle.xml - ${basedir}/suppressions.xml - true - false - - - - org.jacoco - jacoco-maven-plugin - 0.8.1 - - - default-prepare-agent - - prepare-agent - - - - default-report - - report - - - - default-check - - check - - - - - BUNDLE - - - COMPLEXITY - COVEREDRATIO - 0.60 - - - - - - - - - - org.apache.maven.plugins - maven-release-plugin - 2.5 - - maven.test.skip=true - v@{project.version} - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.7 - true - - ossrh - https://oss.sonatype.org/ - true - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - true - 128m - 512m - 1.8 - 1.8 - UTF-8 - - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - attach-javadocs - - jar - - - - - - com.konghq unirest-java - 2.0.05 + ${project.version} provided @@ -227,17 +29,5 @@ gson 2.8.5 - - junit - junit - 4.12 - test - - - org.skyscreamer - jsonassert - 1.5.0 - test - \ No newline at end of file diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index 6666f196f..6db8b5320 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -2,225 +2,26 @@ 4.0.0 - com.konghq + + com.konghq + unirest-java-parent + 2.2.00-SNAPSHOT + + unirest-objectmapper-jackson - 2.0.06-SNAPSHOT unirest-objectmapper-jackson Jackson based object mapper for Unirest - http://github.com/kong/unirest-java/ - - - - MIT - http://opensource.org/licenses/MIT - repo - - - - - https://github.com/kong/unirest-java - scm:git:git@github.com:kong/unirest-java.git - scm:git:git@github.com:kong/unirest-java.git - v2.0.05 - - - - - Ryber - Ryan Bergman - https://github.com/ryber - - - - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - UTF-8 - UTF-8 2.9.8 + ${project.parent.basedir} - - - ossrh - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - sign-artifacts - verify - - sign - - - - - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.1.0 - - - - Unirest - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 2.17 - - - com.puppycrawl.tools - checkstyle - 8.18 - - - - - compile - auto-checkstyle - - checkstyle - check - - - - - ${basedir}/checkstyle.xml - ${basedir}/suppressions.xml - true - false - - - - org.jacoco - jacoco-maven-plugin - 0.8.1 - - - default-prepare-agent - - prepare-agent - - - - default-report - - report - - - - default-check - - check - - - - - BUNDLE - - - COMPLEXITY - COVEREDRATIO - 0.60 - - - - - - - - - - org.apache.maven.plugins - maven-release-plugin - 2.5 - - maven.test.skip=true - v@{project.version}-om-jackson - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.7 - true - - ossrh - https://oss.sonatype.org/ - true - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - true - 128m - 512m - 1.8 - 1.8 - UTF-8 - - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - attach-javadocs - - jar - - - - - - com.konghq unirest-java - 2.0.05 + ${project.version} provided @@ -228,17 +29,5 @@ jackson-databind ${jackson.version} - - junit - junit - 4.12 - test - - - org.skyscreamer - jsonassert - 1.5.0 - test - \ No newline at end of file diff --git a/pom.xml b/pom.xml index 6e7ac9147..5f4e77820 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.1.04-SNAPSHOT + 2.2.00-SNAPSHOT unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -19,6 +19,8 @@ unirest + object-mapper-gson + object-mapper-jackson @@ -325,6 +327,12 @@ 4.12 test + + org.skyscreamer + jsonassert + 1.5.0 + test + diff --git a/unirest/pom.xml b/unirest/pom.xml index 9c6cfe0ce..e1d18261f 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.1.04-SNAPSHOT + 2.2.00-SNAPSHOT Simplified, lightweight HTTP client library. From e844820e96498c9e77d84ffe672cd272187b3ced Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 6 Apr 2019 10:23:52 -0500 Subject: [PATCH 0567/1769] [maven-release-plugin] prepare release v2.2.00 --- object-mapper-gson/pom.xml | 2 +- object-mapper-jackson/pom.xml | 2 +- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/object-mapper-gson/pom.xml b/object-mapper-gson/pom.xml index b5db14af6..2541539c7 100644 --- a/object-mapper-gson/pom.xml +++ b/object-mapper-gson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.2.00-SNAPSHOT + 2.2.00 unirest-object-mappers-gson diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index 6db8b5320..14d767cd4 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.2.00-SNAPSHOT + 2.2.00 unirest-objectmapper-jackson diff --git a/pom.xml b/pom.xml index 5f4e77820..90e2dac07 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.2.00-SNAPSHOT + 2.2.00 unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -34,7 +34,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - HEAD + v2.2.00 diff --git a/unirest/pom.xml b/unirest/pom.xml index e1d18261f..70d42ff31 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.2.00-SNAPSHOT + 2.2.00 Simplified, lightweight HTTP client library. From db4ccea5fad0c72a85db71192454469c58be0846 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 6 Apr 2019 10:23:59 -0500 Subject: [PATCH 0568/1769] [maven-release-plugin] prepare for next development iteration --- object-mapper-gson/pom.xml | 2 +- object-mapper-jackson/pom.xml | 2 +- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/object-mapper-gson/pom.xml b/object-mapper-gson/pom.xml index 2541539c7..ae70d5725 100644 --- a/object-mapper-gson/pom.xml +++ b/object-mapper-gson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.2.00 + 2.2.01-SNAPSHOT unirest-object-mappers-gson diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index 14d767cd4..6115b2d04 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.2.00 + 2.2.01-SNAPSHOT unirest-objectmapper-jackson diff --git a/pom.xml b/pom.xml index 90e2dac07..f6c4bec8c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.2.00 + 2.2.01-SNAPSHOT unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -34,7 +34,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - v2.2.00 + HEAD diff --git a/unirest/pom.xml b/unirest/pom.xml index 70d42ff31..7f4211a49 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.2.00 + 2.2.01-SNAPSHOT Simplified, lightweight HTTP client library. From b6770db3645bc23b38f2fc23891773d34eba6b80 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 6 Apr 2019 12:07:43 -0500 Subject: [PATCH 0569/1769] update doc --- CHANGELOG.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88242ea5c..e5716ea79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 2.2.00 (pending) +## 2.2.00 * Introduce default implementations of popular object mappers * Jackson * GSON diff --git a/README.md b/README.md index 91885aa37..f4c5575b5 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ We are looking for official maintainers, check out issue [#252](https://github.c com.konghq unirest-java - 2.1.03 + 2.2.00 ``` From 10a64ff3e7b6edd5057e8db8da1617dd25fb3cc6 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 13 Apr 2019 09:51:22 -0500 Subject: [PATCH 0570/1769] closes PR #196. Pass a cookiespec policy --- CHANGELOG.md | 3 +++ README.md | 1 + .../src/main/java/kong/unirest/Config.java | 21 +++++++++++++++++++ .../java/kong/unirest/apache/RequestPrep.java | 1 + .../test/java/BehaviorTests/CookieTest.java | 13 ++++++++++++ 5 files changed, 39 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5716ea79..b92ef9c31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.2.01 (pending) +* add cookiespec policies to config. These are the same as Apache Http Clients cookiespec. See org.apache.http.client.config.CookieSpec + ## 2.2.00 * Introduce default implementations of popular object mappers * Jackson diff --git a/README.md b/README.md index f4c5575b5..888390584 100644 --- a/README.md +++ b/README.md @@ -225,6 +225,7 @@ Unirest config allows easy access to build a configuration just like you would b | ```setDefaultBasicAuth(String, String)``` | Add a default Basic Auth Header | | | ```followRedirects(boolean)``` | toggle following redirects | true | | ```enableCookieManagement(boolean)``` | toggle accepting and storing cookies | true | +| ```cookieSpec(boolean)``` | set a cookie policy. Acceptable values: 'default' (same as Netscape), 'netscape', 'ignoreCookies', 'standard' (RFC 6265 interoprability profile) , 'standard-strict' (RFC 6265 strict profile) | true | | ```automaticRetries(boolean)``` | toggle disabling automatic retries (up to 4 times) for socket timeouts | true | | ```verifySsl(boolean)``` |toggle enforcing SSL | true | | ```addShutdownHook(boolean)``` | toggle to add the clients to the system shutdown hooks automatically | false | diff --git a/unirest/src/main/java/kong/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java index deec4c9f7..f2ee271a1 100644 --- a/unirest/src/main/java/kong/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -420,6 +420,23 @@ public Config automaticRetries(boolean value) { return this; } + /** + * Sets a cookie policy + * Acceptable values: + * 'default' (same as Netscape), + * 'netscape', + * 'ignoreCookies', + * 'standard' (RFC 6265 interoprability profile) , + * 'standard-strict' (RFC 6265 strict profile) + * + * @param policy: the policy for cookies to follow + * @return this config object + */ + public Config cookieSpec(String policy) { + this.cookieSpec = policy; + return this; + } + /** * Set the default encoding that will be used for serialization into Strings. * The default-default is UTF-8 @@ -629,4 +646,8 @@ public boolean isVerifySsl() { public boolean shouldAddShutdownHook() { return addShutdownHook; } + + public String getCookieSpec() { + return cookieSpec; + } } diff --git a/unirest/src/main/java/kong/unirest/apache/RequestPrep.java b/unirest/src/main/java/kong/unirest/apache/RequestPrep.java index d7f0f604e..d65086646 100644 --- a/unirest/src/main/java/kong/unirest/apache/RequestPrep.java +++ b/unirest/src/main/java/kong/unirest/apache/RequestPrep.java @@ -99,6 +99,7 @@ private RequestConfig overrideConfig() { .setSocketTimeout(request.getSocketTimeout()) .setConnectionRequestTimeout(request.getSocketTimeout()) .setProxy(RequestOptions.toApacheProxy(request.getProxy())) + .setCookieSpec(config.getCookieSpec()) .build(); } diff --git a/unirest/src/test/java/BehaviorTests/CookieTest.java b/unirest/src/test/java/BehaviorTests/CookieTest.java index ee53bacad..375a31abf 100644 --- a/unirest/src/test/java/BehaviorTests/CookieTest.java +++ b/unirest/src/test/java/BehaviorTests/CookieTest.java @@ -26,6 +26,7 @@ package BehaviorTests; import kong.unirest.Unirest; +import org.apache.http.client.config.CookieSpecs; import org.junit.Test; public class CookieTest extends BddTest { @@ -49,4 +50,16 @@ public void canTurnOffCookieManagement() { .getBody() .assertNoCookie("JSESSIONID"); } + + @Test + public void canSetCookieSpec() { + Unirest.config().cookieSpec(CookieSpecs.IGNORE_COOKIES); + + MockServer.expectCookie("JSESSIONID", "ABC123"); + Unirest.get(MockServer.GET).asEmpty(); + Unirest.get(MockServer.GET) + .asObject(RequestCapture.class) + .getBody() + .assertNoCookie("JSESSIONID"); + } } From c0bbaf7c0df80aaa3007b823e27ff05f0f0a7ac8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 14 Apr 2019 07:57:19 -0500 Subject: [PATCH 0571/1769] fix readme. default value for cookieSpec --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 888390584..a9d81e823 100644 --- a/README.md +++ b/README.md @@ -225,7 +225,7 @@ Unirest config allows easy access to build a configuration just like you would b | ```setDefaultBasicAuth(String, String)``` | Add a default Basic Auth Header | | | ```followRedirects(boolean)``` | toggle following redirects | true | | ```enableCookieManagement(boolean)``` | toggle accepting and storing cookies | true | -| ```cookieSpec(boolean)``` | set a cookie policy. Acceptable values: 'default' (same as Netscape), 'netscape', 'ignoreCookies', 'standard' (RFC 6265 interoprability profile) , 'standard-strict' (RFC 6265 strict profile) | true | +| ```cookieSpec(boolean)``` | set a cookie policy. Acceptable values: 'default' (same as Netscape), 'netscape', 'ignoreCookies', 'standard' (RFC 6265 interoprability profile) , 'standard-strict' (RFC 6265 strict profile) | default | | ```automaticRetries(boolean)``` | toggle disabling automatic retries (up to 4 times) for socket timeouts | true | | ```verifySsl(boolean)``` |toggle enforcing SSL | true | | ```addShutdownHook(boolean)``` | toggle to add the clients to the system shutdown hooks automatically | false | From 2c74968257f41f625478eb7fe539da125fa675f1 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 14 Apr 2019 07:59:10 -0500 Subject: [PATCH 0572/1769] [maven-release-plugin] prepare release v2.2.01 --- object-mapper-gson/pom.xml | 2 +- object-mapper-jackson/pom.xml | 2 +- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/object-mapper-gson/pom.xml b/object-mapper-gson/pom.xml index ae70d5725..173f749cb 100644 --- a/object-mapper-gson/pom.xml +++ b/object-mapper-gson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.2.01-SNAPSHOT + 2.2.01 unirest-object-mappers-gson diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index 6115b2d04..5932e05b1 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.2.01-SNAPSHOT + 2.2.01 unirest-objectmapper-jackson diff --git a/pom.xml b/pom.xml index f6c4bec8c..5a22e5d99 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.2.01-SNAPSHOT + 2.2.01 unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -34,7 +34,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - HEAD + v2.2.01 diff --git a/unirest/pom.xml b/unirest/pom.xml index 7f4211a49..db6407c11 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.2.01-SNAPSHOT + 2.2.01 Simplified, lightweight HTTP client library. From 3e2f25ea04c21cbe50e31901a08afd6a63c369e1 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 14 Apr 2019 07:59:16 -0500 Subject: [PATCH 0573/1769] [maven-release-plugin] prepare for next development iteration --- object-mapper-gson/pom.xml | 2 +- object-mapper-jackson/pom.xml | 2 +- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/object-mapper-gson/pom.xml b/object-mapper-gson/pom.xml index 173f749cb..9fa6bb717 100644 --- a/object-mapper-gson/pom.xml +++ b/object-mapper-gson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.2.01 + 2.2.02-SNAPSHOT unirest-object-mappers-gson diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index 5932e05b1..a37253240 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.2.01 + 2.2.02-SNAPSHOT unirest-objectmapper-jackson diff --git a/pom.xml b/pom.xml index 5a22e5d99..c9893e83a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.2.01 + 2.2.02-SNAPSHOT unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -34,7 +34,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - v2.2.01 + HEAD diff --git a/unirest/pom.xml b/unirest/pom.xml index db6407c11..4bfc3b7da 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.2.01 + 2.2.02-SNAPSHOT Simplified, lightweight HTTP client library. From ce39834d664b1aff5e0c8bcb7b388b9138ba5077 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 14 Apr 2019 08:02:35 -0500 Subject: [PATCH 0574/1769] fix the type in the doc for cookie spec --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a9d81e823..778f0c673 100644 --- a/README.md +++ b/README.md @@ -225,7 +225,7 @@ Unirest config allows easy access to build a configuration just like you would b | ```setDefaultBasicAuth(String, String)``` | Add a default Basic Auth Header | | | ```followRedirects(boolean)``` | toggle following redirects | true | | ```enableCookieManagement(boolean)``` | toggle accepting and storing cookies | true | -| ```cookieSpec(boolean)``` | set a cookie policy. Acceptable values: 'default' (same as Netscape), 'netscape', 'ignoreCookies', 'standard' (RFC 6265 interoprability profile) , 'standard-strict' (RFC 6265 strict profile) | default | +| ```cookieSpec(String)``` | set a cookie policy. Acceptable values: 'default' (same as Netscape), 'netscape', 'ignoreCookies', 'standard' (RFC 6265 interoprability profile) , 'standard-strict' (RFC 6265 strict profile) | default | | ```automaticRetries(boolean)``` | toggle disabling automatic retries (up to 4 times) for socket timeouts | true | | ```verifySsl(boolean)``` |toggle enforcing SSL | true | | ```addShutdownHook(boolean)``` | toggle to add the clients to the system shutdown hooks automatically | false | From 027113d6a38e9f2e7f9c2a5a4ec9b22620cbf470 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 16 Apr 2019 12:49:40 -0500 Subject: [PATCH 0575/1769] issue #261 add a HttpResponse Mapper function to map a response to another response --- CHANGELOG.md | 10 +++- .../main/java/kong/unirest/BaseResponse.java | 13 ++++- .../main/java/kong/unirest/HttpResponse.java | 9 +++ .../java/kong/unirest/MappedResponse.java | 40 +++++++++++++ .../BehaviorTests/GenericMappingTest.java | 57 +++++++++++++++++++ .../test/java/BehaviorTests/MockServer.java | 33 +++++++---- 6 files changed, 148 insertions(+), 14 deletions(-) create mode 100644 unirest/src/main/java/kong/unirest/MappedResponse.java create mode 100644 unirest/src/test/java/BehaviorTests/GenericMappingTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index b92ef9c31..76ea47722 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,12 @@ -## 2.2.01 (pending) +## 2.2.02 (pending) +* Add a mapper function to transform a HttpResponse to a HttpResponse +```java +HttpResponse response = Unirest.get("http://someplace/number") + .asString() + .map(Integer::valueOf); +``` + +## 2.2.01 * add cookiespec policies to config. These are the same as Apache Http Clients cookiespec. See org.apache.http.client.config.CookieSpec ## 2.2.00 diff --git a/unirest/src/main/java/kong/unirest/BaseResponse.java b/unirest/src/main/java/kong/unirest/BaseResponse.java index 7d8bcb651..cff6524f4 100644 --- a/unirest/src/main/java/kong/unirest/BaseResponse.java +++ b/unirest/src/main/java/kong/unirest/BaseResponse.java @@ -37,11 +37,17 @@ abstract class BaseResponse implements HttpResponse { private Optional parsingerror = Optional.empty(); protected BaseResponse(RawResponse response){ - headers = response.getHeaders(); + this.headers = response.getHeaders(); this.statusCode = response.getStatus(); this.statusText = response.getStatusText(); } + protected BaseResponse(BaseResponse other){ + this.headers = other.headers; + this.statusCode = other.statusCode; + this.statusText = other.statusText; + } + @Override public int getStatus() { return statusCode; @@ -70,6 +76,11 @@ public V mapBody(Function func){ return func.apply(getBody()); } + @Override + public HttpResponse map(Function func) { + return new MappedResponse(this, mapBody(func)); + } + protected void setParsingException(String originalBody, RuntimeException e) { parsingerror = Optional.of(new UnirestParsingException(originalBody, e)); } diff --git a/unirest/src/main/java/kong/unirest/HttpResponse.java b/unirest/src/main/java/kong/unirest/HttpResponse.java index 57200bda8..34386e558 100644 --- a/unirest/src/main/java/kong/unirest/HttpResponse.java +++ b/unirest/src/main/java/kong/unirest/HttpResponse.java @@ -62,12 +62,21 @@ public interface HttpResponse { Optional getParsingError(); /** + * Map the body into another type * @param func a function to transform a body type to something else. * @param The return type of the function * @return the return type */ V mapBody(Function func); + /** + * Map the Response into another response with a different body + * @param func a function to transform a body type to something else. + * @param The return type of the function + * @return the return type + */ + HttpResponse map(Function func); + /** * If the response was a 200-series response. Invoke this consumer * can be chained with ifFailure diff --git a/unirest/src/main/java/kong/unirest/MappedResponse.java b/unirest/src/main/java/kong/unirest/MappedResponse.java new file mode 100644 index 000000000..357279733 --- /dev/null +++ b/unirest/src/main/java/kong/unirest/MappedResponse.java @@ -0,0 +1,40 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +class MappedResponse extends BaseResponse { + private final V body; + + public MappedResponse(BaseResponse response, V body) { + super(response); + this.body = body; + } + + @Override + public V getBody() { + return body; + } +} diff --git a/unirest/src/test/java/BehaviorTests/GenericMappingTest.java b/unirest/src/test/java/BehaviorTests/GenericMappingTest.java new file mode 100644 index 000000000..eeedff7b0 --- /dev/null +++ b/unirest/src/test/java/BehaviorTests/GenericMappingTest.java @@ -0,0 +1,57 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package BehaviorTests; + +import kong.unirest.HttpResponse; +import kong.unirest.Unirest; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class GenericMappingTest extends BddTest { + @Test + public void canMapBody() { + MockServer.setStringResponse("123456"); + + int body = Unirest.get(MockServer.GET).asString().mapBody(Integer::valueOf); + + assertEquals(123456, body); + } + + @Test + public void canMapTheEntireResponseIntoAnotherResponse() { + MockServer.setStringResponse("123456"); + MockServer.addResponseHeader("cheese","cheddar"); + + HttpResponse response = Unirest.get(MockServer.GET) + .asString() + .map(Integer::valueOf); + + assertEquals(123456, response.getBody().intValue()); + assertEquals(200, response.getStatus()); + assertEquals("cheddar", response.getHeaders().getFirst("cheese")); + } +} diff --git a/unirest/src/test/java/BehaviorTests/MockServer.java b/unirest/src/test/java/BehaviorTests/MockServer.java index 036d50c14..81628d55f 100644 --- a/unirest/src/test/java/BehaviorTests/MockServer.java +++ b/unirest/src/test/java/BehaviorTests/MockServer.java @@ -40,6 +40,7 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -167,25 +168,33 @@ private static Object gzipResponse(Request request, Response response) { } private static Object proxiedResponse(Request req, Response res) { - if(responseBody != null){ - return responseBody; + return simpleResponse(req, res) + .orElseGet(() -> { + RequestCapture value = getRequestCapture(req, res); + value.setIsProxied(true); + return om.writeValue(value); + }); + } + + private static Optional simpleResponse(Request req, Response res) { + cookies.forEach(c -> res.cookie(c.key, c.value)); + responseHeaders.forEach(h -> res.header(h.key, h.value)); + + if(responseBody != null) { + return Optional.of(responseBody); } - RequestCapture value = getRequestCapture(req, res); - value.setIsProxied(true); - return om.writeValue(value); + return Optional.empty(); } private static Object jsonResponse(Request req, Response res) { - if(responseBody != null){ - return responseBody; - } - RequestCapture value = getRequestCapture(req, res); - return om.writeValue(value); + return simpleResponse(req, res) + .orElseGet(() -> { + RequestCapture value = getRequestCapture(req, res); + return om.writeValue(value); + }); } private static RequestCapture getRequestCapture(Request req, Response res) { - cookies.forEach(c -> res.cookie(c.key, c.value)); - responseHeaders.forEach(h -> res.header(h.key, h.value)); RequestCapture value = new RequestCapture(req); value.writeBody(req); return value; From caba6c04a74658ee90fa0f9f6ce82cb97afd4ecb Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 21 Apr 2019 07:44:06 -0500 Subject: [PATCH 0576/1769] issue #262 add a option to get either a value or an error --- .../main/java/kong/unirest/BaseRequest.java | 9 ++++ .../java/kong/unirest/EitherResponse.java | 48 +++++++++++++++++++ .../java/kong/unirest/HttpEitherResponse.java | 30 ++++++++++++ .../main/java/kong/unirest/HttpRequest.java | 4 +- .../test/java/BehaviorTests/AsObjectTest.java | 9 ++++ .../test/java/BehaviorTests/ErrorThing.java | 43 +++++++++++++++++ .../test/java/BehaviorTests/MockServer.java | 8 +++- 7 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 unirest/src/main/java/kong/unirest/EitherResponse.java create mode 100644 unirest/src/main/java/kong/unirest/HttpEitherResponse.java create mode 100644 unirest/src/test/java/BehaviorTests/ErrorThing.java diff --git a/unirest/src/main/java/kong/unirest/BaseRequest.java b/unirest/src/main/java/kong/unirest/BaseRequest.java index bdc509a48..0d8856844 100644 --- a/unirest/src/main/java/kong/unirest/BaseRequest.java +++ b/unirest/src/main/java/kong/unirest/BaseRequest.java @@ -221,6 +221,15 @@ public HttpResponse asObject(Function function) { return config.getClient().request(this, funcResponse(function)); } + @Override + public HttpEitherResponse asObject(Class responseClass, Class errorClass) { + ObjectMapper om = getObjectMapper(); + HttpResponse response = config.getClient().request(this, r -> new ObjectResponse(om, r, responseClass)); + return new EitherResponse( + (BaseResponse) response, + om, errorClass); + } + @Override public CompletableFuture> asObjectAsync(Function function) { diff --git a/unirest/src/main/java/kong/unirest/EitherResponse.java b/unirest/src/main/java/kong/unirest/EitherResponse.java new file mode 100644 index 000000000..34906720c --- /dev/null +++ b/unirest/src/main/java/kong/unirest/EitherResponse.java @@ -0,0 +1,48 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +class EitherResponse extends BaseResponse implements HttpEitherResponse { + private T body; + private E error; + + EitherResponse(BaseResponse response, ObjectMapper om, Class errorClass) { + super(response); + if(!response.isSuccess()){ + error = om.readValue(response.getParsingError().get().getOriginalBody(), errorClass); + } + } + + @Override + public T getBody() { + return body; + } + + @Override + public E getError() { + return error; + } +} diff --git a/unirest/src/main/java/kong/unirest/HttpEitherResponse.java b/unirest/src/main/java/kong/unirest/HttpEitherResponse.java new file mode 100644 index 000000000..f755ba06d --- /dev/null +++ b/unirest/src/main/java/kong/unirest/HttpEitherResponse.java @@ -0,0 +1,30 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +public interface HttpEitherResponse extends HttpResponse { + E getError(); +} diff --git a/unirest/src/main/java/kong/unirest/HttpRequest.java b/unirest/src/main/java/kong/unirest/HttpRequest.java index 477e5b104..b0bb99d90 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequest.java +++ b/unirest/src/main/java/kong/unirest/HttpRequest.java @@ -267,6 +267,8 @@ public interface HttpRequest { */ CompletableFuture> asObjectAsync(Function function); + HttpEitherResponse asObject(Class responseClass, Class errorThingClass); + /** * Executes the request and writes the contents into a file * @param path The path to the file. @@ -288,7 +290,6 @@ public interface HttpRequest { * @return a file containing the results */ CompletableFuture> asFileAsync(String path, Callback callback); - /** * Allows for following paging links common in many APIs. * Each request will result in the same request (headers, etc) but will use the "next" link provided by the extract function. @@ -300,6 +301,7 @@ public interface HttpRequest { */ PagedList asPaged(Function mappingFunction, Function, String> linkExtractor); + /** * Executes the request and returns the response without parsing the body * @return the basic HttpResponse diff --git a/unirest/src/test/java/BehaviorTests/AsObjectTest.java b/unirest/src/test/java/BehaviorTests/AsObjectTest.java index 7b107af57..b753baa5b 100644 --- a/unirest/src/test/java/BehaviorTests/AsObjectTest.java +++ b/unirest/src/test/java/BehaviorTests/AsObjectTest.java @@ -126,6 +126,15 @@ public void unirestExceptionsAreAlsoParseExceptions() { assertEquals("You did something bad", request.getParsingError().get().getOriginalBody()); } + @Test + public void parsingAnAlternativeErrorObject() { + HttpEitherResponse request = Unirest.get(MockServer.ERROR_RESPONSE) + .asObject(RequestCapture.class, ErrorThing.class); + + assertEquals("boom!", request.getError().getMessage()); + + } + public static class TestingMapper implements ObjectMapper { public boolean wasCalled; diff --git a/unirest/src/test/java/BehaviorTests/ErrorThing.java b/unirest/src/test/java/BehaviorTests/ErrorThing.java new file mode 100644 index 000000000..f18d9899d --- /dev/null +++ b/unirest/src/test/java/BehaviorTests/ErrorThing.java @@ -0,0 +1,43 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package BehaviorTests; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ErrorThing { + + private final String message; + + @JsonCreator + public ErrorThing(@JsonProperty("message") String message){ + this.message = message; + } + + public String getMessage() { + return message; + } +} diff --git a/unirest/src/test/java/BehaviorTests/MockServer.java b/unirest/src/test/java/BehaviorTests/MockServer.java index 81628d55f..6f1f5d40f 100644 --- a/unirest/src/test/java/BehaviorTests/MockServer.java +++ b/unirest/src/test/java/BehaviorTests/MockServer.java @@ -49,7 +49,7 @@ public class MockServer { private static int pages = 1; private static int onPage = 1; - private static final List> responseHeaders = new ArrayList<>(); + private static final List> responseHeaders = new ArrayList<>(); private static final List> cookies = new ArrayList<>(); private static final JacksonObjectMapper om = new JacksonObjectMapper(); @@ -64,6 +64,7 @@ public class MockServer { public static final String PROXY = "localhost:4567"; public static final String POST = HOST + "/post"; public static final String GET = HOST + "/get"; + public static final String ERROR_RESPONSE = HOST + "/error"; public static final String DELETE = HOST + "/delete"; public static final String GZIP = HOST + "/gzip"; public static final String PATCH = HOST + "/patch"; @@ -108,6 +109,7 @@ public static void reset(){ get("/binary", MockServer::file); get("/paged", MockServer::paged); post("/raw", MockServer::echo); + get("/error", MockServer::error); Runtime.getRuntime().addShutdownHook(new Thread(Spark::stop)); try { new CountDownLatch(1).await(2, TimeUnit.SECONDS); @@ -116,6 +118,10 @@ public static void reset(){ } } + private static Object error(Request request, Response response) { + return Spark.halt(400, om.writeValue(new ErrorThing("boom!"))); + } + private static Object echo(Request request, Response response) { return request.body(); } From e332162efcce78dc0bd50c6d94eda805ac78419c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 21 Apr 2019 13:26:16 -0500 Subject: [PATCH 0577/1769] add documentation and change name --- CHANGELOG.md | 9 +++++++++ .../src/main/java/kong/unirest/BaseRequest.java | 4 ++-- .../{EitherResponse.java => Either.java} | 4 ++-- ...{HttpEitherResponse.java => HttpEither.java} | 5 ++++- .../src/main/java/kong/unirest/HttpRequest.java | 17 +++++++++++++++-- .../test/java/BehaviorTests/AsObjectTest.java | 2 +- 6 files changed, 33 insertions(+), 8 deletions(-) rename unirest/src/main/java/kong/unirest/{EitherResponse.java => Either.java} (89%) rename unirest/src/main/java/kong/unirest/{HttpEitherResponse.java => HttpEither.java} (91%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76ea47722..a5634bfb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,15 @@ HttpResponse response = Unirest.get("http://someplace/number") .asString() .map(Integer::valueOf); ``` +* Add a new response builder for getting an object OR an alternative error object. This is nice for systems that return errors in the same format as the primary objects (json, xml, etc). +```java +HttpEither response = Unirest.get("http://someplace") + .asObject(Thing.class, ErrorThing.class); + +response.getBody(); // Has the thing +response.getError(); // has an error object (as defined by the server) + +``` ## 2.2.01 * add cookiespec policies to config. These are the same as Apache Http Clients cookiespec. See org.apache.http.client.config.CookieSpec diff --git a/unirest/src/main/java/kong/unirest/BaseRequest.java b/unirest/src/main/java/kong/unirest/BaseRequest.java index 0d8856844..a1f423ead 100644 --- a/unirest/src/main/java/kong/unirest/BaseRequest.java +++ b/unirest/src/main/java/kong/unirest/BaseRequest.java @@ -222,10 +222,10 @@ public HttpResponse asObject(Function function) { } @Override - public HttpEitherResponse asObject(Class responseClass, Class errorClass) { + public HttpEither asObject(Class responseClass, Class errorClass) { ObjectMapper om = getObjectMapper(); HttpResponse response = config.getClient().request(this, r -> new ObjectResponse(om, r, responseClass)); - return new EitherResponse( + return new Either( (BaseResponse) response, om, errorClass); } diff --git a/unirest/src/main/java/kong/unirest/EitherResponse.java b/unirest/src/main/java/kong/unirest/Either.java similarity index 89% rename from unirest/src/main/java/kong/unirest/EitherResponse.java rename to unirest/src/main/java/kong/unirest/Either.java index 34906720c..e37c4ca06 100644 --- a/unirest/src/main/java/kong/unirest/EitherResponse.java +++ b/unirest/src/main/java/kong/unirest/Either.java @@ -25,11 +25,11 @@ package kong.unirest; -class EitherResponse extends BaseResponse implements HttpEitherResponse { +class Either extends BaseResponse implements HttpEither { private T body; private E error; - EitherResponse(BaseResponse response, ObjectMapper om, Class errorClass) { + Either(BaseResponse response, ObjectMapper om, Class errorClass) { super(response); if(!response.isSuccess()){ error = om.readValue(response.getParsingError().get().getOriginalBody(), errorClass); diff --git a/unirest/src/main/java/kong/unirest/HttpEitherResponse.java b/unirest/src/main/java/kong/unirest/HttpEither.java similarity index 91% rename from unirest/src/main/java/kong/unirest/HttpEitherResponse.java rename to unirest/src/main/java/kong/unirest/HttpEither.java index f755ba06d..821e6a855 100644 --- a/unirest/src/main/java/kong/unirest/HttpEitherResponse.java +++ b/unirest/src/main/java/kong/unirest/HttpEither.java @@ -25,6 +25,9 @@ package kong.unirest; -public interface HttpEitherResponse extends HttpResponse { +/** + * A response with an alternate error class + */ +public interface HttpEither extends HttpResponse { E getError(); } diff --git a/unirest/src/main/java/kong/unirest/HttpRequest.java b/unirest/src/main/java/kong/unirest/HttpRequest.java index b0bb99d90..ee5bd6fe9 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequest.java +++ b/unirest/src/main/java/kong/unirest/HttpRequest.java @@ -33,6 +33,10 @@ import java.util.function.Consumer; import java.util.function.Function; +/** + The primary request builder used to create a request. This will be completed after calling one of + the "as**" methods like asString() + */ public interface HttpRequest { /** * add a route param that replaces the matching {name} @@ -223,6 +227,17 @@ public interface HttpRequest { */ HttpResponse asObject(Function function); + /** + * Executes the request and returns the response with the body mapped into T by a configured ObjectMapper + * if the response resulted in an error then map the error into an alternative object + * @param responseClass the class to return. This will be passed to the ObjectMapper + * @param errorClass the error class to return. This will be passed to the ObjectMapper + * @param the return type + * @param the error type + * @return a response + */ + HttpEither asObject(Class responseClass, Class errorClass); + /** * Executes the request asynchronously and returns response with the body mapped into T by a configured ObjectMapper * @param responseClass the class type to map to @@ -267,8 +282,6 @@ public interface HttpRequest { */ CompletableFuture> asObjectAsync(Function function); - HttpEitherResponse asObject(Class responseClass, Class errorThingClass); - /** * Executes the request and writes the contents into a file * @param path The path to the file. diff --git a/unirest/src/test/java/BehaviorTests/AsObjectTest.java b/unirest/src/test/java/BehaviorTests/AsObjectTest.java index b753baa5b..7e281a821 100644 --- a/unirest/src/test/java/BehaviorTests/AsObjectTest.java +++ b/unirest/src/test/java/BehaviorTests/AsObjectTest.java @@ -128,7 +128,7 @@ public void unirestExceptionsAreAlsoParseExceptions() { @Test public void parsingAnAlternativeErrorObject() { - HttpEitherResponse request = Unirest.get(MockServer.ERROR_RESPONSE) + HttpEither request = Unirest.get(MockServer.ERROR_RESPONSE) .asObject(RequestCapture.class, ErrorThing.class); assertEquals("boom!", request.getError().getMessage()); From fdacd38a7c0b2af4dc54085402c0d447e3b64e37 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 21 Apr 2019 13:40:16 -0500 Subject: [PATCH 0578/1769] more tests, deal with failure of the failure --- .../src/main/java/kong/unirest/Either.java | 6 +++- .../main/java/kong/unirest/HttpEither.java | 6 ++++ .../test/java/BehaviorTests/AsObjectTest.java | 9 ----- .../test/java/BehaviorTests/EitherTest.java | 35 +++++++++++++++++++ 4 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 unirest/src/test/java/BehaviorTests/EitherTest.java diff --git a/unirest/src/main/java/kong/unirest/Either.java b/unirest/src/main/java/kong/unirest/Either.java index e37c4ca06..f741e70b2 100644 --- a/unirest/src/main/java/kong/unirest/Either.java +++ b/unirest/src/main/java/kong/unirest/Either.java @@ -32,7 +32,11 @@ class Either extends BaseResponse implements HttpEither { Either(BaseResponse response, ObjectMapper om, Class errorClass) { super(response); if(!response.isSuccess()){ - error = om.readValue(response.getParsingError().get().getOriginalBody(), errorClass); + try { + error = om.readValue(response.getParsingError().get().getOriginalBody(), errorClass); + }catch (RuntimeException e) { + setParsingException(response.getParsingError().get().getOriginalBody(), e); + } } } diff --git a/unirest/src/main/java/kong/unirest/HttpEither.java b/unirest/src/main/java/kong/unirest/HttpEither.java index 821e6a855..6a3461d06 100644 --- a/unirest/src/main/java/kong/unirest/HttpEither.java +++ b/unirest/src/main/java/kong/unirest/HttpEither.java @@ -29,5 +29,11 @@ * A response with an alternate error class */ public interface HttpEither extends HttpResponse { + + /** + * @return the error object or null if the request was: + * 1) successful + * 2) failed but didn't return a result that could be mapped into a error object. + */ E getError(); } diff --git a/unirest/src/test/java/BehaviorTests/AsObjectTest.java b/unirest/src/test/java/BehaviorTests/AsObjectTest.java index 7e281a821..7b107af57 100644 --- a/unirest/src/test/java/BehaviorTests/AsObjectTest.java +++ b/unirest/src/test/java/BehaviorTests/AsObjectTest.java @@ -126,15 +126,6 @@ public void unirestExceptionsAreAlsoParseExceptions() { assertEquals("You did something bad", request.getParsingError().get().getOriginalBody()); } - @Test - public void parsingAnAlternativeErrorObject() { - HttpEither request = Unirest.get(MockServer.ERROR_RESPONSE) - .asObject(RequestCapture.class, ErrorThing.class); - - assertEquals("boom!", request.getError().getMessage()); - - } - public static class TestingMapper implements ObjectMapper { public boolean wasCalled; diff --git a/unirest/src/test/java/BehaviorTests/EitherTest.java b/unirest/src/test/java/BehaviorTests/EitherTest.java new file mode 100644 index 000000000..a3084b7bb --- /dev/null +++ b/unirest/src/test/java/BehaviorTests/EitherTest.java @@ -0,0 +1,35 @@ +package BehaviorTests; + +import com.fasterxml.jackson.annotation.JsonProperty; +import kong.unirest.HttpEither; +import kong.unirest.Unirest; +import org.junit.Test; + +import static junit.framework.TestCase.assertEquals; + +public class EitherTest extends BddTest { + + @Test + public void parsingAnAlternativeErrorObject() { + HttpEither request = Unirest.get(MockServer.ERROR_RESPONSE) + .asObject(RequestCapture.class, ErrorThing.class); + + assertEquals("boom!", request.getError().getMessage()); + } + + @Test + public void failsIfErrorResponseCantBeMapped() { + + HttpEither request = Unirest.get(MockServer.ERROR_RESPONSE) + .asObject(RequestCapture.class, NotTheError.class); + + assertEquals(null, request.getError()); + assertEquals(null, request.getBody()); + assertEquals("{\"message\":\"boom!\"}", request.getParsingError().get().getOriginalBody()); + } + + public static class NotTheError { + @JsonProperty("merp") + public String merp; + } +} From 0cf58948110f677cbb8155e2e6c273361c7fdc97 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 22 Apr 2019 20:50:23 -0500 Subject: [PATCH 0579/1769] make sure to take the body with us duh --- .../src/main/java/kong/unirest/Either.java | 1 + .../test/java/BehaviorTests/EitherTest.java | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/unirest/src/main/java/kong/unirest/Either.java b/unirest/src/main/java/kong/unirest/Either.java index f741e70b2..b39a587bd 100644 --- a/unirest/src/main/java/kong/unirest/Either.java +++ b/unirest/src/main/java/kong/unirest/Either.java @@ -31,6 +31,7 @@ class Either extends BaseResponse implements HttpEither { Either(BaseResponse response, ObjectMapper om, Class errorClass) { super(response); + this.body = response.getBody(); if(!response.isSuccess()){ try { error = om.readValue(response.getParsingError().get().getOriginalBody(), errorClass); diff --git a/unirest/src/test/java/BehaviorTests/EitherTest.java b/unirest/src/test/java/BehaviorTests/EitherTest.java index a3084b7bb..22714b365 100644 --- a/unirest/src/test/java/BehaviorTests/EitherTest.java +++ b/unirest/src/test/java/BehaviorTests/EitherTest.java @@ -1,3 +1,28 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package BehaviorTests; import com.fasterxml.jackson.annotation.JsonProperty; @@ -6,6 +31,7 @@ import org.junit.Test; import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertNull; public class EitherTest extends BddTest { @@ -15,6 +41,16 @@ public void parsingAnAlternativeErrorObject() { .asObject(RequestCapture.class, ErrorThing.class); assertEquals("boom!", request.getError().getMessage()); + assertNull(request.getBody()); + } + + @Test + public void ifNoErrorThenGetTheRegularBody() { + HttpEither request = Unirest.get(MockServer.GET) + .asObject(RequestCapture.class, ErrorThing.class); + + request.getBody().assertStatus(200); + assertNull(request.getError()); } @Test From 5736d2ee33cbb17b006e6edf79ec9cda05c62762 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 24 Apr 2019 07:36:29 -0500 Subject: [PATCH 0580/1769] switch over the error parsing to be on the response. The either was awkward and wasnt going to work well in async or post parsing overloads. If only java has a 'this' ref in generics --- .../main/java/kong/unirest/BaseRequest.java | 9 ---- .../main/java/kong/unirest/BaseResponse.java | 19 ++++++- .../src/main/java/kong/unirest/Either.java | 53 ------------------- .../main/java/kong/unirest/HttpEither.java | 39 -------------- .../main/java/kong/unirest/HttpRequest.java | 11 ---- .../main/java/kong/unirest/HttpResponse.java | 8 +++ .../main/java/kong/unirest/RawResponse.java | 1 + .../java/kong/unirest/RawResponseBase.java | 4 ++ ...{EitherTest.java => ErrorParsingTest.java} | 28 +++++----- 9 files changed, 44 insertions(+), 128 deletions(-) delete mode 100644 unirest/src/main/java/kong/unirest/Either.java delete mode 100644 unirest/src/main/java/kong/unirest/HttpEither.java rename unirest/src/test/java/BehaviorTests/{EitherTest.java => ErrorParsingTest.java} (68%) diff --git a/unirest/src/main/java/kong/unirest/BaseRequest.java b/unirest/src/main/java/kong/unirest/BaseRequest.java index a1f423ead..bdc509a48 100644 --- a/unirest/src/main/java/kong/unirest/BaseRequest.java +++ b/unirest/src/main/java/kong/unirest/BaseRequest.java @@ -221,15 +221,6 @@ public HttpResponse asObject(Function function) { return config.getClient().request(this, funcResponse(function)); } - @Override - public HttpEither asObject(Class responseClass, Class errorClass) { - ObjectMapper om = getObjectMapper(); - HttpResponse response = config.getClient().request(this, r -> new ObjectResponse(om, r, responseClass)); - return new Either( - (BaseResponse) response, - om, errorClass); - } - @Override public CompletableFuture> asObjectAsync(Function function) { diff --git a/unirest/src/main/java/kong/unirest/BaseResponse.java b/unirest/src/main/java/kong/unirest/BaseResponse.java index cff6524f4..4d4045d77 100644 --- a/unirest/src/main/java/kong/unirest/BaseResponse.java +++ b/unirest/src/main/java/kong/unirest/BaseResponse.java @@ -35,17 +35,20 @@ abstract class BaseResponse implements HttpResponse { private final String statusText; private final int statusCode; private Optional parsingerror = Optional.empty(); + private final Config config; protected BaseResponse(RawResponse response){ this.headers = response.getHeaders(); this.statusCode = response.getStatus(); this.statusText = response.getStatusText(); + this.config = response.getConfig(); } protected BaseResponse(BaseResponse other){ this.headers = other.headers; this.statusCode = other.statusCode; this.statusText = other.statusText; + this.config = other.config; } @Override @@ -85,6 +88,11 @@ protected void setParsingException(String originalBody, RuntimeException e) { parsingerror = Optional.of(new UnirestParsingException(originalBody, e)); } + @Override + public boolean isSuccess() { + return getStatus() >= 200 && getStatus() < 300 && !getParsingError().isPresent(); + } + @Override public HttpResponse ifSuccess(Consumer> consumer) { if(isSuccess()){ @@ -102,7 +110,14 @@ public HttpResponse ifFailure(Consumer> consumer) { } @Override - public boolean isSuccess() { - return getStatus() >= 200 && getStatus() < 300 && !getParsingError().isPresent(); + public E mapError(Class errorClass) { + if(!isSuccess()){ + try { + return config.getObjectMapper().readValue(getParsingError().get().getOriginalBody(), errorClass); + }catch (RuntimeException e) { + setParsingException(getParsingError().get().getOriginalBody(), e); + } + } + return null; } } diff --git a/unirest/src/main/java/kong/unirest/Either.java b/unirest/src/main/java/kong/unirest/Either.java deleted file mode 100644 index b39a587bd..000000000 --- a/unirest/src/main/java/kong/unirest/Either.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package kong.unirest; - -class Either extends BaseResponse implements HttpEither { - private T body; - private E error; - - Either(BaseResponse response, ObjectMapper om, Class errorClass) { - super(response); - this.body = response.getBody(); - if(!response.isSuccess()){ - try { - error = om.readValue(response.getParsingError().get().getOriginalBody(), errorClass); - }catch (RuntimeException e) { - setParsingException(response.getParsingError().get().getOriginalBody(), e); - } - } - } - - @Override - public T getBody() { - return body; - } - - @Override - public E getError() { - return error; - } -} diff --git a/unirest/src/main/java/kong/unirest/HttpEither.java b/unirest/src/main/java/kong/unirest/HttpEither.java deleted file mode 100644 index 6a3461d06..000000000 --- a/unirest/src/main/java/kong/unirest/HttpEither.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * The MIT License - * - * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package kong.unirest; - -/** - * A response with an alternate error class - */ -public interface HttpEither extends HttpResponse { - - /** - * @return the error object or null if the request was: - * 1) successful - * 2) failed but didn't return a result that could be mapped into a error object. - */ - E getError(); -} diff --git a/unirest/src/main/java/kong/unirest/HttpRequest.java b/unirest/src/main/java/kong/unirest/HttpRequest.java index ee5bd6fe9..f6d2b2de4 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequest.java +++ b/unirest/src/main/java/kong/unirest/HttpRequest.java @@ -227,17 +227,6 @@ public interface HttpRequest { */ HttpResponse asObject(Function function); - /** - * Executes the request and returns the response with the body mapped into T by a configured ObjectMapper - * if the response resulted in an error then map the error into an alternative object - * @param responseClass the class to return. This will be passed to the ObjectMapper - * @param errorClass the error class to return. This will be passed to the ObjectMapper - * @param the return type - * @param the error type - * @return a response - */ - HttpEither asObject(Class responseClass, Class errorClass); - /** * Executes the request asynchronously and returns response with the body mapped into T by a configured ObjectMapper * @param responseClass the class type to map to diff --git a/unirest/src/main/java/kong/unirest/HttpResponse.java b/unirest/src/main/java/kong/unirest/HttpResponse.java index 34386e558..51fdf1729 100644 --- a/unirest/src/main/java/kong/unirest/HttpResponse.java +++ b/unirest/src/main/java/kong/unirest/HttpResponse.java @@ -97,4 +97,12 @@ public interface HttpResponse { * @return true if the response was a 200-series response and no mapping exception happened, else false */ boolean isSuccess(); + + /** + * Map the body into a error class if the response was NOT a 200-series response or a mapping exception happened. + * Uses the system Object Mapper + * @param errorClass the class for the error + * @return the error object + */ + E mapError(Class errorClass); } diff --git a/unirest/src/main/java/kong/unirest/RawResponse.java b/unirest/src/main/java/kong/unirest/RawResponse.java index 18ba7c14d..632e516eb 100644 --- a/unirest/src/main/java/kong/unirest/RawResponse.java +++ b/unirest/src/main/java/kong/unirest/RawResponse.java @@ -40,4 +40,5 @@ public interface RawResponse { boolean hasContent(); String getContentType(); String getEncoding(); + Config getConfig(); } diff --git a/unirest/src/main/java/kong/unirest/RawResponseBase.java b/unirest/src/main/java/kong/unirest/RawResponseBase.java index 6f3ff2419..7ff9ff370 100644 --- a/unirest/src/main/java/kong/unirest/RawResponseBase.java +++ b/unirest/src/main/java/kong/unirest/RawResponseBase.java @@ -64,4 +64,8 @@ private String getCharsetFromContentType(String contentType) { return null; } + @Override + public Config getConfig() { + return config; + } } diff --git a/unirest/src/test/java/BehaviorTests/EitherTest.java b/unirest/src/test/java/BehaviorTests/ErrorParsingTest.java similarity index 68% rename from unirest/src/test/java/BehaviorTests/EitherTest.java rename to unirest/src/test/java/BehaviorTests/ErrorParsingTest.java index 22714b365..85278a78a 100644 --- a/unirest/src/test/java/BehaviorTests/EitherTest.java +++ b/unirest/src/test/java/BehaviorTests/ErrorParsingTest.java @@ -26,41 +26,41 @@ package BehaviorTests; import com.fasterxml.jackson.annotation.JsonProperty; -import kong.unirest.HttpEither; +import kong.unirest.HttpResponse; import kong.unirest.Unirest; import org.junit.Test; import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertNull; -public class EitherTest extends BddTest { +public class ErrorParsingTest extends BddTest { @Test public void parsingAnAlternativeErrorObject() { - HttpEither request = Unirest.get(MockServer.ERROR_RESPONSE) - .asObject(RequestCapture.class, ErrorThing.class); + ErrorThing e = Unirest.get(MockServer.ERROR_RESPONSE) + .asObject(RequestCapture.class) + .mapError(ErrorThing.class); - assertEquals("boom!", request.getError().getMessage()); - assertNull(request.getBody()); + assertEquals("boom!", e.getMessage()); } @Test public void ifNoErrorThenGetTheRegularBody() { - HttpEither request = Unirest.get(MockServer.GET) - .asObject(RequestCapture.class, ErrorThing.class); + ErrorThing error = Unirest.get(MockServer.GET) + .asObject(RequestCapture.class) + .mapError(ErrorThing.class); - request.getBody().assertStatus(200); - assertNull(request.getError()); + assertNull(error); } @Test public void failsIfErrorResponseCantBeMapped() { + HttpResponse request = Unirest.get(MockServer.ERROR_RESPONSE) + .asObject(RequestCapture.class); - HttpEither request = Unirest.get(MockServer.ERROR_RESPONSE) - .asObject(RequestCapture.class, NotTheError.class); + NotTheError error = request.mapError(NotTheError.class); - assertEquals(null, request.getError()); - assertEquals(null, request.getBody()); + assertEquals(null, error); assertEquals("{\"message\":\"boom!\"}", request.getParsingError().get().getOriginalBody()); } From e964cbe6a390ac2332d540ce7448dfa2a87a02a4 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 24 Apr 2019 08:06:39 -0500 Subject: [PATCH 0581/1769] add an overload for ifFailure that does the mapping --- CHANGELOG.md | 17 +++++--- .../main/java/kong/unirest/BaseResponse.java | 9 +++++ .../main/java/kong/unirest/HttpResponse.java | 9 +++++ .../java/kong/unirest/SimpleResponse.java | 40 +++++++++++++++++++ .../java/BehaviorTests/ErrorParsingTest.java | 25 ++++++++++-- 5 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 unirest/src/main/java/kong/unirest/SimpleResponse.java diff --git a/CHANGELOG.md b/CHANGELOG.md index a5634bfb9..5e9802f51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,13 +5,18 @@ HttpResponse response = Unirest.get("http://someplace/number") .asString() .map(Integer::valueOf); ``` -* Add a new response builder for getting an object OR an alternative error object. This is nice for systems that return errors in the same format as the primary objects (json, xml, etc). +* Add a few ways to map a error response into a different type than the original ```java -HttpEither response = Unirest.get("http://someplace") - .asObject(Thing.class, ErrorThing.class); - -response.getBody(); // Has the thing -response.getError(); // has an error object (as defined by the server) +ErrorThing error = Unirest.get("http://someplace") + .asObject(Thing.class) + .mapError(ErrorThing.class); // will be null if the request had been successful + +Unirest.get("http://someplace") + .asObject(Thing.class) + .ifFailure(ErrorThing.class, f -> { + // f is a HttpResponse + // this function is not called if the request was succesful + }); ``` diff --git a/unirest/src/main/java/kong/unirest/BaseResponse.java b/unirest/src/main/java/kong/unirest/BaseResponse.java index 4d4045d77..55de9c225 100644 --- a/unirest/src/main/java/kong/unirest/BaseResponse.java +++ b/unirest/src/main/java/kong/unirest/BaseResponse.java @@ -120,4 +120,13 @@ public E mapError(Class errorClass) { } return null; } + + @Override + public HttpResponse ifFailure(Class errorClass, Consumer> consumer) { + if(!isSuccess()){ + E error = mapError(errorClass); + consumer.accept(new SimpleResponse(error, this)); + } + return this; + } } diff --git a/unirest/src/main/java/kong/unirest/HttpResponse.java b/unirest/src/main/java/kong/unirest/HttpResponse.java index 51fdf1729..00b310f22 100644 --- a/unirest/src/main/java/kong/unirest/HttpResponse.java +++ b/unirest/src/main/java/kong/unirest/HttpResponse.java @@ -93,6 +93,15 @@ public interface HttpResponse { */ HttpResponse ifFailure(Consumer> consumer); + + /** + * If the response was NOT a 200-series response or a mapping exception happened. map the original body into a error type and invoke this consumer + * can be chained with ifSuccess + * @param consumer a function to consume a HttpResponse + * @return the same response + */ + HttpResponse ifFailure(Class errorClass, Consumer> consumer); + /** * @return true if the response was a 200-series response and no mapping exception happened, else false */ diff --git a/unirest/src/main/java/kong/unirest/SimpleResponse.java b/unirest/src/main/java/kong/unirest/SimpleResponse.java new file mode 100644 index 000000000..21437d7d8 --- /dev/null +++ b/unirest/src/main/java/kong/unirest/SimpleResponse.java @@ -0,0 +1,40 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +class SimpleResponse extends BaseResponse { + private final T body; + + SimpleResponse(T body, BaseResponse response) { + super(response); + this.body = body; + } + + @Override + public T getBody() { + return body; + } +} diff --git a/unirest/src/test/java/BehaviorTests/ErrorParsingTest.java b/unirest/src/test/java/BehaviorTests/ErrorParsingTest.java index 85278a78a..65f77cc8e 100644 --- a/unirest/src/test/java/BehaviorTests/ErrorParsingTest.java +++ b/unirest/src/test/java/BehaviorTests/ErrorParsingTest.java @@ -30,10 +30,10 @@ import kong.unirest.Unirest; import org.junit.Test; -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.assertNull; +import static junit.framework.TestCase.*; public class ErrorParsingTest extends BddTest { + private boolean errorCalled; @Test public void parsingAnAlternativeErrorObject() { @@ -41,7 +41,7 @@ public void parsingAnAlternativeErrorObject() { .asObject(RequestCapture.class) .mapError(ErrorThing.class); - assertEquals("boom!", e.getMessage()); + assertErrorThing(e); } @Test @@ -64,7 +64,26 @@ public void failsIfErrorResponseCantBeMapped() { assertEquals("{\"message\":\"boom!\"}", request.getParsingError().get().getOriginalBody()); } + @Test + public void mapTheErrorWithAFunction() { + errorCalled = false; + Unirest.get(MockServer.ERROR_RESPONSE) + .asObject(RequestCapture.class) + .ifFailure(ErrorThing.class, e -> { + assertEquals(400, e.getStatus()); + assertErrorThing(e.getBody()); + errorCalled = true; + }).ifSuccess(e -> {throw new AssertionError("No");}); + + assertTrue(errorCalled); + } + + private void assertErrorThing(ErrorThing e) { + assertEquals("boom!", e.getMessage()); + } + public static class NotTheError { + @JsonProperty("merp") public String merp; } From eb0930e891fcadd1b080073017452e0946042bfa Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 24 Apr 2019 08:15:39 -0500 Subject: [PATCH 0582/1769] [maven-release-plugin] prepare release v2.2.02 --- object-mapper-gson/pom.xml | 2 +- object-mapper-jackson/pom.xml | 2 +- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/object-mapper-gson/pom.xml b/object-mapper-gson/pom.xml index 9fa6bb717..2a43ec275 100644 --- a/object-mapper-gson/pom.xml +++ b/object-mapper-gson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.2.02-SNAPSHOT + 2.2.02 unirest-object-mappers-gson diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index a37253240..775377dc7 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.2.02-SNAPSHOT + 2.2.02 unirest-objectmapper-jackson diff --git a/pom.xml b/pom.xml index c9893e83a..c68c43ead 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.2.02-SNAPSHOT + 2.2.02 unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -34,7 +34,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - HEAD + v2.2.02 diff --git a/unirest/pom.xml b/unirest/pom.xml index 4bfc3b7da..0d389f48f 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.2.02-SNAPSHOT + 2.2.02 Simplified, lightweight HTTP client library. From 2b4b328593f509d1302c30a356bdf2606295bc6d Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 24 Apr 2019 08:15:44 -0500 Subject: [PATCH 0583/1769] [maven-release-plugin] prepare for next development iteration --- object-mapper-gson/pom.xml | 2 +- object-mapper-jackson/pom.xml | 2 +- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/object-mapper-gson/pom.xml b/object-mapper-gson/pom.xml index 2a43ec275..9e283519b 100644 --- a/object-mapper-gson/pom.xml +++ b/object-mapper-gson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.2.02 + 2.2.03-SNAPSHOT unirest-object-mappers-gson diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index 775377dc7..7b57ba03b 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.2.02 + 2.2.03-SNAPSHOT unirest-objectmapper-jackson diff --git a/pom.xml b/pom.xml index c68c43ead..258c2bbd6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.2.02 + 2.2.03-SNAPSHOT unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -34,7 +34,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - v2.2.02 + HEAD diff --git a/unirest/pom.xml b/unirest/pom.xml index 0d389f48f..59d114381 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.2.02 + 2.2.03-SNAPSHOT Simplified, lightweight HTTP client library. From ce4a5872ea056ecac05df95724f2ac848739f15c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 26 Apr 2019 09:32:56 -0500 Subject: [PATCH 0584/1769] update docs --- CHANGELOG.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e9802f51..85c395e17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 2.2.02 (pending) +## 2.2.02 * Add a mapper function to transform a HttpResponse to a HttpResponse ```java HttpResponse response = Unirest.get("http://someplace/number") diff --git a/README.md b/README.md index 778f0c673..c9e3fd562 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ We are looking for official maintainers, check out issue [#252](https://github.c com.konghq unirest-java - 2.2.00 + 2.2.02 ``` From c9530a66db65d21a80888e27394933eabf19bf96 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 28 Apr 2019 09:11:13 -0500 Subject: [PATCH 0585/1769] start to introduce a metric object --- .../main/java/kong/unirest/BaseRequest.java | 5 + .../src/main/java/kong/unirest/Config.java | 10 ++ .../main/java/kong/unirest/HttpRequest.java | 12 +- .../java/kong/unirest/HttpRequestSummary.java | 43 ++++++++ .../main/java/kong/unirest/MetricContext.java | 31 ++++++ .../main/java/kong/unirest/NoopMetric.java | 33 ++++++ unirest/src/main/java/kong/unirest/Path.java | 6 + .../main/java/kong/unirest/RawResponse.java | 4 +- .../java/kong/unirest/ResponseSummary.java | 31 ++++++ .../src/main/java/kong/unirest/UniMetric.java | 30 +++++ .../kong/unirest/apache/ApacheClient.java | 7 +- .../test/java/BehaviorTests/MetricsTest.java | 104 ++++++++++++++++++ .../src/test/java/BehaviorTests/MyMetric.java | 65 +++++++++++ 13 files changed, 365 insertions(+), 16 deletions(-) create mode 100644 unirest/src/main/java/kong/unirest/HttpRequestSummary.java create mode 100644 unirest/src/main/java/kong/unirest/MetricContext.java create mode 100644 unirest/src/main/java/kong/unirest/NoopMetric.java create mode 100644 unirest/src/main/java/kong/unirest/ResponseSummary.java create mode 100644 unirest/src/main/java/kong/unirest/UniMetric.java create mode 100644 unirest/src/test/java/BehaviorTests/MetricsTest.java create mode 100644 unirest/src/test/java/BehaviorTests/MyMetric.java diff --git a/unirest/src/main/java/kong/unirest/BaseRequest.java b/unirest/src/main/java/kong/unirest/BaseRequest.java index bdc509a48..a20af16b1 100644 --- a/unirest/src/main/java/kong/unirest/BaseRequest.java +++ b/unirest/src/main/java/kong/unirest/BaseRequest.java @@ -312,6 +312,11 @@ public String getUrl() { return url.toString(); } + @Override + public String getRawPath() { + return url.rawPath(); + } + @Override public Headers getHeaders() { return headers; diff --git a/unirest/src/main/java/kong/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java index f2ee271a1..f8eb987d5 100644 --- a/unirest/src/main/java/kong/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -75,6 +75,7 @@ public class Config { private KeyStore keystore; private String keystorePassword; private String cookieSpec; + private UniMetric metrics = new NoopMetric(); public Config() { setDefaults(); @@ -336,6 +337,11 @@ public Config addDefaultHeader(String name, String value) { return this; } + public Config instramentWith(UniMetric metric) { + this.metrics = metric; + return this; + } + /** * Add a HttpRequestInterceptor to the clients. This can be called multiple times to add as many as you like. * https://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/HttpRequestInterceptor.html @@ -650,4 +656,8 @@ public boolean shouldAddShutdownHook() { public String getCookieSpec() { return cookieSpec; } + + public UniMetric getMetric() { + return metrics; + } } diff --git a/unirest/src/main/java/kong/unirest/HttpRequest.java b/unirest/src/main/java/kong/unirest/HttpRequest.java index f6d2b2de4..1a4a7bc26 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequest.java +++ b/unirest/src/main/java/kong/unirest/HttpRequest.java @@ -37,7 +37,7 @@ The primary request builder used to create a request. This will be completed after calling one of the "as**" methods like asString() */ -public interface HttpRequest { +public interface HttpRequest extends HttpRequestSummary { /** * add a route param that replaces the matching {name} * For example routeParam("name", "fred") will replace {name} in @@ -340,16 +340,6 @@ PagedList asPaged(Function mappingFunction, */ void thenConsumeAsync(Consumer consumer); - /** - * @return The HTTP method of the request - */ - HttpMethod getHttpMethod(); - - /** - * @return The current URL string for the request - */ - String getUrl(); - /** * @return the current headers for the request */ diff --git a/unirest/src/main/java/kong/unirest/HttpRequestSummary.java b/unirest/src/main/java/kong/unirest/HttpRequestSummary.java new file mode 100644 index 000000000..b24dc547d --- /dev/null +++ b/unirest/src/main/java/kong/unirest/HttpRequestSummary.java @@ -0,0 +1,43 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +public interface HttpRequestSummary { + /** + * @return The HTTP method of the request + */ + HttpMethod getHttpMethod(); + + /** + * @return The current URL string for the request + */ + String getUrl(); + + /** + * @return The raw un-parameterized path (http://somewhere/{param}) + */ + String getRawPath(); +} diff --git a/unirest/src/main/java/kong/unirest/MetricContext.java b/unirest/src/main/java/kong/unirest/MetricContext.java new file mode 100644 index 000000000..fe64ae9a6 --- /dev/null +++ b/unirest/src/main/java/kong/unirest/MetricContext.java @@ -0,0 +1,31 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +@FunctionalInterface +public interface MetricContext { + void complete(ResponseSummary httpResponse, Exception ex); +} diff --git a/unirest/src/main/java/kong/unirest/NoopMetric.java b/unirest/src/main/java/kong/unirest/NoopMetric.java new file mode 100644 index 000000000..86a68cd40 --- /dev/null +++ b/unirest/src/main/java/kong/unirest/NoopMetric.java @@ -0,0 +1,33 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +class NoopMetric implements UniMetric { + @Override + public MetricContext begin(HttpRequestSummary request) { + return (r,e) -> {}; + } +} diff --git a/unirest/src/main/java/kong/unirest/Path.java b/unirest/src/main/java/kong/unirest/Path.java index f93d57fc2..deeed3558 100644 --- a/unirest/src/main/java/kong/unirest/Path.java +++ b/unirest/src/main/java/kong/unirest/Path.java @@ -34,9 +34,11 @@ class Path { private String url; + private String rawPath; Path(String url) { this.url = url; + this.rawPath = url; } public void param(Map params) { @@ -91,4 +93,8 @@ public void queryString(Map parameters) { public String toString() { return url; } + + public String rawPath() { + return rawPath; + } } diff --git a/unirest/src/main/java/kong/unirest/RawResponse.java b/unirest/src/main/java/kong/unirest/RawResponse.java index 632e516eb..6903edb13 100644 --- a/unirest/src/main/java/kong/unirest/RawResponse.java +++ b/unirest/src/main/java/kong/unirest/RawResponse.java @@ -28,9 +28,7 @@ import java.io.InputStream; import java.io.InputStreamReader; -public interface RawResponse { - int getStatus(); - String getStatusText(); +public interface RawResponse extends ResponseSummary { Headers getHeaders(); InputStream getContent(); byte[] getContentAsBytes(); diff --git a/unirest/src/main/java/kong/unirest/ResponseSummary.java b/unirest/src/main/java/kong/unirest/ResponseSummary.java new file mode 100644 index 000000000..01eeb24c4 --- /dev/null +++ b/unirest/src/main/java/kong/unirest/ResponseSummary.java @@ -0,0 +1,31 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +public interface ResponseSummary { + int getStatus(); + String getStatusText(); +} diff --git a/unirest/src/main/java/kong/unirest/UniMetric.java b/unirest/src/main/java/kong/unirest/UniMetric.java new file mode 100644 index 000000000..6368b1a30 --- /dev/null +++ b/unirest/src/main/java/kong/unirest/UniMetric.java @@ -0,0 +1,30 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +public interface UniMetric { + MetricContext begin(HttpRequestSummary request); +} diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java index 93bc1f1d5..1d1f593aa 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java @@ -99,13 +99,16 @@ public ApacheClient(HttpClient httpClient, Config config, PoolingHttpClientConne public HttpResponse request(HttpRequest request, Function> transformer) { HttpRequestBase requestObj = new RequestPrep(request, config, false).prepare(); - + MetricContext metric = config.getMetric().begin(request); try { org.apache.http.HttpResponse execute = client.execute(requestObj); - HttpResponse httpResponse = transformer.apply(new ApacheResponse(execute, config)); + ApacheResponse t = new ApacheResponse(execute, config); + metric.complete(t, null); + HttpResponse httpResponse = transformer.apply(t); requestObj.releaseConnection(); return httpResponse; } catch (Exception e) { + metric.complete(null, e); throw new UnirestException(e); } finally { requestObj.releaseConnection(); diff --git a/unirest/src/test/java/BehaviorTests/MetricsTest.java b/unirest/src/test/java/BehaviorTests/MetricsTest.java new file mode 100644 index 000000000..31d577556 --- /dev/null +++ b/unirest/src/test/java/BehaviorTests/MetricsTest.java @@ -0,0 +1,104 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package BehaviorTests; + +import kong.unirest.HttpRequestSummary; +import kong.unirest.Unirest; +import org.junit.Test; + +import static BehaviorTests.MockServer.*; +import static org.junit.Assert.assertEquals; + +public class MetricsTest extends BddTest { + @Test + public void canSetAMetricObjectToInstramentUnirest() { + MyMetric metric = new MyMetric(HttpRequestSummary::getUrl); + Unirest.config().instramentWith(metric); + + Unirest.get(GET).asEmpty(); + Unirest.get(GET).asEmpty(); + Unirest.get(PASSED_PATH_PARAM) + .routeParam("params","foo") + .queryString("fruit","orange") + .asEmpty(); + + assertEquals(2, metric.routes.get(GET).size()); + assertEquals(1, metric.routes.get("http://localhost:4567/get/foo/passed?fruit=orange").size()); + } + + @Test + public void canGetParamedUrlInSummary() { + MyMetric metric = new MyMetric(HttpRequestSummary::getRawPath); + Unirest.config().instramentWith(metric); + + Unirest.get(PASSED_PATH_PARAM) + .routeParam("params","foo") + .queryString("fruit","orange") + .asEmpty(); + + assertEquals(1, metric.routes.get("http://localhost:4567/get/{params}/passed").size()); + } + + @Test + public void canGetToMethod() { + MyMetric metric = new MyMetric(s -> s.getHttpMethod().name()); + Unirest.config().instramentWith(metric); + + Unirest.get(GET).asEmpty(); + Unirest.get(GET).asEmpty(); + Unirest.post(POST).asEmpty(); + Unirest.delete(DELETE).asEmpty(); + + assertEquals(2, metric.routes.get("GET").size()); + assertEquals(1, metric.routes.get("DELETE").size()); + } + + @Test + public void amountOfTimeBetweenRequestAndResponseDoesNotIncludeDeserialization() { + MyMetric metric = new MyMetric(HttpRequestSummary::getUrl); + Unirest.config().instramentWith(metric); + + Unirest.get(GET).asObject(r -> { + assertEquals(1, metric.routes.get(GET).size()); + return null; + }); + } + + @Test + public void canGetInformationOnStatus() { + MyMetric metric = new MyMetric(HttpRequestSummary::getUrl); + Unirest.config().followRedirects(false).instramentWith(metric); + + Unirest.get(GET).asEmpty(); + Unirest.get(REDIRECT).asEmpty(); + Unirest.get(REDIRECT).asEmpty(); + Unirest.get(ERROR_RESPONSE).asEmpty(); + + assertEquals(1L, metric.countResponses(200)); + assertEquals(2L, metric.countResponses(301)); + assertEquals(1L, metric.countResponses(400)); + } +} diff --git a/unirest/src/test/java/BehaviorTests/MyMetric.java b/unirest/src/test/java/BehaviorTests/MyMetric.java new file mode 100644 index 000000000..4e168b04d --- /dev/null +++ b/unirest/src/test/java/BehaviorTests/MyMetric.java @@ -0,0 +1,65 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package BehaviorTests; + +import com.google.common.collect.ArrayListMultimap; +import kong.unirest.HttpRequestSummary; +import kong.unirest.MetricContext; +import kong.unirest.UniMetric; + +import java.util.function.Function; + +public class MyMetric implements UniMetric { + private final Function keyFunction; + public ArrayListMultimap routes = ArrayListMultimap.create(); + + public MyMetric(Function keyFunction){ + this.keyFunction = keyFunction; + } + + @Override + public MetricContext begin(HttpRequestSummary request) { + long startNanos = System.nanoTime(); + return (r, e) -> routes.put(keyFunction.apply(request), new Execution(System.nanoTime() - startNanos, r.getStatus())); + } + + public long countResponses(int i) { + return routes.entries() + .stream() + .filter(e -> e.getValue().status == i) + .count(); + } + + public static class Execution { + public final long time; + public final int status; + + public Execution(long time, int status){ + this.time = time; + this.status = status; + } + } +} From b9680b532999bdc547eb706822a18c9aa78c4173 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 28 Apr 2019 11:40:00 -0500 Subject: [PATCH 0586/1769] dont put the entire request and response into the metric so folks dont end up holding them --- .../main/java/kong/unirest/BaseRequest.java | 14 +++-- .../main/java/kong/unirest/HttpRequest.java | 17 +++++- .../kong/unirest/HttpResponseSummary.java | 31 +++++++++++ .../main/java/kong/unirest/MetricContext.java | 2 +- .../main/java/kong/unirest/RawResponse.java | 5 +- .../java/kong/unirest/RawResponseBase.java | 5 ++ .../java/kong/unirest/RequestSummary.java | 53 +++++++++++++++++++ .../java/kong/unirest/ResponseSummary.java | 21 ++++++-- .../kong/unirest/apache/ApacheClient.java | 4 +- .../java/kong/unirest/ResponseUtilsTest.java | 5 ++ 10 files changed, 144 insertions(+), 13 deletions(-) create mode 100644 unirest/src/main/java/kong/unirest/HttpResponseSummary.java create mode 100644 unirest/src/main/java/kong/unirest/RequestSummary.java diff --git a/unirest/src/main/java/kong/unirest/BaseRequest.java b/unirest/src/main/java/kong/unirest/BaseRequest.java index a20af16b1..4f5216818 100644 --- a/unirest/src/main/java/kong/unirest/BaseRequest.java +++ b/unirest/src/main/java/kong/unirest/BaseRequest.java @@ -312,11 +312,6 @@ public String getUrl() { return url.toString(); } - @Override - public String getRawPath() { - return url.rawPath(); - } - @Override public Headers getHeaders() { return headers; @@ -341,10 +336,19 @@ public Proxy getProxy() { return valueOr(proxy, config::getProxy); } + @Override + public HttpRequestSummary toSummary() { + return new RequestSummary(this); + } + private T valueOr(T x, Supplier o){ if(x != null){ return x; } return o.get(); } + + Path getPath() { + return url; + } } diff --git a/unirest/src/main/java/kong/unirest/HttpRequest.java b/unirest/src/main/java/kong/unirest/HttpRequest.java index 1a4a7bc26..962901541 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequest.java +++ b/unirest/src/main/java/kong/unirest/HttpRequest.java @@ -37,7 +37,7 @@ The primary request builder used to create a request. This will be completed after calling one of the "as**" methods like asString() */ -public interface HttpRequest extends HttpRequestSummary { +public interface HttpRequest { /** * add a route param that replaces the matching {name} * For example routeParam("name", "fred") will replace {name} in @@ -340,6 +340,16 @@ PagedList asPaged(Function mappingFunction, */ void thenConsumeAsync(Consumer consumer); + /** + * @return The HTTP method of the request + */ + HttpMethod getHttpMethod(); + + /** + * @return The current URL string for the request + */ + String getUrl(); + /** * @return the current headers for the request */ @@ -366,4 +376,9 @@ default Optional getBody(){ * @return the proxy for this request */ Proxy getProxy(); + + /** + * @return a summary for the response, used in metrics + */ + HttpRequestSummary toSummary(); } diff --git a/unirest/src/main/java/kong/unirest/HttpResponseSummary.java b/unirest/src/main/java/kong/unirest/HttpResponseSummary.java new file mode 100644 index 000000000..2ca1d31ee --- /dev/null +++ b/unirest/src/main/java/kong/unirest/HttpResponseSummary.java @@ -0,0 +1,31 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +public interface HttpResponseSummary { + int getStatus(); + String getStatusText(); +} diff --git a/unirest/src/main/java/kong/unirest/MetricContext.java b/unirest/src/main/java/kong/unirest/MetricContext.java index fe64ae9a6..99d3c532b 100644 --- a/unirest/src/main/java/kong/unirest/MetricContext.java +++ b/unirest/src/main/java/kong/unirest/MetricContext.java @@ -27,5 +27,5 @@ @FunctionalInterface public interface MetricContext { - void complete(ResponseSummary httpResponse, Exception ex); + void complete(HttpResponseSummary httpResponse, Exception ex); } diff --git a/unirest/src/main/java/kong/unirest/RawResponse.java b/unirest/src/main/java/kong/unirest/RawResponse.java index 6903edb13..8b9fc11ab 100644 --- a/unirest/src/main/java/kong/unirest/RawResponse.java +++ b/unirest/src/main/java/kong/unirest/RawResponse.java @@ -28,7 +28,9 @@ import java.io.InputStream; import java.io.InputStreamReader; -public interface RawResponse extends ResponseSummary { +public interface RawResponse { + int getStatus(); + String getStatusText(); Headers getHeaders(); InputStream getContent(); byte[] getContentAsBytes(); @@ -39,4 +41,5 @@ public interface RawResponse extends ResponseSummary { String getContentType(); String getEncoding(); Config getConfig(); + HttpResponseSummary toSummary(); } diff --git a/unirest/src/main/java/kong/unirest/RawResponseBase.java b/unirest/src/main/java/kong/unirest/RawResponseBase.java index 7ff9ff370..66e0fbe9c 100644 --- a/unirest/src/main/java/kong/unirest/RawResponseBase.java +++ b/unirest/src/main/java/kong/unirest/RawResponseBase.java @@ -68,4 +68,9 @@ private String getCharsetFromContentType(String contentType) { public Config getConfig() { return config; } + + @Override + public HttpResponseSummary toSummary() { + return new ResponseSummary(this); + } } diff --git a/unirest/src/main/java/kong/unirest/RequestSummary.java b/unirest/src/main/java/kong/unirest/RequestSummary.java new file mode 100644 index 000000000..743112571 --- /dev/null +++ b/unirest/src/main/java/kong/unirest/RequestSummary.java @@ -0,0 +1,53 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +class RequestSummary implements HttpRequestSummary { + private final String rawPath; + private final String url; + private final HttpMethod method; + + RequestSummary(BaseRequest request) { + this.url = request.getUrl(); + this.method = request.getHttpMethod(); + this.rawPath = request.getPath().rawPath(); + } + + @Override + public HttpMethod getHttpMethod() { + return method; + } + + @Override + public String getUrl() { + return url; + } + + @Override + public String getRawPath() { + return rawPath; + } +} diff --git a/unirest/src/main/java/kong/unirest/ResponseSummary.java b/unirest/src/main/java/kong/unirest/ResponseSummary.java index 01eeb24c4..5985b689a 100644 --- a/unirest/src/main/java/kong/unirest/ResponseSummary.java +++ b/unirest/src/main/java/kong/unirest/ResponseSummary.java @@ -25,7 +25,22 @@ package kong.unirest; -public interface ResponseSummary { - int getStatus(); - String getStatusText(); +class ResponseSummary implements HttpResponseSummary { + private final int status; + private final String statusText; + + ResponseSummary(RawResponse response) { + this.status = response.getStatus(); + this.statusText = response.getStatusText(); + } + + @Override + public int getStatus() { + return status; + } + + @Override + public String getStatusText() { + return statusText; + } } diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java index 1d1f593aa..be930ca7b 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java @@ -99,11 +99,11 @@ public ApacheClient(HttpClient httpClient, Config config, PoolingHttpClientConne public HttpResponse request(HttpRequest request, Function> transformer) { HttpRequestBase requestObj = new RequestPrep(request, config, false).prepare(); - MetricContext metric = config.getMetric().begin(request); + MetricContext metric = config.getMetric().begin(request.toSummary()); try { org.apache.http.HttpResponse execute = client.execute(requestObj); ApacheResponse t = new ApacheResponse(execute, config); - metric.complete(t, null); + metric.complete(t.toSummary(), null); HttpResponse httpResponse = transformer.apply(t); requestObj.releaseConnection(); return httpResponse; diff --git a/unirest/src/test/java/kong/unirest/ResponseUtilsTest.java b/unirest/src/test/java/kong/unirest/ResponseUtilsTest.java index 983157391..d56266526 100644 --- a/unirest/src/test/java/kong/unirest/ResponseUtilsTest.java +++ b/unirest/src/test/java/kong/unirest/ResponseUtilsTest.java @@ -140,5 +140,10 @@ public String getContentType() { public String getEncoding() { return null; } + + @Override + public HttpResponseSummary toSummary() { + return null; + } } } \ No newline at end of file From 10b165968f94258106777a2937addfb10599aec7 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 28 Apr 2019 11:56:23 -0500 Subject: [PATCH 0587/1769] add in async methods --- .../unirest/apache/ApacheAsyncClient.java | 11 +++++++--- .../test/java/BehaviorTests/MetricsTest.java | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java index d94cc2392..b6ab4a216 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java @@ -142,21 +142,26 @@ public CompletableFuture> request( Objects.requireNonNull(callback); HttpUriRequest requestObj = new RequestPrep(request, config, true).prepare(); - + MetricContext metric = config.getMetric().begin(request.toSummary()); client.execute(requestObj, new FutureCallback() { @Override public void completed(org.apache.http.HttpResponse httpResponse) { - callback.complete(transformer.apply(new ApacheResponse(httpResponse, config))); + ApacheResponse t = new ApacheResponse(httpResponse, config); + metric.complete(t.toSummary(), null); + callback.complete(transformer.apply(t)); } @Override public void failed(Exception e) { + metric.complete(null, e); callback.completeExceptionally(e); } @Override public void cancelled() { - callback.completeExceptionally(new UnirestException("canceled")); + UnirestException canceled = new UnirestException("canceled"); + metric.complete(null, canceled); + callback.completeExceptionally(canceled); } }); return callback; diff --git a/unirest/src/test/java/BehaviorTests/MetricsTest.java b/unirest/src/test/java/BehaviorTests/MetricsTest.java index 31d577556..a5970c71a 100644 --- a/unirest/src/test/java/BehaviorTests/MetricsTest.java +++ b/unirest/src/test/java/BehaviorTests/MetricsTest.java @@ -101,4 +101,25 @@ public void canGetInformationOnStatus() { assertEquals(2L, metric.countResponses(301)); assertEquals(1L, metric.countResponses(400)); } + + @Test + public void metricsOnAsyncRequests() throws Exception { + MyMetric metric = new MyMetric(HttpRequestSummary::getUrl); + Unirest.config().instramentWith(metric); + + Unirest.get(GET).asEmptyAsync().get(); + + assertEquals(1L, metric.countResponses(200)); + } + + @Test + public void metricsOnAsyncMethodsWithCallbacks() { + MyMetric metric = new MyMetric(HttpRequestSummary::getUrl); + Unirest.config().instramentWith(metric); + + Unirest.get(GET).asEmptyAsync(r -> asyncSuccess()); + + assertAsync(); + assertEquals(1L, metric.countResponses(200)); + } } From 6971ff058d8cbd36ceb9b3b9ac46d849cf00c9f4 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sun, 28 Apr 2019 14:25:28 -0500 Subject: [PATCH 0588/1769] add error handling --- .../main/java/kong/unirest/BasicResponse.java | 7 +- .../unirest/apache/ApacheAsyncClient.java | 2 +- .../kong/unirest/apache/ApacheClient.java | 2 +- .../kong/unirest/apache/BaseApacheClient.java | 22 +++++ .../test/java/BehaviorTests/MetricsTest.java | 80 ++++++++++++++----- .../src/test/java/BehaviorTests/MyMetric.java | 16 +++- .../BehaviorTests/ObjectFunctionalTest.java | 35 +++++++- 7 files changed, 139 insertions(+), 25 deletions(-) diff --git a/unirest/src/main/java/kong/unirest/BasicResponse.java b/unirest/src/main/java/kong/unirest/BasicResponse.java index b94ce12f9..5b086c86e 100644 --- a/unirest/src/main/java/kong/unirest/BasicResponse.java +++ b/unirest/src/main/java/kong/unirest/BasicResponse.java @@ -25,7 +25,7 @@ package kong.unirest; -class BasicResponse extends BaseResponse { +public class BasicResponse extends BaseResponse { private final T body; public BasicResponse(RawResponse httpResponse, T body) { @@ -33,6 +33,11 @@ public BasicResponse(RawResponse httpResponse, T body) { this.body = body; } + public BasicResponse(RawResponse httpResponse, String ogBody, RuntimeException ex) { + this(httpResponse, null); + setParsingException(ogBody, ex); + } + @Override public T getBody() { return body; diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java index b6ab4a216..b52078b2f 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java @@ -148,7 +148,7 @@ public CompletableFuture> request( public void completed(org.apache.http.HttpResponse httpResponse) { ApacheResponse t = new ApacheResponse(httpResponse, config); metric.complete(t.toSummary(), null); - callback.complete(transformer.apply(t)); + callback.complete(transformBody(transformer, t)); } @Override diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java index be930ca7b..43676e9b3 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java @@ -104,7 +104,7 @@ public HttpResponse request(HttpRequest request, Function httpResponse = transformer.apply(t); + HttpResponse httpResponse = transformBody(transformer, t); requestObj.releaseConnection(); return httpResponse; } catch (Exception e) { diff --git a/unirest/src/main/java/kong/unirest/apache/BaseApacheClient.java b/unirest/src/main/java/kong/unirest/apache/BaseApacheClient.java index 93c989362..402c88043 100644 --- a/unirest/src/main/java/kong/unirest/apache/BaseApacheClient.java +++ b/unirest/src/main/java/kong/unirest/apache/BaseApacheClient.java @@ -25,12 +25,17 @@ package kong.unirest.apache; +import kong.unirest.BasicResponse; +import kong.unirest.HttpResponse; import kong.unirest.Proxy; +import kong.unirest.RawResponse; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.CredentialsProvider; import org.apache.http.impl.client.BasicCredentialsProvider; +import java.util.function.Function; + abstract class BaseApacheClient { protected CredentialsProvider toApacheCreds(Proxy proxy) { @@ -42,4 +47,21 @@ protected CredentialsProvider toApacheCreds(Proxy proxy) { } return null; } + + protected HttpResponse transformBody(Function> transformer, RawResponse rr) { + try { + return transformer.apply(rr); + }catch (RuntimeException e){ + String originalBody = recoverBody(rr); + return new BasicResponse(rr, originalBody, e); + } + } + + private String recoverBody(RawResponse rr){ + try { + return rr.getContentAsString(); + }catch (Exception e){ + return null; + } + } } diff --git a/unirest/src/test/java/BehaviorTests/MetricsTest.java b/unirest/src/test/java/BehaviorTests/MetricsTest.java index a5970c71a..cdc712039 100644 --- a/unirest/src/test/java/BehaviorTests/MetricsTest.java +++ b/unirest/src/test/java/BehaviorTests/MetricsTest.java @@ -25,24 +25,35 @@ package BehaviorTests; +import kong.unirest.Client; +import kong.unirest.Config; import kong.unirest.HttpRequestSummary; import kong.unirest.Unirest; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.concurrent.FutureCallback; +import org.apache.http.nio.client.HttpAsyncClient; +import org.junit.Ignore; import org.junit.Test; +import java.util.function.Function; + import static BehaviorTests.MockServer.*; import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class MetricsTest extends BddTest { @Test public void canSetAMetricObjectToInstramentUnirest() { - MyMetric metric = new MyMetric(HttpRequestSummary::getUrl); - Unirest.config().instramentWith(metric); + MyMetric metric = configureMetric(); Unirest.get(GET).asEmpty(); Unirest.get(GET).asEmpty(); Unirest.get(PASSED_PATH_PARAM) - .routeParam("params","foo") - .queryString("fruit","orange") + .routeParam("params", "foo") + .queryString("fruit", "orange") .asEmpty(); assertEquals(2, metric.routes.get(GET).size()); @@ -51,12 +62,11 @@ public void canSetAMetricObjectToInstramentUnirest() { @Test public void canGetParamedUrlInSummary() { - MyMetric metric = new MyMetric(HttpRequestSummary::getRawPath); - Unirest.config().instramentWith(metric); + MyMetric metric = configureMetric(HttpRequestSummary::getRawPath); Unirest.get(PASSED_PATH_PARAM) - .routeParam("params","foo") - .queryString("fruit","orange") + .routeParam("params", "foo") + .queryString("fruit", "orange") .asEmpty(); assertEquals(1, metric.routes.get("http://localhost:4567/get/{params}/passed").size()); @@ -64,8 +74,7 @@ public void canGetParamedUrlInSummary() { @Test public void canGetToMethod() { - MyMetric metric = new MyMetric(s -> s.getHttpMethod().name()); - Unirest.config().instramentWith(metric); + MyMetric metric = configureMetric(s -> s.getHttpMethod().name()); Unirest.get(GET).asEmpty(); Unirest.get(GET).asEmpty(); @@ -78,8 +87,7 @@ public void canGetToMethod() { @Test public void amountOfTimeBetweenRequestAndResponseDoesNotIncludeDeserialization() { - MyMetric metric = new MyMetric(HttpRequestSummary::getUrl); - Unirest.config().instramentWith(metric); + MyMetric metric = configureMetric(); Unirest.get(GET).asObject(r -> { assertEquals(1, metric.routes.get(GET).size()); @@ -89,8 +97,7 @@ public void amountOfTimeBetweenRequestAndResponseDoesNotIncludeDeserialization() @Test public void canGetInformationOnStatus() { - MyMetric metric = new MyMetric(HttpRequestSummary::getUrl); - Unirest.config().followRedirects(false).instramentWith(metric); + MyMetric metric = configureMetric(HttpRequestSummary::getUrl); Unirest.get(GET).asEmpty(); Unirest.get(REDIRECT).asEmpty(); @@ -104,8 +111,7 @@ public void canGetInformationOnStatus() { @Test public void metricsOnAsyncRequests() throws Exception { - MyMetric metric = new MyMetric(HttpRequestSummary::getUrl); - Unirest.config().instramentWith(metric); + MyMetric metric = configureMetric(); Unirest.get(GET).asEmptyAsync().get(); @@ -114,12 +120,50 @@ public void metricsOnAsyncRequests() throws Exception { @Test public void metricsOnAsyncMethodsWithCallbacks() { - MyMetric metric = new MyMetric(HttpRequestSummary::getUrl); - Unirest.config().instramentWith(metric); + MyMetric metric = configureMetric(); Unirest.get(GET).asEmptyAsync(r -> asyncSuccess()); assertAsync(); assertEquals(1L, metric.countResponses(200)); } + + @Test + public void errorHandling() throws Exception { + HttpClient mock = mock(HttpClient.class); + when(mock.execute(any(HttpRequestBase.class))).thenThrow(new RuntimeException("boo")); + MyMetric metric = new MyMetric(HttpRequestSummary::getUrl); + Unirest.config().reset().httpClient(mock).instramentWith(metric); + + try { + Unirest.get(GET).asEmpty(); + }catch (Exception e){ + + } + + assertEquals("boo", metric.routes.get(GET).get(0).e.getMessage()); + } + + @Test @Ignore + public void errorHandling_async() throws Exception { + MyMetric metric = configureMetric(); + + try { + Unirest.get("http://localhost:0000").asEmptyAsync().get(); + }catch (Exception e){ + + } + + assertEquals("Connection refused", metric.routes.get("http://localhost:0000").get(0).e.getMessage()); + } + + private MyMetric configureMetric() { + return configureMetric(HttpRequestSummary::getUrl); + } + + private MyMetric configureMetric(Function keyFunction) { + MyMetric metric = new MyMetric(keyFunction); + Unirest.config().followRedirects(false).instramentWith(metric); + return metric; + } } diff --git a/unirest/src/test/java/BehaviorTests/MyMetric.java b/unirest/src/test/java/BehaviorTests/MyMetric.java index 4e168b04d..6d1cb03f1 100644 --- a/unirest/src/test/java/BehaviorTests/MyMetric.java +++ b/unirest/src/test/java/BehaviorTests/MyMetric.java @@ -27,6 +27,7 @@ import com.google.common.collect.ArrayListMultimap; import kong.unirest.HttpRequestSummary; +import kong.unirest.HttpResponseSummary; import kong.unirest.MetricContext; import kong.unirest.UniMetric; @@ -43,7 +44,16 @@ public MyMetric(Function keyFunction){ @Override public MetricContext begin(HttpRequestSummary request) { long startNanos = System.nanoTime(); - return (r, e) -> routes.put(keyFunction.apply(request), new Execution(System.nanoTime() - startNanos, r.getStatus())); + return (r, e) -> { + routes.put(keyFunction.apply(request), new Execution(System.nanoTime() - startNanos, statusOr(r), e)); + }; + } + + private int statusOr(HttpResponseSummary r) { + if(r == null){ + return -1; + } + return r.getStatus(); } public long countResponses(int i) { @@ -56,10 +66,12 @@ public long countResponses(int i) { public static class Execution { public final long time; public final int status; + public final Exception e; - public Execution(long time, int status){ + public Execution(long time, int status, Exception e){ this.time = time; this.status = status; + this.e = e; } } } diff --git a/unirest/src/test/java/BehaviorTests/ObjectFunctionalTest.java b/unirest/src/test/java/BehaviorTests/ObjectFunctionalTest.java index 6f4a3f48c..15c7c1b1b 100644 --- a/unirest/src/test/java/BehaviorTests/ObjectFunctionalTest.java +++ b/unirest/src/test/java/BehaviorTests/ObjectFunctionalTest.java @@ -26,6 +26,7 @@ package BehaviorTests; import com.google.gson.Gson; +import kong.unirest.HttpResponse; import org.junit.Test; import kong.unirest.Unirest; @@ -43,7 +44,6 @@ public void canUseAFunctionToTransform() { MockServer.setJsonAsResponse(of("foo", "bar")); Map r = Unirest.get(MockServer.GET) - .queryString("foo", "bar") .asObject(i -> gson.fromJson(i.getContentReader(), HashMap.class)) .getBody(); @@ -55,11 +55,42 @@ public void canUseAFunctionToTransformAsync() throws Exception { MockServer.setJsonAsResponse(of("foo", "bar")); Map r = Unirest.get(MockServer.GET) - .queryString("foo", "bar") .asObjectAsync(i -> gson.fromJson(i.getContentReader(), HashMap.class)) .get() .getBody(); assertEquals("bar", r.get("foo")); } + + @Test + public void willNotStopForParsingExceptions() { + MockServer.setStringResponse("call me ishmael"); + + RuntimeException ohNoes = new RuntimeException("oh noes"); + + HttpResponse r = Unirest.get(MockServer.GET) + .asObject(i -> { + throw ohNoes; + }); + + assertEquals(200, r.getStatus()); + assertEquals(ohNoes, r.getParsingError().get().getCause()); + assertEquals("call me ishmael", r.getParsingError().get().getOriginalBody()); + } + + @Test + public void willNotStopForParsingExceptions_async() throws Exception { + MockServer.setStringResponse("call me ishmael"); + + RuntimeException ohNoes = new RuntimeException("oh noes"); + + HttpResponse r = Unirest.get(MockServer.GET) + .asObjectAsync(i -> { + throw ohNoes; + }).get(); + + assertEquals(200, r.getStatus()); + assertEquals(ohNoes, r.getParsingError().get().getCause()); + assertEquals("call me ishmael", r.getParsingError().get().getOriginalBody()); + } } From 992515e343f9f71c8a12121c4614705c1a5798a0 Mon Sep 17 00:00:00 2001 From: Onilton Maciel Date: Tue, 30 Apr 2019 10:03:45 -0300 Subject: [PATCH 0589/1769] Remove maintainers needed since issue was closed --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index c9e3fd562..05c021dd1 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,6 @@ [![Javadocs](http://www.javadoc.io/badge/com.konghq/unirest-java.svg)](http://www.javadoc.io/doc/com.konghq/unirest-java) -We are looking for official maintainers, check out issue [#252](https://github.com/Kong/unirest-java/issues/252) - ## Install With [Maven](https://mvnrepository.com/artifact/com.konghq/unirest-java)[:](https://repo.maven.apache.org/maven2/com/konghq/unirest-java/) ```xml From 6e584dd4558d239861adee66ac2d8642a0e06b79 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 30 Apr 2019 13:20:13 -0500 Subject: [PATCH 0590/1769] small test adjustment --- unirest/src/test/java/BehaviorTests/MetricsTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/unirest/src/test/java/BehaviorTests/MetricsTest.java b/unirest/src/test/java/BehaviorTests/MetricsTest.java index cdc712039..1012cc90c 100644 --- a/unirest/src/test/java/BehaviorTests/MetricsTest.java +++ b/unirest/src/test/java/BehaviorTests/MetricsTest.java @@ -155,6 +155,7 @@ public void errorHandling_async() throws Exception { } assertEquals("Connection refused", metric.routes.get("http://localhost:0000").get(0).e.getMessage()); + assertEquals(1, metric.routes.get("http://localhost:0000").size()); } private MyMetric configureMetric() { From 43751449c4ef41b935917aee15fce1435938efab Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 1 May 2019 07:05:04 -0500 Subject: [PATCH 0591/1769] closes #267 make sure hooks are registered regardless of where we are in the lifecycle of the client engines --- CHANGELOG.md | 1 + .../main/java/kong/unirest/AsyncClient.java | 2 + .../src/main/java/kong/unirest/Client.java | 2 + .../src/main/java/kong/unirest/Config.java | 4 ++ .../unirest/apache/ApacheAsyncClient.java | 11 +++- .../kong/unirest/apache/ApacheClient.java | 9 +++ .../java/BehaviorTests/LifeCycleTest.java | 58 ++++++++++++++++--- 7 files changed, 77 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85c395e17..ad4139429 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Unirest.get("http://someplace") }); ``` +* #267 make sure hooks are registered regardless of where we are in the lifecycle of the client engines ## 2.2.01 * add cookiespec policies to config. These are the same as Apache Http Clients cookiespec. See org.apache.http.client.config.CookieSpec diff --git a/unirest/src/main/java/kong/unirest/AsyncClient.java b/unirest/src/main/java/kong/unirest/AsyncClient.java index 4439f6f75..1dbfbf286 100644 --- a/unirest/src/main/java/kong/unirest/AsyncClient.java +++ b/unirest/src/main/java/kong/unirest/AsyncClient.java @@ -61,4 +61,6 @@ default Stream close() { default boolean isRunning() { return true; } + + void registerShutdownHook(); } diff --git a/unirest/src/main/java/kong/unirest/Client.java b/unirest/src/main/java/kong/unirest/Client.java index 4b4dd205d..19a9c08ca 100644 --- a/unirest/src/main/java/kong/unirest/Client.java +++ b/unirest/src/main/java/kong/unirest/Client.java @@ -47,4 +47,6 @@ public interface Client { * @return a stream of exceptions possibly thrown while closing all the things. */ Stream close(); + + void registerShutdownHook(); } diff --git a/unirest/src/main/java/kong/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java index f8eb987d5..7509c4c16 100644 --- a/unirest/src/main/java/kong/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -465,6 +465,10 @@ public Config setDefaultResponseEncoding(String value) { */ public Config addShutdownHook(boolean value) { this.addShutdownHook = value; + if(value){ + client.ifPresent(Client::registerShutdownHook); + asyncClient.ifPresent(AsyncClient::registerShutdownHook); + } return this; } diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java index b52078b2f..a22629441 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheAsyncClient.java @@ -54,6 +54,7 @@ public class ApacheAsyncClient extends BaseApacheClient implements AsyncClient { private final AsyncIdleConnectionMonitorThread syncMonitor; private final PoolingNHttpClientConnectionManager manager; private Config config; + private boolean hookset; public ApacheAsyncClient(Config config) { this.config = config; @@ -76,13 +77,21 @@ public ApacheAsyncClient(Config config) { syncMonitor.tryStart(); client = build; if(config.shouldAddShutdownHook()){ - Runtime.getRuntime().addShutdownHook(new Thread(this::close, "Unirest Apache Async Client Shutdown Hook")); + registerShutdownHook(); } } catch (Exception e) { throw new UnirestConfigException(e); } } + @Override + public void registerShutdownHook() { + if(!hookset) { + hookset = true; + Runtime.getRuntime().addShutdownHook(new Thread(this::close, "Unirest Apache Async Client Shutdown Hook")); + } + } + private void setOptions(HttpAsyncClientBuilder ab) { if(!config.isVerifySsl()){ disableSsl(ab); diff --git a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java index 43676e9b3..0e0b62d5a 100644 --- a/unirest/src/main/java/kong/unirest/apache/ApacheClient.java +++ b/unirest/src/main/java/kong/unirest/apache/ApacheClient.java @@ -44,6 +44,7 @@ public class ApacheClient extends BaseApacheClient implements Client { private final PoolingHttpClientConnectionManager manager; private final SyncIdleConnectionMonitorThread syncMonitor; private final SecurityConfig security; + private boolean hookset; public ApacheClient(Config config) { this.config = config; @@ -82,6 +83,14 @@ private void setOptions(HttpClientBuilder cb) { } config.getInterceptors().stream().forEach(cb::addInterceptorFirst); if (config.shouldAddShutdownHook()) { + registerShutdownHook(); + } + } + + @Override + public void registerShutdownHook() { + if(!hookset) { + hookset = true; Runtime.getRuntime().addShutdownHook(new Thread(this::close, "Unirest Apache Client Shutdown Hook")); } } diff --git a/unirest/src/test/java/BehaviorTests/LifeCycleTest.java b/unirest/src/test/java/BehaviorTests/LifeCycleTest.java index f7adc084c..9840d5678 100644 --- a/unirest/src/test/java/BehaviorTests/LifeCycleTest.java +++ b/unirest/src/test/java/BehaviorTests/LifeCycleTest.java @@ -26,6 +26,7 @@ package BehaviorTests; import com.github.paweladamski.httpclientmock.HttpClientMock; +import com.google.common.collect.Sets; import kong.unirest.*; import kong.unirest.apache.AsyncIdleConnectionMonitorThread; import kong.unirest.apache.SyncIdleConnectionMonitorThread; @@ -45,7 +46,6 @@ import java.util.Set; import java.util.stream.IntStream; -import static java.lang.Thread.getAllStackTraces; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.lessThan; import static org.junit.Assert.*; @@ -67,6 +67,12 @@ public class LifeCycleTest extends BddTest { @Mock private PoolingNHttpClientConnectionManager manager; + @Override + public void setUp() { + super.setUp(); + clearUnirestHooks(); + } + @Test public void settingACustomClient() { HttpClientMock httpClientMock = new HttpClientMock(); @@ -77,19 +83,26 @@ public void settingACustomClient() { assertEquals("Howdy Ho!", result.getBody()); } + @Test + public void ifClientsAreAlreadyRunningCanAddShutdownHooks() throws Exception { + assertShutdownHooks(0); + + Unirest.get(MockServer.GET).asEmpty(); + Unirest.get(MockServer.GET).asEmptyAsync(); + Unirest.config().addShutdownHook(true); + Unirest.config().addShutdownHook(true); + + assertShutdownHooks(1); + } + @Test public void canAddShutdownHooks() throws Exception { + assertShutdownHooks(0); + Unirest.config().addShutdownHook(true).getClient(); Unirest.config().addShutdownHook(true).getAsyncClient(); - // oh this is so dirty and horrible. Set to @Ignore if it starts to be a problem. - Class clazz = Class.forName("java.lang.ApplicationShutdownHooks"); - Field field = clazz.getDeclaredField("hooks"); - field.setAccessible(true); - Set threads = ((Map)field.get(null)).keySet(); - - assertTrue(threads.stream().anyMatch(t -> "Unirest Apache Client Shutdown Hook".equals(t.getName()))); - assertTrue(threads.stream().anyMatch(t -> "Unirest Apache Async Client Shutdown Hook".equals(t.getName()))); + assertShutdownHooks(1); } @Test @@ -163,4 +176,31 @@ public void testUnirestInstanceIsShutdownWhenClosed() { } assertEquals(0, reference.config().getDefaultHeaders().size()); } + + private void assertShutdownHooks(int expected) { + Set threads = getShutdownHookMap(); + + assertEquals(expected, threads.stream().filter(t -> "Unirest Apache Client Shutdown Hook".equals(t.getName())).count()); + assertEquals(expected, threads.stream().filter(t -> "Unirest Apache Async Client Shutdown Hook".equals(t.getName())).count()); + } + + private void clearUnirestHooks() { + getShutdownHookMap() + .stream() + .filter(t -> t.getName().contains("Unirest")) + .forEach(t -> Runtime.getRuntime().removeShutdownHook(t)); + } + + private Set getShutdownHookMap() { + try { + // oh this is so dirty and horrible. Set to @Ignore if it starts to be a problem. + Class clazz = Class.forName("java.lang.ApplicationShutdownHooks"); + Field field = clazz.getDeclaredField("hooks"); + field.setAccessible(true); + Set threads = ((Map) field.get(null)).keySet(); + return Sets.newHashSet(threads); + }catch (Exception e){ + throw new RuntimeException(e); + } + } } From 191b6c600a7921fca41579fda75b24ef0173810f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 1 May 2019 07:31:44 -0500 Subject: [PATCH 0592/1769] update javadocs for metrics --- CHANGELOG.md | 5 ++++- .../java/kong/unirest/HttpRequestSummary.java | 3 +++ .../kong/unirest/HttpResponseSummary.java | 10 +++++++++ .../main/java/kong/unirest/MetricContext.java | 11 ++++++++++ .../src/main/java/kong/unirest/UniMetric.java | 9 ++++++++ .../test/java/BehaviorTests/MetricsTest.java | 21 +++++++++++++++---- 6 files changed, 54 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad4139429..245398bdb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.3.00 +* #267 make sure hooks are registered regardless of where we are in the lifecycle of the client engines +* Adds a metric hook for observing the health and performance of unirest. + ## 2.2.02 * Add a mapper function to transform a HttpResponse to a HttpResponse ```java @@ -19,7 +23,6 @@ Unirest.get("http://someplace") }); ``` -* #267 make sure hooks are registered regardless of where we are in the lifecycle of the client engines ## 2.2.01 * add cookiespec policies to config. These are the same as Apache Http Clients cookiespec. See org.apache.http.client.config.CookieSpec diff --git a/unirest/src/main/java/kong/unirest/HttpRequestSummary.java b/unirest/src/main/java/kong/unirest/HttpRequestSummary.java index b24dc547d..2c78b3c0f 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestSummary.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestSummary.java @@ -25,6 +25,9 @@ package kong.unirest; +/** + * A summary of a request about to be performed + */ public interface HttpRequestSummary { /** * @return The HTTP method of the request diff --git a/unirest/src/main/java/kong/unirest/HttpResponseSummary.java b/unirest/src/main/java/kong/unirest/HttpResponseSummary.java index 2ca1d31ee..e49a65297 100644 --- a/unirest/src/main/java/kong/unirest/HttpResponseSummary.java +++ b/unirest/src/main/java/kong/unirest/HttpResponseSummary.java @@ -25,7 +25,17 @@ package kong.unirest; +/** + * A Summary of rhe response + */ public interface HttpResponseSummary { + /** + * @return the http response code + */ int getStatus(); + + /** + * @return the text of the http response code + */ String getStatusText(); } diff --git a/unirest/src/main/java/kong/unirest/MetricContext.java b/unirest/src/main/java/kong/unirest/MetricContext.java index 99d3c532b..22b7c059d 100644 --- a/unirest/src/main/java/kong/unirest/MetricContext.java +++ b/unirest/src/main/java/kong/unirest/MetricContext.java @@ -25,7 +25,18 @@ package kong.unirest; +/** + * A metric context for the current request + */ @FunctionalInterface public interface MetricContext { + /** + * Finishes a Http Request. Called just after the main request but before any mapping + * function including before any streaming responses (like file downloads) are complete. + * @param httpResponse a summary of the just executed response or null in the case of a system exception. + * @param ex an exception if one happened or null . + * Note that this is not just a 500 from the remote, + * but more likely a socket or connection timeout. + */ void complete(HttpResponseSummary httpResponse, Exception ex); } diff --git a/unirest/src/main/java/kong/unirest/UniMetric.java b/unirest/src/main/java/kong/unirest/UniMetric.java index 6368b1a30..62afeeb7b 100644 --- a/unirest/src/main/java/kong/unirest/UniMetric.java +++ b/unirest/src/main/java/kong/unirest/UniMetric.java @@ -25,6 +25,15 @@ package kong.unirest; +/** + * A UniMetric is a factory for producing a MetricContext this will be called just before + * any Http Request + */ public interface UniMetric { + /** + * Factory method for a MetricContext + * @param request A summary of the current Http Request about to be performed + * @return a MetricContext for this request + */ MetricContext begin(HttpRequestSummary request); } diff --git a/unirest/src/test/java/BehaviorTests/MetricsTest.java b/unirest/src/test/java/BehaviorTests/MetricsTest.java index 1012cc90c..83d48b046 100644 --- a/unirest/src/test/java/BehaviorTests/MetricsTest.java +++ b/unirest/src/test/java/BehaviorTests/MetricsTest.java @@ -25,21 +25,19 @@ package BehaviorTests; -import kong.unirest.Client; -import kong.unirest.Config; import kong.unirest.HttpRequestSummary; import kong.unirest.Unirest; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpRequestBase; -import org.apache.http.concurrent.FutureCallback; -import org.apache.http.nio.client.HttpAsyncClient; import org.junit.Ignore; import org.junit.Test; import java.util.function.Function; import static BehaviorTests.MockServer.*; +import static org.hamcrest.Matchers.greaterThan; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -158,6 +156,21 @@ public void errorHandling_async() throws Exception { assertEquals(1, metric.routes.get("http://localhost:0000").size()); } + long exTime; + + @Test + public void metricAsALambda() { + exTime = 0; + Unirest.config().instramentWith((s) -> { + long startNanos = System.nanoTime(); + return (r,e) -> exTime = System.nanoTime() - startNanos; + }); + + Unirest.get(GET).asEmpty(); + + assertThat(exTime, greaterThan(0L)); + } + private MyMetric configureMetric() { return configureMetric(HttpRequestSummary::getUrl); } From 03a57e82d45f3e4a2596802f4cc6b6e1b1aab699 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 1 May 2019 07:47:33 -0500 Subject: [PATCH 0593/1769] javadoc warnings --- unirest/src/main/java/kong/unirest/HttpResponse.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/unirest/src/main/java/kong/unirest/HttpResponse.java b/unirest/src/main/java/kong/unirest/HttpResponse.java index 00b310f22..f1ccd35c5 100644 --- a/unirest/src/main/java/kong/unirest/HttpResponse.java +++ b/unirest/src/main/java/kong/unirest/HttpResponse.java @@ -97,6 +97,7 @@ public interface HttpResponse { /** * If the response was NOT a 200-series response or a mapping exception happened. map the original body into a error type and invoke this consumer * can be chained with ifSuccess + * @param the type of error class to map the body * @param consumer a function to consume a HttpResponse * @return the same response */ @@ -110,6 +111,7 @@ public interface HttpResponse { /** * Map the body into a error class if the response was NOT a 200-series response or a mapping exception happened. * Uses the system Object Mapper + * @param the response type * @param errorClass the class for the error * @return the error object */ From aeb2534fd491c6a877e9070c446d4c10b2bc8448 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 1 May 2019 14:39:09 -0500 Subject: [PATCH 0594/1769] just a little diagnostic test to show what spark does --- .../test/java/BehaviorTests/MetricsTest.java | 19 +++++++++++ .../test/java/BehaviorTests/MockServer.java | 32 ++++++++++++++++--- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/unirest/src/test/java/BehaviorTests/MetricsTest.java b/unirest/src/test/java/BehaviorTests/MetricsTest.java index 83d48b046..6a88a14c6 100644 --- a/unirest/src/test/java/BehaviorTests/MetricsTest.java +++ b/unirest/src/test/java/BehaviorTests/MetricsTest.java @@ -26,12 +26,14 @@ package BehaviorTests; import kong.unirest.HttpRequestSummary; +import kong.unirest.HttpResponse; import kong.unirest.Unirest; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpRequestBase; import org.junit.Ignore; import org.junit.Test; +import java.util.HashMap; import java.util.function.Function; import static BehaviorTests.MockServer.*; @@ -171,6 +173,23 @@ public void metricAsALambda() { assertThat(exTime, greaterThan(0L)); } + @Test + public void showWhatSparkDoes() { + HashMap map = Unirest.get(SPARKLE) + .routeParam("spark", "joy") + .queryString("food", "hamberders") + .queryString("colour", "red") + .asObject(HashMap.class) + .getBody(); + + assertEquals("localhost:4567", map.get("host()")); + assertEquals("/sparkle/joy/yippy", map.get("uri()")); // this is different from what the Spark doc says. + assertEquals("http://localhost:4567/sparkle/joy/yippy", map.get("url()")); + assertEquals(null, map.get("contextPath()")); + assertEquals("/sparkle/joy/yippy", map.get("pathInfo()")); + assertEquals("food=hamberders&colour=red", map.get("queryString()")); + } + private MyMetric configureMetric() { return configureMetric(HttpRequestSummary::getUrl); } diff --git a/unirest/src/test/java/BehaviorTests/MockServer.java b/unirest/src/test/java/BehaviorTests/MockServer.java index 6f1f5d40f..167296512 100644 --- a/unirest/src/test/java/BehaviorTests/MockServer.java +++ b/unirest/src/test/java/BehaviorTests/MockServer.java @@ -38,16 +38,16 @@ import java.io.File; import java.io.FileInputStream; import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; +import java.util.*; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.Stream; import static spark.Spark.*; public class MockServer { - private static int pages = 1; + private static int pages = 1; private static int onPage = 1; private static final List> responseHeaders = new ArrayList<>(); private static final List> cookies = new ArrayList<>(); @@ -58,6 +58,7 @@ public class MockServer { public static final String HOST = "http://localhost:" + PORT; public static final String WINDOWS_LATIN_1_FILE = HOST + "data/cp1250.txt"; public static final String REDIRECT = HOST + "/redirect"; + public static final String SPARKLE = HOST + "/sparkle/{spark}/yippy"; public static final String BINARYFILE = HOST + "/binary"; public static final String NOBODY = HOST + "/nobody"; public static final String PAGED = HOST + "/paged"; @@ -93,6 +94,7 @@ public static void reset(){ Spark.staticFileLocation("data"); Spark.notFound(MockServer::notFound); delete("/delete", MockServer::jsonResponse); + get("/sparkle/:spark/yippy", MockServer::sparkle); post("/post", MockServer::jsonResponse); get("/get", MockServer::jsonResponse); get("/gzip", MockServer::gzipResponse); @@ -118,6 +120,28 @@ public static void reset(){ } } + private static Object sparkle(Request request, Response response) { + Map sparks = new HashMap<>(); + sparks.put("contentType()", request.contentType()); + sparks.put("contextPath()", request.contextPath()); + sparks.put("host()", request.host()); + sparks.put("ip()", request.ip()); + sparks.put("pathInfo()", request.pathInfo()); + sparks.put("port()", String.valueOf(request.port())); + sparks.put("protocol()", request.protocol()); + sparks.put("requestMethod()", request.requestMethod()); + sparks.put("scheme()", request.scheme()); + sparks.put("servletPath()", request.servletPath()); + sparks.put("requestMethod()", request.requestMethod()); + sparks.put("splat()", Stream.of(request.splat()).collect(Collectors.joining(" | "))); + sparks.put("uri()", request.uri()); + sparks.put("url()", request.url()); + sparks.put("userAgent()", request.userAgent()); + sparks.put("queryString()", request.queryString()); + + return om.writeValue(sparks); + } + private static Object error(Request request, Response response) { return Spark.halt(400, om.writeValue(new ErrorThing("boom!"))); } From 43003fde620d2f71f77997a61a779785d2921145 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 4 May 2019 09:51:28 -0500 Subject: [PATCH 0595/1769] javadoc improvements --- unirest/src/main/java/kong/unirest/HttpRequestSummary.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unirest/src/main/java/kong/unirest/HttpRequestSummary.java b/unirest/src/main/java/kong/unirest/HttpRequestSummary.java index 2c78b3c0f..9da4ea9b6 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestSummary.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestSummary.java @@ -35,12 +35,12 @@ public interface HttpRequestSummary { HttpMethod getHttpMethod(); /** - * @return The current URL string for the request + * @return The current full URL string for the request with query params (http://somewhere/else?colour=red) */ String getUrl(); /** - * @return The raw un-parameterized path (http://somewhere/{param}) + * @return The raw un-parameterized path without query strings (http://somewhere/{param}) */ String getRawPath(); } From a8e104e7f3d432f498be298307461e127abdd886 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 6 May 2019 08:34:57 -0500 Subject: [PATCH 0596/1769] fix typo. add more javadocs --- unirest/src/main/java/kong/unirest/AsyncClient.java | 3 +++ unirest/src/main/java/kong/unirest/Config.java | 7 ++++++- unirest/src/main/java/kong/unirest/UnirestInstance.java | 9 +++++++++ unirest/src/test/java/BehaviorTests/MetricsTest.java | 7 +++---- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/unirest/src/main/java/kong/unirest/AsyncClient.java b/unirest/src/main/java/kong/unirest/AsyncClient.java index 1dbfbf286..84829fc7a 100644 --- a/unirest/src/main/java/kong/unirest/AsyncClient.java +++ b/unirest/src/main/java/kong/unirest/AsyncClient.java @@ -62,5 +62,8 @@ default boolean isRunning() { return true; } + /** + * Register the Async clients with shutdown hooks + */ void registerShutdownHook(); } diff --git a/unirest/src/main/java/kong/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java index 7509c4c16..16db7fc15 100644 --- a/unirest/src/main/java/kong/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -337,7 +337,12 @@ public Config addDefaultHeader(String name, String value) { return this; } - public Config instramentWith(UniMetric metric) { + /** + * Add a metric object for instrumentation + * @param metric a UniMetric object + * @return this config object + */ + public Config instrumentWith(UniMetric metric) { this.metrics = metric; return this; } diff --git a/unirest/src/main/java/kong/unirest/UnirestInstance.java b/unirest/src/main/java/kong/unirest/UnirestInstance.java index ccee8ea10..dfe74f606 100644 --- a/unirest/src/main/java/kong/unirest/UnirestInstance.java +++ b/unirest/src/main/java/kong/unirest/UnirestInstance.java @@ -25,10 +25,19 @@ package kong.unirest; +/** + * A Instance of the unirest runtime, you can have many of these but it is the config + * and its clients where all the action happens. + * This class is suitable for mocking. + */ public class UnirestInstance implements AutoCloseable { private final Config config; + /** + * Create a new UnirestInstance with a config + * @param config the config for the instance + */ public UnirestInstance(Config config){ this.config = config; } diff --git a/unirest/src/test/java/BehaviorTests/MetricsTest.java b/unirest/src/test/java/BehaviorTests/MetricsTest.java index 6a88a14c6..17ec52969 100644 --- a/unirest/src/test/java/BehaviorTests/MetricsTest.java +++ b/unirest/src/test/java/BehaviorTests/MetricsTest.java @@ -26,7 +26,6 @@ package BehaviorTests; import kong.unirest.HttpRequestSummary; -import kong.unirest.HttpResponse; import kong.unirest.Unirest; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpRequestBase; @@ -133,7 +132,7 @@ public void errorHandling() throws Exception { HttpClient mock = mock(HttpClient.class); when(mock.execute(any(HttpRequestBase.class))).thenThrow(new RuntimeException("boo")); MyMetric metric = new MyMetric(HttpRequestSummary::getUrl); - Unirest.config().reset().httpClient(mock).instramentWith(metric); + Unirest.config().reset().httpClient(mock).instrumentWith(metric); try { Unirest.get(GET).asEmpty(); @@ -163,7 +162,7 @@ public void errorHandling_async() throws Exception { @Test public void metricAsALambda() { exTime = 0; - Unirest.config().instramentWith((s) -> { + Unirest.config().instrumentWith((s) -> { long startNanos = System.nanoTime(); return (r,e) -> exTime = System.nanoTime() - startNanos; }); @@ -196,7 +195,7 @@ private MyMetric configureMetric() { private MyMetric configureMetric(Function keyFunction) { MyMetric metric = new MyMetric(keyFunction); - Unirest.config().followRedirects(false).instramentWith(metric); + Unirest.config().followRedirects(false).instrumentWith(metric); return metric; } } From 2466c30dea1d8bc45bf9abf3140d886e3af381fb Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 6 May 2019 08:46:40 -0500 Subject: [PATCH 0597/1769] more docs --- .../src/main/java/kong/unirest/Config.java | 67 ++++++++++++++----- 1 file changed, 50 insertions(+), 17 deletions(-) diff --git a/unirest/src/main/java/kong/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java index 16db7fc15..779073718 100644 --- a/unirest/src/main/java/kong/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -1,8 +1,8 @@ /** * The MIT License - * + *

* Copyright for portions of unirest-java are held by Kong Inc (c) 2013. - * + *

* Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including @@ -10,10 +10,10 @@ * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: - * + *

* The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -81,7 +81,7 @@ public Config() { setDefaults(); } - private void setDefaults(){ + private void setDefaults() { interceptors.clear(); proxy = null; headers = new Headers(); @@ -159,7 +159,7 @@ public Config asyncClient(AsyncClient value) { * @param asyncClientBuilder A builder function for creating a AsyncClient * @return this config object */ - public Config asyncClient(Function asyncClientBuilder){ + public Config asyncClient(Function asyncClientBuilder) { this.asyncBuilder = asyncClientBuilder; return this; } @@ -234,7 +234,7 @@ public Config clientCertificateStore(KeyStore store, String password) { public Config clientCertificateStore(String fileLocation, String password) { try (InputStream keyStoreStream = Util.getFileInputStream(fileLocation)) { this.keystorePassword = password; - this.keystore = KeyStore.getInstance("PKCS12"); + this.keystore = KeyStore.getInstance("PKCS12"); this.keystore.load(keyStoreStream, keystorePassword.toCharArray()); } catch (Exception e) { throw new UnirestConfigException(e); @@ -427,8 +427,8 @@ public Config requestCompression(boolean value) { * @return this config object */ public Config automaticRetries(boolean value) { - automaticRetries = value; - return this; + automaticRetries = value; + return this; } /** @@ -470,7 +470,7 @@ public Config setDefaultResponseEncoding(String value) { */ public Config addShutdownHook(boolean value) { this.addShutdownHook = value; - if(value){ + if (value) { client.ifPresent(Client::registerShutdownHook); asyncClient.ifPresent(AsyncClient::registerShutdownHook); } @@ -506,7 +506,6 @@ public Config reset() { } - /** * Shut down the configuration and its clients. * The config can be re-initialized with its settings @@ -526,7 +525,7 @@ public void shutDown(boolean clearOptions) { setDefaults(); } - if(!ex.isEmpty()){ + if (!ex.isEmpty()) { throw new UnirestException(ex); } } @@ -535,7 +534,7 @@ public void shutDown(boolean clearOptions) { * Return the current Client. One will be build if it does * not yet exist. * - * @return A synchronous Client + * @return A synchronous Client */ public Client getClient() { if (!client.isPresent()) { @@ -554,7 +553,7 @@ private synchronized void buildClient() { * Return the current HttpAsyncClient. One will be build if it does * not yet exist. * - * @return Apache HttpAsyncClient + * @return Apache HttpAsyncClient */ public AsyncClient getAsyncClient() { if (!asyncClientIsReady()) { @@ -578,45 +577,79 @@ private synchronized void buildAsyncClient() { } private void verifyIsOn(AsyncClient value) { - if(!value.isRunning()){ + if (!value.isRunning()) { throw new UnirestConfigException("Attempted to get a new async client but it was not started. Please ensure it is"); } } // Accessors for unirest. + /** + * @return if cookie management should be enabled. + * default: true + */ public boolean getEnabledCookieManagement() { return cookieManagement; } + /** + * @return if the clients should follow redirects + * default: true + */ public boolean getFollowRedirects() { return followRedirects; } + /** + * @return the maximum number of connections the clients for this config will manage at once + * default: 200 + */ public int getMaxConnections() { return maxTotal; } + /** + * @return the maximum number of connections per route the clients for this config will manage at once + * default: 20 + */ public int getMaxPerRoutes() { return maxPerRoute; } + /** + * @return the connection timeout in milliseconds + * default: 10000 + */ public int getConnectionTimeout() { return connectionTimeout; } + /** + * @return socket timeout in milliseconds + * default: 60000 + */ public int getSocketTimeout() { return socketTimeout; } + /** + * @return a security keystore if one has been provided + */ public KeyStore getKeystore() { return this.keystore; } - public String getKeyStorePassword(){ + /** + * @return The password for the keystore if provided + */ + public String getKeyStorePassword() { return this.keystorePassword; } + /** + * @return a configured object mapper + * @throws UnirestException if none has been configured. + */ public ObjectMapper getObjectMapper() { return objectMapper.orElseThrow(() -> new UnirestException("No Object Mapper Configured. Please config one with Unirest.config().setObjectMapper")); } @@ -638,7 +671,7 @@ public Proxy getProxy() { return proxy; } - public boolean useSystemProperties(){ + public boolean useSystemProperties() { return this.useSystemProperties; } From 72ba2b0651d319a4a3bf37c020b0b6905ede75f2 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 6 May 2019 08:53:23 -0500 Subject: [PATCH 0598/1769] keep the keystore password as a lambda which is slightly more secure than having a cleartext password --- unirest/src/main/java/kong/unirest/Config.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/unirest/src/main/java/kong/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java index 779073718..f3c3c3536 100644 --- a/unirest/src/main/java/kong/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -1,8 +1,8 @@ /** * The MIT License - *

+ * * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. - *

+ * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including @@ -10,10 +10,10 @@ * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: - *

+ * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -73,7 +73,7 @@ public class Config { private boolean verifySsl = true; private boolean addShutdownHook = false; private KeyStore keystore; - private String keystorePassword; + private Supplier keystorePassword = () -> null; private String cookieSpec; private UniMetric metrics = new NoopMetric(); @@ -220,7 +220,7 @@ public Config setObjectMapper(ObjectMapper om) { */ public Config clientCertificateStore(KeyStore store, String password) { this.keystore = store; - this.keystorePassword = password; + this.keystorePassword = () -> password; return this; } @@ -233,9 +233,9 @@ public Config clientCertificateStore(KeyStore store, String password) { */ public Config clientCertificateStore(String fileLocation, String password) { try (InputStream keyStoreStream = Util.getFileInputStream(fileLocation)) { - this.keystorePassword = password; + this.keystorePassword = () -> password; this.keystore = KeyStore.getInstance("PKCS12"); - this.keystore.load(keyStoreStream, keystorePassword.toCharArray()); + this.keystore.load(keyStoreStream, keystorePassword.get().toCharArray()); } catch (Exception e) { throw new UnirestConfigException(e); } @@ -643,7 +643,7 @@ public KeyStore getKeystore() { * @return The password for the keystore if provided */ public String getKeyStorePassword() { - return this.keystorePassword; + return this.keystorePassword.get(); } /** From 20ec053431f891e57152441565fef30b8505ae47 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 7 May 2019 11:17:13 -0700 Subject: [PATCH 0599/1769] throw a exception explaining about issues with older versions of apache client --- bad-maven-test/pom.xml | 43 +++++++++++++++++ .../test/java/kong/BadMavenConfigTest.java | 47 +++++++++++++++++++ pom.xml | 1 + .../src/main/java/kong/unirest/Config.java | 11 ++++- .../java/kong/unirest/UnirestException.java | 4 ++ 5 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 bad-maven-test/pom.xml create mode 100644 bad-maven-test/src/test/java/kong/BadMavenConfigTest.java diff --git a/bad-maven-test/pom.xml b/bad-maven-test/pom.xml new file mode 100644 index 000000000..1274e1978 --- /dev/null +++ b/bad-maven-test/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + + + com.konghq + unirest-java-parent + 2.2.03-SNAPSHOT + + + bad-maven-test + 2.2.03-SNAPSHOT + Errors that happen when people are using crusty old version of apache Http client + + + ${project.parent.basedir} + + + + + org.apache.httpcomponents + httpclient + 4.0.1 + + + org.apache.httpcomponents + httpmime + 4.5.6 + + + org.apache.httpcomponents + httpasyncclient + 4.1.4 + + + com.konghq + unirest-java + ${project.version} + + + \ No newline at end of file diff --git a/bad-maven-test/src/test/java/kong/BadMavenConfigTest.java b/bad-maven-test/src/test/java/kong/BadMavenConfigTest.java new file mode 100644 index 000000000..d851fe673 --- /dev/null +++ b/bad-maven-test/src/test/java/kong/BadMavenConfigTest.java @@ -0,0 +1,47 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong; + +import kong.unirest.Unirest; +import kong.unirest.UnirestException; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class BadMavenConfigTest { + + @Test + public void interpretError() { + try { + Unirest.get("https://konghq.com").asEmpty(); + }catch (ExceptionInInitializerError e){ + assertEquals("It looks like you are using an older version of Apache Http Client. \n" + + "For security and performance reasons Unirest requires the most recent version. Please upgrade.", e.getCause().getMessage()); + return; + } + fail("Should have thrown a Unirest Exception"); + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 258c2bbd6..4c32e64e3 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,7 @@ unirest object-mapper-gson object-mapper-jackson + diff --git a/unirest/src/main/java/kong/unirest/Config.java b/unirest/src/main/java/kong/unirest/Config.java index f3c3c3536..824733399 100644 --- a/unirest/src/main/java/kong/unirest/Config.java +++ b/unirest/src/main/java/kong/unirest/Config.java @@ -66,8 +66,8 @@ public class Config { private boolean cookieManagement; private boolean useSystemProperties; private String defaultResponseEncoding = StandardCharsets.UTF_8.name(); - private Function asyncBuilder = ApacheAsyncClient::new; - private Function clientBuilder = ApacheClient::new; + private Function asyncBuilder; + private Function clientBuilder; private boolean requestCompressionOn = true; private boolean automaticRetries; private boolean verifySsl = true; @@ -79,6 +79,13 @@ public class Config { public Config() { setDefaults(); + try { + asyncBuilder = ApacheAsyncClient::new; + clientBuilder = ApacheClient::new; + }catch (BootstrapMethodError e){ + throw new UnirestException("It looks like you are using an older version of Apache Http Client. \n" + + "For security and performance reasons Unirest requires the most recent version. Please upgrade.", e); + } } private void setDefaults() { diff --git a/unirest/src/main/java/kong/unirest/UnirestException.java b/unirest/src/main/java/kong/unirest/UnirestException.java index d4f58aa0e..2dceef403 100644 --- a/unirest/src/main/java/kong/unirest/UnirestException.java +++ b/unirest/src/main/java/kong/unirest/UnirestException.java @@ -44,6 +44,10 @@ public UnirestException(Throwable ex) { super(ex); } + public UnirestException(String message, Throwable e) { + super(message, e); + } + public UnirestException(Collection ex) { super(ex.stream().map(e -> e.getClass().getName() + " " + e.getMessage()).collect(Collectors.joining("\n"))); } From 2d6672983b5111281288ec9a19ba1e9c5922443f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 7 May 2019 11:21:58 -0700 Subject: [PATCH 0600/1769] comment out the vulnerable apache things so security doesn't think its used --- bad-maven-test/pom.xml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/bad-maven-test/pom.xml b/bad-maven-test/pom.xml index 1274e1978..07a5857b0 100644 --- a/bad-maven-test/pom.xml +++ b/bad-maven-test/pom.xml @@ -19,21 +19,21 @@ - - org.apache.httpcomponents - httpclient - 4.0.1 - - - org.apache.httpcomponents - httpmime - 4.5.6 - - - org.apache.httpcomponents - httpasyncclient - 4.1.4 - + + + + + + + + + + + + + + + com.konghq unirest-java From ecb230142768bfec2732c3778b4fd660d1e54d60 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 7 May 2019 12:35:25 -0700 Subject: [PATCH 0601/1769] upgrade apache --- unirest/pom.xml | 4 ++-- unirest/src/main/java/kong/unirest/apache/RequestPrep.java | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/unirest/pom.xml b/unirest/pom.xml index 59d114381..225ff8825 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -19,12 +19,12 @@ org.apache.httpcomponents httpclient - 4.5.6 + 4.5.8 org.apache.httpcomponents httpmime - 4.5.6 + 4.5.8 org.apache.httpcomponents diff --git a/unirest/src/main/java/kong/unirest/apache/RequestPrep.java b/unirest/src/main/java/kong/unirest/apache/RequestPrep.java index d65086646..0b92c453c 100644 --- a/unirest/src/main/java/kong/unirest/apache/RequestPrep.java +++ b/unirest/src/main/java/kong/unirest/apache/RequestPrep.java @@ -97,6 +97,7 @@ private RequestConfig overrideConfig() { return RequestConfig.custom() .setConnectTimeout(request.getConnectTimeout()) .setSocketTimeout(request.getSocketTimeout()) + .setNormalizeUri(false) .setConnectionRequestTimeout(request.getSocketTimeout()) .setProxy(RequestOptions.toApacheProxy(request.getProxy())) .setCookieSpec(config.getCookieSpec()) From 6d308b76b366848c0d90d4f3afffabbaa9eb5044 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 7 May 2019 13:18:27 -0700 Subject: [PATCH 0602/1769] minor bump --- CHANGELOG.md | 4 +++- bad-maven-test/pom.xml | 4 ++-- object-mapper-gson/pom.xml | 2 +- object-mapper-jackson/pom.xml | 2 +- pom.xml | 2 +- unirest/pom.xml | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 245398bdb..69392a9e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## 2.3.00 * #267 make sure hooks are registered regardless of where we are in the lifecycle of the client engines -* Adds a metric hook for observing the health and performance of unirest. +* #264 Adds a metric hook for observing the health and performance of unirest. +* #270 Throw a more helpful error when a older version of Apache Client has been pulled in over Unirest's requirement. +* Upgrade Apache Http Client Dependency to 4.5.8 ## 2.2.02 * Add a mapper function to transform a HttpResponse to a HttpResponse diff --git a/bad-maven-test/pom.xml b/bad-maven-test/pom.xml index 07a5857b0..9057be766 100644 --- a/bad-maven-test/pom.xml +++ b/bad-maven-test/pom.xml @@ -7,11 +7,11 @@ com.konghq unirest-java-parent - 2.2.03-SNAPSHOT + 2.3.00-SNAPSHOT bad-maven-test - 2.2.03-SNAPSHOT + 2.3.00-SNAPSHOT Errors that happen when people are using crusty old version of apache Http client diff --git a/object-mapper-gson/pom.xml b/object-mapper-gson/pom.xml index 9e283519b..24b45ec3c 100644 --- a/object-mapper-gson/pom.xml +++ b/object-mapper-gson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.2.03-SNAPSHOT + 2.3.00-SNAPSHOT unirest-object-mappers-gson diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index 7b57ba03b..175ec35bb 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.2.03-SNAPSHOT + 2.3.00-SNAPSHOT unirest-objectmapper-jackson diff --git a/pom.xml b/pom.xml index 4c32e64e3..10eca65fc 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.2.03-SNAPSHOT + 2.3.00-SNAPSHOT unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ diff --git a/unirest/pom.xml b/unirest/pom.xml index 225ff8825..122462059 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.2.03-SNAPSHOT + 2.3.00-SNAPSHOT Simplified, lightweight HTTP client library. From a6cd3daf02714c44564b1cf733ed6bd58aa79f8f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 7 May 2019 13:20:20 -0700 Subject: [PATCH 0603/1769] [maven-release-plugin] prepare release v2.3.00 --- object-mapper-gson/pom.xml | 2 +- object-mapper-jackson/pom.xml | 2 +- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/object-mapper-gson/pom.xml b/object-mapper-gson/pom.xml index 24b45ec3c..5942389f9 100644 --- a/object-mapper-gson/pom.xml +++ b/object-mapper-gson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.3.00-SNAPSHOT + 2.3.00 unirest-object-mappers-gson diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index 175ec35bb..39ca59aef 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.3.00-SNAPSHOT + 2.3.00 unirest-objectmapper-jackson diff --git a/pom.xml b/pom.xml index 10eca65fc..7ed92bb52 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.3.00-SNAPSHOT + 2.3.00 unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -35,7 +35,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - HEAD + v2.3.00 diff --git a/unirest/pom.xml b/unirest/pom.xml index 122462059..4a0609b14 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.3.00-SNAPSHOT + 2.3.00 Simplified, lightweight HTTP client library. From 2379d15d996d29676e804c3f1d2fa979d24dadec Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 7 May 2019 13:20:28 -0700 Subject: [PATCH 0604/1769] [maven-release-plugin] prepare for next development iteration --- object-mapper-gson/pom.xml | 2 +- object-mapper-jackson/pom.xml | 2 +- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/object-mapper-gson/pom.xml b/object-mapper-gson/pom.xml index 5942389f9..ecf0ebd70 100644 --- a/object-mapper-gson/pom.xml +++ b/object-mapper-gson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.3.00 + 2.3.01-SNAPSHOT unirest-object-mappers-gson diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index 39ca59aef..084b34e6c 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.3.00 + 2.3.01-SNAPSHOT unirest-objectmapper-jackson diff --git a/pom.xml b/pom.xml index 7ed92bb52..0e6b4a6ac 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.3.00 + 2.3.01-SNAPSHOT unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -35,7 +35,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - v2.3.00 + HEAD diff --git a/unirest/pom.xml b/unirest/pom.xml index 4a0609b14..dd0584bf5 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.3.00 + 2.3.01-SNAPSHOT Simplified, lightweight HTTP client library. From 3aefddac3406af7dff6bc67b155aa652c013d2b4 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 23 May 2019 09:45:43 -0500 Subject: [PATCH 0605/1769] update some test dependencies that have security issues --- pom.xml | 2 +- unirest/pom.xml | 17 ++++++++++++++++- .../java/BehaviorTests/ResponseHeaderTest.java | 1 - 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 0e6b4a6ac..8ad937943 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ UTF-8 UTF-8 - 2.9.8 + 2.9.9 ${project.basedir} diff --git a/unirest/pom.xml b/unirest/pom.xml index dd0584bf5..e1245d408 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -87,9 +87,24 @@ com.sparkjava spark-core - 2.8.0 + 2.9.0 test + + + + org.eclipse.jetty.websocket + websocket-server + 9.4.18.v20190429 + test + + + + org.eclipse.jetty + jetty-server + 9.4.18.v20190429 + + org.skyscreamer jsonassert diff --git a/unirest/src/test/java/BehaviorTests/ResponseHeaderTest.java b/unirest/src/test/java/BehaviorTests/ResponseHeaderTest.java index 0bf3d61b8..b0d19f106 100644 --- a/unirest/src/test/java/BehaviorTests/ResponseHeaderTest.java +++ b/unirest/src/test/java/BehaviorTests/ResponseHeaderTest.java @@ -54,7 +54,6 @@ public void responseHeadersAreInTheSameOrderAsTheResponse() { assertHeader("zed", "grapes", h.all().get(6)); assertHeader("Content-Type", "text/html;charset=utf-8", h.all().get(7)); assertHeader("Transfer-Encoding", "chunked", h.all().get(8)); - assertHeader("Server", "Jetty(9.4.12.v20180830)", h.all().get(9)); } From d7f42139ced8a1c92bc53856fdea3e6a449007a5 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 23 May 2019 10:23:08 -0500 Subject: [PATCH 0606/1769] update jackson in the object-mapper-jackson --- object-mapper-jackson/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index 084b34e6c..60dafdac5 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -13,7 +13,7 @@ Jackson based object mapper for Unirest - 2.9.8 + 2.9.9 ${project.parent.basedir} From 610968629bc4b2343bc0a878f8b4971d6e360524 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 23 May 2019 10:33:44 -0500 Subject: [PATCH 0607/1769] [maven-release-plugin] prepare release v2.3.01 --- object-mapper-gson/pom.xml | 2 +- object-mapper-jackson/pom.xml | 2 +- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/object-mapper-gson/pom.xml b/object-mapper-gson/pom.xml index ecf0ebd70..ad705a65d 100644 --- a/object-mapper-gson/pom.xml +++ b/object-mapper-gson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.3.01-SNAPSHOT + 2.3.01 unirest-object-mappers-gson diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index 60dafdac5..289a67f6a 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.3.01-SNAPSHOT + 2.3.01 unirest-objectmapper-jackson diff --git a/pom.xml b/pom.xml index 8ad937943..748fa6aff 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.3.01-SNAPSHOT + 2.3.01 unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -35,7 +35,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - HEAD + v2.3.01 diff --git a/unirest/pom.xml b/unirest/pom.xml index e1245d408..e98053b61 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.3.01-SNAPSHOT + 2.3.01 Simplified, lightweight HTTP client library. From 8a3d017beb99ad5103e616706e361431d5e2859b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 23 May 2019 10:33:51 -0500 Subject: [PATCH 0608/1769] [maven-release-plugin] prepare for next development iteration --- object-mapper-gson/pom.xml | 2 +- object-mapper-jackson/pom.xml | 2 +- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/object-mapper-gson/pom.xml b/object-mapper-gson/pom.xml index ad705a65d..65f5bd3bc 100644 --- a/object-mapper-gson/pom.xml +++ b/object-mapper-gson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.3.01 + 2.3.02-SNAPSHOT unirest-object-mappers-gson diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index 289a67f6a..938a8e99d 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.3.01 + 2.3.02-SNAPSHOT unirest-objectmapper-jackson diff --git a/pom.xml b/pom.xml index 748fa6aff..264bf075e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.3.01 + 2.3.02-SNAPSHOT unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -35,7 +35,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - v2.3.01 + HEAD diff --git a/unirest/pom.xml b/unirest/pom.xml index e98053b61..edd452389 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.3.01 + 2.3.02-SNAPSHOT Simplified, lightweight HTTP client library. From 57209c6723e436cfdb24b6f5493ae657a74ef056 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 24 May 2019 09:07:58 -0500 Subject: [PATCH 0609/1769] update docs --- CHANGELOG.md | 3 +++ README.md | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69392a9e3..4e423265b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.3.01 +* Update Jackson dependency in object-mapper-jackson due to security. + ## 2.3.00 * #267 make sure hooks are registered regardless of where we are in the lifecycle of the client engines * #264 Adds a metric hook for observing the health and performance of unirest. diff --git a/README.md b/README.md index 05c021dd1..2e7df7868 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ com.konghq unirest-java - 2.2.02 + 2.3.01 ``` From b26a5d312ef05aa5fd180e1e60a330c9198f2621 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 24 May 2019 13:24:45 -0500 Subject: [PATCH 0610/1769] properly scope jetty to test --- unirest/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/unirest/pom.xml b/unirest/pom.xml index edd452389..3a39c2dbe 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -103,6 +103,7 @@ org.eclipse.jetty jetty-server 9.4.18.v20190429 + test From b8463c4cd4c071c85133cd297a0766c60daeb100 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 24 May 2019 13:27:46 -0500 Subject: [PATCH 0611/1769] [maven-release-plugin] prepare release v2.3.02 --- object-mapper-gson/pom.xml | 2 +- object-mapper-jackson/pom.xml | 2 +- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/object-mapper-gson/pom.xml b/object-mapper-gson/pom.xml index 65f5bd3bc..0f36a74ac 100644 --- a/object-mapper-gson/pom.xml +++ b/object-mapper-gson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.3.02-SNAPSHOT + 2.3.02 unirest-object-mappers-gson diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index 938a8e99d..2e8721dac 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.3.02-SNAPSHOT + 2.3.02 unirest-objectmapper-jackson diff --git a/pom.xml b/pom.xml index 264bf075e..1eac05a7c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.3.02-SNAPSHOT + 2.3.02 unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -35,7 +35,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - HEAD + v2.3.02 diff --git a/unirest/pom.xml b/unirest/pom.xml index 3a39c2dbe..44d4318f2 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.3.02-SNAPSHOT + 2.3.02 Simplified, lightweight HTTP client library. From 23f5563e1f27c5f6cda8636914fdc797ce85a57f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 24 May 2019 13:27:52 -0500 Subject: [PATCH 0612/1769] [maven-release-plugin] prepare for next development iteration --- object-mapper-gson/pom.xml | 2 +- object-mapper-jackson/pom.xml | 2 +- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/object-mapper-gson/pom.xml b/object-mapper-gson/pom.xml index 0f36a74ac..851be8238 100644 --- a/object-mapper-gson/pom.xml +++ b/object-mapper-gson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.3.02 + 2.3.03-SNAPSHOT unirest-object-mappers-gson diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index 2e8721dac..61f9196a4 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.3.02 + 2.3.03-SNAPSHOT unirest-objectmapper-jackson diff --git a/pom.xml b/pom.xml index 1eac05a7c..c0a16818b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.3.02 + 2.3.03-SNAPSHOT unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -35,7 +35,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - v2.3.02 + HEAD diff --git a/unirest/pom.xml b/unirest/pom.xml index 44d4318f2..1e4233e79 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.3.02 + 2.3.03-SNAPSHOT Simplified, lightweight HTTP client library. From dd2bf752bbdcfce183ac5494fbbd8f549ac3c31e Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 24 May 2019 13:37:06 -0500 Subject: [PATCH 0613/1769] update to secure spark --- unirest/pom.xml | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/unirest/pom.xml b/unirest/pom.xml index 1e4233e79..3bfd386a2 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -87,25 +87,9 @@ com.sparkjava spark-core - 2.9.0 + 2.9.1 test - - - - org.eclipse.jetty.websocket - websocket-server - 9.4.18.v20190429 - test - - - - org.eclipse.jetty - jetty-server - 9.4.18.v20190429 - test - - org.skyscreamer jsonassert From 699dc2ef0d0cfbfbd92bad7f21d1a3e0e02a99e7 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Fri, 24 May 2019 16:35:44 -0500 Subject: [PATCH 0614/1769] update docs --- CHANGELOG.md | 3 +++ README.md | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e423265b..1f68011eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.3.02 +* Remove mistaken dependency that should have been scoped to test. + ## 2.3.01 * Update Jackson dependency in object-mapper-jackson due to security. diff --git a/README.md b/README.md index 2e7df7868..37364a501 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ com.konghq unirest-java - 2.3.01 + 2.3.02 ``` From 4c67dcab5c674a9c643d89021eea088c81f50c5d Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Wed, 29 May 2019 10:07:42 -0500 Subject: [PATCH 0615/1769] add gitter badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 37364a501..c6498f78b 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![Build Status](https://travis-ci.org/Kong/unirest-java.svg?branch=master)](https://travis-ci.org/Kong/unirest-java) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.konghq/unirest-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.kong/unirest-java) [![Javadocs](http://www.javadoc.io/badge/com.konghq/unirest-java.svg)](http://www.javadoc.io/doc/com.konghq/unirest-java) +[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/Kong/unirest-java) ## Install With [Maven](https://mvnrepository.com/artifact/com.konghq/unirest-java)[:](https://repo.maven.apache.org/maven2/com/konghq/unirest-java/) From 604290136b9d8df6330ac9fde29f3e8b6edd472f Mon Sep 17 00:00:00 2001 From: David Ghiurco Date: Fri, 31 May 2019 10:56:55 -0500 Subject: [PATCH 0616/1769] Use Maven Shade Plugin to create standalone jars which relocate Apache HttpClient, Jackson, and Google Guava dependencies --- pom.xml | 54 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index c0a16818b..2429d7a9f 100644 --- a/pom.xml +++ b/pom.xml @@ -221,7 +221,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.1 + 3.8.1 true 128m @@ -231,16 +231,6 @@ UTF-8 - - org.apache.maven.plugins - maven-assembly-plugin - 2.4 - - - jar-with-dependencies - - - org.apache.maven.plugins maven-source-plugin @@ -310,6 +300,48 @@ + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + + package + + shade + + + + true + + + standalone + + + + + org.apache.http + unirest.shaded.org.apache.http + + + + com.fasterxml.jackson + unirest.shaded.com.fasterxml.jackson + + + + com.google.common + shaded.com.google.common + + + + false + + + + + + From 8c29fd18499c050c77a80f21214be902681e3cb8 Mon Sep 17 00:00:00 2001 From: David Ghiurco Date: Fri, 31 May 2019 10:56:55 -0500 Subject: [PATCH 0617/1769] Use Maven Shade Plugin to create standalone jars which relocate Apache HttpClient, Jackson, and Google Guava dependencies --- pom.xml | 54 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index c0a16818b..def5b9201 100644 --- a/pom.xml +++ b/pom.xml @@ -221,7 +221,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.1 + 3.8.1 true 128m @@ -231,16 +231,6 @@ UTF-8 - - org.apache.maven.plugins - maven-assembly-plugin - 2.4 - - - jar-with-dependencies - - - org.apache.maven.plugins maven-source-plugin @@ -310,6 +300,48 @@ + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + + package + + shade + + + + true + + + standalone + + + + + org.apache.http + unirest.shaded.org.apache.http + + + + com.fasterxml.jackson + unirest.shaded.com.fasterxml.jackson + + + + com.google.common + unirest.shaded.com.google.common + + + + false + + + + + + From 101031f7984e8f08018de0d875c1a7f1b7ca255b Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 1 Jun 2019 08:27:58 -0500 Subject: [PATCH 0618/1769] [maven-release-plugin] prepare release v2.3.03 --- object-mapper-gson/pom.xml | 2 +- object-mapper-jackson/pom.xml | 2 +- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/object-mapper-gson/pom.xml b/object-mapper-gson/pom.xml index 851be8238..87437ed62 100644 --- a/object-mapper-gson/pom.xml +++ b/object-mapper-gson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.3.03-SNAPSHOT + 2.3.03 unirest-object-mappers-gson diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index 61f9196a4..dbf5306e7 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.3.03-SNAPSHOT + 2.3.03 unirest-objectmapper-jackson diff --git a/pom.xml b/pom.xml index def5b9201..22c052f17 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.3.03-SNAPSHOT + 2.3.03 unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -35,7 +35,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - HEAD + v2.3.03 diff --git a/unirest/pom.xml b/unirest/pom.xml index 3bfd386a2..78a3d1094 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.3.03-SNAPSHOT + 2.3.03 Simplified, lightweight HTTP client library. From a819241ae574ea77deecbc2f757d808a03060046 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 1 Jun 2019 08:28:08 -0500 Subject: [PATCH 0619/1769] [maven-release-plugin] prepare for next development iteration --- object-mapper-gson/pom.xml | 2 +- object-mapper-jackson/pom.xml | 2 +- pom.xml | 4 ++-- unirest/pom.xml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/object-mapper-gson/pom.xml b/object-mapper-gson/pom.xml index 87437ed62..e44913a66 100644 --- a/object-mapper-gson/pom.xml +++ b/object-mapper-gson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.3.03 + 2.3.04-SNAPSHOT unirest-object-mappers-gson diff --git a/object-mapper-jackson/pom.xml b/object-mapper-jackson/pom.xml index dbf5306e7..2dba728a9 100644 --- a/object-mapper-jackson/pom.xml +++ b/object-mapper-jackson/pom.xml @@ -5,7 +5,7 @@ com.konghq unirest-java-parent - 2.3.03 + 2.3.04-SNAPSHOT unirest-objectmapper-jackson diff --git a/pom.xml b/pom.xml index 22c052f17..9339f3732 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent pom - 2.3.03 + 2.3.04-SNAPSHOT unirest Parent pom for unirest packages http://github.com/Kong/unirest-java/ @@ -35,7 +35,7 @@ https://github.com/Kong/unirest-java scm:git:git@github.com:Kong/unirest-java.git scm:git:git@github.com:Kong/unirest-java.git - v2.3.03 + HEAD diff --git a/unirest/pom.xml b/unirest/pom.xml index 78a3d1094..a67b34d1f 100644 --- a/unirest/pom.xml +++ b/unirest/pom.xml @@ -4,7 +4,7 @@ com.konghq unirest-java-parent - 2.3.03 + 2.3.04-SNAPSHOT Simplified, lightweight HTTP client library. From a7d944275e5c9f9f9aa95c3db6dcd686b8f6fdee Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 1 Jun 2019 09:06:38 -0500 Subject: [PATCH 0620/1769] add org.json to shade --- pom.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9339f3732..24cafac48 100644 --- a/pom.xml +++ b/pom.xml @@ -316,13 +316,17 @@ standalone - + true org.apache.http unirest.shaded.org.apache.http + + org.json + unirest.shaded.org.json + com.fasterxml.jackson From e8abef9f2dd6002e6ee3c83360200cb1830a9ef1 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 1 Jun 2019 10:28:37 -0500 Subject: [PATCH 0621/1769] starting to build out better docs --- docs/index.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/index.md diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 000000000..52971a26e --- /dev/null +++ b/docs/index.md @@ -0,0 +1 @@ +# Future Home Of New Docs \ No newline at end of file From bb4165ec8c6754925725e4ee74f3018ccebd24cc Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 1 Jun 2019 10:29:03 -0500 Subject: [PATCH 0622/1769] Set theme jekyll-theme-slate --- docs/_config.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/_config.yml diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 000000000..c74188174 --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-slate \ No newline at end of file From 2e3a990e7b19a666a8c24ef0a5b4f4ef4d7d51e8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 1 Jun 2019 10:41:07 -0500 Subject: [PATCH 0623/1769] start off by copying the readme into the docs --- docs/_layouts/default.html | 62 ++++++++ docs/index.md | 285 ++++++++++++++++++++++++++++++++++++- 2 files changed, 346 insertions(+), 1 deletion(-) create mode 100644 docs/_layouts/default.html diff --git a/docs/_layouts/default.html b/docs/_layouts/default.html new file mode 100644 index 000000000..85681f40f --- /dev/null +++ b/docs/_layouts/default.html @@ -0,0 +1,62 @@ + + + + + + + + + + {% seo %} + + + + + +

+
+ {% if site.github.is_project_page %} + View on GitHub + {% endif %} + +

{{ site.title | default: site.github.repository_name }}

+

{{ site.description | default: site.github.project_tagline }}

+ + {% if site.show_downloads %} +
+ Download this project as a .zip file + Download this project as a tar.gz file +
+ {% endif %} +
+
+ + +
+
+ {{ content }} +
+
+ + + + +{% if site.google_analytics %} + +{% endif %} + + diff --git a/docs/index.md b/docs/index.md index 52971a26e..6c3866f59 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1 +1,284 @@ -# Future Home Of New Docs \ No newline at end of file +# Unirest for Java + +[![Build Status](https://travis-ci.org/Kong/unirest-java.svg?branch=master)](https://travis-ci.org/Kong/unirest-java) +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.konghq/unirest-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.kong/unirest-java) +[![Javadocs](http://www.javadoc.io/badge/com.konghq/unirest-java.svg)](http://www.javadoc.io/doc/com.konghq/unirest-java) +[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/Kong/unirest-java) + + +## Install With [Maven](https://mvnrepository.com/artifact/com.konghq/unirest-java)[:](https://repo.maven.apache.org/maven2/com/konghq/unirest-java/) +```xml + + com.konghq + unirest-java + 2.3.02 + +``` + +### Upgrading from Previous Versions +See the [Upgrade Guide](UPGRADE_GUIDE.md) + +## Features + +* Make `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `HEAD`, `OPTIONS` requests +* Both synchronous and asynchronous (non-blocking) requests +* It supports form parameters, file uploads and custom body entities +* Easily add route parameters without ugly string concatenations +* Supports gzip +* Supports Basic Authentication natively +* Customizable timeout, concurrency levels and proxy settings +* Customizable default headers for every request (DRY) +* Automatic JSON parsing into a native object for JSON responses +* Customizable binding, with mapping from response body to java Object + + +## Creating Request +So you're probably wondering how using Unirest makes creating requests in Java easier, here is a basic POST request that will explain everything: + +```java +HttpResponse response = Unirest.post("http://httpbin.org/post") + .header("accept", "application/json") + .queryString("apiKey", "123") + .field("parameter", "value") + .field("foo", "bar") + .asJson(); +``` + +Requests are made when `as[Type]()` is invoked, possible types include `Json`, `String`, `Object` `Empty` and `File`. + + +### Route Parameters +Sometimes you want to add dynamic parameters in the URL, you can easily do that by adding a placeholder in the URL, and then by setting the route parameters with the `routeParam` function, like: + +```java +Unirest.get("http://httpbin.org/{method}") + .routeParam("method", "get") + .asJson(); +``` +In the example above the final URL will be `http://httpbin.org/get` - Basically the placeholder `{method}` will be replaced with `get`. + +The placeholder's format is as easy as: `{custom_name}` + +### Advanced Object Mapping with Jackson, GSON, JAX-B or others +Before an `asObject(Class)` or a `.body(Object)` invocation, is necessary to provide a custom implementation of the `ObjectMapper` interface. +This should be done only the first time, as the instance of the ObjectMapper will be shared globally. +Unirest offers a few plug-ins implementing popular object mappers like Jackson and Gson. See [mvn central](https://mvnrepository.com/artifact/com.konghq) for details. +nes of code. +For example, serializing Json from\to Object using the popular Jackson ObjectMapper takes only few li + +```java +// Only one time +Unirest.config().setObjectMapper(new JacksonObjectMapper()); + +// Response to Object +Book book = Unirest.get("http://httpbin.org/books/1") + .asObject(Book.class) + .getBody(); + +Author author = Unirest.get("http://httpbin.org/books/{id}/author") + .routeParam("id", bookObject.getId()) + .asObject(Author.class) + .getBody(); + +// Sending a JSON object +Unirest.post("http://httpbin.org/authors/post") + .header("accept", "application/json") + .header("Content-Type", "application/json") + .body(author) + .asJson(); +``` + +#### Errors in Object or JSON parsing +You can't always get what you want. And sometimes results you get from web services will not map into what you expect them to. +When this happens with a ```asObject``` or ```asJson``` request the resulting body will be null, but the response object will contain a ParsingException that allows you to get the error and the original body for inspection. + +```java +UnirestParsingException ex = response.getParsingError().get(); + +ex.getOriginalBody(); // Has the original body as a string. +ex.getMessage(); // Will have the parsing exception. +ex.getCause(); // of course will have the original parsing exception itself. +``` + +#### Asynchronous Requests +Sometimes, well most of the time, you want your application to be asynchronous and not block, Unirest supports this in Java using anonymous callbacks, or direct method placement: + +```java +CompletableFuture> future = Unirest.post("http://httpbin.org/post") + .header("accept", "application/json") + .field("param1", "value1") + .field("param2", "value2") + .asJsonAsync(response -> { + int code = response.getStatus(); + JsonNode body = response.getBody(); + }); +``` + +#### Custom mappings and handling large responses +Most response methods (```asString```, ```asJson```, and even ```asBinary```) read the entire +response stream into memory. In order to read the original stream and handle large responses you +can use several functional methods like: + +```java + Map r = Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asObject(i -> new Gson().fromJson(i.getContentReader(), HashMap.class)) + .getBody(); + +``` + +or consumers: + +```java + + Unirest.get(MockServer.GET) + .thenConsumeAsync(r -> { + // something like writing a file to disk + }); +``` + +#### File Uploads +Creating `multipart` requests with Java is trivial, simply pass along a `File` or an InputStream Object as a field: + +```java +HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") + .header("accept", "application/json") + .field("parameter", "value") + .field("file", new File("/tmp/file")) + .asJson(); +``` + +#### Custom Entity Body + +```java +HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") + .header("accept", "application/json") + .body("{\"parameter\":\"value\", \"foo\":\"bar\"}") + .asJson(); +``` + +#### JSON Patch Requests +Unirest has full native support for JSON Patch requests +```java + Unirest.jsonPatch(MockServer.PATCH) + .add("/fruits/-", "Apple") + .remove("/bugs") + .replace("/lastname", "Flintstone") + .test("/firstname", "Fred") + .move("/old/location", "/new/location") + .copy("/original/location", "/new/location") + .asJson(); +``` +will send a request with a body of +```json + [ + {"op":"add","path":"/fruits/-","value":"Apple"}, + {"op":"remove","path":"/bugs"}, + {"op":"replace","path":"/lastname","value":"Flintstone"}, + {"op":"test","path":"/firstname","value":"Fred"}, + {"op":"move","path":"/new/location","from":"/old/location"}, + {"op":"copy","path":"/new/location","from":"/original/location"} + ] + +``` + +#### Basic Authentication +Authenticating the request with basic authentication can be done by calling the `basicAuth(username, password)` function: +```java + Unirest.get("http://httpbin.org/headers") + .basicAuth("username", "password") + .asJson(); +``` + +# Configuration +Previous versions of unirest had configuration split across several different places. Sometimes it was done on ```Unirest```, sometimes it was done on ```Option```, sometimes it was somewhere else. +All configuration is now done through ```Unirest.config()``` + +#### Unirest.config() +Unirest config allows easy access to build a configuration just like you would build a request: + +```java + Unirest.config() + .socketTimeout(500) + .connectTimeout(1000) + .concurrency(10, 5) + .proxy(new Proxy("https://proxy")) + .setDefaultHeader("Accept", "application/json") + .followRedirects(false) + .enableCookieManagement(false) + .addInterceptor(new MyCustomInterceptor()); +``` + +#### Config Options + +| Builder Method | Impact | Default | +| ------------- | ------------- | ------------- | +| ```socketTimeout(int)``` | Sets the socket timeout for all requests in millis | 60000 | +| ```connectTimeout(int)``` | Sets the connection timeout for all requests in millis | 10000 | +| ```concurrency(int, int)``` | Sets concurrency rates; max total, max per route | 200, 20 | +| ```proxy(proxy)``` | Sets a proxy object for negotiating proxy servers. Can include auth credentials | | +| ```setDefaultHeader(String, String)``` | Sets a default header. Will overwrite if it exists | | +| ```setDefaultHeader(String, Supplier)``` | Sets a default header by supplier. Good for setting trace tokens for microservice architectures. Will overwrite if it exists | | +| ```addDefaultHeader(String, String)``` | Adds a default header. Multiple for the same name can exist | | +| ```addDefaultHeader(String, Supplier)``` | Add a default header by supplier. Good for setting trace tokens for microservice architectures. | | +| ```setDefaultBasicAuth(String, String)``` | Add a default Basic Auth Header | | +| ```followRedirects(boolean)``` | toggle following redirects | true | +| ```enableCookieManagement(boolean)``` | toggle accepting and storing cookies | true | +| ```cookieSpec(String)``` | set a cookie policy. Acceptable values: 'default' (same as Netscape), 'netscape', 'ignoreCookies', 'standard' (RFC 6265 interoprability profile) , 'standard-strict' (RFC 6265 strict profile) | default | +| ```automaticRetries(boolean)``` | toggle disabling automatic retries (up to 4 times) for socket timeouts | true | +| ```verifySsl(boolean)``` |toggle enforcing SSL | true | +| ```addShutdownHook(boolean)``` | toggle to add the clients to the system shutdown hooks automatically | false | +| ```clientCertificateStore(String,String)``` | Add a PKCS12 KeyStore by path for doing client certificates | | +| ```clientCertificateStore(KeyStore,String)``` | Add a PKCS12 KeyStore for doing client certificates | | + + + +#### Changing the config +Changing Unirest's config should ideally be done once, or rarely. There are several background threads spawned by both Unirest itself and Apache HttpAsyncClient. Once Unirest has been activated configuration options that are involved in creating the client cannot be changed without an explicit shutdown or reset. + +```Java + Unirest.config() + .reset() + .connectTimeout(5000) +``` + +#### Setting custom Apache Client +You can set your own custom Apache HttpClient and HttpAsyncClient. Note that Unirest settings like timeouts or interceptors are not applied to custom clients. + +```java + Unirest.config() + .httpClient(myClient) + .asyncClient(myAsyncClient) +``` + +#### Multiple Configuration Instances +As usual, Unirest maintains a primary single instance. Sometimes you might want different configurations for different systems. You might also want an instance rather than a static context for testing purposes. + +```java + + // this returns the same instance used by Unirest.get("http://somewhere/") + UnirestInstance unirest = Unirest.primaryInstance(); + // It can be configured and used just like the static context + unirest.config().connectTimeout(5000); + String result = unirest.get("http://foo").asString().getBody(); + + // You can also get a whole new instance + UnirestInstance unirest = Unirest.spawnInstance(); +``` + +**WARNING!** If you get a new instance of unirest YOU are responsible for shutting it down when the JVM shuts down. It is not tracked or shut down by ```Unirest.shutDown();``` + + + + +## Exiting an application + +Unirest starts a background event loop and your Java application won't be able to exit until you manually shutdown all the threads by invoking: + +```java +Unirest.shutdown(); +``` + +Once shutdown, using Unirest again will re-init the system + + From f3b8ee339bcb481a7c9abe745b5c6f6aff483023 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 1 Jun 2019 14:07:43 -0500 Subject: [PATCH 0624/1769] can i haz a right nav --- docs/index.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 6c3866f59..3cccb41be 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,4 +1,7 @@ -# Unirest for Java +
+* [Features](#features) +* [Creating Request](#creating-request) +
[![Build Status](https://travis-ci.org/Kong/unirest-java.svg?branch=master)](https://travis-ci.org/Kong/unirest-java) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.konghq/unirest-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.kong/unirest-java) From a9f74af9bbe24f399dfb084dec854209227f56fd Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 1 Jun 2019 14:09:13 -0500 Subject: [PATCH 0625/1769] can i haz a right nav 2 --- docs/index.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/index.md b/docs/index.md index 3cccb41be..5a0e6835d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,3 +1,9 @@ +--- +layout: default +title: Documentation +rightmenu: true +--- +
* [Features](#features) * [Creating Request](#creating-request) From 2774b9ff0fe223f2bbef720109b1bd7942d963f6 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 1 Jun 2019 14:47:23 -0500 Subject: [PATCH 0626/1769] borrow the theme from spark --- docs/Gemfile | 2 + docs/_config.yml | 16 +- docs/_includes/base64/facebook.b64 | 1 + docs/_includes/base64/ghFork.b64 | 1 + docs/_includes/base64/ghStars.b64 | 1 + docs/_includes/base64/twitter.b64 | 1 + docs/_includes/gtm.html | 11 + docs/_includes/macros/mavenDep.md | 28 ++ docs/_includes/macros/mavenLink.html | 2 + docs/_includes/macros/mavenLinkKotlin.html | 2 + docs/_includes/macros/seeCommitHistory.html | 2 + docs/_includes/macros/teamMember.html | 26 ++ docs/_includes/socialButtons.html | 11 + docs/_layouts/default.html | 101 ++-- docs/_sass/_contact.scss | 90 ++++ docs/_sass/_frame.scss | 211 +++++++++ docs/_sass/_main.scss | 166 +++++++ docs/_sass/_modifiers.scss | 3 + docs/_sass/_normalize.scss | 461 +++++++++++++++++++ docs/_sass/_prism.scss | 181 ++++++++ docs/_sass/_prismOverrides.scss | 55 +++ docs/_sass/_tutorial.scss | 67 +++ docs/css/main.scss | 12 + docs/img/email.svg | 19 + docs/img/favicon.png | Bin 0 -> 11102 bytes docs/img/github.svg | 11 + docs/img/linkedin.svg | 18 + docs/img/paper.jpg | Bin 0 -> 5640 bytes docs/img/twitter.svg | 18 + docs/index.md | 1 - docs/js/_partials/main.js | 40 ++ docs/js/_partials/tutorials.js | 10 + docs/js/_partials/vendor/clipboard.min.js | 7 + docs/js/_partials/vendor/gumshoe.min.js | 2 + docs/js/_partials/vendor/prism.min.js | 13 + docs/js/_partials/vendor/smoothscroll.min.js | 3 + docs/js/scripts.js | 9 + docs/pages/index.md | 293 ++++++++++++ 38 files changed, 1841 insertions(+), 54 deletions(-) create mode 100644 docs/Gemfile create mode 100644 docs/_includes/base64/facebook.b64 create mode 100644 docs/_includes/base64/ghFork.b64 create mode 100644 docs/_includes/base64/ghStars.b64 create mode 100644 docs/_includes/base64/twitter.b64 create mode 100644 docs/_includes/gtm.html create mode 100644 docs/_includes/macros/mavenDep.md create mode 100644 docs/_includes/macros/mavenLink.html create mode 100644 docs/_includes/macros/mavenLinkKotlin.html create mode 100644 docs/_includes/macros/seeCommitHistory.html create mode 100644 docs/_includes/macros/teamMember.html create mode 100644 docs/_includes/socialButtons.html create mode 100644 docs/_sass/_contact.scss create mode 100644 docs/_sass/_frame.scss create mode 100644 docs/_sass/_main.scss create mode 100644 docs/_sass/_modifiers.scss create mode 100644 docs/_sass/_normalize.scss create mode 100644 docs/_sass/_prism.scss create mode 100644 docs/_sass/_prismOverrides.scss create mode 100644 docs/_sass/_tutorial.scss create mode 100644 docs/css/main.scss create mode 100644 docs/img/email.svg create mode 100644 docs/img/favicon.png create mode 100644 docs/img/github.svg create mode 100644 docs/img/linkedin.svg create mode 100644 docs/img/paper.jpg create mode 100644 docs/img/twitter.svg create mode 100644 docs/js/_partials/main.js create mode 100644 docs/js/_partials/tutorials.js create mode 100644 docs/js/_partials/vendor/clipboard.min.js create mode 100644 docs/js/_partials/vendor/gumshoe.min.js create mode 100644 docs/js/_partials/vendor/prism.min.js create mode 100644 docs/js/_partials/vendor/smoothscroll.min.js create mode 100644 docs/js/scripts.js create mode 100644 docs/pages/index.md diff --git a/docs/Gemfile b/docs/Gemfile new file mode 100644 index 000000000..3a1ebf306 --- /dev/null +++ b/docs/Gemfile @@ -0,0 +1,2 @@ +source 'https://rubygems.org' +gem 'github-pages' \ No newline at end of file diff --git a/docs/_config.yml b/docs/_config.yml index c74188174..d580e58a1 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1 +1,15 @@ -theme: jekyll-theme-slate \ No newline at end of file +# Site settings +sparkversion: 2.8.0 +templateversion: 2.7.1 +description: > # > means to ignore newlines as long as indent is kept + unirest-java + Unirest in Java: Simplified, lightweight HTTP client library. +baseurl: "" # the subpath of your site, e.g. /blog +url: "http://kong.github.io/unirest-java/" # the base hostname & protocol for your site +gems: [jekyll-redirect-from] + +# Build settings +markdown: kramdown +sass: + sass_dir: _sass + style: compressed diff --git a/docs/_includes/base64/facebook.b64 b/docs/_includes/base64/facebook.b64 new file mode 100644 index 000000000..df8168f9e --- /dev/null +++ b/docs/_includes/base64/facebook.b64 @@ -0,0 +1 @@ +data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAApVBMVEU7WZj///8dP4guTpGmutM3VpeltNEqSo/6/P08Wpk2VJUsTJDo7PNlfa4yUZQsS48mRoxceq1ieqxddqr8/v/q9vnv8veitdB8j7tyh7VQa6RIZJ9EYZ33+Pvw9/q/yd63wdmqu9Sdsc+DmL+DlL54jbltg7NKZaAwT5IpSY4gQYn38vjk6fHi5/HZ4e3Z3uvC0OKers1lg7JkgrJgeKxacqgNMX/YOePtAAAA1klEQVRIx+3RxxKCQBAEUEDXTbBLlGgOBHP8/0/T5YI3hqNKn/vVVE1rff48rOCcY0aBdYpF7nmelSJg377OTqZpjjcYBnA01eusbVBfpAe9E7BXdZtMSFSCQLVU/WNsbXMGAsZIgSFGCPQhhJ8XBUKDYwEAKHOzuQLzxHMftP3I4D7eTxTYvXdYFe1AWnqTGPBW/gGIhQHAJcRXbZ+QwJHtgKWRO1PgvN3EGWgHZITNDl2GG2haD74LLBRYwEG19INgGsIBS26O4yQIDKgopZSCan1+KC9JdQ1nh5XlRQAAAABJRU5ErkJggg== \ No newline at end of file diff --git a/docs/_includes/base64/ghFork.b64 b/docs/_includes/base64/ghFork.b64 new file mode 100644 index 000000000..41289b107 --- /dev/null +++ b/docs/_includes/base64/ghFork.b64 @@ -0,0 +1 @@ +data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJUAAACVCAMAAABmfEh9AAAAllBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPEhwAAAAFBgkAAAARFR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X6JiUDqtBqhAFVwBM5UIU8kQHVW8krDlShcwEDqoAncqAaYqEncqAaYpEnMqD6D2v15QnHQA5Ufaz71eqJxsAFg/BY35HriXbIHMJhEdftM+6QWUSHRVw3+L+VLXhEh4VcGM8LJnHGQjCKBZcgLOKysWATiEXBjAqxiMvGglEsMfhRWS4bC3bBk+ojPuIjPiIc/wAQkAE6ZqHsywAAAABJRU5ErkJggg== \ No newline at end of file diff --git a/docs/_includes/base64/ghStars.b64 b/docs/_includes/base64/ghStars.b64 new file mode 100644 index 000000000..f7442b380 --- /dev/null +++ b/docs/_includes/base64/ghStars.b64 @@ -0,0 +1 @@ +data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFwAAAAUCAIAAACPhs0OAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJI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NHjp0CAAcDgfDMGVlZcqNTks99DBNaDUAAHhOzKQFiVypW0lqNTAnorxWdmJJwlqtpiAgTBjIFXN5Pp1VboZ37typrq5eSHF4eNjlci0bIqOjoyVOtHq9nmGYa9eudXZ2xmIx2a7T6QCgtraWYZjSG5AkZhDPycKnc3OAcT4rW9K5BSePEOI4PiPgbJrjuHT2QTzREvLMV9RKp9MxDHPz5k2bzSZ7rVZrX19fbW2tRqNZ/P791eqDQpJkoVAgCGJxxdxu9wKPbDZbyZPLfdeiKJIkqdjoBUFYnkVZEASKogiTycRxnF6vl3FRVwqFAkLIaDQWG00mE8uyFotlGS6ZWJY1mUyaB+o6kiRJk8mk1nUkRVFy9L8HANLhIkH01sUwAAAAAElFTkSuQmCC \ No newline at end of file diff --git a/docs/_includes/base64/twitter.b64 b/docs/_includes/base64/twitter.b64 new file mode 100644 index 000000000..1c9e6a3fe --- /dev/null +++ b/docs/_includes/base64/twitter.b64 @@ -0,0 +1 @@ +data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAA2FBMVEVWo9n///9UotlSodhNntdLndZDmNVVo9lQoNhInNZap9tXpNpOn9f4+/6Ow+ZuseBCmdLx+P2jzeqLweWBvORiq91ZpdlGmtY+ltT8/v/0+/7f8Pvc7fe+3vF8ueJztOFpsN9qr9tAl9T4/f/q9fzl8/rP5/bH5PbK4/TH4/Oy1u6o0uuZyeeHv+R4uON5uN5xtNz6/f7b7vrX7PnC3/K12O6gzeyTxuibyueWx+Vkrd5JnNfi8PrY6/jV6Pe53fK42e6u1e2MwOF+u+B4t+Bus+BrsN86lNPPXfvkAAABhklEQVRIx+3T107rQBSF4T3V427c0xukNw4dTqO//xsREIhJvAfuUb5La/322JJhbw+4LEvJ4RWjUEHV1kWXySyI4ySLqKtKx6kGuUP1wru5OCEbzXlR5nHgVh6hrkeX0edVRqfkXet/s760rd1AdIgfcPZxPjonmtR5yHcLu03Icey+J8w50vbN4aTHoBpsjNZUsNegfUw0hysPOdKAbNSnIZMF55f6vtETlT0oOCVv/OldJ2NBTQsunqHK7ff8j0H9z+lYD+Z9JGC9NDgkuEAigZ364wN8P0gLJBChTwx+dwV2JOvMFEw8BgjRbRiCWQkouzuuY/uDR4EHFMJ/2Gu3IsCpfNJAPmxtKcAguiKIMwEmlMfVfSNnxsBVavFr941XHL6gbOd+qO/9xLMAxzzObc9Zt3z9/omiYJB1wnB1NaoRzd+1MO0tKzw/IduOZnADZtxbtLb+41k3Yi58gcriKbh9+0qD4XmaRRy+4VLRt6/bSbJYOn1ZmeMoL6SUtmfB3g/zAm+LHEPGGjqhAAAAAElFTkSuQmCC \ No newline at end of file diff --git a/docs/_includes/gtm.html b/docs/_includes/gtm.html new file mode 100644 index 000000000..fff1143db --- /dev/null +++ b/docs/_includes/gtm.html @@ -0,0 +1,11 @@ +
+ + + + +
diff --git a/docs/_includes/macros/mavenDep.md b/docs/_includes/macros/mavenDep.md new file mode 100644 index 000000000..2ca02e30e --- /dev/null +++ b/docs/_includes/macros/mavenDep.md @@ -0,0 +1,28 @@ +

Java

+~~~xml + + com.sparkjava + spark-core + {{site.sparkversion}} + +~~~ +

Kotlin

+~~~xml + + com.sparkjava + spark-kotlin + 1.0.0-alpha + +~~~ + +[Not familiar with Maven? Click here for more detailed instructions.](/tutorials/maven-setup) + +### Other dependency managers: +
+~~~java +Gradle : compile "com.sparkjava:spark-core:{{site.sparkversion}}" // add to build.gradle (for Java users) +Gradle : compile "com.sparkjava:spark-kotlin:1.0.0-alpha" // add to build.gradle (for Kotlin users) + Ivy : // ivy.xml + SBT : libraryDependencies += "com.sparkjava" % "spark-core" % "{{site.sparkversion}}" // build.sbt +~~~ +
\ No newline at end of file diff --git a/docs/_includes/macros/mavenLink.html b/docs/_includes/macros/mavenLink.html new file mode 100644 index 000000000..a90f4a647 --- /dev/null +++ b/docs/_includes/macros/mavenLink.html @@ -0,0 +1,2 @@ +Spark {{include.version}} is available for download on +Maven Central. \ No newline at end of file diff --git a/docs/_includes/macros/mavenLinkKotlin.html b/docs/_includes/macros/mavenLinkKotlin.html new file mode 100644 index 000000000..5b1982ea5 --- /dev/null +++ b/docs/_includes/macros/mavenLinkKotlin.html @@ -0,0 +1,2 @@ +Spark-kotlin {{include.version}} is available for download on +Maven Central. \ No newline at end of file diff --git a/docs/_includes/macros/seeCommitHistory.html b/docs/_includes/macros/seeCommitHistory.html new file mode 100644 index 000000000..1b1befb25 --- /dev/null +++ b/docs/_includes/macros/seeCommitHistory.html @@ -0,0 +1,2 @@ +See the +commit history on GitHub for details. \ No newline at end of file diff --git a/docs/_includes/macros/teamMember.html b/docs/_includes/macros/teamMember.html new file mode 100644 index 000000000..7a13176c0 --- /dev/null +++ b/docs/_includes/macros/teamMember.html @@ -0,0 +1,26 @@ +{% assign _ = include %} +
+ +
+

{{_.firstName}} {{_.lastName}}

+ {{_.role}} + +
+
\ No newline at end of file diff --git a/docs/_includes/socialButtons.html b/docs/_includes/socialButtons.html new file mode 100644 index 000000000..e596f0ecd --- /dev/null +++ b/docs/_includes/socialButtons.html @@ -0,0 +1,11 @@ + + \ No newline at end of file diff --git a/docs/_layouts/default.html b/docs/_layouts/default.html index 85681f40f..8ea1c7a74 100644 --- a/docs/_layouts/default.html +++ b/docs/_layouts/default.html @@ -1,62 +1,59 @@ - - + - + - - - - {% seo %} + + + {% if page.title %}{{ page.title }} - {% endif %}Spark Framework: An expressive web framework for Kotlin and Java + + + + + + + + - - - -
-
- {% if site.github.is_project_page %} - View on GitHub - {% endif %} - -

{{ site.title | default: site.github.repository_name }}

-

{{ site.description | default: site.github.project_tagline }}

- - {% if site.show_downloads %} -
- Download this project as a .zip file - Download this project as a tar.gz file -
- {% endif %} + + Fork me on GitHub + +
+
-
- - -
-
+
{{ content }} -
-
- - - - -{% if site.google_analytics %} - -{% endif %} + diff --git a/docs/_sass/_contact.scss b/docs/_sass/_contact.scss new file mode 100644 index 000000000..3ca949cf3 --- /dev/null +++ b/docs/_sass/_contact.scss @@ -0,0 +1,90 @@ +.team { + margin-top: 20px; + width: 100%; + overflow: auto; + .team-member { + margin: 10px 0; + font-size: 14px; + width: 48%; + padding: 15px; + background: #f5f5f5; + border: 1px solid #ddd; + float: left; + overflow: auto; + &:nth-child(even) { + margin-left: 2%; + } + &:nth-child(odd) { + margin-right: 2%; + } + > img { + border-radius: 3px; + float: left; + width: 100px; + margin-right: 15px; + } + .info-wrap { + float: left; + h3 { + margin: 8px 0 0; + } + img { + display: inline-block; + opacity: 0.4; + margin-top: 10px; + width: 30px; + margin-right: 8px; + &:hover { + opacity: 0.7; + } + } + } + } +} + +@media (max-width: 800px) { + .team { + .team-member { + width: 100%; + &:nth-child(even), + &:nth-child(odd) { + margin: 0; + } + + .team-member { + margin-top: 20px; + } + } + } +} + +ul.contributors { + padding: 0; + margin: 0; + list-style: none; + display: flex; + flex-wrap: wrap; + justify-content: space-between; + li { + position: relative; + display: inline-block; + margin: 10px 5px; + border: 1px solid #000; + width: 110px; + } + img { + display: block; + width: 100%; + } + span { + padding: 1px 3px; + display: inline-block; + width: 100%; + background: linear-gradient(to right, rgba(0,0,0,1), rgba(0,0,0,0.5)); + position: absolute; + bottom: 0; + font-size: 12px; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } +} \ No newline at end of file diff --git a/docs/_sass/_frame.scss b/docs/_sass/_frame.scss new file mode 100644 index 000000000..35c6f96d6 --- /dev/null +++ b/docs/_sass/_frame.scss @@ -0,0 +1,211 @@ +$spark-orange: #e88300; + +html { + position: relative; + min-height: 100%; +} + +body { + padding-top: 80px; + margin-bottom: 60px; +} + +header { + z-index: 1; + background: #fff; + position: fixed; + height: 80px; + width: 100%; + top: 0; + left: 0; + box-shadow: 0 1px 2px rgba(0,0,0,0.3); +} + +footer { + font-size: 13px; + position: absolute; + left: 0; + bottom: 0; + height: 40px; + width: 100%; + line-height: 40px; + text-align: center; + background: #f5f5f5; + border-top: 1px solid #ddd; + padding: 0 20px; + overflow: hidden; +} + +.width-limit { + width: 100%; + padding-left: 20px; + padding-right: 20px; + max-width: 840px; + margin: 0 auto; +} + +nav { + height: 80px; + position: relative; + #logo img { + margin: 10px 0; + height: 60px; + } + ul { + padding: 0; + margin: 0; + list-style: none; + float: right; + height: 40px; + margin-top: 40px; + li { + display: inline-block; + a { + display: block; + color: #333; + text-decoration: none; + margin: 0 5px; + padding: 0 5px; + line-height: 40px; + } + &:last-of-type a { + padding-right: 0; + margin-right: 0; + } + } + } +} + +#some-buttons { + position: absolute; + top: 15px; + right: 20px; + #githubStar { + display: inline-block; + width: 95px; + height: 20px; + position: relative; + #starBg, + #starFrame { + position: absolute; + border: 0; + } + } + a { + display: inline-block; + &:last-of-type { + margin-left: 3px; + } + img { + border-radius: 3px; + height: 20px; + } + } +} + +.right-menu { + position: fixed; + left: 50%; + list-style: none; + padding: 0; + margin-left: 430px; + top: 120px; + z-index: 999999; + width: 200px; + ul { + margin: 0; + list-style: none; + padding: 0; + .active > a { + font-weight: 700; + } + a { + display: inline-block; + padding: 1px 0; + margin: 1px 0; + } + ul { + font-size: 14px; + padding-left: 15px; + } + } + ul.tutorial-menu { + font-size: 13px; + font-family: Tahoma, arial, sans-serif; + a { + padding: 2px 0; + margin: 2px 0; + } + } +} + +@media (max-height: 850px) { + .right-menu { + font-size: 14px; + } +} + +@media (max-height: 750px) { + .right-menu { + ul a { + margin: 0; + } + } +} + +@media (max-width: 1200px) { + #fork-me { + display: none; + } +} + +@media (min-width: 701px) and (max-width: 1200px) { + main.width-limit, + nav.width-limit { + max-width: 100%; + } + .has-right-menu { + &.width-limit { + padding-right: 220px; + } + } + .right-menu { + top: 80px; + right: 0; + left: auto; + margin-left: 0; + height: 100%; + border-left: 1px solid #e0e0e0; + background: linear-gradient(to right, #f9f9f9, white); + padding: 40px 15px 0 15px; + z-index: 0; + } +} +@media (max-width: 700px) { + .right-menu { + display: none; + } +} +@media (max-width: 600px) { + a[href="/download"] { + display: none; + } +} +@media (max-width: 480px) { + nav ul li a { + margin: 0 2px; + font-size: 14px; + } +} +@media (max-width: 400px) { + nav { + ul li a { + padding: 0; + font-size: 12px; + } + #logo img { + margin: 30px 0 10px; + height: 40px; + } + } +} diff --git a/docs/_sass/_main.scss b/docs/_sass/_main.scss new file mode 100644 index 000000000..bd755fd0a --- /dev/null +++ b/docs/_sass/_main.scss @@ -0,0 +1,166 @@ +$spark-orange: #e88300; + +* { + box-sizing: border-box; +} + +html { + overflow-y: scroll; + color: #333; + line-height: 1.4; +} + +a { + color: $spark-orange; + text-decoration: none; +} + +h1 { font-size: 36px; } +h2 { font-size: 28px; } +h3 { font-size: 22px; } +h4 { font-size: 20px; } + +h1, +h2, +h3, +h4 { + font-weight: 700; + font-family: 'Lato', sans-serif; + font-style: italic; + letter-spacing: -0.5px; + margin-top: 1.75em; + margin-bottom: 0.75em; + + p { + margin-top: 0.25em; + } +} + +h2 { + font-weight: 400; +} + +p { + margin: 1.5em 0 0.25em; + font-family: 'Lato', sans-serif; +} + +p, +li { + code { + font-family: 'Fira Mono', monospace; + font-size: 80%; + border: 1px solid #ccc; + background: #f5f5f5; + padding: 1px 3px; + color: #0008bc; + border-radius: 3px; + font-style: normal; + } +} + +.star-one { + margin: 15px 0; + background: #fff; + padding: 15px; + border: 1px dashed #bbb; + p { + margin: 0; + } +} + +.star-two { + overflow: auto; + margin: 25px 0 10px; + > * { + height: 30px; + line-height: 30px; + float: left; + margin-right: 10px; + } +} + +pre { + margin: .5em 0; + background: #333; + padding: 15px; + border-radius: 5px; + color: #f5f5f5; + overflow-x: scroll; +} + +main { + padding: 40px 0; + img { + width: 100%; + display: block; + max-width: 100%; + } +} + +.notification { + margin: 15px 0; + background: #f5f5f5; + padding: 15px; + border-left: 5px solid $spark-orange; + p { + margin: 0; + } +} + +.template-engine { + margin-top: 32px; + h2, + p { + margin: 5px 0; + } +} + +.template-engine-list { + color: #777; +} + +.small-list { + font-size: 80%; +} + +blockquote { + background: #f9f9f9; + border-left: 10px solid #ccc; + margin: 0 0 20px 0; + padding: 0.5em 10px; + quotes: "\201C""\201D""\2018""\2019"; + &:before { + color: #ccc; + content: open-quote; + font-size: 4em; + line-height: 0.1em; + margin-right: 5px; + vertical-align: -0.5em; + } + p { + line-height: 200%; + display: inline; + } +} + +pre { // scrollbar in code examples + &::-webkit-scrollbar { + width: 5px; + height: 5px; + } + &::-webkit-scrollbar-thumb { + background: #777; + border-radius: 5px; + } + &::-webkit-scrollbar-thumb:hover { + background: #999; + } + &::-webkit-scrollbar-track { + background: #333; + border-radius: 5px; + } + &::-webkit-scrollbar-button { + width: 8px; + height: 8px; + } +} diff --git a/docs/_sass/_modifiers.scss b/docs/_sass/_modifiers.scss new file mode 100644 index 000000000..4fe3d9209 --- /dev/null +++ b/docs/_sass/_modifiers.scss @@ -0,0 +1,3 @@ +.no-margin-top { + margin-top: 0; +} \ No newline at end of file diff --git a/docs/_sass/_normalize.scss b/docs/_sass/_normalize.scss new file mode 100644 index 000000000..b9d2f75d4 --- /dev/null +++ b/docs/_sass/_normalize.scss @@ -0,0 +1,461 @@ +/*! normalize.css v5.0.0 | MIT License | github.com/necolas/normalize.css */ + +/** + * 1. Change the default font family in all browsers (opinionated). + * 2. Correct the line height in all browsers. + * 3. Prevent adjustments of font size after orientation changes in + * IE on Windows Phone and in iOS. + */ + +/* Document + ========================================================================== */ + +html { + font-family: sans-serif; /* 1 */ + line-height: 1.25; /* 2 */ + -ms-text-size-adjust: 100%; /* 3 */ + -webkit-text-size-adjust: 100%; /* 3 */ +} + +/* Sections + ========================================================================== */ + +/** + * Remove the margin in all browsers (opinionated). + */ + +body { + margin: 0; +} + +/** + * Add the correct display in IE 9-. + */ + +article, +aside, +footer, +header, +nav, +section { + display: block; +} + +/** + * Correct the font size and margin on `h1` elements within `section` and + * `article` contexts in Chrome, Firefox, and Safari. + */ + +h1 { + font-size: 2em; + margin: 0.67em 0; +} + +/* Grouping content + ========================================================================== */ + +/** + * Add the correct display in IE 9-. + * 1. Add the correct display in IE. + */ + +figcaption, +figure, +main { /* 1 */ + display: block; +} + +/** + * Add the correct margin in IE 8. + */ + +figure { + margin: 1em 40px; +} + +/** + * 1. Add the correct box sizing in Firefox. + * 2. Show the overflow in Edge and IE. + */ + +hr { + box-sizing: content-box; /* 1 */ + height: 0; /* 1 */ + overflow: visible; /* 2 */ +} + +/** + * 1. Correct the inheritance and scaling of font size in all browsers. + * 2. Correct the odd `em` font sizing in all browsers. + */ + +pre { + font-family: monospace, monospace; /* 1 */ + font-size: 1em; /* 2 */ +} + +/* Text-level semantics + ========================================================================== */ + +/** + * 1. Remove the gray background on active links in IE 10. + * 2. Remove gaps in links underline in iOS 8+ and Safari 8+. + */ + +a { + background-color: transparent; /* 1 */ + -webkit-text-decoration-skip: objects; /* 2 */ +} + +/** + * Remove the outline on focused links when they are also active or hovered + * in all browsers (opinionated). + */ + +a:active, +a:hover { + outline-width: 0; +} + +/** + * 1. Remove the bottom border in Firefox 39-. + * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari. + */ + +abbr[title] { + border-bottom: none; /* 1 */ + text-decoration: underline; /* 2 */ + text-decoration: underline dotted; /* 2 */ +} + +/** + * Prevent the duplicate application of `bolder` by the next rule in Safari 6. + */ + +b, +strong { + font-weight: inherit; +} + +/** + * Add the correct font weight in Chrome, Edge, and Safari. + */ + +b, +strong { + font-weight: bolder; +} + +/** + * 1. Correct the inheritance and scaling of font size in all browsers. + * 2. Correct the odd `em` font sizing in all browsers. + */ + +code, +kbd, +samp { + font-family: monospace, monospace; /* 1 */ + font-size: 1em; /* 2 */ +} + +/** + * Add the correct font style in Android 4.3-. + */ + +dfn { + font-style: italic; +} + +/** + * Add the correct background and color in IE 9-. + */ + +mark { + background-color: #ff0; + color: #000; +} + +/** + * Add the correct font size in all browsers. + */ + +small { + font-size: 80%; +} + +/** + * Prevent `sub` and `sup` elements from affecting the line height in + * all browsers. + */ + +sub, +sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; +} + +sub { + bottom: -0.25em; +} + +sup { + top: -0.5em; +} + +/* Embedded content + ========================================================================== */ + +/** + * Add the correct display in IE 9-. + */ + +audio, +video { + display: inline-block; +} + +/** + * Add the correct display in iOS 4-7. + */ + +audio:not([controls]) { + display: none; + height: 0; +} + +/** + * Remove the border on images inside links in IE 10-. + */ + +img { + border-style: none; +} + +/** + * Hide the overflow in IE. + */ + +svg:not(:root) { + overflow: hidden; +} + +/* Forms + ========================================================================== */ + +/** + * 1. Change the font styles in all browsers (opinionated). + * 2. Remove the margin in Firefox and Safari. + */ + +button, +input, +optgroup, +select, +textarea { + font-family: sans-serif; /* 1 */ + font-size: 100%; /* 1 */ + line-height: 1.15; /* 1 */ + margin: 0; /* 2 */ +} + +/** + * Show the overflow in IE. + * 1. Show the overflow in Edge. + */ + +button, +input { /* 1 */ + overflow: visible; +} + +/** + * Remove the inheritance of text transform in Edge, Firefox, and IE. + * 1. Remove the inheritance of text transform in Firefox. + */ + +button, +select { /* 1 */ + text-transform: none; +} + +/** + * 1. Prevent a WebKit bug where (2) destroys native `audio` and `video` + * controls in Android 4. + * 2. Correct the inability to style clickable types in iOS and Safari. + */ + +button, +html [type="button"], /* 1 */ +[type="reset"], +[type="submit"] { + -webkit-appearance: button; /* 2 */ +} + +/** + * Remove the inner border and padding in Firefox. + */ + +button::-moz-focus-inner, +[type="button"]::-moz-focus-inner, +[type="reset"]::-moz-focus-inner, +[type="submit"]::-moz-focus-inner { + border-style: none; + padding: 0; +} + +/** + * Restore the focus styles unset by the previous rule. + */ + +button:-moz-focusring, +[type="button"]:-moz-focusring, +[type="reset"]:-moz-focusring, +[type="submit"]:-moz-focusring { + outline: 1px dotted ButtonText; +} + +/** + * Change the border, margin, and padding in all browsers (opinionated). + */ + +fieldset { + border: 1px solid #c0c0c0; + margin: 0 2px; + padding: 0.35em 0.625em 0.75em; +} + +/** + * 1. Correct the text wrapping in Edge and IE. + * 2. Correct the color inheritance from `fieldset` elements in IE. + * 3. Remove the padding so developers are not caught out when they zero out + * `fieldset` elements in all browsers. + */ + +legend { + box-sizing: border-box; /* 1 */ + color: inherit; /* 2 */ + display: table; /* 1 */ + max-width: 100%; /* 1 */ + padding: 0; /* 3 */ + white-space: normal; /* 1 */ +} + +/** + * 1. Add the correct display in IE 9-. + * 2. Add the correct vertical alignment in Chrome, Firefox, and Opera. + */ + +progress { + display: inline-block; /* 1 */ + vertical-align: baseline; /* 2 */ +} + +/** + * Remove the default vertical scrollbar in IE. + */ + +textarea { + overflow: auto; +} + +/** + * 1. Add the correct box sizing in IE 10-. + * 2. Remove the padding in IE 10-. + */ + +[type="checkbox"], +[type="radio"] { + box-sizing: border-box; /* 1 */ + padding: 0; /* 2 */ +} + +/** + * Correct the cursor style of increment and decrement buttons in Chrome. + */ + +[type="number"]::-webkit-inner-spin-button, +[type="number"]::-webkit-outer-spin-button { + height: auto; +} + +/** + * 1. Correct the odd appearance in Chrome and Safari. + * 2. Correct the outline style in Safari. + */ + +[type="search"] { + -webkit-appearance: textfield; /* 1 */ + outline-offset: -2px; /* 2 */ +} + +/** + * Remove the inner padding and cancel buttons in Chrome and Safari on macOS. + */ + +[type="search"]::-webkit-search-cancel-button, +[type="search"]::-webkit-search-decoration { + -webkit-appearance: none; +} + +/** + * 1. Correct the inability to style clickable types in iOS and Safari. + * 2. Change font properties to `inherit` in Safari. + */ + +::-webkit-file-upload-button { + -webkit-appearance: button; /* 1 */ + font: inherit; /* 2 */ +} + +/* Interactive + ========================================================================== */ + +/* + * Add the correct display in IE 9-. + * 1. Add the correct display in Edge, IE, and Firefox. + */ + +details, /* 1 */ +menu { + display: block; +} + +/* + * Add the correct display in all browsers. + */ + +summary { + display: list-item; +} + +/* Scripting + ========================================================================== */ + +/** + * Add the correct display in IE 9-. + */ + +canvas { + display: inline-block; +} + +/** + * Add the correct display in IE. + */ + +template { + display: none; +} + +/* Hidden + ========================================================================== */ + +/** + * Add the correct display in IE 10-. + */ + +[hidden] { + display: none; +} \ No newline at end of file diff --git a/docs/_sass/_prism.scss b/docs/_sass/_prism.scss new file mode 100644 index 000000000..7ad7dcb96 --- /dev/null +++ b/docs/_sass/_prism.scss @@ -0,0 +1,181 @@ +/* http://prismjs.com/download.html?themes=prism-okaidia&languages=markup+css+clike+javascript+bash+ruby+java+kotlin+sql&plugins=toolbar+copy-to-clipboard */ +/** + * okaidia theme for JavaScript, CSS and HTML + * Loosely based on Monokai textmate theme by http://www.monokai.nl/ + * @author ocodia + */ + +code[class*="language-"], +pre[class*="language-"] { + color: #f8f8f2; + background: none; + text-shadow: 0 1px rgba(0, 0, 0, 0.3); + font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; + text-align: left; + white-space: pre; + word-spacing: normal; + word-break: normal; + word-wrap: normal; + line-height: 1.5; + + -moz-tab-size: 4; + -o-tab-size: 4; + tab-size: 4; + + -webkit-hyphens: none; + -moz-hyphens: none; + -ms-hyphens: none; + hyphens: none; +} + +/* Code blocks */ +pre[class*="language-"] { + padding: 1em; + margin: .5em 0; + overflow: auto; + border-radius: 0.3em; +} + +:not(pre) > code[class*="language-"], +pre[class*="language-"] { + background: #272822; +} + +/* Inline code */ +:not(pre) > code[class*="language-"] { + padding: .1em; + border-radius: .3em; + white-space: normal; +} + +.token.comment, +.token.prolog, +.token.doctype, +.token.cdata { + color: slategray; +} + +.token.punctuation { + color: #f8f8f2; +} + +.namespace { + opacity: .7; +} + +.token.property, +.token.tag, +.token.constant, +.token.symbol, +.token.deleted { + color: #f92672; +} + +.token.boolean, +.token.number { + color: #ae81ff; +} + +.token.selector, +.token.attr-name, +.token.string, +.token.char, +.token.builtin, +.token.inserted { + color: #a6e22e; +} + +.token.operator, +.token.entity, +.token.url, +.language-css .token.string, +.style .token.string, +.token.variable { + color: #f8f8f2; +} + +.token.atrule, +.token.attr-value, +.token.function { + color: #e6db74; +} + +.token.keyword { + color: #66d9ef; +} + +.token.regex, +.token.important { + color: #fd971f; +} + +.token.important, +.token.bold { + font-weight: bold; +} +.token.italic { + font-style: italic; +} + +.token.entity { + cursor: help; +} + +pre.code-toolbar { + position: relative; +} + +pre.code-toolbar > .toolbar { + position: absolute; + top: .3em; + right: .2em; + transition: opacity 0.3s ease-in-out; + opacity: 0; +} + +pre.code-toolbar:hover > .toolbar { + opacity: 1; +} + +pre.code-toolbar > .toolbar .toolbar-item { + display: inline-block; +} + +pre.code-toolbar > .toolbar a { + cursor: pointer; +} + +pre.code-toolbar > .toolbar button { + background: none; + border: 0; + color: inherit; + font: inherit; + line-height: normal; + overflow: visible; + padding: 0; + -webkit-user-select: none; /* for button */ + -moz-user-select: none; + -ms-user-select: none; +} + +pre.code-toolbar > .toolbar a, +pre.code-toolbar > .toolbar button, +pre.code-toolbar > .toolbar span { + color: #bbb; + font-size: .8em; + padding: 0 .5em; + background: #f5f2f0; + background: rgba(224, 224, 224, 0.2); + box-shadow: 0 2px 0 0 rgba(0,0,0,0.2); + border-radius: .5em; +} + +pre.code-toolbar > .toolbar a:hover, +pre.code-toolbar > .toolbar a:focus, +pre.code-toolbar > .toolbar button:hover, +pre.code-toolbar > .toolbar button:focus, +pre.code-toolbar > .toolbar span:hover, +pre.code-toolbar > .toolbar span:focus { + color: inherit; + text-decoration: none; +} diff --git a/docs/_sass/_prismOverrides.scss b/docs/_sass/_prismOverrides.scss new file mode 100644 index 000000000..8e50be283 --- /dev/null +++ b/docs/_sass/_prismOverrides.scss @@ -0,0 +1,55 @@ +.highlighter-rouge { + margin: 10px 0; + position: relative; + overflow: auto; + pre { + margin: 0; + overflow: auto; + background: #30312a; + padding: 15px; + code { + float: left; + font-family: 'Fira Mono', monospace; + font-size: 15px; + line-height: 1.6; + } + } +} + +.smaller-code { + pre code { + font-size: 13px; + } +} + +// Toolbar + +pre.code-toolbar { + position: initial; +} + +pre.code-toolbar > .toolbar { + opacity: 1; + transition: none; + top: 0px; + right: 0px; +} + +pre.code-toolbar > .toolbar a { + font-size: 13px; + padding: 1px 6px 3px; +} + +pre.code-toolbar > .toolbar a, +pre.code-toolbar > .toolbar button, +pre.code-toolbar > .toolbar span { + display: inline-block; + padding: 2px 8px; + background: #30312a; + box-shadow: none; + border-radius: 0 5px 0 5px; + color: #888; + border: 1px solid #444; + border-top: 0; + border-right: 0; +} diff --git a/docs/_sass/_tutorial.scss b/docs/_sass/_tutorial.scss new file mode 100644 index 000000000..69233937b --- /dev/null +++ b/docs/_sass/_tutorial.scss @@ -0,0 +1,67 @@ +.tutorial { + h1, h2, h3, h4 { + font-family: "Trebuchet MS", Helvetica, sans-serif; + font-weight: 400; + } + h1 { font-size: 26px; } + h2 { font-size: 22px; } + h3 { font-size: 20px; } + h4 { font-size: 18px; } + #timeToRead { + float: right; + } + .tutorial-header .notification { + font-size: 14px; + margin-bottom: 30px; + .github-link { + display: block; + width: 100%; + padding-top: 8px; + margin-top: 8px; + border-top: 1px solid #ddd; + } + } +} + +.tutorial-overview { + overflow: hidden; + margin: 24px 0; + padding: 24px 0; + border-bottom: 1px solid #ddd; + border-top: 1px solid #ddd; +} + +.tutorials-header, +.tutorials-footer { + clear: both; + p { + margin: 0; + } +} + +ul.tutorial-list { + list-style: none; + padding: 0; + margin: 0; + width: 50%; + float: left; + h2 { + margin-top: 0; + } + li { + padding-right: 24px; + + li { + margin-top: 24px; + } + h2 { + font-size: 20px; + max-width: 100%; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + p { + font-size: 13px; + } + } +} \ No newline at end of file diff --git a/docs/css/main.scss b/docs/css/main.scss new file mode 100644 index 000000000..dcc3b2dd7 --- /dev/null +++ b/docs/css/main.scss @@ -0,0 +1,12 @@ +--- +# Only the main Sass file needs front matter (the dashes are enough) +--- + +@import 'normalize'; +@import 'main'; +@import 'frame'; +@import 'tutorial'; +@import 'contact'; +@import 'modifiers'; +@import 'prism'; +@import 'prismOverrides'; diff --git a/docs/img/email.svg b/docs/img/email.svg new file mode 100644 index 000000000..9d45484cf --- /dev/null +++ b/docs/img/email.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + diff --git a/docs/img/favicon.png b/docs/img/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..6bc913c0ea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z=$w%pwc0x(F!t=%yF(X*uReJajSj>*kI%xF)T#^OQ0<{VQqGyWkHHa(OkO5lil`1i zxqsz6k60^>#Zc;ve;clI=10aH=<5K~ zn5al$HW>V$g{R`t73{SlWvAF`P!)Yup(#dFgT4zjev;y>Ce1v<=6D#Gb^}ZaXt@m= zr6!#H*aJkTdNLP0k~Uc0D=&`Mrjk6BmsB6r;4l*~dwt0gx8{4(zK2GoXGtZ(VPg#o zQ(0l&3insvu^*bbaQ*)AX9?CQ*?K3r{C+XA4@>B~X(AStT{*}YcT6?R>`$r&W<}C9 z6-G9>GHnfeoctr<1HN>I?pE7pKfQW-+11RpL>A#ijdg4`uB~$Ad;Lv13I3uc48sv} zRho+YEXDK%!Pbp@L3TaVZrvAmIEo&&hSeD8|Og0P{)9Z`}0{RFoh9|j6G%CJ?8DoJdi*dfU+l}ZW!?D zcso66HdU_E>D=wMK2L)@UbRg8>A(o?MsqWPjNhYp2RNMA-@dxBy~9Vk^9>e+RBt-Z zS-T4$^@*`#q)m9CI`-bJFyS6CqDO44FR${6nqqExAf{9&jkV*Q4>vQBMNt7o zGu4mNzx*)nt$;`)NvTT6rs^|cmWbuT1S7-!{~|0Y;9f + + + + diff --git a/docs/img/linkedin.svg b/docs/img/linkedin.svg new file mode 100644 index 000000000..559aad145 --- /dev/null +++ b/docs/img/linkedin.svg @@ -0,0 +1,18 @@ + + + + + diff --git a/docs/img/paper.jpg b/docs/img/paper.jpg new file mode 100644 index 0000000000000000000000000000000000000000..178f899e5a7ea9cc37a81c76407fa76dea8cb0c1 GIT binary patch literal 5640 zcma)AcT`i)woXEX&=We+6A02n0@5Ld(3^sQ2qL|R0s-m0_Yy#wF-Qjm1w;V_6=?~e zfFeZ^`B4NL5~K>k4R^hD-@5<2^}ac0)|uJ+?D_Vdz1EcDnd1cj)YQ<#5C8-M06=;H z9Df8P1HcR?px0nVF#TmZ1qPpDf-o{NF)~6}Ak1_?SXkIjK(E=^+1Oww;Q0@L;8Uj{ zOb|{M7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(&Xo<`tsbzW||@A6-NU=~q2J#bOXJ8zbbc_DZ=7vz> zK2xmdE%uV{kDGbYlQQQwTIyEnu%$Ql=~g|T&Qfoz!ONK+Ij0Nc>eW@!%GAC&USYCA zptar_t=mep#qEcl4d|k*eM(c+yt0FQ>q;%{5zX+g{mbfGLbUk3evQ&jlkyE_{9HEM?U&X5_r|c+8bxEw8N|Xn+BLnK6Gvzf-W7kZc&dlzMYNKRzmtMhr6pxZ>wiK10F<&j^ zuAlPT3mjFgdTg8VP2;|b^f5p>>52g_{0x56()4WqknM=#XsCq#x68>N84lLGBV`~H ze)@>CBqx4ri+9s0%OyHP0n~d)Sy^jMlI{MEM(_fOdhb@$74SEQftoj`d?woE!gwYo zLp>YhRJ4mKT-EEh?2u$U$(%pw4&T=c(-~dKgaPws=RdPu^o?Wk{EOk^aV%77FSarH zrnoG`T@Q7hDKC|xNnW@g;Duhh(NvVyyBa)co9bPeo8IgwCWzc|UbR%wdcZB4e?RDT zXXlU3t|#6Vh^{=`5zh9C`LnEtROp9;$y=|}RwhR;Mnvz)vE&po{^7Pvo(cQ)&x6Fj zFczQh$kJaw4B|ku-I>ExEtQvMs9O;VGq2QUYBNOCW&S8}41qpn8;s_B_~K$ZNAmXO p=@&b7m`7jkd0_u_BT8TG@BVvT2LXY40D##4p+Udr`nSgHzX0=5v?Txl literal 0 HcmV?d00001 diff --git a/docs/img/twitter.svg b/docs/img/twitter.svg new file mode 100644 index 000000000..dbd7b8a4c --- /dev/null +++ b/docs/img/twitter.svg @@ -0,0 +1,18 @@ + + + + + diff --git a/docs/index.md b/docs/index.md index 5a0e6835d..f6b7bde8d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -290,4 +290,3 @@ Unirest.shutdown(); Once shutdown, using Unirest again will re-init the system - diff --git a/docs/js/_partials/main.js b/docs/js/_partials/main.js new file mode 100644 index 000000000..2bff6435a --- /dev/null +++ b/docs/js/_partials/main.js @@ -0,0 +1,40 @@ +// add target blank to all external links +for (var i = 0; i < document.links.length; i++) { + if (document.links[i].hostname != window.location.hostname) { + document.links[i].target = "_blank"; + } +} + +var offset = 24; +var fixedHeaderSelector = 'body > header'; +smoothScroll.init({ // https://github.com/cferdinandi/smooth-scroll + selector: 'a[href^="#"]', // Selector for links (must be a class, ID, data attribute, or element tag) + selectorHeader: fixedHeaderSelector, // Selector for fixed headers [optional] + speed: 500, // Integer. How fast to complete the scroll in milliseconds + easing: 'easeInOutCubic', // Easing pattern to use + offset: offset, // Integer. How far to offset the scrolling anchor location in pixels + callback: function ( anchor, toggle ) {} // Function to run after scrolling +}); + +// scroll to current element on load +if (window.location.hash && performance.navigation.type !== 1) { + setTimeout(function() { + window.scrollTo(0, window.scrollY - 106); + }, 0); +} + +setTimeout(function() { + gumshoe.init({ // https://github.com/cferdinandi/gumshoe (scrollspy) + selector: '#spy-nav > ul > li > a', // Default link selector + selectorHeader: fixedHeaderSelector, // Fixed header selector + container: window, // The element to spy on scrolling in (must be a valid DOM Node) + offset: offset, // Distance in pixels to offset calculations + activeClass: 'active', // Class to apply to active navigation link and its parent list item + scrollDelay: false, // Wait until scrolling has stopped before updating the navigation + callback: function (nav) { + try { + window.history.replaceState({}, "", location.pathname + "#" + nav.target.id); + } catch(e) { /* Doesn't matter */ } + } + }); +}, 500); diff --git a/docs/js/_partials/tutorials.js b/docs/js/_partials/tutorials.js new file mode 100644 index 000000000..64db908a6 --- /dev/null +++ b/docs/js/_partials/tutorials.js @@ -0,0 +1,10 @@ + // trim blank lines around code +var codeBlocks = document.getElementsByTagName("code"); +for (var i = 0; i < codeBlocks.length; i++) { + codeBlocks[i].innerHTML = codeBlocks[i].innerHTML.trim(); +} + +// Calculate time to read +if (document.getElementById("timeToRead") !== null) { + function getText(a){for(var d="",c=0;c"; +} diff --git a/docs/js/_partials/vendor/clipboard.min.js b/docs/js/_partials/vendor/clipboard.min.js new file mode 100644 index 000000000..15210c824 --- /dev/null +++ b/docs/js/_partials/vendor/clipboard.min.js @@ -0,0 +1,7 @@ +/*! + * clipboard.js v1.5.8 + * https://zenorocha.github.io/clipboard.js + * + * Licensed MIT © Zeno Rocha + */ +!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.Clipboard=t()}}(function(){var t,e,n;return function t(e,n,r){function o(a,s){if(!n[a]){if(!e[a]){var c="function"==typeof require&&require;if(!s&&c)return c(a,!0);if(i)return i(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var l=n[a]={exports:{}};e[a][0].call(l.exports,function(t){var n=e[a][1][t];return o(n?n:t)},l,l.exports,t,e,n,r)}return n[a].exports}for(var i="function"==typeof require&&require,a=0;ar;r++)n[r].fn.apply(n[r].ctx,e);return this},off:function(t,e){var n=this.e||(this.e={}),r=n[t],o=[];if(r&&e)for(var i=0,a=r.length;a>i;i++)r[i].fn!==e&&r[i].fn._!==e&&o.push(r[i]);return o.length?n[t]=o:delete n[t],this}},e.exports=r},{}],8:[function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}n.__esModule=!0;var i=function(){function t(t,e){for(var n=0;n=0?n:0},p=function(t){var n=t.getBoundingClientRect();return n.top>=0&&n.left>=0&&n.bottom<=(e.innerHeight||document.documentElement.clientHeight)&&n.right<=(e.innerWidth||document.documentElement.clientWidth)},y=function(){u.sort((function(e,t){return e.distance>t.distance?-1:e.distance=o&&p(u[0].target))return C(u[0]),u[0];for(var r=0,a=u.length;re.length)break e;if(!(v instanceof a)){u.lastIndex=0;var b=u.exec(v),k=1;if(!b&&h&&m!=r.length-1){if(u.lastIndex=y,b=u.exec(e),!b)break;for(var w=b.index+(c?b[1].length:0),_=b.index+b[0].length,P=m,A=y,j=r.length;j>P&&_>A;++P)A+=r[P].length,w>=A&&(++m,y=A);if(r[m]instanceof a||r[P-1].greedy)continue;k=P-m,v=e.slice(y,A),b.index-=y}if(b){c&&(f=b[1].length);var w=b.index+f,b=b[0].slice(f),_=w+b.length,x=v.slice(0,w),O=v.slice(_),S=[m,k];x&&S.push(x);var N=new a(i,g?n.tokenize(b,g):b,d,b,h);S.push(N),O&&S.push(O),Array.prototype.splice.apply(r,S)}}}}}return r},hooks:{all:{},add:function(e,t){var a=n.hooks.all;a[e]=a[e]||[],a[e].push(t)},run:function(e,t){var a=n.hooks.all[e];if(a&&a.length)for(var r,l=0;r=a[l++];)r(t)}}},a=n.Token=function(e,t,n,a,r){this.type=e,this.content=t,this.alias=n,this.length=0|(a||"").length,this.greedy=!!r};if(a.stringify=function(e,t,r){if("string"==typeof e)return e;if("Array"===n.util.type(e))return e.map(function(n){return a.stringify(n,t,e)}).join("");var l={type:e.type,content:a.stringify(e.content,t,r),tag:"span",classes:["token",e.type],attributes:{},language:t,parent:r};if("comment"==l.type&&(l.attributes.spellcheck="true"),e.alias){var i="Array"===n.util.type(e.alias)?e.alias:[e.alias];Array.prototype.push.apply(l.classes,i)}n.hooks.run("wrap",l);var o=Object.keys(l.attributes).map(function(e){return e+'="'+(l.attributes[e]||"").replace(/"/g,""")+'"'}).join(" ");return"<"+l.tag+' class="'+l.classes.join(" ")+'"'+(o?" "+o:"")+">"+l.content+""},!_self.document)return _self.addEventListener?(_self.addEventListener("message",function(e){var t=JSON.parse(e.data),a=t.language,r=t.code,l=t.immediateClose;_self.postMessage(n.highlight(r,n.languages[a],a)),l&&_self.close()},!1),_self.Prism):_self.Prism;var r=document.currentScript||[].slice.call(document.getElementsByTagName("script")).pop();return r&&(n.filename=r.src,!document.addEventListener||n.manual||r.hasAttribute("data-manual")||("loading"!==document.readyState?window.requestAnimationFrame?window.requestAnimationFrame(n.highlightAll):window.setTimeout(n.highlightAll,16):document.addEventListener("DOMContentLoaded",n.highlightAll))),_self.Prism}();"undefined"!=typeof module&&module.exports&&(module.exports=Prism),"undefined"!=typeof global&&(global.Prism=Prism); +Prism.languages.markup={comment://,prolog:/<\?[\w\W]+?\?>/,doctype://i,cdata://i,tag:{pattern:/<\/?(?!\d)[^\s>\/=$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\w\W])*\1|[^\s'">=]+))?)*\s*\/?>/i,inside:{tag:{pattern:/^<\/?[^\s>\/]+/i,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"attr-value":{pattern:/=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,inside:{punctuation:/[=>"']/}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:/&#?[\da-z]{1,8};/i},Prism.hooks.add("wrap",function(a){"entity"===a.type&&(a.attributes.title=a.content.replace(/&/,"&"))}),Prism.languages.xml=Prism.languages.markup,Prism.languages.html=Prism.languages.markup,Prism.languages.mathml=Prism.languages.markup,Prism.languages.svg=Prism.languages.markup; +Prism.languages.css={comment:/\/\*[\w\W]*?\*\//,atrule:{pattern:/@[\w-]+?.*?(;|(?=\s*\{))/i,inside:{rule:/@[\w-]+/}},url:/url\((?:(["'])(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,selector:/[^\{\}\s][^\{\};]*?(?=\s*\{)/,string:{pattern:/("|')(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1/,greedy:!0},property:/(\b|\B)[\w-]+(?=\s*:)/i,important:/\B!important\b/i,"function":/[-a-z0-9]+(?=\()/i,punctuation:/[(){};:]/},Prism.languages.css.atrule.inside.rest=Prism.util.clone(Prism.languages.css),Prism.languages.markup&&(Prism.languages.insertBefore("markup","tag",{style:{pattern:/()[\w\W]*?(?=<\/style>)/i,lookbehind:!0,inside:Prism.languages.css,alias:"language-css"}}),Prism.languages.insertBefore("inside","attr-value",{"style-attr":{pattern:/\s*style=("|').*?\1/i,inside:{"attr-name":{pattern:/^\s*style/i,inside:Prism.languages.markup.tag.inside},punctuation:/^\s*=\s*['"]|['"]\s*$/,"attr-value":{pattern:/.+/i,inside:Prism.languages.css}},alias:"language-css"}},Prism.languages.markup.tag)); +Prism.languages.clike={comment:[{pattern:/(^|[^\\])\/\*[\w\W]*?\*\//,lookbehind:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0}],string:{pattern:/(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},"class-name":{pattern:/((?:\b(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,lookbehind:!0,inside:{punctuation:/(\.|\\)/}},keyword:/\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,"boolean":/\b(true|false)\b/,"function":/[a-z0-9_]+(?=\()/i,number:/\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i,operator:/--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/,punctuation:/[{}[\];(),.:]/}; +Prism.languages.javascript=Prism.languages.extend("clike",{keyword:/\b(as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|var|void|while|with|yield)\b/,number:/\b-?(0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|Infinity)\b/,"function":/[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*(?=\()/i,operator:/--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*\*?|\/|~|\^|%|\.{3}/}),Prism.languages.insertBefore("javascript","keyword",{regex:{pattern:/(^|[^\/])\/(?!\/)(\[.+?]|\\.|[^\/\\\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,lookbehind:!0,greedy:!0}}),Prism.languages.insertBefore("javascript","string",{"template-string":{pattern:/`(?:\\\\|\\?[^\\])*?`/,greedy:!0,inside:{interpolation:{pattern:/\$\{[^}]+\}/,inside:{"interpolation-punctuation":{pattern:/^\$\{|\}$/,alias:"punctuation"},rest:Prism.languages.javascript}},string:/[\s\S]+/}}}),Prism.languages.markup&&Prism.languages.insertBefore("markup","tag",{script:{pattern:/()[\w\W]*?(?=<\/script>)/i,lookbehind:!0,inside:Prism.languages.javascript,alias:"language-javascript"}}),Prism.languages.js=Prism.languages.javascript; +!function(e){var t={variable:[{pattern:/\$?\(\([\w\W]+?\)\)/,inside:{variable:[{pattern:/(^\$\(\([\w\W]+)\)\)/,lookbehind:!0},/^\$\(\(/],number:/\b-?(?:0x[\dA-Fa-f]+|\d*\.?\d+(?:[Ee]-?\d+)?)\b/,operator:/--?|-=|\+\+?|\+=|!=?|~|\*\*?|\*=|\/=?|%=?|<<=?|>>=?|<=?|>=?|==?|&&?|&=|\^=?|\|\|?|\|=|\?|:/,punctuation:/\(\(?|\)\)?|,|;/}},{pattern:/\$\([^)]+\)|`[^`]+`/,inside:{variable:/^\$\(|^`|\)$|`$/}},/\$(?:[a-z0-9_#\?\*!@]+|\{[^}]+\})/i]};e.languages.bash={shebang:{pattern:/^#!\s*\/bin\/bash|^#!\s*\/bin\/sh/,alias:"important"},comment:{pattern:/(^|[^"{\\])#.*/,lookbehind:!0},string:[{pattern:/((?:^|[^<])<<\s*)(?:"|')?(\w+?)(?:"|')?\s*\r?\n(?:[\s\S])*?\r?\n\2/g,lookbehind:!0,greedy:!0,inside:t},{pattern:/(["'])(?:\\\\|\\?[^\\])*?\1/g,greedy:!0,inside:t}],variable:t.variable,"function":{pattern:/(^|\s|;|\||&)(?:alias|apropos|apt-get|aptitude|aspell|awk|basename|bash|bc|bg|builtin|bzip2|cal|cat|cd|cfdisk|chgrp|chmod|chown|chroot|chkconfig|cksum|clear|cmp|comm|command|cp|cron|crontab|csplit|cut|date|dc|dd|ddrescue|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|du|egrep|eject|enable|env|ethtool|eval|exec|expand|expect|export|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|getopts|git|grep|groupadd|groupdel|groupmod|groups|gzip|hash|head|help|hg|history|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|jobs|join|kill|killall|less|link|ln|locate|logname|logout|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|make|man|mkdir|mkfifo|mkisofs|mknod|more|most|mount|mtools|mtr|mv|mmv|nano|netstat|nice|nl|nohup|notify-send|npm|nslookup|open|op|passwd|paste|pathchk|ping|pkill|popd|pr|printcap|printenv|printf|ps|pushd|pv|pwd|quota|quotacheck|quotactl|ram|rar|rcp|read|readarray|readonly|reboot|rename|renice|remsync|rev|rm|rmdir|rsync|screen|scp|sdiff|sed|seq|service|sftp|shift|shopt|shutdown|sleep|slocate|sort|source|split|ssh|stat|strace|su|sudo|sum|suspend|sync|tail|tar|tee|test|time|timeout|times|touch|top|traceroute|trap|tr|tsort|tty|type|ulimit|umask|umount|unalias|uname|unexpand|uniq|units|unrar|unshar|uptime|useradd|userdel|usermod|users|uuencode|uudecode|v|vdir|vi|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yes|zip)(?=$|\s|;|\||&)/,lookbehind:!0},keyword:{pattern:/(^|\s|;|\||&)(?:let|:|\.|if|then|else|elif|fi|for|break|continue|while|in|case|function|select|do|done|until|echo|exit|return|set|declare)(?=$|\s|;|\||&)/,lookbehind:!0},"boolean":{pattern:/(^|\s|;|\||&)(?:true|false)(?=$|\s|;|\||&)/,lookbehind:!0},operator:/&&?|\|\|?|==?|!=?|<<>|<=?|>=?|=~/,punctuation:/\$?\(\(?|\)\)?|\.\.|[{}[\];]/};var a=t.variable[1].inside;a["function"]=e.languages.bash["function"],a.keyword=e.languages.bash.keyword,a.boolean=e.languages.bash.boolean,a.operator=e.languages.bash.operator,a.punctuation=e.languages.bash.punctuation}(Prism); +!function(e){e.languages.ruby=e.languages.extend("clike",{comment:/#(?!\{[^\r\n]*?\}).*/,keyword:/\b(alias|and|BEGIN|begin|break|case|class|def|define_method|defined|do|each|else|elsif|END|end|ensure|false|for|if|in|module|new|next|nil|not|or|raise|redo|require|rescue|retry|return|self|super|then|throw|true|undef|unless|until|when|while|yield)\b/});var n={pattern:/#\{[^}]+\}/,inside:{delimiter:{pattern:/^#\{|\}$/,alias:"tag"},rest:e.util.clone(e.languages.ruby)}};e.languages.insertBefore("ruby","keyword",{regex:[{pattern:/%r([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1[gim]{0,3}/,greedy:!0,inside:{interpolation:n}},{pattern:/%r\((?:[^()\\]|\\[\s\S])*\)[gim]{0,3}/,greedy:!0,inside:{interpolation:n}},{pattern:/%r\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}[gim]{0,3}/,greedy:!0,inside:{interpolation:n}},{pattern:/%r\[(?:[^\[\]\\]|\\[\s\S])*\][gim]{0,3}/,greedy:!0,inside:{interpolation:n}},{pattern:/%r<(?:[^<>\\]|\\[\s\S])*>[gim]{0,3}/,greedy:!0,inside:{interpolation:n}},{pattern:/(^|[^\/])\/(?!\/)(\[.+?]|\\.|[^\/\\\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/,lookbehind:!0,greedy:!0}],variable:/[@$]+[a-zA-Z_][a-zA-Z_0-9]*(?:[?!]|\b)/,symbol:/:[a-zA-Z_][a-zA-Z_0-9]*(?:[?!]|\b)/}),e.languages.insertBefore("ruby","number",{builtin:/\b(Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Stat|File|Fixnum|Float|Hash|Integer|IO|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|String|Struct|TMS|Symbol|ThreadGroup|Thread|Time|TrueClass)\b/,constant:/\b[A-Z][a-zA-Z_0-9]*(?:[?!]|\b)/}),e.languages.ruby.string=[{pattern:/%[qQiIwWxs]?([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1/,greedy:!0,inside:{interpolation:n}},{pattern:/%[qQiIwWxs]?\((?:[^()\\]|\\[\s\S])*\)/,greedy:!0,inside:{interpolation:n}},{pattern:/%[qQiIwWxs]?\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/,greedy:!0,inside:{interpolation:n}},{pattern:/%[qQiIwWxs]?\[(?:[^\[\]\\]|\\[\s\S])*\]/,greedy:!0,inside:{interpolation:n}},{pattern:/%[qQiIwWxs]?<(?:[^<>\\]|\\[\s\S])*>/,greedy:!0,inside:{interpolation:n}},{pattern:/("|')(#\{[^}]+\}|\\(?:\r?\n|\r)|\\?.)*?\1/,greedy:!0,inside:{interpolation:n}}]}(Prism); +Prism.languages.java=Prism.languages.extend("clike",{keyword:/\b(abstract|continue|for|new|switch|assert|default|goto|package|synchronized|boolean|do|if|private|this|break|double|implements|protected|throw|byte|else|import|public|throws|case|enum|instanceof|return|transient|catch|extends|int|short|try|char|final|interface|static|void|class|finally|long|strictfp|volatile|const|float|native|super|while)\b/,number:/\b0b[01]+\b|\b0x[\da-f]*\.?[\da-fp\-]+\b|\b\d*\.?\d+(?:e[+-]?\d+)?[df]?\b/i,operator:{pattern:/(^|[^.])(?:\+[+=]?|-[-=]?|!=?|<>?>?=?|==?|&[&=]?|\|[|=]?|\*=?|\/=?|%=?|\^=?|[?:~])/m,lookbehind:!0}}),Prism.languages.insertBefore("java","function",{annotation:{alias:"punctuation",pattern:/(^|[^.])@\w+/,lookbehind:!0}}); +!function(n){n.languages.kotlin=n.languages.extend("clike",{keyword:{pattern:/(^|[^.])\b(?:abstract|annotation|as|break|by|catch|class|companion|const|constructor|continue|crossinline|data|do|else|enum|final|finally|for|fun|get|if|import|in|init|inline|inner|interface|internal|is|lateinit|noinline|null|object|open|out|override|package|private|protected|public|reified|return|sealed|set|super|tailrec|this|throw|to|try|val|var|when|where|while)\b/,lookbehind:!0},"function":[/\w+(?=\s*\()/,{pattern:/(\.)\w+(?=\s*\{)/,lookbehind:!0}],number:/\b(?:0[bx][\da-fA-F]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?[fFL]?)\b/,operator:/\+[+=]?|-[-=>]?|==?=?|!(?:!|==?)?|[\/*%<>]=?|[?:]:?|\.\.|&&|\|\||\b(?:and|inv|or|shl|shr|ushr|xor)\b/}),delete n.languages.kotlin["class-name"],n.languages.insertBefore("kotlin","string",{"raw-string":{pattern:/(["'])\1\1[\s\S]*?\1{3}/,alias:"string"}}),n.languages.insertBefore("kotlin","keyword",{annotation:{pattern:/\B@(?:\w+:)?(?:[A-Z]\w*|\[[^\]]+\])/,alias:"builtin"}}),n.languages.insertBefore("kotlin","function",{label:{pattern:/\w+@|@\w+/,alias:"symbol"}});var e=[{pattern:/\$\{[^}]+\}/,inside:{delimiter:{pattern:/^\$\{|\}$/,alias:"variable"},rest:n.util.clone(n.languages.kotlin)}},{pattern:/\$\w+/,alias:"variable"}];n.languages.kotlin.string.inside=n.languages.kotlin["raw-string"].inside={interpolation:e}}(Prism); +Prism.languages.sql={comment:{pattern:/(^|[^\\])(?:\/\*[\w\W]*?\*\/|(?:--|\/\/|#).*)/,lookbehind:!0},string:{pattern:/(^|[^@\\])("|')(?:\\?[\s\S])*?\2/,greedy:!0,lookbehind:!0},variable:/@[\w.$]+|@("|'|`)(?:\\?[\s\S])+?\1/,"function":/\b(?:COUNT|SUM|AVG|MIN|MAX|FIRST|LAST|UCASE|LCASE|MID|LEN|ROUND|NOW|FORMAT)(?=\s*\()/i,keyword:/\b(?:ACTION|ADD|AFTER|ALGORITHM|ALL|ALTER|ANALYZE|ANY|APPLY|AS|ASC|AUTHORIZATION|AUTO_INCREMENT|BACKUP|BDB|BEGIN|BERKELEYDB|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|BREAK|BROWSE|BTREE|BULK|BY|CALL|CASCADED?|CASE|CHAIN|CHAR VARYING|CHARACTER (?:SET|VARYING)|CHARSET|CHECK|CHECKPOINT|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMN|COLUMNS|COMMENT|COMMIT|COMMITTED|COMPUTE|CONNECT|CONSISTENT|CONSTRAINT|CONTAINS|CONTAINSTABLE|CONTINUE|CONVERT|CREATE|CROSS|CURRENT(?:_DATE|_TIME|_TIMESTAMP|_USER)?|CURSOR|DATA(?:BASES?)?|DATE(?:TIME)?|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFINER|DELAYED|DELETE|DELIMITER(?:S)?|DENY|DESC|DESCRIBE|DETERMINISTIC|DISABLE|DISCARD|DISK|DISTINCT|DISTINCTROW|DISTRIBUTED|DO|DOUBLE(?: PRECISION)?|DROP|DUMMY|DUMP(?:FILE)?|DUPLICATE KEY|ELSE|ENABLE|ENCLOSED BY|END|ENGINE|ENUM|ERRLVL|ERRORS|ESCAPE(?:D BY)?|EXCEPT|EXEC(?:UTE)?|EXISTS|EXIT|EXPLAIN|EXTENDED|FETCH|FIELDS|FILE|FILLFACTOR|FIRST|FIXED|FLOAT|FOLLOWING|FOR(?: EACH ROW)?|FORCE|FOREIGN|FREETEXT(?:TABLE)?|FROM|FULL|FUNCTION|GEOMETRY(?:COLLECTION)?|GLOBAL|GOTO|GRANT|GROUP|HANDLER|HASH|HAVING|HOLDLOCK|IDENTITY(?:_INSERT|COL)?|IF|IGNORE|IMPORT|INDEX|INFILE|INNER|INNODB|INOUT|INSERT|INT|INTEGER|INTERSECT|INTO|INVOKER|ISOLATION LEVEL|JOIN|KEYS?|KILL|LANGUAGE SQL|LAST|LEFT|LIMIT|LINENO|LINES|LINESTRING|LOAD|LOCAL|LOCK|LONG(?:BLOB|TEXT)|MATCH(?:ED)?|MEDIUM(?:BLOB|INT|TEXT)|MERGE|MIDDLEINT|MODIFIES SQL DATA|MODIFY|MULTI(?:LINESTRING|POINT|POLYGON)|NATIONAL(?: CHAR VARYING| CHARACTER(?: VARYING)?| VARCHAR)?|NATURAL|NCHAR(?: VARCHAR)?|NEXT|NO(?: SQL|CHECK|CYCLE)?|NONCLUSTERED|NULLIF|NUMERIC|OFF?|OFFSETS?|ON|OPEN(?:DATASOURCE|QUERY|ROWSET)?|OPTIMIZE|OPTION(?:ALLY)?|ORDER|OUT(?:ER|FILE)?|OVER|PARTIAL|PARTITION|PERCENT|PIVOT|PLAN|POINT|POLYGON|PRECEDING|PRECISION|PREV|PRIMARY|PRINT|PRIVILEGES|PROC(?:EDURE)?|PUBLIC|PURGE|QUICK|RAISERROR|READ(?:S SQL DATA|TEXT)?|REAL|RECONFIGURE|REFERENCES|RELEASE|RENAME|REPEATABLE|REPLICATION|REQUIRE|RESTORE|RESTRICT|RETURNS?|REVOKE|RIGHT|ROLLBACK|ROUTINE|ROW(?:COUNT|GUIDCOL|S)?|RTREE|RULE|SAVE(?:POINT)?|SCHEMA|SELECT|SERIAL(?:IZABLE)?|SESSION(?:_USER)?|SET(?:USER)?|SHARE MODE|SHOW|SHUTDOWN|SIMPLE|SMALLINT|SNAPSHOT|SOME|SONAME|START(?:ING BY)?|STATISTICS|STATUS|STRIPED|SYSTEM_USER|TABLES?|TABLESPACE|TEMP(?:ORARY|TABLE)?|TERMINATED BY|TEXT(?:SIZE)?|THEN|TIMESTAMP|TINY(?:BLOB|INT|TEXT)|TOP?|TRAN(?:SACTIONS?)?|TRIGGER|TRUNCATE|TSEQUAL|TYPES?|UNBOUNDED|UNCOMMITTED|UNDEFINED|UNION|UNIQUE|UNPIVOT|UPDATE(?:TEXT)?|USAGE|USE|USER|USING|VALUES?|VAR(?:BINARY|CHAR|CHARACTER|YING)|VIEW|WAITFOR|WARNINGS|WHEN|WHERE|WHILE|WITH(?: ROLLUP|IN)?|WORK|WRITE(?:TEXT)?)\b/i,"boolean":/\b(?:TRUE|FALSE|NULL)\b/i,number:/\b-?(?:0x)?\d*\.?[\da-f]+\b/,operator:/[-+*\/=%^~]|&&?|\|?\||!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|IN|LIKE|NOT|OR|IS|DIV|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,punctuation:/[;[\]()`,.]/}; +!function(){if("undefined"!=typeof self&&self.Prism&&self.document){var t=[],e={},n=function(){};Prism.plugins.toolbar={};var a=Prism.plugins.toolbar.registerButton=function(n,a){var o;o="function"==typeof a?a:function(t){var e;return"function"==typeof a.onClick?(e=document.createElement("button"),e.type="button",e.addEventListener("click",function(){a.onClick.call(this,t)})):"string"==typeof a.url?(e=document.createElement("a"),e.href=a.url):e=document.createElement("span"),e.textContent=a.text,e},t.push(e[n]=o)},o=Prism.plugins.toolbar.hook=function(a){var o=a.element.parentNode;if(o&&/pre/i.test(o.nodeName)&&!o.classList.contains("code-toolbar")){o.classList.add("code-toolbar");var r=document.createElement("div");r.classList.add("toolbar"),document.body.hasAttribute("data-toolbar-order")&&(t=document.body.getAttribute("data-toolbar-order").split(",").map(function(t){return e[t]||n})),t.forEach(function(t){var e=t(a);if(e){var n=document.createElement("div");n.classList.add("toolbar-item"),n.appendChild(e),r.appendChild(n)}}),o.appendChild(r)}};a("label",function(t){var e=t.element.parentNode;if(e&&/pre/i.test(e.nodeName)&&e.hasAttribute("data-label")){var n,a,o=e.getAttribute("data-label");try{a=document.querySelector("template#"+o)}catch(r){}return a?n=a.content:(e.hasAttribute("data-url")?(n=document.createElement("a"),n.href=e.getAttribute("data-url")):n=document.createElement("span"),n.textContent=o),n}}),Prism.hooks.add("complete",o)}}(); +!function(){if("undefined"!=typeof self&&self.Prism&&self.document){if(!Prism.plugins.toolbar)return console.warn("Copy to Clipboard plugin loaded before Toolbar plugin."),void 0;var o=window.Clipboard||void 0;o||"function"!=typeof require||(o=require("clipboard"));var e=[];if(!o){var t=document.createElement("script"),n=document.querySelector("head");t.onload=function(){if(o=window.Clipboard)for(;e.length;)e.pop()()},t.src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.5.8/clipboard.min.js",n.appendChild(t)}Prism.plugins.toolbar.registerButton("copy-to-clipboard",function(t){function n(){var e=new o(i,{text:function(){return t.code}});e.on("success",function(){i.textContent="Copied!",r()}),e.on("error",function(){i.textContent="Press Ctrl+C to copy",r()})}function r(){setTimeout(function(){i.textContent="Copy"},5e3)}var i=document.createElement("a");return i.textContent="Copy",o?n():e.push(n),i})}}(); diff --git a/docs/js/_partials/vendor/smoothscroll.min.js b/docs/js/_partials/vendor/smoothscroll.min.js new file mode 100644 index 000000000..037825077 --- /dev/null +++ b/docs/js/_partials/vendor/smoothscroll.min.js @@ -0,0 +1,3 @@ +// https://github.com/cferdinandi/smooth-scroll +/*! smooth-scroll v10.2.1 | (c) 2016 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */ +!(function(e,t){"function"==typeof define&&define.amd?define([],t(e)):"object"==typeof exports?module.exports=t(e):e.smoothScroll=t(e)})("undefined"!=typeof global?global:this.window||this.global,(function(e){"use strict";var t,n,o,r,a,c,l,i={},u="querySelector"in document&&"addEventListener"in e,s={selector:"[data-scroll]",selectorHeader:null,speed:500,easing:"easeInOutCubic",offset:0,callback:function(){}},d=function(){var e={},t=!1,n=0,o=arguments.length;"[object Boolean]"===Object.prototype.toString.call(arguments[0])&&(t=arguments[0],n++);for(var r=function(n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t&&"[object Object]"===Object.prototype.toString.call(n[o])?e[o]=d(!0,e[o],n[o]):e[o]=n[o])};n=0&&t.item(n)!==this;);return n>-1});e&&e!==document;e=e.parentNode)if(e.matches(t))return e;return null},m=function(e){"#"===e.charAt(0)&&(e=e.substr(1));for(var t,n=String(e),o=n.length,r=-1,a="",c=n.charCodeAt(0);++r=1&&t<=31||127==t||0===r&&t>=48&&t<=57||1===r&&t>=48&&t<=57&&45===c?"\\"+t.toString(16)+" ":t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(r):"\\"+n.charAt(r)}return"#"+a},p=function(e,t){var n;return"easeInQuad"===e&&(n=t*t),"easeOutQuad"===e&&(n=t*(2-t)),"easeInOutQuad"===e&&(n=t<.5?2*t*t:-1+(4-2*t)*t),"easeInCubic"===e&&(n=t*t*t),"easeOutCubic"===e&&(n=--t*t*t+1),"easeInOutCubic"===e&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e&&(n=t*t*t*t),"easeOutQuart"===e&&(n=1- --t*t*t*t),"easeInOutQuart"===e&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e&&(n=t*t*t*t*t),"easeOutQuint"===e&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),n||t},g=function(e,t,n){var o=0;if(e.offsetParent)do o+=e.offsetTop,e=e.offsetParent;while(e);return o=Math.max(o-t-n,0),Math.min(o,v()-b())},b=function(){return Math.max(document.documentElement.clientHeight,e.innerHeight||0)},v=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},y=function(e){return e&&"object"==typeof JSON&&"function"==typeof JSON.parse?JSON.parse(e):{}},O=function(e){return e?f(e)+e.offsetTop:0},S=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))};i.animateScroll=function(n,o,c){var i=y(o?o.getAttribute("data-options"):null),u=d(t||s,c||{},i),f="[object Number]"===Object.prototype.toString.call(n),h=f||!n.tagName?null:n;if(f||h){var m=e.pageYOffset;u.selectorHeader&&!r&&(r=document.querySelector(u.selectorHeader)),a||(a=O(r));var b,E,I=f?n:g(h,a,parseInt(u.offset,10)),H=I-m,A=v(),j=0,C=function(t,r,a){var c=e.pageYOffset;(t==r||c==r||e.innerHeight+c>=A)&&(clearInterval(a),S(n,r,f),u.callback(n,o))},M=function(){j+=16,b=j/parseInt(u.speed,10),b=b>1?1:b,E=m+H*p(u.easing,b),e.scrollTo(0,Math.floor(E)),C(E,I,l)},w=function(){clearInterval(l),l=setInterval(M,16)};0===e.pageYOffset&&e.scrollTo(0,0),w()}};var E=function(t){var r;try{r=m(decodeURIComponent(e.location.hash))}catch(t){r=m(e.location.hash)}n&&(n.id=n.getAttribute("data-scroll-id"),i.animateScroll(n,o),n=null,o=null)},I=function(r){if(0===r.button&&!r.metaKey&&!r.ctrlKey&&(o=h(r.target,t.selector),o&&"a"===o.tagName.toLowerCase()&&o.hostname===e.location.hostname&&o.pathname===e.location.pathname&&/#/.test(o.href))){var a;try{a=m(decodeURIComponent(o.hash))}catch(e){a=m(o.hash)}if("#"===a){r.preventDefault(),n=document.body;var c=n.id?n.id:"smooth-scroll-top";return n.setAttribute("data-scroll-id",c),n.id="",void(e.location.hash.substring(1)===c?E():e.location.hash=c)}n=document.querySelector(a),n&&(n.setAttribute("data-scroll-id",n.id),n.id="",o.hash===e.location.hash&&(r.preventDefault(),E()))}},H=function(e){c||(c=setTimeout((function(){c=null,a=O(r)}),66))};return i.destroy=function(){t&&(document.removeEventListener("click",I,!1),e.removeEventListener("resize",H,!1),t=null,n=null,o=null,r=null,a=null,c=null,l=null)},i.init=function(n){u&&(i.destroy(),t=d(s,n||{}),r=t.selectorHeader?document.querySelector(t.selectorHeader):null,a=O(r),document.addEventListener("click",I,!1),e.addEventListener("hashchange",E,!1),r&&e.addEventListener("resize",H,!1))},i})); diff --git a/docs/js/scripts.js b/docs/js/scripts.js new file mode 100644 index 000000000..28c82cd03 --- /dev/null +++ b/docs/js/scripts.js @@ -0,0 +1,9 @@ +--- +--- + +{% include_relative _partials/vendor/clipboard.min.js %} +{% include_relative _partials/vendor/prism.min.js %} +{% include_relative _partials/vendor/smoothscroll.min.js %} +{% include_relative _partials/vendor/gumshoe.min.js %} +{% include_relative _partials/tutorials.js %} +{% include_relative _partials/main.js %} diff --git a/docs/pages/index.md b/docs/pages/index.md new file mode 100644 index 000000000..5a0e6835d --- /dev/null +++ b/docs/pages/index.md @@ -0,0 +1,293 @@ +--- +layout: default +title: Documentation +rightmenu: true +--- + +
+* [Features](#features) +* [Creating Request](#creating-request) +
+ +[![Build Status](https://travis-ci.org/Kong/unirest-java.svg?branch=master)](https://travis-ci.org/Kong/unirest-java) +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.konghq/unirest-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.kong/unirest-java) +[![Javadocs](http://www.javadoc.io/badge/com.konghq/unirest-java.svg)](http://www.javadoc.io/doc/com.konghq/unirest-java) +[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/Kong/unirest-java) + + +## Install With [Maven](https://mvnrepository.com/artifact/com.konghq/unirest-java)[:](https://repo.maven.apache.org/maven2/com/konghq/unirest-java/) +```xml + + com.konghq + unirest-java + 2.3.02 + +``` + +### Upgrading from Previous Versions +See the [Upgrade Guide](UPGRADE_GUIDE.md) + +## Features + +* Make `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `HEAD`, `OPTIONS` requests +* Both synchronous and asynchronous (non-blocking) requests +* It supports form parameters, file uploads and custom body entities +* Easily add route parameters without ugly string concatenations +* Supports gzip +* Supports Basic Authentication natively +* Customizable timeout, concurrency levels and proxy settings +* Customizable default headers for every request (DRY) +* Automatic JSON parsing into a native object for JSON responses +* Customizable binding, with mapping from response body to java Object + + +## Creating Request +So you're probably wondering how using Unirest makes creating requests in Java easier, here is a basic POST request that will explain everything: + +```java +HttpResponse response = Unirest.post("http://httpbin.org/post") + .header("accept", "application/json") + .queryString("apiKey", "123") + .field("parameter", "value") + .field("foo", "bar") + .asJson(); +``` + +Requests are made when `as[Type]()` is invoked, possible types include `Json`, `String`, `Object` `Empty` and `File`. + + +### Route Parameters +Sometimes you want to add dynamic parameters in the URL, you can easily do that by adding a placeholder in the URL, and then by setting the route parameters with the `routeParam` function, like: + +```java +Unirest.get("http://httpbin.org/{method}") + .routeParam("method", "get") + .asJson(); +``` +In the example above the final URL will be `http://httpbin.org/get` - Basically the placeholder `{method}` will be replaced with `get`. + +The placeholder's format is as easy as: `{custom_name}` + +### Advanced Object Mapping with Jackson, GSON, JAX-B or others +Before an `asObject(Class)` or a `.body(Object)` invocation, is necessary to provide a custom implementation of the `ObjectMapper` interface. +This should be done only the first time, as the instance of the ObjectMapper will be shared globally. +Unirest offers a few plug-ins implementing popular object mappers like Jackson and Gson. See [mvn central](https://mvnrepository.com/artifact/com.konghq) for details. +nes of code. +For example, serializing Json from\to Object using the popular Jackson ObjectMapper takes only few li + +```java +// Only one time +Unirest.config().setObjectMapper(new JacksonObjectMapper()); + +// Response to Object +Book book = Unirest.get("http://httpbin.org/books/1") + .asObject(Book.class) + .getBody(); + +Author author = Unirest.get("http://httpbin.org/books/{id}/author") + .routeParam("id", bookObject.getId()) + .asObject(Author.class) + .getBody(); + +// Sending a JSON object +Unirest.post("http://httpbin.org/authors/post") + .header("accept", "application/json") + .header("Content-Type", "application/json") + .body(author) + .asJson(); +``` + +#### Errors in Object or JSON parsing +You can't always get what you want. And sometimes results you get from web services will not map into what you expect them to. +When this happens with a ```asObject``` or ```asJson``` request the resulting body will be null, but the response object will contain a ParsingException that allows you to get the error and the original body for inspection. + +```java +UnirestParsingException ex = response.getParsingError().get(); + +ex.getOriginalBody(); // Has the original body as a string. +ex.getMessage(); // Will have the parsing exception. +ex.getCause(); // of course will have the original parsing exception itself. +``` + +#### Asynchronous Requests +Sometimes, well most of the time, you want your application to be asynchronous and not block, Unirest supports this in Java using anonymous callbacks, or direct method placement: + +```java +CompletableFuture> future = Unirest.post("http://httpbin.org/post") + .header("accept", "application/json") + .field("param1", "value1") + .field("param2", "value2") + .asJsonAsync(response -> { + int code = response.getStatus(); + JsonNode body = response.getBody(); + }); +``` + +#### Custom mappings and handling large responses +Most response methods (```asString```, ```asJson```, and even ```asBinary```) read the entire +response stream into memory. In order to read the original stream and handle large responses you +can use several functional methods like: + +```java + Map r = Unirest.get(MockServer.GET) + .queryString("foo", "bar") + .asObject(i -> new Gson().fromJson(i.getContentReader(), HashMap.class)) + .getBody(); + +``` + +or consumers: + +```java + + Unirest.get(MockServer.GET) + .thenConsumeAsync(r -> { + // something like writing a file to disk + }); +``` + +#### File Uploads +Creating `multipart` requests with Java is trivial, simply pass along a `File` or an InputStream Object as a field: + +```java +HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") + .header("accept", "application/json") + .field("parameter", "value") + .field("file", new File("/tmp/file")) + .asJson(); +``` + +#### Custom Entity Body + +```java +HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") + .header("accept", "application/json") + .body("{\"parameter\":\"value\", \"foo\":\"bar\"}") + .asJson(); +``` + +#### JSON Patch Requests +Unirest has full native support for JSON Patch requests +```java + Unirest.jsonPatch(MockServer.PATCH) + .add("/fruits/-", "Apple") + .remove("/bugs") + .replace("/lastname", "Flintstone") + .test("/firstname", "Fred") + .move("/old/location", "/new/location") + .copy("/original/location", "/new/location") + .asJson(); +``` +will send a request with a body of +```json + [ + {"op":"add","path":"/fruits/-","value":"Apple"}, + {"op":"remove","path":"/bugs"}, + {"op":"replace","path":"/lastname","value":"Flintstone"}, + {"op":"test","path":"/firstname","value":"Fred"}, + {"op":"move","path":"/new/location","from":"/old/location"}, + {"op":"copy","path":"/new/location","from":"/original/location"} + ] + +``` + +#### Basic Authentication +Authenticating the request with basic authentication can be done by calling the `basicAuth(username, password)` function: +```java + Unirest.get("http://httpbin.org/headers") + .basicAuth("username", "password") + .asJson(); +``` + +# Configuration +Previous versions of unirest had configuration split across several different places. Sometimes it was done on ```Unirest```, sometimes it was done on ```Option```, sometimes it was somewhere else. +All configuration is now done through ```Unirest.config()``` + +#### Unirest.config() +Unirest config allows easy access to build a configuration just like you would build a request: + +```java + Unirest.config() + .socketTimeout(500) + .connectTimeout(1000) + .concurrency(10, 5) + .proxy(new Proxy("https://proxy")) + .setDefaultHeader("Accept", "application/json") + .followRedirects(false) + .enableCookieManagement(false) + .addInterceptor(new MyCustomInterceptor()); +``` + +#### Config Options + +| Builder Method | Impact | Default | +| ------------- | ------------- | ------------- | +| ```socketTimeout(int)``` | Sets the socket timeout for all requests in millis | 60000 | +| ```connectTimeout(int)``` | Sets the connection timeout for all requests in millis | 10000 | +| ```concurrency(int, int)``` | Sets concurrency rates; max total, max per route | 200, 20 | +| ```proxy(proxy)``` | Sets a proxy object for negotiating proxy servers. Can include auth credentials | | +| ```setDefaultHeader(String, String)``` | Sets a default header. Will overwrite if it exists | | +| ```setDefaultHeader(String, Supplier)``` | Sets a default header by supplier. Good for setting trace tokens for microservice architectures. Will overwrite if it exists | | +| ```addDefaultHeader(String, String)``` | Adds a default header. Multiple for the same name can exist | | +| ```addDefaultHeader(String, Supplier)``` | Add a default header by supplier. Good for setting trace tokens for microservice architectures. | | +| ```setDefaultBasicAuth(String, String)``` | Add a default Basic Auth Header | | +| ```followRedirects(boolean)``` | toggle following redirects | true | +| ```enableCookieManagement(boolean)``` | toggle accepting and storing cookies | true | +| ```cookieSpec(String)``` | set a cookie policy. Acceptable values: 'default' (same as Netscape), 'netscape', 'ignoreCookies', 'standard' (RFC 6265 interoprability profile) , 'standard-strict' (RFC 6265 strict profile) | default | +| ```automaticRetries(boolean)``` | toggle disabling automatic retries (up to 4 times) for socket timeouts | true | +| ```verifySsl(boolean)``` |toggle enforcing SSL | true | +| ```addShutdownHook(boolean)``` | toggle to add the clients to the system shutdown hooks automatically | false | +| ```clientCertificateStore(String,String)``` | Add a PKCS12 KeyStore by path for doing client certificates | | +| ```clientCertificateStore(KeyStore,String)``` | Add a PKCS12 KeyStore for doing client certificates | | + + + +#### Changing the config +Changing Unirest's config should ideally be done once, or rarely. There are several background threads spawned by both Unirest itself and Apache HttpAsyncClient. Once Unirest has been activated configuration options that are involved in creating the client cannot be changed without an explicit shutdown or reset. + +```Java + Unirest.config() + .reset() + .connectTimeout(5000) +``` + +#### Setting custom Apache Client +You can set your own custom Apache HttpClient and HttpAsyncClient. Note that Unirest settings like timeouts or interceptors are not applied to custom clients. + +```java + Unirest.config() + .httpClient(myClient) + .asyncClient(myAsyncClient) +``` + +#### Multiple Configuration Instances +As usual, Unirest maintains a primary single instance. Sometimes you might want different configurations for different systems. You might also want an instance rather than a static context for testing purposes. + +```java + + // this returns the same instance used by Unirest.get("http://somewhere/") + UnirestInstance unirest = Unirest.primaryInstance(); + // It can be configured and used just like the static context + unirest.config().connectTimeout(5000); + String result = unirest.get("http://foo").asString().getBody(); + + // You can also get a whole new instance + UnirestInstance unirest = Unirest.spawnInstance(); +``` + +**WARNING!** If you get a new instance of unirest YOU are responsible for shutting it down when the JVM shuts down. It is not tracked or shut down by ```Unirest.shutDown();``` + + + + +## Exiting an application + +Unirest starts a background event loop and your Java application won't be able to exit until you manually shutdown all the threads by invoking: + +```java +Unirest.shutdown(); +``` + +Once shutdown, using Unirest again will re-init the system + + From 019e34ab92551dcee24282faff129e7a2297cd93 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 4 Jun 2019 08:39:09 -0500 Subject: [PATCH 0627/1769] fix layout --- docs/_layouts/default.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/_layouts/default.html b/docs/_layouts/default.html index 8ea1c7a74..a8b2712f8 100644 --- a/docs/_layouts/default.html +++ b/docs/_layouts/default.html @@ -13,7 +13,7 @@ - + @@ -54,6 +54,6 @@  |  Contact  |  Team - + From c49e47fbef0f343279da63829a4abd3a26d2a545 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 4 Jun 2019 08:42:23 -0500 Subject: [PATCH 0628/1769] more doc tweeks --- docs/_config.yml | 4 +- docs/index.md | 292 -------------------------------------------- docs/pages/index.md | 5 - 3 files changed, 2 insertions(+), 299 deletions(-) delete mode 100644 docs/index.md diff --git a/docs/_config.yml b/docs/_config.yml index d580e58a1..9c2f210a2 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -4,8 +4,8 @@ templateversion: 2.7.1 description: > # > means to ignore newlines as long as indent is kept unirest-java Unirest in Java: Simplified, lightweight HTTP client library. -baseurl: "" # the subpath of your site, e.g. /blog -url: "http://kong.github.io/unirest-java/" # the base hostname & protocol for your site +baseurl: "/unirest-java" # the subpath of your site, e.g. /blog +url: "http://kong.github.io" # the base hostname & protocol for your site gems: [jekyll-redirect-from] # Build settings diff --git a/docs/index.md b/docs/index.md deleted file mode 100644 index f6b7bde8d..000000000 --- a/docs/index.md +++ /dev/null @@ -1,292 +0,0 @@ ---- -layout: default -title: Documentation -rightmenu: true ---- - -
-* [Features](#features) -* [Creating Request](#creating-request) -
- -[![Build Status](https://travis-ci.org/Kong/unirest-java.svg?branch=master)](https://travis-ci.org/Kong/unirest-java) -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.konghq/unirest-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.kong/unirest-java) -[![Javadocs](http://www.javadoc.io/badge/com.konghq/unirest-java.svg)](http://www.javadoc.io/doc/com.konghq/unirest-java) -[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/Kong/unirest-java) - - -## Install With [Maven](https://mvnrepository.com/artifact/com.konghq/unirest-java)[:](https://repo.maven.apache.org/maven2/com/konghq/unirest-java/) -```xml - - com.konghq - unirest-java - 2.3.02 - -``` - -### Upgrading from Previous Versions -See the [Upgrade Guide](UPGRADE_GUIDE.md) - -## Features - -* Make `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `HEAD`, `OPTIONS` requests -* Both synchronous and asynchronous (non-blocking) requests -* It supports form parameters, file uploads and custom body entities -* Easily add route parameters without ugly string concatenations -* Supports gzip -* Supports Basic Authentication natively -* Customizable timeout, concurrency levels and proxy settings -* Customizable default headers for every request (DRY) -* Automatic JSON parsing into a native object for JSON responses -* Customizable binding, with mapping from response body to java Object - - -## Creating Request -So you're probably wondering how using Unirest makes creating requests in Java easier, here is a basic POST request that will explain everything: - -```java -HttpResponse response = Unirest.post("http://httpbin.org/post") - .header("accept", "application/json") - .queryString("apiKey", "123") - .field("parameter", "value") - .field("foo", "bar") - .asJson(); -``` - -Requests are made when `as[Type]()` is invoked, possible types include `Json`, `String`, `Object` `Empty` and `File`. - - -### Route Parameters -Sometimes you want to add dynamic parameters in the URL, you can easily do that by adding a placeholder in the URL, and then by setting the route parameters with the `routeParam` function, like: - -```java -Unirest.get("http://httpbin.org/{method}") - .routeParam("method", "get") - .asJson(); -``` -In the example above the final URL will be `http://httpbin.org/get` - Basically the placeholder `{method}` will be replaced with `get`. - -The placeholder's format is as easy as: `{custom_name}` - -### Advanced Object Mapping with Jackson, GSON, JAX-B or others -Before an `asObject(Class)` or a `.body(Object)` invocation, is necessary to provide a custom implementation of the `ObjectMapper` interface. -This should be done only the first time, as the instance of the ObjectMapper will be shared globally. -Unirest offers a few plug-ins implementing popular object mappers like Jackson and Gson. See [mvn central](https://mvnrepository.com/artifact/com.konghq) for details. -nes of code. -For example, serializing Json from\to Object using the popular Jackson ObjectMapper takes only few li - -```java -// Only one time -Unirest.config().setObjectMapper(new JacksonObjectMapper()); - -// Response to Object -Book book = Unirest.get("http://httpbin.org/books/1") - .asObject(Book.class) - .getBody(); - -Author author = Unirest.get("http://httpbin.org/books/{id}/author") - .routeParam("id", bookObject.getId()) - .asObject(Author.class) - .getBody(); - -// Sending a JSON object -Unirest.post("http://httpbin.org/authors/post") - .header("accept", "application/json") - .header("Content-Type", "application/json") - .body(author) - .asJson(); -``` - -#### Errors in Object or JSON parsing -You can't always get what you want. And sometimes results you get from web services will not map into what you expect them to. -When this happens with a ```asObject``` or ```asJson``` request the resulting body will be null, but the response object will contain a ParsingException that allows you to get the error and the original body for inspection. - -```java -UnirestParsingException ex = response.getParsingError().get(); - -ex.getOriginalBody(); // Has the original body as a string. -ex.getMessage(); // Will have the parsing exception. -ex.getCause(); // of course will have the original parsing exception itself. -``` - -#### Asynchronous Requests -Sometimes, well most of the time, you want your application to be asynchronous and not block, Unirest supports this in Java using anonymous callbacks, or direct method placement: - -```java -CompletableFuture> future = Unirest.post("http://httpbin.org/post") - .header("accept", "application/json") - .field("param1", "value1") - .field("param2", "value2") - .asJsonAsync(response -> { - int code = response.getStatus(); - JsonNode body = response.getBody(); - }); -``` - -#### Custom mappings and handling large responses -Most response methods (```asString```, ```asJson```, and even ```asBinary```) read the entire -response stream into memory. In order to read the original stream and handle large responses you -can use several functional methods like: - -```java - Map r = Unirest.get(MockServer.GET) - .queryString("foo", "bar") - .asObject(i -> new Gson().fromJson(i.getContentReader(), HashMap.class)) - .getBody(); - -``` - -or consumers: - -```java - - Unirest.get(MockServer.GET) - .thenConsumeAsync(r -> { - // something like writing a file to disk - }); -``` - -#### File Uploads -Creating `multipart` requests with Java is trivial, simply pass along a `File` or an InputStream Object as a field: - -```java -HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") - .header("accept", "application/json") - .field("parameter", "value") - .field("file", new File("/tmp/file")) - .asJson(); -``` - -#### Custom Entity Body - -```java -HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") - .header("accept", "application/json") - .body("{\"parameter\":\"value\", \"foo\":\"bar\"}") - .asJson(); -``` - -#### JSON Patch Requests -Unirest has full native support for JSON Patch requests -```java - Unirest.jsonPatch(MockServer.PATCH) - .add("/fruits/-", "Apple") - .remove("/bugs") - .replace("/lastname", "Flintstone") - .test("/firstname", "Fred") - .move("/old/location", "/new/location") - .copy("/original/location", "/new/location") - .asJson(); -``` -will send a request with a body of -```json - [ - {"op":"add","path":"/fruits/-","value":"Apple"}, - {"op":"remove","path":"/bugs"}, - {"op":"replace","path":"/lastname","value":"Flintstone"}, - {"op":"test","path":"/firstname","value":"Fred"}, - {"op":"move","path":"/new/location","from":"/old/location"}, - {"op":"copy","path":"/new/location","from":"/original/location"} - ] - -``` - -#### Basic Authentication -Authenticating the request with basic authentication can be done by calling the `basicAuth(username, password)` function: -```java - Unirest.get("http://httpbin.org/headers") - .basicAuth("username", "password") - .asJson(); -``` - -# Configuration -Previous versions of unirest had configuration split across several different places. Sometimes it was done on ```Unirest```, sometimes it was done on ```Option```, sometimes it was somewhere else. -All configuration is now done through ```Unirest.config()``` - -#### Unirest.config() -Unirest config allows easy access to build a configuration just like you would build a request: - -```java - Unirest.config() - .socketTimeout(500) - .connectTimeout(1000) - .concurrency(10, 5) - .proxy(new Proxy("https://proxy")) - .setDefaultHeader("Accept", "application/json") - .followRedirects(false) - .enableCookieManagement(false) - .addInterceptor(new MyCustomInterceptor()); -``` - -#### Config Options - -| Builder Method | Impact | Default | -| ------------- | ------------- | ------------- | -| ```socketTimeout(int)``` | Sets the socket timeout for all requests in millis | 60000 | -| ```connectTimeout(int)``` | Sets the connection timeout for all requests in millis | 10000 | -| ```concurrency(int, int)``` | Sets concurrency rates; max total, max per route | 200, 20 | -| ```proxy(proxy)``` | Sets a proxy object for negotiating proxy servers. Can include auth credentials | | -| ```setDefaultHeader(String, String)``` | Sets a default header. Will overwrite if it exists | | -| ```setDefaultHeader(String, Supplier)``` | Sets a default header by supplier. Good for setting trace tokens for microservice architectures. Will overwrite if it exists | | -| ```addDefaultHeader(String, String)``` | Adds a default header. Multiple for the same name can exist | | -| ```addDefaultHeader(String, Supplier)``` | Add a default header by supplier. Good for setting trace tokens for microservice architectures. | | -| ```setDefaultBasicAuth(String, String)``` | Add a default Basic Auth Header | | -| ```followRedirects(boolean)``` | toggle following redirects | true | -| ```enableCookieManagement(boolean)``` | toggle accepting and storing cookies | true | -| ```cookieSpec(String)``` | set a cookie policy. Acceptable values: 'default' (same as Netscape), 'netscape', 'ignoreCookies', 'standard' (RFC 6265 interoprability profile) , 'standard-strict' (RFC 6265 strict profile) | default | -| ```automaticRetries(boolean)``` | toggle disabling automatic retries (up to 4 times) for socket timeouts | true | -| ```verifySsl(boolean)``` |toggle enforcing SSL | true | -| ```addShutdownHook(boolean)``` | toggle to add the clients to the system shutdown hooks automatically | false | -| ```clientCertificateStore(String,String)``` | Add a PKCS12 KeyStore by path for doing client certificates | | -| ```clientCertificateStore(KeyStore,String)``` | Add a PKCS12 KeyStore for doing client certificates | | - - - -#### Changing the config -Changing Unirest's config should ideally be done once, or rarely. There are several background threads spawned by both Unirest itself and Apache HttpAsyncClient. Once Unirest has been activated configuration options that are involved in creating the client cannot be changed without an explicit shutdown or reset. - -```Java - Unirest.config() - .reset() - .connectTimeout(5000) -``` - -#### Setting custom Apache Client -You can set your own custom Apache HttpClient and HttpAsyncClient. Note that Unirest settings like timeouts or interceptors are not applied to custom clients. - -```java - Unirest.config() - .httpClient(myClient) - .asyncClient(myAsyncClient) -``` - -#### Multiple Configuration Instances -As usual, Unirest maintains a primary single instance. Sometimes you might want different configurations for different systems. You might also want an instance rather than a static context for testing purposes. - -```java - - // this returns the same instance used by Unirest.get("http://somewhere/") - UnirestInstance unirest = Unirest.primaryInstance(); - // It can be configured and used just like the static context - unirest.config().connectTimeout(5000); - String result = unirest.get("http://foo").asString().getBody(); - - // You can also get a whole new instance - UnirestInstance unirest = Unirest.spawnInstance(); -``` - -**WARNING!** If you get a new instance of unirest YOU are responsible for shutting it down when the JVM shuts down. It is not tracked or shut down by ```Unirest.shutDown();``` - - - - -## Exiting an application - -Unirest starts a background event loop and your Java application won't be able to exit until you manually shutdown all the threads by invoking: - -```java -Unirest.shutdown(); -``` - -Once shutdown, using Unirest again will re-init the system - diff --git a/docs/pages/index.md b/docs/pages/index.md index 5a0e6835d..09c24e238 100644 --- a/docs/pages/index.md +++ b/docs/pages/index.md @@ -9,11 +9,6 @@ rightmenu: true * [Creating Request](#creating-request)
-[![Build Status](https://travis-ci.org/Kong/unirest-java.svg?branch=master)](https://travis-ci.org/Kong/unirest-java) -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.konghq/unirest-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.kong/unirest-java) -[![Javadocs](http://www.javadoc.io/badge/com.konghq/unirest-java.svg)](http://www.javadoc.io/doc/com.konghq/unirest-java) -[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/Kong/unirest-java) - ## Install With [Maven](https://mvnrepository.com/artifact/com.konghq/unirest-java)[:](https://repo.maven.apache.org/maven2/com/konghq/unirest-java/) ```xml From fdffdca929c6997a27f9866156b725cbf16981b8 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 4 Jun 2019 08:44:01 -0500 Subject: [PATCH 0629/1769] move the index up --- docs/{pages => }/index.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/{pages => }/index.md (100%) diff --git a/docs/pages/index.md b/docs/index.md similarity index 100% rename from docs/pages/index.md rename to docs/index.md From 0ae36046468fc54ba74974061706569c2c440724 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 4 Jun 2019 08:48:06 -0500 Subject: [PATCH 0630/1769] add title --- docs/index.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/index.md b/docs/index.md index 09c24e238..6f45dd7ff 100644 --- a/docs/index.md +++ b/docs/index.md @@ -9,6 +9,8 @@ rightmenu: true * [Creating Request](#creating-request) +# Unirest-Java +Unirest in Java: Simplified, lightweight HTTP client library. ## Install With [Maven](https://mvnrepository.com/artifact/com.konghq/unirest-java)[:](https://repo.maven.apache.org/maven2/com/konghq/unirest-java/) ```xml From ac4ebd4880f7f01885d9ee57ff20328fa005758c Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Tue, 4 Jun 2019 08:52:18 -0500 Subject: [PATCH 0631/1769] add header --- docs/_layouts/default.html | 3 ++- docs/index.md | 3 --- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/_layouts/default.html b/docs/_layouts/default.html index a8b2712f8..0c7dc4b2f 100644 --- a/docs/_layouts/default.html +++ b/docs/_layouts/default.html @@ -21,7 +21,8 @@