* Invoke should rethrow any exceptions it catches, wrapped in
* an AxisFault.
*/
public void invoke(MessageContext msgContext) throws AxisFault {
SOAPEnvelope req = msgContext.getRequestMessage().getSOAPEnvelope();
SOAPHeaderElement header = req.getHeaderByName(NS_URI_WSRM, "Sequence");
if (header == null)
return;
Iterator i = header.getChildElements(new PrefixedQName(NS_URI_WSU, "Identifier", null));
if (!i.hasNext()) {
// return fault
throw new AxisFault("WSRM.Fault", "Missing identifier in Sequence", null, null);
}
MessageElement el = (MessageElement)i.next();
String id = el.getValue();
Sequence seq = (Sequence)sequences.get(id);
if (seq == null) {
seq = new Sequence(id);
sequences.put(id, seq);
}
i = header.getChildElements(new PrefixedQName(NS_URI_WSRM, "MessageNumber", null));
el = (MessageElement)i.next();
// We've received a message with a given ID.
int seqNum = Integer.parseInt(el.getValue());
int nextSeq = seq.maxReceived + 1;
if (seqNum < nextSeq) {
Integer s = new Integer(seqNum);
if (seq.missing.contains(s)) {
seq.missing.remove(s);
}
} else {
if (seqNum > nextSeq) {
// Missing everything between maxReceived and this
for (int n = nextSeq; n < seqNum; n++) {
seq.missing.add(new Integer(n));
}
}
seq.maxReceived = seqNum;
}
header.setProcessed(true);
String from = null;
header = req.getHeaderByName(NS_URI_WSA, "From");
if (header != null) {
i = header.getChildElements(new PrefixedQName(NS_URI_WSA, "Address", null));
if (!i.hasNext()) {
throw new AxisFault("WSRM.NoAddress", "No <Address> element in <From> header", null, null);
}
el = (MessageElement)i.next();
from = el.getValue();
header.setProcessed(true);
}
msgContext.setProperty("wsrm.From", from);
// Always schedule an async ack if there's a valid From
boolean doSynchronousAcks = (URI_ANONYMOUS.equals(from));
if (seq.endpoint == null)
seq.endpoint = from;
if (!doSynchronousAcks) {
AckTask.getSingleton().scheduleAck(seq);
} else {
Message respMsg = msgContext.getResponseMessage();
if (respMsg == null) {
respMsg = new Message(new SOAPEnvelope());
msgContext.setResponseMessage(respMsg);
}
SOAPEnvelope env = respMsg.getSOAPEnvelope();
try {
generateAck(env, seq);
} catch (SOAPException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
}
header = req.getHeaderByName(NS_URI_WSA, "To");
if (header != null) {
header.setProcessed(true);
}
header = req.getHeaderByName(NS_URI_WSA, "MessageID");
if (header != null) {
header.setProcessed(true);
}
header = req.getHeaderByName(NS_URI_WSA, "Action");
if (header != null) {
header.setProcessed(true);
}
}