Java Code Examples for org.apache.cxf.transports.http.configuration.HTTPClientPolicy#setAutoRedirect()
The following examples show how to use
org.apache.cxf.transports.http.configuration.HTTPClientPolicy#setAutoRedirect() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JettyDigestAuthTest.java From cxf with Apache License 2.0 | 6 votes |
private HTTPConduit setupClient(boolean async) throws Exception { URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl"); greeter = new SOAPService(wsdl, SERVICE_NAME).getPort(Greeter.class); BindingProvider bp = (BindingProvider)greeter; ClientProxy.getClient(greeter).getInInterceptors().add(new LoggingInInterceptor()); ClientProxy.getClient(greeter).getOutInterceptors().add(new LoggingOutInterceptor()); bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ADDRESS); HTTPConduit cond = (HTTPConduit)ClientProxy.getClient(greeter).getConduit(); HTTPClientPolicy client = new HTTPClientPolicy(); cond.setClient(client); if (async) { if (cond instanceof AsyncHTTPConduit) { UsernamePasswordCredentials creds = new UsernamePasswordCredentials("ffang", "pswd"); bp.getRequestContext().put(Credentials.class.getName(), creds); bp.getRequestContext().put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE); client.setAutoRedirect(true); } else { fail("Not an async conduit"); } } else { bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "ffang"); bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pswd"); cond.setAuthSupplier(new DigestAuthSupplier()); } ClientProxy.getClient(greeter).getOutInterceptors() .add(new AbstractPhaseInterceptor<Message>(Phase.PRE_STREAM_ENDING) { public void handleMessage(Message message) throws Fault { Map<String, ?> headers = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS)); if (headers.containsKey("Proxy-Authorization")) { throw new RuntimeException("Should not have Proxy-Authorization"); } } }); client.setAllowChunking(false); return cond; }
Example 2
Source File: HTTPSConduitTest.java From cxf with Apache License 2.0 | 5 votes |
@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); }
Example 3
Source File: UndertowDigestAuthTest.java From cxf with Apache License 2.0 | 4 votes |
private HTTPConduit setupClient(boolean async) throws Exception { URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl"); greeter = new SOAPService(wsdl, SERVICE_NAME).getPort(Greeter.class); BindingProvider bp = (BindingProvider)greeter; ClientProxy.getClient(greeter).getInInterceptors().add(new LoggingInInterceptor()); ClientProxy.getClient(greeter).getOutInterceptors().add(new LoggingOutInterceptor()); bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ADDRESS); HTTPConduit cond = (HTTPConduit)ClientProxy.getClient(greeter).getConduit(); HTTPClientPolicy client = new HTTPClientPolicy(); client.setConnectionTimeout(600000); client.setReceiveTimeout(600000); cond.setClient(client); if (async) { if (cond instanceof AsyncHTTPConduit) { UsernamePasswordCredentials creds = new UsernamePasswordCredentials("ffang", "pswd"); bp.getRequestContext().put(Credentials.class.getName(), creds); bp.getRequestContext().put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE); client.setAutoRedirect(true); } else { fail("Not an async conduit"); } } else { bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "ffang"); bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pswd"); cond.setAuthSupplier(new DigestAuthSupplier()); } ClientProxy.getClient(greeter).getOutInterceptors() .add(new AbstractPhaseInterceptor<Message>(Phase.PRE_STREAM_ENDING) { public void handleMessage(Message message) throws Fault { Map<String, ?> headers = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS)); if (headers.containsKey("Proxy-Authorization")) { throw new RuntimeException("Should not have Proxy-Authorization"); } } }); client.setAllowChunking(false); return cond; }
Example 4
Source File: HTTPSConduitTest.java From cxf with Apache License 2.0 | 4 votes |
/** * This methods tests a basic https connection to Bethal. * It supplies an authorization policy with premetive user/pass * to avoid the 401. */ @Test public void testHttpsBasicConnection() throws Exception { startServer("Bethal"); URL wsdl = getClass().getResource("greeting.wsdl"); assertNotNull("WSDL is null", wsdl); SOAPService service = new SOAPService(wsdl, serviceName); assertNotNull("Service is null", service); Greeter bethal = service.getPort(bethalQ, Greeter.class); assertNotNull("Port is null", bethal); updateAddressPort(bethal, getPort("PORT4")); // Okay, I'm sick of configuration files. // This also tests dynamic configuration of the conduit. Client client = ClientProxy.getClient(bethal); HTTPConduit http = (HTTPConduit) client.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setAutoRedirect(false); // If we set any name, but Edward, Mary, or George, // and a password of "password" we will get through // Bethal. AuthorizationPolicy authPolicy = new AuthorizationPolicy(); authPolicy.setUserName("Betty"); authPolicy.setPassword("password"); http.setClient(httpClientPolicy); http.setTlsClientParameters(tlsClientParameters); http.setAuthorization(authPolicy); configureProxy(client); String answer = bethal.sayHi(); assertTrue("Unexpected answer: " + answer, "Bonjour from Bethal".equals(answer)); assertProxyRequestCount(0); }
Example 5
Source File: HTTPSConduitTest.java From cxf with Apache License 2.0 | 4 votes |
@Test public void testHttpsTrust() throws Exception { startServer("Bethal"); URL wsdl = getClass().getResource("greeting.wsdl"); assertNotNull("WSDL is null", wsdl); SOAPService service = new SOAPService(wsdl, serviceName); assertNotNull("Service is null", service); Greeter bethal = service.getPort(bethalQ, Greeter.class); assertNotNull("Port is null", bethal); updateAddressPort(bethal, getPort("PORT4")); // Okay, I'm sick of configuration files. // This also tests dynamic configuration of the conduit. Client client = ClientProxy.getClient(bethal); HTTPConduit http = (HTTPConduit) client.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setAutoRedirect(false); // If we set any name, but Edward, Mary, or George, // and a password of "password" we will get through // Bethal. AuthorizationPolicy authPolicy = new AuthorizationPolicy(); authPolicy.setUserName("Betty"); authPolicy.setPassword("password"); http.setClient(httpClientPolicy); http.setTlsClientParameters(tlsClientParameters); http.setAuthorization(authPolicy); // Our expected server should be OU=Bethal http.setTrustDecider(new MyHttpsTrustDecider("Bethal")); configureProxy(client); String answer = bethal.sayHi(); assertTrue("Unexpected answer: " + answer, "Bonjour from Bethal".equals(answer)); assertProxyRequestCount(0); // Nobody will not equal OU=Bethal MyHttpsTrustDecider trustDecider = new MyHttpsTrustDecider("Nobody"); http.setTrustDecider(trustDecider); try { answer = bethal.sayHi(); fail("Unexpected answer from Bethal: " + answer); } catch (Exception e) { //e.printStackTrace(); //assertTrue("Trust Decider was not called", // 0 > trustDecider.wasCalled()); } assertProxyRequestCount(0); }
Example 6
Source File: HTTPSConduitTest.java From cxf with Apache License 2.0 | 4 votes |
/** * This tests redirects through Gordy to Bethal. Bethal will * supply a series of 401s. See PushBack401. */ @Test public void testHttpsRedirect401Response() throws Exception { startServer("Gordy"); startServer("Bethal"); URL wsdl = getClass().getResource("greeting.wsdl"); assertNotNull("WSDL is null", wsdl); SOAPService service = new SOAPService(wsdl, serviceName); assertNotNull("Service is null", service); Greeter gordy = service.getPort(gordyQ, Greeter.class); assertNotNull("Port is null", gordy); updateAddressPort(gordy, getPort("PORT3")); // Okay, I'm sick of configuration files. // This also tests dynamic configuration of the conduit. Client client = ClientProxy.getClient(gordy); HTTPConduit http = (HTTPConduit) client.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setAutoRedirect(true); http.setClient(httpClientPolicy); http.setTlsClientParameters(tlsClientParameters); // We get redirected from Gordy, to Bethal. http.setTrustDecider( new MyHttpsTrustDecider( new String[] {"Gordy", "Bethal"})); // Without preemptive user/pass Bethal returns a // 401 for realm Cronus. If we supply any name other // than Edward, George, or Mary, with the pass of "password" // we should succeed. http.setAuthSupplier( new MyBasicAuthSupplier("Cronus", "Betty", "password")); // We actually get our answer from Bethal at the end of the // redirects. String answer = gordy.sayHi(); assertTrue("Unexpected answer: " + answer, "Bonjour from Bethal".equals(answer)); // The loop auth supplier, // We should die with looping realms. http.setAuthSupplier(new MyBasicAuthSupplier()); try { answer = gordy.sayHi(); fail("Unexpected answer from Gordy: " + answer); } catch (Exception e) { //e.printStackTrace(); } }
Example 7
Source File: ClientPolicyCalculator.java From cxf with Apache License 2.0 | 4 votes |
/** * Returns a new HTTPClientPolicy that is compatible with the two specified * policies or null if no compatible policy can be determined. * * @param p1 one policy * @param p2 another policy * @return the compatible policy */ public HTTPClientPolicy intersect(HTTPClientPolicy p1, HTTPClientPolicy p2) { // incompatibilities if (!compatible(p1, p2)) { return null; } // ok - compute compatible policy 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()); } p.setCookie(StringUtils.combine(p1.getCookie(), p2.getCookie())); p.setDecoupledEndpoint(StringUtils.combine(p1.getDecoupledEndpoint(), p2.getDecoupledEndpoint())); p.setHost(StringUtils.combine(p1.getHost(), p2.getHost())); p.setProxyServer(StringUtils.combine(p1.getProxyServer(), p2.getProxyServer())); if (p1.isSetProxyServerPort()) { p.setProxyServerPort(p1.getProxyServerPort()); } else if (p2.isSetProxyServerPort()) { p.setProxyServerPort(p2.getProxyServerPort()); } if (p1.isSetProxyServerType()) { p.setProxyServerType(p1.getProxyServerType()); } else if (p2.isSetProxyServerType()) { p.setProxyServerType(p2.getProxyServerType()); } p.setReferer(StringUtils.combine(p1.getReferer(), p2.getReferer())); if (p1.isSetConnectionTimeout()) { p.setConnectionTimeout(p1.getConnectionTimeout()); } else if (p2.isSetConnectionTimeout()) { p.setConnectionTimeout(p2.getConnectionTimeout()); } if (p1.isSetConnectionRequestTimeout()) { p.setConnectionRequestTimeout(p1.getConnectionRequestTimeout()); } else if (p2.isSetConnectionRequestTimeout()) { p.setConnectionRequestTimeout(p2.getConnectionRequestTimeout()); } if (p1.isSetReceiveTimeout()) { p.setReceiveTimeout(p1.getReceiveTimeout()); } else if (p2.isSetReceiveTimeout()) { p.setReceiveTimeout(p2.getReceiveTimeout()); } return p; }