本文整理汇总了Java中javax.ws.rs.client.Client.target方法的典型用法代码示例。如果您正苦于以下问题:Java Client.target方法的具体用法?Java Client.target怎么用?Java Client.target使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.client.Client
的用法示例。
在下文中一共展示了Client.target方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClientBuilder
import javax.ws.rs.client.Client; //导入方法依赖的package包/类
/**
* Gets a client web resource builder.
*
* @param localUrl the URL to access remote resource
* @return web resource builder
*/
public Invocation.Builder getClientBuilder(String localUrl) {
log.info("URL: {}", localUrl);
Client client = ClientBuilder.newClient();
WebTarget wt = client.target(localUrl);
return wt.request(UTF_8);
}
示例2: testMPToken
import javax.ws.rs.client.Client; //导入方法依赖的package包/类
public void testMPToken() {
MPJWTToken mpjwtToken = tokenBuilder.setAudience("Octopus Rest MP").
setSubject("Octopus Test").build();
JWTParameters parameters = JWTParametersBuilder.newBuilderFor(JWTEncoding.JWS)
.withSecretKeyForSigning(jwkManager.getJWKSigningKey())
.build();
String bearerHeader = jwtEncoder.encode(mpjwtToken, parameters);
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:8080/rest-mp/data/hello");
Response response = target.request(MediaType.APPLICATION_JSON)
.header(AUTHORIZATION_HEADER, BEARER + " " + bearerHeader)
.get();
System.out.println("status : " + response.getStatus());
System.out.println(response.readEntity(String.class));
}
示例3: registerUser
import javax.ws.rs.client.Client; //导入方法依赖的package包/类
private static void registerUser(String url, MediaType mediaType) {
System.out.println("Registering user via " + url);
User user = new User(1L, "larrypage");
Client client = ClientBuilder.newClient();
WebTarget target = client.target(url);
Response response = target.request().post(Entity.entity(user, mediaType));
try {
if (response.getStatus() != 200) {
throw new RuntimeException("Failed with HTTP error code : " + response.getStatus());
}
System.out.println("Successfully got result: " + response.readEntity(String.class));
} finally {
response.close();
client.close();
}
}
示例4: getNlp
import javax.ws.rs.client.Client; //导入方法依赖的package包/类
static NLP getNlp(String deckID) {
Client client = ClientBuilder.newClient();
String hostIp = "https://nlpstore.experimental.slidewiki.org/nlp/" + deckID;
WebTarget webTarget = client.target(hostIp);
NLP nlp = webTarget
.request(MediaType.APPLICATION_JSON)
.get(NLP.class);
if (nlp == null) {
hostIp = "https://nlpservice.experimental.slidewiki.org/nlp/nlpForDeck/" + deckID;
webTarget = client.target(hostIp);
nlp = webTarget
.queryParam(DBPEDIA_SPOTLIGHT_CONFIDENCE_FOR_SLIDE, SPOTLIGHT_CONFIDENCE_FOR_SLIDE_VALUE)
.queryParam(DBPEDIA_SPOTLIGHT_CONFIDENCE_FOR_DECK, SPOTLIGHT_CONFIDENCE_FOR_DECK_VALUE)
.request(MediaType.APPLICATION_JSON)
.get(NLP.class);
}
return nlp;
}
示例5: getInvocationBuilder
import javax.ws.rs.client.Client; //导入方法依赖的package包/类
protected Builder getInvocationBuilder(String url, Map<String, String> queryParameters) {
ClientConfig clientConfig = new ClientConfig();
if (getProxyAddress() != null) {
clientConfig.connectorProvider(new ApacheConnectorProvider());
clientConfig.property(ClientProperties.PROXY_URI, getProxyAddress());
}
Client client = ClientBuilder.newClient(clientConfig);
client.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
WebTarget webTarget = client.target(url);
if (queryParameters != null) {
for (Map.Entry<String, String> queryParameter: queryParameters.entrySet())
// webTarget = webTarget.queryParam(queryParameter.getKey(), queryParameter.getValue().replace("_", "_1").replace("%", "_0"));
webTarget = webTarget.queryParam(queryParameter.getKey(), queryParameter.getValue());
}
return webTarget.request(MediaType.APPLICATION_JSON).accept("application/ld+json").header("Authorization", getCloudTokenValue());
}
示例6: testJaxRSOptionsDeleteTypes
import javax.ws.rs.client.Client; //导入方法依赖的package包/类
@Test
@RunAsClient
public void testJaxRSOptionsDeleteTypes() throws Exception {
logger.info("start JaxRS options delete test");
Client client = newClient();
WebTarget target = client.target(url + "services/receiver/options");
Response response = target.request().options();
String calledMethod = response.getHeaderString("calledMethod");
double value = response.readEntity(Double.class);
assertEquals("options implemented: ", 88.99, value, 0.0);
client.close();
assertEquals("The filter registerCall is called only for @Logged services", OPTIONS, calledMethod);
client = newClient();
target = client.target(url + "services/receiver/delete");
response = target.request().delete();
calledMethod = response.getHeaderString("calledMethod");
value = response.readEntity(Double.class);
assertEquals("delete implemented: ", 99.66, value, 0.0);
client.close();
assertEquals("The filter registerCall is called only for @Logged services", DELETE, calledMethod);
client = newClient();
target = client.target(url + "services/receiver/header");
Builder builder = target.request().header("my_new_header", "Hi all");
response = builder.get();
calledMethod = response.getHeaderString("calledMethod");
String valueStr = response.readEntity(String.class);
assertEquals("head implemented: ", "Hi all", valueStr);
client.close();
assertNotEquals("The filter registerCall is called only for @Logged services", HEAD, calledMethod);
client = newClient();
target = client.target(url + "services/receiver/headerWithContext");
builder = target.request(TEXT_PLAIN).header("my_new_header", "Hi allll");
response = builder.get();
calledMethod = response.getHeaderString("calledMethod");
valueStr = response.readEntity(String.class);
assertEquals("head implemented: ", "Hi allll", valueStr);
client.close();
assertNotEquals("The filter registerCall is called only for @Logged services", HEAD, calledMethod);
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:40,代码来源:OtherTestCase.java
示例7: getUser
import javax.ws.rs.client.Client; //导入方法依赖的package包/类
private static void getUser(String url) {
System.out.println("Getting user via " + url);
Client client = ClientBuilder.newClient();
WebTarget target = client.target(url);
Response response = target.request().get();
try {
if (response.getStatus() != 200) {
throw new RuntimeException("Failed with HTTP error code : " + response.getStatus());
}
System.out.println("Successfully got result: " + response.readEntity(String.class));
} finally {
response.close();
client.close();
}
}
示例8: tccCoordinatorClient
import javax.ws.rs.client.Client; //导入方法依赖的package包/类
@Bean
public WebTarget tccCoordinatorClient() {
Client client = ClientBuilder.newClient();
client.register(new JacksonJaxbJsonProvider());
client.register(new TransactionProvider());
WebTarget target = client.target(tccCoordinatorBaseUrl);
return target.path("/coordinator");
}
开发者ID:jotorren,项目名称:microservices-transactions-tcc,代码行数:9,代码来源:CompositeTransactionConfiguration.java
示例9: setUp
import javax.ws.rs.client.Client; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
// start the server
server = Server.startServer();
// create the client
Client c = ClientBuilder.newClient();
target = c.target(Server.BASE_URI);
}
示例10: getMyResourceJarStyles
import javax.ws.rs.client.Client; //导入方法依赖的package包/类
@Test
public void getMyResourceJarStyles() throws MalformedURLException {
Client client = newClient();
WebTarget target = client.target(create(new URL(base, "styles.css").toExternalForm()));
Response response = target.request().get();
assertThat(response.getStatus(), is(equalTo(200)));
String style = response.readEntity(String.class);
assertThat(style, startsWith("body {"));
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:12,代码来源:ResourcePackagingTestCase.java
示例11: testSwaggerJson
import javax.ws.rs.client.Client; //导入方法依赖的package包/类
@Test
public void testSwaggerJson() {
Client client = JerseyClientBuilder.createClient();
WebTarget target = client.target("http://localhost:" + port + "/docs");
Response response = target.request().get();
Assert.assertEquals(200, response.getStatus());
Assert.assertNotNull(response.getEntity());
Assert.assertEquals("application/json", response.getMediaType().toString());
}
示例12: setUp
import javax.ws.rs.client.Client; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
// start the server
server = Main.startServer();
// create the client
Client c = ClientBuilder.newClient();
// uncomment the following line if you want to enable
// support for JSON in the client (you also have to uncomment
// dependency on jersey-media-json module in pom.xml and Main.startServer())
// --
// c.configuration().enable(new org.glassfish.jersey.media.json.JsonJaxbFeature());
target = c.target(Main.BASE_URI);
}
示例13: sendRequest
import javax.ws.rs.client.Client; //导入方法依赖的package包/类
public Response sendRequest(String url, String requestType) {
Client client = ClientBuilder.newClient();
System.out.println("Testing " + url);
WebTarget target = client.target(url);
Invocation.Builder invoBuild = target.request();
Response response = invoBuild.build(requestType).invoke();
return response;
}
示例14: getGreeting
import javax.ws.rs.client.Client; //导入方法依赖的package包/类
private static Greeting getGreeting(String url, String token, String from) {
Client client = ClientBuilder.newClient();
try {
WebTarget target = client.target(url);
System.out.println("URL : " + url);
target.register((ClientRequestFilter) requestContext -> {
requestContext.getHeaders().add("Authorization", "Bearer " + token);
});
IGreeting greetingClient = ((ResteasyWebTarget) target).proxy(IGreeting.class);
return greetingClient.greeting(from);
} finally {
client.close();
}
}
示例15: testSwaggerJson
import javax.ws.rs.client.Client; //导入方法依赖的package包/类
@Test
public void testSwaggerJson() {
Client client = new ResteasyClientBuilder().build();
WebTarget target = client.target("http://localhost:" + port + "/docs");
Response response = target.request().get();
Assert.assertEquals(200, response.getStatus());
Assert.assertNotNull(response.readEntity(String.class));
Assert.assertEquals("application/json", response.getMediaType().toString());
}
开发者ID:holon-platform,项目名称:holon-jaxrs,代码行数:10,代码来源:TestSwaggerResteasyAutoConfigurationResource.java