You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2011/01/17 19:26:24 UTC

svn commit: r1060036 - in /activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java: ./ src/ src/main/ src/main/java/ src/main/java/example/ src/test/ src/test/scala/ src/test/scala/org/ src/test/scala/org/fusesource/ src/test/scala/...

Author: chirino
Date: Mon Jan 17 18:26:23 2011
New Revision: 1060036

URL: http://svn.apache.org/viewvc?rev=1060036&view=rev
Log:
Added a new java stomp example using the stompjms library.

Added:
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/pom.xml
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/readme.md
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/main/
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/main/java/
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/main/java/example/
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/main/java/example/Listener.java
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/main/java/example/Publisher.java
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/test/
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/test/scala/
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/test/scala/org/
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/test/scala/org/fusesource/
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/test/scala/org/fusesource/scalate/
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/test/scala/org/fusesource/scalate/sample/
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/test/scala/org/fusesource/scalate/sample/Main.scala
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/test/scala/org/fusesource/scalate/sample/SampleTest.scala

Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/pom.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/pom.xml?rev=1060036&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/pom.xml (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/pom.xml Mon Jan 17 18:26:23 2011
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You 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.
+-->
+<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>
+  
+  <groupId>example</groupId>
+  <artifactId>example</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  
+  <name>${project.artifactId}</name>
+  <description>Apollo Java Examples</description>
+
+  <repositories>
+    <repository>
+      <id>Fusesource Snapshots</id>
+      <url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
+    </repository>
+  </repositories>
+  
+  <dependencies>
+    
+    <dependency>
+      <groupId>org.fusesource.stompjms</groupId>
+      <artifactId>stompjms-client</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
+
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.1</version>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+
+      <!-- include all the dependencies into the jar so it's easier to execute the example -->
+      <plugin>
+        <groupId>org.fusesource.mvnplugins</groupId>
+        <artifactId>maven-uberize-plugin</artifactId>
+        <version>1.5</version>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals><goal>uberize</goal></goals>
+          </execution>
+        </executions>
+      </plugin>
+      
+    </plugins>
+  </build>
+  
+</project>
+

Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/readme.md
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/readme.md?rev=1060036&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/readme.md (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/readme.md Mon Jan 17 18:26:23 2011
@@ -0,0 +1,31 @@
+Prereqs
+=======
+
+- Install Java SDK
+- Install [Maven](http://maven.apache.org/download.html) 
+
+Building
+========
+
+Run:
+
+    mvn install
+
+Running the Examples
+====================
+
+In one terminal window run:
+
+    java -cp target/example-1.0-SNAPSHOT.jar example.Publisher
+
+In another terminal window run:
+
+    java -cp target/example-1.0-SNAPSHOT.jar example.Listener
+
+You can control to which stomp server the examples try to connect to by
+setting the following environment variables: 
+
+* `STOMP_HOST`
+* `STOMP_PORT`
+* `STOMP_USER`
+* `STOMP_PASSWORD`

Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/main/java/example/Listener.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/main/java/example/Listener.java?rev=1060036&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/main/java/example/Listener.java (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/main/java/example/Listener.java Mon Jan 17 18:26:23 2011
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 example;
+
+import org.fusesource.stompjms.StompJmsConnectionFactory;
+import org.fusesource.stompjms.StompJmsDestination;
+
+import javax.jms.*;
+
+class Listener {
+
+    public static void main(String []args) throws JMSException {
+
+        String user = env("STOMP_USER", "admin");
+        String password = env("STOMP_PASSWORD", "password");
+        String host = env("STOMP_HOST", "localhost");
+        int port = Integer.parseInt(env("STOMP_PORT", "61613"));
+        String destination = arg(args, 0, "/topic/event");
+
+        StompJmsConnectionFactory factory = new StompJmsConnectionFactory();
+        factory.setBrokerURI("tcp://" + host + ":" + port);
+
+        Connection connection = factory.createConnection(user, password);
+        connection.start();
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        Destination dest = StompJmsDestination.createDestination(destination);
+
+        MessageConsumer consumer = session.createConsumer(dest);
+        long start = System.currentTimeMillis();
+        long count = 0;
+        while(true) {
+            Message msg = consumer.receive();
+            if( msg instanceof  TextMessage ) {
+                String body = ((TextMessage) msg).getText();
+                if( "SHUTDOWN".equals(body)) {
+                    long diff = System.currentTimeMillis() - start;
+                    System.out.println(String.format("Received %d in %.2f seconds", count, (1.0*diff/1000.0)));
+                    break;
+                } else {
+                    if( count == 0 ) {
+                        start = System.currentTimeMillis();
+                    }
+                    count ++;
+                    if( count % 1000 == 0 ) {
+                        System.out.println(String.format("Received %d messages.", count));
+                    }
+                }
+
+            } else {
+                System.out.println("Unexpected message type: "+msg.getClass());
+            }
+        }
+        connection.close();
+    }
+
+    private static String env(String key, String defaultValue) {
+        String rc = System.getenv(key);
+        if( rc== null )
+            return defaultValue;
+        return rc;
+    }
+
+    private static String arg(String []args, int index, String defaultValue) {
+        if( index < args.length )
+            return args[index];
+        else
+            return defaultValue;
+    }
+}
\ No newline at end of file

Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/main/java/example/Publisher.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/main/java/example/Publisher.java?rev=1060036&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/main/java/example/Publisher.java (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/main/java/example/Publisher.java Mon Jan 17 18:26:23 2011
@@ -0,0 +1,79 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 example;
+
+import org.fusesource.stompjms.StompJmsConnectionFactory;
+import org.fusesource.stompjms.StompJmsDestination;
+
+import javax.jms.*;
+
+class Publisher {
+
+    public static void main(String []args) throws JMSException {
+
+        String user = env("STOMP_USER", "admin");
+        String password = env("STOMP_PASSWORD", "password");
+        String host = env("STOMP_HOST", "localhost");
+        int port = Integer.parseInt(env("STOMP_PORT", "61613"));
+        String destination = arg(args, 0, "/topic/event");
+
+        int messages = 10000;
+        int size = 256;
+
+        String DATA = "abcdefghijklmnopqrstuvwxyz";
+        String body = "";
+        for( int i=0; i < size; i ++) {
+            body += DATA.charAt(i%DATA.length());
+        }
+
+        StompJmsConnectionFactory factory = new StompJmsConnectionFactory();
+        factory.setBrokerURI("tcp://" + host + ":" + port);
+
+        Connection connection = factory.createConnection(user, password);
+        connection.start();
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        Destination dest = StompJmsDestination.createDestination(destination);
+        MessageProducer producer = session.createProducer(dest);
+        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+        for( int i=1; i <= messages; i ++) {
+            producer.send(session.createTextMessage(body));
+            if( (i % 1000) == 0) {
+                System.out.println(String.format("Sent %d messages", i));
+            }
+        }
+
+        producer.send(session.createTextMessage("SHUTDOWN"));
+        connection.close();
+
+    }
+
+    private static String env(String key, String defaultValue) {
+        String rc = System.getenv(key);
+        if( rc== null )
+            return defaultValue;
+        return rc;
+    }
+
+    private static String arg(String []args, int index, String defaultValue) {
+        if( index < args.length )
+            return args[index];
+        else
+            return defaultValue;
+    }
+
+}
\ No newline at end of file

Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/test/scala/org/fusesource/scalate/sample/Main.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/test/scala/org/fusesource/scalate/sample/Main.scala?rev=1060036&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/test/scala/org/fusesource/scalate/sample/Main.scala (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/test/scala/org/fusesource/scalate/sample/Main.scala Mon Jan 17 18:26:23 2011
@@ -0,0 +1,36 @@
+/**
+ * Copyright (C) 2009-2010 the original author or authors.
+ * See the notice.md file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * 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.fusesource.scalate.sample
+
+import org.fusesource.scalate.test.JettyServer
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+object Main {
+
+  var jetty = new JettyServer
+  jetty.port = 8080
+
+  def main(args:Array[String]) {
+    jetty.start
+  }
+}
\ No newline at end of file

Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/test/scala/org/fusesource/scalate/sample/SampleTest.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/test/scala/org/fusesource/scalate/sample/SampleTest.scala?rev=1060036&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/test/scala/org/fusesource/scalate/sample/SampleTest.scala (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/java/src/test/scala/org/fusesource/scalate/sample/SampleTest.scala Mon Jan 17 18:26:23 2011
@@ -0,0 +1,140 @@
+/**
+ * Copyright (C) 2009-2010 the original author or authors.
+ * See the notice.md file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * 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.fusesource.scalate.sample
+
+import _root_.org.junit.runner.RunWith
+import _root_.org.scalatest.junit.JUnitRunner
+import _root_.org.scalatest.{FunSuite}
+
+import _root_.org.fusesource.scalate.test._
+
+/**
+ * @version $Revision: 1.1 $
+ */
+@RunWith(classOf[JUnitRunner])
+class SampleTest extends FunSuite with WebServerMixin with WebDriverMixin {
+
+  override protected def beforeAll(configMap: Map[String, Any]) = {
+    System.setProperty("scalate.mode", "development")
+    super.beforeAll(configMap)
+  }
+
+  testPageContains("ssp/renderObject.ssp", "Strachan")
+
+  test("home page") {
+    webDriver.get(rootUrl)
+    pageContains("Scalate")
+  }
+
+  testPageContains("jade/captureAttribute.jade", "the captured template", "some javascript goes here", "Hello World")
+
+  testPageContains("mustache", "Scala", "Great", "Java", "Crufty")
+  testPageContains("mustache/errors/templateCompileError.mustache", "Missing", "'{{/items}}'", "near line 8")
+
+  testPageContains("sampleServlet", "The foo is: Foo(")
+
+  testPageContains("ssp/capture.ssp", "Hello James", "Sample 2", "Hello James")
+  testPageContains("ssp/customLayout.ssp", "layout header goes here...", "Custom page", "This is some text", "layout footer goes here...")
+  testPageContains("ssp/defaultAttribute.ssp", "James")
+  testPageContains("ssp/exampleIncludes.ssp", "included from /includes/something.jsp",
+    "included from /ssp/child/foo.ssp", "included from /includes/something.jsp", "Finished including!")
+
+  testPageContains("ssp/errors/badAttributeType.ssp",
+    "error: not found: type StringF",
+    "in /ssp/errors/badAttributeType.ssp near line 3 col 13")
+  
+  testPageContains("ssp/errors/badExpression.ssp",
+    "error: not found: value nameX",
+    "in /ssp/errors/badExpression.ssp near line 5 col 13")
+
+  testPageContains("ssp/errors/missingAttribute.ssp", "The value for 'name' was not set")
+  testPageContains("ssp/errors/missingInclude.ssp", "Could not load resource")
+  testPageContains("ssp/errors/missingView.ssp", "No 'index' view template could be found for model object")
+
+  testPageContains("ssp/ifExpression.ssp", "x = 1", "x is 1", "x = 2", "x is not 1")
+  testPageContains("ssp/ifExpression2.ssp", "x = 1", "x is 1", "x = 2", "x is not 1")
+  testPageContains("ssp/includeServlet.ssp", "Scalate Start", "Hello World!", "Scalate End")
+  testPageContains("ssp/implicitParamTest.ssp", "encoded '/somePath'", "encoded2 '/anotherPath'", "encoded3 '/path3'")
+  testPageContains("ssp/locale.ssp", "22.0 / 7 = 3.143")
+  testPageContains("ssp/matchExpression.ssp", "i = 1", "i is 1", "i = 2", "i is 2", "i = 3", "i is something")
+
+  testPage("ssp/noLayout.ssp") {
+    pageContains("No Layout", "This page has no separate layout")
+    pageNotContains("stylesheet", "text/css", "style.css")
+  }
+
+//  testPageContains("ssp/renderObject.ssp", "Strachan")
+  testPageContains("ssp/optionTest.ssp", "no bar", "no foo")
+  testPageContains("ssp/optionTest2.ssp", "no foo")
+  testPageContains("ssp/renderCaseClass.ssp", "Strachan", "<hr/>", "Chirino")
+  testPageContains("ssp/renderCollection.ssp", "Strachan", "<hr/>", "Chirino")
+  testPageContains("ssp/renderCollection2.ssp", "Strachan", "Person 2", "Chirino")
+  testPageContains("ssp/renderCollection3.ssp", "Strachan", "Dude 2", "Chirino")
+  testPageContains("ssp/renderTemplate.ssp", "James", "London", "Hiram", "Tampa", "Matt", "No Location", "Paul", "USA")
+  testPageContains("ssp/sampleTag.ssp",  "Wrapped body", "hey James this is some body text!", "End of wrapped body")
+  testPageContains("ssp/sampleTag2.ssp", "Wrapped body", "hey James this is some body text!", "End of wrapped body")
+  testPageContains("ssp/sampleTag3.ssp", "Wrapped body", "hey Hiram this is some body text!", "End of wrapped body")
+  testPageContains("ssp/simple.ssp", "1 + 2 = 3")
+  testPageContains("ssp/snippet.ssp", "mmm I like beer")
+  testPageContains("ssp/velocity/sampleTag.ssp",  "Wrapped body", "hey James this is some body text!", "End of wrapped body")
+
+  testPageContains("bad", "error: not found: value unknown")
+  testPageContains("foo", "Hello from a FooResource!")
+  testPageContains("foo/abc", "The item id is", "abc")
+  testPageContains("foo/def", "The item id is", "def")
+
+  testPageContains("scaml/defaultAttribute.scaml", "James")
+
+  testPageContains("scaml/errors/badAttributeType.scaml",
+    "error: not found: type StringT",
+    "in /scaml/errors/badAttributeType.scaml near line 19 col 13")
+
+  testPageContains("scaml/errors/badExpression.scaml",
+    "error: not found: value nameX",
+    "in /scaml/errors/badExpression.scaml near line 24 col 11")
+
+  testPageContains("scaml/errors/missingAttribute.scaml", "The value for 'name' was not set")
+  testPageContains("scaml/errors/missingInclude.scaml", "Could not load resource")
+
+  testPageContains("scaml/errors/scalaCompileError.scaml",
+    "error: not found: value unknown",
+    "in /scaml/errors/scalaCompileError.scaml near line 25 col 17",
+    "- for (i &lt;-")
+
+  testPageContains("scaml/errors/templateCompileError.scaml",
+    "Inconsistent indent level detected: intended too shallow",
+    "in /scaml/errors/templateCompileError.scaml near line 23 col 4",
+    "%h1 Template Compiler Error")
+
+
+  testPageContains("scaml/captureAttribute.scaml", "Captured text", "Hello World")
+  testPageContains("scaml/locale.scaml", "22.0 / 7 = 3.143")
+  testPageContains("scaml/optionTest.scaml", "no foo")
+  testPageContains("scaml/renderObject.scaml", "Strachan")
+  testPageContains("scaml/renderCaseClass.scaml", "Strachan", "<hr/>", "Chirino")
+  testPageContains("scaml/renderCollection.scaml", "Strachan", "<hr/>", "Chirino")
+  testPageContains("scaml/sampleTag.scaml",  "Wrapped body", "hey Hiram this is some body text!", "End of wrapped body")
+  testPageContains("scaml/sampleTag2.scaml", "Wrapped body", "hey Hiram this is some body text!", "End of wrapped body")
+  testPageContains("scaml/sampleTag3.scaml", "Wrapped body", "hey James this is some body text!", "End of wrapped body")
+  testPageContains("scaml/simple.scaml", "Scaml is a Scala version of", "Haml")
+  testPageContains("scaml/snippet.scaml", "mmm I like beer")
+  testPageContains("scaml/standalone.scaml", "1 + 2 = 3")
+  testPageContains("filtered.html", "This AWESOME page is rendered by the filter.")
+
+}
\ No newline at end of file