當前位置: 首頁>>代碼示例>>Java>>正文


Java Client.create方法代碼示例

本文整理匯總了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/");
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:19,代碼來源:Base.java

示例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/");
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:17,代碼來源:Base.java

示例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());
  }
}
 
開發者ID:attivio,項目名稱:scmsynchronizer,代碼行數:25,代碼來源:Server.java

示例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;	
}
 
開發者ID:att,項目名稱:music,代碼行數:20,代碼來源:VotingApp.java

示例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;
}
 
開發者ID:att,項目名稱:music,代碼行數:19,代碼來源:MicroBenchMarks.java

示例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;
}
 
開發者ID:att,項目名稱:music,代碼行數:20,代碼來源:MusicHandle.java

示例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;	
}
 
開發者ID:att,項目名稱:music,代碼行數:21,代碼來源:MicroBenchMarks.java

示例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();
    }

}
 
開發者ID:aws-samples,項目名稱:blog-multi-region-serverless-service,代碼行數:31,代碼來源:JavaClient.java

示例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;
}
 
開發者ID:LithiumSR,項目名稱:gw2_launcher,代碼行數:8,代碼來源:UpdateNotifier.java

示例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;
}
 
開發者ID:LithiumSR,項目名稱:media_information_service,代碼行數:9,代碼來源:UpdateNotifier.java

示例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;
}
 
開發者ID:tmobile,項目名稱:keybiner,代碼行數:28,代碼來源:ABFCodeMap.java

示例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);
}
 
開發者ID:att,項目名稱:music,代碼行數:15,代碼來源:MusicHandle.java

示例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());
	}
}
 
開發者ID:att,項目名稱:music,代碼行數:13,代碼來源:MusicRestClient.java

示例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());

}
 
開發者ID:att,項目名稱:music,代碼行數:30,代碼來源:MusicRestClient.java

示例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");
}
 
開發者ID:UnionVMS,項目名稱:USM,代碼行數:11,代碼來源:OrganisationRestClient.java


注:本文中的com.sun.jersey.api.client.Client.create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。