Last active
February 27, 2017 11:31
-
-
Save dmikurube/44f41258380bc348daed735fed1a8938 to your computer and use it in GitHub Desktop.
JettyClient
This file contains hidden or 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
/* 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(); | |
} | |
} | |
} |
This file contains hidden or 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
HTTP/1.0 200 OK | |
{} |
Author
dmikurube
commented
Feb 27, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment