FileDocCategorySizeDatePackage
InboundMessageProcessor.javaAPI DocExample8720Tue May 29 16:56:42 BST 2007com.sun.xml.ws.rm.jaxws.runtime

InboundMessageProcessor

public class InboundMessageProcessor extends Object
InboundMessageProcessor examines the headers of inbound Messages and based on the sequence id's and types of the headers, dispatches them to appropriate ClientInboundSequence or ClientOutboundSequence methods.

Fields Summary
private RMProvider
provider
Constructors Summary
public InboundMessageProcessor(RMProvider provider)

       
        this.provider = provider;
    
Methods Summary
public voidprocessMessage(Message message, javax.xml.bind.Marshaller marshaller, javax.xml.bind.Unmarshaller unmarshaller)
For each inbound Message, invokes protocol logic dictated by the contents of the WS-RM protocol headers on the message.
  • Sequence Header
    Adds the message to the instance data of this incoming sequence according using the Sequence Identifier and Message Number in the header.
  • SequenceAcknowledgement Header
    Invokes the handleAckResponse method of the companion ClientOutboundSequence which marks acknowledged messages as delivered.
  • AckRequested Header
    Constructs a SequenceAcknowledgementElement reflecting the messages belonging to this sequence that have been received. Sets the resulting SequenceAcknowledgementElement in the state of the companion ClientOutboundSequence.

param
message The inbound Message.


            
            try {
                
                /*
                 * Check for each RM header type and do the right thing in RMProvider
                 * depending on the type.
                 */

                InboundSequence inseq =null;

                Header header = message.getHeader("Sequence");
                if (header != null) {
                    //identify sequence and message number from data in header and add
                    //the message to the sequence at the specified index.
                    //TODO handle error condition seq == null
                    SequenceElement el = 
                                (SequenceElement)header.readAsJAXB(unmarshaller);
                    
                    message.setSequenceElement(el);
                    
                    String seqid = el.getId();

                    //add message to ClientInboundSequence
                    int messageNumber = (int)el.getNumber();
                    if (messageNumber == Integer.MAX_VALUE){
                        throw new MessageNumberRolloverException(String.format(Constants.MESSAGE_NUMBER_ROLLOVER_TEXT,messageNumber),messageNumber);
                    }
                    
                    inseq =   provider.getInboundSequence(seqid);
                    
                    if (inseq != null) {
                        inseq.set(messageNumber, message);
                    } else {
                        throw new InvalidSequenceException(String.format(Constants.UNKNOWN_SEQUENCE_TEXT,seqid),seqid);
                    }

                } 


                header = message.getHeader("SequenceAcknowledgement");
                if (header != null) {
                    
                    //determine OutboundSequence id from data in header and update
                    //state of that sequence according to the acks and nacks in the element 
                    SequenceAcknowledgementElement ackHeader =
                            (SequenceAcknowledgementElement)(header.readAsJAXB(unmarshaller));
                    
                    message.setSequenceAcknowledgementElement(ackHeader);
                    
                    OutboundSequence seq =
                            provider.getOutboundSequence(ackHeader.getId());

                    if (seq != null) {
                        seq.handleAckResponse(ackHeader);
                    }
                }
                
                
                header = message.getHeader("AckRequested");
                if (header != null) {
 
                    //dispatch to InboundSequence to construct response.
                    //TODO handle error condition no such sequence
                     AckRequestedElement el = 
                             (AckRequestedElement)header.readAsJAXB(unmarshaller);
                     
                     message.setAckRequestedElement(el);
                     
                     String id = el.getId();

                    InboundSequence seq =
                            provider.getInboundSequence(id);

                    if (seq != null) {
                        seq.handleAckRequested((AckRequestedElement)el, marshaller);
                    }

                } else {
                    //FIXME - We need to be checking whether this is a ServerInboundSequence
                    //in a port with a two-way operation.  This is the case where MS
                    //puts a SequenceAcknowledgement on every message.
                    
                    //Need to check this with the latest CTP
                    //Currently with Dec CTP the client message
                    //does not have AckRequested element
                    // but they are expecting a SequenceAcknowledgement
                    //Hack for now
                    
                    if (inseq != null) {
                        
                        inseq.handleAckRequested(null, marshaller);
                    } else {
                        //we can get here if there is no sequence header.  Perhaps this
                        //is a ClientInboundSequence where the OutboundSequence has no two-ways
                    }
                    
                }

                
            } catch (JAXBException e) {
                throw new RMException(e);
            }