Search in sources :

Example 36 with HTTPConduit

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

the class WSAFaultToClientServerTest method testTwoWayFaultTo.

@Test
public void testTwoWayFaultTo() throws Exception {
    ByteArrayOutputStream input = setupInLogging();
    AddNumbersPortType port = getTwoWayPort();
    // setup a real decoupled endpoint that will process the fault correctly
    HTTPConduit c = (HTTPConduit) ClientProxy.getClient(port).getConduit();
    c.getClient().setDecoupledEndpoint("http://localhost:" + FaultToEndpointServer.FAULT_PORT2 + "/sendFaultHere");
    EndpointReferenceType faultTo = new EndpointReferenceType();
    AddressingProperties addrProperties = new AddressingProperties();
    AttributedURIType epr = new AttributedURIType();
    epr.setValue("http://localhost:" + FaultToEndpointServer.FAULT_PORT2 + "/sendFaultHere");
    faultTo.setAddress(epr);
    addrProperties.setFaultTo(faultTo);
    BindingProvider provider = (BindingProvider) port;
    Map<String, Object> requestContext = provider.getRequestContext();
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + FaultToEndpointServer.PORT + "/jaxws/add");
    requestContext.put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, addrProperties);
    try {
        port.addNumbers(-1, -2);
        fail("Exception is expected");
    } catch (Exception e) {
    // do nothing
    }
    String in = new String(input.toByteArray());
    // System.out.println(in);
    assertTrue("The response from faultTo endpoint is expected and actual response is " + in, in.indexOf("Address: http://localhost:" + FaultToEndpointServer.FAULT_PORT2 + "/sendFaultHere") > -1);
    assertTrue("WS addressing header is expected", in.indexOf("http://www.w3.org/2005/08/addressing") > -1);
    assertTrue("Fault deatil is expected", in.indexOf("Negative numbers cant be added") > -1);
    ((Closeable) port).close();
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) Closeable(java.io.Closeable) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BindingProvider(javax.xml.ws.BindingProvider) Test(org.junit.Test)

Example 37 with HTTPConduit

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

the class WebSocketTransportFactory method getConduit.

/**
 * {@inheritDoc}
 */
public Conduit getConduit(EndpointInfo endpointInfo, EndpointReferenceType target, Bus bus) throws IOException {
    HTTPConduit conduit = new AhcWebSocketConduit(bus, endpointInfo, target);
    String address = conduit.getAddress();
    if (address != null && address.indexOf('?') != -1) {
        address = address.substring(0, address.indexOf('?'));
    }
    HTTPConduitConfigurer c1 = bus.getExtension(HTTPConduitConfigurer.class);
    if (c1 != null) {
        c1.configure(conduit.getBeanName(), address, conduit);
    }
    configure(bus, conduit, conduit.getBeanName(), address);
    conduit.finalizeConfig();
    return conduit;
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) AhcWebSocketConduit(org.apache.cxf.transport.websocket.ahc.AhcWebSocketConduit) HTTPConduitConfigurer(org.apache.cxf.transport.http.HTTPConduitConfigurer)

Example 38 with HTTPConduit

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

the class JAXRSSamlTest method testSAMLTokenHeaderUsingAuthorizationPolicy.

@Test
public void testSAMLTokenHeaderUsingAuthorizationPolicy() throws Exception {
    String address = "https://localhost:" + PORT + "/samlheader/bookstore/books/123";
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    bean.setAddress(address);
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = JAXRSSamlTest.class.getResource("client.xml");
    Bus springBus = bf.createBus(busFile.toString());
    bean.setBus(springBus);
    // Create SAML Token
    SAMLCallback samlCallback = new SAMLCallback();
    SAMLUtil.doSAMLCallback(new SamlCallbackHandler(), samlCallback);
    SamlAssertionWrapper assertion = new SamlAssertionWrapper(samlCallback);
    Document doc = DOMUtils.createDocument();
    Element token = assertion.toDOM(doc);
    WebClient wc = bean.createWebClient();
    HTTPConduit http = (HTTPConduit) WebClient.getConfig(wc).getConduit();
    AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();
    String encodedToken = encodeToken(DOM2Writer.nodeToString(token));
    authorizationPolicy.setAuthorization(encodedToken);
    authorizationPolicy.setAuthorizationType("SAML");
    http.setAuthorization(authorizationPolicy);
    try {
        Book book = wc.get(Book.class);
        assertEquals(123L, book.getId());
    } catch (WebApplicationException ex) {
        fail(ex.getMessage());
    } catch (ProcessingException ex) {
        if (ex.getCause() != null && ex.getCause().getMessage() != null) {
            fail(ex.getCause().getMessage());
        } else {
            fail(ex.getMessage());
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) WebApplicationException(javax.ws.rs.WebApplicationException) Element(org.w3c.dom.Element) SamlAssertionWrapper(org.apache.wss4j.common.saml.SamlAssertionWrapper) Document(org.w3c.dom.Document) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) Book(org.apache.cxf.systest.jaxrs.security.Book) SAMLCallback(org.apache.wss4j.common.saml.SAMLCallback) ProcessingException(javax.ws.rs.ProcessingException) Test(org.junit.Test)

Example 39 with HTTPConduit

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

the class WSSecurity10Test method testClientServer.

@Test
public void testClientServer() {
    BusFactory.setDefaultBus(getStaticBus());
    BusFactory.setThreadDefaultBus(getStaticBus());
    URL wsdlLocation = null;
    PingService svc = null;
    wsdlLocation = getWsdlLocation(test.prefix, test.port);
    svc = new PingService(wsdlLocation);
    final IPingService port = svc.getPort(new QName("http://WSSec/wssec10", test.prefix + "_IPingService"), IPingService.class);
    Client cl = ClientProxy.getClient(port);
    if (test.streaming) {
        // Streaming
        ((BindingProvider) port).getRequestContext().put(SecurityConstants.ENABLE_STREAMING_SECURITY, "true");
        ((BindingProvider) port).getResponseContext().put(SecurityConstants.ENABLE_STREAMING_SECURITY, "true");
    }
    HTTPConduit http = (HTTPConduit) cl.getConduit();
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout(0);
    httpClientPolicy.setReceiveTimeout(0);
    http.setClient(httpClientPolicy);
    String output = port.echo(INPUT);
    assertEquals(INPUT, output);
    cl.destroy();
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) IPingService(wssec.wssec10.IPingService) QName(javax.xml.namespace.QName) IPingService(wssec.wssec10.IPingService) PingService(wssec.wssec10.PingService) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Client(org.apache.cxf.endpoint.Client) URL(java.net.URL) Test(org.junit.Test)

Example 40 with HTTPConduit

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

the class UsernameTokenTest method testPlaintextWSDLOverHTTPSViaCode.

@org.junit.Test
public void testPlaintextWSDLOverHTTPSViaCode() throws Exception {
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    final KeyStore ts = KeyStore.getInstance("JKS");
    try (InputStream trustStore = ClassLoaderUtils.getResourceAsStream("keys/Truststore.jks", UsernameTokenTest.class)) {
        ts.load(trustStore, "password".toCharArray());
    }
    tmf.init(ts);
    TLSClientParameters tlsParams = new TLSClientParameters();
    tlsParams.setTrustManagers(tmf.getTrustManagers());
    tlsParams.setDisableCNCheck(true);
    HTTPConduitConfigurer myHttpConduitConfig = new HTTPConduitConfigurer() {

        public void configure(String name, String address, HTTPConduit c) {
            if ("{http://cxf.apache.org}TransportURIResolver.http-conduit".equals(name)) {
                c.setTlsClientParameters(tlsParams);
            }
        }
    };
    BusFactory busFactory = BusFactory.newInstance();
    bus = busFactory.createBus();
    bus.setExtension(myHttpConduitConfig, HTTPConduitConfigurer.class);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = new URL("https://localhost:" + PORT + "/DoubleItUTPlaintext?wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItPlaintextPort");
    DoubleItPortType utPort = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, test.getPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(utPort);
    }
    ((BindingProvider) utPort).getRequestContext().put(SecurityConstants.USERNAME, "Alice");
    ((BindingProvider) utPort).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.ws.common.UTPasswordCallback");
    Client client = ClientProxy.getClient(utPort);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    http.setTlsClientParameters(tlsParams);
    assertEquals(50, utPort.doubleIt(25));
    ((java.io.Closeable) utPort).close();
}
Also used : TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) BusFactory(org.apache.cxf.BusFactory) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) KeyStore(java.security.KeyStore) URL(java.net.URL) HTTPConduitConfigurer(org.apache.cxf.transport.http.HTTPConduitConfigurer) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) 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