Search in sources :

Example 11 with HelloWorldPortType

use of org.apache.cxf.hello_world_jms.HelloWorldPortType in project cxf by apache.

the class JMSClientServerTest method testContextPropagation.

@Test
public void testContextPropagation() throws Exception {
    final String testReturnPropertyName = "Test_Prop";
    final String testIgnoredPropertyName = "Test_Prop_No_Return";
    QName serviceName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldService");
    QName portName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldPort");
    URL wsdl = getWSDLURL("/wsdl/jms_test.wsdl");
    HelloWorldService service = new HelloWorldService(wsdl, serviceName);
    HelloWorldPortType greeter = service.getPort(portName, HelloWorldPortType.class);
    Map<String, Object> requestContext = ((BindingProvider) greeter).getRequestContext();
    JMSMessageHeadersType requestHeader = new JMSMessageHeadersType();
    requestHeader.setJMSCorrelationID("JMS_SAMPLE_CORRELATION_ID");
    requestHeader.setJMSExpiration(3600000L);
    requestHeader.putProperty(testReturnPropertyName, "mustReturn");
    requestHeader.putProperty(testIgnoredPropertyName, "mustNotReturn");
    requestContext.put(JMSConstants.JMS_CLIENT_REQUEST_HEADERS, requestHeader);
    String greeting = greeter.greetMe("Milestone-");
    assertNotNull("no response received from service", greeting);
    assertEquals("Hello Milestone-", greeting);
    Map<String, Object> responseContext = ((BindingProvider) greeter).getResponseContext();
    JMSMessageHeadersType responseHdr = (JMSMessageHeadersType) responseContext.get(JMSConstants.JMS_CLIENT_RESPONSE_HEADERS);
    if (responseHdr == null) {
        fail("response Header should not be null");
    }
    assertTrue("CORRELATION ID should match :", "JMS_SAMPLE_CORRELATION_ID".equals(responseHdr.getJMSCorrelationID()));
    assertTrue("response Headers must conain the app property set in request context.", responseHdr.getPropertyKeys().size() > 0);
    boolean found = responseHdr.getPropertyKeys().contains(testReturnPropertyName);
    assertTrue("response Headers must match the app property set in request context.", found);
    ((Closeable) greeter).close();
}
Also used : QName(javax.xml.namespace.QName) HelloWorldService(org.apache.cxf.hello_world_jms.HelloWorldService) Closeable(java.io.Closeable) HelloWorldPortType(org.apache.cxf.hello_world_jms.HelloWorldPortType) JMSMessageHeadersType(org.apache.cxf.transport.jms.JMSMessageHeadersType) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) Test(org.junit.Test)

Example 12 with HelloWorldPortType

use of org.apache.cxf.hello_world_jms.HelloWorldPortType in project cxf by apache.

the class JMSClientServerTest method testBasicConnection.

@Test
public void testBasicConnection() throws Exception {
    QName serviceName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldService");
    QName portName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldPort");
    URL wsdl = getWSDLURL("/wsdl/jms_test.wsdl");
    HelloWorldService service = new HelloWorldService(wsdl, serviceName);
    String response1 = new String("Hello Milestone-");
    String response2 = new String("Bonjour");
    HelloWorldPortType greeter = service.getPort(portName, HelloWorldPortType.class);
    for (int idx = 0; idx < 5; idx++) {
        String greeting = greeter.greetMe("Milestone-" + idx);
        assertNotNull("no response received from service", greeting);
        String exResponse = response1 + idx;
        assertEquals(exResponse, greeting);
        String reply = greeter.sayHi();
        assertNotNull("no response received from service", reply);
        assertEquals(response2, reply);
        try {
            greeter.testRpcLitFault("BadRecordLitFault");
            fail("Should have thrown BadRecoedLitFault");
        } catch (BadRecordLitFault ex) {
            assertNotNull(ex.getFaultInfo());
        }
        try {
            greeter.testRpcLitFault("NoSuchCodeLitFault");
            fail("Should have thrown NoSuchCodeLitFault exception");
        } catch (NoSuchCodeLitFault nslf) {
            assertNotNull(nslf.getFaultInfo());
            assertNotNull(nslf.getFaultInfo().getCode());
        }
    }
    ((java.io.Closeable) greeter).close();
}
Also used : BadRecordLitFault(org.apache.cxf.hello_world_jms.BadRecordLitFault) QName(javax.xml.namespace.QName) NoSuchCodeLitFault(org.apache.cxf.hello_world_jms.NoSuchCodeLitFault) HelloWorldService(org.apache.cxf.hello_world_jms.HelloWorldService) Closeable(java.io.Closeable) HelloWorldPortType(org.apache.cxf.hello_world_jms.HelloWorldPortType) URL(java.net.URL) Endpoint(javax.xml.ws.Endpoint) Test(org.junit.Test)

Example 13 with HelloWorldPortType

use of org.apache.cxf.hello_world_jms.HelloWorldPortType in project cxf by apache.

the class JMSClientServerTest method testAsyncCall.

@Ignore
@Test
public void testAsyncCall() throws Exception {
    QName serviceName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldService");
    QName portName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldPort");
    URL wsdl = getWSDLURL("/wsdl/jms_test.wsdl");
    HelloWorldService service = new HelloWorldService(wsdl, serviceName);
    HelloWorldPortType greeter = service.getPort(portName, HelloWorldPortType.class);
    final Thread thread = Thread.currentThread();
    class TestAsyncHandler implements AsyncHandler<String> {

        String expected;

        TestAsyncHandler(String x) {
            expected = x;
        }

        public String getExpected() {
            return expected;
        }

        public void handleResponse(Response<String> response) {
            try {
                Thread thread2 = Thread.currentThread();
                assertNotSame(thread, thread2);
                assertEquals("Hello " + expected, response.get());
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }
    }
    TestAsyncHandler h1 = new TestAsyncHandler("Homer");
    TestAsyncHandler h2 = new TestAsyncHandler("Maggie");
    TestAsyncHandler h3 = new TestAsyncHandler("Bart");
    TestAsyncHandler h4 = new TestAsyncHandler("Lisa");
    TestAsyncHandler h5 = new TestAsyncHandler("Marge");
    Future<?> f1 = greeter.greetMeAsync("Santa's Little Helper", new TestAsyncHandler("Santa's Little Helper"));
    f1.get();
    f1 = greeter.greetMeAsync("PauseForTwoSecs Santa's Little Helper", new TestAsyncHandler("Santa's Little Helper"));
    long start = System.currentTimeMillis();
    f1 = greeter.greetMeAsync("PauseForTwoSecs " + h1.getExpected(), h1);
    Future<?> f2 = greeter.greetMeAsync("PauseForTwoSecs " + h2.getExpected(), h2);
    Future<?> f3 = greeter.greetMeAsync("PauseForTwoSecs " + h3.getExpected(), h3);
    Future<?> f4 = greeter.greetMeAsync("PauseForTwoSecs " + h4.getExpected(), h4);
    Future<?> f5 = greeter.greetMeAsync("PauseForTwoSecs " + h5.getExpected(), h5);
    long mid = System.currentTimeMillis();
    assertEquals("Hello " + h1.getExpected(), f1.get());
    assertEquals("Hello " + h2.getExpected(), f2.get());
    assertEquals("Hello " + h3.getExpected(), f3.get());
    assertEquals("Hello " + h4.getExpected(), f4.get());
    assertEquals("Hello " + h5.getExpected(), f5.get());
    long end = System.currentTimeMillis();
    assertTrue("Time too long: " + (mid - start), (mid - start) < 1000);
    assertTrue((end - mid) > 1000);
    f1 = null;
    f2 = null;
    f3 = null;
    f4 = null;
    f5 = null;
    ((java.io.Closeable) greeter).close();
    greeter = null;
    service = null;
    System.gc();
}
Also used : AsyncHandler(javax.xml.ws.AsyncHandler) QName(javax.xml.namespace.QName) HelloWorldService(org.apache.cxf.hello_world_jms.HelloWorldService) Closeable(java.io.Closeable) HelloWorldPortType(org.apache.cxf.hello_world_jms.HelloWorldPortType) URL(java.net.URL) Response(javax.xml.ws.Response) ExecutionException(java.util.concurrent.ExecutionException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 14 with HelloWorldPortType

use of org.apache.cxf.hello_world_jms.HelloWorldPortType in project cxf by apache.

the class JMSClientServerTest method testConnectionsWithinSpring.

@Test
public void testConnectionsWithinSpring() throws Exception {
    BusFactory.setDefaultBus(null);
    BusFactory.setThreadDefaultBus(null);
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "/org/apache/cxf/systest/jms/JMSClients.xml" });
    try {
        String wsdlString2 = "classpath:wsdl/jms_test.wsdl";
        wsdlStrings.add(wsdlString2);
        broker.updateWsdl((Bus) ctx.getBean("cxf"), wsdlString2);
        HelloWorldPortType greeter = (HelloWorldPortType) ctx.getBean("jmsRPCClient");
        try {
            for (int idx = 0; idx < 5; idx++) {
                String greeting = greeter.greetMe("Milestone-" + idx);
                assertNotNull("no response received from service", greeting);
                String exResponse = "Hello Milestone-" + idx;
                assertEquals(exResponse, greeting);
                String reply = greeter.sayHi();
                assertEquals("Bonjour", reply);
                try {
                    greeter.testRpcLitFault("BadRecordLitFault");
                    fail("Should have thrown BadRecoedLitFault");
                } catch (BadRecordLitFault ex) {
                    assertNotNull(ex.getFaultInfo());
                }
                try {
                    greeter.testRpcLitFault("NoSuchCodeLitFault");
                    fail("Should have thrown NoSuchCodeLitFault exception");
                } catch (NoSuchCodeLitFault nslf) {
                    assertNotNull(nslf.getFaultInfo());
                    assertNotNull(nslf.getFaultInfo().getCode());
                }
            }
        } catch (UndeclaredThrowableException ex) {
            ctx.close();
            throw (Exception) ex.getCause();
        }
        HelloWorldOneWayPort greeter1 = (HelloWorldOneWayPort) ctx.getBean("jmsQueueOneWayServiceClient");
        assertNotNull(greeter1);
        try {
            greeter1.greetMeOneWay("hello");
        } catch (Exception ex) {
            fail("There should not throw the exception" + ex);
        }
    } finally {
        ctx.close();
        BusFactory.setDefaultBus(getBus());
        BusFactory.setThreadDefaultBus(getBus());
    }
}
Also used : BadRecordLitFault(org.apache.cxf.hello_world_jms.BadRecordLitFault) HelloWorldOneWayPort(org.apache.cxf.hello_world_jms.HelloWorldOneWayPort) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) NoSuchCodeLitFault(org.apache.cxf.hello_world_jms.NoSuchCodeLitFault) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) HelloWorldPortType(org.apache.cxf.hello_world_jms.HelloWorldPortType) Endpoint(javax.xml.ws.Endpoint) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 15 with HelloWorldPortType

use of org.apache.cxf.hello_world_jms.HelloWorldPortType in project cxf by apache.

the class JMSWSSecurityTest method testUnsignedSAML2AudienceRestrictionTokenBadURI.

@Test
public void testUnsignedSAML2AudienceRestrictionTokenBadURI() throws Exception {
    QName serviceName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldService");
    QName portName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldPort");
    URL wsdl = getWSDLURL("/wsdl/jms_test.wsdl");
    HelloWorldService service = new HelloWorldService(wsdl, serviceName);
    HelloWorldPortType greeter = service.getPort(portName, HelloWorldPortType.class);
    SamlCallbackHandler callbackHandler = new SamlCallbackHandler();
    callbackHandler.setSignAssertion(true);
    callbackHandler.setConfirmationMethod(SAML2Constants.CONF_BEARER);
    ConditionsBean conditions = new ConditionsBean();
    conditions.setTokenPeriodMinutes(5);
    List<String> audiences = new ArrayList<>();
    audiences.add("jms:jndi:dynamicQueues/test.jmstransport.text.bad");
    AudienceRestrictionBean audienceRestrictionBean = new AudienceRestrictionBean();
    audienceRestrictionBean.setAudienceURIs(audiences);
    conditions.setAudienceRestrictions(Collections.singletonList(audienceRestrictionBean));
    callbackHandler.setConditions(conditions);
    Map<String, Object> outProperties = new HashMap<>();
    outProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_UNSIGNED);
    outProperties.put(ConfigurationConstants.SAML_CALLBACK_REF, callbackHandler);
    WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(outProperties);
    Client client = ClientProxy.getClient(greeter);
    client.getOutInterceptors().add(outInterceptor);
    try {
        greeter.sayHi();
        fail("Failure expected on a bad audience restriction");
    } catch (SOAPFaultException ex) {
    // expected
    }
    ((java.io.Closeable) greeter).close();
}
Also used : AudienceRestrictionBean(org.apache.wss4j.common.saml.bean.AudienceRestrictionBean) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) HelloWorldService(org.apache.cxf.hello_world_jms.HelloWorldService) ConditionsBean(org.apache.wss4j.common.saml.bean.ConditionsBean) ArrayList(java.util.ArrayList) HelloWorldPortType(org.apache.cxf.hello_world_jms.HelloWorldPortType) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) URL(java.net.URL) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Aggregations

HelloWorldPortType (org.apache.cxf.hello_world_jms.HelloWorldPortType)18 Test (org.junit.Test)18 QName (javax.xml.namespace.QName)17 URL (java.net.URL)16 HelloWorldService (org.apache.cxf.hello_world_jms.HelloWorldService)10 ArrayList (java.util.ArrayList)7 AbstractVmJMSTest (org.apache.cxf.systest.jms.AbstractVmJMSTest)7 Closeable (java.io.Closeable)5 HashMap (java.util.HashMap)5 Client (org.apache.cxf.endpoint.Client)5 WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)5 AudienceRestrictionBean (org.apache.wss4j.common.saml.bean.AudienceRestrictionBean)4 ConditionsBean (org.apache.wss4j.common.saml.bean.ConditionsBean)4 Endpoint (javax.xml.ws.Endpoint)3 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)3 ExecutionException (java.util.concurrent.ExecutionException)2 BadRecordLitFault (org.apache.cxf.hello_world_jms.BadRecordLitFault)2 NoSuchCodeLitFault (org.apache.cxf.hello_world_jms.NoSuchCodeLitFault)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 AsyncHandler (javax.xml.ws.AsyncHandler)1