@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; }
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())); } else if ("AsyncExecuteTimeoutRejection".equals(k)) { 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())); } else if ("AllowChunking".equals(k)) { p.setAllowChunking(Boolean.parseBoolean(v.trim())); } else if ("ChunkingThreshold".equals(k)) { p.setChunkingThreshold(Integer.parseInt(v.trim())); } else if ("ChunkLength".equals(k)) { p.setChunkLength(Integer.parseInt(v.trim())); } else if ("Connection".equals(k)) { p.setConnection(ConnectionType.valueOf(v)); } else if ("DecoupledEndpoint".equals(k)) {
HTTPClientPolicy p = new HTTPClientPolicy(); p.setAccept(StringUtils.combine(p1.getAccept(), p2.getAccept())); p.setAcceptEncoding(StringUtils.combine(p1.getAcceptEncoding(), p2.getAcceptEncoding())); p.setAcceptLanguage(StringUtils.combine(p1.getAcceptLanguage(), p2.getAcceptLanguage())); if (p1.isSetAllowChunking()) { p.setAllowChunking(p1.isAllowChunking()); } else if (p2.isSetAllowChunking()) { p.setAllowChunking(p2.isAllowChunking()); if (p1.isSetAutoRedirect()) { p.setAutoRedirect(p1.isAutoRedirect()); } else if (p2.isSetAutoRedirect()) { p.setAutoRedirect(p2.isAutoRedirect()); p.setBrowserType(StringUtils.combine(p1.getBrowserType(), p2.getBrowserType())); if (p1.isSetCacheControl()) { p.setCacheControl(p1.getCacheControl()); } else if (p2.isSetCacheControl()) { p.setCacheControl(p2.getCacheControl()); if (p1.isSetConnection()) { p.setConnection(p1.getConnection()); } else if (p2.isSetConnection()) { p.setConnection(p2.getConnection()); if (p1.isSetContentType()) { p.setContentType(p1.getContentType()); } else if (p2.isSetContentType()) { p.setContentType(p2.getContentType());
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; }
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); }
@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 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)); }
/** * 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); }
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); }
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 testConnectionWithProxy() throws Exception { QName serviceName = new QName("http://cxf.apache.org/systest/jaxws/", "HelloService"); HelloService service = new HelloService(null, serviceName); assertNotNull(service); Hello hello = service.getHelloPort(); Client client = ClientProxy.getClient(hello); client.getInInterceptors().add(new LoggingInInterceptor()); client.getOutInterceptors().add(new LoggingOutInterceptor()); HTTPConduit http = (HTTPConduit)client.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setAllowChunking(false); httpClientPolicy.setReceiveTimeout(0); httpClientPolicy.setProxyServerType(ProxyServerType.HTTP); httpClientPolicy.setProxyServer("localhost"); httpClientPolicy.setProxyServerPort(PROXY_PORT); http.setClient(httpClientPolicy); ((BindingProvider)hello).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + PORT + "/hello"); assertEquals("getSayHi", hello.sayHi("SayHi")); } }
/** * {@inheritDoc} */ @Override public void onProxyChange(ProxySettings proxySettings) { HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setConnection(ConnectionType.CLOSE); httpClientPolicy.setAllowChunking(true); httpClientPolicy.setCacheControl(ClientCacheControlType.NO_CACHE); if (proxySettings.isEnabled()) { httpClientPolicy.setProxyServer(proxySettings.getProxyHost()); httpClientPolicy.setProxyServerPort(proxySettings.getProxyPort()); httpClientPolicy.setProxyServerType(ProxyServerType.HTTP); } else { httpClientPolicy.setProxyServer(null); httpClientPolicy.unsetProxyServerPort(); httpClientPolicy.setProxyServerType(null); } Client client = ClientProxy.getClient(pronomService); HTTPConduit http = (HTTPConduit) client.getConduit(); http.setClient(httpClientPolicy); }
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); }
Client client = ClientProxy.getClient(XYZSOAPEndPoint); HTTPConduit http = (HTTPConduit) client.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setAllowChunking(false); http.setClient(policy); ((BindingProvider)XYZSOAPEndPoint).getRequestContext().put("schema-validation-enabled",true);
this.client = WebClient.create(uri); this.client = WebClient.create(uri, this.config.getCxfConfigFile()); this.client.header("User-Agent", VersionInfo.info()); HTTPClientPolicy clientPolicy = WebClient.getConfig(this.client).getHttpConduit().getClient(); if (config.getReadTimeout() != 0) { clientPolicy.setReceiveTimeout(config.getReadTimeout()); clientPolicy.setConnectionTimeout(config.getConnectionTimeout()); clientPolicy.setAllowChunking(true); clientPolicy.setChunkLength(4096); clientPolicy.setProxyServer(addr.getHostName()); clientPolicy.setProxyServerPort(addr.getPort());
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); } }
Message outMessage = new MessageImpl(); Exchange exch = new ExchangeImpl(); outMessage.setExchange(exch); exch.put("org.apache.cxf.transport.process_fault_on_http_400", true); //JBWS-3945 if ("Content-Type".equals(mimeHeader.getName())) outMessage.put(Message.CONTENT_TYPE, mimeHeader.getValue()); && c instanceof HTTPConduit) ((HTTPConduit)c).getClient().setAllowChunking(false); continue; outMessage.put(Message.HTTP_REQUEST_METHOD, "POST"); outMessage.put(Message.PROTOCOL_HEADERS, outHeaders); c.prepare(outMessage);
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(); }
public void initialize(String serviceEndpoint, String userName, String password) throws ConnectionException { Object proxy = this.serviceClient; java.util.Map<String, Object> requestContext = ((javax.xml.ws.BindingProvider) proxy) .getRequestContext(); // This will show you how to configure the http conduit dynamically Client client = ClientProxy.getClient(proxy); Bus bus = ((EndpointImpl) client.getEndpoint()).getBus(); bus.getProperties().put("soap.no.validate.parts", true); HTTPConduit http = (HTTPConduit) client.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); http.setClient(httpClientPolicy); if (StringUtils.isNotBlank(userName) && StringUtils.isNotBlank(password)) { requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceEndpoint); requestContext.put(BindingProvider.USERNAME_PROPERTY, userName); requestContext.put(BindingProvider.PASSWORD_PROPERTY, password); } setServiceClient(proxy); }