Search in sources :

Example 31 with GreeterService

use of org.apache.cxf.greeter_control.GreeterService in project cxf by apache.

the class DecoupledClientServerTest method testDecoupled.

@Test
public void testDecoupled() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    bus = bf.createBus("/org/apache/cxf/systest/ws/rm/decoupled.xml");
    BusFactory.setDefaultBus(bus);
    LoggingInInterceptor in = new LoggingInInterceptor();
    bus.getInInterceptors().add(in);
    bus.getInFaultInterceptors().add(in);
    LoggingOutInterceptor out = new LoggingOutInterceptor();
    bus.getOutInterceptors().add(out);
    bus.getOutFaultInterceptors().add(out);
    GreeterService gs = new GreeterService();
    final Greeter greeter = gs.getGreeterPort();
    updateAddressPort(greeter, PORT);
    ((BindingProvider) greeter).getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.TRUE);
    LOG.fine("Created greeter client.");
    ConnectionHelper.setKeepAliveConnection(greeter, true);
    class TwowayThread extends Thread {

        String response;

        @Override
        public void run() {
            response = greeter.greetMe("twoway");
        }
    }
    TwowayThread t = new TwowayThread();
    t.start();
    // allow for partial response to twoway request to arrive
    long wait = 3000;
    while (wait > 0) {
        long start = System.currentTimeMillis();
        try {
            Thread.sleep(wait);
        } catch (InterruptedException ex) {
        // ignore
        }
        wait -= System.currentTimeMillis() - start;
    }
    greeter.greetMeOneWay("oneway");
    t.join();
    assertEquals("Unexpected response to twoway request", "oneway", t.response);
}
Also used : SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) Greeter(org.apache.cxf.greeter_control.Greeter) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) GreeterService(org.apache.cxf.greeter_control.GreeterService) Test(org.junit.Test)

Example 32 with GreeterService

use of org.apache.cxf.greeter_control.GreeterService in project cxf by apache.

the class ManagedEndpointsTest method testSuspendAndResumeSourceSequence.

@Test
public void testSuspendAndResumeSourceSequence() throws Exception {
    prepareClient();
    RMManager clientManager = clientBus.getExtension(RMManager.class);
    InstrumentationManager serverIM = serverBus.getExtension(InstrumentationManager.class);
    MBeanServer mbs = serverIM.getMBeanServer();
    assertNotNull("MBeanServer must be available.", mbs);
    Object o;
    GreeterService gs = new GreeterService();
    final Greeter greeter = gs.getGreeterPort();
    updateAddressPort(greeter, ManagedEndpointsTest.PORT);
    LOG.fine("Created greeter client.");
    org.apache.cxf.endpoint.Endpoint ep = ClientProxy.getClient(greeter).getEndpoint();
    ObjectName clientEndpointName = RMUtils.getManagedObjectName(clientManager, ep);
    // sent
    greeter.greetMeOneWay("one");
    o = mbs.invoke(clientEndpointName, "getCurrentSourceSequenceId", null, null);
    assertTrue(o instanceof String);
    String sseqId = (String) o;
    o = mbs.invoke(clientEndpointName, "getUnAcknowledgedMessageIdentifiers", new Object[] { sseqId }, ONESTRING_SIGNATURE);
    assertTrue("No unacknowledged message", o instanceof Long[] && 0 == ((Long[]) o).length);
    // sent but suspended
    greeter.greetMeOneWay("two");
    // sent but suspended
    greeter.greetMeOneWay("three");
    o = mbs.invoke(clientEndpointName, "getQueuedMessageTotalCount", new Object[] { true }, ONEBOOLEAN_SIGNATURE);
    assertTrue("One queued message", o instanceof Integer && 1 == ((Integer) o).intValue());
    mbs.invoke(clientEndpointName, "suspendSourceQueue", new Object[] { sseqId }, ONESTRING_SIGNATURE);
    LOG.info("suspended the source queue: " + sseqId);
    // 3 sec retry interval + 1 sec
    LOG.info("waiting for 4 secs for the retry (suspended)...");
    Thread.sleep(4000);
    o = mbs.invoke(clientEndpointName, "getQueuedMessageTotalCount", new Object[] { true }, ONEBOOLEAN_SIGNATURE);
    assertTrue("One queued message", o instanceof Integer && 1 == ((Integer) o).intValue());
    mbs.invoke(clientEndpointName, "resumeSourceQueue", new Object[] { sseqId }, ONESTRING_SIGNATURE);
    LOG.info("resumed the source queue: " + sseqId);
    o = mbs.invoke(clientEndpointName, "getQueuedMessageTotalCount", new Object[] { true }, ONEBOOLEAN_SIGNATURE);
    int count = 0;
    assertTrue(o instanceof Integer);
    while (((Integer) o).intValue() > 0) {
        Thread.sleep(200);
        count++;
        if (count > 100) {
            // up to 20 seconds to do the resend, should be within 3 or 4
            fail("Failed to empty the resend queue");
        }
        o = mbs.invoke(clientEndpointName, "getQueuedMessageTotalCount", new Object[] { true }, ONEBOOLEAN_SIGNATURE);
        assertTrue(o instanceof Integer);
    }
    assertTrue("No queued messages", o instanceof Integer && 0 == ((Integer) o).intValue());
}
Also used : GreeterService(org.apache.cxf.greeter_control.GreeterService) InstrumentationManager(org.apache.cxf.management.InstrumentationManager) Endpoint(javax.xml.ws.Endpoint) ObjectName(javax.management.ObjectName) RMManager(org.apache.cxf.ws.rm.RMManager) Greeter(org.apache.cxf.greeter_control.Greeter) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 33 with GreeterService

use of org.apache.cxf.greeter_control.GreeterService in project cxf by apache.

the class MessageCallbackOnewayTest method initProxy.

private void initProxy(Executor executor) {
    GreeterService gs = new GreeterService();
    if (null != executor) {
        gs.setExecutor(executor);
    }
    greeter = gs.getGreeterPort();
    try {
        updateAddressPort(greeter, PORT);
    } catch (Exception e) {
    // ignore
    }
    LOG.fine("Created greeter client.");
    ConnectionHelper.setKeepAliveConnection(greeter, false);
    callback = new RecordingMessageCallback();
    ((BindingProvider) greeter).getRequestContext().put(RMMessageConstants.RM_CLIENT_CALLBACK, callback);
}
Also used : GreeterService(org.apache.cxf.greeter_control.GreeterService)

Example 34 with GreeterService

use of org.apache.cxf.greeter_control.GreeterService in project cxf by apache.

the class RetransmissionGZIPTest method testDecoupleFaultHandling.

@Test
public void testDecoupleFaultHandling() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    bus = bf.createBus("/org/apache/cxf/systest/ws/rm/gzip-enabled.xml");
    BusFactory.setDefaultBus(bus);
    LoggingInInterceptor in = new LoggingInInterceptor();
    bus.getInInterceptors().add(in);
    bus.getInFaultInterceptors().add(in);
    LoggingOutInterceptor out = new LoggingOutInterceptor();
    bus.getOutInterceptors().add(out);
    bus.getExtension(RMManager.class).getConfiguration().setBaseRetransmissionInterval(new Long(4000));
    // an interceptor to simulate a transmission error
    MessageLossSimulator loser = new MessageLossSimulator();
    bus.getOutInterceptors().add(loser);
    bus.getOutFaultInterceptors().add(out);
    GreeterService gs = new GreeterService();
    final Greeter greeter = gs.getGreeterPort();
    updateAddressPort(greeter, PORT);
    LOG.fine("Created greeter client.");
    ConnectionHelper.setKeepAliveConnection(greeter, true);
    loser.setMode(-1);
    loser.setThrowsException(true);
    try {
        greeter.greetMeOneWay("oneway");
    } catch (Exception e) {
        fail("fault thrown after queued for retransmission");
    }
    Thread.sleep(2000);
    RMManager manager = bus.getExtension(RMManager.class);
    boolean empty = manager.getRetransmissionQueue().isEmpty();
    assertFalse("RetransmissionQueue is empty", empty);
    loser.setMode(1);
    Thread.sleep(6000);
    empty = manager.getRetransmissionQueue().isEmpty();
    assertTrue("RetransmissionQueue not cleared", empty);
}
Also used : SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) RMManager(org.apache.cxf.ws.rm.RMManager) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) Greeter(org.apache.cxf.greeter_control.Greeter) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) GreeterService(org.apache.cxf.greeter_control.GreeterService) Test(org.junit.Test)

Example 35 with GreeterService

use of org.apache.cxf.greeter_control.GreeterService in project cxf by apache.

the class RetransmissionQueueTest method testOnewayFaultHandlingWithoutRetry.

@Test
public void testOnewayFaultHandlingWithoutRetry() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    bus = bf.createBus("/org/apache/cxf/systest/ws/rm/message-loss.xml");
    BusFactory.setDefaultBus(bus);
    LoggingInInterceptor in = new LoggingInInterceptor();
    bus.getInInterceptors().add(in);
    bus.getInFaultInterceptors().add(in);
    LoggingOutInterceptor out = new LoggingOutInterceptor();
    bus.getOutInterceptors().add(out);
    bus.getExtension(RMManager.class).getConfiguration().setBaseRetransmissionInterval(new Long(4000));
    SourcePolicyType sourcePolicy = new SourcePolicyType();
    RetryPolicyType retryP = new RetryPolicyType();
    retryP.setMaxRetries(0);
    sourcePolicy.setRetryPolicy(retryP);
    bus.getExtension(RMManager.class).setSourcePolicy(sourcePolicy);
    // an interceptor to simulate a transmission error
    MessageLossSimulator loser = new MessageLossSimulator();
    bus.getOutInterceptors().add(loser);
    bus.getOutFaultInterceptors().add(out);
    GreeterService gs = new GreeterService();
    final Greeter greeter = gs.getGreeterPort();
    updateAddressPort(greeter, PORT);
    LOG.fine("Created greeter client.");
    ConnectionHelper.setKeepAliveConnection(greeter, true);
    loser.setMode(-1);
    loser.setThrowsException(true);
    try {
        greeter.greetMeOneWay("oneway");
        fail("no retransmission so catch an Exception");
    } catch (Exception e) {
        assertEquals("simulated transmission exception", e.getMessage());
    }
    Thread.sleep(6000);
    RMManager manager = bus.getExtension(RMManager.class);
    boolean empty = manager.getRetransmissionQueue().isEmpty();
    assertFalse("RetransmissionQueue is empty", empty);
}
Also used : SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) RMManager(org.apache.cxf.ws.rm.RMManager) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) Greeter(org.apache.cxf.greeter_control.Greeter) SourcePolicyType(org.apache.cxf.ws.rm.manager.SourcePolicyType) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) GreeterService(org.apache.cxf.greeter_control.GreeterService) RetryPolicyType(org.apache.cxf.ws.rm.manager.RetryPolicyType) Test(org.junit.Test)

Aggregations

GreeterService (org.apache.cxf.greeter_control.GreeterService)42 Greeter (org.apache.cxf.greeter_control.Greeter)28 Test (org.junit.Test)28 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)15 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)10 BindingProvider (javax.xml.ws.BindingProvider)10 RMManager (org.apache.cxf.ws.rm.RMManager)10 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)7 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)7 ControlService (org.apache.cxf.greeter_control.ControlService)4 MBeanServer (javax.management.MBeanServer)3 ObjectName (javax.management.ObjectName)3 InstrumentationManager (org.apache.cxf.management.InstrumentationManager)3 IOException (java.io.IOException)2 List (java.util.List)2 TransformerException (javax.xml.transform.TransformerException)2 DOMSource (javax.xml.transform.dom.DOMSource)2 WebServiceException (javax.xml.ws.WebServiceException)2 Bus (org.apache.cxf.Bus)2 Client (org.apache.cxf.endpoint.Client)2