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