public String getEndpointAddress() { return wc.getBaseURI().toString(); } }
/** * Moves WebClient to a new baseURI or forwards to new currentURI * @param newAddress new URI * @param forward if true then currentURI will be based on baseURI * @return updated WebClient */ public WebClient to(String newAddress, boolean forward) { getState().setTemplates(null); if (forward) { if (!newAddress.startsWith("/") && !newAddress.startsWith(getBaseURI().toString())) { throw new IllegalArgumentException("Base address can not be preserved"); } resetCurrentBuilder(URI.create(newAddress)); } else { resetBaseAddress(URI.create(newAddress)); } return this; }
/** * Moves WebClient to a new baseURI or forwards to new currentURI * @param newAddress new URI * @param forward if true then currentURI will be based on baseURI * @return updated WebClient */ public WebClient to(String newAddress, boolean forward) { getState().setTemplates(null); if (forward) { if (!newAddress.startsWith("/") && !newAddress.startsWith(getBaseURI().toString())) { throw new IllegalArgumentException("Base address can not be preserved"); } resetCurrentBuilder(URI.create(newAddress)); } else { resetBaseAddress(URI.create(newAddress)); } return this; }
/** * Moves WebClient to a new baseURI or forwards to new currentURI * @param newAddress new URI * @param forward if true then currentURI will be based on baseURI * @return updated WebClient */ public WebClient to(String newAddress, boolean forward) { getState().setTemplates(null); if (forward) { if (!newAddress.startsWith(getBaseURI().toString())) { throw new IllegalArgumentException("Base address can not be preserved"); } resetCurrentBuilder(URI.create(newAddress)); } else { resetBaseAddress(URI.create(newAddress)); } return this; }
private WebClient configureTLS(WebClient client) throws Exception { if (client.getBaseURI().getScheme().startsWith(HTTPS_SCHEME) && !(trustStorePath == null || trustStorePassword ==null)) { HTTPConduit conduit = (HTTPConduit)WebClient.getConfig(client).getConduit(); TLSClientParameters tlsParameters = new TLSClientParameters(); KeyStore trustStore = KeyStore.getInstance("JKS"); trustStore.load(new FileInputStream(trustStorePath), trustStorePassword.toCharArray()); TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); trustFactory.init(trustStore); tlsParameters.setTrustManagers(trustFactory.getTrustManagers()); // allow a hostname mismatch tlsParameters.setDisableCNCheck(true); conduit.setTlsClientParameters(tlsParameters); } return client; }
private static Token getToken(WebClient tokenService, OAuthAccessor accessor, Map<String, String> parameters) throws OAuthServiceException { String header = doGetAuthorizationHeader(accessor, "POST", tokenService.getBaseURI().toString(), parameters); try { tokenService.replaceHeader("Authorization", header); Form form = tokenService.post(null, Form.class); return new Token(form.asMap().getFirst("oauth_token"), form.asMap().getFirst("oauth_token_secret")); } catch (WebApplicationException ex) { throw new OAuthServiceException(ex); } }
/** * Goes back * @param fast if true then goes back to baseURI otherwise to a previous path segment * @return updated WebClient */ public WebClient back(boolean fast) { getState().setTemplates(null); if (fast) { getCurrentBuilder().replacePath(getBaseURI().getPath()); } else { URI uri = getCurrentURI(); if (uri == getBaseURI()) { return this; } List<PathSegment> segments = JAXRSUtils.getPathSegments(uri.getPath(), false); getCurrentBuilder().replacePath(null); for (int i = 0; i < segments.size() - 1; i++) { getCurrentBuilder().path(HttpUtils.fromPathSegment(segments.get(i))); } } return this; }
/** * Goes back * @param fast if true then goes back to baseURI otherwise to a previous path segment * @return updated WebClient */ public WebClient back(boolean fast) { getState().setTemplates(null); if (fast) { getCurrentBuilder().replacePath(getBaseURI().getPath()); } else { URI uri = getCurrentURI(); if (uri == getBaseURI()) { return this; } List<PathSegment> segments = JAXRSUtils.getPathSegments(uri.getPath(), false); getCurrentBuilder().replacePath(null); for (int i = 0; i < segments.size() - 1; i++) { getCurrentBuilder().path(HttpUtils.fromPathSegment(segments.get(i))); } } return this; }
/** * Goes back * @param fast if true then goes back to baseURI otherwise to a previous path segment * @return updated WebClient */ public WebClient back(boolean fast) { getState().setTemplates(null); if (fast) { getCurrentBuilder().replacePath(getBaseURI().getPath()); } else { URI uri = getCurrentURI(); if (uri == getBaseURI()) { return this; } List<PathSegment> segments = JAXRSUtils.getPathSegments(uri.getPath(), false); getCurrentBuilder().replacePath(null); for (int i = 0; i < segments.size() - 1; i++) { getCurrentBuilder().path(HttpUtils.fromPathSegment(segments.get(i))); } } return this; }
client.reset(); switchServerURL(client.getBaseURI().toString(), e); deleteObject(key, false);
client.reset(); switchServerURL(client.getBaseURI().toString()); return saveObject(ctx, false); client.reset(); switchServerURL(client.getBaseURI().toString(), e); return saveObject(ctx);
client.reset(); switchServerURL(client.getBaseURI().toString(), e); deleteObject(key, false);
client.reset(); switchServerURL(client.getBaseURI().toString(), e); return lookupObject(contextKey, false);
client.reset(); switchServerURL(client.getBaseURI().toString(), e); return lookupObject(contextKey, false);
@Test public void testAbsolutePathOne() throws Exception { WebClient wc = WebClient.create("http://localhost:" + PORT + "/one/bookstore/request"); String path = wc.accept("text/plain").get(String.class); assertEquals("Absolute RequestURI is wrong", wc.getBaseURI().toString(), path); }
@Test public void testAbsolutePathTwo() throws Exception { WebClient wc = WebClient.create("http://localhost:" + PORT + "/two/bookstore/request"); String path = wc.accept("text/plain").get(String.class); assertEquals("Absolute RequestURI is wrong", wc.getBaseURI().toString(), path); }
private void doTestGetBook123WebClient(String configFile) throws Exception { WebClient client = WebClient.create("https://localhost:" + PORT, configFile); assertEquals("https://localhost:" + PORT, client.getBaseURI().toString()); client.path("/bookstore/securebooks/123").accept(MediaType.APPLICATION_XML_TYPE); Book b = client.get(Book.class); assertEquals(123, b.getId()); }
@Test public void testGetBook123WebClientFromSpringWildcard() throws Exception { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {CLIENT_CONFIG_FILE5}); Object bean = ctx.getBean("bookService.proxyFactory"); assertNotNull(bean); JAXRSClientFactoryBean cfb = (JAXRSClientFactoryBean) bean; WebClient wc = (WebClient)cfb.create(); assertEquals("https://localhost:" + PORT, wc.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(); }
assertEquals("root", b.getName()); assertEquals("http://localhost:" + PORT1 + "/bookstore", webClient.getBaseURI().toString()); assertEquals("root", b.getName()); assertEquals("http://localhost:" + PORT2 + "/bookstore", webClient.getBaseURI().toString()); assertEquals("root", b.getName()); assertEquals("http://localhost:" + PORT3 + "/bookstore", webClient.getBaseURI().toString());
@Test @Ignore("Works in the studio only if local jaxrs.xsd is updated to have jaxrs:client") public void testGetBook123WebClientFromSpringWildcardOldJaxrsClient() throws Exception { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {CLIENT_CONFIG_FILE_OLD}); Object bean = ctx.getBean("bookService.proxyFactory"); assertNotNull(bean); JAXRSClientFactoryBean cfb = (JAXRSClientFactoryBean) bean; WebClient wc = (WebClient)cfb.create(); assertEquals("https://localhost:" + PORT, wc.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(); }