Skip to content
Permalink
Browse files
* Default subscription expiration to an hour
* More cleanup
  • Loading branch information
Glen Daniels committed Aug 23, 2008
1 parent 5454d53 commit e3c0d98522ddffd692e0febe27d0f829d6a47246
Showing 5 changed files with 50 additions and 56 deletions.
@@ -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";
@@ -40,7 +40,6 @@
import java.util.Calendar;
import java.util.Date;


public class EventingMessageReceiverDelegator extends MessageReceiverDelegator {

public void doProtocolSpecificProcessing(SavanMessageContext inSavanMessage,
@@ -61,13 +60,12 @@ private void handleSubscriptionRequest(SavanMessageContext subscriptionMessage,
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 @@ private void handleSubscriptionRequest(SavanMessageContext subscriptionMessage,
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,22 +121,21 @@ private void handleSubscriptionRequest(SavanMessageContext subscriptionMessage,
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);

}

private void handleRenewRequest(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 Renew");

MessageContext subscriptionMsgCtx = renewMessage.getMessageContext();

SOAPEnvelope outMessageEnvelope = outMessage.getEnvelope();
SOAPFactory factory = null;
SOAPFactory factory;

if (outMessageEnvelope != null) {
factory = (SOAPFactory)outMessageEnvelope.getOMFactory();
@@ -192,27 +191,24 @@ private void handleRenewRequest(SavanMessageContext renewMessage, MessageContext

//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();

//setting the action
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 @@ private void handleEndSubscriptionRequest(SavanMessageContext renewMessage,
}

//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 void handleGetStatusRequest(SavanMessageContext getStatusMessage,
SubscriberStore store = CommonUtil
.getSubscriberStore(getStatusMessage.getMessageContext().getAxisService());


if (store == null) {
throw new SavanException("AbstractSubscriber Store was not found");
}
@@ -293,8 +286,8 @@ public void handleGetStatusRequest(SavanMessageContext getStatusMessage,
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)
@@ -159,8 +159,8 @@ public Subscriber getSubscriberFromMessage(SavanMessageContext smc) throws Savan

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 Subscriber getSubscriberFromMessage(SavanMessageContext smc) throws Savan
} 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(
@@ -36,8 +36,6 @@

/** 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 void setSubscriptionEndingTime(Date subscriptionEndingTime) {
}

/**
* 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 void sendEventData(OMElement eventData) throws SavanException {
}

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 {
@@ -49,7 +49,5 @@ public void invokeBusinessLogic(MessageContext inMessage, MessageContext outMess

delegator.processMessage(savanInMessage);
delegator.doProtocolSpecificProcessing(savanInMessage, outMessage);

}

}

0 comments on commit e3c0d98

Please sign in to comment.