本文整理汇总了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
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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: 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);
}
示例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);
}
示例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";
}
示例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;
}
示例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;
}
示例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);
}