Client client = Client.create(); WebResource webResource =client.resource("uri"); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); queryParams.add("json", js); //set parametes for request appKey = "Bearer " + appKey; // appKey is unique number //Get response from RESTful Server get(ClientResponse.class); ClientResponse response = null; response = webResource.queryParams(queryParams) .header("Content-Type", "application/json;charset=UTF-8") .header("Authorization", appKey) .get(ClientResponse.class); String jsonStr = response.getEntity(String.class);
logDebug( BaseMessages.getString( PKG, "Rest.Log.queryParameterValue", data.paramNames[i], value ) ); webResource = webResource.queryParams( createMultivalueMap( data.paramNames[i], value ) );
System.out.println("Command Sent " + command + " : " + queryParams); ClientResponse response = webResource.queryParams(queryParams).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
WebResource webResource = client.resource("http://sample.com/rest_service"); MultivaluedMap queryParams = new MultivaluedMapImpl(); queryParams.add("PARAM1", param1); queryParams.add("PARAM2", param2); RESTResult s = webResource.queryParams(queryParams) //Check the return type of the service .accept(MediaType.APPLICATION_JSON) //Put a object with XmlRootElement to map the result .get(RESTResult .class); println(s.status); //Also you can return the result in a string String s = webResource.queryParams(queryParams).get(String.class);
@Override protected WebResource getResourceWithQueryParams(INPUT t) { WebResource wr = wsClient.resource(url); wr = wr.queryParams(getQueryParams(t)); return wr; }
private WebResource makeDocumentResource( MultivaluedMap<String, String> queryParams) { return connection.path("documents").queryParams(queryParams); }
public List<Container> listContainers(boolean allContainers, boolean latest, int limit, boolean showSize, String since, String before) { MultivaluedMap<String, String> params = new MultivaluedMapImpl(); params.add("limit", latest ? "1" : String.valueOf(limit)); params.add("all", allContainers ? "1" : "0"); params.add("since", since); params.add("before", before); params.add("size", showSize ? "1" : "0"); WebResource webResource = client.resource(restEndpointUrl + "/containers/json").queryParams(params); LOGGER.trace("GET: {}", webResource); List<Container> containers = webResource.accept(MediaType.APPLICATION_JSON).get(new GenericType<List<Container>>() { }); LOGGER.trace("Response: {}", containers); return containers; }
@Override public EIExchangeInstance getResource(String uri) { WebResource webResource = client.resource( baseServiceUrl ); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); queryParams.add( "uri", uri ); String json = webResource.queryParams( queryParams ).accept( MediaType.APPLICATION_JSON ).get( String.class ); try { return mapper.readValue( json, EIExchangeInstance.class ); } catch (Exception e) { logger.error( "Error getting remote instance", e ); throw new RuntimeException(e); } }
Client client = Client.create(); WebResource webResource =client.resource("URL"); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); queryParams.add("json", js); //set parametes for request appKey = "Addkey " + appKey; // appKey is unique number //Get response from RESTful Server get(ClientResponse.class); ClientResponse response = null; response = webResource.queryParams(queryParams) .header("Content-Type", "application/json;charset=UTF-8") .header("Authorization", appKey) .get(ClientResponse.class); String jsonStr = response.getEntity(String.class);
public User getUser(long id, Boolean includeAttributes) { WebResource wr = getBaseWebResource("users", "user", id); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); if (includeAttributes != null) { queryParams.add("includeattributes", includeAttributes.toString()); } return wr.queryParams(queryParams).get(User.class); }
public static WebResource newResource(Client client, String url, User user) { MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); if (user != null) // todo basic auth? { queryParams.add("os_username", user.getUsername()); queryParams.add("os_password", user.getPassword()); } WebResource webResource; if (url == null) { webResource = client.resource(TestProperties.getBaseUrl(1) + RestHelper.PROTOTYPE_REST_PATH); } else { webResource = client.resource(url); } return webResource.queryParams(queryParams); }
public WebResource.Builder uri( final String uri, final MultivaluedMap<String, String> queryParameters ) { return getClient() .resource( resolvePath( uri ) ) .queryParams( queryParameters ) .getRequestBuilder(); }
private ClientResponse doPutObjects(URI base, String path, MultivaluedMap<String, String> params, Object obj) { return connector.getClient().resource(base).path(path).queryParams(params) .accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON) .put(ClientResponse.class, obj); }
public String version(ArtifactDescriptor descriptor, @CheckForNull MediaType mediaType) throws IOException { return get(path("artifact/version") .queryParams(queryParameters(descriptor)) .accept(null != mediaType ? mediaType : TEXT_PLAIN_TYPE) ).getEntity(String.class); }
public String version(ArtifactDescriptor descriptor, @Nullable MediaType mediaType) throws IOException { return get(path("artifact/version") .queryParams(queryParameters(descriptor)) .accept(null != mediaType ? mediaType : TEXT_PLAIN_TYPE) ).getEntity(String.class); }
@Override public InputStream input() throws IOException { return get(path("artifact/diff") .queryParams(queryParameters(descriptor)) .queryParam("update-version", updateVersion) .accept(APPLICATION_OCTET_STREAM_TYPE) ).getEntityInputStream(); } };
@Override public InputStream input() throws IOException { return get(path("artifact/diff") .queryParams(queryParameters(descriptor)) .queryParam("update-version", updateVersion) .accept(APPLICATION_OCTET_STREAM_TYPE) ).getEntityInputStream(); } };
public WebResource.Builder serviceResource( final String uri, final MultivaluedMap<String, String> queryParameters ) { return getClient() .resource( resolveServicePath( uri ) ) .queryParams( queryParameters ) .type( getMediaType() ) .accept( getMediaType() ); }
public JsonRestClientResponse get(String path, MultivaluedMap<String, String> params) throws ClientHandlerException { ClientResponse response; WebResource r = this.webResource.path(path); if (params == null) { response = r.accept(MediaType.APPLICATION_JSON_TYPE).get(ClientResponse.class); } else { response = r.queryParams(params) .accept(MediaType.APPLICATION_JSON_TYPE) .get(ClientResponse.class); } return new JsonRestClientResponse(response); }
protected void GET(String url, Map<String, String> queryParams) { WebResource resource = resource().path(url); MultivaluedMapImpl params = new MultivaluedMapImpl(); for (Map.Entry<String, String> entry : queryParams.entrySet()) { params.add(entry.getKey(), entry.getValue()); } response = builder(resource.queryParams(params)).get(ClientResponse.class); }