Java 类com.sun.jersey.api.client.config.DefaultClientConfig 实例源码

项目:twitter-java-ads-sdk    文件:ClientServiceImpl.java   
@Override
public WebResource getResource() {
    WebResource webResource = null;
    ClientConfig config = new DefaultClientConfig();
    config.getClasses().add(GsonJerseyProvider.class);
    Client client = Client.create(config);
    OAuthParameters oaParams = new OAuthParameters().signatureMethod("HMAC-SHA1").consumerKey(consumerKey)
            .token(accessToken).version("1.0");
    OAuthSecrets oaSecrets = new OAuthSecrets().consumerSecret(consumerSecret).tokenSecret(accessTokenSecret);

    OAuthClientFilter oAuthFilter = new OAuthClientFilter(client.getProviders(), oaParams, oaSecrets);
    client.addFilter(oAuthFilter);

    if (this.sandbox) {
        webResource = client.resource(Constants.SANDBOX_BASE_API_URL);
    } else if (null!= this.domain){
        webResource = client.resource(this.domain);
    }
    else{
        webResource = client.resource(Constants.BASE_API_URL);
    }


    if (this.trace) {
        webResource.addFilter(new LoggingFilter());
    }
    return webResource;
}
项目:twitter-java-ads-sdk    文件:ClientServiceImpl.java   
public Client getClient() {

        ClientConfig config = new DefaultClientConfig();
        Client client = Client.create(config);

        OAuthParameters oaParams = new OAuthParameters().signatureMethod("HMAC-SHA1").consumerKey(consumerKey)
                .token(accessToken).version("1.0");

        OAuthSecrets oaSecrets = new OAuthSecrets().consumerSecret(consumerSecret).tokenSecret(accessTokenSecret);

        OAuthClientFilter oAuthFilter = new OAuthClientFilter(client.getProviders(), oaParams, oaSecrets);
        client.addFilter(oAuthFilter);

        return client;
    }
项目:hadoop    文件:TestRMHA.java   
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
  }
项目:aliyun-oss-hadoop-fs    文件:TestRMHA.java   
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
  }
项目:galaxy-PROV    文件:GalaxyApiTest.java   
@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);
    }
项目:music    文件:MusicHandle.java   
public  static Map<String,Object> readSpecificRow(String keyspaceName, String tableName,String keyName, String keyValue){
    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+"/tables/"+tableName+"/rows?"+keyName+"="+keyValue);

    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);

    Map<String, Object> rowMap=null;
    for (Map.Entry<String, Object> entry : output.entrySet()){
        rowMap = (Map<String, Object>)entry.getValue();
        break;
    }

    return rowMap;  
}
项目:music    文件:MusicHandle.java   
public static void dropTable(String keyspaceName, String tableName){
    Map<String,String> consistencyInfo= new HashMap<String, String>();
    consistencyInfo.put("type", "eventual");

    JsonTable jsonTb = new JsonTable();
    jsonTb.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+"/tables/"+tableName);

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

    if (response.getStatus() < 200 || response.getStatus() > 299) 
        throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus());
}
项目:music    文件:MusicHandle.java   
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());
}
项目:music    文件:VotingApp.java   
private  void deleteCandidateEntryEventually(String candidateName){
    Map<String,String> consistencyInfo= new HashMap<String, String>();
    consistencyInfo.put("type", "eventual");

    JsonDelete jDel = new JsonDelete();
    jDel.setConsistencyInfo(consistencyInfo);
    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;
    System.out.println(url);
    WebResource webResource = client
            .resource(url);

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

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

}
项目:music    文件:VotingApp.java   
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;  
}
项目:music    文件:VotingApp.java   
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;  
}
项目:music    文件:VotingApp.java   
private void dropKeySpace(){
    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(musicHandle.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());
}
项目:music    文件:MusicRestClient.java   
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());

}
项目:music    文件:MusicRestClient.java   
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);


}
项目:music    文件:MusicRestClient.java   
private void basicUpdateRow(String keyspaceName, String tableName, String primaryKeyName, String primaryKeyValue, Map<String, Object> values, Map<String,String> consistencyInfo){
    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?"+primaryKeyName+"="+primaryKeyValue;
    WebResource webResource = client
            .resource(url);

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

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

}
项目:music    文件:MusicRestClient.java   
public  void deleteEntry(String keyspaceName, String tableName, String primaryKeyName, String primaryKeyValue){
    Map<String,String> consistencyInfo= new HashMap<String, String>();
    consistencyInfo.put("type", "eventual");

    JsonDelete jDel = new JsonDelete();
    jDel.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?"+primaryKeyName+"="+primaryKeyValue;
    WebResource webResource = client
            .resource(url);

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

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

}
项目:music    文件:MusicRestClient.java   
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;  
}
项目:music    文件:MusicRestClient.java   
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;  
}
项目:music    文件:MusicRestClient.java   
public 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(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());
}
项目:music    文件:MicroBenchMarks.java   
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; 
}
项目:music    文件:MicroBenchMarks.java   
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; 
}
项目:music    文件:MicroBenchMarks.java   
private void zkCreate(String candidateName){
    //http://135.197.226.98:8080/MUSIC/rest/formal/purezk/shankarzknode
    ClientConfig clientConfig = new DefaultClientConfig();

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

    Client client = Client.create(clientConfig);

    WebResource webResource = client
            .resource(musicurl+"/purezk/"+candidateName);

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

    if (response.getStatus() < 200 || response.getStatus() > 299) 
        throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus());
}
项目:music    文件:TestMusicE2E.java   
private  void deleteCandidateEntryEventually(String candidateName){
    Map<String,String> consistencyInfo= new HashMap<String, String>();
    consistencyInfo.put("type", "eventual");

    JsonDelete jDel = new JsonDelete();
    jDel.setConsistencyInfo(consistencyInfo);
    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;
    System.out.println(url);
    WebResource webResource = client
            .resource(url);

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

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

}
项目:music    文件:TestMusicE2E.java   
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;  
}
项目:music    文件:TestMusicE2E.java   
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;  
}
项目:music    文件:TestMusicE2E.java   
private void dropKeySpace(){
    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(musicHandle.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());
}
项目:big-c    文件:TestRMHA.java   
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
  }
项目:forge-api-java-client    文件:ApiClient.java   
/**
 * 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;
}
项目:motu    文件:RestUtilTest.java   
/**
 * 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);
    }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestRMHA.java   
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
  }
项目:TinyTank    文件:DataServer.java   
private ClientResponse getClientResponse(Object st, String path) {
    String masterServer = "http://tinytank.lefrantguillaume.com/api/server/";

    ClientConfig clientConfig = new DefaultClientConfig();
    clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
    Client client = Client.create(clientConfig);
    client.addFilter(new HTTPBasicAuthFilter("T0N1jjOQIDmA4cJnmiT6zHvExjoSLRnbqEJ6h2zWKXLtJ9N8ygVHvkP7Sy4kqrv", "lMhIq0tVVwIvPKSBg8p8YbPg0zcvihBPJW6hsEGUiS6byKjoZcymXQs5urequUo"));
    WebResource webResource = client.resource(masterServer + path);
    System.out.println("sending to data server : " + st);
    ClientResponse response = webResource
            .accept("application/json")
            .type("application/json")
            .post(ClientResponse.class, st);
    if (response.getStatus() != 200) {
        throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
    }
    System.out.println("response from data server : " + response);
    return response;
}
项目:Processor    文件:Application.java   
/**
 * Initializes root resource classes and provider singletons
 * @param servletConfig
 */
public Application(@Context ServletConfig servletConfig)
{
    this(
        servletConfig.getInitParameter(A.dataset.getURI()) != null ? getDataset(servletConfig.getInitParameter(A.dataset.getURI()), null) : null,
        servletConfig.getInitParameter(SD.endpoint.getURI()) != null ? servletConfig.getInitParameter(SD.endpoint.getURI()) : null,
        servletConfig.getInitParameter(A.graphStore.getURI()) != null ? servletConfig.getInitParameter(A.graphStore.getURI()) : null,
        servletConfig.getInitParameter(org.apache.jena.sparql.engine.http.Service.queryAuthUser.getSymbol()) != null ? servletConfig.getInitParameter(org.apache.jena.sparql.engine.http.Service.queryAuthUser.getSymbol()) : null,
        servletConfig.getInitParameter(org.apache.jena.sparql.engine.http.Service.queryAuthPwd.getSymbol()) != null ? servletConfig.getInitParameter(org.apache.jena.sparql.engine.http.Service.queryAuthPwd.getSymbol()) : null,
        new MediaTypes(), getClient(new DefaultClientConfig()),
        servletConfig.getInitParameter(A.maxGetRequestSize.getURI()) != null ? Integer.parseInt(servletConfig.getInitParameter(A.maxGetRequestSize.getURI())) : null,
        servletConfig.getInitParameter(A.preemptiveAuth.getURI()) != null ? Boolean.parseBoolean(servletConfig.getInitParameter(A.preemptiveAuth.getURI())) : false,
        getFileManager(new LocationMapper(servletConfig.getInitParameter(AP.locationMapping.getURI()) != null ? servletConfig.getInitParameter(AP.locationMapping.getURI()) : null)),
        servletConfig.getInitParameter(LDT.ontology.getURI()) != null ? servletConfig.getInitParameter(LDT.ontology.getURI()) : null,
        servletConfig.getInitParameter(AP.sitemapRules.getURI()) != null ? servletConfig.getInitParameter(AP.sitemapRules.getURI()) : null,
        servletConfig.getInitParameter(AP.cacheSitemap.getURI()) != null ? Boolean.valueOf(servletConfig.getInitParameter(AP.cacheSitemap.getURI())) : true
    );       
}
项目:eway-rapid-java    文件:RapidClientImpl.java   
/**
 * Fetches and configures a Web Resource to connect to eWAY
 *
 * @return A WebResource
 */
private WebResource getEwayWebResource() {
    ClientConfig clientConfig = new DefaultClientConfig();
    clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
    Client client = Client.create(clientConfig);
    client.addFilter(new HTTPBasicAuthFilter(APIKey, password));

    if (this.debug) {
        client.addFilter(new LoggingFilter(System.out));
    }

    // Set additional headers
    RapidClientFilter rapidFilter = new RapidClientFilter();
    rapidFilter.setVersion(apiVersion);
    client.addFilter(rapidFilter);

    WebResource resource = client.resource(webUrl);
    return resource;
}
项目:hops    文件:TestRMHA.java   
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
  }
项目:request-api    文件:RequestApi.java   
/**
 * Process url.
 *
 * @return the client response
 * @throws Exception the exception
 */
private ClientResponse processUrl() throws Exception {
    ClientConfig clientConfig = new DefaultClientConfig();
    clientConfig.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE );

    Client client = Client.create( clientConfig );

    WebResource webResource = createWebResource( client );
    webResource.accept( MediaType.APPLICATION_JSON );
    webResource.type( MediaType.APPLICATION_JSON );
    try {
        ClientResponse response = webResource.get( ClientResponse.class );

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

    } catch ( ClientHandlerException e ) {
        setStatus( STATUS_URL_NOK );
        throw new Exception( e );
    }

}
项目:osiris    文件:RestRequestSender.java   
public void uploadVoid(String url, File f, String formName, Headers... headers) {

        FormDataMultiPart form = new FormDataMultiPart().field(formName, f, MediaType.MULTIPART_FORM_DATA_TYPE);
        String urlCreated = createURI(url);
        ClientConfig cc = new DefaultClientConfig();
        cc.getClasses().add(MultiPartWriter.class);
        WebResource webResource = Client.create(cc).resource(urlCreated);

        Builder builder = webResource.type(MULTIPART_MEDIA).accept(MEDIA);

        for (Headers h : headers) {
            builder.header(h.getKey(), h.getValue());
        }

        builder.post(form);
    }
项目:osiris    文件:RestRequestSender.java   
public ClientResponse<File> upload(String url, File f, Headers... headers) {
    @SuppressWarnings("resource")
    FormDataMultiPart form = new FormDataMultiPart();
    form.bodyPart(new FileDataBodyPart("file", f, MediaType.APPLICATION_OCTET_STREAM_TYPE));

    String urlCreated = createURI(url);
    ClientConfig cc = new DefaultClientConfig();
    cc.getClasses().add(MultiPartWriter.class);
    WebResource webResource = Client.create(cc).resource(urlCreated);
    Builder builder = webResource.type(MULTIPART_MEDIA).accept(MEDIA).accept("text/plain");
    for (Headers h : headers) {
        builder.header(h.getKey(), h.getValue());
    }

    com.sun.jersey.api.client.ClientResponse clienteResponse = null;

    clienteResponse = builder.post(com.sun.jersey.api.client.ClientResponse.class, form);

    return new ClientResponse<File>(clienteResponse, File.class);
}
项目:osiris    文件:RestRequestSender.java   
public <T> ClientResponse<T> upload(String url, File f, Class<T> expectedResponse, Headers... headers) {

    @SuppressWarnings("resource")
    FormDataMultiPart form = new FormDataMultiPart();
    form.bodyPart(new FileDataBodyPart("file", f, MediaType.APPLICATION_OCTET_STREAM_TYPE));

    String urlCreated = createURI(url);
    ClientConfig cc = new DefaultClientConfig();
    cc.getClasses().add(MultiPartWriter.class);
    WebResource webResource = Client.create(cc).resource(urlCreated);
    Builder builder = webResource.type(MULTIPART_MEDIA).accept(MEDIA).accept("text/plain");
    for (Headers h : headers) {
        builder.header(h.getKey(), h.getValue());
    }

    com.sun.jersey.api.client.ClientResponse clienteResponse = null;

    clienteResponse = builder.post(com.sun.jersey.api.client.ClientResponse.class, form);

    return new ClientResponse<T>(clienteResponse, expectedResponse);
}
项目:osiris    文件:RestRequestSender.java   
public ClientResponse<File> uploadNoMultipart(String url, File f, Headers... headers) throws FileNotFoundException {

        InputStream is = new FileInputStream(f);

        String urlCreated = createURI(url);
        ClientConfig cc = new DefaultClientConfig();
        cc.getClasses().add(MultiPartWriter.class);
        WebResource webResource = Client.create(cc).resource(urlCreated);
        Builder builder = webResource.type(MediaType.APPLICATION_OCTET_STREAM).accept(MEDIA).accept("text/plain");

        String sContentDisposition = "attachment; filename=\"" + f.getName() + "\"";
        builder.header("Content-Disposition", sContentDisposition);

        for (Headers h : headers) {
            builder.header(h.getKey(), h.getValue());
        }

        com.sun.jersey.api.client.ClientResponse clienteResponse = null;

        clienteResponse = builder.post(com.sun.jersey.api.client.ClientResponse.class, is);

        return new ClientResponse<File>(clienteResponse, File.class);
    }
项目:curator    文件:TestStringsWithJersey.java   
@Test
public void     testEmptyServiceNames()
{
    ClientConfig    config = new DefaultClientConfig()
    {
        @Override
        public Set<Object> getSingletons()
        {
            Set<Object>     singletons = Sets.newHashSet();
            singletons.add(context);
            singletons.add(serviceNamesMarshaller);
            singletons.add(serviceInstanceMarshaller);
            singletons.add(serviceInstancesMarshaller);
            return singletons;
        }
    };
    Client          client = Client.create(config);
    WebResource     resource = client.resource("http://localhost:" + port);
    ServiceNames names = resource.path("/v1/service").get(ServiceNames.class);
    Assert.assertEquals(names.getNames(), Lists.<String>newArrayList());
}