org.apache.cxf.transport.http.HTTPConduit Java Examples

The following examples show how to use org.apache.cxf.transport.http.HTTPConduit. 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: JAXRSSoapBookTest.java    From cxf with Apache License 2.0 7 votes vote down vote up
@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());
}
 
Example #2
Source File: RestUtil.java    From peer-os with Apache License 2.0 7 votes vote down vote up
public static WebClient createTrustedWebClient( String url )
{
    WebClient client = WebClient.create( url );

    HTTPConduit httpConduit = ( HTTPConduit ) WebClient.getConfig( client ).getConduit();

    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout( defaultConnectionTimeout );
    httpClientPolicy.setReceiveTimeout( defaultReceiveTimeout );
    httpClientPolicy.setMaxRetransmits( defaultMaxRetransmits );


    httpConduit.setClient( httpClientPolicy );

    SSLManager sslManager = new SSLManager( null, null, null, null );

    TLSClientParameters tlsClientParameters = new TLSClientParameters();
    tlsClientParameters.setDisableCNCheck( true );
    tlsClientParameters.setTrustManagers( sslManager.getClientFullTrustManagers() );
    httpConduit.setTlsClientParameters( tlsClientParameters );

    return client;
}
 
Example #3
Source File: TransformFeatureTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testClientOutTransformationOnConnectionRefused() throws IOException {
    Service service = Service.create(SERVICE_NAME);
    ServerSocket socket = new ServerSocket(0);
    String endpoint = "http://127.0.0.1:" + socket.getLocalPort() + "/";
    socket.close();
    service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpoint);

    Echo port = service.getPort(PORT_NAME, Echo.class);
    Client client = ClientProxy.getClient(port);
    HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
    // We need to disable chunking to make the client write directly to the connection OutputStream
    httpConduit.getClient().setAllowChunking(false);

    XSLTOutInterceptor outInterceptor = new XSLTOutInterceptor(XSLT_REQUEST_PATH);
    client.getOutInterceptors().add(outInterceptor);

    try {
        port.echo("test");
        fail("Connection refused expected");
    } catch (Exception e) {
        String exceptionMessage = e.getMessage();
        assertTrue(exceptionMessage.toLowerCase().contains("connection refused"));
    }
}
 
Example #4
Source File: JettyDigestAuthTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
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 #5
Source File: RestFolderClient.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
public RestFolderClient(String endpoint, String username, String password, int timeout) {
	super(endpoint, username, password, timeout);

	JacksonJsonProvider provider = new JacksonJsonProvider();

	if ((username == null) || (password == null)) {
		proxy = JAXRSClientFactory.create(endpoint, FolderService.class, Arrays.asList(provider));
	} else {
		// proxy = JAXRSClientFactory.create(endpoint, FolderService.class,
		// Arrays.asList(provider));
		// create(String baseAddress, Class<T> cls, List<?> providers,
		// String username, String password, String configLocation)
		proxy = JAXRSClientFactory.create(endpoint, FolderService.class, Arrays.asList(provider), username,
				password, null);
	}

	if (timeout > 0) {
		HTTPConduit conduit = WebClient.getConfig(proxy).getHttpConduit();
		HTTPClientPolicy policy = new HTTPClientPolicy();
		policy.setReceiveTimeout(timeout);
		conduit.setClient(policy);
	}
}
 
Example #6
Source File: NettyHttpConduitFactory.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public HTTPConduit createConduit(HTTPTransportFactory f,
                                 Bus bus,
                                 EndpointInfo localInfo,
                                 EndpointReferenceType target)
    throws IOException {
    // need to check if the EventLoopGroup is created or not
    // if not create a new EventLoopGroup for it
    EventLoopGroup eventLoopGroup = bus.getExtension(EventLoopGroup.class);
    if (eventLoopGroup == null) {
        final EventLoopGroup group = new NioEventLoopGroup();
        // register a BusLifeCycleListener for it
        bus.setExtension(group, EventLoopGroup.class);
        registerBusLifeListener(bus, group);
    }
    return new NettyHttpConduit(bus, localInfo, target, this);
}
 
Example #7
Source File: RestDocumentClient.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
public RestDocumentClient(String endpoint, String username, String password, int timeout) {
	super(endpoint, username, password, timeout);

	JacksonJsonProvider provider = new JacksonJsonProvider();

	if ((username == null) || (password == null)) {
		proxy = JAXRSClientFactory.create(endpoint, DocumentService.class, Arrays.asList(provider));
	} else {
		proxy = JAXRSClientFactory.create(endpoint, DocumentService.class, Arrays.asList(provider), username,
				password, null);
	}

	if (timeout > 0) {
		HTTPConduit conduit = WebClient.getConfig(proxy).getHttpConduit();
		HTTPClientPolicy policy = new HTTPClientPolicy();
		policy.setReceiveTimeout(timeout);
		conduit.setClient(policy);
	}
}
 
Example #8
Source File: HttpConduitConfigurationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void verifyConduit(HTTPConduit conduit) {
    AuthorizationPolicy authp = conduit.getAuthorization();
    assertNotNull(authp);
    assertEquals("Betty", authp.getUserName());
    assertEquals("password", authp.getPassword());
    TLSClientParameters tlscps = conduit.getTlsClientParameters();
    assertNotNull(tlscps);
    assertTrue(tlscps.isDisableCNCheck());
    assertEquals(3600000, tlscps.getSslCacheTimeout());

    KeyManager[] kms = tlscps.getKeyManagers();
    assertTrue(kms != null && kms.length == 1);
    assertTrue(kms[0] instanceof X509KeyManager);

    TrustManager[] tms = tlscps.getTrustManagers();
    assertTrue(tms != null && tms.length == 1);
    assertTrue(tms[0] instanceof X509TrustManager);

    FiltersType csfs = tlscps.getCipherSuitesFilter();
    assertNotNull(csfs);
    assertEquals(1, csfs.getInclude().size());
    assertEquals(1, csfs.getExclude().size());
    HTTPClientPolicy clientPolicy = conduit.getClient();
    assertEquals(10240, clientPolicy.getChunkLength());
}
 
Example #9
Source File: HttpConduitConfigApplier.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void applyProxyAuthorization(Dictionary<String, String> d, HTTPConduit c) {
    Enumeration<String> keys = d.keys();
    ProxyAuthorizationPolicy p = c.getProxyAuthorization();
    while (keys.hasMoreElements()) {
        String k = keys.nextElement();
        if (k.startsWith("proxyAuthorization.")) {
            if (p == null) {
                p = new ProxyAuthorizationPolicy();
                c.setProxyAuthorization(p);
            }
            String v = d.get(k);
            k = k.substring("proxyAuthorization.".length());

            if ("UserName".equals(k)) {
                p.setUserName(v);
            } else if ("Password".equals(k)) {
                p.setPassword(v);
            } else if ("Authorization".equals(k)) {
                p.setAuthorization(v);
            } else if ("AuthorizationType".equals(k)) {
                p.setAuthorizationType(v);
            }
        }
    }
}
 
Example #10
Source File: JaxwsBasicAuthTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseBasicAuthFromClient() throws Exception {
    // setup the feature by using JAXWS front-end API
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    // set a fake address to kick off the failover feature
    factory.setAddress("http://localhost:" + PORT + "/SoapContext/GreeterPort");
    factory.setServiceClass(Greeter.class);
    Greeter proxy = factory.create(Greeter.class);

    Client clientProxy = ClientProxy.getClient(proxy);
    HTTPConduit conduit = (HTTPConduit) clientProxy.getConduit();
    conduit.getAuthorization().setAuthorizationType("Basic");
    conduit.getAuthorization().setUserName("user");
    conduit.getAuthorization().setPassword("test");
    
    final BindingProvider bindingProvider = (BindingProvider) proxy;
    bindingProvider.getRequestContext().put("encode.basicauth.with.iso8859", true);

    String response = proxy.greetMe("cxf");
    assertThat("CXF is protected: cxf", equalTo(response));
}
 
Example #11
Source File: RestUtil.java    From peer-os with Apache License 2.0 6 votes vote down vote up
public static WebClient createTrustedWebClient( String url, Object provider )
{
    WebClient client = WebClient.create( url, Arrays.asList( provider ) );

    HTTPConduit httpConduit = ( HTTPConduit ) WebClient.getConfig( client ).getConduit();

    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout( defaultConnectionTimeout );
    httpClientPolicy.setReceiveTimeout( defaultReceiveTimeout );
    httpClientPolicy.setMaxRetransmits( defaultMaxRetransmits );


    httpConduit.setClient( httpClientPolicy );

    SSLManager sslManager = new SSLManager( null, null, null, null );

    TLSClientParameters tlsClientParameters = new TLSClientParameters();
    tlsClientParameters.setDisableCNCheck( true );
    tlsClientParameters.setTrustManagers( sslManager.getClientFullTrustManagers() );
    httpConduit.setTlsClientParameters( tlsClientParameters );

    return client;
}
 
Example #12
Source File: CXF6655Test.java    From cxf with Apache License 2.0 6 votes vote down vote up
@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"));

}
 
Example #13
Source File: JaxRsClientStarter.java    From paymentgateway with GNU General Public License v3.0 6 votes vote down vote up
public T start(Class<T> cls, String url, boolean trustAllCerts, String trustStore, String trustStorePassword, 
	List<?> providers, int connectTimeout, int receiveTimeout) {

	try {
		
		T resource = JAXRSClientFactory.create(url, cls, providers);
	    HTTPConduit conduit = WebClient.getConfig(resource).getHttpConduit();
	    WebClient.getConfig(resource).getInInterceptors().add(new LoggingInInterceptor());
	    WebClient.getConfig(resource).getOutInterceptors().add(new LoggingOutInterceptor());
		configureHTTPS(resource, conduit, trustAllCerts, trustStore, trustStorePassword);
		
	    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); 
	    httpClientPolicy.setConnectionTimeout(connectTimeout); 
	    httpClientPolicy.setReceiveTimeout(receiveTimeout); 
	    conduit.setClient(httpClientPolicy);
		
		return resource;
		
	} catch (Exception e) {
		LOG.error(" rest client '{}': NOT STARTED", url);
		return null;
	}
	
}
 
Example #14
Source File: RestTagClient.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
public RestTagClient(String endpoint, String username, String password, int timeout) {
	super(endpoint, username, password, timeout);

	JacksonJsonProvider provider = new JacksonJsonProvider();

	if ((username == null) || (password == null)) {
		proxy = JAXRSClientFactory.create(endpoint, TagService.class, Arrays.asList(provider));
	} else {
		proxy = JAXRSClientFactory.create(endpoint, TagService.class, Arrays.asList(provider), username, password,
				null);
	}

	if (timeout > 0) {
		HTTPConduit conduit = WebClient.getConfig(proxy).getHttpConduit();
		HTTPClientPolicy policy = new HTTPClientPolicy();
		policy.setReceiveTimeout(timeout);
		conduit.setClient(policy);
	}
}
 
Example #15
Source File: HttpConduitConfigApplierTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testTrustVerificationEnabled() throws IOException {
    HttpConduitConfigApplier configApplier = new HttpConduitConfigApplier();

    Dictionary<String, String> configValues = new Hashtable<>();
    configValues.put("tlsClientParameters.disableCNCheck", "true");
    configValues.put("tlsClientParameters.trustManagers.disableTrustVerification", "false");
    String address = "https://localhost:12345";
    Bus bus = new ExtensionManagerBus();
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress(address);
    HTTPConduit conduit = new URLConnectionHTTPConduit(bus, ei, null);

    configApplier.apply(configValues, conduit, address);

    assertNotNull(conduit.getTlsClientParameters().getTrustManagers());
    assertEquals(conduit.getTlsClientParameters().getTrustManagers().length, 1);
    assertFalse(conduit.getTlsClientParameters().getTrustManagers()[0].getClass()
            .getName().startsWith(InsecureTrustManager.class.getName()));
    assertTrue(conduit.getTlsClientParameters().isDisableCNCheck());
}
 
Example #16
Source File: BatchResponse.java    From syncope with Apache License 2.0 6 votes vote down vote up
/**
 * If asynchronous processing was requested, queries the monitor URI.
 *
 * @param monitor monitor URI
 * @param jwt authorization JWT
 * @param boundary mutipart / mixed boundary
 * @param tlsClientParameters (optional) TLS client parameters
 *
 * @return the last Response received from the Batch service
 */
public static Response poll(
        final URI monitor,
        final String jwt,
        final String boundary,
        final TLSClientParameters tlsClientParameters) {

    WebClient webClient = WebClient.create(monitor).
            header(HttpHeaders.AUTHORIZATION, "Bearer " + jwt).
            type(RESTHeaders.multipartMixedWith(boundary.substring(2)));
    if (tlsClientParameters != null) {
        ClientConfiguration config = WebClient.getConfig(webClient);
        HTTPConduit httpConduit = (HTTPConduit) config.getConduit();
        httpConduit.setTlsClientParameters(tlsClientParameters);
    }

    return webClient.get();
}
 
Example #17
Source File: BusShutdownTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #18
Source File: DigestAuthSupplierJettyTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
    WebClient client = WebClient.create("http://localhost:" + DigestAuthSupplierJettyServer.PORT, (String) null);

    assertThrows(NotAuthorizedException.class, () -> client.get(String.class));

    HTTPConduit conduit = WebClient.getConfig(client).getHttpConduit();
    conduit.setAuthSupplier(new DigestAuthSupplier());
    conduit.getAuthorization().setUserName(USER);
    conduit.getAuthorization().setPassword(PWD);

    assertEquals(TestServlet.RESPONSE, client.get(String.class));
}
 
Example #19
Source File: SSLNettyServerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static void setupTLS(Greeter port)
    throws FileNotFoundException, IOException, GeneralSecurityException {
    String keyStoreLoc =
        "/keys/clientstore.jks";
    HTTPConduit httpConduit = (HTTPConduit) ClientProxy.getClient(port).getConduit();

    TLSClientParameters tlsCP = new TLSClientParameters();
    String keyPassword = "ckpass";
    KeyStore keyStore = KeyStore.getInstance("JKS");
    keyStore.load(SSLNettyServerTest.class.getResourceAsStream(keyStoreLoc), "cspass".toCharArray());
    KeyManager[] myKeyManagers = getKeyManagers(keyStore, keyPassword);
    tlsCP.setKeyManagers(myKeyManagers);


    KeyStore trustStore = KeyStore.getInstance("JKS");
    trustStore.load(SSLNettyServerTest.class.getResourceAsStream(keyStoreLoc), "cspass".toCharArray());
    TrustManager[] myTrustStoreKeyManagers = getTrustManagers(trustStore);
    tlsCP.setTrustManagers(myTrustStoreKeyManagers);

    tlsCP.setDisableCNCheck(true);
    httpConduit.setTlsClientParameters(tlsCP);
}
 
Example #20
Source File: JaxRsClientStarter.java    From paymentgateway with GNU General Public License v3.0 6 votes vote down vote up
public T start(Class<T> cls, String url, boolean trustAllCerts, String trustStore, String trustStorePassword, 
	List<?> providers, int connectTimeout, int receiveTimeout) {

	try {
		
		T resource = JAXRSClientFactory.create(url, cls, providers);
	    HTTPConduit conduit = WebClient.getConfig(resource).getHttpConduit();
	    WebClient.getConfig(resource).getInInterceptors().add(new LoggingInInterceptor());
	    WebClient.getConfig(resource).getOutInterceptors().add(new LoggingOutInterceptor());
		configureHTTPS(resource, conduit, trustAllCerts, trustStore, trustStorePassword);
		
	    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); 
	    httpClientPolicy.setConnectionTimeout(connectTimeout); 
	    httpClientPolicy.setReceiveTimeout(receiveTimeout); 
	    conduit.setClient(httpClientPolicy);
		
		return resource;
		
	} catch (Exception e) {
		LOG.error(" rest client '{}': NOT STARTED", url);
		return null;
	}
	
}
 
Example #21
Source File: JaxRsClientStarter.java    From paymentgateway with GNU General Public License v3.0 6 votes vote down vote up
public T start(Class<T> cls, String url, boolean trustAllCerts, String trustStore, String trustStorePassword, 
	List<?> providers, int connectTimeout, int receiveTimeout) {

	try {
		
		T resource = JAXRSClientFactory.create(url, cls, providers);
	    HTTPConduit conduit = WebClient.getConfig(resource).getHttpConduit();
	    WebClient.getConfig(resource).getInInterceptors().add(new LoggingInInterceptor());
	    WebClient.getConfig(resource).getOutInterceptors().add(new LoggingOutInterceptor());
		configureHTTPS(resource, conduit, trustAllCerts, trustStore, trustStorePassword);
		
	    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); 
	    httpClientPolicy.setConnectionTimeout(connectTimeout); 
	    httpClientPolicy.setReceiveTimeout(receiveTimeout); 
	    conduit.setClient(httpClientPolicy);
		
		return resource;
		
	} catch (Exception e) {
		LOG.error(" rest client '{}': NOT STARTED", url);
		return null;
	}
	
}
 
Example #22
Source File: JaxRsClientStarter.java    From paymentgateway with GNU General Public License v3.0 6 votes vote down vote up
public T start(Class<T> cls, String url, boolean trustAllCerts, String trustStore, String trustStorePassword, 
	List<?> providers, int connectTimeout, int receiveTimeout) {

	try {
		
		T resource = JAXRSClientFactory.create(url, cls, providers);
	    HTTPConduit conduit = WebClient.getConfig(resource).getHttpConduit();
	    WebClient.getConfig(resource).getInInterceptors().add(new LoggingInInterceptor());
	    WebClient.getConfig(resource).getOutInterceptors().add(new LoggingOutInterceptor());
		configureHTTPS(resource, conduit, trustAllCerts, trustStore, trustStorePassword);
		
	    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); 
	    httpClientPolicy.setConnectionTimeout(connectTimeout); 
	    httpClientPolicy.setReceiveTimeout(receiveTimeout); 
	    conduit.setClient(httpClientPolicy);
		
		return resource;
		
	} catch (Exception e) {
		LOG.error(" rest client '{}': NOT STARTED", url);
		return null;
	}
	
}
 
Example #23
Source File: HttpConduitConfigApplier.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void applyAuthSupplier(Dictionary<String, String> d, HTTPConduit c) {
    Enumeration<String> keys = d.keys();
    while (keys.hasMoreElements()) {
        String k = keys.nextElement();
        if (k.startsWith("authSupplier")) {
            String v = d.get(k);
            Object obj;
            try {
                obj = Class.forName(v).newInstance();
            } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
            if (obj instanceof HttpAuthSupplier) {
                c.setAuthSupplier((HttpAuthSupplier)obj);
            }
        }
    }
}
 
Example #24
Source File: NettyHttpConduitTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoTimeoutAsync() throws Exception {
    updateAddressPort(g, PORT);
    HTTPConduit c = (HTTPConduit)ClientProxy.getClient(g).getConduit();
    c.getClient().setReceiveTimeout(2000);
    c.getClient().setAsyncExecuteTimeout(2000);

    Response<GreetMeLaterResponse> future = g.greetMeLaterAsync(-100L);
    future.get();
    
    Response<GreetMeLaterResponse> future2 = g.greetMeLaterAsync(-100L);
    future2.get();
    
    Thread.sleep(3000);
}
 
Example #25
Source File: HttpConduitConfigurationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testConduitBean() throws Exception {
    SpringBusFactory factory = new SpringBusFactory();
    bus = factory.createBus("org/apache/cxf/transport/http/spring/conduit-bean.xml");
    HTTPTransportFactory atf = new HTTPTransportFactory();
    HTTPConduit conduit = (HTTPConduit)atf.getConduit(ei, bus);

    verifyConduit(conduit);
}
 
Example #26
Source File: DigestAuthSupplierSpringTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    WebClient client = WebClient.create("http://localhost:" + port, (String) null);

    assertThrows(NotAuthorizedException.class, () -> client.get(String.class));

    HTTPConduit conduit = WebClient.getConfig(client).getHttpConduit();
    conduit.setAuthSupplier(new DigestAuthSupplier());
    conduit.getAuthorization().setUserName(USER);
    conduit.getAuthorization().setPassword(PWD);

    assertEquals(Controller.RESPONSE, client.get(String.class));
}
 
Example #27
Source File: ClientConfiguration.java    From cxf with Apache License 2.0 5 votes vote down vote up
public long getSynchronousTimeout() {
    Conduit conduit = getConduit();
    if (conduit instanceof HTTPConduit) {
        return ((HTTPConduit)conduit).getClient().getReceiveTimeout();
    }
    return synchronousTimeout;
}
 
Example #28
Source File: DigestAuthTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testDigestAuth() throws Exception {
    URL wsdl = getClass().getResource("../greeting.wsdl");
    assertNotNull("WSDL is null", wsdl);

    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull("Service is null", service);

    Greeter mortimer = service.getPort(mortimerQ, Greeter.class);
    assertNotNull("Port is null", mortimer);

    TestUtil.setAddress(mortimer, "http://localhost:" + PORT + "/digestauth/greeter");

    Client client = ClientProxy.getClient(mortimer);

    HTTPConduit http =
        (HTTPConduit) client.getConduit();
    AuthorizationPolicy authPolicy = new AuthorizationPolicy();
    authPolicy.setAuthorizationType("Digest");
    authPolicy.setUserName("foo");
    authPolicy.setPassword("bar");
    http.setAuthorization(authPolicy);

    String answer = mortimer.sayHi();
    assertEquals("Unexpected answer: " + answer,
            "Hi", answer);

}
 
Example #29
Source File: WSSecurityClientTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static Dispatch<Source> createUsernameTokenDispatcher(boolean decoupled, String port) {
    final Service service = Service.create(
        GREETER_SERVICE_QNAME
    );
    service.addPort(
        USERNAME_TOKEN_PORT_QNAME,
        decoupled ? SOAPBinding.SOAP11HTTP_BINDING : HTTPBinding.HTTP_BINDING,
        "http://localhost:" + port + "/GreeterService/UsernameTokenPort"
    );
    final Dispatch<Source> dispatcher = service.createDispatch(
        USERNAME_TOKEN_PORT_QNAME,
        Source.class,
        Service.Mode.MESSAGE,
        new AddressingFeature(decoupled, decoupled)
    );
    final java.util.Map<String, Object> requestContext =
        dispatcher.getRequestContext();
    requestContext.put(
        MessageContext.HTTP_REQUEST_METHOD,
        "POST"
    );
    if (decoupled) {
        HTTPConduit cond = (HTTPConduit)((DispatchImpl<?>)dispatcher).getClient().getConduit();
        cond.getClient().setDecoupledEndpoint("http://localhost:" + DEC_PORT + "/decoupled");
    }
    return dispatcher;
}
 
Example #30
Source File: AsyncHTTPConduitFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public HTTPConduit createConduit(HTTPTransportFactory f,
                                 Bus bus,
                                 EndpointInfo localInfo,
                                 EndpointReferenceType target) throws IOException {

    return createConduit(bus, localInfo, target);
}