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

The following examples show how to use javax.ws.rs.client.Invocation.Builder#get() . 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: ApiPagesResourceTest.java    From gravitee-management-rest-api with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldGetNoApiPage() {
    final Builder request = target(API).path("pages").request();
    
    // case 1
    doReturn(false).when(groupService).isUserAuthorizedToAccessApiData(any(), any(), any());
    
    Response response = request.get();
    assertEquals(OK_200, response.getStatus());

    PagesResponse pagesResponse = response.readEntity(PagesResponse.class);
    List<Page> pages = pagesResponse.getData();
    assertNotNull(pages);
    assertEquals(0, pages.size());
    
    // case 2
    doReturn(false).when(groupService).isUserAuthorizedToAccessApiData(any(), any(), any());
    
    response = request.get();
    assertEquals(OK_200, response.getStatus());

    pagesResponse = response.readEntity(PagesResponse.class);
    pages = pagesResponse.getData();
    assertNotNull(pages);
    assertEquals(0, pages.size());
}
 
Example 2
Source File: RestDemoServiceIT.java    From demo-rest-jersey-spring with MIT License 5 votes vote down vote up
@Test
public void testGetLegacyPodcasts() throws JsonGenerationException,
		JsonMappingException, IOException {

	ClientConfig clientConfig = new ClientConfig();
	clientConfig.register(JacksonFeature.class);

	Client client = ClientBuilder.newClient(clientConfig);

	WebTarget webTarget = client
			.target("http://localhost:8888/demo-rest-jersey-spring/legacy/podcasts/");

	Builder request = webTarget.request();
	request.header("Content-type", MediaType.APPLICATION_JSON);

	Response response = request.get();
	Assert.assertTrue(response.getStatus() == 200);

	List<Podcast> podcasts = response
			.readEntity(new GenericType<List<Podcast>>() {
			});

	ObjectMapper mapper = new ObjectMapper();
	System.out.print(mapper.writerWithDefaultPrettyPrinter()
			.writeValueAsString(podcasts));

	Assert.assertTrue("At least one podcast is present in the LEGACY",
			podcasts.size() > 0);
}
 
Example 3
Source File: RestDemoServiceIT.java    From demo-restWS-spring-jersey-jpa2-hibernate with MIT License 5 votes vote down vote up
@Test
public void testGetLegacyPodcasts() throws JsonGenerationException,
		JsonMappingException, IOException {

	ClientConfig clientConfig = new ClientConfig();
	clientConfig.register(JacksonFeature.class);

	Client client = ClientBuilder.newClient(clientConfig);

	WebTarget webTarget = client
			.target("http://localhost:8888/demo-rest-spring-jersey-jpa2-hibernate-0.0.1-SNAPSHOT/legacy/podcasts/");

	Builder request = webTarget.request();
	request.header("Content-type", MediaType.APPLICATION_JSON);

	Response response = request.get();
	Assert.assertTrue(response.getStatus() == 200);

	List<Podcast> podcasts = response
			.readEntity(new GenericType<List<Podcast>>() {
			});

	ObjectMapper mapper = new ObjectMapper();
	System.out.print(mapper.writerWithDefaultPrettyPrinter()
			.writeValueAsString(podcasts));

	Assert.assertTrue("At least one podcast is present in the LEGACY",
			podcasts.size() > 0);
}
 
Example 4
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 5
Source File: SchemaRegisterResourceTest.java    From hermes with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetSchema() {
	Client client = ClientBuilder.newClient();
	WebTarget webTarget = client.target("http://localhost:1248");
	Builder request = webTarget.path("/schema/register").queryParam("id", 142).request();
	String schema = request.get(String.class);
	System.out.println(schema);
	Assert.assertNotNull(schema);
}
 
Example 6
Source File: PrincipalCreator.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private void checkTheExistenceOnGraph(String accessToken, String objectId, String tenantId, Client client) {
    WebTarget resource = client.target(GRAPH_WINDOWS + tenantId);
    Builder request = resource.path("servicePrincipals/" + objectId).queryParam("api-version", GRAPH_API_VERSION).request();
    request.accept(MediaType.APPLICATION_JSON);
    request.header("Authorization", "Bearer " + accessToken);
    try (Response response = request.get()) {
        if (response.getStatus() != HttpStatus.SC_OK) {
            throw new RetryException("Principal with objectId (" + objectId + ") hasn't been created yet");
        }
    }
}
 
Example 7
Source File: SimpleRestClient.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
private Response executeService(Map<String, Object> parameters, String serviceUrl, String userId, RequestTypeEnum type, String mediaType, Object data)
		throws Exception {
	logger.debug("IN");

	MultivaluedMap<String, Object> myHeaders = new MultivaluedHashMap<String, Object>();

	if (!serviceUrl.contains("http") && addServerUrl) {
		logger.debug("Adding the server URL");
		if (serverUrl != null) {
			logger.debug("Executing the dataset from the core so use relative path to service");
			serviceUrl = serverUrl + serviceUrl;
		}
	}

	Client client = ClientBuilder.newBuilder().sslContext(SSLContext.getDefault()).build();

	logger.debug("Service URL to be invoked : " + serviceUrl);
	WebTarget target = client.target(serviceUrl);

	if (parameters != null) {
		Iterator<String> iter = parameters.keySet().iterator();
		while (iter.hasNext()) {
			String param = iter.next();
			LogMF.debug(logger, "Adding parameter [{0}] : [{1}]", param, parameters.get(param));
			target = target.queryParam(param, parameters.get(param));
		}
	}

	logger.debug("Media type : " + mediaType);
	Builder request = target.request(mediaType);

	logger.debug("adding headers");

	addAuthorizations(request, userId, myHeaders);

	logger.debug("Call service");
	Response response = null;

	// provide authentication exactly before of call
	authenticationProvider.provideAuthentication(request, target, myHeaders, data);
	if (type.equals(RequestTypeEnum.POST)) {
		response = request.post(Entity.json(data.toString()));
	} else if (type.equals(RequestTypeEnum.PUT)) {
		response = request.put(Entity.json(data.toString()));
	} else {
		response = request.get();
	}

	logger.debug("Rest query status " + response.getStatus());
	// logger.debug("Rest query status info "+response.getStatusInfo());
	logger.debug("Rest query status getReasonPhrase " + response.getStatusInfo().getReasonPhrase());
	logger.debug("OUT");
	return response;
}
 
Example 8
Source File: OpenIDRequestObjectWithESAlgEmbeddedTest.java    From oxAuth with MIT License 4 votes vote down vote up
@Parameters({ "authorizePath", "userId", "userSecret", "redirectUri", "ES384_keyId", "dnName", "keyStoreFile",
		"keyStoreSecret" })
@Test(dependsOnMethods = "requestParameterMethodES384X509CertStep1")
public void requestParameterMethodES384X509CertStep2(final String authorizePath, final String userId,
		final String userSecret, final String redirectUri, final String keyId, final String dnName,
		final String keyStoreFile, final String keyStoreSecret) throws Exception {
	Builder request = null;
	try {
		OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);

		List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN);
		List<String> scopes = Arrays.asList("openid");
		String nonce = UUID.randomUUID().toString();
		String state = UUID.randomUUID().toString();

		AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId5, scopes,
				redirectUri, nonce);
		authorizationRequest.setState(state);
		authorizationRequest.getPrompts().add(Prompt.NONE);
		authorizationRequest.setAuthUsername(userId);
		authorizationRequest.setAuthPassword(userSecret);

		JwtAuthorizationRequest jwtAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest,
				SignatureAlgorithm.ES384, cryptoProvider);
		jwtAuthorizationRequest.setKeyId(keyId);
		jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.NAME, ClaimValue.createNull()));
		jwtAuthorizationRequest
				.addUserInfoClaim(new Claim(JwtClaimName.NICKNAME, ClaimValue.createEssential(false)));
		jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.EMAIL, ClaimValue.createNull()));
		jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.EMAIL_VERIFIED, ClaimValue.createNull()));
		jwtAuthorizationRequest
				.addUserInfoClaim(new Claim(JwtClaimName.PICTURE, ClaimValue.createEssential(false)));
		jwtAuthorizationRequest
				.addIdTokenClaim(new Claim(JwtClaimName.AUTHENTICATION_TIME, ClaimValue.createNull()));
		jwtAuthorizationRequest.addIdTokenClaim(new Claim(JwtClaimName.AUTHENTICATION_CONTEXT_CLASS_REFERENCE,
				ClaimValue.createValueList(new String[] { ACR_VALUE })));
		String authJwt = jwtAuthorizationRequest.getEncodedJwt();
		authorizationRequest.setRequest(authJwt);
		System.out.println("Request JWT: " + authJwt);

		request = ResteasyClientBuilder.newClient()
				.target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
		request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
		request.header("Accept", MediaType.TEXT_PLAIN);
	} catch (Exception ex) {
		fail(ex.getMessage(), ex);
	}

	Response response = request.get();
	String entity = response.readEntity(String.class);

	showResponse("requestParameterMethodES384X509CertStep2", response, entity);

	assertEquals(response.getStatus(), 302, "Unexpected response code.");
	assertNotNull(response.getLocation(), "Unexpected result: " + response.getLocation());

	try {
		URI uri = new URI(response.getLocation().toString());
		assertNotNull(uri.getFragment(), "Query string is null");

		Map<String, String> params = QueryStringDecoder.decode(uri.getFragment());

		assertNotNull(params.get("access_token"), "The accessToken is null");
		assertNotNull(params.get("scope"), "The scope is null");
		assertNotNull(params.get("state"), "The state is null");
	} catch (URISyntaxException e) {
		fail(e.getMessage(), e);
	}
}
 
Example 9
Source File: UserInfoRestWebServiceEmbeddedTest.java    From oxAuth with MIT License 4 votes vote down vote up
@Parameters({"authorizePath", "userId", "userSecret", "redirectUri"})
@Test(dependsOnMethods = "requestUserInfoHS512Step1")
public void requestUserInfoHS512Step2(final String authorizePath, final String userId, final String userSecret,
                                      final String redirectUri) throws Exception {
    final String state = UUID.randomUUID().toString();

    List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN);
    List<String> scopes = Arrays.asList("openid", "profile", "email");
    String nonce = UUID.randomUUID().toString();

    AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId3, scopes,
            redirectUri, nonce);
    authorizationRequest.setState(state);
    authorizationRequest.getPrompts().add(Prompt.NONE);
    authorizationRequest.setAuthUsername(userId);
    authorizationRequest.setAuthPassword(userSecret);

    OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider();

    JwtAuthorizationRequest jwtAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest,
            SignatureAlgorithm.HS512, clientSecret3, cryptoProvider);
    jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.NAME, ClaimValue.createNull()));
    jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.NICKNAME, ClaimValue.createEssential(false)));
    jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.EMAIL, ClaimValue.createNull()));
    jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.EMAIL_VERIFIED, ClaimValue.createNull()));
    jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.PICTURE, ClaimValue.createEssential(false)));
    String authJwt = jwtAuthorizationRequest.getEncodedJwt();
    authorizationRequest.setRequest(authJwt);
    System.out.println("Request JWT: " + authJwt);

    Builder request = ResteasyClientBuilder.newClient()
            .target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
    request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
    request.header("Accept", MediaType.TEXT_PLAIN);

    Response response = request.get();
    String entity = response.readEntity(String.class);

    showResponse("requestUserInfoHS512Step2", response, entity);

    assertEquals(response.getStatus(), 302, "Unexpected response code.");
    assertNotNull(response.getLocation(), "Unexpected result: " + response.getLocation());

    try {
        URI uri = new URI(response.getLocation().toString());
        assertNotNull(uri.getFragment(), "Query string is null");

        Map<String, String> params = QueryStringDecoder.decode(uri.getFragment());

        assertNotNull(params.get(AuthorizeResponseParam.ACCESS_TOKEN), "The accessToken is null");
        assertNotNull(params.get(AuthorizeResponseParam.SCOPE), "The scope is null");
        assertNotNull(params.get(AuthorizeResponseParam.STATE), "The state is null");
        assertEquals(params.get(AuthorizeResponseParam.STATE), state);

        accessToken7 = params.get(AuthorizeResponseParam.ACCESS_TOKEN);
    } catch (URISyntaxException e) {
        e.printStackTrace();
        fail("Response URI is not well formed");
    }
}
 
Example 10
Source File: AuthorizeRestWebServiceEmbeddedTest.java    From oxAuth with MIT License 4 votes vote down vote up
@Parameters({"authorizePath", "redirectUri"})
@Test(dependsOnMethods = "dynamicClientRegistration")
public void requestAuthorizationPromptNoneFail(final String authorizePath, final String redirectUri)
        throws Exception {
    final String state = UUID.randomUUID().toString();

    List<ResponseType> responseTypes = Arrays.asList(ResponseType.CODE);
    List<String> scopes = Arrays.asList("openid", "profile", "address", "email");

    AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId1, scopes,
            redirectUri, null);
    authorizationRequest.setState(state);
    authorizationRequest.getPrompts().add(Prompt.NONE);

    Builder request = ResteasyClientBuilder.newClient()
            .target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();

    Response response = request.get();
    String entity = response.readEntity(String.class);

    showResponse("requestAuthorizationPromptNoneFail", response, entity);

    assertEquals(response.getStatus(), 302, "Unexpected response code.");
    assertNotNull(response.getLocation(), "Unexpected result: " + response.getLocation());

    if (response.getLocation() != null) {
        try {
            URI uri = new URI(response.getLocation().toString());
            assertNotNull(uri.getQuery(), "Query is null");

            Map<String, String> params = QueryStringDecoder.decode(uri.getQuery());

            assertNotNull(params.get("error"), "The error value is null");
            assertNotNull(params.get("error_description"), "The errorDescription value is null");
            assertNotNull(params.get(AuthorizeResponseParam.STATE), "The state is null");
            assertEquals(params.get(AuthorizeResponseParam.STATE), state);
        } catch (URISyntaxException e) {
            e.printStackTrace();
            fail("Response URI is not well formed");
        }
    }
}
 
Example 11
Source File: AuthorizeRestWebServiceEmbeddedTest.java    From oxAuth with MIT License 4 votes vote down vote up
@Parameters({"authorizePath", "userId", "userSecret", "redirectUri"})
@Test(dependsOnMethods = "dynamicClientRegistration")
public void requestAuthorizationAccessTokenStep1(final String authorizePath, final String userId,
                                                 final String userSecret, final String redirectUri) throws Exception {
    final String state = UUID.randomUUID().toString();

    List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN);
    List<String> scopes = Arrays.asList("openid", "profile", "address", "email");
    String nonce = UUID.randomUUID().toString();

    AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId1, scopes,
            redirectUri, nonce);
    authorizationRequest.setState(state);
    authorizationRequest.getPrompts().add(Prompt.NONE);
    authorizationRequest.setAuthUsername(userId);
    authorizationRequest.setAuthPassword(userSecret);

    Builder request = ResteasyClientBuilder.newClient()
            .target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
    request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
    request.header("Accept", MediaType.TEXT_PLAIN);

    Response response = request.get();
    String entity = response.readEntity(String.class);

    showResponse("requestAuthorizationAccessTokenStep1", response, entity);

    assertEquals(response.getStatus(), 302, "Unexpected response code.");
    assertNotNull(response.getLocation(), "Unexpected result: " + response.getLocation());

    if (response.getLocation() != null) {
        try {
            URI uri = new URI(response.getLocation().toString());
            assertNotNull(uri.getFragment(), "Fragment is null");

            Map<String, String> params = QueryStringDecoder.decode(uri.getFragment());

            assertNotNull(params.get(AuthorizeResponseParam.ACCESS_TOKEN), "The access token is null");
            assertNotNull(params.get(AuthorizeResponseParam.STATE), "The state is null");
            assertNotNull(params.get(AuthorizeResponseParam.TOKEN_TYPE), "The token type is null");
            assertNotNull(params.get(AuthorizeResponseParam.EXPIRES_IN), "The expires in value is null");
            assertNotNull(params.get(AuthorizeResponseParam.SCOPE), "The scope must be null");
            assertNull(params.get("refresh_token"), "The refresh_token must be null");
            assertEquals(params.get(AuthorizeResponseParam.STATE), state);

            accessToken2 = params.get("access_token");
        } catch (URISyntaxException e) {
            e.printStackTrace();
            fail("Response URI is not well formed");
        }
    }
}
 
Example 12
Source File: ResponseTypesRestrictionEmbeddedTest.java    From oxAuth with MIT License 4 votes vote down vote up
/**
 * Client read request to verify the Client using the
 * <code>code and id_token</code> response types.
 */
@Parameters({"registerPath"})
@Test(dependsOnMethods = "responseTypesCodeIdTokenStep1")
public void responseTypesCodeIdTokenStep2(final String registerPath) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + registerPath + "?"
            + registrationClientUri2.substring(registrationClientUri2.indexOf("?") + 1)).request();
    request.header("Authorization", "Bearer " + registrationAccessToken2);

    Response response = request.get();
    String entity = response.readEntity(String.class);

    showResponse("responseTypesCodeIdTokenStep2", response, entity);

    assertEquals(response.getStatus(), 200, "Unexpected response code. " + entity);
    assertNotNull(entity, "Unexpected result: " + entity);
    try {
        JSONObject jsonObj = new JSONObject(entity);
        assertTrue(jsonObj.has(RegisterResponseParam.CLIENT_ID.toString()));
        assertTrue(jsonObj.has(CLIENT_SECRET.toString()));
        assertTrue(jsonObj.has(CLIENT_ID_ISSUED_AT.toString()));
        assertTrue(jsonObj.has(CLIENT_SECRET_EXPIRES_AT.toString()));

        // Registered Metadata
        assertTrue(jsonObj.has(RESPONSE_TYPES.toString()));
        assertNotNull(jsonObj.optJSONArray(RESPONSE_TYPES.toString()));
        Set<String> responseTypes = new HashSet<String>();
        for (int i = 0; i < jsonObj.getJSONArray(RESPONSE_TYPES.toString()).length(); i++) {
            responseTypes.add(jsonObj.getJSONArray(RESPONSE_TYPES.toString()).getString(i));
        }
        assertTrue(responseTypes
                .containsAll(Arrays.asList(ResponseType.CODE.toString(), ResponseType.ID_TOKEN.toString())));
        assertTrue(jsonObj.has(REDIRECT_URIS.toString()));
        assertTrue(jsonObj.has(APPLICATION_TYPE.toString()));
        assertTrue(jsonObj.has(CLIENT_NAME.toString()));
        assertTrue(jsonObj.has(ID_TOKEN_SIGNED_RESPONSE_ALG.toString()));
        assertTrue(jsonObj.has(SCOPE.toString()));
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage() + "\nResponse was: " + entity);
    }
}
 
Example 13
Source File: AuthorizeRestWebServiceEmbeddedTest.java    From oxAuth with MIT License 4 votes vote down vote up
@Parameters({"authorizePath", "userId", "userSecret", "redirectUri"})
@Test(dependsOnMethods = "dynamicClientRegistration")
public void requestAuthorizationTokenIdToken(final String authorizePath, final String userId,
                                             final String userSecret, final String redirectUri) throws Exception {
    final String state = UUID.randomUUID().toString();

    List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN);
    List<String> scopes = Arrays.asList("openid", "profile", "address", "email");
    String nonce = UUID.randomUUID().toString();

    AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId1, scopes,
            redirectUri, nonce);
    authorizationRequest.setState(state);
    authorizationRequest.getPrompts().add(Prompt.NONE);
    authorizationRequest.setAuthUsername(userId);
    authorizationRequest.setAuthPassword(userSecret);

    Builder request = ResteasyClientBuilder.newClient()
            .target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
    request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
    request.header("Accept", MediaType.TEXT_PLAIN);

    Response response = request.get();
    String entity = response.readEntity(String.class);

    showResponse("requestAuthorizationTokenIdToken", response, entity);

    assertEquals(response.getStatus(), 302, "Unexpected response code.");
    assertNotNull(response.getLocation(), "Unexpected result: " + response.getLocation());

    if (response.getLocation() != null) {
        try {
            URI uri = new URI(response.getLocation().toString());
            assertNotNull(uri.getFragment(), "Fragment is null");

            Map<String, String> params = QueryStringDecoder.decode(uri.getFragment());

            assertNotNull(params.get(AuthorizeResponseParam.ACCESS_TOKEN), "The access token is null");
            assertNotNull(params.get(AuthorizeResponseParam.TOKEN_TYPE), "The token type is null");
            assertNotNull(params.get(AuthorizeResponseParam.ID_TOKEN), "The id token is null");
            assertNotNull(params.get(AuthorizeResponseParam.STATE), "The state is null");
            assertEquals(params.get(AuthorizeResponseParam.STATE), state);
        } catch (URISyntaxException e) {
            e.printStackTrace();
            fail("Response URI is not well formed");
        }
    }
}
 
Example 14
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 15
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 16
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 17
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 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 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 20
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);

	}