incubator-nuvem-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r1146503 - in /incubator/nuvem/trunk: nuvem-google/ nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/ nuvem-samples/store-appengine-webapp/war/ nuvem-samples/store-appengine-webapp/war/WEB-INF/ nuvem-samples/store-assets/src/main...
Date Wed, 13 Jul 2011 22:24:05 GMT
Author: johnp
Date: Wed Jul 13 22:24:05 2011
New Revision: 1146503

URL: http://svn.apache.org/viewvc?rev=1146503&view=rev
Log:
--corrected the google presence reciever servlet to broadcast presence changes to listeners
--modified the store application to demonstrate how to listen to presence changes and respond
to such changes

Modified:
    incubator/nuvem/trunk/nuvem-google/pom.xml
    incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GooglePresenceServlet.java
    incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleRecieverServlet.java
    incubator/nuvem/trunk/nuvem-samples/store-appengine-webapp/war/WEB-INF/appengine-web.xml
    incubator/nuvem/trunk/nuvem-samples/store-appengine-webapp/war/WEB-INF/web.xml
    incubator/nuvem/trunk/nuvem-samples/store-appengine-webapp/war/store.composite
    incubator/nuvem/trunk/nuvem-samples/store-assets/src/main/java/services/XMPPShipmentObserver.java

Modified: incubator/nuvem/trunk/nuvem-google/pom.xml
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-google/pom.xml?rev=1146503&r1=1146502&r2=1146503&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-google/pom.xml (original)
+++ incubator/nuvem/trunk/nuvem-google/pom.xml Wed Jul 13 22:24:05 2011
@@ -50,7 +50,6 @@
 			<groupId>com.google.appengine</groupId>
 			<artifactId>appengine-api-1.0-sdk</artifactId>
 			<version>${gae.version}</version>
-			<scope>provided</scope>
 		</dependency>
 		
 		<dependency>

Modified: incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GooglePresenceServlet.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GooglePresenceServlet.java?rev=1146503&r1=1146502&r2=1146503&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GooglePresenceServlet.java
(original)
+++ incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GooglePresenceServlet.java
Wed Jul 13 22:24:05 2011
@@ -22,6 +22,8 @@ package org.apache.nuvem.cloud.xmpp.impl
 import java.io.IOException;
 import java.util.logging.Logger;
 
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -29,6 +31,7 @@ import javax.servlet.http.HttpServletRes
 import org.apache.nuvem.cloud.xmpp.XMPPEndPoint;
 import org.apache.nuvem.cloud.xmpp.presence.PresenceListener;
 import org.apache.nuvem.cloud.xmpp.presence.PresenceManager;
+import org.oasisopen.sca.ComponentContext;
 import org.oasisopen.sca.annotation.Reference;
 
 import com.google.appengine.api.xmpp.Presence;
@@ -61,10 +64,28 @@ public class GooglePresenceServlet exten
 	 */
 	private static final long serialVersionUID = 3109512262386132981L;
 
-	@Reference
+	@Reference(required = false)
 	private XMPPEndPoint endPoint;
 
 	/**
+	 * If the servlet container doesnt support SCA then the endpoint will be
+	 * identified explicitly.
+	 */
+	@Override
+	public void init(ServletConfig config) {
+		if (endPoint == null) {
+			log.info("endpoint not wired, trying to fetch one from the component context");
+			ServletContext servletContext = config.getServletContext();
+			ComponentContext context = (ComponentContext) servletContext
+					.getAttribute("org.oasisopen.sca.ComponentContext");
+			
+			endPoint = context.getService(XMPPEndPoint.class, "endPoint");
+			log.info("endpoint: " + endPoint);
+		}
+	}
+
+	
+	/**
 	 * Adapts the HTTP Post request into a call to the
 	 * {@link PresenceListener#listen(org.apache.nuvem.cloud.xmpp.presence.Presence)}
 	 * .

Modified: incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleRecieverServlet.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleRecieverServlet.java?rev=1146503&r1=1146502&r2=1146503&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleRecieverServlet.java
(original)
+++ incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleRecieverServlet.java
Wed Jul 13 22:24:05 2011
@@ -75,7 +75,7 @@ public class GoogleRecieverServlet exten
 	@Override
 	public void init(ServletConfig config) {
 		if (endPoint == null) {
-			log.info("endpoint not wired, trying to fetch one from the component context using the
name: XMPPComponent/XMPPEndPoint");
+			log.info("endpoint not wired, trying to fetch one from the component context");
 			ServletContext servletContext = config.getServletContext();
 			ComponentContext context = (ComponentContext) servletContext
 					.getAttribute("org.oasisopen.sca.ComponentContext");

Modified: incubator/nuvem/trunk/nuvem-samples/store-appengine-webapp/war/WEB-INF/appengine-web.xml
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-samples/store-appengine-webapp/war/WEB-INF/appengine-web.xml?rev=1146503&r1=1146502&r2=1146503&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-samples/store-appengine-webapp/war/WEB-INF/appengine-web.xml
(original)
+++ incubator/nuvem/trunk/nuvem-samples/store-appengine-webapp/war/WEB-INF/appengine-web.xml
Wed Jul 13 22:24:05 2011
@@ -28,6 +28,7 @@
 
 	<inbound-services>
     	<service>xmpp_message</service>
+    	<service>xmpp_presence</service>
   	</inbound-services>
   	
 </appengine-web-app>
\ No newline at end of file

Modified: incubator/nuvem/trunk/nuvem-samples/store-appengine-webapp/war/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-samples/store-appengine-webapp/war/WEB-INF/web.xml?rev=1146503&r1=1146502&r2=1146503&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-samples/store-appengine-webapp/war/WEB-INF/web.xml (original)
+++ incubator/nuvem/trunk/nuvem-samples/store-appengine-webapp/war/WEB-INF/web.xml Wed Jul
13 22:24:05 2011
@@ -42,6 +42,16 @@ http://java.sun.com/xml/ns/javaee/web-ap
 		<url-pattern>/_ah/xmpp/message/chat/</url-pattern>
 	</servlet-mapping>
 
+    <servlet>
+        <servlet-name>presencereciever</servlet-name>
+        <servlet-class>org.apache.nuvem.cloud.xmpp.impl.GooglePresenceServlet</servlet-class>
+    </servlet>
+    <servlet-mapping>
+        <servlet-name>presencereciever</servlet-name>
+        <url-pattern>/_ah/xmpp/presence/*</url-pattern>
+        <url-pattern>/_ah/xmpp/subscription/*</url-pattern>
+    </servlet-mapping>
+    
 	<!-- Default page to serve -->
 	<welcome-file-list>
 		<welcome-file>store.html</welcome-file>

Modified: incubator/nuvem/trunk/nuvem-samples/store-appengine-webapp/war/store.composite
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-samples/store-appengine-webapp/war/store.composite?rev=1146503&r1=1146502&r2=1146503&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-samples/store-appengine-webapp/war/store.composite (original)
+++ incubator/nuvem/trunk/nuvem-samples/store-appengine-webapp/war/store.composite Wed Jul
13 22:24:05 2011
@@ -75,15 +75,16 @@
     <component name="XMPP">
         <implementation.composite name="nuvem:xmppgoogle" /> 
     </component>
+
     
 	<component name="ShipmentService">
 		<implementation.java class="services.ShipmentServiceImpl" />
 		<reference name="observer" target="ShipmentObserver" />
 	</component>
-
+    
     <component name="XMPPReciever">
         <implementation.web web-uri="/_ah/xmpp/message/chat/"/>
-        <reference name="endPoint" target="XMPPComponent/XMPPEndPoint">
+        <reference name="endPoint" target="XMPP/XMPPEndPoint">
             <interface.java interface="org.apache.nuvem.cloud.xmpp.XMPPEndPoint" />
         </reference>
     </component>

Modified: incubator/nuvem/trunk/nuvem-samples/store-assets/src/main/java/services/XMPPShipmentObserver.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-samples/store-assets/src/main/java/services/XMPPShipmentObserver.java?rev=1146503&r1=1146502&r2=1146503&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-samples/store-assets/src/main/java/services/XMPPShipmentObserver.java
(original)
+++ incubator/nuvem/trunk/nuvem-samples/store-assets/src/main/java/services/XMPPShipmentObserver.java
Wed Jul 13 22:24:05 2011
@@ -24,6 +24,10 @@ import org.apache.nuvem.cloud.xmpp.JID;
 import org.apache.nuvem.cloud.xmpp.Status;
 import org.apache.nuvem.cloud.xmpp.XMPPEndPoint;
 import org.apache.nuvem.cloud.xmpp.message.MessageBuilder;
+import org.apache.nuvem.cloud.xmpp.presence.Presence;
+import org.apache.nuvem.cloud.xmpp.presence.PresenceBuilder;
+import org.apache.nuvem.cloud.xmpp.presence.PresenceListener;
+import org.oasisopen.sca.annotation.Init;
 import org.oasisopen.sca.annotation.Reference;
 import org.oasisopen.sca.annotation.Scope;
 
@@ -33,16 +37,42 @@ public class XMPPShipmentObserver implem
 	@Reference
 	private XMPPEndPoint endpoint;
 
+	private static final String message = "Welcome to Nuvem Store";
+
+	@Init
+	public void init() {
+		endpoint.presenceManager().registerListener(new Greeter(endpoint));
+	}
+
 	public void onStatusUpdate(Shipment shipment, Event event) {
 		JID jid = shipment.getJidToUpdate();
 		System.out.println("inviting user of jid : " + jid.asString());
 		Status status = endpoint.invite(jid.asString());
 		System.out.println("status of invite:" + status.hasErrors());
 		if (!status.hasErrors()) {
-			endpoint.sendMessage(new MessageBuilder().toRecipient(
-					shipment.getJidToUpdate().asString()).containing(
-					event.toString()).build());
+			endpoint.sendMessage(new MessageBuilder()
+					.toRecipient(shipment.getJidToUpdate().asString())
+					.containing(event.toString()).build());
+		}
+	}
+
+	public static class Greeter implements PresenceListener {
+		private XMPPEndPoint xmppEndPoint;
+
+		public Greeter(XMPPEndPoint endPoint) {
+			this.xmppEndPoint = endPoint;
 		}
+
+		@Override
+		public void listen(Presence presence) {
+			if (presence.type() == Presence.Type.AVAILABLE) {
+				PresenceBuilder builder = new PresenceBuilder()
+						.to(presence.from()).withStatus(message)
+						.withType(Presence.Type.AVAILABLE);
+				xmppEndPoint.presenceManager().sendPresence(builder.build());
+			}
+		}
+
 	}
 
 }



Mime
View raw message