org.apache.cxf.jaxrs.client.WebClient.fromClient()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(121)

本文整理了Java中org.apache.cxf.jaxrs.client.WebClient.fromClient()方法的一些代码示例,展示了WebClient.fromClient()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebClient.fromClient()方法的具体详情如下:
包路径:org.apache.cxf.jaxrs.client.WebClient
类名称:WebClient
方法名:fromClient

WebClient.fromClient介绍

[英]Creates WebClient, baseURI will be set to Client currentURI
[中]创建WebClient,baseURI将设置为Client currentURI

代码示例

代码示例来源:origin: apache/cxf

/**
 * Creates WebClient, baseURI will be set to Client currentURI
 * @param client existing client
 */
public static WebClient fromClient(Client client) {
  return fromClient(client, false);
}

代码示例来源:origin: org.apache.cxf/cxf-rt-rs-client

/**
 * Creates WebClient, baseURI will be set to Client currentURI
 * @param client existing client
 */
public static WebClient fromClient(Client client) {
  return fromClient(client, false);
}

代码示例来源:origin: org.apache.cxf/cxf-bundle-jaxrs

/**
 * Creates WebClient, baseURI will be set to Client currentURI
 * @param client existing client
 */
public static WebClient fromClient(Client client) {
  return fromClient(client, false);
}

代码示例来源:origin: org.apache.cxf/cxf-rt-rs-client

/**
 * Creates WebClient, baseURI will be set to Client currentURI
 * @param object existing client object
 */
public static WebClient fromClientObject(Object object) {
  Client client = client(object);
  return client == null ? null : fromClient(client, false);
}

代码示例来源:origin: apache/cxf

/**
 * Creates WebClient, baseURI will be set to Client currentURI
 * @param object existing client object
 */
public static WebClient fromClientObject(Object object) {
  Client client = client(object);
  return client == null ? null : fromClient(client, false);
}

代码示例来源:origin: apache/cxf

private WebTarget newWebTarget(UriBuilder newBuilder) {
  WebClient newClient;
  if (targetClient != null) {
    newClient = WebClient.fromClient(targetClient);
  } else {
    newClient = null;
  }
  return new WebTargetImpl(newBuilder, getConfiguration(), newClient);
}

代码示例来源:origin: org.apache.cxf/cxf-rt-rs-client

private WebTarget newWebTarget(UriBuilder newBuilder) {
  WebClient newClient;
  if (targetClient != null) {
    newClient = WebClient.fromClient(targetClient);
  } else {
    newClient = null;
  }
  return new WebTargetImpl(newBuilder, getConfiguration(), newClient);
}

代码示例来源:origin: hlavki/g-suite-identity-sync

@Override
public GSuiteGroup getGroup(String groupKey) {
  String path = MessageFormat.format("groups/{0}", new Object[]{groupKey});
  WebClient webClient = WebClient.fromClient(directoryApiClient, true);
  webClient.authorization(tokenCache.get());
  GSuiteGroup group = webClient.path(path).get(GSuiteGroup.class);
  return group;
}

代码示例来源:origin: hlavki/g-suite-identity-sync

@Override
public GSuiteUser getUser(String userKey) {
  String path = MessageFormat.format("users/{0}", new Object[]{userKey});
  WebClient webClient = WebClient.fromClient(directoryApiClient, true);
  ClientAccessToken accessToken = tokenCache.get();
  webClient.authorization(accessToken);
  GSuiteUser user = webClient.path(path).get(GSuiteUser.class);
  return user;
}

代码示例来源:origin: hlavki/g-suite-identity-sync

@Override
public void updateUserPassword(String userKey, String password) throws InvalidPasswordException {
  String path = MessageFormat.format("users/{0}", new Object[]{userKey});
  WebClient webClient = WebClient.fromClient(directoryApiClient, true);
  ClientAccessToken accessToken = tokenCache.get();
  webClient.authorization(accessToken);
  GSuiteUser user = new GSuiteUser();
  user.setPassword(password);
  Response response = webClient.path(path).put(user);
  if (response.getStatus() != Response.Status.OK.getStatusCode()) {
    throw new InvalidPasswordException("Can't change password. Response: " + response.readEntity(String.class));
  }
}

代码示例来源:origin: apache/cxf

public AccessTokenValidation validateAccessToken(MessageContext mc,
                         String authScheme,
                         String authSchemeData,
                         MultivaluedMap<String, String> extraProps)
  throws OAuthServiceException {
  WebClient client = WebClient.fromClient(tokenValidatorClient, true);
  MultivaluedMap<String, String> props = new MetadataMap<>();
  props.putSingle(OAuthConstants.AUTHORIZATION_SCHEME_TYPE, authScheme);
  props.putSingle(OAuthConstants.AUTHORIZATION_SCHEME_DATA, authSchemeData);
  if (extraProps != null) {
    props.putAll(extraProps);
  }
  try {
    return client.post(props, AccessTokenValidation.class);
  } catch (WebApplicationException ex) {
    throw new OAuthServiceException(ex);
  }
}

代码示例来源:origin: apache/cxf

public AccessTokenValidation validateAccessToken(MessageContext mc,
                         String authScheme,
                         String authSchemeData,
                         MultivaluedMap<String, String> extraProps)
  throws OAuthServiceException {
  WebClient client = WebClient.fromClient(tokenValidatorClient, true);
  MultivaluedMap<String, String> props = new MetadataMap<>();
  props.putSingle(OAuthConstants.TOKEN_ID, authSchemeData);
  try {
    TokenIntrospection response = client.post(props, TokenIntrospection.class);
    return convertIntrospectionToValidation(response);
  } catch (WebApplicationException ex) {
    throw new OAuthServiceException(ex);
  }
}

代码示例来源:origin: org.apache.cxf/cxf-rt-rs-security-oauth2

public AccessTokenValidation validateAccessToken(MessageContext mc,
                         String authScheme,
                         String authSchemeData,
                         MultivaluedMap<String, String> extraProps)
  throws OAuthServiceException {
  WebClient client = WebClient.fromClient(tokenValidatorClient, true);
  MultivaluedMap<String, String> props = new MetadataMap<>();
  props.putSingle(OAuthConstants.TOKEN_ID, authSchemeData);
  try {
    TokenIntrospection response = client.post(props, TokenIntrospection.class);
    return convertIntrospectionToValidation(response);
  } catch (WebApplicationException ex) {
    throw new OAuthServiceException(ex);
  }
}

代码示例来源:origin: apache/cxf

private void runWebClients(WebClient client, int numberOfClients,
  boolean threadSafe, boolean stateCanBeChanged) throws Exception {
  ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 5, 0, TimeUnit.SECONDS,
                             new ArrayBlockingQueue<Runnable>(10));
  CountDownLatch startSignal = new CountDownLatch(1);
  CountDownLatch doneSignal = new CountDownLatch(numberOfClients);
  for (int i = 1; i <= numberOfClients; i++) {
    WebClient wc = !threadSafe ? WebClient.fromClient(client) : client;
    String bookName = stateCanBeChanged ? Integer.toString(i) : "TheBook";
    String bookHeader = stateCanBeChanged ? "value" + i : "CustomValue";
    executor.execute(new WebClientWorker(wc, bookName, bookHeader,
             startSignal, doneSignal, stateCanBeChanged));
  }
  startSignal.countDown();
  doneSignal.await(60, TimeUnit.SECONDS);
  executor.shutdownNow();
  assertEquals("Not all invocations have completed", 0, doneSignal.getCount());
}

代码示例来源:origin: hlavki/g-suite-identity-sync

@Override
public GroupList getUserGroups(String userKey) {
  WebClient webClient = WebClient.fromClient(directoryApiClient, true).path("groups");
  webClient.authorization(tokenCache.get());
  if (userKey != null) {
    webClient.query("userKey", userKey);
  }
  GroupList groupList = webClient.query("domain", config.getGSuiteDomain()).get(GroupList.class);
  return groupList;
}

代码示例来源:origin: apache/cxf

private void doGetBookWebClient(String address, String username, String password, int expectedStatus) {
  WebClient wc = WebClient.create(address, username, password, null);
  Response r = wc.get();
  assertEquals(expectedStatus, r.getStatus());
  WebClient wc2 = WebClient.fromClient(wc);
  r = wc2.get();
  assertEquals(expectedStatus, r.getStatus());
}

代码示例来源:origin: hlavki/g-suite-identity-sync

private GSuiteUsers readAllUsers(GSuiteUsers parent) {
  WebClient webClient = WebClient.fromClient(directoryApiClient, true).path("users");
  ClientAccessToken accessToken = tokenCache.get();
  webClient.authorization(accessToken);
  GSuiteUsers result;
  webClient.query("domain", config.getGSuiteDomain());
  if (parent != null && parent.getNextPageToken() != null) {
    result = webClient.query("pageToken", parent.getNextPageToken()).get(GSuiteUsers.class);
    result.getUsers().addAll(parent.getUsers());
  } else {
    result = webClient.get(GSuiteUsers.class);
  }
  return result.getNextPageToken() != null ? readAllUsers(result) : result;
}

代码示例来源:origin: apache/syncope

protected static <E extends JAXRSService, T> T getObject(
    final E service, final URI location, final Class<T> resultClass) {
  WebClient webClient = WebClient.fromClient(WebClient.client(service));
  webClient.accept(SyncopeConsoleSession.get().getMediaType()).to(location.toASCIIString(), false);
  return webClient.
      header(RESTHeaders.DOMAIN, SyncopeConsoleSession.get().getDomain()).
      header(HttpHeaders.AUTHORIZATION, "Bearer " + SyncopeConsoleSession.get().getJWT()).
      get(resultClass);
}

代码示例来源:origin: apache/cxf

@Test
public void testGetBook123ProxyFromSpringWildcard() throws Exception {
  ClassPathXmlApplicationContext ctx =
    new ClassPathXmlApplicationContext(new String[] {CLIENT_CONFIG_FILE4});
  Object bean = ctx.getBean("bookService.proxyFactory");
  assertNotNull(bean);
  JAXRSClientFactoryBean cfb = (JAXRSClientFactoryBean) bean;
  BookStore bs = cfb.create(BookStore.class);
  assertEquals("https://localhost:" + PORT, WebClient.client(bs).getBaseURI().toString());
  WebClient wc = WebClient.fromClient(WebClient.client(bs));
  assertEquals("https://localhost:" + PORT, WebClient.client(bs).getBaseURI().toString());
  wc.accept("application/xml");
  wc.path("bookstore/securebooks/123");
  TheBook b = wc.get(TheBook.class);
  assertEquals(b.getId(), 123);
  b = wc.get(TheBook.class);
  assertEquals(b.getId(), 123);
  ctx.close();
}

代码示例来源:origin: apache/cxf

@Test
public void testGetBook123ProxyToWebClient() throws Exception {
  BookStore bs = JAXRSClientFactory.create("https://localhost:" + PORT, BookStore.class,
                       CLIENT_CONFIG_FILE1);
  Book b = bs.getSecureBook("123");
  assertEquals(b.getId(), 123);
  WebClient wc = WebClient.fromClient(WebClient.client(bs));
  wc.path("/bookstore/securebooks/123").accept(MediaType.APPLICATION_XML_TYPE);
  Book b2 = wc.get(Book.class);
  assertEquals(123, b2.getId());
}

相关文章

WebClient类方法