Skip to content

Instantly share code, notes, and snippets.

@KomanRudden
Last active August 29, 2015 13:56
Show Gist options
  • Save KomanRudden/8896590 to your computer and use it in GitHub Desktop.
Save KomanRudden/8896590 to your computer and use it in GitHub Desktop.
JAX-RS 1.0 Client examples - Jersey
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