本文整理匯總了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