This is an automated email from the ASF dual-hosted git repository. billblough pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-savan.git
commit e3c0d98522ddffd692e0febe27d0f829d6a47246 Author: Glen Daniels <gdani...@apache.org> AuthorDate: Sat Aug 23 03:33:25 2008 +0000 * Default subscription expiration to an hour * More cleanup --- .../apache/savan/eventing/EventingConstants.java | 4 ++ .../eventing/EventingMessageReceiverDelegator.java | 71 ++++++++++------------ .../eventing/EventingSubscriptionProcessor.java | 12 +++- .../eventing/subscribers/EventingSubscriber.java | 17 ++---- .../messagereceiver/SavanInOutMessageReceiver.java | 2 - 5 files changed, 50 insertions(+), 56 deletions(-) diff --git a/modules/core/src/main/java/org/apache/savan/eventing/EventingConstants.java b/modules/core/src/main/java/org/apache/savan/eventing/EventingConstants.java index 5070296..31ba079 100644 --- a/modules/core/src/main/java/org/apache/savan/eventing/EventingConstants.java +++ b/modules/core/src/main/java/org/apache/savan/eventing/EventingConstants.java @@ -17,6 +17,8 @@ package org.apache.savan.eventing; +import javax.xml.namespace.QName; + public interface EventingConstants { String EVENTING_NAMESPACE = "http://schemas.xmlsoap.org/ws/2004/08/eventing"; @@ -26,6 +28,8 @@ public interface EventingConstants { "http://schemas.xmlsoap.org/ws/2004/08/eventing/DeliveryModes/Push"; String DEFAULT_FILTER_IDENTIFIER = FilterDialects.XPath; + QName EXPIRES_QNAME = new QName( + EventingConstants.EVENTING_NAMESPACE, EventingConstants.ElementNames.Expires); interface TransferedProperties { String SUBSCRIBER_UUID = "SAVAN_EVENTING_SUBSCRIBER_UUID"; diff --git a/modules/core/src/main/java/org/apache/savan/eventing/EventingMessageReceiverDelegator.java b/modules/core/src/main/java/org/apache/savan/eventing/EventingMessageReceiverDelegator.java index f0eb37e..64a8c61 100644 --- a/modules/core/src/main/java/org/apache/savan/eventing/EventingMessageReceiverDelegator.java +++ b/modules/core/src/main/java/org/apache/savan/eventing/EventingMessageReceiverDelegator.java @@ -40,7 +40,6 @@ import javax.xml.namespace.QName; import java.util.Calendar; import java.util.Date; - public class EventingMessageReceiverDelegator extends MessageReceiverDelegator { public void doProtocolSpecificProcessing(SavanMessageContext inSavanMessage, @@ -61,13 +60,12 @@ public class EventingMessageReceiverDelegator extends MessageReceiverDelegator { MessageContext outMessage) throws SavanException { if (outMessage == null) - throw new SavanException( - "Eventing protocol need to sent the SubscriptionResponseMessage. But the outMessage is null"); + throw new SavanException("Missing outMessage for Subscribe"); MessageContext subscriptionMsgCtx = subscriptionMessage.getMessageContext(); SOAPEnvelope outMessageEnvelope = outMessage.getEnvelope(); - SOAPFactory factory = null; + SOAPFactory factory; if (outMessageEnvelope != null) { factory = (SOAPFactory)outMessageEnvelope.getOMFactory(); @@ -94,23 +92,25 @@ public class EventingMessageReceiverDelegator extends MessageReceiverDelegator { if (id == null) throw new SavanException("Subscription UUID is not set"); - subscriptionManagerEPR.addReferenceParameter(new QName(EventingConstants.EVENTING_NAMESPACE, - EventingConstants.ElementNames.Identifier, - EventingConstants.EVENTING_PREFIX), - id); + subscriptionManagerEPR.addReferenceParameter( + new QName(EventingConstants.EVENTING_NAMESPACE, + EventingConstants.ElementNames.Identifier, + EventingConstants.EVENTING_PREFIX), + id); OMNamespace ens = factory.createOMNamespace(EventingConstants.EVENTING_NAMESPACE, EventingConstants.EVENTING_PREFIX); OMElement subscribeResponseElement = factory.createOMElement(EventingConstants.ElementNames.SubscribeResponse, ens); - OMElement subscriptionManagerElement = null; + OMElement subscriptionManagerElement; try { subscriptionManagerElement = EndpointReferenceHelper.toOM( - subscribeResponseElement.getOMFactory(), subscriptionManagerEPR, new QName( - EventingConstants.EVENTING_NAMESPACE, - EventingConstants.ElementNames.SubscriptionManager, - EventingConstants.EVENTING_PREFIX), - AddressingConstants.Submission.WSA_NAMESPACE); + subscribeResponseElement.getOMFactory(), + subscriptionManagerEPR, + new QName(EventingConstants.EVENTING_NAMESPACE, + EventingConstants.ElementNames.SubscriptionManager, + EventingConstants.EVENTING_PREFIX), + AddressingConstants.Submission.WSA_NAMESPACE); } catch (AxisFault e) { throw new SavanException(e); } @@ -121,8 +121,8 @@ public class EventingMessageReceiverDelegator extends MessageReceiverDelegator { outMessageEnvelope.getBody().addChild(subscribeResponseElement); //setting the message type - outMessage.setProperty(SavanConstants.MESSAGE_TYPE, new Integer( - SavanConstants.MessageTypes.SUBSCRIPTION_RESPONSE_MESSAGE)); + outMessage.setProperty(SavanConstants.MESSAGE_TYPE, + SavanConstants.MessageTypes.SUBSCRIPTION_RESPONSE_MESSAGE); } @@ -130,13 +130,12 @@ public class EventingMessageReceiverDelegator extends MessageReceiverDelegator { throws SavanException { if (outMessage == null) - throw new SavanException( - "Eventing protocol need to sent the SubscriptionResponseMessage. But the outMessage is null"); + throw new SavanException("Missing outMessage for Renew"); MessageContext subscriptionMsgCtx = renewMessage.getMessageContext(); SOAPEnvelope outMessageEnvelope = outMessage.getEnvelope(); - SOAPFactory factory = null; + SOAPFactory factory; if (outMessageEnvelope != null) { factory = (SOAPFactory)outMessageEnvelope.getOMFactory(); @@ -192,15 +191,14 @@ public class EventingMessageReceiverDelegator extends MessageReceiverDelegator { //setting the message type outMessage.setProperty(SavanConstants.MESSAGE_TYPE, - new Integer(SavanConstants.MessageTypes.RENEW_RESPONSE_MESSAGE)); + SavanConstants.MessageTypes.RENEW_RESPONSE_MESSAGE); } private void handleEndSubscriptionRequest(SavanMessageContext renewMessage, MessageContext outMessage) throws SavanException { if (outMessage == null) - throw new SavanException( - "Eventing protocol need to sent the SubscriptionResponseMessage. But the outMessage is null"); + throw new SavanException("Missing outMessage for EndSubscription"); MessageContext subscriptionMsgCtx = renewMessage.getMessageContext(); @@ -208,11 +206,9 @@ public class EventingMessageReceiverDelegator extends MessageReceiverDelegator { outMessage.getOptions().setAction(EventingConstants.Actions.UnsubscribeResponse); SOAPEnvelope outMessageEnvelope = outMessage.getEnvelope(); - SOAPFactory factory = null; - if (outMessageEnvelope != null) { - factory = (SOAPFactory)outMessageEnvelope.getOMFactory(); - } else { + if (outMessageEnvelope == null) { + SOAPFactory factory; factory = (SOAPFactory)subscriptionMsgCtx.getEnvelope().getOMFactory(); outMessageEnvelope = factory.getDefaultEnvelope(); @@ -224,36 +220,34 @@ public class EventingMessageReceiverDelegator extends MessageReceiverDelegator { } //setting the message type - outMessage.setProperty(SavanConstants.MESSAGE_TYPE, new Integer( - SavanConstants.MessageTypes.UNSUBSCRIPTION_RESPONSE_MESSAGE)); + outMessage.setProperty(SavanConstants.MESSAGE_TYPE, + SavanConstants.MessageTypes.UNSUBSCRIPTION_RESPONSE_MESSAGE); } public void handleGetStatusRequest(SavanMessageContext getStatusMessage, MessageContext outMessage) throws SavanException { if (outMessage == null) - throw new SavanException( - "Eventing protocol need to sent the SubscriptionResponseMessage. But the outMessage is null"); + throw new SavanException("Missing outMessage for getStatus!"); - MessageContext subscriptionMsgCtx = getStatusMessage.getMessageContext(); + MessageContext getStatusContext = getStatusMessage.getMessageContext(); String id = (String)getStatusMessage .getProperty(EventingConstants.TransferedProperties.SUBSCRIBER_UUID); if (id == null) - throw new SavanException("Cannot fulfil request. AbstractSubscriber ID not found"); + throw new SavanException("Subscriber ID not found"); //setting the action - outMessage.getOptions().setAction(EventingConstants.Actions.UnsubscribeResponse); + outMessage.getOptions().setAction(EventingConstants.Actions.GetStatusResponse); SOAPEnvelope outMessageEnvelope = outMessage.getEnvelope(); - SOAPFactory factory = null; + SOAPFactory factory; if (outMessageEnvelope != null) { factory = (SOAPFactory)outMessageEnvelope.getOMFactory(); } else { - factory = (SOAPFactory)subscriptionMsgCtx.getEnvelope().getOMFactory(); + factory = (SOAPFactory)getStatusContext.getEnvelope().getOMFactory(); outMessageEnvelope = factory.getDefaultEnvelope(); - try { outMessage.setEnvelope(outMessageEnvelope); } catch (AxisFault e) { @@ -264,7 +258,6 @@ public class EventingMessageReceiverDelegator extends MessageReceiverDelegator { SubscriberStore store = CommonUtil .getSubscriberStore(getStatusMessage.getMessageContext().getAxisService()); - if (store == null) { throw new SavanException("AbstractSubscriber Store was not found"); } @@ -293,8 +286,8 @@ public class EventingMessageReceiverDelegator extends MessageReceiverDelegator { outMessageEnvelope.getBody().addChild(getStatusResponseElement); //setting the message type - outMessage.setProperty(SavanConstants.MESSAGE_TYPE, new Integer( - SavanConstants.MessageTypes.GET_STATUS_RESPONSE_MESSAGE)); + outMessage.setProperty(SavanConstants.MESSAGE_TYPE, + SavanConstants.MessageTypes.GET_STATUS_RESPONSE_MESSAGE); } public void doProtocolSpecificProcessing(SavanMessageContext inSavanMessage) diff --git a/modules/core/src/main/java/org/apache/savan/eventing/EventingSubscriptionProcessor.java b/modules/core/src/main/java/org/apache/savan/eventing/EventingSubscriptionProcessor.java index 86fcc64..be9da1a 100644 --- a/modules/core/src/main/java/org/apache/savan/eventing/EventingSubscriptionProcessor.java +++ b/modules/core/src/main/java/org/apache/savan/eventing/EventingSubscriptionProcessor.java @@ -159,8 +159,8 @@ public class EventingSubscriptionProcessor extends SubscriptionProcessor { eventingSubscriber.setDelivery(delivery); - OMElement expiresElement = subscribeElement.getFirstChildWithName(new QName( - EventingConstants.EVENTING_NAMESPACE, EventingConstants.ElementNames.Expires)); + OMElement expiresElement = + subscribeElement.getFirstChildWithName(EventingConstants.EXPIRES_QNAME); if (expiresElement != null) { String expiresText = expiresElement.getText(); @@ -180,13 +180,19 @@ public class EventingSubscriptionProcessor extends SubscriptionProcessor { } else expiration = expirationBean.getDateValue(); - if (expiration == null) { String message = "Cannot understand the given date-time value for the Expiration"; throw new SavanException(message); } eventingSubscriber.setSubscriptionEndingTime(expiration); + } else { + // They didn't specify an expiration, so default to an hour. + Calendar calendar = Calendar.getInstance(); + Duration duration = new Duration(); + duration.setHours(1); + CommonUtil.addDurationToCalendar(calendar, duration); + eventingSubscriber.setSubscriptionEndingTime(calendar.getTime()); } OMElement filterElement = subscribeElement.getFirstChildWithName(new QName( diff --git a/modules/core/src/main/java/org/apache/savan/eventing/subscribers/EventingSubscriber.java b/modules/core/src/main/java/org/apache/savan/eventing/subscribers/EventingSubscriber.java index c19a1ea..bc0c158 100644 --- a/modules/core/src/main/java/org/apache/savan/eventing/subscribers/EventingSubscriber.java +++ b/modules/core/src/main/java/org/apache/savan/eventing/subscribers/EventingSubscriber.java @@ -36,8 +36,6 @@ import java.util.Date; /** Defines methods common to all eventing subscribers. */ public class EventingSubscriber implements Subscriber { - - private URI id; private Filter filter = null; private EndpointReference endToEPr; @@ -47,7 +45,6 @@ public class EventingSubscriber implements Subscriber { /** The time at which further notification of messages should be avaoded to this subscriber. */ private Date subscriptionEndingTime = null; - public Filter getFilter() { return filter; } @@ -100,12 +97,11 @@ public class EventingSubscriber implements Subscriber { } /** - * This method first checks weather the passed message complies with the current filter. If so - * message is sent, and the subscriberID is added to the PublicationReport. Else message is - * ignored. + * This method first checks whether the passed message complies with the current filter. + * If so the message is sent, and the subscriberID is added to the PublicationReport. + * Otherwise the message is ignored. * - * @param smc - * @param report + * @param eventData an OMElement containing the SOAP Envelope * @throws SavanException */ public void sendEventData(OMElement eventData) throws SavanException { @@ -126,10 +122,7 @@ public class EventingSubscriber implements Subscriber { } private boolean doesEventDataBelongToTheFilter(OMElement eventData) throws SavanException { - if (filter != null) { - return filter.checkCompliance(eventData); - } else - return true; + return filter == null || filter.checkCompliance(eventData); } private void sendThePublication(OMElement eventData) throws SavanException { diff --git a/modules/core/src/main/java/org/apache/savan/messagereceiver/SavanInOutMessageReceiver.java b/modules/core/src/main/java/org/apache/savan/messagereceiver/SavanInOutMessageReceiver.java index 7a51589..173026f 100644 --- a/modules/core/src/main/java/org/apache/savan/messagereceiver/SavanInOutMessageReceiver.java +++ b/modules/core/src/main/java/org/apache/savan/messagereceiver/SavanInOutMessageReceiver.java @@ -49,7 +49,5 @@ public class SavanInOutMessageReceiver extends AbstractInOutSyncMessageReceiver delegator.processMessage(savanInMessage); delegator.doProtocolSpecificProcessing(savanInMessage, outMessage); - } - }