當前位置: 首頁>>代碼示例>>Java>>正文


Java ClientBuilder類代碼示例

本文整理匯總了Java中javax.ws.rs.client.ClientBuilder的典型用法代碼示例。如果您正苦於以下問題:Java ClientBuilder類的具體用法?Java ClientBuilder怎麽用?Java ClientBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ClientBuilder類屬於javax.ws.rs.client包,在下文中一共展示了ClientBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: verifyInjectedRawTokenStandard

import javax.ws.rs.client.ClientBuilder; //導入依賴的package包/類
@RunAsClient
@Test(groups = TEST_GROUP_CDI,
    description = "Verify that the injected raw token claim using @Claim(standard) is as expected")
public void verifyInjectedRawTokenStandard() throws Exception {
    Reporter.log("Begin verifyInjectedRawTokenStandard\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedRawTokenStandard";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.raw_token.name(), token)
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
開發者ID:eclipse,項目名稱:microprofile-jwt-auth,代碼行數:19,代碼來源:ClaimValueInjectionTest.java

示例2: testRegister

import javax.ws.rs.client.ClientBuilder; //導入依賴的package包/類
/**
 * Test if after registration of service they can be found in registry.
 */
@Test
public void testRegister() {
	 Response response1 = ClientBuilder.newBuilder().build().target("http://localhost:" 
			 + getTomcatPort() + "/test/rest/services/service1/abbaasd")
			 .request(MediaType.APPLICATION_JSON).put(Entity.text(""));
	 Assert.assertTrue(response1.getStatus() == Response.Status.OK.getStatusCode());
	 Response response2 = ClientBuilder.newBuilder().build().target("http://localhost:" 
			 + getTomcatPort() + "/test/rest/services/service1/abbaasd2")
			 .request(MediaType.APPLICATION_JSON).put(Entity.text(""));
	 Assert.assertTrue(response2.getStatus() == Response.Status.OK.getStatusCode());
	 Response response = ClientBuilder.newBuilder().build().target("http://localhost:" 
			 + getTomcatPort() + "/test/rest/services/service1").request(MediaType.APPLICATION_JSON).get();
	 Assert.assertTrue(response.getStatus() == Response.Status.OK.getStatusCode());
	 List<String> list = response.readEntity(new GenericType<List<String>>() { }); 
	 Assert.assertTrue(list != null);
	 Assert.assertTrue(list.size() == 2);
	 Assert.assertTrue(list.get(0).equals("abbaasd"));
	 Assert.assertTrue(list.get(1).equals("abbaasd2"));
}
 
開發者ID:DescartesResearch,項目名稱:Pet-Supply-Store,代碼行數:23,代碼來源:RegistryTest.java

示例3: RadioBrowser

import javax.ws.rs.client.ClientBuilder; //導入依賴的package包/類
/** Custom constructor for mocked unit testing.
 * @param apiUrl the base URL of the API.
 * @param timeout the timeout in milliseconds for connecting
 *                and reading.
 * @param myUserAgent the user agent string to use.
 * */
RadioBrowser(final String apiUrl,
                     final int timeout,
                     final String myUserAgent) {
    if (timeout <= 0) {
        throw new IllegalArgumentException(
                "timeout must be > 0, but is "
                        + timeout);
    }
    this.userAgent = Objects.requireNonNull(myUserAgent,
            "User agent is null");
    Client client = ClientBuilder.newBuilder()
            .register(JacksonFeature.class)
            .build();
    client.property(ClientProperties.CONNECT_TIMEOUT, timeout);
    client.property(ClientProperties.READ_TIMEOUT,    timeout);
    webTarget = client.target(apiUrl);
}
 
開發者ID:sfuhrm,項目名稱:radiobrowser4j,代碼行數:24,代碼來源:RadioBrowser.java

示例4: verifyInjectedAudienceStandard

import javax.ws.rs.client.ClientBuilder; //導入依賴的package包/類
@RunAsClient
@Test(groups = TEST_GROUP_CDI,
    description = "Verify that the injected aud claim using @Claim(standard) is as expected")
public void verifyInjectedAudienceStandard() throws Exception {
    Reporter.log("Begin verifyInjectedAudienceStandard\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedAudienceStandard";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.aud.name(), "s6BhdRkqt3")
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    System.out.println(reply);
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
開發者ID:eclipse,項目名稱:microprofile-jwt-auth,代碼行數:20,代碼來源:ClaimValueInjectionTest.java

示例5: verifyInjectedCustomInteger2

import javax.ws.rs.client.ClientBuilder; //導入依賴的package包/類
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
    description = "Verify that the injected customInteger claim is as expected")
public void verifyInjectedCustomInteger2() throws Exception {
    Reporter.log("Begin verifyInjectedCustomInteger\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedCustomInteger";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam("value", 123456789)
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
開發者ID:eclipse,項目名稱:microprofile-jwt-auth,代碼行數:19,代碼來源:ProviderInjectionTest.java

示例6: verifyInjectedCustomString2

import javax.ws.rs.client.ClientBuilder; //導入依賴的package包/類
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
    description = "Verify that the injected customString claim is as expected")
public void verifyInjectedCustomString2() throws Exception {
    Reporter.log("Begin verifyInjectedCustomString\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedCustomString";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam("value", "customStringValue")
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
開發者ID:eclipse,項目名稱:microprofile-jwt-auth,代碼行數:19,代碼來源:ProviderInjectionTest.java

示例7: verifyInjectedCustomDouble2

import javax.ws.rs.client.ClientBuilder; //導入依賴的package包/類
@RunAsClient
@Test(groups = TEST_GROUP_CDI_JSON,
    description = "Verify that the injected customDouble claim is as expected")
public void verifyInjectedCustomDouble2() throws Exception {
    Reporter.log("Begin verifyInjectedCustomDouble2\n");
    String token2 = TokenUtils.generateTokenString("/Token2.json");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedCustomDouble";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam("value", 3.241592653589793)
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token2).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
開發者ID:eclipse,項目名稱:microprofile-jwt-auth,代碼行數:20,代碼來源:JsonValueInjectionTest.java

示例8: testGet

import javax.ws.rs.client.ClientBuilder; //導入依賴的package包/類
@Test
public void testGet() throws Exception {
    Server server = createServer();
    server.start();
    WebTarget client1 = ClientBuilder.newClient().target("http://localhost:8384/Hello");
    WebTarget client2 = ClientBuilder.newClient().target("http://localhost:8384/World");
    /*
    Mono<String> get1 = fromCompletionStage(client1.request().rx().get(String.class));
    Mono<String> get2 = fromCompletionStage(client2.request().rx().get(String.class));
    List<String> result = Mono
        .from(get1)
        .concatWith(get2)
        .doOnError(ex -> ex.printStackTrace())
        .collectList()
        .block(Duration.ofMillis(1500));
    String resultSt = result.stream().collect(Collectors.joining(" "));
    org.junit.Assert.assertEquals("Hello World", resultSt);
    */
    server.stop();
}
 
開發者ID:cschneider,項目名稱:reactive-components,代碼行數:21,代碼來源:TestRs.java

示例9: verifyInjectedSubjectStandard

import javax.ws.rs.client.ClientBuilder; //導入依賴的package包/類
@RunAsClient
@Test(groups = TEST_GROUP_CDI,
    description = "Verify that the injected sub claim using @Claim(standard) is as expected")
public void verifyInjectedSubjectStandard() throws Exception {
    Reporter.log("Begin verifyInjectedSubjectStandard\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedSubjectStandard";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.sub.name(), "24400320")
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
開發者ID:eclipse,項目名稱:microprofile-jwt-auth,代碼行數:19,代碼來源:ClaimValueInjectionTest.java

示例10: verifyInjectedOptionalAuthTime

import javax.ws.rs.client.ClientBuilder; //導入依賴的package包/類
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
    description = "Verify that the injected raw token claim is as expected")
public void verifyInjectedOptionalAuthTime() throws Exception {
    Reporter.log("Begin verifyInjectedOptionalAuthTime\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedOptionalAuthTime";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
開發者ID:eclipse,項目名稱:microprofile-jwt-auth,代碼行數:18,代碼來源:ProviderInjectionTest.java

示例11: verifyInjectedRawToken

import javax.ws.rs.client.ClientBuilder; //導入依賴的package包/類
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
    description = "Verify that the injected raw token claim is as expected")
public void verifyInjectedRawToken() throws Exception {
    Reporter.log("Begin verifyInjectedRawToken\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedRawToken";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.raw_token.name(), token)
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
開發者ID:eclipse,項目名稱:microprofile-jwt-auth,代碼行數:19,代碼來源:PrimitiveInjectionTest.java

示例12: connectSwitch

import javax.ws.rs.client.ClientBuilder; //導入依賴的package包/類
private boolean connectSwitch(String switchName, String controller) throws Exception {
    System.out.println("\n==> Connect Switch");

    long current = System.currentTimeMillis();
    Client client = ClientBuilder.newClient(new ClientConfig());
    Response result = client
            .target(trafficEndpoint)
            .path("/reviveswitch")
            .queryParam("switch", switchName)
            .queryParam("controller", "tcp:" + controller + ":6653")
            .request()
            .post(Entity.json(""));

    System.out.println(String.format("===> Response = %s", result.toString()));
    System.out.println(String.format("===> Connect Switch Time: %,.3f", getTimeDuration(current)));

    return result.getStatus() == 200;
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:19,代碼來源:FlowFFRTest.java

示例13: generateClient

import javax.ws.rs.client.ClientBuilder; //導入依賴的package包/類
public <T> T generateClient(Class<T> resource) {
    Client clientToUse = client != null
            ? client
            : ClientBuilder.newClient();

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

    WebTarget webTarget = clientToUse.target(uri);
    if (apiPath != null) {
        webTarget = webTarget.path(apiPath);
    }
    if(throwExceptionForErrors) {
        webTarget.register(ClientErrorResponseFilter.class);
    }
    webTarget.register(RequestIdClientFilter.class);
    webTarget.register(ClientNameFilter.class);
    if (logging) {
        webTarget.register(ClientLogFilter.class);
    }

    return WebResourceFactory.newResource(resource, webTarget, false, headerArg, cookies, new Form());
}
 
開發者ID:code-obos,項目名稱:servicebuilder,代碼行數:23,代碼來源:StubGenerator.java

示例14: verifyInjectedSUB

import javax.ws.rs.client.ClientBuilder; //導入依賴的package包/類
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
    description = "Verify that the injected sub claim is as expected")
public void verifyInjectedSUB() throws Exception {
    Reporter.log("Begin verifyInjectedSUB\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedSUB";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.sub.name(), "24400320")
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
開發者ID:eclipse,項目名稱:microprofile-jwt-auth,代碼行數:19,代碼來源:PrimitiveInjectionTest.java

示例15: testUnregisterSuccess

import javax.ws.rs.client.ClientBuilder; //導入依賴的package包/類
/**
 * Test if unregistering a service actually removes it from the registry.
 */
@Test
public void testUnregisterSuccess() {
	 Response response1 = ClientBuilder.newBuilder().build().target("http://localhost:" 
			 + getTomcatPort() + "/test/rest/services/service2/abbaasd")
			 .request(MediaType.APPLICATION_JSON).put(Entity.text(""));
	 Assert.assertTrue(response1.getStatus() == Response.Status.OK.getStatusCode());
	 Response response2 = ClientBuilder.newBuilder().build().target("http://localhost:" 
			 + getTomcatPort() + "/test/rest/services/service2/abbaasd")
			 .request(MediaType.APPLICATION_JSON).delete();
	 Assert.assertTrue(response2.getStatus() == Response.Status.OK.getStatusCode());
	 Response response = ClientBuilder.newBuilder().build().target("http://localhost:" 
			 + getTomcatPort() + "/test/rest/services/service2").request(MediaType.APPLICATION_JSON).get();
	 Assert.assertTrue(response.getStatus() == Response.Status.OK.getStatusCode());
	 List<String> list = response.readEntity(new GenericType<List<String>>() { }); 
	 Assert.assertTrue(list != null);
	 Assert.assertTrue(list.size() == 0);
}
 
開發者ID:DescartesResearch,項目名稱:Pet-Supply-Store,代碼行數:21,代碼來源:RegistryTest.java


注:本文中的javax.ws.rs.client.ClientBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。