• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Client类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.sun.jersey.api.client.Client的典型用法代码示例。如果您正苦于以下问题:Java Client类的具体用法?Java Client怎么用?Java Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Client类属于com.sun.jersey.api.client包,在下文中一共展示了Client类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: rebuildHttpClient

import com.sun.jersey.api.client.Client; //导入依赖的package包/类
/**
 * Build the Client used to make HTTP requests with the latest settings,
 * i.e. objectMapper and debugging.
 * TODO: better to use the Builder Pattern?
 */
public ApiClient rebuildHttpClient() {
  // Add the JSON serialization support to Jersey
  JacksonJsonProvider jsonProvider = new JacksonJsonProvider(objectMapper);
  DefaultClientConfig conf = new DefaultClientConfig();
  conf.getSingletons().add(jsonProvider);
  Client client = Client.create(conf);
  if (debugging) {
    client.addFilter(new LoggingFilter());
  }
  
  //to solve the issue of GET:metadata/:guid with accepted encodeing is 'gzip' 
  //in the past, when clients use gzip header, actually it doesn't trigger a gzip encoding... So everything is fine 
  //After the release, the content is return in gzip, while the sdk doesn't handle it correctly
  client.addFilter(new GZIPContentEncodingFilter(false));

  this.httpClient = client;
  return this;
}
 
开发者ID:Autodesk-Forge,项目名称:forge-api-java-client,代码行数:24,代码来源:ApiClient.java


示例2: hostIgnoringClient

import com.sun.jersey.api.client.Client; //导入依赖的package包/类
/**
 * Create a client which trust any HTTPS server
 * 
 * @return
 */
public static Client hostIgnoringClient() {
    try {
        SSLContext sslcontext = SSLContext.getInstance("TLS");
        sslcontext.init(null, null, null);
        DefaultClientConfig config = new DefaultClientConfig();
        Map<String, Object> properties = config.getProperties();
        HTTPSProperties httpsProperties = new HTTPSProperties(new HostnameVerifier() {
            @Override
            public boolean verify(String s, SSLSession sslSession) {
                return true;
            }
        }, sslcontext);
        properties.put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, httpsProperties);
        // config.getClasses().add( JacksonJsonProvider.class );
        return Client.create(config);
    } catch (KeyManagementException | NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:clstoulouse,项目名称:motu,代码行数:25,代码来源:RestUtilTest.java


示例3: 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:maoling,项目名称:fuck_zookeeper,代码行数:19,代码来源:Base.java


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


示例5: configure

import com.sun.jersey.api.client.Client; //导入依赖的package包/类
@Override
protected void configure() {

    // Bind core implementations of guacamole-ext classes
    bind(AuthenticationProvider.class).toInstance(authProvider);
    bind(Environment.class).toInstance(environment);

    // Bind services
    bind(ConfigurationService.class);
    bind(UserDataService.class);

    // Bind singleton ObjectMapper for JSON serialization/deserialization
    bind(ObjectMapper.class).in(Scopes.SINGLETON);

    // Bind singleton Jersey REST client
    bind(Client.class).toInstance(Client.create(CLIENT_CONFIG));

}
 
开发者ID:glyptodon,项目名称:guacamole-auth-callback,代码行数:19,代码来源:CallbackAuthenticationProviderModule.java


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


示例7: readAllRows

import com.sun.jersey.api.client.Client; //导入依赖的package包/类
public  Map<String,Object> readAllRows(String keyspaceName, String tableName){
	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";		
	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,代码行数:19,代码来源:MusicRestClient.java


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


示例9: cassaGet

import com.sun.jersey.api.client.Client; //导入依赖的package包/类
public  String cassaGet(){
	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 "cassaGet:"+url;	
}
 
开发者ID:att,项目名称:music,代码行数:21,代码来源:MicroBenchMarks.java


示例10: createKitchenSink

import com.sun.jersey.api.client.Client; //导入依赖的package包/类
private static void createKitchenSink(int port) throws Exception {
	
	List<TaskDef> taskDefs = new LinkedList<>();
	for(int i = 0; i < 40; i++) {
		taskDefs.add(new TaskDef("task_" + i, "task_" + i, 1, 0));
	}
	taskDefs.add(new TaskDef("search_elasticsearch", "search_elasticsearch", 1, 0));
	
	Client client = Client.create();
	ObjectMapper om = new ObjectMapper();
	client.resource("http://localhost:" + port + "/api/metadata/taskdefs").type(MediaType.APPLICATION_JSON).post(om.writeValueAsString(taskDefs));
	
	InputStream stream = Main.class.getResourceAsStream("/kitchensink.json");
	client.resource("http://localhost:" + port + "/api/metadata/workflow").type(MediaType.APPLICATION_JSON).post(stream);
	
	stream = Main.class.getResourceAsStream("/sub_flow_1.json");
	client.resource("http://localhost:" + port + "/api/metadata/workflow").type(MediaType.APPLICATION_JSON).post(stream);
	
	String input = "{\"task2Name\":\"task_5\"}";
	client.resource("http://localhost:" + port + "/api/workflow/kitchensink").type(MediaType.APPLICATION_JSON).post(input);
	
	logger.info("Kitchen sink workflows are created!");
}
 
开发者ID:Netflix,项目名称:conductor,代码行数:24,代码来源:ConductorServer.java


示例11: galaxyRestConnect

import com.sun.jersey.api.client.Client; //导入依赖的package包/类
@Test
    public void galaxyRestConnect() throws URISyntaxException, MalformedURLException, IOException, JSONException {
        //http://galaxy.readthedocs.io/en/master/lib/galaxy.webapps.galaxy.api.html#module-galaxy.webapps.galaxy.api.histories

        ClientConfig config = new DefaultClientConfig();
        Client client = Client.create(config);
        config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
        WebResource service = client.resource(new URI(gURL));

//        MultivaluedMap<String, String> params = new MultivaluedMapImpl();
//        params.add("key", gKey);
        ClientResponse responseHist = service.path("/api/histories").queryParam("key", gApiKey).accept("application/json").type("application/json").get(ClientResponse.class);
        System.out.println("----------");
        String r = responseHist.getEntity(String.class);
        Util.jsonPP(r);
        System.out.println("----------");

//        /api/tools
        ClientResponse responseTools = service.path("/api/tools").queryParam("key", gApiKey).accept("application/json").type("application/json").get(ClientResponse.class);
        System.out.println("----------");
        r = responseTools.getEntity(String.class);
        Util.jsonPP(r);
    }
 
开发者ID:albangaignard,项目名称:galaxy-PROV,代码行数:24,代码来源:GalaxyApiTest.java


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


示例13: provideQueueClient

import com.sun.jersey.api.client.Client; //导入依赖的package包/类
/** Create an SOA QueueService client for forwarding non-partition-aware clients to the right server. */
@Provides @Singleton @PartitionAwareClient
QueueServiceAuthenticator provideQueueClient(QueueService queueService, Client jerseyClient,
                                             @SelfHostAndPort HostAndPort self, @Global CuratorFramework curator,
                                             MetricRegistry metricRegistry, HealthCheckRegistry healthCheckRegistry) {
    MultiThreadedServiceFactory<AuthQueueService> serviceFactory = new PartitionAwareServiceFactory<>(
            AuthQueueService.class,
            QueueClientFactory.forClusterAndHttpClient(_configuration.getCluster(), jerseyClient),
            new TrustedQueueService(queueService), self, healthCheckRegistry, metricRegistry);
    AuthQueueService client = ServicePoolBuilder.create(AuthQueueService.class)
            .withHostDiscovery(new ZooKeeperHostDiscovery(curator, serviceFactory.getServiceName(), metricRegistry))
            .withServiceFactory(serviceFactory)
            .withMetricRegistry(metricRegistry)
            .withCachingPolicy(ServiceCachingPolicyBuilder.getMultiThreadedClientPolicy())
            .buildProxy(new ExponentialBackoffRetry(5, 50, 1000, TimeUnit.MILLISECONDS));
    _environment.lifecycle().manage(new ManagedServicePoolProxy(client));
    return QueueServiceAuthenticator.proxied(client);
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:19,代码来源:EmoModule.java


示例14: acquireLock

import com.sun.jersey.api.client.Client; //导入依赖的package包/类
private  boolean acquireLock(String lockId){
	Client client = Client.create();
	String msg = musicHandle.getMusicNodeURL()+"/locks/acquire/"+lockId;
	System.out.println(msg);
	WebResource webResource = client.resource(msg);


	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()+"url:"+msg);
	}

	String output = response.getEntity(String.class);
	Boolean status = Boolean.parseBoolean(output);
	System.out.println("Server response .... \n");
	System.out.println(output);
	return status;
}
 
开发者ID:att,项目名称:music,代码行数:22,代码来源:TestMusicE2E.java


示例15: provideSystemDataStore

import com.sun.jersey.api.client.Client; //导入依赖的package包/类
/** Provides a DataStore client that delegates to the remote system center data store. */
@Provides @Singleton @SystemDataStore
DataStore provideSystemDataStore (DataCenterConfiguration config, Client jerseyClient, @Named ("AdminKey") String apiKey, MetricRegistry metricRegistry) {

    ServiceFactory<DataStore> clientFactory = DataStoreClientFactory
            .forClusterAndHttpClient(_configuration.getCluster(), jerseyClient)
            .usingCredentials(apiKey);

    URI uri = config.getSystemDataCenterServiceUri();
    ServiceEndPoint endPoint = new ServiceEndPointBuilder()
            .withServiceName(clientFactory.getServiceName())
            .withId(config.getSystemDataCenter())
            .withPayload(new PayloadBuilder()
                    .withUrl(uri.resolve(DataStoreClient.SERVICE_PATH))
                    .withAdminUrl(uri)
                    .toString())
            .build();

    return ServicePoolBuilder.create(DataStore.class)
            .withMetricRegistry(metricRegistry)
            .withHostDiscovery(new FixedHostDiscovery(endPoint))
            .withServiceFactory(clientFactory)
            .buildProxy(new ExponentialBackoffRetry(30, 1, 10, TimeUnit.SECONDS));
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:25,代码来源:EmoModule.java


示例16: createRow

import com.sun.jersey.api.client.Client; //导入依赖的package包/类
public  void createRow(String keyspaceName, String tableName,Map<String, Object> values){
	Map<String,String> consistencyInfo= new HashMap<String, String>();
	consistencyInfo.put("type", "eventual");

	JsonInsert jIns = new JsonInsert();
	jIns.setValues(values);
	jIns.setConsistencyInfo(consistencyInfo);
	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";
	WebResource webResource = client
			.resource(url);

	ClientResponse response = webResource.accept("application/json")
			.type("application/json").post(ClientResponse.class, jIns);

	if (response.getStatus() < 200 || response.getStatus() > 299) 
		throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()+"url:"+url+"values:"+values);


}
 
开发者ID:att,项目名称:music,代码行数:27,代码来源:MusicRestClient.java


示例17: createStringMapTable

import com.sun.jersey.api.client.Client; //导入依赖的package包/类
public void createStringMapTable(String keyspaceName, String tableName,Map<String,String> fields){
	Map<String,String> consistencyInfo= new HashMap<String, String>();
	consistencyInfo.put("type", "eventual");

	JsonTable jtab = new JsonTable();
	jtab.setFields(fields);
	jtab.setConsistencyInfo(consistencyInfo);

	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;
	WebResource webResource = client
			.resource(url);

	ClientResponse response = webResource.accept("application/json")
			.type("application/json").post(ClientResponse.class, jtab);

	if (response.getStatus() < 200 || response.getStatus() > 299) 
		throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus());

}
 
开发者ID:att,项目名称:music,代码行数:26,代码来源:MusicRestClient.java


示例18: dropKeySpace

import com.sun.jersey.api.client.Client; //导入依赖的package包/类
public static void dropKeySpace(String keyspaceName){
	Map<String,String> consistencyInfo= new HashMap<String, String>();
	consistencyInfo.put("type", "eventual");

	JsonKeySpace jsonKp = new JsonKeySpace();
	jsonKp.setConsistencyInfo(consistencyInfo);

	ClientConfig clientConfig = new DefaultClientConfig();

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

	Client client = Client.create(clientConfig);

	WebResource webResource = client
			.resource(HalUtil.getMusicNodeURL()+"/keyspaces/"+keyspaceName);

	ClientResponse response = webResource.type("application/json")
			.delete(ClientResponse.class, jsonKp);

	if (response.getStatus() < 200 || response.getStatus() > 299) 
		throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus());
}
 
开发者ID:att,项目名称:music,代码行数:24,代码来源:MusicHandle.java


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


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



注:本文中的com.sun.jersey.api.client.Client类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FillLayout类代码示例发布时间:2022-05-20
下一篇:
Java Transaction类代码示例发布时间:2022-05-20
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap