Java Code Examples for org.apache.cxf.endpoint.Client#getConduit()

The following examples show how to use org.apache.cxf.endpoint.Client#getConduit() . 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: 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 2
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 3
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 4
Source File: ClientServerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasicAuth() throws Exception {
    Service service = Service.create(serviceName);
    service.addPort(fakePortName, "http://schemas.xmlsoap.org/soap/",
                    "http://localhost:" + PORT + "/SoapContext/SoapPort");
    Greeter greeter = service.getPort(fakePortName, Greeter.class);

    try {
        //try the jaxws way
        BindingProvider bp = (BindingProvider)greeter;
        bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "BJ");
        bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pswd");
        String s = greeter.greetMe("secure");
        assertEquals("Hello BJ", s);
        bp.getRequestContext().remove(BindingProvider.USERNAME_PROPERTY);
        bp.getRequestContext().remove(BindingProvider.PASSWORD_PROPERTY);

        //try setting on the conduit directly
        Client client = ClientProxy.getClient(greeter);
        HTTPConduit httpConduit = (HTTPConduit)client.getConduit();
        AuthorizationPolicy policy = new AuthorizationPolicy();
        policy.setUserName("BJ2");
        policy.setPassword("pswd");
        httpConduit.setAuthorization(policy);

        s = greeter.greetMe("secure");
        assertEquals("Hello BJ2", s);
    } catch (UndeclaredThrowableException ex) {
        throw (Exception)ex.getCause();
    }
}
 
Example 5
Source File: CipherSuitesTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testAESIncludedTLSv10() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = CipherSuitesTest.class.getResource("ciphersuites-client-noconfig.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL url = SOAPService.WSDL_LOCATION;
    SOAPService service = new SOAPService(url, SOAPService.SERVICE);
    assertNotNull("Service is null", service);
    final Greeter port = service.getHttpsPort();
    assertNotNull("Port is null", port);

    updateAddressPort(port, PORT);

    // Enable Async
    if (async) {
        ((BindingProvider)port).getRequestContext().put("use.async.http.conduit", true);
    }

    Client client = ClientProxy.getClient(port);
    HTTPConduit conduit = (HTTPConduit) client.getConduit();

    TLSClientParameters tlsParams = new TLSClientParameters();
    TrustManager[] trustManagers = InsecureTrustManager.getNoOpX509TrustManagers();
    tlsParams.setTrustManagers(trustManagers);
    tlsParams.setDisableCNCheck(true);

    tlsParams.setSecureSocketProtocol("TLSv1");

    conduit.setTlsClientParameters(tlsParams);

    assertEquals(port.greetMe("Kitty"), "Hello Kitty");

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 6
Source File: SequenceTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void initDecoupledEndpoint(Client c) {
    // programatically configure decoupled endpoint that is guaranteed to
    // be unique across all test cases
    decoupledEndpoint = "http://localhost:"
        + allocatePort("decoupled-" + decoupledCount++) + "/decoupled_endpoint";

    HTTPConduit hc = (HTTPConduit)(c.getConduit());
    HTTPClientPolicy cp = hc.getClient();
    cp.setDecoupledEndpoint(decoupledEndpoint);

    LOG.fine("Using decoupled endpoint: " + cp.getDecoupledEndpoint());
}
 
Example 7
Source File: SecureEETCommunication.java    From eet-client with MIT License 5 votes vote down vote up
private void configureTimeout(final Client clientProxy) {
    final HTTPConduit conduit = (HTTPConduit) clientProxy.getConduit();
    final HTTPClientPolicy policy = new HTTPClientPolicy();
    policy.setReceiveTimeout(this.wsConfiguration.getReceiveTimeout());
    policy.setConnectionTimeout(this.wsConfiguration.getReceiveTimeout());
    policy.setAsyncExecuteTimeout(this.wsConfiguration.getReceiveTimeout());
    conduit.setClient(policy);
}
 
Example 8
Source File: WebServiceProtocol.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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;
  }
 
Example 9
Source File: ConnectionHelper.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void setKeepAliveConnection(Object proxy, boolean keepAlive, boolean force) {
    if (force || "HP-UX".equals(System.getProperty("os.name"))
        || "Windows XP".equals(System.getProperty("os.name"))) {
        Client client = ClientProxy.getClient(proxy);
        HTTPConduit hc = (HTTPConduit)client.getConduit();
        HTTPClientPolicy cp = hc.getClient();
        cp.setConnection(keepAlive ? ConnectionType.KEEP_ALIVE : ConnectionType.CLOSE);
    }
}
 
Example 10
Source File: TrustManagerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testNoOpX509TrustManager() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = TrustManagerTest.class.getResource("client-trust.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL url = SOAPService.WSDL_LOCATION;
    SOAPService service = new SOAPService(url, SOAPService.SERVICE);
    assertNotNull("Service is null", service);
    final Greeter port = service.getHttpsPort();
    assertNotNull("Port is null", port);

    updateAddressPort(port, PORT);

    // Enable Async
    if (async) {
        ((BindingProvider)port).getRequestContext().put("use.async.http.conduit", true);
    }

    TLSClientParameters tlsParams = new TLSClientParameters();
    tlsParams.setTrustManagers(InsecureTrustManager.getNoOpX509TrustManagers());
    tlsParams.setDisableCNCheck(true);

    Client client = ClientProxy.getClient(port);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    http.setTlsClientParameters(tlsParams);

    assertEquals(port.greetMe("Kitty"), "Hello Kitty");

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 11
Source File: ClientConfig.java    From cxf-jaxws with MIT License 5 votes vote down vote up
@Bean
public HTTPConduit ticketAgentConduit()
    throws NoSuchAlgorithmException, KeyStoreException,
    CertificateException, IOException {
  Client client = ClientProxy.getClient(ticketAgentProxy());

  HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
  httpConduit.setTlsClientParameters(tlsClientParameters());

  return httpConduit;
}
 
Example 12
Source File: AbstractServerPersistenceTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testRecovery() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    bus = bf.createBus();
    BusFactory.setDefaultBus(bus);
    LOG.fine("Created bus " + bus + " with default cfg");
    ControlService cs = new ControlService();
    Control control = cs.getControlPort();
    ConnectionHelper.setKeepAliveConnection(control, false, true);
    updateAddressPort(control, getPort());

    assertTrue("Failed to start greeter", control.startGreeter(SERVER_LOSS_CFG));
    LOG.fine("Started greeter server.");

    System.setProperty("db.name", getPrefix() + "-recovery");
    greeterBus = new SpringBusFactory().createBus(CFG);
    System.clearProperty("db.name");
    LOG.fine("Created bus " + greeterBus + " with cfg : " + CFG);
    BusFactory.setDefaultBus(greeterBus);

    // avoid early client resends
    greeterBus.getExtension(RMManager.class).getConfiguration()
        .setBaseRetransmissionInterval(Long.valueOf(60000));
    GreeterService gs = new GreeterService();
    Greeter greeter = gs.getGreeterPort();
    updateAddressPort(greeter, getPort());

    LOG.fine("Created greeter client.");

    ConnectionHelper.setKeepAliveConnection(greeter, false, true);

    Client c = ClientProxy.getClient(greeter);
    HTTPConduit hc = (HTTPConduit)(c.getConduit());
    HTTPClientPolicy cp = hc.getClient();
    cp.setDecoupledEndpoint("http://localhost:" + getDecoupledPort() + "/decoupled_endpoint");

    out = new OutMessageRecorder();
    in = new InMessageRecorder();

    greeterBus.getOutInterceptors().add(out);
    greeterBus.getInInterceptors().add(in);

    LOG.fine("Configured greeter client.");

    Response<GreetMeResponse>[] responses = cast(new Response[4]);

    responses[0] = greeter.greetMeAsync("one");
    responses[1] = greeter.greetMeAsync("two");
    responses[2] = greeter.greetMeAsync("three");

    verifyMissingResponse(responses);
    control.stopGreeter(SERVER_LOSS_CFG);
    LOG.fine("Stopped greeter server");

    out.getOutboundMessages().clear();
    in.getInboundMessages().clear();

    control.startGreeter(CFG);
    String nl = System.getProperty("line.separator");
    LOG.fine("Restarted greeter server" + nl + nl);

    verifyServerRecovery(responses);
    responses[3] = greeter.greetMeAsync("four");

    verifyRetransmissionQueue();
    verifyAcknowledgementRange(1, 4);

    out.getOutboundMessages().clear();
    in.getInboundMessages().clear();

    greeterBus.shutdown(true);

    control.stopGreeter(CFG);
    bus.shutdown(true);
}
 
Example 13
Source File: CipherSuitesTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testAESIncludedTLSv11() throws Exception {
    // Doesn't work with IBM JDK
    if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
        return;
    }

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = CipherSuitesTest.class.getResource("ciphersuites-client-noconfig.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL url = SOAPService.WSDL_LOCATION;
    SOAPService service = new SOAPService(url, SOAPService.SERVICE);
    assertNotNull("Service is null", service);
    final Greeter port = service.getHttpsPort();
    assertNotNull("Port is null", port);

    updateAddressPort(port, PORT);

    // Enable Async
    if (async) {
        ((BindingProvider)port).getRequestContext().put("use.async.http.conduit", true);
    }

    Client client = ClientProxy.getClient(port);
    HTTPConduit conduit = (HTTPConduit) client.getConduit();

    TLSClientParameters tlsParams = new TLSClientParameters();
    TrustManager[] trustManagers = InsecureTrustManager.getNoOpX509TrustManagers();
    tlsParams.setTrustManagers(trustManagers);
    tlsParams.setDisableCNCheck(true);

    tlsParams.setSecureSocketProtocol("TLSv1.1");

    conduit.setTlsClientParameters(tlsParams);

    assertEquals(port.greetMe("Kitty"), "Hello Kitty");

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 14
Source File: InterceptorFaultTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
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());
}
 
Example 15
Source File: HTTPSConduitTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * 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 16
Source File: TrustManagerTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testValidServerCertX509TrustManager() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = TrustManagerTest.class.getResource("client-trust.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL url = SOAPService.WSDL_LOCATION;
    SOAPService service = new SOAPService(url, SOAPService.SERVICE);
    assertNotNull("Service is null", service);
    final Greeter port = service.getHttpsPort();
    assertNotNull("Port is null", port);

    updateAddressPort(port, PORT);

    // Enable Async
    if (async) {
        ((BindingProvider)port).getRequestContext().put("use.async.http.conduit", true);
    }

    String validPrincipalName = "CN=Bethal,OU=Bethal,O=ApacheTest,L=Syracuse,C=US";

    TLSClientParameters tlsParams = new TLSClientParameters();
    X509TrustManager trustManager =
        new ServerCertX509TrustManager(validPrincipalName);
    TrustManager[] trustManagers = new TrustManager[1];
    trustManagers[0] = trustManager;
    tlsParams.setTrustManagers(trustManagers);
    tlsParams.setDisableCNCheck(true);

    Client client = ClientProxy.getClient(port);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    http.setTlsClientParameters(tlsParams);

    assertEquals(port.greetMe("Kitty"), "Hello Kitty");

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 17
Source File: UsernameTokenTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testPlaintextCodeFirst() throws Exception {

    String address = "https://localhost:" + PORT + "/DoubleItUTPlaintext";
    QName portQName = new QName(NAMESPACE, "DoubleItPlaintextPort");

    WSPolicyFeature policyFeature = new WSPolicyFeature();
    Element policyElement =
        StaxUtils.read(getClass().getResourceAsStream("plaintext-pass-timestamp-policy.xml")).getDocumentElement();
    policyFeature.setPolicyElements(Collections.singletonList(policyElement));

    JaxWsProxyFactoryBean clientFactoryBean = new JaxWsProxyFactoryBean();
    clientFactoryBean.setFeatures(Collections.singletonList(policyFeature));
    clientFactoryBean.setAddress(address);
    clientFactoryBean.setServiceName(SERVICE_QNAME);
    clientFactoryBean.setEndpointName(portQName);
    clientFactoryBean.setServiceClass(DoubleItPortType.class);

    DoubleItPortType port = (DoubleItPortType)clientFactoryBean.create();

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }

    ((BindingProvider)port).getRequestContext().put(SecurityConstants.USERNAME, "Alice");

    ((BindingProvider)port).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      "org.apache.cxf.systest.ws.common.UTPasswordCallback");

    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);

    Client client = ClientProxy.getClient(port);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    http.setTlsClientParameters(tlsParams);

    assertEquals(50, port.doubleIt(25));

    ((java.io.Closeable)port).close();
}
 
Example 18
Source File: CipherSuitesTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testAESIncludedTLSv13ViaCode() throws Exception {
    // Doesn't work with IBM JDK
    if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
        return;
    }
    Assume.assumeTrue(JavaUtils.isJava11Compatible());

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = CipherSuitesTest.class.getResource("ciphersuites-client-noconfig.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL url = SOAPService.WSDL_LOCATION;
    SOAPService service = new SOAPService(url, SOAPService.SERVICE);
    assertNotNull("Service is null", service);
    final Greeter port = service.getHttpsPort();
    assertNotNull("Port is null", port);

    updateAddressPort(port, PORT);

    // Enable Async
    if (async) {
        ((BindingProvider)port).getRequestContext().put("use.async.http.conduit", true);
    }

    Client client = ClientProxy.getClient(port);
    HTTPConduit conduit = (HTTPConduit) client.getConduit();

    TLSClientParameters tlsParams = new TLSClientParameters();
    TrustManager[] trustManagers = InsecureTrustManager.getNoOpX509TrustManagers();
    tlsParams.setTrustManagers(trustManagers);
    tlsParams.setDisableCNCheck(true);

    tlsParams.setSecureSocketProtocol("TLSv1.3");
    tlsParams.setCipherSuites(Collections.singletonList("TLS_AES_128_GCM_SHA256"));

    conduit.setTlsClientParameters(tlsParams);

    assertEquals(port.greetMe("Kitty"), "Hello Kitty");

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 19
Source File: JAXRSSoapBookTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void doTestHelloSoapCustomDataBinding(String address) throws Exception {
    final QName serviceName = new QName("http://hello.com", "HelloWorld");
    final QName portName = new QName("http://hello.com", "HelloWorldPort");

    Service service = Service.create(serviceName);
    service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address);

    HelloWorld hw = service.getPort(HelloWorld.class);

    Client cl = ClientProxy.getClient(hw);

    HTTPConduit http = (HTTPConduit) cl.getConduit();

    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout(0);
    httpClientPolicy.setReceiveTimeout(0);

    http.setClient(httpClientPolicy);

    User user = new UserImpl("Barry");
    User user2 = hw.echoUser(user);

    assertNotSame(user, user2);
    assertEquals("Barry", user2.getName());
}
 
Example 20
Source File: SignatureWhitespaceTest.java    From cxf with Apache License 2.0 2 votes vote down vote up
@org.junit.Test
public void testTrailingWhitespaceInSOAPBody() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SignatureWhitespaceTest.class.getResource("client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = SignatureWhitespaceTest.class.getResource("DoubleItAction.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSignaturePort2");

    Dispatch<StreamSource> dispatch =
        service.createDispatch(portQName, StreamSource.class, Service.Mode.MESSAGE);

    Client client = ((DispatchImpl<StreamSource>) dispatch).getClient();

    HTTPConduit http = (HTTPConduit) client.getConduit();

    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout(0);
    httpClientPolicy.setReceiveTimeout(0);
    http.setClient(httpClientPolicy);


    // Creating a DOMSource Object for the request

    URL requestFile =
        SignatureWhitespaceTest.class.getResource("request-with-trailing-whitespace.xml");

    StreamSource request = new StreamSource(new File(requestFile.getPath()));

    updateAddressPort(dispatch, test.getPort());

    // Make a successful request
    StreamSource response = dispatch.invoke(request);
    assertNotNull(response);

    Document doc = StaxUtils.read(response.getInputStream());
    assertEquals("50", doc.getElementsByTagNameNS(null, "doubledNumber").item(0).getTextContent());

    ((java.io.Closeable)dispatch).close();
}