p.setAsyncExecuteTimeoutRejection(Boolean.parseBoolean(v.trim())); } else if ("AutoRedirect".equals(k)) { p.setAutoRedirect(Boolean.parseBoolean(v.trim())); } else if ("MaxRetransmits".equals(k)) { p.setMaxRetransmits(Integer.parseInt(v.trim()));
SOAPService service = new SOAPService(wsdl, serviceName); WsdlInterfaceClass port = service.getPort(portName, WsdlInterfaceClass.class); Client client = ClientProxy.getClient(port); HTTPConduit http = (HTTPConduit) client.getConduit(); final HTTPClientPolicy policy = httpConduit.getClient(); policy.setAutoRedirect(true);
... HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setAllowChunking(false); httpClientPolicy.setAutoRedirect(true); httpClientPolicy.setConnection(ConnectionType.KEEP_ALIVE); String proxyUrl = "http://proxy.com"; String proxyPortString = "8080"; HTTPConduit http = (HTTPConduit)client.getConduit(); SSLContext sslContext = SSLContext.getInstance("TLSv1"); sslContext.init(null, null, null); HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory()); TLSClientParameters tlsClientParameters = new TLSClientParameters(); tlsClientParameters.setUseHttpsURLConnectionDefaultSslSocketFactory(true); http.setTlsClientParameters(tlsClientParameters); http.setClient(httpClientPolicy);
/** * Initialization of authentication for NTLM which is needed for the Exchange web service. */ @PostConstruct public void init() { LOGGER.info("Initializing authentication."); // Make NTLM work Authenticator.setDefault(new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(ewsUser, ewsPassword.toCharArray()); } }); Client clientProxy = ClientProxy.getClient(exchangeServicePort); HTTPConduit conduit = (HTTPConduit) clientProxy.getConduit(); HTTPClientPolicy client = new HTTPClientPolicy(); // client.setProxyServerPort(8888); // client.setProxyServer("localhost"); // These are needed to make NTLM authentication work. client.setAllowChunking(false); client.setAutoRedirect(true); conduit.setClient(client); }
AbstractWordpressServiceAdapter(final String wordpressUrl, final String apiVersion) { checkNotNull(emptyToNull(apiVersion)); this.apiVersion = apiVersion; // @formatter:off this.spi = JAXRSClientFactory.create(wordpressUrl, this.getSpiType(), Collections.singletonList(new JacksonJsonProvider())); // @formatter:on WebClient.client(spi).type(MediaType.APPLICATION_JSON_TYPE); WebClient.client(spi).accept(MediaType.APPLICATION_JSON_TYPE); // TODO: leave this kind of configuration to API clients WebClient.getConfig(spi).getHttpConduit().getClient().setAutoRedirect(true); /* * TODO: aggregate a configuration object to customize the JAXRS behavior, eg.: adding handlers or interceptors */ WebClient.getConfig(spi).getInInterceptors().add(new LoggingInInterceptor()); WebClient.getConfig(spi).getOutInterceptors().add(new LoggingOutInterceptor()); LOGGER.info("******* {} API initialized *********", spi.getClass().getSimpleName()); }
private void setConnectionProperties(Map<String, Object> configProps, ClientConfiguration clientCfg) { Long connTimeOutValue = getLongValue(configProps.get(HTTP_CONNECTION_TIMEOUT_PROP)); if (connTimeOutValue != null) { clientCfg.getHttpConduit().getClient().setConnectionTimeout(connTimeOutValue); } Long recTimeOutValue = getLongValue(configProps.get(HTTP_RECEIVE_TIMEOUT_PROP)); if (recTimeOutValue != null) { clientCfg.getHttpConduit().getClient().setReceiveTimeout(recTimeOutValue); } Object proxyServerValue = configProps.get(HTTP_PROXY_SERVER_PROP); if (proxyServerValue != null) { clientCfg.getHttpConduit().getClient().setProxyServer((String)proxyServerValue); } Integer proxyServerPortValue = getIntValue(configProps.get(HTTP_PROXY_SERVER_PORT_PROP)); if (proxyServerPortValue != null) { clientCfg.getHttpConduit().getClient().setProxyServerPort(proxyServerPortValue); } Boolean autoRedirectValue = getBooleanValue(configProps.get(HTTP_AUTOREDIRECT_PROP)); if (autoRedirectValue != null) { clientCfg.getHttpConduit().getClient().setAutoRedirect(autoRedirectValue); } Boolean mantainSessionValue = getBooleanValue(configProps.get(HTTP_MAINTAIN_SESSION_PROP)); if (mantainSessionValue != null) { clientCfg.getRequestContext().put(Message.MAINTAIN_SESSION, mantainSessionValue); } }
private void setConnectionProperties(Map<String, Object> configProps, ClientConfiguration clientCfg) { Long connTimeOutValue = getLongValue(configProps.get(HTTP_CONNECTION_TIMEOUT_PROP)); if (connTimeOutValue != null) { clientCfg.getHttpConduit().getClient().setConnectionTimeout(connTimeOutValue); } Long recTimeOutValue = getLongValue(configProps.get(HTTP_RECEIVE_TIMEOUT_PROP)); if (recTimeOutValue != null) { clientCfg.getHttpConduit().getClient().setReceiveTimeout(recTimeOutValue); } Object proxyServerValue = configProps.get(HTTP_PROXY_SERVER_PROP); if (proxyServerValue != null) { clientCfg.getHttpConduit().getClient().setProxyServer((String)proxyServerValue); } Integer proxyServerPortValue = getIntValue(configProps.get(HTTP_PROXY_SERVER_PORT_PROP)); if (proxyServerPortValue != null) { clientCfg.getHttpConduit().getClient().setProxyServerPort(proxyServerPortValue); } Boolean autoRedirectValue = getBooleanValue(configProps.get(HTTP_AUTOREDIRECT_PROP)); if (autoRedirectValue != null) { clientCfg.getHttpConduit().getClient().setAutoRedirect(autoRedirectValue); } Boolean mantainSessionValue = getBooleanValue(configProps.get(HTTP_MAINTAIN_SESSION_PROP)); if (mantainSessionValue != null) { clientCfg.getRequestContext().put(Message.MAINTAIN_SESSION, mantainSessionValue); } }
private void configureTimeouts(P port) { Client client = getClient(port); HTTPConduit conduit = (HTTPConduit) client.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setConnectionTimeout(connectionTimeoutMs); httpClientPolicy.setReceiveTimeout(receiveTimeoutMs); httpClientPolicy.setAutoRedirect(true); httpClientPolicy.setAllowChunking(true); conduit.setClient(httpClientPolicy); }
p.setAutoRedirect(p1.isAutoRedirect()); } else if (p2.isSetAutoRedirect()) { p.setAutoRedirect(p2.isAutoRedirect());
@Test public void testGetBookRelativeUriAutoRedirectNotAllowed() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/redirect/relative?loop=true"; WebClient wc = WebClient.create(address); WebClient.getConfig(wc).getHttpConduit().getClient().setAutoRedirect(true); try { wc.get(); fail("relative Redirect is not allowed"); } catch (ProcessingException ex) { Throwable cause = ex.getCause(); assertTrue(cause.getMessage().contains("Relative Redirect detected on")); } }
@Test public void testGetBookDiffUriAutoRedirect() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/redirect?sameuri=false"; WebClient wc = WebClient.create(address); WebClient.getConfig(wc).getRequestContext().put("http.redirect.same.host.only", "true"); WebClient.getConfig(wc).getHttpConduit().getClient().setAutoRedirect(true); try { wc.get(); fail("Redirect to different host is not allowed"); } catch (ProcessingException ex) { Throwable cause = ex.getCause(); assertTrue(cause.getMessage().contains("Different HTTP Scheme or Host Redirect detected on")); } }
@Test public void testGetBookRelativeUriAutoRedirectLoop() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/redirect/relative?loop=true"; WebClient wc = WebClient.create(address); WebClient.getConfig(wc).getRequestContext().put("http.redirect.relative.uri", "true"); WebClient.getConfig(wc).getHttpConduit().getClient().setAutoRedirect(true); try { wc.get(); fail("Redirect loop must be detected"); } catch (ProcessingException ex) { Throwable cause = ex.getCause(); assertTrue(cause.getMessage().contains("Redirect loop detected on")); } }
@Test public void testGetBookRelativeUriAutoRedirect() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/redirect/relative?loop=false"; WebClient wc = WebClient.create(address); assertEquals(address, wc.getCurrentURI().toString()); WebClient.getConfig(wc).getRequestContext().put("http.redirect.relative.uri", "true"); WebClient.getConfig(wc).getHttpConduit().getClient().setAutoRedirect(true); Response r = wc.get(); Book book = r.readEntity(Book.class); assertEquals(124L, book.getId()); String newAddress = "http://localhost:" + PORT + "/bookstore/redirect/relative?redirect=true"; assertEquals(newAddress, wc.getCurrentURI().toString()); }
@Test public void testGetBookSameUriAutoRedirect() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/redirect?sameuri=true"; WebClient wc = WebClient.create(address); WebClient.getConfig(wc).getHttpConduit().getClient().setAutoRedirect(true); WebClient.getConfig(wc).getRequestContext().put( org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE); Response r = wc.get(); Book book = r.readEntity(Book.class); assertEquals(123L, book.getId()); String requestUri = r.getStringHeaders().getFirst("RequestURI"); assertEquals("http://localhost:" + PORT + "/bookstore/redirect?redirect=true", requestUri); String theCookie = r.getStringHeaders().getFirst("TheCookie"); assertEquals("b", theCookie); }
bp.getRequestContext().put(Credentials.class.getName(), creds); bp.getRequestContext().put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE); client.setAutoRedirect(true); } else { fail("Not an async conduit");
httpClientPolicy.setAutoRedirect(true); httpClientPolicy.setAllowChunking(false);
@Test public void testGetBook123Client() throws Exception { String baseAddress = "http://localhost:" + PORT + "/test/services/rest"; BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress, BookStoreJaxrsJaxws.class); HTTPConduit conduit = (HTTPConduit)WebClient.getConfig(proxy).getConduit(); Book b = proxy.getBook(Long.valueOf("123")); assertEquals(123, b.getId()); assertEquals("CXF in Action", b.getName()); HTTPConduit conduit2 = (HTTPConduit)WebClient.getConfig(proxy).getConduit(); assertSame(conduit, conduit2); conduit.getClient().setAutoRedirect(true); b = proxy.getBook(Long.valueOf("123")); assertEquals(123, b.getId()); assertEquals("CXF in Action", b.getName()); }
@Test public void testHttpsRedirectToHttpFail() throws Exception { startServer("Mortimer"); startServer("Poltim"); URL wsdl = getClass().getResource("greeting.wsdl"); assertNotNull("WSDL is null", wsdl); SOAPService service = new SOAPService(wsdl, serviceName); assertNotNull("Service is null", service); Greeter poltim = service.getPort(poltimQ, Greeter.class); assertNotNull("Port is null", poltim); updateAddressPort(poltim, getPort("PORT2")); // Okay, I'm sick of configuration files. // This also tests dynamic configuration of the conduit. Client client = ClientProxy.getClient(poltim); HTTPConduit http = (HTTPConduit) client.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setAutoRedirect(true); http.setClient(httpClientPolicy); http.setTlsClientParameters(tlsClientParameters); configureProxy(client); poltim.sayHi(); //client -> poltim is https and thus not recorded but then redirected to mortimer //client -> mortimer is http and recoreded assertProxyRequestCount(1); }
((HTTPConduit)c).getClient().setAutoRedirect(true);
httpClientPolicy.setAutoRedirect(false);