Created
July 27, 2013 14:27
-
-
Save mneedham/6095019 to your computer and use it in GitHub Desktop.
Jersey Client Example
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 | |
| public void jerseyClientExample() { | |
| Foo foo = new Foo(Client.create()); | |
| // some code here to fake the call to google to make it return 200 | |
| String result = foo.doSomething(); | |
| assertEquals("win", result); | |
| } | |
| class Foo { | |
| private Client httpClient; | |
| public Foo(Client httpClient) { | |
| this.httpClient = httpClient; | |
| } | |
| public String doSomething() { | |
| ClientResponse response = httpClient.resource("http://www.google.com").get(ClientResponse.class); | |
| if(response.getStatus() >= 100 && response.getStatus() < 400) { | |
| return "win"; | |
| } else { | |
| return "fail"; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment