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


Java Client.target方法代碼示例

本文整理匯總了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);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:13,代碼來源:RestClient.java

示例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));

    }
 
開發者ID:atbashEE,項目名稱:atbash-octopus,代碼行數:20,代碼來源:MPTokenBean.java

示例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();
    }
}
 
開發者ID:flychao88,項目名稱:dubbocloud,代碼行數:18,代碼來源:RestClient.java

示例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;
}
 
開發者ID:slidewiki,項目名稱:auto-questions-service,代碼行數:19,代碼來源:NLPServiceClient.java

示例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());
	}
 
開發者ID:Smartlogic-Semaphore-Limited,項目名稱:Java-APIs,代碼行數:20,代碼來源:OEClientReadOnly.java

示例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();
    }
}
 
開發者ID:zhuxiaolei,項目名稱:dubbo2,代碼行數:16,代碼來源:RestClient.java

示例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);
}
 
開發者ID:ryyan,項目名稱:http-bench,代碼行數:10,代碼來源:EchoResourceTest.java

示例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());
}
 
開發者ID:holon-platform,項目名稱:holon-jaxrs,代碼行數:10,代碼來源:TestSwaggerJerseyAutoDetectCfg.java

示例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);
}
 
開發者ID:YMonnier,項目名稱:docker-restful-java,代碼行數:16,代碼來源:MyResourceTest.java

示例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;
}
 
開發者ID:IBM,項目名稱:microservices-traffic-management-using-istio,代碼行數:9,代碼來源:EndpointTest.java

示例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();
    }
}
 
開發者ID:obsidian-toaster-quickstarts,項目名稱:redhat-sso,代碼行數:15,代碼來源:SsoIT.java

示例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


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