diff --git a/gradle.properties b/gradle.properties index 35a0bd4..d642e95 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,8 +1,8 @@ group = org.xbib name = netty-http-client -version = 4.1.22.0 +version = 4.1.19.0 -netty.version = 4.1.22.Final +netty.version = 4.1.19.Final tcnative.version = 2.0.1.Final xbib-net-url.version = 1.1.0 alpnagent.version = 2.0.7 diff --git a/gradle/publish.gradle b/gradle/publish.gradle index ccafc9b..0935c6f 100644 --- a/gradle/publish.gradle +++ b/gradle/publish.gradle @@ -1,5 +1,6 @@ task xbibUpload(type: Upload) { + group = 'publish' configuration = configurations.archives uploadDescriptor = true repositories { @@ -15,6 +16,7 @@ task xbibUpload(type: Upload) { } task sonaTypeUpload(type: Upload) { + group = 'publish' configuration = configurations.archives uploadDescriptor = true repositories { diff --git a/src/main/java/org/xbib/netty/http/client/Client.java b/src/main/java/org/xbib/netty/http/client/Client.java index 593b289..2324f39 100644 --- a/src/main/java/org/xbib/netty/http/client/Client.java +++ b/src/main/java/org/xbib/netty/http/client/Client.java @@ -100,6 +100,10 @@ public final class Client { return new ClientBuilder(); } + public ByteBufAllocator getByteBufAllocator() { + return byteBufAllocator; + } + public void setTransportListener(TransportListener transportListener) { this.transportListener = transportListener; } diff --git a/src/main/java/org/xbib/netty/http/client/rest/RestClient.java b/src/main/java/org/xbib/netty/http/client/rest/RestClient.java index a8133e1..90ed4a8 100644 --- a/src/main/java/org/xbib/netty/http/client/rest/RestClient.java +++ b/src/main/java/org/xbib/netty/http/client/rest/RestClient.java @@ -7,10 +7,12 @@ import org.xbib.net.URL; import org.xbib.netty.http.client.Client; import org.xbib.netty.http.client.HttpAddress; import org.xbib.netty.http.client.Request; +import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.transport.Transport; import java.io.IOException; import java.net.ConnectException; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.logging.Logger; @@ -39,6 +41,16 @@ public class RestClient { } public static RestClient get(String urlString) throws IOException { + return method(urlString, null, null, HttpMethod.GET); + } + + public static RestClient post(String urlString, String body) throws IOException { + return method(urlString, body, null, HttpMethod.POST); + } + + public static RestClient method(String urlString, + String body, Charset charset, + HttpMethod httpMethod) throws IOException { URL url = URL.create(urlString); Client client = new Client(); Transport transport = client.newTransport(HttpAddress.http1(url)); @@ -50,8 +62,16 @@ public class RestClient { throw new ConnectException("unable to connect to " + url); } transport.awaitSettings(); - transport.execute(Request.builder(HttpMethod.GET).setURL(url).build()); - transport.get(); + RequestBuilder requestBuilder = Request.builder(httpMethod); + requestBuilder.setURL(url); + if (body != null && charset != null) { + ByteBuf byteBuf = client.getByteBufAllocator().buffer(); + byteBuf.writeCharSequence(body, charset); + requestBuilder.setContent(byteBuf); + } + transport.execute(requestBuilder.build()).get(); return restClient; } + + }