Skip to content

Instantly share code, notes, and snippets.

@dmikurube
Last active February 27, 2017 11:31
Show Gist options
  • Save dmikurube/44f41258380bc348daed735fed1a8938 to your computer and use it in GitHub Desktop.
Save dmikurube/44f41258380bc348daed735fed1a8938 to your computer and use it in GitHub Desktop.
JettyClient
/* test.txt:
HTTP/1.0 200 OK
{}
*/
// $ cat test.txt | sudo nc -l 80
// $ javac -cp .:jetty-client-9.3.16.v20170120.jar:jetty-http-9.3.16.v20170120.jar:jetty-io-9.3.16.v20170120.jar:jetty-util-9.3.16.v20170120.jar JettyClient.java
// $ java -cp .:jetty-client-9.3.16.v20170120.jar:jetty-http-9.3.16.v20170120.jar:jetty-io-9.3.16.v20170120.jar:jetty-util-9.3.16.v20170120.jar JettyClient
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.util.ssl.SslContextFactory;
public class JettyClient {
public static void main(String[] args) throws Exception {
HttpClient client = new HttpClient(/*new SslContextFactory()*/);
client.setConnectTimeout(5000);
client.setIdleTimeout(5000);
client.setTCPNoDelay(true);
client.start();
try {
ContentResponse response = client
.newRequest("http://localhost")
.method(HttpMethod.GET)
.send();
System.out.println(response.getContentAsString());
} finally {
client.stop();
}
}
}
HTTP/1.0 200 OK
{}
@dmikurube
Copy link
Author

2017-02-27 20:19:58.979:INFO::main: Logging initialized @129ms
Exception in thread "main" java.util.concurrent.ExecutionException: org.eclipse.jetty.io.EofException
	at org.eclipse.jetty.client.util.FutureResponseListener.getResult(FutureResponseListener.java:118)
	at org.eclipse.jetty.client.util.FutureResponseListener.get(FutureResponseListener.java:101)
	at org.eclipse.jetty.client.HttpRequest.send(HttpRequest.java:652)
	at JettyClient.main(JettyClient.java:26)
Caused by: org.eclipse.jetty.io.EofException
	at org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:199)
	at org.eclipse.jetty.io.WriteFlusher.flush(WriteFlusher.java:420)
	at org.eclipse.jetty.io.WriteFlusher.write(WriteFlusher.java:313)
	at org.eclipse.jetty.io.AbstractEndPoint.write(AbstractEndPoint.java:147)
	at org.eclipse.jetty.client.http.HttpSenderOverHTTP$HeadersCallback.process(HttpSenderOverHTTP.java:236)
	at org.eclipse.jetty.util.IteratingCallback.processing(IteratingCallback.java:241)
	at org.eclipse.jetty.util.IteratingCallback.iterate(IteratingCallback.java:224)
	at org.eclipse.jetty.client.http.HttpSenderOverHTTP.sendHeaders(HttpSenderOverHTTP.java:59)
	at org.eclipse.jetty.client.HttpSender.send(HttpSender.java:204)
	at org.eclipse.jetty.client.http.HttpChannelOverHTTP.send(HttpChannelOverHTTP.java:79)
	at org.eclipse.jetty.client.HttpConnection.send(HttpConnection.java:203)
	at org.eclipse.jetty.client.http.HttpConnectionOverHTTP$Delegate.send(HttpConnectionOverHTTP.java:202)
	at org.eclipse.jetty.client.http.HttpConnectionOverHTTP.send(HttpConnectionOverHTTP.java:82)
	at org.eclipse.jetty.client.http.HttpDestinationOverHTTP.send(HttpDestinationOverHTTP.java:37)
	at org.eclipse.jetty.client.http.HttpDestinationOverHTTP.send(HttpDestinationOverHTTP.java:27)
	at org.eclipse.jetty.client.PoolingHttpDestination.process(PoolingHttpDestination.java:165)
	at org.eclipse.jetty.client.PoolingHttpDestination.process(PoolingHttpDestination.java:113)
	at org.eclipse.jetty.client.PoolingHttpDestination.send(PoolingHttpDestination.java:97)
	at org.eclipse.jetty.client.PoolingHttpDestination.succeeded(PoolingHttpDestination.java:84)
	at org.eclipse.jetty.client.DuplexConnectionPool.proceed(DuplexConnectionPool.java:171)
	at org.eclipse.jetty.client.DuplexConnectionPool$1.succeeded(DuplexConnectionPool.java:148)
	at org.eclipse.jetty.client.DuplexConnectionPool$1.succeeded(DuplexConnectionPool.java:139)
	at org.eclipse.jetty.util.Promise$Wrapper.succeeded(Promise.java:78)
	at org.eclipse.jetty.client.http.HttpConnectionOverHTTP.onOpen(HttpConnectionOverHTTP.java:90)
	at org.eclipse.jetty.io.SelectorManager.connectionOpened(SelectorManager.java:324)
	at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:425)
	at org.eclipse.jetty.io.ManagedSelector.access$1600(ManagedSelector.java:56)
	at org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:605)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.execute(ExecuteProduceConsume.java:100)
	at org.eclipse.jetty.io.ManagedSelector.run(ManagedSelector.java:147)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.nio.channels.ClosedChannelException
	at sun.nio.ch.SocketChannelImpl.ensureWriteOpen(SocketChannelImpl.java:270)
	at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:494)
	at org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:179)
	... 34 more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment