Java Code Examples for org.apache.cxf.Bus#shutdown()

The following examples show how to use org.apache.cxf.Bus#shutdown() . 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: X509TokenTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testSymmetricThumbprintEndorsing() throws Exception {

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

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

    URL wsdl = X509TokenTest.class.getResource("DoubleItX509.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSymmetricThumbprintEndorsingPort");
    DoubleItPortType x509Port =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(x509Port, test.getPort());

    if (!test.isStreaming()) {
        assertEquals(50, x509Port.doubleIt(25));
    }

    ((java.io.Closeable)x509Port).close();
    bus.shutdown(true);
}
 
Example 2
Source File: ClientServerWrappedContinuationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testHttpWrappedContinuations() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    Bus bus = bf.createBus(CLIENT_CONFIG_FILE);
    BusFactory.setDefaultBus(bus);

    QName serviceName = new QName("http://cxf.apache.org/systest/jaxws", "HelloContinuationService");

    URL wsdlURL = new URL("http://localhost:" + PORT + "/hellocontinuation?wsdl");

    HelloContinuationService service = new HelloContinuationService(wsdlURL, serviceName);
    assertNotNull(service);
    final HelloContinuation helloPort = service.getHelloContinuationPort();
    doTest(helloPort);
    bus.shutdown(true);
}
 
Example 3
Source File: WSDLAddrPolicyAttachmentJaxwsMMProviderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUsingAddressing() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();

    Bus bus = bf.createBus("org/apache/cxf/systest/ws/policy/addr-inline-policy-old.xml");

    BusFactory.setDefaultBus(bus);

    URL wsdlURL = new URL(WSDL_ADDRESS);

    AsyncMessagingService ams = new AsyncMessagingService(wsdlURL, ENDPOINT_NAME);
    AsyncMessaging am = ams.getAsyncMessagingImplPort();

    ConnectionHelper.setKeepAliveConnection(am, true);
    testInterceptors(bus);

    // oneway
    am.deliver("This is a test");
    am.deliver("This is another test");
    bus.shutdown(true);
}
 
Example 4
Source File: ManagedBusTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testManagedSpringBus() throws Exception {
    SpringBusFactory factory = new SpringBusFactory();
    Bus bus = factory.createBus();
    InstrumentationManager im = bus.getExtension(InstrumentationManager.class);
    assertNotNull(im);

    InstrumentationManagerImpl imi = (InstrumentationManagerImpl)im;
    assertFalse(imi.isEnabled());
    assertNull(imi.getMBeanServer());

    //Test that registering without an MBeanServer is a no-op
    im.register(imi, new ObjectName("org.apache.cxf:foo=bar"));

    bus.shutdown(true);
}
 
Example 5
Source File: UsernameTokenTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testPlaintextSupporting() throws Exception {

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

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

    URL wsdl = UsernameTokenTest.class.getResource("DoubleItUt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItPlaintextSupportingPort");
    DoubleItPortType utPort =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, test.getPort());

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

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

    ((java.io.Closeable)utPort).close();
    bus.shutdown(true);
}
 
Example 6
Source File: BindingPropertiesTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testSignatureConfirmationEncBeforeSigning() throws Exception {

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

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

    URL wsdl = BindingPropertiesTest.class.getResource("DoubleItBindings.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);

    QName portQName = new QName(NAMESPACE, "DoubleItSignatureConfirmationEncBeforeSigningPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());

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

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

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 7
Source File: HTTPGetTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testHTTPGetClientSecurityPolicy() throws Exception {
    if (!TestUtilities.checkUnrestrictedPoliciesInstalled()) {
        return;
    }

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

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

    String address = "http://localhost:" + PORT + "/DoubleItX509KeyIdentifier/DoubleIt";
    WebClient client = WebClient.create(address);
    client.query("numberToDouble", "20");

    try {
        client.get(XMLSource.class);
        fail("Failure expected on security policy failure");
    } catch (Exception ex) {
        // expected
    }

    bus.shutdown(true);
}
 
Example 8
Source File: JaxwsBasicAuthTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testBadBasicAuth() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = JaxwsBasicAuthTest.class.getResource("cxf-bad-client.xml");

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

    URL wsdl = JaxwsBasicAuthTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItPort");
    DoubleItPortType port =
        service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());

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

    try {
        doubleIt(port, 30);
        fail("Expected failure on a bad password");
    } catch (javax.xml.ws.soap.SOAPFaultException fault) {
        String message = fault.getMessage();
        assertTrue(message.contains("STS Authentication failed")
            || message.contains("Validation of security token failed"));
    }

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

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

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

    URL wsdl = BasicAuthTest.class.getResource("DoubleItBasicAuth.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItBasicAuthPort2");
    DoubleItPortType utPort =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, PORT);

    try {
        utPort.doubleIt(25);
        fail("Failure expected on no basic auth creds");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        // expected
    }

    ((java.io.Closeable)utPort).close();
    bus.shutdown(true);
}
 
Example 10
Source File: SamlTokenTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testSaml2EndorsingOverTransportSP11() throws Exception {

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

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

    URL wsdl = SamlTokenTest.class.getResource("DoubleItSaml.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSaml2EndorsingTransportSP11Port");
    DoubleItPortType saml2Port =
            service.getPort(portQName, DoubleItPortType.class);
    String portNumber = PORT2;
    if (STAX_PORT.equals(test.getPort())) {
        portNumber = STAX_PORT2;
    }
    updateAddressPort(saml2Port, portNumber);

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

    SamlCallbackHandler callbackHandler = new SamlCallbackHandler(true, true);
    callbackHandler.setConfirmationMethod(SAML2Constants.CONF_HOLDER_KEY);
    ((BindingProvider)saml2Port).getRequestContext().put(
        SecurityConstants.SAML_CALLBACK_HANDLER, callbackHandler
    );

    int result = saml2Port.doubleIt(25);
    assertTrue(result == 50);

    ((java.io.Closeable)saml2Port).close();
    bus.shutdown(true);
}
 
Example 11
Source File: Client.java    From servicemix with Apache License 2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    try {

        SpringBusFactory bf = new SpringBusFactory();
        URL busFile = Client.class.getResource("ws_rm.xml");
        Bus bus = bf.createBus(busFile.toString());
        bf.setDefaultBus(bus);
        bus.getOutInterceptors().add(new MessageLossSimulator());
        // Endpoint Address
        Service service = Service.create(Client.class.getResource("/HelloWorld.wsdl"), SERVICE_NAME);

        String endpointAddress = "http://localhost:8181/cxf/HelloWorld";

        // Add a port to the Service
        service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
        HelloWorld hw = service.getPort(HelloWorld.class);
        
        String[] names = new String[] {"Anne", "Bill", "Chris", "Daisy"};
        // make a sequence of 4 invocations
        for (int i = 0; i < 4; i++) {
            System.out.println("Calling HelloWorld service");
            System.out.println(hw.sayHi(names[i]));
        }

        // allow aynchronous resends to occur
        Thread.sleep(60 * 1000);
        bus.shutdown(true);

    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        System.exit(0);
    }
}
 
Example 12
Source File: TemplateTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testSendSAML2PublicKey() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = TemplateTest.class.getResource("cxf-client.xml");

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

    URL wsdl = TemplateTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML2PublicKeyPort");
    DoubleItPortType port =
        service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());

    // Setup STSClient
    STSClient stsClient = createSTSClient(bus);
    String wsdlLocation = "https://localhost:" + test.getStsPort() + "/SecurityTokenService/Transport?wsdl";
    stsClient.setWsdlLocation(wsdlLocation);

    ((BindingProvider)port).getRequestContext().put(
        SecurityConstants.STS_CLIENT, stsClient
    );

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

    doubleIt(port, 25);

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 13
Source File: IssueUnitTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Test the Bearer SAML1 case
 */
@org.junit.Test
public void testBearerSaml1() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = IssueUnitTest.class.getResource("cxf-client.xml");

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

    // Get a token
    SecurityToken token =
        requestSecurityToken(SAML1_TOKEN_TYPE, BEARER_KEYTYPE, bus, DEFAULT_ADDRESS);
    assertEquals(SAML1_TOKEN_TYPE, token.getTokenType());
    assertNotNull(token.getToken());

    // Process the token
    List<WSSecurityEngineResult> results = processToken(token);
    assertTrue(results != null && results.size() == 1);
    SamlAssertionWrapper assertion =
        (SamlAssertionWrapper)results.get(0).get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
    assertNotNull(assertion);
    assertTrue(assertion.getSaml1() != null && assertion.getSaml2() == null);
    assertTrue(assertion.isSigned());

    List<String> methods = assertion.getConfirmationMethods();
    String confirmMethod = null;
    if (methods != null && !methods.isEmpty()) {
        confirmMethod = methods.get(0);
    }
    assertTrue(confirmMethod != null && confirmMethod.contains("bearer"));

    bus.shutdown(true);
}
 
Example 14
Source File: AlgorithmSuiteTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testManualConfigurationSignature() throws Exception {

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

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

    URL wsdl = AlgorithmSuiteTest.class.getResource("DoubleItAlgSuite.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSignaturePort");
    DoubleItPortType port =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, PORT);

    // This should succeed as the client + server settings match
    assertEquals(50, port.doubleIt(25));

    // This should fail as the client uses uses RSA-SHA256 + the server uses RSA-SHA1
    if (TestUtilities.checkUnrestrictedPoliciesInstalled()) {
        portQName = new QName(NAMESPACE, "DoubleItSignaturePort2");
        port = service.getPort(portQName, DoubleItPortType.class);
        updateAddressPort(port, PORT);

        // This should fail as the client uses uses RSA-SHA256 + the server uses RSA-SHA1
        try {
            port.doubleIt(25);
            fail("Failure expected on SHA-256");
        } catch (Exception ex) {
            // expected
        }
    }

    bus.shutdown(true);
}
 
Example 15
Source File: SamlTokenTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testSaml1SelfSignedOverTransportSP11() throws Exception {

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

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

    URL wsdl = SamlTokenTest.class.getResource("DoubleItSaml.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSaml1SelfSignedTransportSP11Port");
    DoubleItPortType saml1Port =
            service.getPort(portQName, DoubleItPortType.class);
    String portNumber = PORT2;
    if (STAX_PORT.equals(test.getPort())) {
        portNumber = STAX_PORT2;
    }
    updateAddressPort(saml1Port, portNumber);

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

    ((BindingProvider)saml1Port).getRequestContext().put(
        SecurityConstants.SAML_CALLBACK_HANDLER, new SamlCallbackHandler(false, true)
    );
    int result = saml1Port.doubleIt(25);
    assertTrue(result == 50);

    ((java.io.Closeable)saml1Port).close();
    bus.shutdown(true);
}
 
Example 16
Source File: X509TokenTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testKeyIdentifier2() throws Exception {

    if (test.isStreaming()) {
        return;
    }

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

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

    URL wsdl = X509TokenTest.class.getResource("DoubleItOperations.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItKeyIdentifierPort2");
    DoubleItPortType2 x509Port =
            service.getPort(portQName, DoubleItPortType2.class);
    updateAddressPort(x509Port, PORT);

    List<Header> headers = new ArrayList<>();
    Header dummyHeader = new Header(new QName("uri:org.apache.cxf", "dummy"), "dummy-header",
                                    new JAXBDataBinding(String.class));
    headers.add(dummyHeader);
    ((BindingProvider)x509Port).getRequestContext().put(Header.HEADER_LIST, headers);

    int response = x509Port.doubleIt(25);
    assertEquals(50, response);

    int response2 = x509Port.doubleIt2(15);
    assertEquals(30, response2);

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

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

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

    URL wsdl = UsernameTokenTest.class.getResource("DoubleItUt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItPlaintextPrincipalPort");
    DoubleItPortType utPort =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, test.getPort());

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

    ((BindingProvider)utPort).getRequestContext().put(SecurityConstants.USERNAME, "Alice");
    assertEquals(50, utPort.doubleIt(25));

    try {
        ((BindingProvider)utPort).getRequestContext().put(SecurityConstants.USERNAME, "Frank");
        utPort.doubleIt(30);
        fail("Failure expected on a user with the wrong role");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        String error = "Unauthorized";
        assertTrue(ex.getMessage().contains(error));
    }

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

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = CustomParameterTest.class.getResource("cxf-client.xml");

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

    URL wsdl = CustomParameterTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportCustomParameterPort");
    DoubleItPortType transportClaimsPort =
        service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(transportClaimsPort, PORT);

    TokenTestUtils.updateSTSPort((BindingProvider)transportClaimsPort, STSPORT);

    STSClient stsClient = new STSClient(bus);
    stsClient.setWsdlLocation("https://localhost:" + STSPORT + "/SecurityTokenService/UT?wsdl");
    stsClient.setServiceName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}SecurityTokenService");
    stsClient.setEndpointName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}UT_Port");

    Map<String, Object> properties = new HashMap<>();
    properties.put(SecurityConstants.USERNAME, "alice");
    properties.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.sts.common.CommonCallbackHandler");
    properties.put("security.sts.token.username", "myclientkey");
    properties.put("security.sts.token.properties", "clientKeystore.properties");
    properties.put("security.sts.token.usecert", "true");
    stsClient.setProperties(properties);

    ((BindingProvider)transportClaimsPort).getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);

    // Successful test

    // Add custom content to the RST
    stsClient.setCustomContent("<realm xmlns=\"http://cxf.apache.org/custom\">custom-realm</realm>");
    doubleIt(transportClaimsPort, 25);

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

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

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

    URL wsdl = PartsTest.class.getResource("DoubleItParts.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);

    // Successful invocation
    QName portQName = new QName(NAMESPACE, "DoubleItSignedAttachmentsPort");
    DoubleItSwaPortType port = service.getPort(portQName, DoubleItSwaPortType.class);
    updateAddressPort(port, test.getPort());

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

    DoubleIt3 doubleIt = new DoubleIt3();
    doubleIt.setNumberToDouble(25);
    port.doubleIt3(doubleIt, "12345".getBytes());

    // This should fail, as the service requires that the Attachments must be signed
    portQName = new QName(NAMESPACE, "DoubleItSignedAttachmentsPort2");
    port = service.getPort(portQName, DoubleItSwaPortType.class);
    updateAddressPort(port, test.getPort());

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

    try {
        doubleIt = new DoubleIt3();
        doubleIt.setNumberToDouble(25);
        port.doubleIt3(doubleIt, "12345".getBytes());
        fail("Failure expected on an attachment which isn't signed");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        String error = "SignedParts";
        assertTrue(ex.getMessage().contains(error));
    }

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

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

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

    URL wsdl = CachingTest.class.getResource("DoubleItCache.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItCachePerProxySymmetricPort");

    // First invocation
    DoubleItPortType port =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());

    ((BindingProvider)port).getRequestContext().put(
        SecurityConstants.CACHE_IDENTIFIER, "proxy1"
    );
    ((BindingProvider)port).getRequestContext().put(
        SecurityConstants.CACHE_CONFIG_FILE,
            ClassLoaderUtils.getResource("per-proxy-cache.xml", this.getClass())
    );

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

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

    Client client = ClientProxy.getClient(port);
    TokenStore tokenStore =
        (TokenStore)client.getEndpoint().getEndpointInfo().getProperty(
            SecurityConstants.TOKEN_STORE_CACHE_INSTANCE
        );
    assertNotNull(tokenStore);
    // We expect two tokens as the identifier + SHA-1 are cached
    assertEquals(2, tokenStore.getTokenIdentifiers().size());

    // Second invocation
    DoubleItPortType port2 = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port2, test.getPort());

    ((BindingProvider)port2).getRequestContext().put(
        SecurityConstants.CACHE_IDENTIFIER, "proxy2"
    );
    ((BindingProvider)port2).getRequestContext().put(
        SecurityConstants.CACHE_CONFIG_FILE,
            ClassLoaderUtils.getResource("per-proxy-cache.xml", this.getClass())
    );

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

    assertEquals(70, port2.doubleIt(35));

    client = ClientProxy.getClient(port2);
    tokenStore =
        (TokenStore)client.getEndpoint().getEndpointInfo().getProperty(
            SecurityConstants.TOKEN_STORE_CACHE_INSTANCE
        );
    assertNotNull(tokenStore);
    // We expect two tokens as the identifier + SHA-1 are cached
    assertEquals(2, tokenStore.getTokenIdentifiers().size());

    ((java.io.Closeable)port).close();
    ((java.io.Closeable)port2).close();
    bus.shutdown(true);
}