ARTEMIS-1019 Removing Aeroegear
Aeroegear has other ways to use Artemis
This commit is contained in:
parent
c0fe187666
commit
c1fa5d07c7
|
@ -81,11 +81,6 @@
|
|||
<groupId>org.apache.activemq.rest</groupId>
|
||||
<artifactId>artemis-rest</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>artemis-aerogear-integration</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
|
|
|
@ -41,9 +41,6 @@ import java.io.File;
|
|||
@MessageLogger(projectCode = "AMQ")
|
||||
public interface ActiveMQWebLogger extends BasicLogger {
|
||||
|
||||
/**
|
||||
* The aerogear logger.
|
||||
*/
|
||||
ActiveMQWebLogger LOGGER = Logger.getMessageLogger(ActiveMQWebLogger.class, ActiveMQWebLogger.class.getPackage().getName());
|
||||
|
||||
@LogMessage(level = Logger.Level.INFO)
|
||||
|
|
|
@ -51,7 +51,6 @@
|
|||
* [Embedding Apache ActiveMQ Artemis](embedding-activemq.md)
|
||||
* [Apache Karaf](karaf.md)
|
||||
* [Spring Integration](spring-integration.md)
|
||||
* [AeroGear Integration](aerogear-integration.md)
|
||||
* [CDI Integration](cdi-integration.md)
|
||||
* [Intercepting Operations](intercepting-operations.md)
|
||||
* [Protocols and Interoperability](protocols-interoperability.md)
|
||||
|
|
|
@ -1,104 +0,0 @@
|
|||
# AeroGear Integration
|
||||
|
||||
AeroGears push technology provides support for different push
|
||||
notification technologies like Google Cloud Messaging, Apple's APNs or
|
||||
Mozilla's SimplePush. Apache ActiveMQ Artemis allows you to configure a Connector
|
||||
Service that will consume messages from a queue and forward them to an
|
||||
AeroGear push server and subsequently sent as notifications to mobile
|
||||
devices.
|
||||
|
||||
## Configuring an AeroGear Connector Service
|
||||
|
||||
AeroGear Connector services are configured in the connector-services
|
||||
configuration:
|
||||
|
||||
<connector-service name="aerogear-connector">
|
||||
<factory-class>org.apache.activemq.artemis.integration.aerogear.AeroGearConnectorServiceFactory</factory-class>
|
||||
<param key="endpoint" value="endpoint"/>
|
||||
<param key="queue" value="jms.queue.aerogearQueue"/>
|
||||
<param key="application-id" value="an applicationid"/>
|
||||
<param key="master-secret" value="a mastersecret"/>
|
||||
</connector-service>
|
||||
<address-setting match="jms.queue.lastValueQueue">
|
||||
<last-value-queue>true</last-value-queue>
|
||||
</address-setting>
|
||||
|
||||
|
||||
Shown are the required params for the connector service and are:
|
||||
|
||||
- `endpoint`. The endpoint or URL of you AeroGear application.
|
||||
|
||||
- `queue`. The name of the queue to consume from.
|
||||
|
||||
- `application-id`. The application id of your mobile application in
|
||||
AeroGear.
|
||||
|
||||
- `master-secret`. The secret of your mobile application in AeroGear.
|
||||
|
||||
As well as these required parameters there are the following optional
|
||||
parameters
|
||||
|
||||
- `ttl`. The time to live for the message once AeroGear receives it.
|
||||
|
||||
- `badge`. The badge the mobile app should use for the notification.
|
||||
|
||||
- `sound`. The sound the mobile app should use for the notification.
|
||||
|
||||
- `filter`. A message filter(selector) to use on the connector.
|
||||
|
||||
- `retry-interval`. If an error occurs on send, how long before we try
|
||||
again to connect.
|
||||
|
||||
- `retry-attempts`. How many times we should try to reconnect after an
|
||||
error.
|
||||
|
||||
- `variants`. A comma separated list of variants that should get the
|
||||
message.
|
||||
|
||||
- `aliases`. A list of aliases that should get the message.
|
||||
|
||||
- `device-types`. A list of device types that should get the messag.
|
||||
|
||||
More in depth explanations of the AeroGear related parameters can be
|
||||
found in the [AeroGear Push docs](http://aerogear.org/push/)
|
||||
|
||||
## How to send a message for AeroGear
|
||||
|
||||
To send a message intended for AeroGear simply send a JMS Message and
|
||||
set the appropriate headers, like so
|
||||
|
||||
``` java
|
||||
Message message = session.createMessage();
|
||||
|
||||
message.setStringProperty("AEROGEAR_ALERT", "Hello this is a notification from ActiveMQ");
|
||||
|
||||
producer.send(message);
|
||||
```
|
||||
|
||||
|
||||
The 'AEROGEAR_ALERT' property will be the alert sent to the mobile
|
||||
device.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> If the message does not contain this property then it will be simply
|
||||
> ignored and left on the queue
|
||||
|
||||
Its also possible to override any of the other AeroGear parameters by
|
||||
simply setting them on the message, for instance if you wanted to set
|
||||
ttl of a message you would:
|
||||
|
||||
``` java
|
||||
message.setIntProperty("AEROGEAR_TTL", 1234);
|
||||
```
|
||||
|
||||
|
||||
or if you wanted to set the list of variants you would use:
|
||||
|
||||
``` java
|
||||
message.setStringProperty("AEROGEAR_VARIANTS", "variant1,variant2,variant3");
|
||||
```
|
||||
```
|
||||
|
||||
Again refer to the AeroGear documentation for a more in depth view on
|
||||
how to use these settings
|
|
@ -1,115 +0,0 @@
|
|||
<?xml version='1.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.
|
||||
-->
|
||||
|
||||
<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.activemq.examples.modules</groupId>
|
||||
<artifactId>broker-modules</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<endpoint />
|
||||
<applicationid />
|
||||
<mastersecret />
|
||||
<activemq.basedir>${project.basedir}/../../../..</activemq.basedir>
|
||||
</properties>
|
||||
|
||||
<artifactId>aerogear</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>ActiveMQ Artemis JMS AeroGear Example</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>artemis-cli</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>artemis-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>create</id>
|
||||
<goals>
|
||||
<goal>create</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<ignore>${noServer}</ignore>
|
||||
<!-- this list was extracted from mvn dependency:tree on integration/aerogear -->
|
||||
<libListWithDeps>
|
||||
<param>org.apache.activemq:artemis-aerogear-integration:${project.version}</param>
|
||||
</libListWithDeps>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>start</id>
|
||||
<goals>
|
||||
<goal>cli</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<ignore>${noServer}</ignore>
|
||||
<spawn>true</spawn>
|
||||
<testURI>tcp://localhost:61616</testURI>
|
||||
<args>
|
||||
<param>run</param>
|
||||
</args>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>runClient</id>
|
||||
<goals>
|
||||
<goal>runClient</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<clientClass>org.apache.activemq.artemis.jms.example.AerogearExample</clientClass>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>stop</id>
|
||||
<goals>
|
||||
<goal>cli</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<ignore>${noServer}</ignore>
|
||||
<args>
|
||||
<param>stop</param>
|
||||
</args>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq.examples.modules</groupId>
|
||||
<artifactId>aerogear</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -1,157 +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>ActiveMQ Artemis JMS AeroGear Example</title>
|
||||
<link rel="stylesheet" type="text/css" href="../../../common/common.css" />
|
||||
<link rel="stylesheet" type="text/css" href="../../../common/prettify.css" />
|
||||
<script type="text/javascript" src="../../../common/prettify.js"></script>
|
||||
</head>
|
||||
<body onload="prettyPrint()">
|
||||
<h1>JMS AeroGear Example</h1>
|
||||
|
||||
|
||||
<pre>To run the example, simply type <b>mvn verify</b> from this directory, <br>or <b>mvn -PnoServer verify</b> if you want to start and create the server manually.</pre>
|
||||
|
||||
<p>This example shows how you can send a message to a mobile device by leveraging <a href="http://aerogear.org/push/">AeroGears push</a> technology which
|
||||
provides support for different push notification technologies like Google Cloud Messaging, Apple's APNs or
|
||||
Mozilla's SimplePush.</p>
|
||||
|
||||
<p>For this example you will need an AeroGear Application running somewhere, a good way to do this is to deploy the
|
||||
Push Application on <href a="">openshift</href>, you can follow the AeroGear Push 0.X Quickstart.</p>
|
||||
|
||||
<p>Once you have created your AeroGear Push Application you can create a mobile application. Simply log into the application
|
||||
on the web and create a new mobile application by clicking the 'create' button. Once created you will see an application id
|
||||
and a master secret, you will need the later to run the example.</p>
|
||||
|
||||
<p>lastly you will need to create a variant. For this example we will be using Android so you will need to create a google project,
|
||||
this <a href="http://aerogear.org/docs/guides/aerogear-push-android/google-setup/">article</a> explains how to do this.
|
||||
Once created click on your app then click 'add' to add a variant. choose 'google cloud messaging', enter your google
|
||||
API key and the project number from your google project and click create</p>
|
||||
|
||||
<p>Now before we run the example we need a mobile application to receive it. Writing a mobile app is beyond the scope
|
||||
of this example but for testing purposes we have supplied an Android app you can use, simply install on your android phone.
|
||||
It can be found <a href="http://downloads.jboss.org/hornetq/HornetQAeroGear.apk">here</a>. For a more in depth mobile
|
||||
app example visit the AeroGear site.</p>
|
||||
|
||||
<p>Once you have installed the mobile app you will need to configure the following:</p>
|
||||
<p>AeroGear Unified Push URL : This is the URL where your aerogear server is running, something like http://myapp-mydomain.rhcloud.com
|
||||
AeroGear Variant ID : This is the ID of the variant you created in AeroGear
|
||||
AeroGear Variant Secret : This is the secret for your variant
|
||||
GCM Sender ID : this is the Google project Number you created on Google
|
||||
Variant : you can use this to target messages if needed.
|
||||
</p>
|
||||
|
||||
<p>Once you set all these correctly you should get a message saying your mobile app is registered, if you log into
|
||||
your AeroGear app you should see it registered with the variant.</p>
|
||||
|
||||
|
||||
<p>Now to run the example simply run the following command
|
||||
'mvn -Dendpoint=my aerogear url -Dapplicationid=my application id -Dmastersecret=my master secret -Djsse.enableSNIExtension=false clean verify'.
|
||||
If you arent using java 7 you can omit the 'jsse.enableSNIExtension=false'</p>
|
||||
|
||||
<p>You should see something like this in your ActiveMQServer</p>
|
||||
<ol>
|
||||
<pre class="prettyprint">
|
||||
<code>
|
||||
Dec 04, 2013 3:25:39 PM org.jboss.aerogear.unifiedpush.SenderClient submitPayload
|
||||
INFO: HTTP Response code from UnifiedPush Server: 302
|
||||
Dec 04, 2013 3:25:39 PM org.jboss.aerogear.unifiedpush.SenderClient submitPayload
|
||||
INFO: Performing redirect to 'https://myapp-mydomain.rhcloud.com/rest/sender/'
|
||||
Dec 04, 2013 3:25:40 PM org.jboss.aerogear.unifiedpush.SenderClient submitPayload
|
||||
INFO: HTTP Response code from UnifiedPush Server: 200
|
||||
</code>
|
||||
</pre>
|
||||
</ol>
|
||||
<p>And on your mobile app you should see a message from ActiveMQ</p>
|
||||
|
||||
<p>Now lets look a bit more closely at the configuration in broker.xml</p>
|
||||
<ol>
|
||||
<pre class="prettyprint">
|
||||
<code>
|
||||
<queues>
|
||||
<queue name="jms.queue.exampleQueue">
|
||||
<address>jms.queue.exampleQueue</address>
|
||||
</queue>
|
||||
</queues>
|
||||
|
||||
<connector-services>
|
||||
<connector-service name="aerogear-connector">
|
||||
<factory-class>org.apache.activemq.integration.aerogear.AeroGearConnectorServiceFactory</factory-class>
|
||||
<param key="endpoint" value="${endpoint}"/>
|
||||
<param key="queue" value="jms.queue.exampleQueue"/>
|
||||
<param key="application-id" value="${applicationid}"/>
|
||||
<param key="master-secret" value="${mastersecret}"/>
|
||||
</connector-service>
|
||||
</connector-services>
|
||||
</code>
|
||||
</pre>
|
||||
</ol>
|
||||
<p>Firstly you will see that we have to create a core queue so it is available when the connector is started, the following are mandatory parameters:</p>
|
||||
<ol>
|
||||
<li>endpoint - The endpoint or URL of you AeroGear application</li>
|
||||
<li>queue - The name of the queue to consume from</li>
|
||||
<li>application-id - The application id of your mobile application in AeroGear</li>
|
||||
<li>master-secret - the secret of your mobile application in AeroGear</li>
|
||||
</ol>
|
||||
<p>as well as those there are also the following optional parameters</p>
|
||||
<ol>
|
||||
<li>ttl - The time to live for the message once AeroGear receives it</li>
|
||||
<li>badge - The badge the mobile app should use for the notification</li>
|
||||
<li>sound - The sound the mobile app should use for the notification</li>
|
||||
<li>filter - A message filter(selector) to use on the connector</li>
|
||||
<li>retry-interval - If an error occurs on send, how long before we try again</li>
|
||||
<li>retry-attempts - How many times we should try to reconnect after an error</li>
|
||||
<li>variants - A comma separated list of variants that should get the message</li>
|
||||
<li>aliases - A list of aliases that should get the message</li>
|
||||
<li>device-types - A list of device types that should get the message</li>
|
||||
</ol>
|
||||
<p>More in depth explanations of these can be found in the AeroGear docs.</p>
|
||||
<p>Now lets look at a snippet of code we used to send the message for our JMS client</p>
|
||||
<pre class="prettyprint">
|
||||
<code>
|
||||
Queue queue = (Queue)initialContext.lookup("queue/exampleQueue");
|
||||
|
||||
// Step 3. Perform a lookup on the Connection Factory
|
||||
ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
|
||||
|
||||
// Step 4.Create a JMS Connection
|
||||
connection = cf.createConnection();
|
||||
|
||||
// Step 5. Create a JMS Session
|
||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
|
||||
// Step 6. Create a JMS Message Producer
|
||||
MessageProducer producer = session.createProducer(queue);
|
||||
|
||||
// Step 7. Create a Text Message
|
||||
Message message = session.createMessage();
|
||||
|
||||
message.setStringProperty("AEROGEAR_ALERT", "Hello this is a notification from ActiveMQ");
|
||||
|
||||
producer.send(message);
|
||||
</code>
|
||||
</pre>
|
||||
<p> The most important thing here is string propert we have set on the message, i.e. 'AEROGEAR_ALERT'. This is the
|
||||
actual alert that is sent via AeroGear</p>
|
||||
<p>As well as the alert itself you can override any of the above optional parameters in the same fashionby using the
|
||||
following propert names: AEROGEAR_SOUND,AEROGEAR_BADGE,AEROGEAR_TTL,AEROGEAR_VARIANTS,AEROGEAR_ALIASES and AEROGEAR_DEVICE_TYPES</p>
|
||||
</body>
|
||||
</html>
|
|
@ -1,76 +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.
|
||||
*/
|
||||
package org.apache.activemq.artemis.jms.example;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.Queue;
|
||||
import javax.jms.Session;
|
||||
import javax.naming.InitialContext;
|
||||
|
||||
/**
|
||||
* A simple JMS Queue example that creates a producer and consumer on a queue and sends then receives a message.
|
||||
*/
|
||||
public class AerogearExample {
|
||||
|
||||
public static void main(final String[] args) throws Exception {
|
||||
Connection connection = null;
|
||||
InitialContext initialContext = null;
|
||||
try {
|
||||
// Step 1. Create an initial context to perform the JNDI lookup.
|
||||
initialContext = new InitialContext();
|
||||
|
||||
// Step 2. Perfom a lookup on the queue
|
||||
Queue queue = (Queue) initialContext.lookup("queue/exampleQueue");
|
||||
|
||||
// Step 3. Perform a lookup on the Connection Factory
|
||||
ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("ConnectionFactory");
|
||||
|
||||
// Step 4.Create a JMS Connection
|
||||
connection = cf.createConnection();
|
||||
|
||||
// Step 5. Create a JMS Session
|
||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
|
||||
// Step 6. Create a JMS Message Producer
|
||||
MessageProducer producer = session.createProducer(queue);
|
||||
|
||||
// Step 7. Create a Text Message
|
||||
Message message = session.createMessage();
|
||||
|
||||
message.setStringProperty("AEROGEAR_ALERT", "Hello this is a notification from ActiveMQ");
|
||||
|
||||
producer.send(message);
|
||||
|
||||
System.out.println("Sent message");
|
||||
|
||||
System.out.println("now check your mobile app and press enter");
|
||||
|
||||
System.in.read();
|
||||
} finally {
|
||||
// Step 12. Be sure to close our JMS resources!
|
||||
if (initialContext != null) {
|
||||
initialContext.close();
|
||||
}
|
||||
if (connection != null) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!--
|
||||
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.
|
||||
--><configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd">
|
||||
|
||||
|
||||
|
||||
<core xmlns="urn:activemq:core">
|
||||
|
||||
<bindings-directory>./data/bindings</bindings-directory>
|
||||
|
||||
<journal-directory>./data/journal</journal-directory>
|
||||
|
||||
<large-messages-directory>./data/largemessages</large-messages-directory>
|
||||
|
||||
<paging-directory>./data/paging</paging-directory>
|
||||
|
||||
<!-- Acceptors -->
|
||||
<acceptors>
|
||||
<acceptor name="netty-acceptor">tcp://localhost:61616</acceptor>
|
||||
</acceptors>
|
||||
|
||||
<!-- We need to create a core queue for the JMS queue explicitly because the connector will be deployed
|
||||
before the JMS queue is deployed, so the first time, it otherwise won't find the queue -->
|
||||
|
||||
|
||||
<connector-services>
|
||||
<connector-service name="aerogear-connector">
|
||||
<factory-class>org.apache.activemq.artemis.integration.aerogear.AeroGearConnectorServiceFactory</factory-class>
|
||||
<param key="endpoint" value="${endpoint}"/>
|
||||
<param key="queue" value="exampleQueue"/>
|
||||
<param key="application-id" value="${applicationid}"/>
|
||||
<param key="master-secret" value="${mastersecret}"/>
|
||||
</connector-service>
|
||||
</connector-services>
|
||||
|
||||
<!-- Other config -->
|
||||
|
||||
<security-settings>
|
||||
<!--security for example queue-->
|
||||
<security-setting match="exampleQueue">
|
||||
<permission roles="guest" type="createDurableQueue"/>
|
||||
<permission roles="guest" type="deleteDurableQueue"/>
|
||||
<permission roles="guest" type="createNonDurableQueue"/>
|
||||
<permission roles="guest" type="deleteNonDurableQueue"/>
|
||||
<permission roles="guest" type="consume"/>
|
||||
<permission roles="guest" type="send"/>
|
||||
</security-setting>
|
||||
</security-settings>
|
||||
<addresses>
|
||||
<address name="exampleQueue">
|
||||
<multicast>
|
||||
<queue name="exampleQueue"/>
|
||||
</multicast>
|
||||
<anycast>
|
||||
<queue name="jms.queue.exampleQueue"/>
|
||||
</anycast>
|
||||
</address>
|
||||
</addresses>
|
||||
</core>
|
||||
</configuration>
|
|
@ -1,20 +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.
|
||||
|
||||
java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory
|
||||
connectionFactory.ConnectionFactory=tcp://localhost:61616
|
||||
queue.queue/exampleQueue=exampleQueue
|
|
@ -49,7 +49,6 @@ under the License.
|
|||
<profile>
|
||||
<id>release</id>
|
||||
<modules>
|
||||
<module>aerogear</module>
|
||||
<module>artemis-ra-rar</module>
|
||||
</modules>
|
||||
</profile>
|
||||
|
|
|
@ -1,102 +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.
|
||||
*/
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Helvetica Neue', Helvetica, Verdana, Arial, sans-serif;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
#disconnect {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#unsubscribe {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#subscribe {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#debug {
|
||||
background-color: #F0F0F0;
|
||||
font-size: 12px;
|
||||
height: 75%;
|
||||
overflow: auto;
|
||||
padding: 10px;
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
top: 10px;
|
||||
width: 250px;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#send_form {
|
||||
bottom: 5px;
|
||||
position: absolute;
|
||||
width: 99%;
|
||||
}
|
||||
|
||||
#send_form #send_form_input {
|
||||
border: 1px solid #CCC;
|
||||
font-size: 16px;
|
||||
height: 20px;
|
||||
padding: 5px;
|
||||
width: 98%;
|
||||
}
|
||||
|
||||
#send_form input[disabled] {
|
||||
background-color: #EEE;
|
||||
}
|
||||
|
||||
#messages {
|
||||
bottom: 25px;
|
||||
left: 0;
|
||||
overflow: auto;
|
||||
padding: 5px;
|
||||
right: 0;
|
||||
top: 2em;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
.message {
|
||||
width: 95%;
|
||||
}
|
||||
|
||||
form dt {
|
||||
clear:both;
|
||||
width:19%;
|
||||
float:left;
|
||||
text-align:right;
|
||||
}
|
||||
|
||||
form dd {
|
||||
float:left;
|
||||
width:80%;
|
||||
margin:0 0 0.5em 0.25em;
|
||||
}
|
||||
|
||||
input {
|
||||
width: 320px;
|
||||
}
|
|
@ -1,116 +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.
|
||||
*/
|
||||
|
||||
$( document ).ready( function () {
|
||||
|
||||
var client,
|
||||
destination;
|
||||
|
||||
$( '#connect_form' ).submit( function ( e ) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
var url = $( '#connect_url' ).val(),
|
||||
loginName = $( '#connect_login' ).val(),
|
||||
passcode = $( '#connect_passcode' ).val();
|
||||
|
||||
destination = $( '#destination' ).val();
|
||||
|
||||
client = AeroGear.Notifier({
|
||||
name: 'stomp',
|
||||
type: 'stompws',
|
||||
settings: {
|
||||
connectURL: url
|
||||
}
|
||||
}).clients.stomp;
|
||||
|
||||
var debug = function ( str ) {
|
||||
$( '#debug' ).append( str + "\n" );
|
||||
},
|
||||
onconnect = function () {
|
||||
debug( 'connected to Stomp');
|
||||
$( '#connect' ).fadeOut({
|
||||
duration: 'fast'
|
||||
});
|
||||
$( '#disconnect' ).fadeIn();
|
||||
$( '#send_form_input' ).removeAttr( 'disabled' );
|
||||
$( '#unsubscribe' ).fadeIn();
|
||||
|
||||
client.debug( debug );
|
||||
|
||||
var onsubscribe = function ( message ) {
|
||||
$( '#messages' ).append( "<p>" + message.body + "</p>\n" );
|
||||
};
|
||||
|
||||
client.subscribe({
|
||||
address: destination,
|
||||
callback: onsubscribe
|
||||
});
|
||||
};
|
||||
|
||||
client.connect({
|
||||
login: loginName,
|
||||
password: passcode,
|
||||
onConnect: onconnect
|
||||
});
|
||||
});
|
||||
|
||||
$( '#disconnect_form' ).submit( function ( e ) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
var ondisconnect = function () {
|
||||
$( '#disconnect' ).fadeOut({
|
||||
duration: 'fast'
|
||||
});
|
||||
$( '#unsubscribe' ).fadeOut({
|
||||
duration: 'fast'
|
||||
});
|
||||
$( '#connect' ).fadeIn();
|
||||
$( '#send_form_input' ).attr( 'disabled', 'disabled' );
|
||||
$( '#messages' ).empty();
|
||||
$( '#debug' ).empty();
|
||||
};
|
||||
|
||||
client.disconnect( ondisconnect );
|
||||
});
|
||||
|
||||
$( '#unsubscribe_form' ).submit( function ( e ) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
client.unsubscribe( [{ address: destination }] );
|
||||
|
||||
$( '#unsubscribe' ).fadeOut({
|
||||
duration: 'fast'
|
||||
});
|
||||
});
|
||||
|
||||
$( '#send_form' ).submit( function ( e ) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
var text = $( '#send_form_input' ).val();
|
||||
if (text) {
|
||||
client.send( destination, text );
|
||||
$('#send_form_input').val( '' );
|
||||
}
|
||||
});
|
||||
|
||||
});
|
|
@ -1,97 +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.
|
||||
-->
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Chat Example Using Stomp Over Web Sockets</title>
|
||||
<link rel="stylesheet" href="aerogear-chat.css" />
|
||||
<script src='http://code.jquery.com/jquery-1.9.1.min.js'></script>
|
||||
<script src='stomp.js'></script>
|
||||
<script src='aerogear.min.js'></script>
|
||||
<script src='aerogear-chat.js'></script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
var supported = ("WebSocket" in window);
|
||||
if(!supported) {
|
||||
var msg = "Your browser does not support Web Sockets. This example will not work properly.<br>";
|
||||
msg += "Please use a Web Browser with Web Sockets support (WebKit or Google Chrome).";
|
||||
$("#connect").html(msg);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id='connect'>
|
||||
<form id='connect_form'>
|
||||
<dl>
|
||||
<dt>
|
||||
<label for=connect_url>Server URL</label>
|
||||
</dt>
|
||||
<dd>
|
||||
<input name=url id='connect_url' value='ws://localhost:61614/stomp'>
|
||||
</dd>
|
||||
<dt>
|
||||
<label for=connect_login>Login</label>
|
||||
</dt>
|
||||
<dd>
|
||||
<input id='connect_login' placeholder="User Login" value="guest">
|
||||
</dd>
|
||||
<dt>
|
||||
<label for=connect_passcode>Password</label>
|
||||
</dt>
|
||||
<dd>
|
||||
<input id='connect_passcode' type=password placeholder="User Password" value="guest">
|
||||
</dd>
|
||||
<dt>
|
||||
<label for=destination>Destination</label>
|
||||
</dt>
|
||||
<dd>
|
||||
<input id='destination' placeholder="Destination" value="jms.topic.chat">
|
||||
</dd>
|
||||
<dt> </dt>
|
||||
<dd>
|
||||
<input type="submit" id='connect_submit' value="Connect">
|
||||
</dd>
|
||||
</dl>
|
||||
</form>
|
||||
|
||||
<p>Use the form above to connect to the Stomp server and subscribe to the destination.</p>
|
||||
<p>Once connected, you can send messages to the destination with the text field at the bottom of this page</p>
|
||||
</div>
|
||||
<div id="disconnect">
|
||||
<form id='disconnect_form'>
|
||||
<input type="submit" id='disconnect_submit' value="Disconnect">
|
||||
</form>
|
||||
</div>
|
||||
<div id="unsubscribe">
|
||||
<form id='unsubscribe_form'>
|
||||
<input type="submit" id='unsubscribe_submit' value="Unsubscribe">
|
||||
</form>
|
||||
</div>
|
||||
<pre id="debug"></pre>
|
||||
<div id="messages"></div>
|
||||
<form id='send_form'>
|
||||
<input id='send_form_input' placeholder="Type your message here" disabled />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
File diff suppressed because one or more lines are too long
|
@ -1,392 +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.
|
||||
*/
|
||||
|
||||
// Generated by CoffeeScript 1.4.0
|
||||
(function() {
|
||||
var Byte, Client, Frame, Stomp,
|
||||
__hasProp = {}.hasOwnProperty;
|
||||
|
||||
Byte = {
|
||||
LF: '\x0A',
|
||||
NULL: '\x00'
|
||||
};
|
||||
|
||||
Frame = (function() {
|
||||
|
||||
function Frame(command, headers, body) {
|
||||
this.command = command;
|
||||
this.headers = headers != null ? headers : {};
|
||||
this.body = body != null ? body : '';
|
||||
}
|
||||
|
||||
Frame.prototype.toString = function() {
|
||||
var lines, name, value, _ref;
|
||||
lines = [this.command];
|
||||
_ref = this.headers;
|
||||
for (name in _ref) {
|
||||
if (!__hasProp.call(_ref, name)) continue;
|
||||
value = _ref[name];
|
||||
lines.push("" + name + ":" + value);
|
||||
}
|
||||
if (this.body) {
|
||||
lines.push("content-length:" + ('' + this.body).length);
|
||||
}
|
||||
lines.push(Byte.LF + this.body);
|
||||
return lines.join(Byte.LF);
|
||||
};
|
||||
|
||||
Frame._unmarshallSingle = function(data) {
|
||||
var body, chr, command, divider, headerLines, headers, i, idx, len, line, start, trim, _i, _j, _ref, _ref1;
|
||||
divider = data.search(RegExp("" + Byte.LF + Byte.LF));
|
||||
headerLines = data.substring(0, divider).split(Byte.LF);
|
||||
command = headerLines.shift();
|
||||
headers = {};
|
||||
trim = function(str) {
|
||||
return str.replace(/^\s+|\s+$/g, '');
|
||||
};
|
||||
line = idx = null;
|
||||
for (i = _i = 0, _ref = headerLines.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
|
||||
line = headerLines[i];
|
||||
idx = line.indexOf(':');
|
||||
headers[trim(line.substring(0, idx))] = trim(line.substring(idx + 1));
|
||||
}
|
||||
body = '';
|
||||
start = divider + 2;
|
||||
if (headers['content-length']) {
|
||||
len = parseInt(headers['content-length']);
|
||||
body = ('' + data).substring(start, start + len);
|
||||
} else {
|
||||
chr = null;
|
||||
for (i = _j = start, _ref1 = data.length; start <= _ref1 ? _j < _ref1 : _j > _ref1; i = start <= _ref1 ? ++_j : --_j) {
|
||||
chr = data.charAt(i);
|
||||
if (chr === Byte.NULL) {
|
||||
break;
|
||||
}
|
||||
body += chr;
|
||||
}
|
||||
}
|
||||
return new Frame(command, headers, body);
|
||||
};
|
||||
|
||||
Frame.unmarshall = function(datas) {
|
||||
var data;
|
||||
return (function() {
|
||||
var _i, _len, _ref, _results;
|
||||
_ref = datas.split(RegExp("" + Byte.NULL + Byte.LF + "*"));
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
data = _ref[_i];
|
||||
if ((data != null ? data.length : void 0) > 0) {
|
||||
_results.push(Frame._unmarshallSingle(data));
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
};
|
||||
|
||||
Frame.marshall = function(command, headers, body) {
|
||||
var frame;
|
||||
frame = new Frame(command, headers, body);
|
||||
return frame.toString() + Byte.NULL;
|
||||
};
|
||||
|
||||
return Frame;
|
||||
|
||||
})();
|
||||
|
||||
Client = (function() {
|
||||
|
||||
function Client(ws) {
|
||||
this.ws = ws;
|
||||
this.ws.binaryType = "arraybuffer";
|
||||
this.counter = 0;
|
||||
this.connected = false;
|
||||
this.heartbeat = {
|
||||
outgoing: 10000,
|
||||
incoming: 10000
|
||||
};
|
||||
this.subscriptions = {};
|
||||
}
|
||||
|
||||
Client.prototype._transmit = function(command, headers, body) {
|
||||
var out;
|
||||
out = Frame.marshall(command, headers, body);
|
||||
if (typeof this.debug === "function") {
|
||||
this.debug(">>> " + out);
|
||||
}
|
||||
return this.ws.send(out);
|
||||
};
|
||||
|
||||
Client.prototype._setupHeartbeat = function(headers) {
|
||||
var serverIncoming, serverOutgoing, ttl, v, _ref, _ref1,
|
||||
_this = this;
|
||||
if ((_ref = headers.version) !== Stomp.VERSIONS.V1_1 && _ref !== Stomp.VERSIONS.V1_2) {
|
||||
return;
|
||||
}
|
||||
_ref1 = (function() {
|
||||
var _i, _len, _ref1, _results;
|
||||
_ref1 = headers['heart-beat'].split(",");
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
v = _ref1[_i];
|
||||
_results.push(parseInt(v));
|
||||
}
|
||||
return _results;
|
||||
})(), serverOutgoing = _ref1[0], serverIncoming = _ref1[1];
|
||||
if (!(this.heartbeat.outgoing === 0 || serverIncoming === 0)) {
|
||||
ttl = Math.max(this.heartbeat.outgoing, serverIncoming);
|
||||
if (typeof this.debug === "function") {
|
||||
this.debug("send PING every " + ttl + "ms");
|
||||
}
|
||||
this.pinger = typeof window !== "undefined" && window !== null ? window.setInterval(function() {
|
||||
_this.ws.send(Byte.LF);
|
||||
return typeof _this.debug === "function" ? _this.debug(">>> PING") : void 0;
|
||||
}, ttl) : void 0;
|
||||
}
|
||||
if (!(this.heartbeat.incoming === 0 || serverOutgoing === 0)) {
|
||||
ttl = Math.max(this.heartbeat.incoming, serverOutgoing);
|
||||
if (typeof this.debug === "function") {
|
||||
this.debug("check PONG every " + ttl + "ms");
|
||||
}
|
||||
return this.ponger = typeof window !== "undefined" && window !== null ? window.setInterval(function() {
|
||||
var delta;
|
||||
delta = Date.now() - _this.serverActivity;
|
||||
if (delta > ttl * 2) {
|
||||
if (typeof _this.debug === "function") {
|
||||
_this.debug("did not receive server activity for the last " + delta + "ms");
|
||||
}
|
||||
return _this.ws.close();
|
||||
}
|
||||
}, ttl) : void 0;
|
||||
}
|
||||
};
|
||||
|
||||
Client.prototype.connect = function(login, passcode, connectCallback, errorCallback, vhost) {
|
||||
var _this = this;
|
||||
this.connectCallback = connectCallback;
|
||||
if (typeof this.debug === "function") {
|
||||
this.debug("Opening Web Socket...");
|
||||
}
|
||||
this.ws.onmessage = function(evt) {
|
||||
var arr, c, data, frame, onreceive, _i, _len, _ref, _results;
|
||||
data = typeof ArrayBuffer !== 'undefined' && evt.data instanceof ArrayBuffer ? (arr = new Uint8Array(evt.data), typeof _this.debug === "function" ? _this.debug("--- got data length: " + arr.length) : void 0, ((function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = arr.length; _i < _len; _i++) {
|
||||
c = arr[_i];
|
||||
_results.push(String.fromCharCode(c));
|
||||
}
|
||||
return _results;
|
||||
})()).join('')) : evt.data;
|
||||
_this.serverActivity = Date.now();
|
||||
if (data === Byte.LF) {
|
||||
if (typeof _this.debug === "function") {
|
||||
_this.debug("<<< PONG");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (typeof _this.debug === "function") {
|
||||
_this.debug("<<< " + data);
|
||||
}
|
||||
_ref = Frame.unmarshall(data);
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
frame = _ref[_i];
|
||||
switch (frame.command) {
|
||||
case "CONNECTED":
|
||||
if (typeof _this.debug === "function") {
|
||||
_this.debug("connected to server " + frame.headers.server);
|
||||
}
|
||||
_this.connected = true;
|
||||
_this._setupHeartbeat(frame.headers);
|
||||
_results.push(typeof _this.connectCallback === "function" ? _this.connectCallback(frame) : void 0);
|
||||
break;
|
||||
case "MESSAGE":
|
||||
onreceive = _this.subscriptions[frame.headers.subscription];
|
||||
_results.push(typeof onreceive === "function" ? onreceive(frame) : void 0);
|
||||
break;
|
||||
case "RECEIPT":
|
||||
_results.push(typeof _this.onreceipt === "function" ? _this.onreceipt(frame) : void 0);
|
||||
break;
|
||||
case "ERROR":
|
||||
_results.push(typeof errorCallback === "function" ? errorCallback(frame) : void 0);
|
||||
break;
|
||||
default:
|
||||
_results.push(typeof _this.debug === "function" ? _this.debug("Unhandled frame: " + frame) : void 0);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
this.ws.onclose = function() {
|
||||
var msg;
|
||||
msg = "Whoops! Lost connection to " + _this.ws.url;
|
||||
if (typeof _this.debug === "function") {
|
||||
_this.debug(msg);
|
||||
}
|
||||
_this._cleanUp();
|
||||
return typeof errorCallback === "function" ? errorCallback(msg) : void 0;
|
||||
};
|
||||
return this.ws.onopen = function() {
|
||||
var headers;
|
||||
if (typeof _this.debug === "function") {
|
||||
_this.debug('Web Socket Opened...');
|
||||
}
|
||||
headers = {
|
||||
"accept-version": Stomp.VERSIONS.supportedVersions(),
|
||||
"heart-beat": [_this.heartbeat.outgoing, _this.heartbeat.incoming].join(',')
|
||||
};
|
||||
if (vhost) {
|
||||
headers.host = vhost;
|
||||
}
|
||||
if (login) {
|
||||
headers.login = login;
|
||||
}
|
||||
if (passcode) {
|
||||
headers.passcode = passcode;
|
||||
}
|
||||
return _this._transmit("CONNECT", headers);
|
||||
};
|
||||
};
|
||||
|
||||
Client.prototype.disconnect = function(disconnectCallback) {
|
||||
this._transmit("DISCONNECT");
|
||||
this.ws.onclose = null;
|
||||
this.ws.close();
|
||||
this._cleanUp();
|
||||
return typeof disconnectCallback === "function" ? disconnectCallback() : void 0;
|
||||
};
|
||||
|
||||
Client.prototype._cleanUp = function() {
|
||||
this.connected = false;
|
||||
if (this.pinger) {
|
||||
if (typeof window !== "undefined" && window !== null) {
|
||||
window.clearInterval(this.pinger);
|
||||
}
|
||||
}
|
||||
if (this.ponger) {
|
||||
return typeof window !== "undefined" && window !== null ? window.clearInterval(this.ponger) : void 0;
|
||||
}
|
||||
};
|
||||
|
||||
Client.prototype.send = function(destination, headers, body) {
|
||||
if (headers == null) {
|
||||
headers = {};
|
||||
}
|
||||
if (body == null) {
|
||||
body = '';
|
||||
}
|
||||
headers.destination = destination;
|
||||
return this._transmit("SEND", headers, body);
|
||||
};
|
||||
|
||||
Client.prototype.subscribe = function(destination, callback, headers) {
|
||||
if (headers == null) {
|
||||
headers = {};
|
||||
}
|
||||
if (!headers.id) {
|
||||
headers.id = "sub-" + this.counter++;
|
||||
}
|
||||
headers.destination = destination;
|
||||
this.subscriptions[headers.id] = callback;
|
||||
this._transmit("SUBSCRIBE", headers);
|
||||
return headers.id;
|
||||
};
|
||||
|
||||
Client.prototype.unsubscribe = function(id) {
|
||||
delete this.subscriptions[id];
|
||||
return this._transmit("UNSUBSCRIBE", {
|
||||
id: id
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.begin = function(transaction) {
|
||||
return this._transmit("BEGIN", {
|
||||
transaction: transaction
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.commit = function(transaction) {
|
||||
return this._transmit("COMMIT", {
|
||||
transaction: transaction
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.abort = function(transaction) {
|
||||
return this._transmit("ABORT", {
|
||||
transaction: transaction
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.ack = function(messageID, subscription, headers) {
|
||||
if (headers == null) {
|
||||
headers = {};
|
||||
}
|
||||
headers["message-id"] = messageID;
|
||||
headers.subscription = subscription;
|
||||
return this._transmit("ACK", headers);
|
||||
};
|
||||
|
||||
Client.prototype.nack = function(messageID, subscription, headers) {
|
||||
if (headers == null) {
|
||||
headers = {};
|
||||
}
|
||||
headers["message-id"] = messageID;
|
||||
headers.subscription = subscription;
|
||||
return this._transmit("NACK", headers);
|
||||
};
|
||||
|
||||
return Client;
|
||||
|
||||
})();
|
||||
|
||||
Stomp = {
|
||||
libVersion: "2.0.0-next",
|
||||
VERSIONS: {
|
||||
V1_0: '1.0',
|
||||
V1_1: '1.1',
|
||||
V1_2: '1.2',
|
||||
supportedVersions: function() {
|
||||
return '1.1,1.0';
|
||||
}
|
||||
},
|
||||
client: function(url, protocols) {
|
||||
var klass, ws;
|
||||
if (protocols == null) {
|
||||
protocols = ['v10.stomp', 'v11.stomp'];
|
||||
}
|
||||
klass = Stomp.WebSocketClass || WebSocket;
|
||||
ws = new klass(url, protocols);
|
||||
return new Client(ws);
|
||||
},
|
||||
over: function(ws) {
|
||||
return new Client(ws);
|
||||
},
|
||||
Frame: Frame
|
||||
};
|
||||
|
||||
if (typeof window !== "undefined" && window !== null) {
|
||||
window.Stomp = Stomp;
|
||||
} else if (typeof exports !== "undefined" && exports !== null) {
|
||||
exports.Stomp = Stomp;
|
||||
Stomp.WebSocketClass = require('./test/server.mock.js').StompServerMock;
|
||||
} else {
|
||||
self.Stomp = Stomp;
|
||||
}
|
||||
|
||||
}).call(this);
|
|
@ -1,75 +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.
|
||||
-->
|
||||
<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.activemq</groupId>
|
||||
<artifactId>artemis-pom</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>artemis-aerogear-integration</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>ActiveMQ Artemis Aerogear Integration</name>
|
||||
|
||||
<properties>
|
||||
<activemq.basedir>${project.basedir}/../..</activemq.basedir>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jboss.logging</groupId>
|
||||
<artifactId>jboss-logging-processor</artifactId>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!--
|
||||
JBoss Logging
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.jboss.logging</groupId>
|
||||
<artifactId>jboss-logging</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>artemis-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jboss.aerogear</groupId>
|
||||
<artifactId>unifiedpush-java-client</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<!-- RestEasy's Jackson Plugin -->
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-jackson-provider</artifactId>
|
||||
<version>2.3.2.Final</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.jboss.spec.javax.annotation</groupId>
|
||||
<artifactId>jboss-annotations-api_1.1_spec</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -1,47 +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.
|
||||
*/
|
||||
package org.apache.activemq.artemis.integration.aerogear;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException;
|
||||
import org.jboss.logging.Messages;
|
||||
import org.jboss.logging.annotations.Message;
|
||||
import org.jboss.logging.annotations.MessageBundle;
|
||||
|
||||
/**
|
||||
* Logger Code 23
|
||||
* <br>
|
||||
* each message id must be 6 digits long starting with 10, the 3rd digit should be 9
|
||||
* <br>
|
||||
* so 239000 to 239999
|
||||
*/
|
||||
@MessageBundle(projectCode = "AMQ")
|
||||
public interface ActiveMQAeroGearBundle {
|
||||
|
||||
ActiveMQAeroGearBundle BUNDLE = Messages.getBundle(ActiveMQAeroGearBundle.class);
|
||||
|
||||
@Message(id = 239000, value = "endpoint can not be null")
|
||||
ActiveMQIllegalStateException endpointNull();
|
||||
|
||||
@Message(id = 239001, value = "application-id can not be null")
|
||||
ActiveMQIllegalStateException applicationIdNull();
|
||||
|
||||
@Message(id = 239002, value = "master-secret can not be null")
|
||||
ActiveMQIllegalStateException masterSecretNull();
|
||||
|
||||
@Message(id = 239003, value = "{0}: queue {1} not found", format = Message.Format.MESSAGE_FORMAT)
|
||||
ActiveMQIllegalStateException noQueue(String connectorName, String queueName);
|
||||
}
|
|
@ -1,70 +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.
|
||||
*/
|
||||
package org.apache.activemq.artemis.integration.aerogear;
|
||||
|
||||
import org.jboss.logging.BasicLogger;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.jboss.logging.annotations.LogMessage;
|
||||
import org.jboss.logging.annotations.Message;
|
||||
import org.jboss.logging.annotations.MessageLogger;
|
||||
|
||||
/**
|
||||
* Logger Code 23
|
||||
*
|
||||
* each message id must be 6 digits long starting with 18, the 3rd digit donates the level so
|
||||
*
|
||||
* INF0 1
|
||||
* WARN 2
|
||||
* DEBUG 3
|
||||
* ERROR 4
|
||||
* TRACE 5
|
||||
* FATAL 6
|
||||
*
|
||||
* so an INFO message would be 181000 to 181999
|
||||
*/
|
||||
@MessageLogger(projectCode = "AMQ")
|
||||
public interface ActiveMQAeroGearLogger extends BasicLogger {
|
||||
|
||||
/**
|
||||
* The aerogear logger.
|
||||
*/
|
||||
ActiveMQAeroGearLogger LOGGER = Logger.getMessageLogger(ActiveMQAeroGearLogger.class, ActiveMQAeroGearLogger.class.getPackage().getName());
|
||||
|
||||
@LogMessage(level = Logger.Level.INFO)
|
||||
@Message(id = 231001, value = "aerogear connector connected to {0}", format = Message.Format.MESSAGE_FORMAT)
|
||||
void connected(String endpoint);
|
||||
|
||||
@LogMessage(level = Logger.Level.WARN)
|
||||
@Message(id = 232003, value = "removing aerogear connector as credentials are invalid", format = Message.Format.MESSAGE_FORMAT)
|
||||
void reply401();
|
||||
|
||||
@LogMessage(level = Logger.Level.WARN)
|
||||
@Message(id = 232004, value = "removing aerogear connector as endpoint is invalid", format = Message.Format.MESSAGE_FORMAT)
|
||||
void reply404();
|
||||
|
||||
@LogMessage(level = Logger.Level.WARN)
|
||||
@Message(id = 232005, value = "removing aerogear connector as unexpected response {0} returned", format = Message.Format.MESSAGE_FORMAT)
|
||||
void replyUnknown(int status);
|
||||
|
||||
@LogMessage(level = Logger.Level.WARN)
|
||||
@Message(id = 232006, value = "unable to connect to aerogear server, retrying in {0} seconds", format = Message.Format.MESSAGE_FORMAT)
|
||||
void sendFailed(int retry);
|
||||
|
||||
@LogMessage(level = Logger.Level.WARN)
|
||||
@Message(id = 232007, value = "removing aerogear connector unable to connect after {0} attempts, giving up", format = Message.Format.MESSAGE_FORMAT)
|
||||
void unableToReconnect(int retryAttempt);
|
||||
}
|
|
@ -1,367 +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.
|
||||
*/
|
||||
package org.apache.activemq.artemis.integration.aerogear;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
import org.apache.activemq.artemis.core.filter.Filter;
|
||||
import org.apache.activemq.artemis.core.filter.impl.FilterImpl;
|
||||
import org.apache.activemq.artemis.core.postoffice.Binding;
|
||||
import org.apache.activemq.artemis.core.postoffice.PostOffice;
|
||||
import org.apache.activemq.artemis.core.server.ActiveMQServerLogger;
|
||||
import org.apache.activemq.artemis.core.server.ConnectorService;
|
||||
import org.apache.activemq.artemis.core.server.Consumer;
|
||||
import org.apache.activemq.artemis.core.server.HandleStatus;
|
||||
import org.apache.activemq.artemis.core.server.MessageReference;
|
||||
import org.apache.activemq.artemis.core.server.Queue;
|
||||
import org.apache.activemq.artemis.core.server.ServerMessage;
|
||||
import org.apache.activemq.artemis.utils.ConfigurationHelper;
|
||||
import org.jboss.aerogear.unifiedpush.JavaSender;
|
||||
import org.jboss.aerogear.unifiedpush.SenderClient;
|
||||
import org.jboss.aerogear.unifiedpush.message.MessageResponseCallback;
|
||||
import org.jboss.aerogear.unifiedpush.message.UnifiedMessage;
|
||||
|
||||
public class AeroGearConnectorService implements ConnectorService, Consumer, MessageResponseCallback {
|
||||
|
||||
private final String connectorName;
|
||||
|
||||
private final PostOffice postOffice;
|
||||
|
||||
private final ScheduledExecutorService scheduledThreadPool;
|
||||
|
||||
private final String queueName;
|
||||
|
||||
private final String endpoint;
|
||||
|
||||
private final String applicationId;
|
||||
|
||||
private final String applicationMasterSecret;
|
||||
|
||||
private final int ttl;
|
||||
|
||||
private final String badge;
|
||||
|
||||
private final String sound;
|
||||
|
||||
private final boolean contentAvailable;
|
||||
|
||||
private final String actionCategory;
|
||||
|
||||
private String[] variants;
|
||||
|
||||
private String[] aliases;
|
||||
|
||||
private String[] deviceTypes;
|
||||
|
||||
private final String filterString;
|
||||
|
||||
private final int retryInterval;
|
||||
|
||||
private final int retryAttempts;
|
||||
|
||||
private Queue queue;
|
||||
|
||||
private Filter filter;
|
||||
|
||||
private volatile boolean handled = false;
|
||||
|
||||
private boolean started = false;
|
||||
|
||||
private boolean reconnecting = false;
|
||||
|
||||
public AeroGearConnectorService(String connectorName,
|
||||
Map<String, Object> configuration,
|
||||
PostOffice postOffice,
|
||||
ScheduledExecutorService scheduledThreadPool) {
|
||||
this.connectorName = connectorName;
|
||||
this.postOffice = postOffice;
|
||||
this.scheduledThreadPool = scheduledThreadPool;
|
||||
this.queueName = ConfigurationHelper.getStringProperty(AeroGearConstants.QUEUE_NAME, null, configuration);
|
||||
this.endpoint = ConfigurationHelper.getStringProperty(AeroGearConstants.ENDPOINT_NAME, null, configuration);
|
||||
this.applicationId = ConfigurationHelper.getStringProperty(AeroGearConstants.APPLICATION_ID_NAME, null, configuration);
|
||||
this.applicationMasterSecret = ConfigurationHelper.getStringProperty(AeroGearConstants.APPLICATION_MASTER_SECRET_NAME, null, configuration);
|
||||
this.ttl = ConfigurationHelper.getIntProperty(AeroGearConstants.TTL_NAME, AeroGearConstants.DEFAULT_TTL, configuration);
|
||||
this.badge = ConfigurationHelper.getStringProperty(AeroGearConstants.BADGE_NAME, null, configuration);
|
||||
this.sound = ConfigurationHelper.getStringProperty(AeroGearConstants.SOUND_NAME, AeroGearConstants.DEFAULT_SOUND, configuration);
|
||||
this.contentAvailable = ConfigurationHelper.getBooleanProperty(AeroGearConstants.CONTENT_AVAILABLE_NAME, false, configuration);
|
||||
this.actionCategory = ConfigurationHelper.getStringProperty(AeroGearConstants.ACTION_CATEGORY_NAME, null, configuration);
|
||||
this.filterString = ConfigurationHelper.getStringProperty(AeroGearConstants.FILTER_NAME, null, configuration);
|
||||
this.retryInterval = ConfigurationHelper.getIntProperty(AeroGearConstants.RETRY_INTERVAL_NAME, AeroGearConstants.DEFAULT_RETRY_INTERVAL, configuration);
|
||||
this.retryAttempts = ConfigurationHelper.getIntProperty(AeroGearConstants.RETRY_ATTEMPTS_NAME, AeroGearConstants.DEFAULT_RETRY_ATTEMPTS, configuration);
|
||||
String variantsString = ConfigurationHelper.getStringProperty(AeroGearConstants.VARIANTS_NAME, null, configuration);
|
||||
if (variantsString != null) {
|
||||
variants = variantsString.split(",");
|
||||
}
|
||||
String aliasesString = ConfigurationHelper.getStringProperty(AeroGearConstants.ALIASES_NAME, null, configuration);
|
||||
if (aliasesString != null) {
|
||||
aliases = aliasesString.split(",");
|
||||
}
|
||||
String deviceTypeString = ConfigurationHelper.getStringProperty(AeroGearConstants.DEVICE_TYPE_NAME, null, configuration);
|
||||
if (deviceTypeString != null) {
|
||||
deviceTypes = deviceTypeString.split(",");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return connectorName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() throws Exception {
|
||||
if (started) {
|
||||
return;
|
||||
}
|
||||
if (filterString != null) {
|
||||
filter = FilterImpl.createFilter(filterString);
|
||||
}
|
||||
|
||||
if (endpoint == null || endpoint.isEmpty()) {
|
||||
throw ActiveMQAeroGearBundle.BUNDLE.endpointNull();
|
||||
}
|
||||
if (applicationId == null || applicationId.isEmpty()) {
|
||||
throw ActiveMQAeroGearBundle.BUNDLE.applicationIdNull();
|
||||
}
|
||||
if (applicationMasterSecret == null || applicationMasterSecret.isEmpty()) {
|
||||
throw ActiveMQAeroGearBundle.BUNDLE.masterSecretNull();
|
||||
}
|
||||
|
||||
Binding b = postOffice.getBinding(new SimpleString(queueName));
|
||||
if (b == null) {
|
||||
throw ActiveMQAeroGearBundle.BUNDLE.noQueue(connectorName, queueName);
|
||||
}
|
||||
|
||||
queue = (Queue) b.getBindable();
|
||||
|
||||
queue.addConsumer(this);
|
||||
|
||||
started = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws Exception {
|
||||
if (!started) {
|
||||
return;
|
||||
}
|
||||
queue.removeConsumer(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStarted() {
|
||||
return started;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandleStatus handle(final MessageReference reference) throws Exception {
|
||||
if (reconnecting) {
|
||||
return HandleStatus.BUSY;
|
||||
}
|
||||
ServerMessage message = reference.getMessage();
|
||||
|
||||
if (filter != null && !filter.match(message)) {
|
||||
if (ActiveMQServerLogger.LOGGER.isTraceEnabled()) {
|
||||
ActiveMQServerLogger.LOGGER.trace("Reference " + reference + " is a noMatch on consumer " + this);
|
||||
}
|
||||
return HandleStatus.NO_MATCH;
|
||||
}
|
||||
|
||||
//we only accept if the alert is set
|
||||
if (!message.containsProperty(AeroGearConstants.AEROGEAR_ALERT)) {
|
||||
return HandleStatus.NO_MATCH;
|
||||
}
|
||||
|
||||
String alert = message.getTypedProperties().getProperty(AeroGearConstants.AEROGEAR_ALERT).toString();
|
||||
|
||||
JavaSender sender = new SenderClient.Builder(endpoint).build();
|
||||
|
||||
UnifiedMessage.Builder builder = new UnifiedMessage.Builder();
|
||||
|
||||
builder.pushApplicationId(applicationId).masterSecret(applicationMasterSecret).alert(alert);
|
||||
|
||||
String sound = message.containsProperty(AeroGearConstants.AEROGEAR_SOUND) ? message.getStringProperty(AeroGearConstants.AEROGEAR_SOUND) : this.sound;
|
||||
|
||||
if (sound != null) {
|
||||
builder.sound(sound);
|
||||
}
|
||||
|
||||
String badge = message.containsProperty(AeroGearConstants.AEROGEAR_BADGE) ? message.getStringProperty(AeroGearConstants.AEROGEAR_BADGE) : this.badge;
|
||||
|
||||
if (badge != null) {
|
||||
builder.badge(badge);
|
||||
}
|
||||
|
||||
boolean contentAvailable = message.containsProperty(AeroGearConstants.AEROGEAR_CONTENT_AVAILABLE) ? message.getBooleanProperty(AeroGearConstants.AEROGEAR_CONTENT_AVAILABLE) : this.contentAvailable;
|
||||
|
||||
if (contentAvailable) {
|
||||
builder.contentAvailable();
|
||||
}
|
||||
|
||||
String actionCategory = message.containsProperty(AeroGearConstants.AEROGEAR_ACTION_CATEGORY) ? message.getStringProperty(AeroGearConstants.AEROGEAR_ACTION_CATEGORY) : this.actionCategory;
|
||||
|
||||
if (actionCategory != null) {
|
||||
builder.actionCategory(actionCategory);
|
||||
}
|
||||
|
||||
Integer ttl = message.containsProperty(AeroGearConstants.AEROGEAR_TTL) ? message.getIntProperty(AeroGearConstants.AEROGEAR_TTL) : this.ttl;
|
||||
|
||||
if (ttl != null) {
|
||||
builder.timeToLive(ttl);
|
||||
}
|
||||
|
||||
String variantsString = message.containsProperty(AeroGearConstants.AEROGEAR_VARIANTS) ? message.getStringProperty(AeroGearConstants.AEROGEAR_VARIANTS) : null;
|
||||
|
||||
String[] variants = variantsString != null ? variantsString.split(",") : this.variants;
|
||||
|
||||
if (variants != null) {
|
||||
builder.variants(Arrays.asList(variants));
|
||||
}
|
||||
|
||||
String aliasesString = message.containsProperty(AeroGearConstants.AEROGEAR_ALIASES) ? message.getStringProperty(AeroGearConstants.AEROGEAR_ALIASES) : null;
|
||||
|
||||
String[] aliases = aliasesString != null ? aliasesString.split(",") : this.aliases;
|
||||
|
||||
if (aliases != null) {
|
||||
builder.aliases(Arrays.asList(aliases));
|
||||
}
|
||||
|
||||
String deviceTypesString = message.containsProperty(AeroGearConstants.AEROGEAR_DEVICE_TYPES) ? message.getStringProperty(AeroGearConstants.AEROGEAR_DEVICE_TYPES) : null;
|
||||
|
||||
String[] deviceTypes = deviceTypesString != null ? deviceTypesString.split(",") : this.deviceTypes;
|
||||
|
||||
if (deviceTypes != null) {
|
||||
builder.deviceType(Arrays.asList(deviceTypes));
|
||||
}
|
||||
|
||||
Set<SimpleString> propertyNames = message.getPropertyNames();
|
||||
|
||||
for (SimpleString propertyName : propertyNames) {
|
||||
String nameString = propertyName.toString();
|
||||
if (nameString.startsWith("AEROGEAR_") && !AeroGearConstants.ALLOWABLE_PROPERTIES.contains(nameString)) {
|
||||
Object property = message.getTypedProperties().getProperty(propertyName);
|
||||
builder.attribute(nameString, property.toString());
|
||||
}
|
||||
}
|
||||
|
||||
UnifiedMessage unifiedMessage = builder.build();
|
||||
|
||||
sender.send(unifiedMessage, this);
|
||||
|
||||
if (handled) {
|
||||
reference.acknowledge();
|
||||
return HandleStatus.HANDLED;
|
||||
} else if (!started) {
|
||||
//if we have been stopped we must return no match as we have been removed as a consumer,
|
||||
// anything else will cause an exception
|
||||
return HandleStatus.NO_MATCH;
|
||||
}
|
||||
//we must be reconnecting
|
||||
return HandleStatus.BUSY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(int statusCode) {
|
||||
if (statusCode != 200) {
|
||||
handled = false;
|
||||
if (statusCode == 401) {
|
||||
ActiveMQAeroGearLogger.LOGGER.reply401();
|
||||
} else if (statusCode == 404) {
|
||||
ActiveMQAeroGearLogger.LOGGER.reply404();
|
||||
} else {
|
||||
ActiveMQAeroGearLogger.LOGGER.replyUnknown(statusCode);
|
||||
}
|
||||
|
||||
queue.removeConsumer(this);
|
||||
started = false;
|
||||
} else {
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
ActiveMQAeroGearLogger.LOGGER.sendFailed(retryInterval);
|
||||
handled = false;
|
||||
reconnecting = true;
|
||||
scheduledThreadPool.schedule(new ReconnectRunnable(0), retryInterval, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
private class ReconnectRunnable implements Runnable {
|
||||
|
||||
private int retryAttempt;
|
||||
|
||||
private ReconnectRunnable(int retryAttempt) {
|
||||
this.retryAttempt = retryAttempt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
HttpURLConnection conn = (HttpURLConnection) new URL(endpoint).openConnection();
|
||||
conn.connect();
|
||||
reconnecting = false;
|
||||
ActiveMQAeroGearLogger.LOGGER.connected(endpoint);
|
||||
queue.deliverAsync();
|
||||
} catch (Exception e) {
|
||||
retryAttempt++;
|
||||
if (retryAttempts == -1 || retryAttempt < retryAttempts) {
|
||||
scheduledThreadPool.schedule(this, retryInterval, TimeUnit.SECONDS);
|
||||
} else {
|
||||
ActiveMQAeroGearLogger.LOGGER.unableToReconnect(retryAttempt);
|
||||
started = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MessageReference> getDeliveringMessages() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void proceedDeliver(MessageReference reference) throws Exception {
|
||||
//noop
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String debug() {
|
||||
return "aerogear connected to " + endpoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toManagementString() {
|
||||
return "aerogear connected to " + endpoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect() {
|
||||
}
|
||||
}
|
|
@ -1,48 +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.
|
||||
*/
|
||||
package org.apache.activemq.artemis.integration.aerogear;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import org.apache.activemq.artemis.core.persistence.StorageManager;
|
||||
import org.apache.activemq.artemis.core.postoffice.PostOffice;
|
||||
import org.apache.activemq.artemis.core.server.ConnectorService;
|
||||
import org.apache.activemq.artemis.core.server.ConnectorServiceFactory;
|
||||
|
||||
public class AeroGearConnectorServiceFactory implements ConnectorServiceFactory {
|
||||
|
||||
@Override
|
||||
public ConnectorService createConnectorService(String connectorName,
|
||||
Map<String, Object> configuration,
|
||||
StorageManager storageManager,
|
||||
PostOffice postOffice,
|
||||
ScheduledExecutorService scheduledThreadPool) {
|
||||
return new AeroGearConnectorService(connectorName, configuration, postOffice, scheduledThreadPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getAllowableProperties() {
|
||||
return AeroGearConstants.ALLOWABLE_PROPERTIES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getRequiredProperties() {
|
||||
return AeroGearConstants.REQUIRED_PROPERTIES;
|
||||
}
|
||||
}
|
|
@ -1,83 +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.
|
||||
*/
|
||||
package org.apache.activemq.artemis.integration.aerogear;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
|
||||
public class AeroGearConstants {
|
||||
|
||||
public static final Set<String> ALLOWABLE_PROPERTIES = new HashSet<>();
|
||||
public static final Set<String> REQUIRED_PROPERTIES = new HashSet<>();
|
||||
|
||||
public static final String QUEUE_NAME = "queue";
|
||||
public static final String ENDPOINT_NAME = "endpoint";
|
||||
public static final String APPLICATION_ID_NAME = "application-id";
|
||||
public static final String APPLICATION_MASTER_SECRET_NAME = "master-secret";
|
||||
public static final String TTL_NAME = "ttl";
|
||||
public static final String BADGE_NAME = "badge";
|
||||
public static final String SOUND_NAME = "sound";
|
||||
public static final String CONTENT_AVAILABLE_NAME = "content-available";
|
||||
public static final String ACTION_CATEGORY_NAME = "action-category";
|
||||
public static final String FILTER_NAME = "filter";
|
||||
public static final String RETRY_INTERVAL_NAME = "retry-interval";
|
||||
public static final String RETRY_ATTEMPTS_NAME = "retry-attempts";
|
||||
public static final String VARIANTS_NAME = "variants";
|
||||
public static final String ALIASES_NAME = "aliases";
|
||||
public static final String DEVICE_TYPE_NAME = "device-types";
|
||||
|
||||
public static final SimpleString AEROGEAR_ALERT = new SimpleString("AEROGEAR_ALERT");
|
||||
public static final SimpleString AEROGEAR_SOUND = new SimpleString("AEROGEAR_SOUND");
|
||||
public static final SimpleString AEROGEAR_CONTENT_AVAILABLE = new SimpleString("AEROGEAR_CONTENT_AVAILABLE");
|
||||
public static final SimpleString AEROGEAR_ACTION_CATEGORY = new SimpleString("AEROGEAR_ACTION_CATEGORY");
|
||||
public static final SimpleString AEROGEAR_BADGE = new SimpleString("AEROGEAR_BADGE");
|
||||
public static final SimpleString AEROGEAR_TTL = new SimpleString("AEROGEAR_TTL");
|
||||
public static final SimpleString AEROGEAR_VARIANTS = new SimpleString("AEROGEAR_VARIANTS");
|
||||
public static final SimpleString AEROGEAR_ALIASES = new SimpleString("AEROGEAR_ALIASES");
|
||||
public static final SimpleString AEROGEAR_DEVICE_TYPES = new SimpleString("AEROGEAR_DEVICE_TYPES");
|
||||
|
||||
public static final String DEFAULT_SOUND = "default";
|
||||
public static final Integer DEFAULT_TTL = 3600;
|
||||
public static final int DEFAULT_RETRY_INTERVAL = 5;
|
||||
public static final int DEFAULT_RETRY_ATTEMPTS = 5;
|
||||
|
||||
static {
|
||||
ALLOWABLE_PROPERTIES.add(QUEUE_NAME);
|
||||
ALLOWABLE_PROPERTIES.add(ENDPOINT_NAME);
|
||||
ALLOWABLE_PROPERTIES.add(APPLICATION_ID_NAME);
|
||||
ALLOWABLE_PROPERTIES.add(APPLICATION_MASTER_SECRET_NAME);
|
||||
ALLOWABLE_PROPERTIES.add(TTL_NAME);
|
||||
ALLOWABLE_PROPERTIES.add(BADGE_NAME);
|
||||
ALLOWABLE_PROPERTIES.add(SOUND_NAME);
|
||||
ALLOWABLE_PROPERTIES.add(CONTENT_AVAILABLE_NAME);
|
||||
ALLOWABLE_PROPERTIES.add(ACTION_CATEGORY_NAME);
|
||||
ALLOWABLE_PROPERTIES.add(FILTER_NAME);
|
||||
ALLOWABLE_PROPERTIES.add(RETRY_INTERVAL_NAME);
|
||||
ALLOWABLE_PROPERTIES.add(RETRY_ATTEMPTS_NAME);
|
||||
ALLOWABLE_PROPERTIES.add(VARIANTS_NAME);
|
||||
ALLOWABLE_PROPERTIES.add(ALIASES_NAME);
|
||||
ALLOWABLE_PROPERTIES.add(DEVICE_TYPE_NAME);
|
||||
|
||||
REQUIRED_PROPERTIES.add(QUEUE_NAME);
|
||||
REQUIRED_PROPERTIES.add(ENDPOINT_NAME);
|
||||
REQUIRED_PROPERTIES.add(APPLICATION_ID_NAME);
|
||||
REQUIRED_PROPERTIES.add(APPLICATION_MASTER_SECRET_NAME);
|
||||
}
|
||||
|
||||
}
|
6
pom.xml
6
pom.xml
|
@ -53,7 +53,6 @@
|
|||
<module>artemis-maven-plugin</module>
|
||||
<module>artemis-server-osgi</module>
|
||||
<module>integration/activemq-spring-integration</module>
|
||||
<module>integration/activemq-aerogear-integration</module>
|
||||
<module>artemis-distribution</module>
|
||||
<module>artemis-tools</module>
|
||||
<module>tests</module>
|
||||
|
@ -734,7 +733,6 @@
|
|||
<module>artemis-maven-plugin</module>
|
||||
<module>artemis-jdbc-store</module>
|
||||
<module>integration/activemq-spring-integration</module>
|
||||
<module>integration/activemq-aerogear-integration</module>
|
||||
<module>tests</module>
|
||||
</modules>
|
||||
<properties>
|
||||
|
@ -769,7 +767,6 @@
|
|||
<module>artemis-service-extensions</module>
|
||||
<module>artemis-maven-plugin</module>
|
||||
<module>integration/activemq-spring-integration</module>
|
||||
<module>integration/activemq-aerogear-integration</module>
|
||||
<module>examples</module>
|
||||
<module>tests</module>
|
||||
<module>artemis-distribution</module>
|
||||
|
@ -827,7 +824,6 @@
|
|||
<module>artemis-service-extensions</module>
|
||||
<module>artemis-maven-plugin</module>
|
||||
<module>integration/activemq-spring-integration</module>
|
||||
<module>integration/activemq-aerogear-integration</module>
|
||||
<module>tests</module>
|
||||
</modules>
|
||||
<properties>
|
||||
|
@ -869,7 +865,6 @@
|
|||
<module>artemis-service-extensions</module>
|
||||
<module>artemis-maven-plugin</module>
|
||||
<module>integration/activemq-spring-integration</module>
|
||||
<module>integration/activemq-aerogear-integration</module>
|
||||
<module>tests</module>
|
||||
</modules>
|
||||
<properties>
|
||||
|
@ -903,7 +898,6 @@
|
|||
<module>artemis-service-extensions</module>
|
||||
<module>artemis-maven-plugin</module>
|
||||
<module>integration/activemq-spring-integration</module>
|
||||
<module>integration/activemq-aerogear-integration</module>
|
||||
<module>tests</module>
|
||||
<module>examples</module>
|
||||
</modules>
|
||||
|
|
|
@ -176,11 +176,6 @@
|
|||
</dependency>
|
||||
<!-- END MQTT Deps -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>artemis-aerogear-integration</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-j2ee-connector_1.5_spec</artifactId>
|
||||
|
|
|
@ -1,350 +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.
|
||||
*/
|
||||
package org.apache.activemq.artemis.tests.integration.aerogear;
|
||||
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonObject;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.JsonUtil;
|
||||
import org.apache.activemq.artemis.api.core.Message;
|
||||
import org.apache.activemq.artemis.api.core.client.ClientConsumer;
|
||||
import org.apache.activemq.artemis.api.core.client.ClientMessage;
|
||||
import org.apache.activemq.artemis.api.core.client.ClientProducer;
|
||||
import org.apache.activemq.artemis.api.core.client.ClientSession;
|
||||
import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
|
||||
import org.apache.activemq.artemis.api.core.client.SendAcknowledgementHandler;
|
||||
import org.apache.activemq.artemis.api.core.client.ServerLocator;
|
||||
import org.apache.activemq.artemis.core.config.Configuration;
|
||||
import org.apache.activemq.artemis.core.config.ConnectorServiceConfiguration;
|
||||
import org.apache.activemq.artemis.core.config.CoreQueueConfiguration;
|
||||
import org.apache.activemq.artemis.core.server.ActiveMQServer;
|
||||
import org.apache.activemq.artemis.integration.aerogear.AeroGearConnectorServiceFactory;
|
||||
import org.apache.activemq.artemis.integration.aerogear.AeroGearConstants;
|
||||
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mortbay.jetty.Request;
|
||||
import org.mortbay.jetty.Server;
|
||||
import org.mortbay.jetty.handler.AbstractHandler;
|
||||
import org.mortbay.jetty.nio.SelectChannelConnector;
|
||||
|
||||
public class AeroGearBasicServerTest extends ActiveMQTestBase {
|
||||
|
||||
private ActiveMQServer server;
|
||||
private ServerLocator locator;
|
||||
private Server jetty;
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
/*
|
||||
* there will be a thread kept alive by the http connection, we could disable the thread check but this means that the tests
|
||||
* interfere with one another, we just have to wait for it to be killed
|
||||
* */
|
||||
jetty = new Server();
|
||||
SelectChannelConnector connector0 = new SelectChannelConnector();
|
||||
connector0.setPort(8080);
|
||||
connector0.setMaxIdleTime(30000);
|
||||
connector0.setHost("localhost");
|
||||
jetty.addConnector(connector0);
|
||||
jetty.start();
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
params.put(AeroGearConstants.QUEUE_NAME, "testQueue");
|
||||
params.put(AeroGearConstants.ENDPOINT_NAME, "http://localhost:8080");
|
||||
params.put(AeroGearConstants.APPLICATION_ID_NAME, "9d646a12-e601-4452-9e05-efb0fccdfd08");
|
||||
params.put(AeroGearConstants.APPLICATION_MASTER_SECRET_NAME, "ed75f17e-cf3c-4c9b-a503-865d91d60d40");
|
||||
params.put(AeroGearConstants.RETRY_ATTEMPTS_NAME, 2);
|
||||
params.put(AeroGearConstants.RETRY_INTERVAL_NAME, 1);
|
||||
params.put(AeroGearConstants.BADGE_NAME, "99");
|
||||
params.put(AeroGearConstants.ALIASES_NAME, "me,him,them");
|
||||
params.put(AeroGearConstants.DEVICE_TYPE_NAME, "android,ipad");
|
||||
params.put(AeroGearConstants.SOUND_NAME, "sound1");
|
||||
params.put(AeroGearConstants.VARIANTS_NAME, "variant1,variant2");
|
||||
|
||||
Configuration configuration = createDefaultInVMConfig().addConnectorServiceConfiguration(new ConnectorServiceConfiguration().setFactoryClassName(AeroGearConnectorServiceFactory.class.getName()).setParams(params).setName("TestAeroGearService")).addQueueConfiguration(new CoreQueueConfiguration().setAddress("testQueue").setName("testQueue"));
|
||||
|
||||
server = addServer(createServer(configuration));
|
||||
server.start();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if (jetty != null) {
|
||||
jetty.stop();
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aerogearSimpleReceiveTest() throws Exception {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
AeroGearHandler aeroGearHandler = new AeroGearHandler(latch);
|
||||
jetty.addHandler(aeroGearHandler);
|
||||
locator = createInVMNonHALocator();
|
||||
ClientSessionFactory sf = createSessionFactory(locator);
|
||||
ClientSession session = sf.createSession(false, true, true);
|
||||
ClientProducer producer = session.createProducer("testQueue");
|
||||
ClientMessage m = session.createMessage(true);
|
||||
m.putStringProperty(AeroGearConstants.AEROGEAR_ALERT.toString(), "hello from ActiveMQ!");
|
||||
m.putStringProperty("AEROGEAR_PROP1", "prop1");
|
||||
m.putBooleanProperty("AEROGEAR_PROP2", true);
|
||||
|
||||
producer.send(m);
|
||||
|
||||
assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||
assertNotNull(aeroGearHandler.jsonObject);
|
||||
JsonObject body = aeroGearHandler.jsonObject.getJsonObject("message");
|
||||
assertNotNull(body);
|
||||
String prop1 = body.getString("AEROGEAR_PROP1");
|
||||
assertNotNull(prop1);
|
||||
assertEquals(prop1, "prop1");
|
||||
prop1 = body.getString("AEROGEAR_PROP2");
|
||||
assertNotNull(prop1);
|
||||
assertEquals(prop1, "true");
|
||||
String alert = body.getString("alert");
|
||||
assertNotNull(alert);
|
||||
assertEquals(alert, "hello from ActiveMQ!");
|
||||
String sound = body.getString("sound");
|
||||
assertNotNull(sound);
|
||||
assertEquals(sound, "sound1");
|
||||
int badge = body.getInt("badge");
|
||||
assertNotNull(badge);
|
||||
assertEquals(badge, 99);
|
||||
JsonArray jsonArray = aeroGearHandler.jsonObject.getJsonArray("variants");
|
||||
assertNotNull(jsonArray);
|
||||
assertEquals(jsonArray.getString(0), "variant1");
|
||||
assertEquals(jsonArray.getString(1), "variant2");
|
||||
jsonArray = aeroGearHandler.jsonObject.getJsonArray("alias");
|
||||
assertNotNull(jsonArray);
|
||||
assertEquals(jsonArray.getString(0), "me");
|
||||
assertEquals(jsonArray.getString(1), "him");
|
||||
assertEquals(jsonArray.getString(2), "them");
|
||||
jsonArray = aeroGearHandler.jsonObject.getJsonArray("deviceType");
|
||||
assertNotNull(jsonArray);
|
||||
assertEquals(jsonArray.getString(0), "android");
|
||||
assertEquals(jsonArray.getString(1), "ipad");
|
||||
int ttl = aeroGearHandler.jsonObject.getInt("ttl");
|
||||
assertEquals(ttl, 3600);
|
||||
latch = new CountDownLatch(1);
|
||||
aeroGearHandler.resetLatch(latch);
|
||||
|
||||
//now override the properties
|
||||
m = session.createMessage(true);
|
||||
m.putStringProperty(AeroGearConstants.AEROGEAR_ALERT.toString(), "another hello from ActiveMQ!");
|
||||
m.putStringProperty(AeroGearConstants.AEROGEAR_BADGE.toString(), "111");
|
||||
m.putStringProperty(AeroGearConstants.AEROGEAR_SOUND.toString(), "s1");
|
||||
m.putIntProperty(AeroGearConstants.AEROGEAR_TTL.toString(), 10000);
|
||||
m.putStringProperty(AeroGearConstants.AEROGEAR_ALIASES.toString(), "alias1,alias2");
|
||||
m.putStringProperty(AeroGearConstants.AEROGEAR_DEVICE_TYPES.toString(), "dev1,dev2");
|
||||
m.putStringProperty(AeroGearConstants.AEROGEAR_VARIANTS.toString(), "v1,v2");
|
||||
|
||||
producer.send(m);
|
||||
assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||
assertNotNull(aeroGearHandler.jsonObject);
|
||||
body = aeroGearHandler.jsonObject.getJsonObject("message");
|
||||
assertNotNull(body);
|
||||
alert = body.getString("alert");
|
||||
assertNotNull(alert);
|
||||
assertEquals(alert, "another hello from ActiveMQ!");
|
||||
sound = body.getString("sound");
|
||||
assertNotNull(sound);
|
||||
assertEquals(sound, "s1");
|
||||
badge = body.getInt("badge");
|
||||
assertEquals(badge, 111);
|
||||
jsonArray = aeroGearHandler.jsonObject.getJsonArray("variants");
|
||||
assertNotNull(jsonArray);
|
||||
assertEquals(jsonArray.getString(0), "v1");
|
||||
assertEquals(jsonArray.getString(1), "v2");
|
||||
jsonArray = aeroGearHandler.jsonObject.getJsonArray("alias");
|
||||
assertNotNull(jsonArray);
|
||||
assertEquals(jsonArray.getString(0), "alias1");
|
||||
assertEquals(jsonArray.getString(1), "alias2");
|
||||
jsonArray = aeroGearHandler.jsonObject.getJsonArray("deviceType");
|
||||
assertNotNull(jsonArray);
|
||||
assertEquals(jsonArray.getString(0), "dev1");
|
||||
assertEquals(jsonArray.getString(1), "dev2");
|
||||
ttl = aeroGearHandler.jsonObject.getInt("ttl");
|
||||
assertEquals(ttl, 10000);
|
||||
session.start();
|
||||
ClientMessage message = session.createConsumer("testQueue").receiveImmediate();
|
||||
assertNull(message);
|
||||
}
|
||||
|
||||
class AeroGearHandler extends AbstractHandler {
|
||||
|
||||
JsonObject jsonObject;
|
||||
private CountDownLatch latch;
|
||||
|
||||
AeroGearHandler(CountDownLatch latch) {
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(String target,
|
||||
HttpServletRequest httpServletRequest,
|
||||
HttpServletResponse httpServletResponse,
|
||||
int i) throws IOException, ServletException {
|
||||
Request request = (Request) httpServletRequest;
|
||||
httpServletResponse.setContentType("text/html");
|
||||
httpServletResponse.setStatus(HttpServletResponse.SC_OK);
|
||||
request.setHandled(true);
|
||||
byte[] bytes = new byte[httpServletRequest.getContentLength()];
|
||||
httpServletRequest.getInputStream().read(bytes);
|
||||
String json = new String(bytes);
|
||||
jsonObject = JsonUtil.readJsonObject(json);
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
public void resetLatch(CountDownLatch latch) {
|
||||
this.latch = latch;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aerogearReconnectTest() throws Exception {
|
||||
jetty.stop();
|
||||
final CountDownLatch reconnectLatch = new CountDownLatch(1);
|
||||
jetty.addHandler(new AbstractHandler() {
|
||||
@Override
|
||||
public void handle(String target,
|
||||
HttpServletRequest httpServletRequest,
|
||||
HttpServletResponse httpServletResponse,
|
||||
int i) throws IOException, ServletException {
|
||||
Request request = (Request) httpServletRequest;
|
||||
httpServletResponse.setContentType("text/html");
|
||||
httpServletResponse.setStatus(HttpServletResponse.SC_OK);
|
||||
request.setHandled(true);
|
||||
reconnectLatch.countDown();
|
||||
}
|
||||
|
||||
});
|
||||
locator = createInVMNonHALocator();
|
||||
ClientSessionFactory sf = createSessionFactory(locator);
|
||||
ClientSession session = sf.createSession(false, true, true);
|
||||
ClientProducer producer = session.createProducer("testQueue");
|
||||
final CountDownLatch latch = new CountDownLatch(2);
|
||||
ClientMessage m = session.createMessage(true);
|
||||
m.putStringProperty(AeroGearConstants.AEROGEAR_ALERT.toString(), "hello from ActiveMQ!");
|
||||
|
||||
producer.send(m, new SendAcknowledgementHandler() {
|
||||
@Override
|
||||
public void sendAcknowledged(Message message) {
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
m = session.createMessage(true);
|
||||
m.putStringProperty(AeroGearConstants.AEROGEAR_ALERT.toString(), "another hello from ActiveMQ!");
|
||||
|
||||
producer.send(m, new SendAcknowledgementHandler() {
|
||||
@Override
|
||||
public void sendAcknowledged(Message message) {
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
latch.await(5, TimeUnit.SECONDS);
|
||||
Thread.sleep(1000);
|
||||
jetty.start();
|
||||
reconnectLatch.await(5, TimeUnit.SECONDS);
|
||||
session.start();
|
||||
ClientMessage message = session.createConsumer("testQueue").receiveImmediate();
|
||||
assertNull(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aerogear401() throws Exception {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
jetty.addHandler(new AbstractHandler() {
|
||||
@Override
|
||||
public void handle(String target,
|
||||
HttpServletRequest httpServletRequest,
|
||||
HttpServletResponse httpServletResponse,
|
||||
int i) throws IOException, ServletException {
|
||||
Request request = (Request) httpServletRequest;
|
||||
httpServletResponse.setContentType("text/html");
|
||||
httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
request.setHandled(true);
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
});
|
||||
locator = createInVMNonHALocator();
|
||||
ClientSessionFactory sf = createSessionFactory(locator);
|
||||
ClientSession session = sf.createSession(false, true, true);
|
||||
ClientProducer producer = session.createProducer("testQueue");
|
||||
ClientMessage m = session.createMessage(true);
|
||||
m.putStringProperty(AeroGearConstants.AEROGEAR_ALERT.toString(), "hello from ActiveMQ!");
|
||||
|
||||
producer.send(m);
|
||||
m = session.createMessage(true);
|
||||
m.putStringProperty(AeroGearConstants.AEROGEAR_ALERT.toString(), "another hello from ActiveMQ!");
|
||||
|
||||
producer.send(m);
|
||||
assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||
session.start();
|
||||
ClientConsumer consumer = session.createConsumer("testQueue");
|
||||
ClientMessage message = consumer.receive(5000);
|
||||
assertNotNull(message);
|
||||
message = consumer.receive(5000);
|
||||
assertNotNull(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aerogear404() throws Exception {
|
||||
jetty.addHandler(new AbstractHandler() {
|
||||
@Override
|
||||
public void handle(String target,
|
||||
HttpServletRequest httpServletRequest,
|
||||
HttpServletResponse httpServletResponse,
|
||||
int i) throws IOException, ServletException {
|
||||
Request request = (Request) httpServletRequest;
|
||||
httpServletResponse.setContentType("text/html");
|
||||
httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
request.setHandled(true);
|
||||
}
|
||||
|
||||
});
|
||||
locator = createInVMNonHALocator();
|
||||
ClientSessionFactory sf = createSessionFactory(locator);
|
||||
ClientSession session = sf.createSession(false, true, true);
|
||||
ClientProducer producer = session.createProducer("testQueue");
|
||||
ClientMessage m = session.createMessage(true);
|
||||
m.putStringProperty(AeroGearConstants.AEROGEAR_ALERT.toString(), "hello from ActiveMQ!");
|
||||
|
||||
producer.send(m);
|
||||
m = session.createMessage(true);
|
||||
m.putStringProperty(AeroGearConstants.AEROGEAR_ALERT.toString(), "another hello from ActiveMQ!");
|
||||
|
||||
producer.send(m);
|
||||
session.start();
|
||||
ClientConsumer consumer = session.createConsumer("testQueue");
|
||||
ClientMessage message = consumer.receive(5000);
|
||||
assertNotNull(message);
|
||||
message = consumer.receive(5000);
|
||||
assertNotNull(message);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue