private void applyClientPolicies(Dictionary<String, String> d, HTTPConduit c) { Enumeration<String> keys = d.keys(); HTTPClientPolicy p = c.getClient(); while (keys.hasMoreElements()) { String k = keys.nextElement(); if (k.startsWith("client.")) { if (p == null) { p = new HTTPClientPolicy(); c.setClient(p); p.setConnectionTimeout(Long.parseLong(v.trim())); } else if ("ReceiveTimeout".equals(k)) { p.setReceiveTimeout(Long.parseLong(v.trim())); } else if ("AsyncExecuteTimeout".equals(k)) { p.setAsyncExecuteTimeout(Long.parseLong(v.trim()));
private static void configureConduitFromEndpointInfo(HTTPConduit conduit, EndpointInfo endpointInfo) { if (conduit.getClient() == null) { conduit.setClient(endpointInfo.getTraversedExtensor( new HTTPClientPolicy(), HTTPClientPolicy.class)); } if (conduit.getAuthorization() == null) { conduit.setAuthorization(endpointInfo.getTraversedExtensor( new AuthorizationPolicy(), AuthorizationPolicy.class)); } if (conduit.getProxyAuthorization() == null) { conduit.setProxyAuthorization(endpointInfo.getTraversedExtensor( new ProxyAuthorizationPolicy(), ProxyAuthorizationPolicy.class)); } if (conduit.getTlsClientParameters() == null) { conduit.setTlsClientParameters(endpointInfo.getTraversedExtensor( null, TLSClientParameters.class)); } if (conduit.getTrustDecider() == null) { conduit.setTrustDecider(endpointInfo.getTraversedExtensor(null, MessageTrustDecider.class)); } if (conduit.getAuthSupplier() == null) { conduit.setAuthSupplier(endpointInfo.getTraversedExtensor(null, HttpAuthSupplier.class)); } }
public void apply(HTTPConduit conduit) { if (tlsClientParameters != null) { conduit.setTlsClientParameters(tlsClientParameters); } if (clientPolicy != null) { conduit.setClient(clientPolicy); } if (authSupplier != null) { conduit.setAuthSupplier(authSupplier); } if (proxyAuthorizationPolicy != null) { conduit.setProxyAuthorization(proxyAuthorizationPolicy); } if (authorizationPolicy != null) { conduit.setAuthorization(authorizationPolicy); } } }
HelloService hello = new HelloService(); HelloPortType helloPort = cliente.getHelloPort(); org.apache.cxf.endpoint.Client client = ClientProxy.getClient(helloPort); HTTPConduit http = (HTTPConduit) client.getConduit(); http.getClient().setProxyServer("proxy"); http.getClient().setProxyServerPort(8080); http.getProxyAuthorization().setUserName("user proxy"); http.getProxyAuthorization().setPassword("password proxy");
/** * This call gets called by the HTTPTransportFactory after it * causes an injection of the Spring configuration properties * of this Conduit. */ public void finalizeConfig() { // See if not set by configuration, if there are defaults // in order from the Endpoint, Service, or Bus. configureConduitFromEndpointInfo(this, endpointInfo); logConfig(); if (getClient().getDecoupledEndpoint() != null) { this.endpointInfo.setProperty("org.apache.cxf.ws.addressing.replyto", getClient().getDecoupledEndpoint()); } }
@Override @SuppressWarnings("unchecked") protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException { ClientProxyFactoryBean proxyFactoryBean = new ClientProxyFactoryBean(); proxyFactoryBean.setAddress(url.setProtocol("http").toIdentityString()); proxyFactoryBean.setServiceClass(serviceType); proxyFactoryBean.setBus(bus); T ref = (T) proxyFactoryBean.create(); Client proxy = ClientProxy.getClient(ref); HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT)); policy.setReceiveTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)); conduit.setClient(policy); return ref; }
protected WebClient createWebClient(final String url, final String media) { final List< ? > providers = Arrays.asList(new JacksonJsonProvider()); final WebClient wc = WebClient .create("http://localhost:" + getPort() + url, providers) .accept(media); WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(8000L); return wc; }
@Test public void testPostEmptyBook() { String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple"; WebClient wc = createWebClientPost(address); WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(1000000); Book book = wc.post(null, Book.class); assertEquals(124L, book.getId()); validatePostResponse(wc, false, true); }
@Test public void testBookExistsServerAddressOverwriteWithQuery() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/books/checkNQuery?a=b"; WebClient wc = WebClient.create(address); WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000); wc.accept("text/plain").type("text/plain"); assertTrue(wc.post("s", Boolean.class)); }
public static void disableSslChecks(WebClient webClient) { HTTPConduit conduit = WebClient.getConfig(webClient) .getHttpConduit(); TLSClientParameters params = conduit.getTlsClientParameters(); if (params == null) { params = new TLSClientParameters(); conduit.setTlsClientParameters(params); } params.setTrustManagers(new TrustManager[]{new TrustEverythingSSLTrustManager()}); params.setDisableCNCheck(true); }
protected void prepare(Object client) { final Client cl = ClientProxy.getClient(client); if (isLogging()) { cl.getInInterceptors().add(new LoggingInInterceptor()); cl.getOutInterceptors().add(new LoggingOutInterceptor()); } final HTTPConduit http = (HTTPConduit) cl.getConduit(); final HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setReceiveTimeout(getTimeOut()); httpClientPolicy.setAllowChunking(false); httpClientPolicy.setConnectionTimeout(getTimeOut()); http.setClient(httpClientPolicy); }
public void configureProxy(Client client) { HTTPConduit cond = (HTTPConduit)client.getConduit(); HTTPClientPolicy pol = cond.getClient(); if (pol == null) { pol = new HTTPClientPolicy(); cond.setClient(pol); } pol.setProxyServer("localhost"); pol.setProxyServerPort(PROXY_PORT); }
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); }
public void connect(TokenHolder tokenHolder) { for (Class<? extends PublicInterface> interface1 : interfaces) { JaxWsProxyFactoryBean cpfb = new JaxWsProxyFactoryBean(); cpfb.setServiceClass(interface1); cpfb.setAddress(address + "/" + interface1.getSimpleName()); Map<String, Object> properties = new HashMap<String, Object>(); properties.put("mtom-enabled", Boolean.TRUE); cpfb.setProperties(properties); PublicInterface serviceInterface = (PublicInterface) cpfb.create(); client = ClientProxy.getClient(serviceInterface); HTTPConduit http = (HTTPConduit) client.getConduit(); http.getClient().setConnectionTimeout(360000); http.getClient().setAllowChunking(false); http.getClient().setReceiveTimeout(320000); if (!useSoapHeaderSessions) { ((BindingProvider) serviceInterface).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE); } add(interface1.getName(), serviceInterface); } tokenHolder.registerTokenChangeListener(this); notifyOfConnect(); }
@Test public void testJaasFilterWebClientAuthorizationPolicy() throws Exception { String endpointAddress = "http://localhost:" + PORT + "/service/jaas2/bookstorestorage/thosebooks/123"; WebClient wc = WebClient.create(endpointAddress); AuthorizationPolicy pol = new AuthorizationPolicy(); pol.setUserName("bob"); pol.setPassword("bobspassword"); WebClient.getConfig(wc).getHttpConduit().setAuthorization(pol); wc.accept("application/xml"); Book book = wc.get(Book.class); assertEquals(123L, book.getId()); }
private void doWork(URL wsdlUrl, String address) { SOAPService service = new SOAPService(wsdlUrl); assertNotNull(service); Greeter greeter = service.getSoapPort(); // overwrite client address InvocationHandler handler = Proxy.getInvocationHandler(greeter); BindingProvider bp = (BindingProvider)handler; bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address); Client client = ClientProxy.getClient(greeter); HTTPConduit c = (HTTPConduit)client.getConduit(); c.setClient(new HTTPClientPolicy()); c.getClient().setConnection(ConnectionType.CLOSE); // invoke twoway call greeter.sayHi(); }
@Test public void testPostAnd401WithText() throws Exception { String endpointAddress = "http://localhost:" + PORT + "/bookstore/post401"; WebClient wc = WebClient.create(endpointAddress); WebClient.getConfig(wc).getHttpConduit().getClient().setAllowChunking(false); Response r = wc.post(null); assertEquals(401, r.getStatus()); assertEquals("This is 401", getStringFromInputStream((InputStream)r.getEntity())); }
URL url = null; try { url = new URL(endpoint + "/wsdl"); } catch (MalformedURLException e) { LOG.error(e.getMessage()); } javax.xml.ws.Service s = MyService.create(url, new QName(MyService.NAMESPACE, MyService.SERVICE)); ServiceSoap port = s.getPort(ServiceSoap.class); Map<String, Object> reqCtx = ((BindingProvider)port).getRequestContext(); reqCtx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint); reqCtx.put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE); reqCtx.put(BindingProvider.SOAPACTION_URI_PROPERTY, actionName); Client client = ClientProxy.getClient(port); HTTPConduit http = (HTTPConduit) client.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setConnection(ConnectionType.CLOSE); http.setClient(httpClientPolicy); TLSClientParameters tls = new TLSClientParameters(); tls.setSSLSocketFactory(sslFactory); tls.setDisableCNCheck(true); http.setTlsClientParameters(tls);
public static void trustAllForHttpConduit(HTTPConduit conduit) { TLSClientParameters tlsClientParams = conduit.getTlsClientParameters(); if (tlsClientParams == null) { tlsClientParams = new TLSClientParameters(); conduit.setTlsClientParameters(tlsClientParams); } tlsClientParams.setTrustManagers(new TrustManager[] { new FakeX509TrustManager() }); tlsClientParams.setDisableCNCheck(true); } }
private void applyTlsClientParameters(Dictionary<String, String> d, HTTPConduit c) { Enumeration<String> keys = d.keys(); TLSClientParameters p = c.getTlsClientParameters(); SecureRandomParameters srp = null; KeyManagersType kmt = null; if (k.startsWith("tlsClientParameters.")) { if (p == null) { p = new TLSClientParameters(); c.setTlsClientParameters(p); p.setSecureSocketProtocol(v); } else if ("sslCacheTimeout".equals(k)) { p.setSslCacheTimeout(Integer.parseInt(v)); } else if ("jsseProvider".equals(k)) { p.setJsseProvider(v);