Last active
August 29, 2015 13:56
-
-
Save KomanRudden/8896590 to your computer and use it in GitHub Desktop.
JAX-RS 1.0 Client examples - Jersey
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
package i.am.koman.wsclients; | |
import com.sun.jersey.api.client.Client; | |
import com.sun.jersey.api.client.ClientResponse; | |
import com.sun.jersey.api.client.WebResource; | |
import javax.ws.rs.core.MediaType; | |
public class Jersey_Client { | |
public static void main(String args[]) { | |
callJersey(); | |
} | |
private static void callJersey() { | |
Client client = Client.create(); | |
WebResource resource = client.resource("http://<IP address>:8080/<path-to-rest-service>/go"); | |
ClientResponse response = resource.accept(MediaType.TEXT_PLAIN).get(ClientResponse.class); | |
if (response.getStatus() != 200) { | |
System.out.println("BIG JERSEY ERROR"); | |
} else { | |
System.out.println("JERSEY HAPPY DAYS"); | |
System.out.println(response.getEntity(String.class)); | |
} | |
} | |
} | |
//MAVEN Dependencies | |
<dependency> | |
<groupId>com.sun.jersey</groupId> | |
<artifactId>jersey-client</artifactId> | |
<version>1.8</version> | |
<type>jar</type> | |
</dependency> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment