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


Java Client.resource方法代碼示例

本文整理匯總了Java中com.sun.jersey.api.client.Client.resource方法的典型用法代碼示例。如果您正苦於以下問題:Java Client.resource方法的具體用法?Java Client.resource怎麽用?Java Client.resource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.jersey.api.client.Client的用法示例。


在下文中一共展示了Client.resource方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkActiveRMWebServices

import com.sun.jersey.api.client.Client; //導入方法依賴的package包/類
private void checkActiveRMWebServices() throws JSONException {

    // Validate web-service
    Client webServiceClient = Client.create(new DefaultClientConfig());
    InetSocketAddress rmWebappAddr =
        NetUtils.getConnectAddress(rm.getWebapp().getListenerAddress());
    String webappURL =
        "http://" + rmWebappAddr.getHostName() + ":" + rmWebappAddr.getPort();
    WebResource webResource = webServiceClient.resource(webappURL);
    String path = app.getApplicationId().toString();

    ClientResponse response =
        webResource.path("ws").path("v1").path("cluster").path("apps")
          .path(path).accept(MediaType.APPLICATION_JSON)
          .get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    JSONObject json = response.getEntity(JSONObject.class);

    assertEquals("incorrect number of elements", 1, json.length());
    JSONObject appJson = json.getJSONObject("app");
    assertEquals("ACCEPTED", appJson.getString("state"));
    // Other stuff is verified in the regular web-services related tests
  }
 
開發者ID:naver,項目名稱:hadoop,代碼行數:24,代碼來源:TestRMHA.java

示例2: createLockRef

import com.sun.jersey.api.client.Client; //導入方法依賴的package包/類
public static String createLockRef(String lockName){
	Client client = Client.create();
	WebResource webResource = client.resource(HalUtil.getMusicNodeURL()+"/locks/create/"+lockName);

	WebResource.Builder wb = webResource.accept(MediaType.TEXT_PLAIN);

	ClientResponse response = wb.post(ClientResponse.class);

	if (response.getStatus() != 200) {
		throw new RuntimeException("Failed : HTTP error code : "
				+ response.getStatus());
	}

	String output = response.getEntity(String.class);

	return output;
}
 
開發者ID:att,項目名稱:music,代碼行數:18,代碼來源:MusicHandle.java

示例3: readAllVotes

import com.sun.jersey.api.client.Client; //導入方法依賴的package包/類
public  Map<String,Object> readAllVotes(){
	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";
	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,代碼來源:TestMusicE2E.java

示例4: checkMusicVersion

import com.sun.jersey.api.client.Client; //導入方法依賴的package包/類
public void checkMusicVersion(){
	Client client = Client.create();

	WebResource webResource = client
			.resource(getMusicNodeURL()+"/version");

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

示例5: getMusicId

import com.sun.jersey.api.client.Client; //導入方法依賴的package包/類
public String getMusicId(){
	
	Client client = Client.create();

	WebResource webResource = client
			.resource(getMusicNodeURL()+"/nodeId");
	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 output;
}
 
開發者ID:att,項目名稱:music,代碼行數:18,代碼來源:MusicRestClient.java

示例6: createLock

import com.sun.jersey.api.client.Client; //導入方法依賴的package包/類
private  String createLock(String lockName){
	Client client = Client.create();
	String msg = musicurl+"/locks/create/"+lockName;
	WebResource webResource = client.resource(msg);
	System.out.println(msg);

	WebResource.Builder wb = webResource.accept(MediaType.TEXT_PLAIN);

	ClientResponse response = wb.post(ClientResponse.class);

	if (response.getStatus() != 200) {
		throw new RuntimeException("Failed : HTTP error code : "
				+ response.getStatus());
	}

	String output = response.getEntity(String.class);

	return output;
}
 
開發者ID:att,項目名稱:music,代碼行數:20,代碼來源:MicroBenchMarks.java

示例7: readRow

import com.sun.jersey.api.client.Client; //導入方法依賴的package包/類
public  Map<String,Object> readRow(String keyspaceName, String tableName, String primaryKeyName, String primaryKeyValue){
	ClientConfig clientConfig = new DefaultClientConfig();

	clientConfig.getFeatures().put(
			JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);

	Client client = Client.create(clientConfig);
	String url =getMusicNodeURL()+"/keyspaces/"+keyspaceName+"/tables/"+tableName+"/rows?"+primaryKeyName+"="+primaryKeyValue;
	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,代碼來源:MusicRestClient.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: getWebResource

import com.sun.jersey.api.client.Client; //導入方法依賴的package包/類
private static WebResource getWebResource(String url, ClientConfig config, String content_type) {
    logger.info("WebResource url = " + url + " , content_type = " + content_type);
    Client client;
    if (config != null) {
        client = Client.create(config);
    } else {
        client = Client.create();
    }
    return client.resource(url);
}
 
開發者ID:mariaklimenko,項目名稱:jeta,代碼行數:11,代碼來源:RestClient.java

示例11: MyClientRest

import com.sun.jersey.api.client.Client; //導入方法依賴的package包/類
public MyClientRest(String myName){
	
	this.myName=myName;
    ClientConfig config = new DefaultClientConfig();
    Client client = Client.create(config);
    service = client.resource(REST_URI);
    
}
 
開發者ID:anirban99,項目名稱:Shopping-Cart-using-Web-Services,代碼行數:9,代碼來源:MyClientRest.java

示例12: dropboxFlow

import com.sun.jersey.api.client.Client; //導入方法依賴的package包/類
@RequestMapping(value = "/dropboxcallback", method = {RequestMethod.GET, RequestMethod.POST})
public String dropboxFlow(@RequestParam(value = "code", defaultValue = "") String code, HttpServletRequest request, Model model) {
    ClientConfig config = new DefaultClientConfig();
    Client client = Client.create(config);
    WebResource webResource = client.resource(UriBuilder.fromUri("https://api.dropboxapi.com/oauth2/token").build());
    MultivaluedMap formData = new MultivaluedMapImpl();
    formData.add("code", code);
    formData.add("client_id", MISConfig.getDropbox_id());
    formData.add("redirect_uri", MISConfig.getDropbox_redirect());
    formData.add("client_secret",
            MISConfig.getDropbox_secret());
    formData.add("grant_type", "authorization_code");
    ClientResponse response1 = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).post(ClientResponse.class, formData); //Exchange code for token
    String json = response1.getEntity(String.class);
    JSONObject jsonObj = new JSONObject(json);
    String token=jsonObj.getString("access_token");
    List<String> names= DbxAPIOp.dropboxGetFiles(token); //Get files name

    List<FilmInfo> films=new LinkedList<FilmInfo>();
    List<BookInfo> books=new LinkedList<BookInfo>();
    List<MusicInfo> songs=new LinkedList<MusicInfo>();
    try {
        MediaOperations.findMediaInfo(names,books,films,songs); //Find info about files
    } catch (Exception e) {
        e.printStackTrace();
    }

    model.addAttribute("films",films);
    model.addAttribute("books",books);
    model.addAttribute("songs",songs);
    if(names!=null) RabbitSend.sendOAuth(MediaOperations.getFilesName(names),"Dropbox", request);
    //Generate HTML result page
    if(books.size()==0 && films.size()==0 && songs.size()==0) return "error_scan";
    else return "result_scan";
    }
 
開發者ID:LithiumSR,項目名稱:media_information_service,代碼行數:36,代碼來源:OAuthController.java

示例13: 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

示例14: 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

示例15: getClientBuilder

import com.sun.jersey.api.client.Client; //導入方法依賴的package包/類
/**
 * Gets a client web resource builder for the base XOS REST API
 * with an optional additional URI.
 *
 * @param uri URI suffix to append to base URI
 * @return web resource builder
 */
public WebResource.Builder getClientBuilder(String uri) {
    Client client = Client.create();
    client.addFilter(new HTTPBasicAuthFilter(AUTH_USER, AUTH_PASS));
    WebResource resource = client.resource(baseUrl() + uri);
    log.info("XOS REST CALL>> {}", resource);
    return resource.accept(UTF_8).type(UTF_8);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:15,代碼來源:XosManagerRestUtils.java


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