/** * Creates WebClient, baseURI will be set to Client currentURI * @param client existing client */ public static WebClient fromClient(Client client) { return fromClient(client, false); }
/** * Creates WebClient, baseURI will be set to Client currentURI * @param client existing client */ public static WebClient fromClient(Client client) { return fromClient(client, false); }
/** * Creates WebClient, baseURI will be set to Client currentURI * @param client existing client */ public static WebClient fromClient(Client client) { return fromClient(client, false); }
/** * 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); }
/** * 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); }
private WebTarget newWebTarget(UriBuilder newBuilder) { WebClient newClient; if (targetClient != null) { newClient = WebClient.fromClient(targetClient); } else { newClient = null; } return new WebTargetImpl(newBuilder, getConfiguration(), newClient); }
private WebTarget newWebTarget(UriBuilder newBuilder) { WebClient newClient; if (targetClient != null) { newClient = WebClient.fromClient(targetClient); } else { newClient = null; } return new WebTargetImpl(newBuilder, getConfiguration(), newClient); }
@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; }
@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; }
@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)); } }
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); } }
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); } }
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); } }
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()); }
@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; }
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()); }
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; }
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); }
@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(); }
@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()); }