[tunguska~hg:43] Welcome page updated

  • From: abien@kenai.com
  • To: commits@tunguska.kenai.com
  • Subject: [tunguska~hg:43] Welcome page updated
  • Date: Wed, 4 Nov 2009 12:27:58 +0000

Project:    tunguska
Repository: hg
Revision:   43
Author:     abien
Date:       2009-11-04 12:26:51 UTC
Link:       

Log Message:
------------
Initial test for HttpEventFire
HttpEventFire implementation finished.
Welcome page updated


Revisions:
----------
41
42
43


Modified Paths:
---------------
tunguska-client/pom.xml
tunguska-client/src/test/java/org/tunguska/client/http/HttpEventFireTest.java
tunguska-client/src/main/webapp/index.jsp


Added Paths:
------------
tunguska-client/src/test/java/org/tunguska/client/http/HttpEventFireTest.java
tunguska-client/src/main/java/org/tunguska/client/EventFire.java
tunguska-client/src/main/java/org/tunguska/client/http/HttpEventFire.java
tunguska-client/src/main/java/org/tunguska/client/jms/JMSEventFire.java


Diffs:
------
diff -r 90ed34b053be -r edf7c09c511f 
tunguska-client/src/test/java/org/tunguska/client/http/HttpEventFireTest.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/tunguska-client/src/test/java/org/tunguska/client/http/HttpEventFireTest.java
     Wed Nov 04 12:54:13 2009 +0100
@@ -0,0 +1,42 @@
+/**
+This file is part of tunguska.
+
+tunguska is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+tunguska 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 General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see 
<http://www.opensource.org/licenses/gpl-2.0.php>.
+
+* Copyright (c) 04. November 2009
+*/
+
+package org.tunguska.client.http;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author http://blog.adam-bien.com
+ */
+public class HttpEventFireTest {
+
+
+    @Test
+    public void buildUrl() throws Exception {
+        HttpEventFire eventFire = new HttpEventFire();
+        final String payload = "message2hugo";
+        String buildUrl = eventFire.buildUrl("hugo", payload);
+        assertNotNull(buildUrl);
+        
assertEquals("http://localhost:8080/tunguska/pub/hugo?payload="+payload,buildUrl);
+
+    }
+
+}
\ No newline at end of file


diff -r edf7c09c511f -r 8425f2653a7f tunguska-client/pom.xml
--- a/tunguska-client/pom.xml   Wed Nov 04 12:54:13 2009 +0100
+++ b/tunguska-client/pom.xml   Wed Nov 04 13:23:08 2009 +0100
@@ -35,7 +35,14 @@
       <type>jar</type>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpclient</artifactId>
+      <version>4.0</version>
+      <scope>compile</scope>
+    </dependency>
   </dependencies>
+
   <build>
     <plugins>
       <plugin>
@@ -63,3 +70,4 @@
     </properties>
 </project>
 
+

diff -r edf7c09c511f -r 8425f2653a7f 
tunguska-client/src/main/java/org/tunguska/client/EventFire.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tunguska-client/src/main/java/org/tunguska/client/EventFire.java  Wed 
Nov 04 13:23:08 2009 +0100
@@ -0,0 +1,29 @@
+/**
+This file is part of tunguska.
+
+tunguska is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+tunguska 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 General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see 
<http://www.opensource.org/licenses/gpl-2.0.php>.
+
+* Copyright (c) 04. November 2009
+*
+*/
+package org.tunguska.client;
+
+/**
+ *
+ * @author http://blog.adam-bien.com
+ */
+public interface EventFire {
+
+     public void send(String toChannel,String message);
+}

diff -r edf7c09c511f -r 8425f2653a7f 
tunguska-client/src/main/java/org/tunguska/client/http/HttpEventFire.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/tunguska-client/src/main/java/org/tunguska/client/http/HttpEventFire.java 
Wed Nov 04 13:23:08 2009 +0100
@@ -0,0 +1,78 @@
+/**
+This file is part of tunguska.
+
+tunguska is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+tunguska 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 General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see 
<http://www.opensource.org/licenses/gpl-2.0.php>.
+
+* Copyright (c) 04. November 2009
+*
+*/
+package org.tunguska.client.http;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+import javax.ejb.Asynchronous;
+import javax.ejb.Local;
+import javax.ejb.LocalBean;
+import javax.ejb.Stateless;
+import javax.jws.WebService;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.utils.URIUtils;
+import org.apache.http.client.utils.URLEncodedUtils;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.message.BasicNameValuePair;
+import org.tunguska.client.EventFire;
+
+/**
+ *
+ * @author http://blog.adam-bien.com
+ */
+@WebService
+@LocalBean
+@Stateless
+@Local(EventFire.class)
+public class HttpEventFire implements EventFire{
+
+    private final static String HOST = "localhost";
+    private final static int PORT = 8080;
+    private final static String CONTEXT = "tunguska";
+    private final static String MAPPING = "pub";
+
+    @Override
+    @Asynchronous
+    public void send(String toChannel, String message) {
+        HttpClient client = new DefaultHttpClient();
+        URI uri = buildUrl(toChannel, message);
+        HttpGet getRequest = new HttpGet(uri);
+        try {
+            client.execute(getRequest);
+        } catch (Exception ex) {
+            throw new IllegalStateException("Cannot execute HttpClient: " + 
ex,ex);
+        }
+    }
+
+    URI buildUrl(String toChannel,String message){
+        List<NameValuePair> qparams = new ArrayList<NameValuePair>();
+        qparams.add(new BasicNameValuePair("payload", message));
+        try {
+            return  URIUtils.createURI("http", HOST,  PORT, CONTEXT + "/" + 
MAPPING + "/" + toChannel,
+                    URLEncodedUtils.format(qparams, "UTF-8"), null);
+        } catch (URISyntaxException ex) {
+            throw new IllegalArgumentException("URL cannot be parsed " 
+ex,ex);
+        }
+    }
+}

diff -r edf7c09c511f -r 8425f2653a7f 
tunguska-client/src/main/java/org/tunguska/client/jms/EventFire.java
--- a/tunguska-client/src/main/java/org/tunguska/client/jms/EventFire.java    
  Wed Nov 04 12:54:13 2009 +0100
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,90 +0,0 @@
-/**
-This file is part of tunguska.
-
-tunguska is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-tunguska 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 General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see 
<http://www.opensource.org/licenses/gpl-2.0.php>.
-
-* Copyright (c) 04. November 2009
-*
-*/package org.tunguska.client.jms;
-
-import javax.jms.Connection;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.annotation.Resource;
-import javax.ejb.Stateless;
-import javax.jms.ConnectionFactory;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.jms.Topic;
-import javax.jws.WebService;
-
-/**
- *
- * @author http://blog.adam-bien.com
- */
-@Stateless
-@WebService
-public class EventFire {
-    public static final String CHANNEL = "CHANNEL";
-    
-    @Resource(mappedName = "jms/tunguska")
-    private Topic tunguska;
-    @Resource(mappedName = "jms/tunguskaFactory")
-    private ConnectionFactory tunguskaFactory;
-
-    private Message createJMSMessageForjmsTunguska(Session session, String 
messageData) throws JMSException {
-        // TODO create and populate message to send
-        TextMessage tm = session.createTextMessage();
-        tm.setText(messageData);
-        return tm;
-    }
-
-    private void sendJMSMessageToTunguska(String toChannel,String message) 
throws JMSException {
-        Connection connection = null;
-        Session session = null;
-        try {
-            connection = tunguskaFactory.createConnection();
-            session = connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
-            MessageProducer messageProducer = 
session.createProducer(tunguska);
-            Message event = createJMSMessageForjmsTunguska(session, message);
-            event.setStringProperty( CHANNEL, toChannel);
-            messageProducer.send(event);
-        } finally {
-            if (session != null) {
-                try {
-                    session.close();
-                } catch (JMSException e) {
-                    
Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Cannot close 
session", e);
-                }
-            }
-            if (connection != null) {
-                connection.close();
-            }
-        }
-    }
-
-    
-    
-   public void send(String toChannel,String message){
-        try {
-            this.sendJMSMessageToTunguska(toChannel,message);
-        } catch (JMSException ex) {
-            throw new IllegalStateException("Cannot send JMS message " + 
ex,ex);
-        }
-   }

-}

diff -r edf7c09c511f -r 8425f2653a7f 
tunguska-client/src/main/java/org/tunguska/client/jms/JMSEventFire.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tunguska-client/src/main/java/org/tunguska/client/jms/JMSEventFire.java 
  Wed Nov 04 13:23:08 2009 +0100
@@ -0,0 +1,95 @@
+/**
+This file is part of tunguska.
+
+tunguska is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+tunguska 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 General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see 
<http://www.opensource.org/licenses/gpl-2.0.php>.
+
+* Copyright (c) 04. November 2009
+*/
+package org.tunguska.client.jms;
+
+import javax.jms.Connection;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.annotation.Resource;
+import javax.ejb.Local;
+import javax.ejb.LocalBean;
+import javax.ejb.Stateless;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.jws.WebService;
+import org.tunguska.client.EventFire;
+
+/**
+ *
+ * @author http://blog.adam-bien.com
+ */
+@Stateless
+@LocalBean
+@WebService
+@Local(EventFire.class)
+public class JMSEventFire implements EventFire{
+    public static final String CHANNEL = "CHANNEL";
+    
+    @Resource(mappedName = "jms/tunguska")
+    private Topic tunguska;
+    @Resource(mappedName = "jms/tunguskaFactory")
+    private ConnectionFactory tunguskaFactory;
+
+    private Message createJMSMessageForjmsTunguska(Session session, String 
messageData) throws JMSException {
+        // TODO create and populate message to send
+        TextMessage tm = session.createTextMessage();
+        tm.setText(messageData);
+        return tm;
+    }
+
+    private void sendJMSMessageToTunguska(String toChannel,String message) 
throws JMSException {
+        Connection connection = null;
+        Session session = null;
+        try {
+            connection = tunguskaFactory.createConnection();
+            session = connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
+            MessageProducer messageProducer = 
session.createProducer(tunguska);
+            Message event = createJMSMessageForjmsTunguska(session, message);
+            event.setStringProperty( CHANNEL, toChannel);
+            messageProducer.send(event);
+        } finally {
+            if (session != null) {
+                try {
+                    session.close();
+                } catch (JMSException e) {
+                    
Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Cannot close 
session", e);
+                }
+            }
+            if (connection != null) {
+                connection.close();
+            }
+        }
+    }
+
+    
+    
+   public void send(String toChannel,String message){
+        try {
+            this.sendJMSMessageToTunguska(toChannel,message);
+        } catch (JMSException ex) {
+            throw new IllegalStateException("Cannot send JMS message " + 
ex,ex);
+        }
+   }

+}

diff -r edf7c09c511f -r 8425f2653a7f 
tunguska-client/src/test/java/org/tunguska/client/http/HttpEventFireTest.java
--- 
a/tunguska-client/src/test/java/org/tunguska/client/http/HttpEventFireTest.java
     Wed Nov 04 12:54:13 2009 +0100
+++ 
b/tunguska-client/src/test/java/org/tunguska/client/http/HttpEventFireTest.java
     Wed Nov 04 13:23:08 2009 +0100
@@ -19,6 +19,7 @@
 
 package org.tunguska.client.http;
 
+import java.net.URI;
 import org.junit.Test;
 import static org.junit.Assert.*;
 
@@ -33,9 +34,9 @@
     public void buildUrl() throws Exception {
         HttpEventFire eventFire = new HttpEventFire();
         final String payload = "message2hugo";
-        String buildUrl = eventFire.buildUrl("hugo", payload);
+        URI buildUrl = eventFire.buildUrl("hugo", payload);
         assertNotNull(buildUrl);
-        
assertEquals("http://localhost:8080/tunguska/pub/hugo?payload="+payload,buildUrl);
+        
assertEquals("http://localhost:8080/tunguska/pub/hugo?payload="+payload,buildUrl.toASCIIString());
 
     }
 


diff -r 8425f2653a7f -r 8358f7fd50de tunguska-client/src/main/webapp/index.jsp
--- a/tunguska-client/src/main/webapp/index.jsp Wed Nov 04 13:23:08 2009 +0100
+++ b/tunguska-client/src/main/webapp/index.jsp Wed Nov 04 13:26:51 2009 +0100
@@ -10,6 +10,7 @@
     <body>
         <h1>Welcome to tunguska-client</h1>
         <p></p>
-        <a 
href="http://localhost:8080/tunguska-client/EventFireService?Tester";>Tester</a><br/>
+        <a 
href="http://localhost:8080/tunguska-client/JMSEventFireService?Tester";>JMS 
Publisher</a><br/>
+        <a 
href="http://localhost:8080/tunguska-client/HttpEventFireService?Tester";>Http 
Publisher</a><br/>
     </body>
 </html>






[tunguska~hg:43] Welcome page updated

abien 11/04/2009
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close