[ https://issues.apache.org/jira/browse/CAMEL-11999?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16247172#comment-16247172 ]
ASF GitHub Bot commented on CAMEL-11999: ---------------------------------------- oscerd closed pull request #2087: [CAMEL-11999] Cannot create queue/message for Azure URL: https://github.com/apache/camel/pull/2087 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/components/camel-azure/pom.xml b/components/camel-azure/pom.xml index d8e94daca95..1e7c7aacdb1 100644 --- a/components/camel-azure/pom.xml +++ b/components/camel-azure/pom.xml @@ -62,6 +62,11 @@ <artifactId>camel-test-spring</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/components/camel-azure/src/main/java/org/apache/camel/component/azure/queue/QueueServiceComponent.java b/components/camel-azure/src/main/java/org/apache/camel/component/azure/queue/QueueServiceComponent.java index 42bd47df930..572989c6333 100644 --- a/components/camel-azure/src/main/java/org/apache/camel/component/azure/queue/QueueServiceComponent.java +++ b/components/camel-azure/src/main/java/org/apache/camel/component/azure/queue/QueueServiceComponent.java @@ -42,15 +42,20 @@ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Obje if (remaining != null) { parts = remaining.split("/"); } - if (parts == null || parts.length < 2) { - throw new IllegalArgumentException("The account and queue names must be specified."); - } - if (parts.length > 2) { + if (parts == null || parts.length < 1) + throw new IllegalArgumentException("The account name must be specified."); + + QueueServiceOperations operation = configuration.getOperation(); + if (operation != null && operation != QueueServiceOperations.listQueues && parts.length < 2) + throw new IllegalArgumentException("The queue name must be specified."); + + if (parts.length > 2) throw new IllegalArgumentException("Only the account and queue names must be specified."); - } configuration.setAccountName(parts[0]); - configuration.setQueueName(parts[1]); + + if (parts.length > 1) + configuration.setQueueName(parts[1]); checkCredentials(configuration); diff --git a/components/camel-azure/src/main/java/org/apache/camel/component/azure/queue/QueueServiceConfiguration.java b/components/camel-azure/src/main/java/org/apache/camel/component/azure/queue/QueueServiceConfiguration.java index e85cd2c029f..699e013762c 100644 --- a/components/camel-azure/src/main/java/org/apache/camel/component/azure/queue/QueueServiceConfiguration.java +++ b/components/camel-azure/src/main/java/org/apache/camel/component/azure/queue/QueueServiceConfiguration.java @@ -16,11 +16,12 @@ */ package org.apache.camel.component.azure.queue; -import com.microsoft.azure.storage.queue.CloudQueue; import org.apache.camel.component.azure.common.AbstractConfiguration; import org.apache.camel.spi.UriParam; import org.apache.camel.spi.UriParams; +import com.microsoft.azure.storage.queue.CloudQueue; + @UriParams public class QueueServiceConfiguration extends AbstractConfiguration { diff --git a/components/camel-azure/src/main/java/org/apache/camel/component/azure/queue/QueueServiceUtil.java b/components/camel-azure/src/main/java/org/apache/camel/component/azure/queue/QueueServiceUtil.java index 6f094184cfd..9669dbe762c 100644 --- a/components/camel-azure/src/main/java/org/apache/camel/component/azure/queue/QueueServiceUtil.java +++ b/components/camel-azure/src/main/java/org/apache/camel/component/azure/queue/QueueServiceUtil.java @@ -31,19 +31,12 @@ private QueueServiceUtil() { } public static URI prepareStorageQueueUri(QueueServiceConfiguration cfg) { - return prepareStorageQueueUri(cfg, true); - } - - public static URI prepareStorageQueueUri(QueueServiceConfiguration cfg, boolean isForMessages) { StringBuilder uriBuilder = new StringBuilder(); uriBuilder.append("https://") .append(cfg.getAccountName()) .append(QueueServiceConstants.SERVICE_URI_SEGMENT) - .append("/") - .append(cfg.getQueueName()); - if (isForMessages) { - uriBuilder.append("/messages"); - } + .append("/" + cfg.getQueueName()); + return URI.create(uriBuilder.toString()); } @@ -73,7 +66,9 @@ public static StorageCredentials getAccountCredentials(QueueServiceConfiguration public static void retrieveMessage(Exchange exchange, QueueServiceConfiguration cfg) throws Exception { CloudQueue client = createQueueClient(cfg); QueueServiceRequestOptions opts = getRequestOptions(exchange); - CloudQueueMessage message = client.retrieveMessage(cfg.getMessageVisibilityDelay(), + int visibilityTimeout = cfg.getMessageVisibilityDelay(); + visibilityTimeout = visibilityTimeout != 0 ? visibilityTimeout : 30; + CloudQueueMessage message = client.retrieveMessage(visibilityTimeout, opts.getRequestOpts(), opts.getOpContext()); ExchangeUtil.getMessageForResponse(exchange).setBody(message); } diff --git a/components/camel-azure/src/test/java/org/apache/camel/component/azure/queue/QueueServiceComponentConfigurationTest.java b/components/camel-azure/src/test/java/org/apache/camel/component/azure/queue/QueueServiceComponentConfigurationTest.java index ac3e3c165d5..111812d03d9 100644 --- a/components/camel-azure/src/test/java/org/apache/camel/component/azure/queue/QueueServiceComponentConfigurationTest.java +++ b/components/camel-azure/src/test/java/org/apache/camel/component/azure/queue/QueueServiceComponentConfigurationTest.java @@ -136,10 +136,10 @@ public void testTooManyPathSegments() throws Exception { public void testTooFewPathSegments() throws Exception { QueueServiceComponent component = new QueueServiceComponent(context); try { - component.createEndpoint("azure-queue://camelazure"); + component.createEndpoint("azure-queue://camelazure?operation=addMessage"); fail(); } catch (IllegalArgumentException ex) { - assertEquals("The account and queue names must be specified.", ex.getMessage()); + assertEquals("The queue name must be specified.", ex.getMessage()); } } diff --git a/components/camel-azure/src/test/java/org/apache/camel/component/azure/queue/QueueServiceProducerTest.java b/components/camel-azure/src/test/java/org/apache/camel/component/azure/queue/QueueServiceProducerTest.java new file mode 100644 index 00000000000..bc3107f80a6 --- /dev/null +++ b/components/camel-azure/src/test/java/org/apache/camel/component/azure/queue/QueueServiceProducerTest.java @@ -0,0 +1,116 @@ +/** + * 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.camel.component.azure.queue; + +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Properties; + +import javax.naming.Context; +import javax.naming.InitialContext; + +import org.apache.camel.CamelContext; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.impl.JndiRegistry; +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Test; + +import com.microsoft.azure.storage.OperationContext; +import com.microsoft.azure.storage.StorageCredentials; +import com.microsoft.azure.storage.StorageCredentialsAccountAndKey; +import com.microsoft.azure.storage.queue.CloudQueue; +import com.microsoft.azure.storage.queue.CloudQueueMessage; + +public class QueueServiceProducerTest { + + private static final String AZURE_STORAGE_QUEUE = "AZURE_STORAGE_QUEUE"; + + @Test + public void testAppendQueue() throws Exception { + + StorageCredentials creds = getStorageCredentials("camelqueue", System.getenv(AZURE_STORAGE_QUEUE)); + Assume.assumeNotNull("Credentials not null", creds); + + OperationContext.setLoggingEnabledByDefault(true); + + CamelContext camelctx = createCamelContext(creds); + camelctx.addRoutes(new RouteBuilder() { + public void configure() throws Exception { + from("direct:createQueue") + .to("azure-queue://camelqueue/queue1?credentials=#creds&operation=createQueue"); + + from("direct:listQueues") + .to("azure-queue://camelqueue?credentials=#creds&operation=listQueues"); + + from("direct:deleteQueue") + .to("azure-queue://camelqueue/queue1?credentials=#creds&operation=deleteQueue"); + + from("direct:addMessage") + .to("azure-queue://camelqueue/queue1?credentials=#creds&operation=addMessage"); + + from("direct:retrieveMessage") + .to("azure-queue://camelqueue/queue1?credentials=#creds&operation=retrieveMessage"); + } + }); + + camelctx.start(); + try { + ProducerTemplate producer = camelctx.createProducerTemplate(); + + Iterator<?> it = producer.requestBody("direct:listQueues", null, Iterable.class).iterator(); + Assert.assertFalse("No more queues", it.hasNext()); + + producer.sendBody("direct:addMessage", "SomeMsg"); + + it = producer.requestBody("direct:listQueues", null, Iterable.class).iterator(); + Assert.assertTrue("Has queues", it.hasNext()); + CloudQueue queue = (CloudQueue) it.next(); + Assert.assertEquals("queue1", queue.getName()); + Assert.assertFalse("No more queues", it.hasNext()); + + try { + CloudQueueMessage msg = producer.requestBody("direct:retrieveMessage", null, CloudQueueMessage.class); + Assert.assertNotNull("Retrieve a message", msg); + Assert.assertEquals("SomeMsg", msg.getMessageContentAsString()); + } finally { + queue.delete(); + } + + } finally { + camelctx.stop(); + } + } + + private StorageCredentials getStorageCredentials(String account, String key) { + return key != null ? new StorageCredentialsAccountAndKey(account, key) : null; + } + + private CamelContext createCamelContext(StorageCredentials credentials) throws Exception { + JndiRegistry registry = new JndiRegistry(createJndiContext()); + registry.bind("creds", credentials); + return new DefaultCamelContext(registry); + } + + private Context createJndiContext() throws Exception { + Properties properties = new Properties(); + properties.put("java.naming.factory.initial", "org.apache.camel.util.jndi.CamelInitialContextFactory"); + return new InitialContext(new Hashtable<Object, Object>(properties)); + } +} \ No newline at end of file diff --git a/components/camel-azure/src/test/java/org/apache/camel/component/azure/queue/QueueServiceUtilTest.java b/components/camel-azure/src/test/java/org/apache/camel/component/azure/queue/QueueServiceUtilTest.java index 40bf2a4d0f2..85a7216433f 100644 --- a/components/camel-azure/src/test/java/org/apache/camel/component/azure/queue/QueueServiceUtilTest.java +++ b/components/camel-azure/src/test/java/org/apache/camel/component/azure/queue/QueueServiceUtilTest.java @@ -32,42 +32,34 @@ @Test public void testPrepareUri() throws Exception { registerCredentials(); - + QueueServiceComponent component = new QueueServiceComponent(context); - QueueServiceEndpoint endpoint = - (QueueServiceEndpoint) component.createEndpoint("azure-queue://camelazure/testqueue?credentials=#creds"); - URI uri = - QueueServiceUtil.prepareStorageQueueUri(endpoint.getConfiguration()); - assertEquals("https://camelazure.queue.core.windows.net/testqueue/messages", uri.toString()); + QueueServiceEndpoint endpoint = (QueueServiceEndpoint) component.createEndpoint("azure-queue://camelazure/testqueue?credentials=#creds"); + URI uri = QueueServiceUtil.prepareStorageQueueUri(endpoint.getConfiguration()); + assertEquals("https://camelazure.queue.core.windows.net/testqueue", uri.toString()); } @Test public void testGetConfiguredClient() throws Exception { - CloudQueue client = - new CloudQueue(URI.create("https://camelazure.queue.core.windows.net/testqueue/messages"), - newAccountKeyCredentials()); - + CloudQueue client = new CloudQueue(URI.create("https://camelazure.queue.core.windows.net/testqueue"), newAccountKeyCredentials()); JndiRegistry registry = (JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry(); registry.bind("azureQueueClient", client); - + QueueServiceComponent component = new QueueServiceComponent(context); - QueueServiceEndpoint endpoint = - (QueueServiceEndpoint) component.createEndpoint("azure-queue://camelazure/testqueue?azureQueueClient=#azureQueueClient"); + QueueServiceEndpoint endpoint = (QueueServiceEndpoint) component.createEndpoint("azure-queue://camelazure/testqueue?azureQueueClient=#azureQueueClient"); assertSame(client, QueueServiceUtil.getConfiguredClient(endpoint.getConfiguration())); } + @Test public void testGetConfiguredClientUriMismatch() throws Exception { - CloudQueue client = - new CloudQueue(URI.create("https://camelazure.queue.core.windows.net/testqueue"), - newAccountKeyCredentials()); - + CloudQueue client = new CloudQueue(URI.create("https://camelazure.queue.core.windows.net/testqueue"), newAccountKeyCredentials()); + JndiRegistry registry = (JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry(); registry.bind("azureQueueClient", client); - + QueueServiceComponent component = new QueueServiceComponent(context); - QueueServiceEndpoint endpoint = - (QueueServiceEndpoint) component.createEndpoint("azure-queue://camelazure/testqueue2?azureQueueClient=#azureQueueClient"); - + QueueServiceEndpoint endpoint = (QueueServiceEndpoint) component.createEndpoint("azure-queue://camelazure/testqueue2?azureQueueClient=#azureQueueClient"); + try { QueueServiceUtil.getConfiguredClient(endpoint.getConfiguration()); fail(); @@ -82,7 +74,6 @@ private void registerCredentials() { } private StorageCredentials newAccountKeyCredentials() { - return new StorageCredentialsAccountAndKey("camelazure", - Base64.encode("key".getBytes())); + return new StorageCredentialsAccountAndKey("camelazure", Base64.encode("key".getBytes())); } } diff --git a/components/camel-azure/src/test/resources/log4j.properties b/components/camel-azure/src/test/resources/log4j.properties new file mode 100644 index 00000000000..6b2698af632 --- /dev/null +++ b/components/camel-azure/src/test/resources/log4j.properties @@ -0,0 +1,36 @@ +### +# #%L +# Wildfly Camel :: Testsuite +# %% +# Copyright (C) 2013 - 2014 RedHat +# %% +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# #L% +### + +# Root logger option +log4j.rootLogger=DEBUG, file, console + +# Direct log messages to a log file +log4j.appender.file=org.apache.log4j.FileAppender +log4j.appender.file.file=target/test.log +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c] (%t) - %m%n +log4j.appender.file.threshold=DEBUG + +# Direct log messages to console +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.target=System.out +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c] (%t) - %m%n +log4j.appender.console.threshold=WARN ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Cannot create queue/message for Azure > ------------------------------------- > > Key: CAMEL-11999 > URL: https://issues.apache.org/jira/browse/CAMEL-11999 > Project: Camel > Issue Type: Bug > Components: camel-azure > Affects Versions: 2.20.0 > Reporter: Thomas Diesler > Assignee: Thomas Diesler > Fix For: 2.20.1, 2.21.0 > > > The Azure Storage Queue API may have changed unnoticed since the component > was incepted. > Currently it is broken in multiple places. > CrossRef: https://github.com/wildfly-extras/wildfly-camel/issues/1819 -- This message was sent by Atlassian JIRA (v6.4.14#64029)