### Question:
DecoupledFaultHandler extends AbstractSoapInterceptor { public void handleFault(SoapMessage message) { if (!ContextUtils.isRequestor(message)) { Exchange exchange = message.getExchange(); Message inMessage = exchange.getInMessage(); final AddressingProperties maps = ContextUtils.retrieveMAPs(inMessage, false, false, true); if (maps != null && !ContextUtils.isGenericAddress(maps.getFaultTo())) { if (exchange.getOutMessage() != null) { message = (SoapMessage)exchange.getOutMessage(); } Iterator<Header> iterator = message.getHeaders().iterator(); while (iterator.hasNext()) { Header header = iterator.next(); if (!isWSAHeader(header)) { iterator.remove(); } } exchange.setOneWay(false); exchange.setOutMessage(message); message.put(ContextUtils.ACTION, WSA_ACTION); Destination destination = createDecoupledDestination( exchange, maps.getFaultTo()); exchange.setDestination(destination); } } } DecoupledFaultHandler(); void handleMessage(SoapMessage message); void handleFault(SoapMessage message); static final String WSA_ACTION; }### Answer:
@Test public void testOnewayFault() { DecoupledFaultHandler handler = new DecoupledFaultHandler() { protected Destination createDecoupledDestination(Exchange exchange, EndpointReferenceType epr) { assertEquals("http: return EasyMock.createMock(Destination.class); } }; SoapMessage message = new SoapMessage(new MessageImpl()); QName qname = new QName("http: message.getHeaders().add(new Header(qname, new Object())); AddressingProperties maps = new AddressingProperties(); EndpointReferenceType faultTo = new EndpointReferenceType(); faultTo.setAddress(new AttributedURIType()); faultTo.getAddress().setValue("http: maps.setFaultTo(faultTo); message.put(ContextUtils.getMAPProperty(false, false, false), maps); Exchange exchange = new ExchangeImpl(); message.setExchange(exchange); exchange.setInMessage(message); exchange.setOneWay(true); handler.handleFault(message); assertTrue(message.getHeaders().isEmpty()); assertFalse(exchange.isOneWay()); assertSame(message, exchange.getOutMessage()); assertNotNull(exchange.getDestination()); }
@Test public void testOnewayFault() { DecoupledFaultHandler handler = new DecoupledFaultHandler() { protected Destination createDecoupledDestination(Exchange exchange, EndpointReferenceType epr) { assertEquals("http: return EasyMock.createMock(Destination.class); } }; SoapMessage message = new SoapMessage(new MessageImpl()); QName qname = new QName("http: message.getHeaders().add(new Header(qname, new Object())); AddressingProperties maps = new AddressingPropertiesImpl(); EndpointReferenceType faultTo = new EndpointReferenceType(); faultTo.setAddress(new AttributedURIType()); faultTo.getAddress().setValue("http: maps.setFaultTo(faultTo); message.put(ContextUtils.getMAPProperty(false, false, false), maps); Exchange exchange = new ExchangeImpl(); message.setExchange(exchange); exchange.setInMessage(message); exchange.setOneWay(true); handler.handleFault(message); assertTrue(message.getHeaders().isEmpty()); assertFalse(exchange.isOneWay()); assertSame(message, exchange.getOutMessage()); assertNotNull(exchange.getDestination()); }