当前位置: 首页>>代码示例>>Java>>正文


Java Client类代码示例

本文整理汇总了Java中javax.ws.rs.client.Client的典型用法代码示例。如果您正苦于以下问题:Java Client类的具体用法?Java Client怎么用?Java Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Client类属于javax.ws.rs.client包,在下文中一共展示了Client类的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: 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

示例3: dumpSwitches

import javax.ws.rs.client.Client; //导入依赖的package包/类
/**
 * Returns Switches through Topology-Engine-Rest service.
 *
 * @return The JSON document of all flows
 */
public static List<SwitchInfoData> dumpSwitches() throws Exception {
    System.out.println("\n==> Topology-Engine Dump Switches");

    Client client = ClientBuilder.newClient(new ClientConfig());

    Response response = client
            .target(topologyEndpoint)
            .path("/api/v1/topology/switches")
            .request()
            .header(HttpHeaders.AUTHORIZATION, authHeaderValue)
            .get();

    System.out.println(String.format("===> Response = %s", response.toString()));

    List<SwitchInfoData> switches = new ObjectMapper().readValue(
            response.readEntity(String.class), new TypeReference<List<SwitchInfoData>>() {});
    System.out.println(String.format("====> Data = %s", switches));

    return switches;
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:26,代码来源:SwitchesUtils.java

示例4: executeAction

import javax.ws.rs.client.Client; //导入依赖的package包/类
private Result executeAction(Action action, Object lraInfo, String lraUri) {
    log.infof("executing action - %s", action);

    Client client = ClientBuilder.newClient();
    URI build = UriBuilder
            .fromUri(servicesLocator.getServiceUri(action.getService()))
            .path(API_PREFIX)
            .path(action.getType().getPath())
            .build();
    log.info("action request url - " + build);
    WebTarget target = client.target(build);

    Response response = target.request().header(LRAClient.LRA_HTTP_HEADER, lraUri).post(Entity.json(lraInfo));
    log.info("Result of action - " + response.readEntity(String.class));

    Result result = response.getStatus() == Response.Status.OK.getStatusCode() ? Result.COMPLETED : Result.NEED_COMPENSATION;

    response.close();

    return result;
}
 
开发者ID:xstefank,项目名称:lra-service,代码行数:22,代码来源:LRAExecutor.java

示例5: start

import javax.ws.rs.client.Client; //导入依赖的package包/类
public TestServiceRunner start() {

        ServiceConfig serviceConfigwithProps = serviceConfig.addPropertiesAndApplyToBindings(propertyMap);
        ServiceConfig serviceConfigWithContext = ServiceConfigInitializer.finalize(serviceConfigwithProps);
        JerseyConfig jerseyConfig = new JerseyConfig(serviceConfigWithContext.serviceDefinition)
                .addRegistrators(serviceConfigWithContext.registrators)
                .addBinders(serviceConfigWithContext.binders);
        serviceConfigWithContext.addons.forEach(it -> it.addToJerseyConfig(jerseyConfig));

        DeploymentContext context = DeploymentContext.builder(jerseyConfig.getResourceConfig()).build();
        URI uri = UriBuilder.fromUri("http://localhost/").port(0).build();
        TestContainer testContainer = new InMemoryTestContainerFactory().create(uri, context);
        testContainer.start();
        ClientConfig clientConfig = testContainer.getClientConfig();
        ClientGenerator clientGenerator = clientConfigurator.apply(
                ClientGenerator.defaults(serviceConfigWithContext.serviceDefinition)
                        .clientConfigBase(clientConfig)
        );
        Client client = clientGenerator.generate();

        Runtime runtime = new Runtime(serviceConfigWithContext, jerseyConfig, testContainer, clientConfig, uri, client, stubConfigurator, targetConfigurator);
        return withServiceConfig(serviceConfigWithContext).withRuntime(runtime);
    }
 
开发者ID:code-obos,项目名称:servicebuilder,代码行数:24,代码来源:TestServiceRunner.java

示例6: processRequest

import javax.ws.rs.client.Client; //导入依赖的package包/类
public static Response processRequest(
    String url, String method, String payload, String authHeader) {
  Client client = ClientBuilder.newClient();
  WebTarget target = client.target(url);
  Builder builder = target.request();
  builder.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
  if (authHeader != null) {
    builder.header(HttpHeaders.AUTHORIZATION, authHeader);
  }
  return (payload != null)
      ? builder.build(method, Entity.json(payload)).invoke()
      : builder.build(method).invoke();
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:14,代码来源:LoginResourceTest.java

示例7: removeServer

import javax.ws.rs.client.Client; //导入依赖的package包/类
public boolean removeServer(String url) {
    for (int i = 0; i < serverTargetsList.size(); i++) {
        try {
            if (serverTargetsList.get(i).getUri().getHost().equals(new URI(url).getHost()) ) {
                serverTargetsList.remove(i);
                Client client = serverList.get(i);
                if (client != null) {
                    client.close();
                }
                serverList.remove(i);
                return true;
            }
        } catch (URISyntaxException ex) {
            Logger.getLogger(ConnectorMThreatModuleRest.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    return false;
}
 
开发者ID:P1sec,项目名称:SigFW,代码行数:20,代码来源:ConnectorMThreatModuleRest.java

示例8: testCommit

import javax.ws.rs.client.Client; //导入依赖的package包/类
@Test
public void testCommit() throws SQLException, ClassNotFoundException, NamingException {

    Client client = ClientBuilder.newClient();
    client.target("http://127.0.0.1:8090/rest/test").request().get();

    Class.forName("org.h2.Driver");
    int resultCount = 0;
    try (Connection conn = DriverManager.getConnection("jdbc:h2:~/data/testdb;AUTO_SERVER=TRUE", "SA", "SA")) {
        ResultSet rs = conn.createStatement().executeQuery("SELECT ID, OWNER FROM TASK");

        while (rs.next()) {
            resultCount++;
        }
    }

    Assert.assertEquals(1, resultCount);
}
 
开发者ID:Taskana,项目名称:taskana,代码行数:19,代码来源:TaskanaProducersTest.java

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

示例10: getGreeting

import javax.ws.rs.client.Client; //导入依赖的package包/类
private Greeting getGreeting(String endpoint, String name) {
     String endpointURL = endpoints.get(endpoint);
     Client client = ClientBuilder.newClient();
     try {
         WebTarget target = client.target(endpointURL);
         // Provide the authorization information
         target.register((ClientRequestFilter) requestContext -> {
	requestContext.getHeaders().add("Authorization", "Bearer "+token);
});
         if(cmdArgs.debugLevel > 0)
	target.register(new LoggingFilter());
         IGreeting greetingClient = ((ResteasyWebTarget)target).proxy(IGreeting.class);
         Greeting greeting = greetingClient.greeting(name);
         return greeting;
     } finally {
         client.close();
     }
 }
 
开发者ID:obsidian-toaster-quickstarts,项目名称:redhat-sso,代码行数:19,代码来源:GreetingAuthzClient.java

示例11: shouldFailHealthcheckWhenMsaMetadataUnavailable

import javax.ws.rs.client.Client; //导入依赖的package包/类
@Test
public void shouldFailHealthcheckWhenMsaMetadataUnavailable() {
    wireMockServer.stubFor(
        get(urlEqualTo("/matching-service/metadata"))
            .willReturn(aResponse()
                .withStatus(500)
            )
    );

    applicationTestSupport.before();
    Client client = new JerseyClientBuilder(applicationTestSupport.getEnvironment()).build("test client");

    Response response = client
        .target(URI.create(String.format(HEALTHCHECK_URL, applicationTestSupport.getLocalPort())))
        .request()
        .buildGet()
        .invoke();

    String expectedResult = "\"msaMetadata\":{\"healthy\":false";

    wireMockServer.verify(getRequestedFor(urlEqualTo("/matching-service/metadata")));

    assertThat(response.getStatus()).isEqualTo(INTERNAL_SERVER_ERROR.getStatusCode());
    assertThat(response.readEntity(String.class)).contains(expectedResult);
}
 
开发者ID:alphagov,项目名称:verify-service-provider,代码行数:26,代码来源:MsaMetadataFeatureTest.java

示例12: trafficIsOk

import javax.ws.rs.client.Client; //导入依赖的package包/类
private boolean trafficIsOk(boolean expectedResult) throws Throwable {
    if (isTrafficTestsEnabled()) {
        System.out.println("=====> Send traffic");

        long current = System.currentTimeMillis();
        Client client = ClientBuilder.newClient(new ClientConfig());
        Response result = client
                .target(trafficEndpoint)
                .path("/checkflowtraffic")
                .queryParam("srcswitch", "s1")
                .queryParam("dstswitch", "s8")
                .queryParam("srcport", "1")
                .queryParam("dstport", "1")
                .queryParam("srcvlan", "1000")
                .queryParam("dstvlan", "1000")
                .request()
                .get();

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

        return result.getStatus() == 200;
    } else {
        return expectedResult;
    }
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:27,代码来源:FlowFFRTest.java

示例13: disconnectSwitch

import javax.ws.rs.client.Client; //导入依赖的package包/类
private boolean disconnectSwitch(String switchName) throws Exception {
    System.out.println("\n==> Disconnect Switch");

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

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

    return result.getStatus() == 200;
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:18,代码来源:FlowFFRTest.java

示例14: islDiscovered

import javax.ws.rs.client.Client; //导入依赖的package包/类
private boolean islDiscovered(String switchName, String portNo) throws Throwable {
    System.out.println("\n==> Set ISL Discovered");

    long current = System.currentTimeMillis();
    Client client = ClientBuilder.newClient(new ClientConfig());
    Response result = client
            .target(trafficEndpoint)
            .path("/restorelink")
            .queryParam("switch", switchName)
            .queryParam("port", portNo)
            .request()
            .post(Entity.json(""));

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

    return result.getStatus() == 200;
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:19,代码来源:FlowFFRTest.java

示例15: portUp

import javax.ws.rs.client.Client; //导入依赖的package包/类
private boolean portUp(String switchName, String portNo) throws Throwable {
    System.out.println("\n==> Set Port Up");

    long current = System.currentTimeMillis();
    Client client = ClientBuilder.newClient(new ClientConfig());
    Response result = client
            .target(trafficEndpoint)
            .path("/port/up")
            .queryParam("switch", switchName)
            .queryParam("port", portNo)
            .request()
            .post(Entity.json(""));

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

    return result.getStatus() == 200;
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:19,代码来源:FlowFFRTest.java


注:本文中的javax.ws.rs.client.Client类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。