https://issues.apache.org/jira/browse/AMQ-4418 - refactor web demo to be war that can be ran in karaf

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1462479 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2013-03-29 13:34:34 +00:00
parent 14b91d41b5
commit 0507ad380b
14 changed files with 144 additions and 400 deletions

View File

@ -65,10 +65,12 @@
javax.transaction*, javax.transaction*,
org.apache.commons.pool*;resolution:=optional, org.apache.commons.pool*;resolution:=optional,
org.apache.commons.net*;resolution:=optional, org.apache.commons.net*;resolution:=optional,
com.sun.syndication*;resolution:=optional,
* *
</activemq.osgi.import.pkg> </activemq.osgi.import.pkg>
<activemq.osgi.export> <activemq.osgi.export>
org.apache.activemq*;version=${project.version};-noimport:=true;-split-package:=merge-first, org.apache.activemq*;version=${project.version};-noimport:=true;-split-package:=merge-first,
org.apache.activemq.web*;version=${project.version};-noimport:=true;-split-package:=merge-first,
</activemq.osgi.export> </activemq.osgi.export>
<activemq.osgi.private.pkg> <activemq.osgi.private.pkg>
org.fusesource*, org.fusesource*,
@ -148,6 +150,11 @@
<artifactId>activemq-ra</artifactId> <artifactId>activemq-ra</artifactId>
</dependency> </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>activemq-web</artifactId>
</dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>activemq-spring</artifactId> <artifactId>activemq-spring</artifactId>

View File

@ -46,6 +46,96 @@
<scanIntervalSeconds>10</scanIntervalSeconds> <scanIntervalSeconds>10</scanIntervalSeconds>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<outputFileNameMapping>@{artifactId}@-@{baseVersion}@@{dashClassifier?}@.@{extension}@</outputFileNameMapping>
<packagingExcludes>
WEB-INF/lib/jetty*.jar,
WEB-INF/lib/servlet*.jar,
WEB-INF/lib/activemq*.jar
</packagingExcludes>
<webResources>
<resource>
<directory>${basedir}/../activemq-web-console/src/main/webapp/styles/</directory>
<targetPath>styles</targetPath>
</resource>
<resource>
<directory>${basedir}/../activemq-web-console/src/main/webapp/images/</directory>
<targetPath>images</targetPath>
</resource>
<resource>
<directory>${basedir}/../activemq-web-console/src/main/webapp/js/</directory>
<targetPath>js</targetPath>
</resource>
</webResources>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
<configuration>
<supportedProjectTypes>
<supportedProjectType>jar</supportedProjectType>
<supportedProjectType>bundle</supportedProjectType>
<supportedProjectType>war</supportedProjectType>
</supportedProjectTypes>
<instructions>
<Webapp-Context>activemqdemo</Webapp-Context>
<Web-ContextPath>activemqdemo</Web-ContextPath>
<Bundle-ClassPath>.,WEB-INF/classes</Bundle-ClassPath>
<Embed-Directory>WEB-INF/lib</Embed-Directory>
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Import-Package>
org.apache.activemq,
org.apache.activemq.web,
org.xml.sax,
org.xml.sax.helpers,
javax.xml.parsers,
javax.xml.transform,
javax.management.remote,
javax.naming,
org.w3c.dom,
javax.servlet,
javax.servlet.http,
javax.servlet.resources,
javax.servlet.jsp,
javax.servlet.jsp.tagext,
javax.servlet.jsp.el,
javax.management,
javax.management.openmbean,
javax.net,
org.osgi.framework,
org.osgi.service.cm,
org.apache.commons.logging;version="[1.1,2)";resolution:=optional,
org.slf4j;version="[1.6,2)";resolution:=optional,
org.slf4j.spi;version="[1.6,2)";resolution:=optional,
org.apache.log4j;version="[1.2.14,2)";resolution:=optional,
org.apache.log4j.spi;version="[1.2.14,2)";resolution:=optional
</Import-Package>
<Export-Package>
!*
</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>

View File

@ -24,11 +24,6 @@
<display-name>Apache ActiveMQ Web Demo</display-name> <display-name>Apache ActiveMQ Web Demo</display-name>
<!-- context config --> <!-- context config -->
<context-param>
<param-name>org.apache.activemq.brokerURL</param-name>
<param-value>vm://amq-broker</param-value>
<description>The URL of the Message Broker to connect to</description>
</context-param>
<context-param> <context-param>
<param-name>org.apache.activemq.embeddedBroker</param-name> <param-name>org.apache.activemq.embeddedBroker</param-name>
<param-value>true</param-value> <param-value>true</param-value>
@ -106,4 +101,9 @@
<url-pattern>/portfolioPublish</url-pattern> <url-pattern>/portfolioPublish</url-pattern>
</servlet-mapping> </servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app> </web-app>

View File

@ -22,10 +22,10 @@
<title>Chat Example - ActiveMQ Web Demos</title> <title>Chat Example - ActiveMQ Web Demos</title>
<link rel="stylesheet" href="chat.css" type="text/css"> <link rel="stylesheet" href="chat.css" type="text/css">
<style type="text/css" media="screen"> <style type="text/css" media="screen">
@import url(/admin/styles/sorttable.css); @import url(styles/sorttable.css);
@import url(/admin/styles/type-settings.css); @import url(styles/type-settings.css);
@import url(/admin/styles/site.css); @import url(styles/site.css);
@import url(/admin/styles/prettify.css); @import url(styles/prettify.css);
</style> </style>
<!--<script type="text/javascript" src="js/prototype.js"></script>--> <!--<script type="text/javascript" src="js/prototype.js"></script>-->

View File

@ -21,16 +21,16 @@
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>ActiveMQ Web Demos</title> <title>ActiveMQ Web Demos</title>
<style type="text/css" media="screen"> <style type="text/css" media="screen">
@import url(/admin/styles/sorttable.css); @import url(styles/sorttable.css);
@import url(/admin/styles/type-settings.css); @import url(styles/type-settings.css);
@import url(/admin/styles/site.css); @import url(styles/site.css);
@import url(/admin/styles/prettify.css); @import url(styles/prettify.css);
</style> </style>
<script type='text/javascript' src='/js/common.js'></script> <script type='text/javascript' src='js/common.js'></script>
<script type='text/javascript' src='/js/css.js'></script> <script type='text/javascript' src='js/css.js'></script>
<script type='text/javascript' src='/js/standardista-table-sorting.js'></script> <script type='text/javascript' src='js/standardista-table-sorting.js'></script>
<script type='text/javascript' src='/js/prettify.js'></script> <script type='text/javascript' src='js/prettify.js'></script>
<script>addEvent(window, 'load', prettyPrint)</script> <script>addEvent(window, 'load', prettyPrint)</script>

View File

@ -1,31 +0,0 @@
<!--
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.
-->
<html>
<head>
<title>Sandbox</title>
<link rel="stylesheet" type="text/css" href="../style.css"></link>
</head>
<body>
<h1>Sandbox</h1>
<p>This area contains the old HTML and JavaScript demos. We've now
migrated to <a href="http://openrico.org/">OpenRico</a> instead to reuse
an off the shelf Ajax library.</p>
</body>
</html>

View File

@ -1,93 +0,0 @@
<!--
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.
-->
<html>
<head>
<title>My Portfolio</title>
<link rel="stylesheet" href="style.css" type="text/css">
<style>
.stocks { border: 1 solid black; }
.stocks td, .stocks th { width: 200; text-align: right; }
.stocks .up { background-color: #9f9; }
.stocks .down { background-color: #f99; }
</style>
</head>
<body onload="subscribe()">
<script src="prototype.js" language="JavaScript1.2"></script>
<script src="portfolio2.js" language="JavaScript1.2"></script>
<h1>My Portfolio</h1>
<p>
This example displays an example stock portfolio.
In a real system this page would be generated dynamically based on the
users current stock portfolio
</p>
<table class="stocks">
<tr>
<th>Stock</th>
<th>Description</th>
<th>Amount</th>
<th>Price</th>
<th>Value</th>
<th>Cost</th>
<th>P & L</th>
</tr>
<tr id="IBMW">
<td>IBMW</td>
<td>IBM Stock</td>
<td id="amount">1000</td>
<td id="price"></td>
<td id="value"></td>
<td id="cost">19000</td>
<td id="pl"></td>
</tr>
<tr id="MSFT">
<td>MSFT</td>
<td>Microsoft</td>
<td id="amount">6000</td>
<td id="price"></td>
<td id="value"></td>
<td id="cost">22000</td>
<td id="pl"></td>
</tr>
<tr id="BEAS">
<td>BEAS</td>
<td>BEA Stock</td>
<td id="amount">1100</td>
<td id="price"></td>
<td id="value"></td>
<td id="cost">12342</td>
<td id="pl"></td>
</tr>
<tr id="SUNW">
<td>SUNW</td>
<td>Sun Microsystems Inc</td>
<td id="amount">3000</td>
<td id="price"></td>
<td id="value"></td>
<td id="cost">7700</td>
<td id="pl"></td>
</tr>
</table>
<div id="stuff"></div>
</body>
</html>

View File

@ -1,49 +0,0 @@
/**
* 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.
*/
// updates the portfolio row for a given message and symbol
function updatePortfolioRow(message, destination) {
var priceMessage = message.documentElement
var price = parseFloat(priceMessage.getAttribute('bid'))
var symbol = priceMessage.getAttribute('stock')
var movement = priceMessage.getAttribute('movement')
if (movement == null) {
movement = 'up'
}
var row = document.getElementById(symbol)
// perform portfolio calculations
var value = asFloat(find(row, 'amount')) * price
var pl = value - asFloat(find(row, 'cost'))
// now lets update the HTML DOM
find(row, 'price').innerHTML = fixedDigits(price, 2)
find(row, 'value').innerHTML = fixedDigits(value, 2)
find(row, 'pl').innerHTML = fixedDigits(pl, 2)
find(row, 'price').className = movement
find(row, 'pl').className = pl >= 0 ? 'up' : 'down'
}
var connection = new Connection("jms/STOCKS/*")
function subscribe() {
connection.addMessageListener(/^STOCKS\..*$/, updatePortfolioRow)
}

View File

@ -1,52 +0,0 @@
/**
* 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.
*/
/// -----------------
// Original code by Joe Walnes
// -----------------
/*** Convenience methods, added as mixins to standard classes (object prototypes) ***/
/**
* Return number as fixed number of digits.
*/
//Number.prototype.fixedDigits = function(digits) {
function fixedDigits(t, digits) {
return (t.toFixed) ? t.toFixed(digits) : this
}
/**
* Find direct child of an element, by id.
*/
// Element.prototype.find = function(id) {
function find(t, id) {
for (i = 0; i < t.childNodes.length; i++) {
var child = t.childNodes[i]
if (child.id == id) {
return child
}
}
return null
}
/**
* Return the text contents of an element as a floating point number.
*/
//Element.prototype.asFloat = function() {
function asFloat(t) {
return parseFloat(t.innerHTML)
}

View File

@ -1,149 +0,0 @@
/**
* 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.
*/
// -----------------
// Original code by Joe Walnes
// -----------------
function Connection(webmqUrl, id) {
this.messageListeners = new Array()
this.webmqUrl = webmqUrl
if (id == null) {
// TODO use secure random id generation
id = Math.round(Math.random() * 100000000)
}
this.id = id
// TODO don't start anything until document has finished loading
var http = this.createHttpControl()
this.getNextMessageAndLoop(webmqUrl, id, http)
}
Connection.prototype.getNextMessageAndLoop = function(webmqUrl, id, http) {
http.open("GET", webmqUrl + "?id=" + id + "&xml=true", true)
var connection = this
http.onreadystatechange = function() {
if (http.readyState == 4) {
var ok
try {
ok = http.status && http.status == 200
}
catch (e) {
ok = false // sometimes accessing the http.status fields causes errors in firefox. dunno why. -joe
}
if (ok) {
connection.processIncomingMessage(http)
}
// why do we have to create a new instance?
// this is not required on firefox but is on mozilla
//http.abort()
http = connection.createHttpControl()
connection.getNextMessageAndLoop(webmqUrl, id, http)
}
}
http.send(null)
}
Connection.prototype.sendMessage = function(destination, message) {
// TODO should post via body rather than URL
// TODO specify destination in message
var http = this.createHttpControl()
http.open("POST", this.webmqUrl + "?id=" + this.id + "&body=" + message, true)
http.send(null)
}
Connection.prototype.processIncomingMessage = function(http) {
var destination = http.getResponseHeader("destination")
var message = http.responseXML
if (message == null) {
message = http.responseText
}
//alert(message.responseText)
for (var j = 0; j < this.messageListeners.length; j++) {
var registration = this.messageListeners[j]
if (registration.matcher(destination)) {
registration.messageListener(message, destination)
}
}
}
Connection.prototype.addMessageListener = function(matcher, messageListener) {
var wrappedMatcher
if (matcher.constructor == RegExp) {
wrappedMatcher = function(destination) {
return matcher.test(destination)
}
}
else if (matcher.constructor == String) {
wrappedMatcher = function(destination) {
return matcher == destination
}
}
else {
wrappedMatcher = matcher
}
this.messageListeners[this.messageListeners.length] = { matcher: wrappedMatcher, messageListener: messageListener }
}
Connection.prototype.createHttpControl = function() {
// for details on using XMLHttpRequest see
// http://webfx.eae.net/dhtml/xmlextras/xmlextras.html
try {
if (window.XMLHttpRequest) {
var req = new XMLHttpRequest()
// some older versions of Moz did not support the readyState property
// and the onreadystate event so we patch it!
if (req.readyState == null) {
req.readyState = 1
req.addEventListener("load", function () {
req.readyState = 4
if (typeof req.onreadystatechange == "function") {
req.onreadystatechange()
}
}, false)
}
return req
}
if (window.ActiveXObject) {
return new ActiveXObject(this.getControlPrefix() + ".XmlHttp")
}
}
catch (ex) {}
// fell through
throw new Error("Your browser does not support XmlHttp objects")
}
Connection.prototype.getControlPrefix = function() {
if (this.prefix) {
return this.prefix
}
var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"]
var o, o2
for (var i = 0; i < prefixes.length; i++) {
try {
// try to create the objects
o = new ActiveXObject(prefixes[i] + ".XmlHttp")
o2 = new ActiveXObject(prefixes[i] + ".XmlDom")
return this.prefix = prefixes[i]
}
catch (ex) {}
}
throw new Error("Could not find an installed XML parser")
}

View File

@ -21,10 +21,10 @@
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="chat.css" type="text/css"> <link rel="stylesheet" href="chat.css" type="text/css">
<style type="text/css" media="screen"> <style type="text/css" media="screen">
@import url(/admin/styles/sorttable.css); @import url(../styles/sorttable.css);
@import url(/admin/styles/type-settings.css); @import url(../styles/type-settings.css);
@import url(/admin/styles/site.css); @import url(../styles/site.css);
@import url(/admin/styles/prettify.css); @import url(../styles/prettify.css);
</style> </style>
<title>Chat Example Using Stomp Over WebSocket</title> <title>Chat Example Using Stomp Over WebSocket</title>
<link rel="stylesheet" type="text/css" href="chat.css"></link> <link rel="stylesheet" type="text/css" href="chat.css"></link>

View File

@ -47,6 +47,8 @@ import javax.servlet.http.HttpSessionEvent;
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.MessageAvailableConsumer; import org.apache.activemq.MessageAvailableConsumer;
import org.apache.activemq.broker.BrokerRegistry;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.camel.component.ActiveMQComponent; import org.apache.activemq.camel.component.ActiveMQComponent;
import org.apache.activemq.camel.component.ActiveMQConfiguration; import org.apache.activemq.camel.component.ActiveMQConfiguration;
import org.apache.activemq.pool.PooledConnectionFactory; import org.apache.activemq.pool.PooledConnectionFactory;
@ -280,11 +282,18 @@ public class WebClient implements HttpSessionActivationListener, HttpSessionBind
if (factory == null) { if (factory == null) {
String brokerURL = servletContext.getInitParameter(BROKER_URL_INIT_PARAM); String brokerURL = servletContext.getInitParameter(BROKER_URL_INIT_PARAM);
LOG.debug("Value of: " + BROKER_URL_INIT_PARAM + " is: " + brokerURL);
if (brokerURL == null) { if (brokerURL == null) {
throw new IllegalStateException("missing brokerURL (specified via " + BROKER_URL_INIT_PARAM + " init-Param"); LOG.debug("Couldn't find " + BROKER_URL_INIT_PARAM + " param, trying to find a broker embedded in a local VM");
BrokerService broker = BrokerRegistry.getInstance().findFirst();
if (broker == null) {
throw new IllegalStateException("missing brokerURL (specified via " + BROKER_URL_INIT_PARAM + " init-Param) or embedded broker");
} else {
brokerURL = "vm://" + broker.getBrokerName();
} }
}
LOG.debug("Using broker URL: " + brokerURL);
ActiveMQConnectionFactory amqfactory = new ActiveMQConnectionFactory(brokerURL); ActiveMQConnectionFactory amqfactory = new ActiveMQConnectionFactory(brokerURL);

View File

@ -67,6 +67,18 @@
<exclude>**/webconsole-embedded.xml</exclude> <exclude>**/webconsole-embedded.xml</exclude>
</excludes> </excludes>
</fileSet> </fileSet>
<fileSet>
<directory>../activemq-web-console/src/main/webapp/styles/</directory>
<outputDirectory>/webapps-demo/demo/styles/</outputDirectory>
</fileSet>
<fileSet>
<directory>../activemq-web-console/src/main/webapp/images/</directory>
<outputDirectory>/webapps-demo/demo/images/</outputDirectory>
</fileSet>
<fileSet>
<directory>../activemq-web-console/src/main/webapp/js/</directory>
<outputDirectory>/webapps-demo/demo/js/</outputDirectory>
</fileSet>
<!-- the file server --> <!-- the file server -->
<fileSet> <fileSet>

View File

@ -234,10 +234,10 @@
<module>activemq-rar</module> <module>activemq-rar</module>
<module>activemq-run</module> <module>activemq-run</module>
<module>activemq-spring</module> <module>activemq-spring</module>
<module>activemq-osgi</module>
<module>activemq-blueprint</module>
<module>activemq-tooling</module> <module>activemq-tooling</module>
<module>activemq-web</module> <module>activemq-web</module>
<module>activemq-osgi</module>
<module>activemq-blueprint</module>
<module>activemq-web-demo</module> <module>activemq-web-demo</module>
<module>activemq-web-console</module> <module>activemq-web-console</module>
<module>activemq-karaf-itest</module> <module>activemq-karaf-itest</module>