本文整理汇总了Java中com.sun.jersey.api.client.Client.create方法的典型用法代码示例。如果您正苦于以下问题:Java Client.create方法的具体用法?Java Client.create怎么用?Java Client.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.jersey.api.client.Client
的用法示例。
在下文中一共展示了Client.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import com.sun.jersey.api.client.Client; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
super.setUp();
RestCfg cfg = new RestCfg(new ByteArrayInputStream(String.format(
"rest.port=%s\n" +
"rest.endpoint.1=%s;%s\n",
GRIZZLY_PORT, CONTEXT_PATH, ZKHOSTPORT).getBytes()));
rest = new RestMain(cfg);
rest.start();
zk = new ZooKeeper(ZKHOSTPORT, 30000, new MyWatcher());
client = Client.create();
znodesr = client.resource(BASEURI).path("znodes/v1");
sessionsr = client.resource(BASEURI).path("sessions/v1/");
}
示例2: setUp
import com.sun.jersey.api.client.Client; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
RestCfg cfg = new RestCfg(new ByteArrayInputStream(String.format(
"rest.port=%s\n" +
"rest.endpoint.1=%s;%s\n",
GRIZZLY_PORT, CONTEXT_PATH, ZKHOSTPORT).getBytes()));
rest = new RestMain(cfg);
rest.start();
zk = new ZooKeeper(ZKHOSTPORT, 30000, new MyWatcher());
client = Client.create();
znodesr = client.resource(BASEURI).path("znodes/v1");
sessionsr = client.resource(BASEURI).path("sessions/v1/");
}
示例3: jirasend
import com.sun.jersey.api.client.Client; //导入方法依赖的package包/类
/**
* Sends an Activity to SCMActivity Plugin's REST api
* @param activity ScmActivity object corresponding to commit found in push payload
* @throws ScmSyncException on post failure
*/
private void jirasend(ScmActivity activity) throws ScmSyncException {
// Setup Client
Client client = Client.create();
WebResource webResource = client.resource(jiraRestUrl);
client.addFilter(new HTTPBasicAuthFilter(jiraUser, jiraPassword));
// Post to SCMActivity
ClientResponse clientResponse = webResource.type("application/json").post(ClientResponse.class, activity.toJson());
String result = clientResponse.getStatus() + " " + clientResponse.getEntity(String.class);
logger.debug("Jira Send: \n\t" + activity.toString() + "\n\tResponse: " + result );
if (clientResponse.getStatus() == 201 ) {
logger.info("OK " + activity.getChangeId());
} else {
throw new ScmSyncException("Jira Rejected Activity because " + result + " " + activity.toString());
}
}
示例4: readVoteCountForCandidate
import com.sun.jersey.api.client.Client; //导入方法依赖的package包/类
public Map<String,Object> readVoteCountForCandidate(String candidateName){
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(
JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
Client client = Client.create(clientConfig);
String url = musicHandle.getMusicNodeURL()+"/keyspaces/"+keyspaceName+"/tables/votecount/rows?name="+candidateName;
WebResource webResource = client
.resource(url);
ClientResponse response = webResource.accept("application/json").get(ClientResponse.class);
if (response.getStatus() < 200 || response.getStatus() > 299)
throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus());
Map<String,Object> output = response.getEntity(Map.class);
return output;
}
示例5: zkGet
import com.sun.jersey.api.client.Client; //导入方法依赖的package包/类
public String zkGet(){
Client client = Client.create();
String url = musicurl+"/purezk/"+userForGets;
System.out.println("in zk get:"+url);
WebResource webResource = client
.resource(url);
ClientResponse response = webResource.accept("text/plain")
.get(ClientResponse.class);
if (response.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatus());
}
String output = response.getEntity(String.class);
return "zkGet:"+url;
}
示例6: whoIsLockHolder
import com.sun.jersey.api.client.Client; //导入方法依赖的package包/类
public static String whoIsLockHolder(String lockName){
Client client = Client.create();
WebResource webResource = client.resource(HalUtil.getMusicNodeURL()+"/locks/enquire/"+lockName);
WebResource.Builder wb = webResource.accept(MediaType.TEXT_PLAIN);
ClientResponse response = wb.get(ClientResponse.class);
if (response.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatus());
}
String output = response.getEntity(String.class);
// System.out.println("Server response .... \n");
// System.out.println(output);
return output;
}
示例7: musicGet
import com.sun.jersey.api.client.Client; //导入方法依赖的package包/类
public String musicGet(){
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(
JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
Client client = Client.create(clientConfig);
String url = musicurl+"/keyspaces/"+keyspaceName+"/tables/votecount/rows?name="+userForGets;
WebResource webResource = client
.resource(url);
ClientResponse response = webResource.accept("application/json").get(ClientResponse.class);
if (response.getStatus() < 200 || response.getStatus() > 299)
throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus());
Map<String,Object> output = response.getEntity(Map.class);
return "musicGet:"+url;
}
示例8: main
import com.sun.jersey.api.client.Client; //导入方法依赖的package包/类
public static void main(String [] args) {
System.out.println("Simple Java test for calling Hello Word service");
try {
// Get the endpoint for Hello World API
String endpoint = args[0];
// Create the client and call the API
Client client = Client.create();
WebResource webResource = client
.resource(endpoint+"helloworld/");
ClientResponse response = webResource.accept("application/json")
.get(ClientResponse.class);
// Process the result
if (response.getStatus() != 200) {
throw new RuntimeException("Called failed to HelloWorld : "
+ response.getStatus());
}
String output = response.getEntity(String.class);
System.out.println("Response: ");
System.out.println(output);
} catch (Exception e) {
e.printStackTrace();
}
}
示例9: getJSONData
import com.sun.jersey.api.client.Client; //导入方法依赖的package包/类
private String getJSONData(){
Client client = Client.create();
WebResource webResource = client.resource(UriBuilder.fromUri("https://api.github.com/repos/"+username+"/"+repoName+"/releases").build());
ClientResponse response = webResource.accept("application/json").get(ClientResponse.class);
String output = response.getEntity(String.class);
return output;
}
示例10: getJSONData
import com.sun.jersey.api.client.Client; //导入方法依赖的package包/类
private String getJSONData(){
Client client = Client.create();
WebResource webResource = client.resource(UriBuilder.fromUri("https://api.github.com/repos/"+username+"/"+repoName+"/releases").build());
ClientResponse response = webResource.accept("application/json").get(ClientResponse.class);
String output = response.getEntity(String.class);
//System.out.println(output);
return output;
}
示例11: getABFMapper
import com.sun.jersey.api.client.Client; //导入方法依赖的package包/类
public static ImmutableBiMap<String,String> getABFMapper() {
String serviceURL = null;
ImmutableBiMap<String,String> ABFMAPPER = null;
try {
serviceURL = System.getenv("authcode.service.URL");
if (serviceURL == null)
serviceURL = System.getProperty("authcode.service.URL","http://localhost:9876/references");
LOG.info("Initializing ABF Reference with remote service URL: "+ serviceURL);
Client client = Client.create();
WebResource webResource = client.resource(serviceURL);
ClientResponse response = webResource.accept("application/json")
.get(ClientResponse.class);
String output = response.getEntity(String.class);
if (response.getStatus() == 200 && output != null && !output.isEmpty()) {
Map<String, String> mapResponse = OBJECT_MAPPER.readValue(output, new TypeReference<Map<String, String>>() {});
ABFMAPPER = ImmutableBiMap.copyOf(Collections.unmodifiableMap(mapResponse));
LOG.info("Success on getting ABF Reference map from "+ serviceURL);
} else {
ABFMAPPER = ImmutableBiMap.copyOf(Collections.unmodifiableMap(ABFCodeMap.defaultABFMapper()));
}
}catch(Exception ex){
ABFMAPPER = ImmutableBiMap.copyOf(Collections.unmodifiableMap(ABFCodeMap.defaultABFMapper()));
LOG.warn("ABF Mapper initialization failed");
}
return ABFMAPPER;
}
示例12: MusicHandle
import com.sun.jersey.api.client.Client; //导入方法依赖的package包/类
public MusicHandle(String[] musicNodes, int repFactor){
this.musicNodes = musicNodes;
this.repFactor=repFactor;
bmKeySpace = "BmKeySpace";
bmTable = "BmEmployees";
clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(
JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
client = Client.create(clientConfig);
}
示例13: releaseLock
import com.sun.jersey.api.client.Client; //导入方法依赖的package包/类
public void releaseLock(String lockId){
Client client = Client.create();
WebResource webResource = client.resource(getMusicNodeURL()+"/locks/release/"+lockId);
ClientResponse response = webResource.delete(ClientResponse.class);
if (response.getStatus() != 204) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatus());
}
}
示例14: createKeyspace
import com.sun.jersey.api.client.Client; //导入方法依赖的package包/类
public void createKeyspace(String keyspaceName){
Map<String,Object> replicationInfo = new HashMap<String, Object>();
replicationInfo.put("class", "SimpleStrategy");
replicationInfo.put("replication_factor", 1);
String durabilityOfWrites="false";
Map<String,String> consistencyInfo= new HashMap<String, String>();
consistencyInfo.put("type", "eventual");
com.att.research.music.datastore.jsonobjects.JsonKeySpace jsonKp = new JsonKeySpace();
jsonKp.setConsistencyInfo(consistencyInfo);
jsonKp.setDurabilityOfWrites(durabilityOfWrites);
jsonKp.setReplicationInfo(replicationInfo);
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(
JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
Client client = Client.create(clientConfig);
WebResource webResource = client
.resource(getMusicNodeURL()+"/keyspaces/"+keyspaceName);
ClientResponse response = webResource.accept("application/json")
.type("application/json").post(ClientResponse.class, jsonKp);
if (response.getStatus() < 200 || response.getStatus() > 299)
throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus());
}
示例15: OrganisationRestClient
import com.sun.jersey.api.client.Client; //导入方法依赖的package包/类
public OrganisationRestClient(String uri)
{
ClientConfig config = new DefaultClientConfig();
config.getClasses().add(JacksonJsonProvider.class);
client = Client.create(config);
webResource = client.resource(uri).path("organisations");
endpointWebResource = client.resource(uri).path("endpoint");
channelWebResource = client.resource(uri).path("channel");
contactWebResource = client.resource(uri).path("endpointcontact");
}