Search in sources :

Example 21 with RMProperties

use of org.apache.cxf.ws.rm.RMProperties in project cxf by apache.

the class RedeliveryQueueImpl method getUndeliveredMessageNumbers.

public List<Long> getUndeliveredMessageNumbers(DestinationSequence seq) {
    List<Long> undelivered = new ArrayList<>();
    List<RedeliverCandidate> sequenceCandidates = getSequenceCandidates(seq);
    if (null != sequenceCandidates) {
        for (int i = 0; i < sequenceCandidates.size(); i++) {
            RedeliverCandidate candidate = sequenceCandidates.get(i);
            RMProperties properties = RMContextUtils.retrieveRMProperties(candidate.getMessage(), false);
            SequenceType st = properties.getSequence();
            undelivered.add(st.getMessageNumber());
        }
    }
    return undelivered;
}
Also used : ArrayList(java.util.ArrayList) SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType) Endpoint(org.apache.cxf.endpoint.Endpoint) RMProperties(org.apache.cxf.ws.rm.RMProperties)

Example 22 with RMProperties

use of org.apache.cxf.ws.rm.RMProperties in project cxf by apache.

the class RetransmissionQueueImpl method getDefaultResender.

/**
 * Create default Resender logic.
 *
 * @return default Resender
 */
protected final Resender getDefaultResender() {
    return new Resender() {

        public void resend(Message message, boolean requestAcknowledge) {
            RMProperties properties = RMContextUtils.retrieveRMProperties(message, true);
            SequenceType st = properties.getSequence();
            if (st != null) {
                LOG.log(Level.INFO, "RESEND_MSG", st.getMessageNumber());
            }
            if (message instanceof SoapMessage) {
                doResend((SoapMessage) message);
            } else {
                doResend(new SoapMessage(message));
            }
        }
    };
}
Also used : SoapMessage(org.apache.cxf.binding.soap.SoapMessage) Message(org.apache.cxf.message.Message) SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType) RMProperties(org.apache.cxf.ws.rm.RMProperties) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Example 23 with RMProperties

use of org.apache.cxf.ws.rm.RMProperties in project cxf by apache.

the class SoapFaultFactory method createSoap12Fault.

Fault createSoap12Fault(SequenceFault sf, Message msg) {
    SoapFault fault = (SoapFault) createSoap11Fault(sf);
    fault.setSubCode(sf.getFaultCode());
    Object detail = sf.getDetail();
    if (null == detail) {
        return fault;
    }
    try {
        RMProperties rmps = RMContextUtils.retrieveRMProperties(msg, false);
        AddressingProperties maps = RMContextUtils.retrieveMAPs(msg, false, false);
        EncoderDecoder codec = ProtocolVariation.findVariant(rmps.getNamespaceURI(), maps.getNamespaceURI()).getCodec();
        setDetail(fault, detail, codec);
    } catch (Exception ex) {
        LogUtils.log(LOG, Level.SEVERE, "MARSHAL_FAULT_DETAIL_EXC", ex);
        ex.printStackTrace();
    }
    return fault;
}
Also used : SoapFault(org.apache.cxf.binding.soap.SoapFault) EncoderDecoder(org.apache.cxf.ws.rm.EncoderDecoder) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) RMProperties(org.apache.cxf.ws.rm.RMProperties)

Example 24 with RMProperties

use of org.apache.cxf.ws.rm.RMProperties in project cxf by apache.

the class SequenceTest method doTestTwowayNoDuplicates.

private void doTestTwowayNoDuplicates(String cfg) throws Exception {
    init(cfg);
    class MessageNumberInterceptor extends AbstractPhaseInterceptor<Message> {

        MessageNumberInterceptor() {
            super(Phase.PRE_STREAM);
        }

        public void handleMessage(Message m) {
            RMProperties rmps = RMContextUtils.retrieveRMProperties(m, true);
            if (null != rmps && null != rmps.getSequence()) {
                rmps.getSequence().setMessageNumber(new Long(1));
            }
        }
    }
    greeterBus.getOutInterceptors().add(new MessageNumberInterceptor());
    RMManager manager = greeterBus.getExtension(RMManager.class);
    manager.getConfiguration().setBaseRetransmissionInterval(new Long(2000));
    greeter.greetMe("one");
    try {
        ((BindingProvider) greeter).getRequestContext().put("cxf.synchronous.timeout", 5000);
        String s = greeter.greetMe("two");
        fail("Expected timeout. Received response: " + s);
    } catch (WebServiceException ex) {
        assertTrue("Unexpected exception cause", ex.getCause() instanceof IOException);
        IOException ie = (IOException) ex.getCause();
        assertTrue("Unexpected IOException message", ie.getMessage().startsWith("Timed out"));
    }
    // wait for resend to occur
    awaitMessages(4, 3, 5000);
    MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);
    // Expected outbound:
    // CreateSequence
    // + two requests
    // + acknowledgement
    String[] expectedActions = new String[4];
    expectedActions[0] = RM10Constants.CREATE_SEQUENCE_ACTION;
    expectedActions[1] = GREETME_ACTION;
    expectedActions[2] = GREETME_ACTION;
    expectedActions[3] = RM10Constants.SEQUENCE_ACKNOWLEDGMENT_ACTION;
    mf.verifyActions(expectedActions, true);
    mf.verifyMessageNumbers(new String[] { null, "1", "1", null }, true);
    mf.verifyLastMessage(new boolean[expectedActions.length], true);
    mf.verifyAcknowledgements(new boolean[] { false, false, false, true }, true);
    // Expected inbound:
    // createSequenceResponse
    // + 1 response without acknowledgement
    // + 1 acknowledgement/last message
    mf.verifyMessages(3, false);
    expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION, GREETME_RESPONSE_ACTION, RM10Constants.SEQUENCE_ACKNOWLEDGMENT_ACTION };
    mf.verifyActions(expectedActions, false);
    mf.verifyMessageNumbers(new String[] { null, "1", null }, false);
    mf.verifyAcknowledgements(new boolean[] { false, false, true }, false);
}
Also used : RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) Message(org.apache.cxf.message.Message) WebServiceException(javax.xml.ws.WebServiceException) RMManager(org.apache.cxf.ws.rm.RMManager) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) IOException(java.io.IOException) MessageFlow(org.apache.cxf.systest.ws.util.MessageFlow) RMProperties(org.apache.cxf.ws.rm.RMProperties)

Example 25 with RMProperties

use of org.apache.cxf.ws.rm.RMProperties in project cxf by apache.

the class SequenceTest method testUnknownSequence.

@Test
public void testUnknownSequence() throws Exception {
    init("org/apache/cxf/systest/ws/rm/rminterceptors.xml");
    class SequenceIdInterceptor extends AbstractPhaseInterceptor<Message> {

        SequenceIdInterceptor() {
            super(Phase.PRE_STREAM);
        }

        public void handleMessage(Message m) {
            RMProperties rmps = RMContextUtils.retrieveRMProperties(m, true);
            if (null != rmps && null != rmps.getSequence()) {
                rmps.getSequence().getIdentifier().setValue("UNKNOWN");
            }
        }
    }
    greeterBus.getOutInterceptors().add(new SequenceIdInterceptor());
    RMManager manager = greeterBus.getExtension(RMManager.class);
    manager.getConfiguration().setBaseRetransmissionInterval(new Long(2000));
    try {
        greeter.greetMe("one");
        fail("Expected fault.");
    } catch (WebServiceException ex) {
        SoapFault sf = (SoapFault) ex.getCause();
        assertEquals("Unexpected fault code.", Soap11.getInstance().getSender(), sf.getFaultCode());
        assertNull("Unexpected sub code.", sf.getSubCode());
        assertTrue("Unexpected reason.", sf.getReason().endsWith("is not a known Sequence identifier."));
    }
    // the third inbound message has a SequenceFault header
    MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);
    mf.verifySequenceFault(RM10Constants.UNKNOWN_SEQUENCE_FAULT_QNAME, false, 1);
    String[] expectedActions = new String[3];
    expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION, RM10_GENERIC_FAULT_ACTION };
    mf.verifyActions(expectedActions, false);
}
Also used : SoapFault(org.apache.cxf.binding.soap.SoapFault) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) Message(org.apache.cxf.message.Message) WebServiceException(javax.xml.ws.WebServiceException) RMManager(org.apache.cxf.ws.rm.RMManager) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) MessageFlow(org.apache.cxf.systest.ws.util.MessageFlow) RMProperties(org.apache.cxf.ws.rm.RMProperties) Test(org.junit.Test)

Aggregations

RMProperties (org.apache.cxf.ws.rm.RMProperties)25 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)12 SequenceType (org.apache.cxf.ws.rm.v200702.SequenceType)11 Message (org.apache.cxf.message.Message)10 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)8 Test (org.junit.Test)6 Endpoint (org.apache.cxf.endpoint.Endpoint)5 MessageImpl (org.apache.cxf.message.MessageImpl)4 Identifier (org.apache.cxf.ws.rm.v200702.Identifier)4 SoapFault (org.apache.cxf.binding.soap.SoapFault)3 Exchange (org.apache.cxf.message.Exchange)3 ProtocolVariation (org.apache.cxf.ws.rm.ProtocolVariation)3 RMEndpoint (org.apache.cxf.ws.rm.RMEndpoint)3 RMException (org.apache.cxf.ws.rm.RMException)3 SequenceAcknowledgement (org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 MessageFactory (javax.xml.soap.MessageFactory)2 SOAPMessage (javax.xml.soap.SOAPMessage)2