javax.ws.rs.client.Client#register ( )源码实例Demo

下面列出了javax.ws.rs.client.Client#register ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: cxf   文件: JAXRS20ClientServerBookTest.java
@Test
public void testGetBookSpecTemplate() {
    String address = "http://localhost:" + PORT + "/bookstore/{a}";
    Client client = ClientBuilder.newClient();
    client.register((Object)ClientFilterClientAndConfigCheck.class);
    client.register(new BTypeParamConverterProvider());
    client.property("clientproperty", "somevalue");
    WebTarget webTarget = client.target(address).path("{b}")
        .resolveTemplate("a", "bookheaders").resolveTemplate("b", "simple");
    Invocation.Builder builder = webTarget.request("application/xml").header("a", new BType());

    Response r = builder.get();
    Book book = r.readEntity(Book.class);
    assertEquals(124L, book.getId());
    assertEquals("b", r.getHeaderString("a"));
}
 
private static Client getJAXRSClient(boolean skipSSLValidation) throws KeyManagementException, NoSuchAlgorithmException {
    ClientBuilder cb = ClientBuilder.newBuilder();

    cb.connectTimeout(10, TimeUnit.SECONDS);

    Client newClient;
    if (skipSSLValidation) {
        SSLContext nullSSLContext = SSLContext.getInstance("TLSv1.2");
        nullSSLContext.init(null, nullTrustManager, null);
        cb.hostnameVerifier(NullHostnameVerifier.INSTANCE)
          .sslContext(nullSSLContext);

        newClient = cb.build();
    } else {
        newClient = cb.build();
    }

    newClient.register(JacksonJsonProvider.class);

    return newClient;
}
 
源代码3 项目: boost   文件: SystemEndpointIT.java
@Test
public void testGetProperties() {
    // String port = System.getProperty("liberty.test.port");
    String port = System.getProperty("boost_http_port");
    // String port = "9000";
    String url = "http://localhost:" + port + "/";

    Client client = ClientBuilder.newClient();
    client.register(JsrJsonpProvider.class);

    WebTarget target = client.target(url + "system/properties");
    Response response = target.request().get();

    assertEquals("Incorrect response code from " + url, 200, response.getStatus());

    JsonObject obj = response.readEntity(JsonObject.class);

    assertEquals("The system property for the local and remote JVM should match", System.getProperty("os.name"),
            obj.getString("os.name"));

    response.close();
}
 
源代码4 项目: boost   文件: SystemEndpointIT.java
@Test
public void testGetProperties() {
    // String port = System.getProperty("liberty.test.port");
    String port = System.getProperty("boost_http_port");
    // String port = "9000";
    String url = "http://localhost:" + port + "/";

    Client client = ClientBuilder.newClient();
    client.register(JsrJsonpProvider.class);

    WebTarget target = client.target(url + "system/properties");
    Response response = target.request().get();

    assertEquals("Incorrect response code from " + url, 200, response.getStatus());

    JsonObject obj = response.readEntity(JsonObject.class);

    assertEquals("The system property for the local and remote JVM should match", System.getProperty("os.name"),
            obj.getString("os.name"));

    response.close();
}
 
源代码5 项目: onos   文件: HttpSBControllerImpl.java
private void authenticate(Client client, RestSBDevice device) {
    AuthenticationScheme authScheme = device.authentication();
    if (authScheme == AuthenticationScheme.NO_AUTHENTICATION) {
        log.debug("{} scheme is specified, ignoring authentication", authScheme);
        return;
    } else if (authScheme == AuthenticationScheme.OAUTH2) {
        String token = checkNotNull(device.token());
        client.register(OAuth2ClientSupport.feature(token));
    } else if (authScheme == AuthenticationScheme.BASIC) {
        String username = device.username();
        String password = device.password() == null ? "" : device.password();
        client.register(HttpAuthenticationFeature.basic(username, password));
    } else {
        // TODO: Add support for other authentication schemes here.
        throw new IllegalArgumentException(String.format("Unsupported authentication scheme: %s",
                authScheme.name()));
    }
}
 
源代码6 项目: tenacity   文件: TenacityAuthenticatorTest.java
@Test
public void shouldNotTransformAuthenticationExceptionIntoMappedException() throws AuthenticationException {
    when(AuthenticatorApp.getMockAuthenticator().authenticate(any(BasicCredentials.class))).thenThrow(new AuthenticationException("test"));
    final Client client = new JerseyClientBuilder(new MetricRegistry())
            .using(executorService, Jackson.newObjectMapper())
            .build("dropwizard-app-rule");

    client.register(HttpAuthenticationFeature.basicBuilder()
            .nonPreemptive()
            .credentials("user", "stuff")
            .build());

    final Response response = client
            .target(URI.create("http://localhost:" + RULE.getLocalPort() + "/auth"))
            .request()
            .get(Response.class);

    assertThat(response.getStatus()).isEqualTo(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());

    verify(AuthenticatorApp.getMockAuthenticator(), times(1)).authenticate(any(BasicCredentials.class));
    verifyZeroInteractions(AuthenticatorApp.getTenacityContainerExceptionMapper());
    verify(AuthenticatorApp.getTenacityExceptionMapper(), times(1)).toResponse(any(HystrixRuntimeException.class));
}
 
源代码7 项目: cxf   文件: JAXRS20ClientServerBookTest.java
@Test
public void testGetSetEntityStreamLambda() {
    String address = "http://localhost:" + PORT + "/bookstore/entityecho";
    String entity = "BOOKSTORE";

    Client client = ClientBuilder.newClient();
    client.register((ClientRequestFilter) context -> {
        context.setEntityStream(new ReplacingOutputStream(context.getEntityStream(), 'X', 'O'));
    });

    WebTarget target = client.target(address);

    Response response = target.request().post(
            Entity.entity(entity.replace('O', 'X'), "text/plain"));
    assertEquals(entity, response.readEntity(String.class));
}
 
源代码8 项目: cubedb   文件: CubeResourceTest.java
@Before
public void setup() throws Exception {
  // create ResourceConfig from Resource class
  ResourceConfig rc = new ResourceConfig();
  MultiCube cube = new MultiCubeTest(null);
  rc.registerInstances(new CubeResource(cube));
  rc.register(JsonIteratorConverter.class);

  // create the Grizzly server instance
  httpServer = GrizzlyHttpServerFactory.createHttpServer(baseUri, rc);
  // start the server
  httpServer.start();

  // configure client with the base URI path
  Client client = ClientBuilder.newClient();
  client.register(JsonIteratorConverter.class);
  webTarget = client.target(baseUri);
}
 
源代码9 项目: cubedb   文件: CubeResourceGeneralTest.java
@Before
public void setup() throws Exception {
  //create ResourceConfig from Resource class
  ResourceConfig rc = new ResourceConfig();
  cube = new MultiCubeImpl(null);
  rc.registerInstances(new CubeResource(cube));
  rc.register(JsonIteratorConverter.class);

  //create the Grizzly server instance
  httpServer = GrizzlyHttpServerFactory.createHttpServer(baseUri, rc);
  //start the server
  httpServer.start();

  //configure client with the base URI path
  Client client = ClientBuilder.newClient();
  client.register(JsonIteratorConverter.class);
  webTarget = client.target(baseUri);
}
 
源代码10 项目: cxf   文件: JAXRS20ClientServerBookTest.java
@Test
public void testGetBookSpec() {
    String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple";
    Client client = ClientBuilder.newClient();
    client.register((Object)ClientFilterClientAndConfigCheck.class);
    client.register(new BTypeParamConverterProvider());
    client.property("clientproperty", "somevalue");
    WebTarget webTarget = client.target(address);
    Invocation.Builder builder = webTarget.request("application/xml").header("a", new BType());

    Response r = builder.get();
    Book book = r.readEntity(Book.class);
    assertEquals(124L, book.getId());
    assertEquals("b", r.getHeaderString("a"));
}
 
源代码11 项目: datacollector   文件: OAuth2ConfigBean.java
public void init(
  Stage.Context context,
  List<Stage.ConfigIssue> issues,
  Client webClient
) throws AuthenticationFailureException, IOException, StageException {

  if (credentialsGrantType == OAuth2GrantTypes.JWT) {
    prepareEL(context, issues);
    if (isRSA()) {
      privateKey = parseRSAKey(key.get(), context, issues);
    }
  }

  if (issues.isEmpty()) {
    String accessToken = obtainAccessToken(webClient);
    if (!accessToken.isEmpty()) {
      String token = parseAccessToken(accessToken);
      if (token.isEmpty()) {
        issues.add(context.createConfigIssue("#0",
            "",
            HTTP_33,
            ACCESS_TOKEN_RFC,
            ACCESS_TOKEN_SF,
            ACCESS_TOKEN_GOOGLE
        ));
      } else {
        filter = new OAuth2HeaderFilter(token);
        webClient.register(filter);
      }
    }
  }
}
 
源代码12 项目: cxf   文件: JAXRS20ClientServerBookTest.java
@Test
public void testGetBookSpecProviderWithFeature() {
    String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple";
    Client client = ClientBuilder.newClient();
    client.register(new ClientTestFeature());
    WebTarget target = client.target(address);
    BookInfo book = target.request("application/xml").get(BookInfo.class);
    assertEquals(124L, book.getId());
    book = target.request("application/xml").get(BookInfo.class);
    assertEquals(124L, book.getId());
}
 
源代码13 项目: micro-server   文件: RestClient.java
protected Client initClient(int rt, int ct) {

		ClientConfig clientConfig = new ClientConfig();
		clientConfig.property(ClientProperties.CONNECT_TIMEOUT, ct);
		clientConfig.property(ClientProperties.READ_TIMEOUT, rt);

		ClientBuilder.newBuilder().register(JacksonFeature.class);
		Client client = ClientBuilder.newClient(clientConfig);
		client.register(JacksonFeature.class);
		JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
		provider.setMapper(JacksonUtil.getMapper());
		client.register(provider);
		return client;

	}
 
源代码14 项目: ee8-sandbox   文件: ObservableClient.java
public final static void main(String[] args) throws Exception {
    Client client = ClientBuilder.newClient();
    
    client.register(RxObservableInvokerProvider.class);
    WebTarget target = client.target("http://localhost:8080/jaxrs-async/rest/ejb");

    target.request()
            .rx(RxObservableInvoker.class)
            .get(String.class)
            .subscribe(new Observer<String>() {
                @Override
                public void onCompleted() {
                    System.out.println("onCompleted");
                }

                @Override
                public void onError(Throwable e) {
                    System.out.println("onError:" + e.getMessage());
                }

                @Override
                public void onNext(String t) {
                    System.out.println("onNext:" + t);
                }
            });

}
 
源代码15 项目: ee8-sandbox   文件: ListenableFutureClient.java
public final static void main(String[] args) throws Exception {
    Client client = ClientBuilder.newClient();

    client.register(RxListenableFutureInvokerProvider.class);
    WebTarget target = client.target("http://localhost:8080/jaxrs-async/rest/ejb");

    ListenableFuture<String> future = target.request()
            .rx(RxListenableFutureInvoker.class)
            .get(String.class);

    FutureCallback<String> callback = new FutureCallback<String>() {
        @Override
        public void onSuccess(String result) {
            System.out.println("result :" + result);
        }

        @Override
        public void onFailure(Throwable t) {
            System.out.println("error :" + t.getMessage());
        }
    };

    Futures.addCallback(future, callback, Executors.newFixedThreadPool(10));

    System.out.println("ListenableFuture:" + future.get());

}
 
源代码16 项目: java-jaxrs   文件: JerseyConfig.java
@Inject
public JerseyConfig(Tracer tracer) {
    Client client = ClientBuilder.newClient();
    client.register(new Builder(tracer).build());

    register(new ServerTracingDynamicFeature.Builder(tracer)
            .build());

    register(new TestHandler(tracer, client));
}
 
源代码17 项目: reladomo-kata   文件: BitemporalBankAPITest.java
private WebTarget webTarget(String path)
{
    Client client = ClientBuilder.newClient();
    client.register(JacksonFeature.class);
    client.register(BitemporalBankJacksonObjectMapperProvider.class);
    return client.target("http://localhost:9998").path(path);
}
 
源代码18 项目: registry   文件: MLModelRegistryClient.java
public MLModelRegistryClient(String catalogURL, Client client) {
    this.modelRegistryURL = String.join("/", catalogURL, "ml", "models");
    this.client = client;
    client.register(MultiPartFeature.class);
}
 
源代码19 项目: hammock   文件: BraveCDIFeature.java
public void configureClient(@Observes @Configuring Client client) {
    client.register(this);
}
 
源代码20 项目: onos   文件: HttpUtil.java
private void authenticate(Client client, String username, String password) {
    client.register(HttpAuthenticationFeature.basic(username, password));

}