Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 33665200C2A for ; Wed, 1 Mar 2017 18:20:58 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 2E9E6160B92; Wed, 1 Mar 2017 17:20:58 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 71BEB160B56 for ; Wed, 1 Mar 2017 18:20:56 +0100 (CET) Received: (qmail 21212 invoked by uid 500); 1 Mar 2017 17:20:55 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 21202 invoked by uid 99); 1 Mar 2017 17:20:55 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Mar 2017 17:20:55 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7CB0DDFDE6; Wed, 1 Mar 2017 17:20:55 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: clebertsuconic@apache.org To: commits@activemq.apache.org Date: Wed, 01 Mar 2017 17:20:55 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [01/23] activemq-artemis git commit: Removing Aeroegear archived-at: Wed, 01 Mar 2017 17:20:58 -0000 Repository: activemq-artemis Updated Branches: refs/heads/artemis-1009 [created] 9cbff99cd http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/4334fcd3/integration/activemq-aerogear-integration/src/main/java/org/apache/activemq/artemis/integration/aerogear/ActiveMQAeroGearBundle.java ---------------------------------------------------------------------- diff --git a/integration/activemq-aerogear-integration/src/main/java/org/apache/activemq/artemis/integration/aerogear/ActiveMQAeroGearBundle.java b/integration/activemq-aerogear-integration/src/main/java/org/apache/activemq/artemis/integration/aerogear/ActiveMQAeroGearBundle.java deleted file mode 100644 index 5855abe..0000000 --- a/integration/activemq-aerogear-integration/src/main/java/org/apache/activemq/artemis/integration/aerogear/ActiveMQAeroGearBundle.java +++ /dev/null @@ -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 - *
- * each message id must be 6 digits long starting with 10, the 3rd digit should be 9 - *
- * 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); -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/4334fcd3/integration/activemq-aerogear-integration/src/main/java/org/apache/activemq/artemis/integration/aerogear/ActiveMQAeroGearLogger.java ---------------------------------------------------------------------- diff --git a/integration/activemq-aerogear-integration/src/main/java/org/apache/activemq/artemis/integration/aerogear/ActiveMQAeroGearLogger.java b/integration/activemq-aerogear-integration/src/main/java/org/apache/activemq/artemis/integration/aerogear/ActiveMQAeroGearLogger.java deleted file mode 100644 index 66c000e..0000000 --- a/integration/activemq-aerogear-integration/src/main/java/org/apache/activemq/artemis/integration/aerogear/ActiveMQAeroGearLogger.java +++ /dev/null @@ -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); -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/4334fcd3/integration/activemq-aerogear-integration/src/main/java/org/apache/activemq/artemis/integration/aerogear/AeroGearConnectorService.java ---------------------------------------------------------------------- diff --git a/integration/activemq-aerogear-integration/src/main/java/org/apache/activemq/artemis/integration/aerogear/AeroGearConnectorService.java b/integration/activemq-aerogear-integration/src/main/java/org/apache/activemq/artemis/integration/aerogear/AeroGearConnectorService.java deleted file mode 100644 index 5191524..0000000 --- a/integration/activemq-aerogear-integration/src/main/java/org/apache/activemq/artemis/integration/aerogear/AeroGearConnectorService.java +++ /dev/null @@ -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 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 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 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() { - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/4334fcd3/integration/activemq-aerogear-integration/src/main/java/org/apache/activemq/artemis/integration/aerogear/AeroGearConnectorServiceFactory.java ---------------------------------------------------------------------- diff --git a/integration/activemq-aerogear-integration/src/main/java/org/apache/activemq/artemis/integration/aerogear/AeroGearConnectorServiceFactory.java b/integration/activemq-aerogear-integration/src/main/java/org/apache/activemq/artemis/integration/aerogear/AeroGearConnectorServiceFactory.java deleted file mode 100644 index 749c87a..0000000 --- a/integration/activemq-aerogear-integration/src/main/java/org/apache/activemq/artemis/integration/aerogear/AeroGearConnectorServiceFactory.java +++ /dev/null @@ -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 configuration, - StorageManager storageManager, - PostOffice postOffice, - ScheduledExecutorService scheduledThreadPool) { - return new AeroGearConnectorService(connectorName, configuration, postOffice, scheduledThreadPool); - } - - @Override - public Set getAllowableProperties() { - return AeroGearConstants.ALLOWABLE_PROPERTIES; - } - - @Override - public Set getRequiredProperties() { - return AeroGearConstants.REQUIRED_PROPERTIES; - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/4334fcd3/integration/activemq-aerogear-integration/src/main/java/org/apache/activemq/artemis/integration/aerogear/AeroGearConstants.java ---------------------------------------------------------------------- diff --git a/integration/activemq-aerogear-integration/src/main/java/org/apache/activemq/artemis/integration/aerogear/AeroGearConstants.java b/integration/activemq-aerogear-integration/src/main/java/org/apache/activemq/artemis/integration/aerogear/AeroGearConstants.java deleted file mode 100644 index 07eda77..0000000 --- a/integration/activemq-aerogear-integration/src/main/java/org/apache/activemq/artemis/integration/aerogear/AeroGearConstants.java +++ /dev/null @@ -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 ALLOWABLE_PROPERTIES = new HashSet<>(); - public static final Set 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); - } - -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/4334fcd3/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index d182bbb..5b056ad 100644 --- a/pom.xml +++ b/pom.xml @@ -53,7 +53,6 @@ artemis-maven-plugin artemis-server-osgi integration/activemq-spring-integration - integration/activemq-aerogear-integration artemis-distribution artemis-tools tests @@ -734,7 +733,6 @@ artemis-maven-plugin artemis-jdbc-store integration/activemq-spring-integration - integration/activemq-aerogear-integration tests @@ -769,7 +767,6 @@ artemis-service-extensions artemis-maven-plugin integration/activemq-spring-integration - integration/activemq-aerogear-integration examples tests artemis-distribution @@ -827,7 +824,6 @@ artemis-service-extensions artemis-maven-plugin integration/activemq-spring-integration - integration/activemq-aerogear-integration tests @@ -869,7 +865,6 @@ artemis-service-extensions artemis-maven-plugin integration/activemq-spring-integration - integration/activemq-aerogear-integration tests @@ -903,7 +898,6 @@ artemis-service-extensions artemis-maven-plugin integration/activemq-spring-integration - integration/activemq-aerogear-integration tests examples http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/4334fcd3/tests/integration-tests/pom.xml ---------------------------------------------------------------------- diff --git a/tests/integration-tests/pom.xml b/tests/integration-tests/pom.xml index afdaee2..33d82b2 100644 --- a/tests/integration-tests/pom.xml +++ b/tests/integration-tests/pom.xml @@ -177,11 +177,6 @@ - org.apache.activemq - artemis-aerogear-integration - ${project.version} - - org.apache.geronimo.specs geronimo-j2ee-connector_1.5_spec http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/4334fcd3/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/aerogear/AeroGearBasicServerTest.java ---------------------------------------------------------------------- diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/aerogear/AeroGearBasicServerTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/aerogear/AeroGearBasicServerTest.java deleted file mode 100644 index 91b6718..0000000 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/aerogear/AeroGearBasicServerTest.java +++ /dev/null @@ -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 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); - } -}