Java Code Examples for javax.ws.rs.client.Invocation.Builder#accept()

The following examples show how to use javax.ws.rs.client.Invocation.Builder#accept() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AzureInteractiveLoginStatusCheckerTask.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
private String createResourceToken(String refreshToken, String tenantId, String resource) throws InteractiveLoginException {
    Form resourceTokenForm = createResourceTokenForm(refreshToken, resource);
    WebTarget webTarget = ClientBuilder.newClient().target(LOGIN_MICROSOFTONLINE);
    Builder request = webTarget.path(tenantId + "/oauth2/token").queryParam("api-version", "1.0").request();
    request.accept(MediaType.APPLICATION_JSON);
    try (Response response = request.post(Entity.entity(resourceTokenForm, MediaType.APPLICATION_FORM_URLENCODED_TYPE))) {
        if (response.getStatusInfo().getFamily() != Family.SUCCESSFUL) {
            throw new InteractiveLoginException("Obtain access token for " + resource + " failed "
                    + "with tenant ID: " + tenantId + ", status code " + response.getStatus()
                    + ", error message: " + response.readEntity(String.class));
        }
        String responseString = response.readEntity(String.class);
        try {
            return new ObjectMapper().readTree(responseString).get("access_token").asText();
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }
}
 
Example 2
Source File: TenantChecker.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public List<AzureTenant> getNextSetOfTenants(String link, String accessToken) throws InteractiveLoginException {
    Client client = ClientBuilder.newClient();
    Builder request = client.target(link).request();
    request.accept(MediaType.APPLICATION_JSON);
    request.header("Authorization", "Bearer " + accessToken);
    Response response = request.get();
    return collectTenants(accessToken, response);
}
 
Example 3
Source File: SubscriptionChecker.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public List<AzureSubscription> getNextSetOfSubscriptions(String link, String accessToken) throws InteractiveLoginException {
    Client client = ClientBuilder.newClient();
    Builder request = client.target(link).request();
    request.accept(MediaType.APPLICATION_JSON);
    request.header("Authorization", "Bearer " + accessToken);
    Response response = request.get();
    return collectSubscriptions(accessToken, response);
}
 
Example 4
Source File: AzureInteractiveLoginStatusCheckerTask.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private Response createPollingRequest() {
    Form pollingForm = createPollingForm();
    WebTarget resource = ClientBuilder.newClient().target(LOGIN_MICROSOFTONLINE_OAUTH2);
    Builder request = resource.path("token").queryParam("api-version", "1.0").request();
    request.accept(MediaType.APPLICATION_JSON);
    return request.post(Entity.entity(pollingForm, MediaType.APPLICATION_FORM_URLENCODED_TYPE));
}
 
Example 5
Source File: CKANClient.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Makes a POST request
 *
 * Submits a POST HTTP request to the CKAN instance configured within the constructor, returning the entire contents of the response.
 *
 * @param path
 *            The URL path to make the POST request to
 * @param jsonParams
 *            The data to be posted to the URL
 * @throws Exception
 * @returns The String contents of the response
 * @throws A
 *             CKANException if the request fails
 */
protected String postAndReturnTheJSON(String path, String jsonParams) throws CKANException {
	String uri = connection.getHost() + path;

	Response response = null;
	String jsonResponse = "";
	try {
		URL url = new URL(uri);
	} catch (MalformedURLException mue) {
		logger.debug("Failed: the provided URI is malformed. URI: " + uri);
		throw new CKANException("Failed: the provided URI is malformed.");
	}

	try {
		WebTarget target = ProxyClientUtilities.getTarget(uri);
		Builder request = target.request();

		// For FIWARE CKAN instance
		if (connection.getApiKey() != null) {
			request.header("X-Auth-Token", connection.getApiKey());
		}
		// For ANY CKAN instance
		// request.header("Authorization", connection.getApiKey());

		request.accept("application/json");

		response = request.post(Entity.json(jsonParams.toString()));

		if (response.getStatus() != 200) {
			throw new CKANException("Failed : HTTP error code : " + response.getStatus());
		}
		jsonResponse = response.readEntity(String.class);
		if (jsonResponse == null) {
			throw new CKANException("Failed: deserialisation has not been perfomed well. jsonResponse is null");
		}
	} catch (CKANException ckane) {
		logger.debug("Error " + ckane.getErrorMessages());
		throw ckane;
	} catch (Exception e) {
		throw new SpagoBIRuntimeException("Error while requesting [" + uri + "]", e);
	}
	return jsonResponse;
}
 
Example 6
Source File: SingleClassTest.java    From micro-server with Apache License 2.0 3 votes vote down vote up
@Test
public void runAppAndBasicTest() throws InterruptedException, ExecutionException{
	
	Client client = ClientBuilder.newClient();

	WebTarget resource = client.target("http://localhost:8080/simple-app/single/ping");

	Builder request = resource.request();
	request.accept(MediaType.TEXT_PLAIN);
	assertTrue(request.get().getHeaders().containsKey("Access-Control-Allow-Origin"));
	
	

}
 
Example 7
Source File: RestAgent.java    From micro-server with Apache License 2.0 3 votes vote down vote up
public<T> T post(String url, Object payload,Class<T> type) {
	Client client = ClientBuilder.newClient();

	WebTarget resource = client.target(url);

	Builder request = resource.request();
	request.accept(MediaType.APPLICATION_JSON);

	return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type);
}
 
Example 8
Source File: RestAgent.java    From micro-server with Apache License 2.0 3 votes vote down vote up
public Response postString(String url, String payload) {
	Client client = ClientBuilder.newClient();

	WebTarget resource = client.target(url);

	Builder request = resource.request();
	request.accept(MediaType.APPLICATION_JSON);

	return request.post(Entity.entity(payload,MediaType.APPLICATION_JSON));
}
 
Example 9
Source File: RestAgent.java    From micro-server with Apache License 2.0 3 votes vote down vote up
public String getJson(String url) {

		Client client = ClientBuilder.newClient();

		WebTarget resource = client.target(url);

		Builder request = resource.request();
		request.accept(MediaType.APPLICATION_JSON);

		return request.get(String.class);

	}
 
Example 10
Source File: RestAgent.java    From micro-server with Apache License 2.0 3 votes vote down vote up
public String get(String url) {

		Client client = ClientBuilder.newClient();

		WebTarget resource = client.target(url);

		Builder request = resource.request();
		request.accept(MediaType.APPLICATION_JSON);

		return request.get(String.class);

	}
 
Example 11
Source File: RestAgent.java    From micro-server with Apache License 2.0 3 votes vote down vote up
public Response get(String url) {

		Client client = ClientBuilder.newClient();

		WebTarget resource = client.target(url);

		Builder request = resource.request();
		request.accept(MediaType.APPLICATION_JSON);

		return request.get();

	}
 
Example 12
Source File: RestAgent.java    From micro-server with Apache License 2.0 3 votes vote down vote up
public String getJson(String url) {

		Client client = ClientBuilder.newClient();

		WebTarget resource = client.target(url);

		Builder request = resource.request();
		request.accept(MediaType.APPLICATION_JSON);

		return request.get(String.class);

	}
 
Example 13
Source File: RestAgent.java    From micro-server with Apache License 2.0 3 votes vote down vote up
public Response postString(String url, String payload) {
	Client client = ClientBuilder.newClient();

	WebTarget resource = client.target(url);

	Builder request = resource.request();
	request.accept(MediaType.APPLICATION_JSON);

	return request.post(Entity.entity(payload,MediaType.APPLICATION_JSON));
}
 
Example 14
Source File: RestAgent.java    From micro-server with Apache License 2.0 3 votes vote down vote up
public<T> T post(String url, Object payload,Class<T> type) {
	Client client = ClientBuilder.newClient();

	WebTarget resource = client.target(url);

	Builder request = resource.request();
	request.accept(MediaType.APPLICATION_JSON);

	return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type);
}
 
Example 15
Source File: RestAgent.java    From micro-server with Apache License 2.0 3 votes vote down vote up
public<T> T post(String url, Object payload,Class<T> type) {
	Client client = ClientBuilder.newClient();

	WebTarget resource = client.target(url);

	Builder request = resource.request();
	request.accept(MediaType.APPLICATION_JSON);

	return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type);
}
 
Example 16
Source File: RestAgent.java    From micro-server with Apache License 2.0 3 votes vote down vote up
public<T> T post(String url, Object payload,Class<T> type) {
	Client client = ClientBuilder.newClient();

	WebTarget resource = client.target(url);

	Builder request = resource.request();
	request.accept(MediaType.APPLICATION_JSON);

	return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type);
}
 
Example 17
Source File: RestAgent.java    From micro-server with Apache License 2.0 3 votes vote down vote up
public<T> T post(String url, Object payload,Class<T> type) {
	Client client = ClientBuilder.newClient();

	WebTarget resource = client.target(url);

	Builder request = resource.request();
	request.accept(MediaType.APPLICATION_JSON);

	return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type);
}
 
Example 18
Source File: RestAgent.java    From micro-server with Apache License 2.0 3 votes vote down vote up
public String get(String url) {

        Client client = ClientBuilder.newClient();

        WebTarget resource = client.target(url);

        Builder request = resource.request();
        request.accept(MediaType.TEXT_PLAIN);

        return request.get(String.class);

    }
 
Example 19
Source File: RestAgent.java    From micro-server with Apache License 2.0 3 votes vote down vote up
public Response postString(String url, String payload) {
	Client client = ClientBuilder.newClient();

	WebTarget resource = client.target(url);

	Builder request = resource.request();
	request.accept(MediaType.APPLICATION_JSON);

	return request.post(Entity.entity(payload,MediaType.APPLICATION_JSON));
}
 
Example 20
Source File: RestAgent.java    From micro-server with Apache License 2.0 3 votes vote down vote up
public<T> T post(String url, Object payload,Class<T> type) {
	Client client = ClientBuilder.newClient();

	WebTarget resource = client.target(url);

	Builder request = resource.request();
	request.accept(MediaType.APPLICATION_JSON);

	return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type);
}