本文整理汇总了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"));
}
示例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"));
}
示例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);
}
示例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"));
}
示例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"));
}
示例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"));
}
示例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"));
}
示例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();
}
示例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"));
}
示例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"));
}
示例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"));
}
示例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;
}
示例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());
}
示例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"));
}
示例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);
}