Last active
September 11, 2015 07:59
-
-
Save gfrison/dea35d109897a00c4810 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.netty.buffer.ByteBuf; | |
import io.netty.handler.codec.http.HttpMethod; | |
import io.netty.handler.logging.LogLevel; | |
import io.netty.handler.proxy.HttpProxyHandler; | |
import io.reactivex.netty.protocol.http.client.HttpClient; | |
import io.reactivex.netty.protocol.http.client.HttpClientResponse; | |
import org.junit.Ignore; | |
import org.junit.Test; | |
import rx.Observable; | |
import javax.ws.rs.core.MediaType; | |
import java.net.InetSocketAddress; | |
import java.nio.charset.Charset; | |
final byte[] body = ("body...").getBytes(); | |
final HttpClientResponse<Object> res = HttpClient.newClient("api.yaas.io", 443) | |
.enableWireLogging(LogLevel.DEBUG).unsafeSecure() | |
.addChannelHandlerFirst("proxy", () -> new HttpProxyHandler(new InetSocketAddress("proxyHost", 8080))) | |
.createRequest(HttpMethod.POST, "/uri-path").addHeader("Content-Type",MediaType.APPLICATION_FORM_URLENCODED) | |
.addHeader("Content-Length", body.length) | |
.writeBytesContent(Observable.just(body)) | |
.toBlocking().first(); | |
final Object content = res.getContent().toBlocking().first(); | |
System.out.println("it works); | |
System.out.println(((ByteBuf) content).toString(Charset.defaultCharset())); | |
---------------- | |
Caused by: java.net.UnknownHostException: api.yaas.io | |
at java.net.InetAddress.getAllByName0(InetAddress.java:1280) | |
at java.net.InetAddress.getAllByName(InetAddress.java:1192) | |
at java.net.InetAddress.getAllByName(InetAddress.java:1126) | |
at java.net.InetAddress.getByName(InetAddress.java:1076) | |
at io.netty.resolver.DefaultNameResolver.doResolve(DefaultNameResolver.java:46) | |
at io.netty.resolver.DefaultNameResolver.doResolve(DefaultNameResolver.java:30) | |
at io.netty.resolver.SimpleNameResolver.resolve(SimpleNameResolver.java:133) | |
at io.netty.bootstrap.Bootstrap.doResolveAndConnect(Bootstrap.java:171) | |
at io.netty.bootstrap.Bootstrap.connect(Bootstrap.java:139) | |
at io.reactivex.netty.protocol.tcp.client.ClientState$3.call(ClientState.java:237) | |
at io.reactivex.netty.protocol.tcp.client.ClientState$3.call(ClientState.java:227) | |
at io.reactivex.netty.protocol.tcp.client.ConnectionObservable$1.call(ConnectionObservable.java:48) | |
at io.reactivex.netty.protocol.tcp.client.ConnectionObservable$1.call(ConnectionObservable.java:45) | |
at rx.Observable.unsafeSubscribe(Observable.java:7713) | |
at io.reactivex.netty.protocol.tcp.client.ConnectionRequestImpl$1$1$1.onCompleted(ConnectionRequestImpl.java:61) | |
at rx.subjects.SubjectSubscriptionManager$SubjectObserver.onCompleted(SubjectSubscriptionManager.java:232) | |
at rx.internal.operators.NotificationLite.accept(NotificationLite.java:140) | |
at rx.subjects.ReplaySubject$UnboundedReplayState.accept(ReplaySubject.java:466) | |
at rx.subjects.ReplaySubject$UnboundedReplayState.replayObserverFromIndex(ReplaySubject.java:515) | |
at rx.subjects.ReplaySubject$1.call(ReplaySubject.java:98) | |
at rx.subjects.ReplaySubject$1.call(ReplaySubject.java:94) | |
at rx.subjects.SubjectSubscriptionManager.call(SubjectSubscriptionManager.java:59) | |
at rx.subjects.SubjectSubscriptionManager.call(SubjectSubscriptionManager.java:35) | |
at rx.Observable.unsafeSubscribe(Observable.java:7713) | |
at rx.internal.operators.OnSubscribeCache.call(OnSubscribeCache.java:74) | |
at rx.internal.operators.OnSubscribeCache.call(OnSubscribeCache.java:42) | |
at rx.Observable$1.call(Observable.java:145) | |
at rx.Observable$1.call(Observable.java:137) | |
at rx.Observable.unsafeSubscribe(Observable.java:7713) | |
at io.reactivex.netty.protocol.tcp.client.ConnectionRequestImpl$1.call(ConnectionRequestImpl.java:76) | |
at io.reactivex.netty.protocol.tcp.client.ConnectionRequestImpl$1.call(ConnectionRequestImpl.java:41) | |
at rx.Observable$1.call(Observable.java:145) | |
at rx.Observable$1.call(Observable.java:137) | |
at rx.Observable$1.call(Observable.java:145) | |
at rx.Observable$1.call(Observable.java:137) | |
at rx.Observable$1.call(Observable.java:145) | |
at rx.Observable$1.call(Observable.java:137) | |
at rx.Observable.unsafeSubscribe(Observable.java:7713) | |
at io.reactivex.netty.protocol.http.client.internal.HttpClientRequestImpl$OnSubscribeFuncImpl.call(HttpClientRequestImpl.java:475) | |
at io.reactivex.netty.protocol.http.client.internal.HttpClientRequestImpl$OnSubscribeFuncImpl.call(HttpClientRequestImpl.java:450) | |
at rx.Observable$1.call(Observable.java:145) | |
at rx.Observable$1.call(Observable.java:137) | |
at rx.Observable$1.call(Observable.java:145) | |
at rx.Observable$1.call(Observable.java:137) | |
at rx.Observable.subscribe(Observable.java:7803) | |
at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:442) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment