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


Java ClientBuilder.newClient方法代码示例

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


在下文中一共展示了ClientBuilder.newClient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getClientBuilder

import javax.ws.rs.client.ClientBuilder; //导入方法依赖的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: CreateMininetTopology

import javax.ws.rs.client.ClientBuilder; //导入方法依赖的package包/类
/**
 * Creates the topology through Mininet.
 *
 * @param json - the json doc that is suitable for the mininet API
 */
public static boolean CreateMininetTopology(String json) {
    System.out.println("\n==> Create Mininet Topology");

    long current = System.currentTimeMillis();
    Client client = ClientBuilder.newClient(new ClientConfig());
    Response result = client
            .target(mininetEndpoint)
            .path("/topology")
            .request(MediaType.APPLICATION_JSON)
            .post(Entity.entity(json, MediaType.APPLICATION_JSON));

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

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

示例3: registerUser

import javax.ws.rs.client.ClientBuilder; //导入方法依赖的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:zhuxiaolei,项目名称:dubbo2,代码行数:18,代码来源:RestClient.java

示例4: dumpLinks

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

    long current = System.currentTimeMillis();
    Client client = ClientBuilder.newClient(new ClientConfig());

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

    System.out.println(String.format("===> Response = %s", response.toString()));
    System.out.println(String.format("===> Topology-Engine Dump Links Time: %,.3f", getTimeDuration(current)));

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

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

示例5: DeleteMininetTopology

import javax.ws.rs.client.ClientBuilder; //导入方法依赖的package包/类
public static boolean DeleteMininetTopology() {
    System.out.println("\n==> Delete Mininet Topology");

    long current = System.currentTimeMillis();
    Client client = ClientBuilder.newClient(new ClientConfig());
    Response result = client
            .target(mininetEndpoint)
            .path("/cleanup")
            .request(MediaType.APPLICATION_JSON)
            .post(null);

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

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

示例6: initialize

import javax.ws.rs.client.ClientBuilder; //导入方法依赖的package包/类
@BeforeClass
public static void initialize() throws Exception {
  injector = Guice.createInjector(new AbstractModule() {
    @Override
    protected void configure() {
      bind(BookResource.class);
    }

    @DefaultConnector
    @Provides
    Configurator configurator() {
      return () -> 0; // port
    }
  }, new WebServerModule(), new HTTPConnectorModule());

  client = ClientBuilder.newClient();
  server = injector.getInstance(Server.class);
  server.start();
}
 
开发者ID:sorskod,项目名称:webserver,代码行数:20,代码来源:BeanParamIntegrationTest.java

示例7: executeAction

import javax.ws.rs.client.ClientBuilder; //导入方法依赖的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

示例8: generate

import javax.ws.rs.client.ClientBuilder; //导入方法依赖的package包/类
public Client generate() {
    ClientConfig clientConfig = clientConfigBase != null
            ? new ClientConfig().loadFrom(clientConfigBase)
            : new ClientConfig();
    final List<JerseyConfig.Binder> binders = new ArrayList<>();
    binders.add(binder -> binder.bind(serviceDefinition).to(ServiceDefinition.class).named(SERVICE_DEFINITION_INJECTION));

    JsonConfig jsonConfig = serviceDefinition.getJsonConfig();
    ObjectMapper mapper = jsonConfig.get();
    JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
    provider.setMapper(mapper);
    clientConfig.register(provider);
    binders.add(binder -> binder.bind(mapper).to(ObjectMapper.class));
    if (! Strings.isNullOrEmpty(clientAppName)) {
        binders.add(binder -> binder.bind(clientAppName).to(String.class).named(ClientNameFilter.CLIENT_APPNAME));
    }
    if (appTokenSupplier != null) {
        binders.add(binder -> binder
                .bind(appTokenSupplier)
                .to(new TypeLiteral<Supplier<String>>() {
                })
                .named(AppTokenClientFilter.APP_TOKEN_SUPPLIER_BIND_NAME)
        );
        clientConfig.register(AppTokenClientFilter.class);
    }

    clientConfig.register(new AbstractBinder() {
        @Override
        protected void configure() {
            binders.forEach(it -> it.addBindings(this));
        }
    });

    return ClientBuilder.newClient(clientConfig);
}
 
开发者ID:code-obos,项目名称:servicebuilder,代码行数:36,代码来源:ClientGenerator.java

示例9: test001

import javax.ws.rs.client.ClientBuilder; //导入方法依赖的package包/类
@Test
void test001() {
  final String generateBasicReqURL = TestPortProvider.generateURL("/rest" + "/security");
  System.out.println("generateBasicReqURL = " + generateBasicReqURL);
  Client client = ClientBuilder.newClient();
  final Invocation.Builder request = client
      .target(generateBasicReqURL)
      .path("check")
      .queryParam("username", "admin")
      .queryParam("password", "admin")
      .request();
  final Response response = request.get();
  Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
  Assert.assertEquals("true", response.readEntity(String.class));
}
 
开发者ID:Java-Publications,项目名称:javamagazin-009-microkernel,代码行数:16,代码来源:LoginRestTest.java

示例10: initialize

import javax.ws.rs.client.ClientBuilder; //导入方法依赖的package包/类
@BeforeClass
public static void initialize() throws Exception {
  injector = Guice.createInjector(new TestModule(), new WebServerModule());

  client = ClientBuilder.newClient();
  server = injector.getInstance(Server.class);
  server.start();
}
 
开发者ID:sorskod,项目名称:webserver,代码行数:9,代码来源:WebServerIntegrationTest.java

示例11: setUp

import javax.ws.rs.client.ClientBuilder; //导入方法依赖的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:Fiware,项目名称:NGSI-LD_Wrapper,代码行数:16,代码来源:MyResourceTest.java

示例12: testEndpoint

import javax.ws.rs.client.ClientBuilder; //导入方法依赖的package包/类
@Test
public void testEndpoint() {
	Client client = ClientBuilder.newClient();
	WebTarget target = client.target("http://localhost:8888/test").path("ping");
	String response = target.request().get(String.class);
	Assert.assertEquals("pong", response);
}
 
开发者ID:holon-platform,项目名称:holon-jaxrs,代码行数:8,代码来源:TestJerseyAutoConfigurationConditional.java

示例13: buildHttpClient

import javax.ws.rs.client.ClientBuilder; //导入方法依赖的package包/类
/**
 * Build the Client used to make HTTP requests.
 * @param debugging Debug setting
 * @return Client
 */
private Client buildHttpClient(boolean debugging) {
  final ClientConfig clientConfig = new ClientConfig();
  clientConfig.register(MultiPartFeature.class);
  clientConfig.register(json);
  clientConfig.register(JacksonFeature.class);
  if (debugging) {
    clientConfig.register(LoggingFilter.class);
  }
  return ClientBuilder.newClient(clientConfig);
}
 
开发者ID:square,项目名称:connect-java-sdk,代码行数:16,代码来源:ApiClient.java

示例14: setup

import javax.ws.rs.client.ClientBuilder; //导入方法依赖的package包/类
@Before
public void setup() throws MalformedURLException {
    client = ClientBuilder.newClient();

    final WebTarget targetAuth = client.target(URI.create(new URL(base, "api/auth/login").toExternalForm()));
    final Response resAuthGetAll = targetAuth.request()
        .accept(MediaType.APPLICATION_JSON)
        .post(form(new Form("username", "user").param("password", "password")));

    assertEquals(200, resAuthGetAll.getStatus());

    String token = resAuthGetAll.getHeaderString(HttpHeaders.AUTHORIZATION);

    client.register(new JwtTokenAuthentication(token.substring(Constants.AUTHORIZATION_PREFIX.length())));
}
 
开发者ID:hantsy,项目名称:javaee8-jaxrs-sample,代码行数:16,代码来源:UserResourceIT.java

示例15: init

import javax.ws.rs.client.ClientBuilder; //导入方法依赖的package包/类
@Before
public void init() {
    this.client = ClientBuilder.newClient();
    this.tut = this.client.target(ADDITION_URI);
}
 
开发者ID:AdamBien,项目名称:javaee-calculator,代码行数:6,代码来源:OperationsResourceIT.java


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