Permalink
Browse files

Add subscription monitoring and retrieval

  • Loading branch information...
1 parent 4dd1feb commit aab812988b890187bc3fa8342890f24a077172c1 @chamerling chamerling committed Nov 15, 2012
@@ -16,6 +16,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <petals.wsstar.version>1.1-SNAPSHOT</petals.wsstar.version>
</properties>
<dependencies>
@@ -29,7 +30,7 @@
<dependency>
<artifactId>wsn-b-services-impl</artifactId>
<groupId>org.ow2.petals.wsstar.oasis-ws-basenotification</groupId>
- <version>1.0.2</version>
+ <version>${petals.wsstar.version}</version>
<!-- Do not want to use bindled CXF version which is not useful here... -->
<exclusions>
<exclusion>
@@ -62,4 +62,5 @@
*/
@WebMethod
void setTopics(List<Topic> topics);
+
}
@@ -19,6 +19,7 @@
*/
package org.petalslink.dsb.jbi.se.wsn.api;
+import javax.jws.WebMethod;
import javax.jws.WebService;
import org.w3c.dom.Document;
@@ -88,5 +89,47 @@ void newOutNotify(String uuid, Document payload, String to, Topic topic, long ti
*/
void newOutNotifyError(String uuid, Document payload, String to, Topic topic, long timestamp,
Exception error) throws WSNException;
+
+ /**
+ * Got a new subscribe request
+ *
+ * @param uuid
+ * @param subscriber
+ * @param topic
+ * @throws WSNException
+ */
+ @WebMethod
+ void newSubscribeRequest(String uuid, String subscriber, Topic topic) throws WSNException;
+
+ /**
+ *
+ * @param uuid
+ * @param subscriber
+ * @param topic
+ * @throws WSNException
+ */
+ @WebMethod
+ void newSubscribeResponse(String uuid, String subscriptionID) throws WSNException;
+
+ /**
+ *
+ * @param uuid
+ * @param subscriber
+ * @param topic
+ * @throws WSNException
+ */
+ @WebMethod
+ void newUnsubscribeRequest(String uuid, String subscriptionID) throws WSNException;
+
+ /**
+ *
+ * @param uuid
+ * @param topic
+ * @throws WSNException
+ */
+ @WebMethod
+ void newUnsubscribeResponse(String uuid) throws WSNException;
+
+
}
@@ -0,0 +1,42 @@
+/**
+ *
+ * Copyright (c) 2012, PetalsLink
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+package org.petalslink.dsb.jbi.se.wsn.api;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * @author chamerling
+ *
+ */
+@XmlRootElement
+public class Subscription {
+
+ public String uuid;
+
+ public String subscriber;
+
+ public Topic topic;
+
+ /**
+ *
+ */
+ public Subscription() {
+ }
+}
@@ -0,0 +1,54 @@
+/**
+ *
+ * Copyright (c) 2012, PetalsLink
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+package org.petalslink.dsb.jbi.se.wsn.api;
+
+import java.util.List;
+
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+
+/**
+ * @author chamerling
+ *
+ */
+@WebService
+public interface SubscriptionManagementService {
+
+ /**
+ * Get all the subscriptions for the given topic
+ *
+ * @param topic
+ * @return
+ * @throws WSNException
+ */
+ @WebMethod
+ List<Subscription> getSubscriptionsForTopic(Topic topic) throws WSNException;
+
+ /**
+ * Get all the subscriptions
+ *
+ * @return
+ * @throws WSNException
+ */
+ @WebMethod
+ List<Subscription> getSubscriptions() throws WSNException;
+
+}
+
@@ -19,6 +19,8 @@
*/
package org.petalslink.dsb.jbi.se.wsn.api;
+import java.util.List;
+
import javax.jws.WebMethod;
import javax.jws.WebService;
@@ -51,4 +53,5 @@
*/
@WebMethod
boolean unsubscribe(String uuid) throws WSNException;
+
}
@@ -44,10 +44,12 @@
import org.petalslink.dsb.jbi.se.wsn.api.MonitoringService;
import org.petalslink.dsb.jbi.se.wsn.api.NotificationService;
import org.petalslink.dsb.jbi.se.wsn.api.StatsService;
+import org.petalslink.dsb.jbi.se.wsn.api.SubscriptionManagementService;
import org.petalslink.dsb.jbi.se.wsn.api.SubscriptionService;
import org.petalslink.dsb.jbi.se.wsn.services.ManagementServiceImpl;
import org.petalslink.dsb.jbi.se.wsn.services.NotificationServiceImpl;
import org.petalslink.dsb.jbi.se.wsn.services.StatsServiceImpl;
+import org.petalslink.dsb.jbi.se.wsn.services.SubscriptionManagementServiceImpl;
import org.petalslink.dsb.jbi.se.wsn.services.SubscriptionServiceImpl;
import org.petalslink.dsb.notification.commons.PropertiesConfigurationProducer;
import org.petalslink.dsb.notification.commons.api.ConfigurationProducer;
@@ -101,6 +103,8 @@
protected NotificationService notificationService;
protected MonitoringService monitoringService;
+
+ protected SubscriptionManagementService subscriptionManagementService;
/*
* (non-Javadoc)
@@ -134,6 +138,11 @@ protected void addServices() {
this.notificationService = new NotificationServiceImpl(this.engine, getLogger());
ws.add(getService(NotificationService.class, this.notificationService, "NotificationService"));
+
+ this.subscriptionManagementService = new SubscriptionManagementServiceImpl(this.engine, getLogger());
+ ws.add(getService(SubscriptionManagementService.class,
+ this.subscriptionManagementService,
+ "SubscriptionManagementService"));
doAddServices();
}
@@ -446,7 +455,7 @@ protected synchronized Client getClient() {
*
* @return
*/
- protected synchronized MonitoringService getMonitoringService() {
+ public synchronized MonitoringService getMonitoringService() {
return null;
}
}
@@ -5,6 +5,7 @@
import java.net.URI;
import java.util.List;
+import java.util.UUID;
import java.util.logging.Level;
import javax.jbi.messaging.MessagingException;
@@ -20,6 +21,10 @@
import org.petalslink.dsb.jbi.se.wsn.Component;
import org.petalslink.dsb.jbi.se.wsn.Constants;
import org.petalslink.dsb.jbi.se.wsn.NotificationEngine;
+import org.petalslink.dsb.jbi.se.wsn.api.MonitoringService;
+import org.petalslink.dsb.jbi.se.wsn.api.WSNException;
+import org.petalslink.dsb.notification.commons.NotificationException;
+import org.petalslink.dsb.notification.commons.NotificationHelper;
import org.w3c.dom.Document;
import com.ebmwebsourcing.wsaddressing10.api.element.Address;
@@ -63,11 +68,14 @@ public boolean onJBIMessage(Exchange exchange) {
}
NotificationEngine engine = getNotificationEngine();
+ // can be null...
+ MonitoringService monitoring = getWSNComponent().getMonitoringService();
boolean response = true;
NormalizedMessage normalizedMessage = null;
Document document = null;
Address address = null;
+ String uuid = UUID.randomUUID().toString();
try {
if (this.getLogger().isLoggable(Level.FINE)) {
@@ -182,6 +190,14 @@ public boolean onJBIMessage(Exchange exchange) {
} catch (TransformerException e) {
}
}
+
+ if (monitoring != null) {
+ try {
+ monitoring.newSubscribeRequest(uuid, consumerAddress.getValue().toString(), null);
+ } catch (WSNException e) {
+ getLogger().warning("Can not send subscribe monitoring " + e.getMessage());
+ }
+ }
// call the producer
final com.ebmwebsourcing.wsstar.basenotification.datatypes.api.abstraction.SubscribeResponse subscribeResponse = engine
@@ -190,6 +206,22 @@ public boolean onJBIMessage(Exchange exchange) {
// set the response
document = RefinedWsnbFactory.getInstance().getWsnbWriter()
.writeSubscribeResponseAsDOM(subscribeResponse);
+
+ if (monitoring != null) {
+ try {
+ String responseId = "";
+ try {
+ responseId = NotificationHelper.getSubscriptionID(subscribeResponse);
+ } catch (NotificationException e) {
+ getLogger().warning(e.getMessage());
+ responseId = "?";
+ }
+ monitoring.newSubscribeResponse(uuid, responseId);
+ } catch (WSNException e) {
+ getLogger().warning("Can not send subscribe monitoring " + e.getMessage());
+ }
+ }
+
normalizedMessage = exchange.getOutMessage();
normalizedMessage.setContent(SourceUtil
.createStreamSource(document));
@@ -216,17 +248,38 @@ public boolean onJBIMessage(Exchange exchange) {
} else if (WsnbConstants.UNSUBSCRIBE_NAME.equals(exchange.getOperation()
.getLocalPart())) {
- getLogger().log(Level.INFO, "Got an unsubscribe message");
+ getLogger().log(Level.FINE, "Got an unsubscribe message");
document = SourceUtil.createDocument(
normalizedMessage.getContent());
com.ebmwebsourcing.wsstar.basenotification.datatypes.api.abstraction.Unsubscribe unsubscribe = RefinedWsnbFactory
.getInstance().getWsnbReader().readUnsubscribe(document);
+ if (monitoring != null) {
+ try {
+ monitoring.newUnsubscribeRequest(uuid, "TODO");
+ } catch (WSNException e) {
+ getLogger().warning(
+ "Can not send unsubscribe request monitoring "
+ + e.getMessage());
+ }
+ }
+
final com.ebmwebsourcing.wsstar.basenotification.datatypes.api.abstraction.UnsubscribeResponse unsubscribeResponse = engine
.getNotificationManager().getSubscriptionManagerEngine()
.unsubscribe(unsubscribe);
+
+ if (monitoring != null) {
+ try {
+ monitoring.newUnsubscribeResponse(uuid);
+ } catch (WSNException e) {
+ getLogger().warning(
+ "Can not send unsubscribe response monitoring "
+ + e.getMessage());
+ }
+ }
+
document = RefinedWsnbFactory.getInstance().getWsnbWriter()
.writeUnsubscribeResponseAsDOM(unsubscribeResponse);
normalizedMessage = exchange.getOutMessage();
@@ -317,4 +370,8 @@ private void addLocation(Address address, String component, String container, St
NotificationEngine getNotificationEngine() {
return ((Component) getComponent()).getNotificationEngine();
}
+
+ Component getWSNComponent() {
+ return ((Component) getComponent());
+ }
}
Oops, something went wrong.

0 comments on commit aab8129

Please sign in to comment.