You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juddi.apache.org by ks...@apache.org on 2009/05/14 06:05:03 UTC

svn commit: r774627 - in /webservices/juddi/branches/v3_trunk/juddi-core/src: main/java/org/apache/juddi/api/ main/java/org/apache/juddi/subscription/ test/java/org/apache/juddi/subscription/

Author: kstam
Date: Thu May 14 04:04:54 2009
New Revision: 774627

URL: http://svn.apache.org/viewvc?rev=774627&view=rev
Log:
JUDDI-205 adding subscriptionNotification code.

Added:
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/AccessPointType.java
Modified:
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/subscription/SubscriptionNotifier.java
    webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/subscription/SubscriptionNotifierTest.java

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/AccessPointType.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/AccessPointType.java?rev=774627&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/AccessPointType.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/AccessPointType.java Thu May 14 04:04:54 2009
@@ -0,0 +1,16 @@
+package org.apache.juddi.api;
+
+public enum AccessPointType {
+	
+	END_POINT ("endPoint"),
+	BINDING_TEMPLATE("bindingTemplate"),
+	HOSTING_REDIRECTOR("hostingDirector"),
+	WSDL_DEPLOYMENT ("wsdlDeployment");
+	
+	final String type;
+
+	private AccessPointType(String type) {
+		this.type = type;
+	}
+	
+}

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/subscription/SubscriptionNotifier.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/subscription/SubscriptionNotifier.java?rev=774627&r1=774626&r2=774627&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/subscription/SubscriptionNotifier.java (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/subscription/SubscriptionNotifier.java Thu May 14 04:04:54 2009
@@ -5,7 +5,6 @@
 import java.util.Collection;
 import java.util.Date;
 import java.util.GregorianCalendar;
-import java.util.List;
 import java.util.Timer;
 import java.util.TimerTask;
 
@@ -14,20 +13,29 @@
 import javax.persistence.Query;
 import javax.xml.datatype.DatatypeFactory;
 import javax.xml.datatype.Duration;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
 
 import org.apache.commons.configuration.ConfigurationException;
+import org.apache.juddi.api.AccessPointType;
 import org.apache.juddi.api.impl.UDDISubscriptionImpl;
 import org.apache.juddi.config.AppConfig;
 import org.apache.juddi.config.Property;
 import org.apache.juddi.model.Subscription;
-import org.apache.juddi.model.SubscriptionMatch;
 import org.apache.juddi.model.UddiEntityPublisher;
 import org.apache.juddi.query.PersistenceManager;
 import org.apache.log4j.Logger;
 import org.uddi.sub_v3.CoveragePeriod;
 import org.uddi.sub_v3.GetSubscriptionResults;
 import org.uddi.sub_v3.SubscriptionResultsList;
-
+import org.uddi.subr_v3.NotifySubscriptionListener;
+import org.uddi.v3_service.DispositionReportFaultMessage;
+import org.uddi.v3_service.UDDISubscriptionListenerPortType;
+
+/*
+ * TODO lock the database per subscription, so multiple nodes can share the same
+ * database and work on notifications.
+ */
 public class SubscriptionNotifier extends TimerTask {
 
 	private Logger log = Logger.getLogger(this.getClass());
@@ -35,6 +43,8 @@
 	long interval = AppConfig.getConfiguration().getLong(Property.JUDDI_NOTIFICATION_INTERVAL, 300000l); //5 min default
 	UDDISubscriptionImpl subscriptionImpl = new UDDISubscriptionImpl();
 	private static long ACCEPTABLE_LAG_TIME = 20l; //20 milliseconds
+	private static String SUBR_V3_NAMESPACE = "urn:uddi-org:subr_v3_portType";
+	private static String SUBSCRIPTION_LISTENER = "SubscriptionListener";
 	
 	public SubscriptionNotifier() throws ConfigurationException {
 		super();
@@ -52,15 +62,8 @@
 				if (subscription.getExpiresAfter()==null || subscription.getExpiresAfter().getTime() > startTime) {
 					SubscriptionResultsList resultList = getSubscriptionResultList(subscription);
 					if (resultListContainsChanges(resultList)) {
-						log.info("We need to notify..");
-						System.out.println(resultList);
-						//Obtain the service we need to call.
-						
-						
-						//now log to the db that we notified.
-						//Date notificationDate = new Date();
-						//subscription.setLastNotified(notificationDate);
-						//em.persist(subscription);
+						log.info("We have a change and need to notify..");
+						notify(resultList);
 					}
 				}
 			}
@@ -76,7 +79,13 @@
 			log.warn("Skipping current notification cycle because the registry is busy.");
 		}
 	}
-	
+	/**
+	 * Checks to see that the event are fired on time. If they are late this may indicate that the server
+	 * is under load.
+	 * 
+	 * @param scheduleExecutionTime
+	 * @return true if the server is within the acceptable latency lag.
+	 */
 	private boolean firedOnTime(long scheduleExecutionTime) {
 		long lagTime = System.currentTimeMillis() - scheduleExecutionTime;
 		if (lagTime <= ACCEPTABLE_LAG_TIME) {
@@ -159,24 +168,45 @@
 	 * Sends out the notifications.
 	 * @param resultList
 	 * @throws MalformedURLException 
+	 * @throws DispositionReportFaultMessage 
 	 */
-	protected void notify(SubscriptionResultsList resultList) throws MalformedURLException {
+	protected void notify(SubscriptionResultsList resultList) 
+	{
 		EntityManager em = PersistenceManager.getEntityManager();
 		EntityTransaction tx = em.getTransaction();
 		tx.begin();
-		org.apache.juddi.model.Subscription modelSubscription = em.find(org.apache.juddi.model.Subscription.class, resultList.getSubscription().getSubscriptionKey());
-		org.apache.juddi.model.BindingTemplate bindingTemplate= em.find(org.apache.juddi.model.BindingTemplate.class, modelSubscription.getBindingKey());
-		if (bindingTemplate!=null) {
-			if (bindingTemplate.getAccessPointType().equalsIgnoreCase("wsdl")) {
-				URL url = new URL(bindingTemplate.getAccessPointUrl());
-				//TODO call this url.
-			} else if (bindingTemplate.getAccessPointType().equalsIgnoreCase("email")) {
-				log.warn("Notifications via email are not yet supported");
-			} else {
-				log.error("Not supported binding type.");
+		try {
+			org.apache.juddi.model.Subscription modelSubscription = em.find(org.apache.juddi.model.Subscription.class, resultList.getSubscription().getSubscriptionKey());
+			org.apache.juddi.model.BindingTemplate bindingTemplate= em.find(org.apache.juddi.model.BindingTemplate.class, modelSubscription.getBindingKey());
+			NotifySubscriptionListener body = new NotifySubscriptionListener();
+			body.setSubscriptionResultsList(resultList);
+			//body.setAuthInfo();  //where would I get the authInfo from?
+			if (bindingTemplate!=null) {
+				if (AccessPointType.END_POINT.toString().equalsIgnoreCase(bindingTemplate.getAccessPointType())) {
+					QName qName = new QName(SUBR_V3_NAMESPACE, SUBSCRIPTION_LISTENER);
+					try {
+						Service service = Service.create(new URL(bindingTemplate.getAccessPointUrl()), qName);
+						UDDISubscriptionListenerPortType subscriptionListener = (UDDISubscriptionListenerPortType) service.getPort(UDDISubscriptionListenerPortType.class);
+						subscriptionListener.notifySubscriptionListener(body);
+					
+						//now log to the db that we notified.
+						Date notificationDate = new Date();
+						modelSubscription.setLastNotified(notificationDate);
+						em.persist(modelSubscription);
+					} catch (Exception e) {
+						log.error(e.getMessage(),e);
+					}
+				} else {
+					log.error("Unsupported binding type.");
+				}
+			}
+			tx.commit();
+		} finally {
+			if (tx.isActive()) {
+				tx.rollback();
 			}
+			em.close();
 		}
-		System.out.println("hello");
 	}
 
 }

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/subscription/SubscriptionNotifierTest.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/subscription/SubscriptionNotifierTest.java?rev=774627&r1=774626&r2=774627&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/subscription/SubscriptionNotifierTest.java (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/subscription/SubscriptionNotifierTest.java Thu May 14 04:04:54 2009
@@ -73,7 +73,7 @@
 		}
 	}
 	@Test
-	public void testGetSubscriptionResults() throws ConfigurationException, MalformedURLException
+	public void testGetSubscriptionResults() throws ConfigurationException, MalformedURLException, DispositionReportFaultMessage
 	{
 		SubscriptionNotifier notifier = new SubscriptionNotifier();
 		notifier.cancel();



---------------------------------------------------------------------
To unsubscribe, e-mail: juddi-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: juddi-cvs-help@ws.apache.org