Search in sources :

Example 1 with RetryPolicyType

use of org.apache.cxf.ws.rm.manager.RetryPolicyType in project cxf by apache.

the class RMInInterceptorTest method testProcessInvalidMessageOnFault.

@Test
public void testProcessInvalidMessageOnFault() throws SequenceFault, RMException {
    interceptor = new RMInInterceptor();
    manager = control.createMock(RMManager.class);
    interceptor.setManager(manager);
    Message message = control.createMock(Message.class);
    Exchange exchange = control.createMock(Exchange.class);
    EasyMock.expect(message.getExchange()).andReturn(exchange).anyTimes();
    control.replay();
    try {
        interceptor.handleFault(message);
    } catch (Exception e) {
        fail("unexpected exception thrown from handleFault: " + e);
    }
    control.reset();
    EasyMock.expect(message.getExchange()).andReturn(exchange).anyTimes();
    EasyMock.expect(message.get(RMMessageConstants.DELIVERING_ROBUST_ONEWAY)).andReturn(true).anyTimes();
    control.replay();
    try {
        interceptor.handleFault(message);
    } catch (Exception e) {
        fail("unexpected exception thrown from handleFault: " + e);
    }
    control.reset();
    org.apache.cxf.transport.Destination td = control.createMock(org.apache.cxf.transport.Destination.class);
    EasyMock.expect(exchange.getDestination()).andReturn(td).anyTimes();
    EasyMock.expect(message.getExchange()).andReturn(exchange).anyTimes();
    EasyMock.expect(message.get(RMMessageConstants.RM_PROTOCOL_VARIATION)).andReturn(ProtocolVariation.RM10WSA200408).anyTimes();
    EasyMock.expect(message.getContent(Exception.class)).andReturn(new SequenceFault("no sequence")).anyTimes();
    DestinationPolicyType dp = new DestinationPolicyType();
    RetryPolicyType rp = new RetryPolicyType();
    dp.setRetryPolicy(rp);
    EasyMock.expect(manager.getDestinationPolicy()).andReturn(dp).anyTimes();
    RedeliveryQueue rq = control.createMock(RedeliveryQueue.class);
    EasyMock.expect(manager.getRedeliveryQueue()).andReturn(rq).anyTimes();
    rq.addUndelivered(message);
    EasyMock.expectLastCall().andThrow(new RuntimeException("shouldn't be queued")).anyTimes();
    control.replay();
    try {
        interceptor.handleFault(message);
    } catch (Exception e) {
        fail("unexpected exception thrown from handleFault: " + e);
    }
}
Also used : Message(org.apache.cxf.message.Message) DestinationPolicyType(org.apache.cxf.ws.rm.manager.DestinationPolicyType) Exchange(org.apache.cxf.message.Exchange) RetryPolicyType(org.apache.cxf.ws.rm.manager.RetryPolicyType) Test(org.junit.Test)

Example 2 with RetryPolicyType

use of org.apache.cxf.ws.rm.manager.RetryPolicyType in project cxf by apache.

the class RetransmissionQueueImplTest method setupRetryPolicy.

private void setupRetryPolicy(Message message) {
    SourcePolicyType spt = control.createMock(SourcePolicyType.class);
    EasyMock.expect(manager.getSourcePolicy()).andReturn(spt).anyTimes();
    RetryPolicyType rpt = control.createMock(RetryPolicyType.class);
    EasyMock.expect(spt.getRetryPolicy()).andReturn(rpt);
    EasyMock.expect(rpt.getMaxRetries()).andReturn(3);
}
Also used : SourcePolicyType(org.apache.cxf.ws.rm.manager.SourcePolicyType) RetryPolicyType(org.apache.cxf.ws.rm.manager.RetryPolicyType)

Example 3 with RetryPolicyType

use of org.apache.cxf.ws.rm.manager.RetryPolicyType in project cxf by apache.

the class RetransmissionInterceptor method handle.

void handle(Message message, boolean isFault) {
    if (null == getManager().getRetransmissionQueue()) {
        return;
    }
    OutputStream os = message.getContent(OutputStream.class);
    if (null == os) {
        return;
    }
    if (isFault) {
        RetryPolicyType rmrp = null != manager.getSourcePolicy() ? manager.getSourcePolicy().getRetryPolicy() : null;
        int maxRetries = null != rmrp ? rmrp.getMaxRetries() : -1;
        if (maxRetries != 0) {
            // remove the exception set by the PhaseInterceptorChain so that the
            // error does not reach the client when retransmission is scheduled
            message.setContent(Exception.class, null);
            message.getExchange().put(Exception.class, null);
        }
    }
}
Also used : OutputStream(java.io.OutputStream) RetryPolicyType(org.apache.cxf.ws.rm.manager.RetryPolicyType)

Example 4 with RetryPolicyType

use of org.apache.cxf.ws.rm.manager.RetryPolicyType 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

RetryPolicyType (org.apache.cxf.ws.rm.manager.RetryPolicyType)4 SourcePolicyType (org.apache.cxf.ws.rm.manager.SourcePolicyType)2 Test (org.junit.Test)2 OutputStream (java.io.OutputStream)1 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)1 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)1 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)1 Greeter (org.apache.cxf.greeter_control.Greeter)1 GreeterService (org.apache.cxf.greeter_control.GreeterService)1 Exchange (org.apache.cxf.message.Exchange)1 Message (org.apache.cxf.message.Message)1 RMManager (org.apache.cxf.ws.rm.RMManager)1 DestinationPolicyType (org.apache.cxf.ws.rm.manager.DestinationPolicyType)1