Search in sources :

Example 31 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.

the class JAXRSClientFactoryBeanTest method testGetConduit.

@Test
public void testGetConduit() throws Exception {
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    bean.setAddress("http://bar");
    bean.setResourceClass(BookStore.class);
    BookStore store = bean.create(BookStore.class);
    Conduit conduit = WebClient.getConfig(store).getConduit();
    assertTrue(conduit instanceof HTTPConduit);
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) BookStore(org.apache.cxf.jaxrs.resources.BookStore) SuperBookStore(org.apache.cxf.jaxrs.resources.SuperBookStore) Conduit(org.apache.cxf.transport.Conduit) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) Test(org.junit.Test)

Example 32 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.

the class ClientNonSpring method setupTLS.

private static void setupTLS(Greeter port) throws IOException, GeneralSecurityException {
    final TLSClientParameters tlsCP = new TLSClientParameters();
    tlsCP.setDisableCNCheck(true);
    final KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
    try (InputStream is = new FileInputStream("src/main/config/clientKeystore.jks")) {
        keyStore.load(is, "cspass".toCharArray());
    }
    KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    kmf.init(keyStore, "ckpass".toCharArray());
    tlsCP.setKeyManagers(kmf.getKeyManagers());
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    tmf.init(keyStore);
    tlsCP.setTrustManagers(tmf.getTrustManagers());
    ((HTTPConduit) ClientProxy.getClient(port).getConduit()).setTlsClientParameters(tlsCP);
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 33 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.

the class AbstractSTSClient method createClient.

protected void createClient() throws BusException, EndpointException {
    if (client != null) {
        return;
    }
    if (wsdlLocation != null) {
        WSDLServiceFactory factory = new WSDLServiceFactory(bus, wsdlLocation, serviceName);
        SourceDataBinding dataBinding = new SourceDataBinding();
        factory.setDataBinding(dataBinding);
        Service service = factory.create();
        service.setDataBinding(dataBinding);
        EndpointInfo ei = service.getEndpointInfo(endpointName);
        Endpoint endpoint = new EndpointImpl(bus, service, ei);
        client = new ClientImpl(bus, endpoint);
    } else if (location != null) {
        Endpoint endpoint = STSUtils.createSTSEndpoint(bus, namespace, null, location, soapVersion, policy, endpointName);
        client = new ClientImpl(bus, endpoint);
    } else {
        throw new TrustException(LOG, "NO_LOCATION");
    }
    client.getInFaultInterceptors().addAll(inFault);
    client.getInInterceptors().addAll(in);
    client.getOutInterceptors().addAll(out);
    client.getOutFaultInterceptors().addAll(outFault);
    if (tlsClientParameters != null) {
        HTTPConduit http = (HTTPConduit) client.getConduit();
        http.setTlsClientParameters(tlsClientParameters);
    }
    in = null;
    out = null;
    inFault = null;
    outFault = null;
    if (features != null) {
        for (Feature f : features) {
            f.initialize(client, bus);
        }
    }
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) Endpoint(org.apache.cxf.endpoint.Endpoint) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) Service(org.apache.cxf.service.Service) ClientImpl(org.apache.cxf.endpoint.ClientImpl) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) Feature(org.apache.cxf.feature.Feature)

Example 34 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.

the class CXF6655Test method testConnectionWithProxy.

@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"));
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) QName(javax.xml.namespace.QName) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Example 35 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.

the class InterceptorFaultTest method setupGreeter.

private void setupGreeter(String cfgResource, boolean useDecoupledEndpoint) throws NumberFormatException, MalformedURLException {
    SpringBusFactory bf = new SpringBusFactory();
    controlBus = bf.createBus();
    BusFactory.setDefaultBus(controlBus);
    ControlService cs = new ControlService();
    control = cs.getControlPort();
    updateAddressPort(control, PORT);
    assertTrue("Failed to start greeter", control.startGreeter(cfgResource));
    greeterBus = bf.createBus(cfgResource);
    BusFactory.setDefaultBus(greeterBus);
    LOG.fine("Initialised greeter bus with configuration: " + cfgResource);
    if (null == comparator) {
        comparator = new PhaseComparator();
    }
    if (null == inPhases) {
        inPhases = new ArrayList<>();
        inPhases.addAll(greeterBus.getExtension(PhaseManager.class).getInPhases());
        Collections.sort(inPhases, comparator);
    }
    if (null == postUnMarshalPhase) {
        postUnMarshalPhase = getPhase(Phase.POST_UNMARSHAL);
    }
    GreeterService gs = new GreeterService();
    greeter = gs.getGreeterPort();
    updateAddressPort(greeter, PORT);
    LOG.fine("Created greeter client.");
    if (!useDecoupledEndpoint) {
        return;
    }
    // programatically configure decoupled endpoint that is guaranteed to
    // be unique across all test cases
    decoupledEndpointPort++;
    decoupledEndpoint = "http://localhost:" + allocatePort("decoupled-" + decoupledEndpointPort) + "/decoupled_endpoint";
    Client c = ClientProxy.getClient(greeter);
    HTTPConduit hc = (HTTPConduit) (c.getConduit());
    HTTPClientPolicy cp = hc.getClient();
    cp.setDecoupledEndpoint(decoupledEndpoint);
    LOG.fine("Using decoupled endpoint: " + cp.getDecoupledEndpoint());
}
Also used : PhaseComparator(org.apache.cxf.phase.PhaseComparator) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) ControlService(org.apache.cxf.greeter_control.ControlService) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) GreeterService(org.apache.cxf.greeter_control.GreeterService) Client(org.apache.cxf.endpoint.Client)

Aggregations

HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)158 Client (org.apache.cxf.endpoint.Client)65 Test (org.junit.Test)60 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)52 URL (java.net.URL)43 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)43 Bus (org.apache.cxf.Bus)36 QName (javax.xml.namespace.QName)24 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)23 KeyStore (java.security.KeyStore)21 Greeter (org.apache.hello_world.Greeter)21 SOAPService (org.apache.hello_world.services.SOAPService)21 Service (javax.xml.ws.Service)18 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)17 InputStream (java.io.InputStream)15 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)15 IOException (java.io.IOException)13 ExecutionException (java.util.concurrent.ExecutionException)13 TrustManager (javax.net.ssl.TrustManager)13 WebClient (org.apache.cxf.jaxrs.client.WebClient)11