jersey client

package com.franky;



import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;

import org.glassfish.jersey.client.ClientConfig;

public class JerseyClient {
private static String URI="http://localhost:8089/webapp1";

/**
* @param args
*/
public static void main(String[] args) {

new JerseyClient().createJerseyClient();
}

private void createJerseyClient(){
ClientConfig clientConfig = new ClientConfig();


Client client = ClientBuilder.newClient(clientConfig);
WebTarget webTarget = client.target(URI);
Invocation.Builder in = webTarget.path("test2").request(MediaType.APPLICATION_JSON);
String res = in.get(String.class);
System.out.println(res);
client.close();
}

}

你可能感兴趣的:(jersey client)