Author: alexoree
Date: Mon Nov  4 03:31:18 2013
New Revision: 1538499

URL: http://svn.apache.org/r1538499
Log:
JUDDI-672 done

Added:
    juddi/trunk/juddi-examples/subscription-notification-amqp/
    juddi/trunk/juddi-examples/subscription-notification-amqp/pom.xml
    juddi/trunk/juddi-examples/subscription-notification-amqp/src/
    juddi/trunk/juddi-examples/subscription-notification-amqp/src/main/
    juddi/trunk/juddi-examples/subscription-notification-amqp/src/main/java/
    juddi/trunk/juddi-examples/subscription-notification-amqp/src/main/java/org/
    
juddi/trunk/juddi-examples/subscription-notification-amqp/src/main/java/org/apache/
    
juddi/trunk/juddi-examples/subscription-notification-amqp/src/main/java/org/apache/juddi/
    
juddi/trunk/juddi-examples/subscription-notification-amqp/src/main/java/org/apache/juddi/subscription/
    
juddi/trunk/juddi-examples/subscription-notification-amqp/src/main/java/org/apache/juddi/subscription/notify/
    
juddi/trunk/juddi-examples/subscription-notification-amqp/src/main/java/org/apache/juddi/subscription/notify/AMQPNotifier.java
    juddi/trunk/juddi-examples/subscription-notification-amqp/src/test/
    juddi/trunk/juddi-examples/subscription-notification-amqp/src/test/java/
Removed:
    juddi/trunk/juddi-examples/subscription-notification-handler/
Modified:
    juddi/trunk/juddi-examples/pom.xml

Modified: juddi/trunk/juddi-examples/pom.xml
URL: 
http://svn.apache.org/viewvc/juddi/trunk/juddi-examples/pom.xml?rev=1538499&r1=1538498&r2=1538499&view=diff
==============================================================================
--- juddi/trunk/juddi-examples/pom.xml (original)
+++ juddi/trunk/juddi-examples/pom.xml Mon Nov  4 03:31:18 2013
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-       <!--
+<!--
                * Copyright 2001-2009 The Apache Software Foundation. * * 
Licensed
                under the Apache License, Version 2.0 (the "License"); * you 
may not
                use this file except in compliance with the License. * You may 
obtain
@@ -10,8 +10,7 @@
                OR CONDITIONS OF ANY KIND, either express or implied. * See the
                License for the specific language governing permissions and *
                limitations under the License. * */
-       -->
-<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+       --><project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
        <modelVersion>4.0.0</modelVersion>
        <parent>
                <groupId>org.apache.juddi</groupId>
@@ -35,5 +34,6 @@
        <module>uddi-annotations</module>
        <module>wsdl2uddi</module>
        <module>wsdl2uddi-lifecyle</module>
-    </modules>
-</project>
+    <module>subscription-notification-amqp</module>
+  </modules>
+</project>
\ No newline at end of file

Added: juddi/trunk/juddi-examples/subscription-notification-amqp/pom.xml
URL: 
http://svn.apache.org/viewvc/juddi/trunk/juddi-examples/subscription-notification-amqp/pom.xml?rev=1538499&view=auto
==============================================================================
--- juddi/trunk/juddi-examples/subscription-notification-amqp/pom.xml (added)
+++ juddi/trunk/juddi-examples/subscription-notification-amqp/pom.xml Mon Nov  
4 03:31:18 2013
@@ -0,0 +1,47 @@
+<?xml version="1.0"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd"; 
xmlns="http://maven.apache.org/POM/4.0.0";
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.juddi.example</groupId>
+    <artifactId>juddi-examples</artifactId>
+    <version>3.2.0-SNAPSHOT</version>
+  </parent>
+  
+  <artifactId>subscription-notification-amqp</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <name>jUDDI subscription-notification-amqp</name>
+  <description>Demonstrates how to write a custom notifier for 
subscriptions</description>
+  <dependencies>
+               <dependency>
+                       <groupId>org.apache.juddi</groupId>
+                       <artifactId>uddi-ws</artifactId>
+                       <version>3.2.0-SNAPSHOT</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.juddi</groupId>
+                       <artifactId>juddi-client</artifactId>
+                       <version>3.2.0-SNAPSHOT</version>
+               </dependency>
+               <dependency>
+                 <groupId>org.apache.geronimo.specs</groupId>
+                 <artifactId>geronimo-jms_1.1_spec</artifactId>
+                 <version>1.0</version>
+               </dependency>
+               <dependency>
+                 <groupId>org.apache.qpid</groupId>
+                 <artifactId>qpid-client</artifactId>
+                 <version>0.24</version>
+               </dependency>
+               <dependency>
+                 <groupId>org.apache.qpid</groupId>
+                 <artifactId>qpid-amqp-1-0-client-jms</artifactId>
+                 <version>0.24</version>
+               </dependency>
+    <dependency>
+      <groupId>org.apache.juddi</groupId>
+      <artifactId>juddi-core</artifactId>
+      <version>3.2.0-SNAPSHOT</version>
+    </dependency>
+  </dependencies>
+</project>

Added: 
juddi/trunk/juddi-examples/subscription-notification-amqp/src/main/java/org/apache/juddi/subscription/notify/AMQPNotifier.java
URL: 
http://svn.apache.org/viewvc/juddi/trunk/juddi-examples/subscription-notification-amqp/src/main/java/org/apache/juddi/subscription/notify/AMQPNotifier.java?rev=1538499&view=auto
==============================================================================
--- 
juddi/trunk/juddi-examples/subscription-notification-amqp/src/main/java/org/apache/juddi/subscription/notify/AMQPNotifier.java
 (added)
+++ 
juddi/trunk/juddi-examples/subscription-notification-amqp/src/main/java/org/apache/juddi/subscription/notify/AMQPNotifier.java
 Mon Nov  4 03:31:18 2013
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.juddi.subscription.notify;
+
+import java.net.URISyntaxException;
+import java.rmi.RemoteException;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.juddi.api_v3.AccessPointType;
+import org.apache.juddi.config.AppConfig;
+import org.apache.juddi.jaxb.JAXBMarshaller;
+import org.apache.juddi.model.BindingTemplate;
+import org.uddi.api_v3.DispositionReport;
+import org.uddi.api_v3.Result;
+import org.uddi.subr_v3.NotifySubscriptionListener;
+import org.uddi.v3_service.DispositionReportFaultMessage;
+
+/**
+ * AMQP Notifier
+ * 
+ * This is designed to enable users to setup AMQP based alerts for UDDI 
subscriptions
+ * 
+ * This class is partically complete, but it is largely untested and lacks any 
kind of 
+ * 
+ * the following settings need to be added to the juddiv3.xml file
+ * 
amqp.java.naming.factory.initial=org.apache.qpid.jndi.PropertiesFileInitialContextFactory
+ * amqp.connectionfactory.qpidConnectionfactory
+ * amqp.destination=(some topic or queue name)
+ * amqp.destination.type=topic
+ * 
+ * usage
+ * create a service/bindingtemplate/accessPoint where the value is 
amqp://url_to_qpid/amqp The useType must be "endPoint".
+ * create a subscription where the binding template reference points to this 
endpoint.
+ * trigger the subscription and wait for delivery.
+ * @author <a href="mailto:[email protected]";>Alex O'Ree</a>
+ */
+public class AMQPNotifier implements Notifier {
+
+    Log log = LogFactory.getLog(this.getClass());
+    String destination = null;
+
+    public AMQPNotifier(BindingTemplate bindingTemplate) throws 
URISyntaxException, ConfigurationException {
+        super();
+        if 
(!AccessPointType.END_POINT.toString().equalsIgnoreCase(bindingTemplate.getAccessPointType()))
 {
+            log.error("AMQP enpoints only support AccessPointType " + 
AccessPointType.END_POINT);
+        }
+        String accessPointUrl = 
bindingTemplate.getAccessPointUrl().toLowerCase();
+        if (!accessPointUrl.startsWith("amqp:")) {
+            log.warn("AMQP accessPointUrl for bindingTemplate " + 
bindingTemplate.getEntityKey()
+                    + " should start with 'amqp:'");
+        } else {
+            destination = accessPointUrl.substring(accessPointUrl.indexOf(":") 
+ 1);
+
+        }
+    }
+
+    @Override
+    public DispositionReport 
notifySubscriptionListener(NotifySubscriptionListener body) throws 
DispositionReportFaultMessage, RemoteException {
+        Connection connection = null;
+        Context context = null;
+        boolean success = false;
+        String err = null;
+        try {
+            if (destination != null) {
+                log.info("Sending notification AMQP to " + destination);
+                Properties properties = new Properties();
+                 
+                properties.put("java.naming.factory.initial", 
+                        
AppConfig.getConfiguration().getString("amqp.java.naming.factory.initial", 
"org.apache.qpid.jndi.PropertiesFileInitialContextFactory"));
+                properties.put("connectionfactory.qpidConnectionfactory", 
destination);
+                properties.put("destination." 
+AppConfig.getConfiguration().getString("amqp.destination") ,
+                        
AppConfig.getConfiguration().getString("amqp.destination.type"));
+                //test only
+                
//properties.load(this.getClass().getResourceAsStream("hello.properties"));
+                context = new InitialContext(properties);
+
+                ConnectionFactory connectionFactory = (ConnectionFactory) 
context.lookup("qpidConnectionfactory");
+                connection = connectionFactory.createConnection();
+                connection.start();
+
+                Session session = connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
+                Destination destinationLocal = (Destination) 
context.lookup("UDDISubscriptionUpdates");
+
+                MessageProducer messageProducer = 
session.createProducer(destinationLocal);
+
+
+                String subscriptionResultXML = 
JAXBMarshaller.marshallToString(body, JAXBMarshaller.PACKAGE_SUBSCR_RES);
+                TextMessage message = 
session.createTextMessage(subscriptionResultXML);
+                messageProducer.send(message);
+                success = true;
+
+            }
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            err = e.getMessage();
+
+        } finally {
+            try {
+                connection.close();
+            } catch (JMSException ex) {
+                log.error(null, ex);
+            }
+            try {
+                context.close();
+            } catch (NamingException ex) {
+                log.error(null, ex);
+            }
+        }
+        if (!success) {
+            throw new DispositionReportFaultMessage(err, null);
+        }
+        DispositionReport dr = new DispositionReport();
+        Result res = new Result();
+        dr.getResult().add(res);
+
+        return dr;
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to