@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; }
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; }
/** * Make HTTP GET call to the given url * * @param url */ public void get(String url) { ClientConfig cc = new DefaultNonBlockingClientConfig(); Client c = NonBlockingClient.create(cc); AsyncWebResource awr = c.asyncResource(url); // makes HTTP GET call awr.get(new TypeListener<ClientResponse>(ClientResponse.class) { public void onComplete(Future<ClientResponse> f) throws InterruptedException { try { System.out.println("Got Response. HTTP Code = " + f.get().getStatus()); } catch (ExecutionException e) { System.out.println("Something went wrong!"); } } }); System.out.println("Continued to execute..."); System.out.println("Done!"); }
@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); }
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; }
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()); }
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()); }
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); }
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; }
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; }
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()); }
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()); }
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); }
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); }
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); }
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; }
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; }
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()); }
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; }
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; }
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()); }
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; }
/** * 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; }
/** * 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 ); } }
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); }
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); }
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); }
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); }
@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()); }
/** * Constructor. * @param rootUrl the root URL (example: http://192.168.1.18:9007/dm/) */ public WsClient( String rootUrl ) { ClientConfig cc = new DefaultClientConfig(); cc.getClasses().add( JacksonJsonProvider.class ); cc.getClasses().add( ObjectMapperProvider.class ); this.client = Client.create( cc ); this.client.setFollowRedirects( true ); WebResource resource = this.client.resource( rootUrl ); this.applicationDelegate = new ApplicationWsDelegate( resource, this ); this.managementDelegate = new ManagementWsDelegate( resource, this ); this.debugDelegate = new DebugWsDelegate( resource, this ); this.targetWsDelegate = new TargetWsDelegate( resource, this ); this.schedulerDelegate = new SchedulerWsDelegate( resource, this ); this.preferencesWsDelegate = new PreferencesWsDelegate( resource, this ); this.authenticationWsDelegate = new AuthenticationWsDelegate( resource, this ); }
public VinothekContainerClient(String containerUrl){ String containerTmp = containerUrl; containerTmp = containerTmp.replaceAll("http://", "").trim(); if (containerTmp.contains(":")) { this.containerHost = this.fetchContainerHost(containerTmp); this.containerPort = this.fetchContainerPort(containerTmp); } else { this.containerHost = containerTmp; this.containerPort = CONFIG.DEFAULT_CONTAINER_PORT; } // Create Jersey Client ClientConfig config = new DefaultClientConfig(); this.jerseyClient = Client.create(config); }
@Test public void testPersist() throws UniformInterfaceException, JSONException, IOException { ClientConfig clientConfig = new DefaultClientConfig(); clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); client = Client.create(clientConfig); WebResource webResource = client.resource("http://localhost:9998/persist"); webResource.post("{\"xyx\" : \"t\"}"); LOG.info("Done posting to the server"); String output = webResource.get(String.class); LOG.info("All key values " + output); Map<String, String> jsonOutput = StageUtils.fromJson(output, Map.class); String value = jsonOutput.get("xyx"); Assert.assertEquals("t", value); webResource = client.resource("http://localhost:9998/persist/xyx"); output = webResource.get(String.class); Assert.assertEquals("t", output); LOG.info("Value for xyx " + output); }
public static void main(String[] args) { String name = "Pavithra"; int age = 25; ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); WebResource resource = client.resource(BASE_URI); WebResource nameResource = resource.path("rest").path(PATH_NAME + name); System.out.println("Client Response \n" + getClientResponse(nameResource)); System.out.println("Response \n" + getResponse(nameResource) + "\n\n"); WebResource ageResource = resource.path("rest").path(PATH_AGE + age); System.out.println("Client Response \n" + getClientResponse(ageResource)); System.out.println("Response \n" + getResponse(ageResource)); }
@Override public void validateApiEndpoint() throws YarnClientException, MalformedURLException { YarnEndpoint dashEndpoint = new YarnEndpoint( apiEndpoint, YarnResourceConstants.APPLICATIONS_PATH ); ClientConfig clientConfig = new DefaultClientConfig(); Client client = Client.create(clientConfig); WebResource webResource = client.resource(dashEndpoint.getFullEndpointUrl().toString()); ClientResponse response = webResource.accept("application/json").type("application/json").get(ClientResponse.class); // Validate HTTP 200 status code if (response.getStatus() != YarnResourceConstants.HTTP_SUCCESS) { String msg = String.format("Received %d status code from url %s, reason: %s", response.getStatus(), dashEndpoint.getFullEndpointUrl().toString(), response.getEntity(String.class)); LOGGER.debug(msg); throw new YarnClientException(msg); } }
@Override public void validateApiEndpoint() throws CloudbreakOrchestratorFailedException, MalformedURLException { YarnEndpoint dashEndpoint = new YarnEndpoint( apiEndpoint, YarnResourceConstants.APPLICATIONS_PATH ); ClientConfig clientConfig = new DefaultClientConfig(); Client client = Client.create(clientConfig); WebResource webResource = client.resource(dashEndpoint.getFullEndpointUrl().toString()); ClientResponse response = webResource.accept("application/json").type("application/json").get(ClientResponse.class); // Validate HTTP 200 status code if (response.getStatus() != YarnResourceConstants.HTTP_SUCCESS) { String msg = String.format("Received %d status code from url %s, reason: %s", response.getStatus(), dashEndpoint.getFullEndpointUrl().toString(), response.getEntity(String.class)); LOGGER.debug(msg); throw new CloudbreakOrchestratorFailedException(msg); } }
/** * @param apiKey your Asana API key * @param connectionTimeout the connection timeout in MILLISECONDS * @param readTimeout the read timeout in MILLISECONDS */ public AbstractClient(String apiKey, int connectionTimeout, int readTimeout){ this.apiKey = apiKey; ClientConfig config = new DefaultClientConfig(); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true); mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); JacksonJsonProvider provider = new JacksonJsonProvider(mapper); config.getSingletons().add(provider); //config.getClasses().add(JacksonJsonProvider.class); Client client = Client.create(config); client.addFilter(new HTTPBasicAuthFilter(apiKey, "")); client.setConnectTimeout(connectionTimeout); client.setReadTimeout(readTimeout); service = client.resource(UriBuilder.fromUri(BASE_URL).build()); }