This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch CAMEL-13678
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 368daaeb855249e9cc349b788f0b196de96adf6c
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Sun Jul 7 20:25:10 2019 +0200

    CAMEL-13678: Move attachments out of camel-core into camel-attachments.
---
 MIGRATION.md                                       |  11 ++
 .../org/apache/camel/attachment/Attachment.java    |   2 -
 .../BeanWithAttachmentAnnotationTest.java          | 125 ---------------------
 .../org/apache/camel/component/bean/BeanInfo.java  |   8 +-
 .../apache/camel/component/bean/MethodInfo.java    |   4 -
 .../camel/component/mock/MockExpressionClause.java |   7 --
 .../mock/MockExpressionClauseSupport.java          |   7 --
 .../java/org/apache/camel/AttachmentObjects.java   |  33 ------
 .../main/java/org/apache/camel/Attachments.java    |  33 ------
 9 files changed, 12 insertions(+), 218 deletions(-)

diff --git a/MIGRATION.md b/MIGRATION.md
index 24d68ef..ea8a343 100644
--- a/MIGRATION.md
+++ b/MIGRATION.md
@@ -35,6 +35,7 @@ You may find how to do that in the examples.
 
 We have also modularized many of the core components and moved them out of 
`camel-core` to individual components:
 
+- camel-attachments
 - camel-bean
 - camel-browse
 - camel-controlbus
@@ -130,6 +131,16 @@ And the same for `<setProperty>`.
 
 The `camel-script` component has been removed and there is no support for 
javax.script, which is also deprecated in the JDK and to be removed from Java 
11 onwards.
 
+### Attachments API on Message
+
+The attachments API (javax.activation) has been moved out of 
`org.apache.camel.message` into an extension 
`org.apache.camel.attachment.AttachmentMessage` from the `camel-attachments` 
JAR.
+
+To use this API you can get it via the `getMessage` method on `Exchange`:
+
+    AttachmentMessage am = exchange.getMessage(AttachmentMessage.class);
+    am.addAttachment("myAtt", new DataHandler(...));
+
+
 ### Mock component
 
 The `mock` component has been moved out of `camel-core` and as part of this 
work, we had to remove a number of methods on its _assertion clause builder_ 
that were seldom in use. 
diff --git 
a/components/camel-attachments/src/main/java/org/apache/camel/attachment/Attachment.java
 
b/components/camel-attachments/src/main/java/org/apache/camel/attachment/Attachment.java
index 9ad220a..d88aecf 100644
--- 
a/components/camel-attachments/src/main/java/org/apache/camel/attachment/Attachment.java
+++ 
b/components/camel-attachments/src/main/java/org/apache/camel/attachment/Attachment.java
@@ -28,8 +28,6 @@ import org.apache.camel.Message;
  */
 public interface Attachment {
 
-    // TODO: Move this to camel-attachment
-
     /**
      * Return a DataHandler for the content within this attachment.
      *
diff --git 
a/components/camel-attachments/src/test/java/org/apache/camel/attachment/BeanWithAttachmentAnnotationTest.java
 
b/components/camel-attachments/src/test/java/org/apache/camel/attachment/BeanWithAttachmentAnnotationTest.java
deleted file mode 100644
index c3d2d30..0000000
--- 
a/components/camel-attachments/src/test/java/org/apache/camel/attachment/BeanWithAttachmentAnnotationTest.java
+++ /dev/null
@@ -1,125 +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.camel.attachment;
-
-import java.util.Map;
-import javax.activation.DataHandler;
-import javax.activation.FileDataSource;
-import javax.naming.Context;
-
-import org.apache.camel.AttachmentObjects;
-import org.apache.camel.Attachments;
-import org.apache.camel.Exchange;
-import org.apache.camel.ExchangePattern;
-import org.apache.camel.Processor;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.support.jndi.JndiContext;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
-
-@Ignore("Need to make camel-bean support this")
-public class BeanWithAttachmentAnnotationTest extends CamelTestSupport {
-    
-    @Test
-    public void testBeanWithOldAnnotationAndExchangeTest() throws Exception {
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedBodiesReceived("attachment");
-        
-        template.send("direct:inOld", new Processor() {
-
-            public void process(Exchange exchange) throws Exception {
-                exchange.setPattern(ExchangePattern.InOut);
-                AttachmentMessage m = exchange.getIn(AttachmentMessage.class);
-                m.addAttachmentObject("attachment", new DefaultAttachment(new 
FileDataSource("src/test/org/apache/camel/attachment/BeanWithAttachmentAnnotationTest.java")));
-            }
-            
-        });
-
-        mock.assertIsSatisfied();
-    }
-
-    @Test
-    public void testBeanWithAnnotationAndExchangeTest() throws Exception {
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedBodiesReceived("attachment");
-        
-        template.send("direct:in", new Processor() {
-
-            public void process(Exchange exchange) throws Exception {
-                exchange.setPattern(ExchangePattern.InOut);
-                AttachmentMessage m = exchange.getIn(AttachmentMessage.class);
-                m.addAttachmentObject("attachment", new DefaultAttachment(new 
FileDataSource("src/test/org/apache/camel/attachment/BeanWithAttachmentAnnotationTest.java")));
-            }
-            
-        });
-
-        mock.assertIsSatisfied();
-    }
-
-    protected Context createJndiContext() throws Exception {
-        JndiContext answer = new JndiContext();
-        answer.bind("processorOld", new AttachmentProcessorOld());
-        answer.bind("processor", new AttachmentProcessor());
-        return answer;
-    }
-
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            public void configure() throws Exception {
-                from("direct:in").to("bean:processor").to("mock:result");
-                from("direct:inOld").to("bean:processorOld").to("mock:result");
-            }
-        };
-    }
-
-    public static class AttachmentProcessorOld {
-        // START SNIPPET: e1
-        public String doSomething(@Attachments Map<String, DataHandler> 
attachments) {
-            Assert.assertNotNull(attachments);
-            Assert.assertEquals("The attache size is wrong", 1, 
attachments.size());
-            String key = attachments.keySet().iterator().next();
-            Assert.assertNotNull(key);
-            Assert.assertNotNull(attachments.get(key));
-            DataHandler handler = attachments.get(key);
-            Assert.assertNotNull(handler);
-            Assert.assertTrue("The data source should be a instance of 
FileDataSource", handler.getDataSource() instanceof FileDataSource);
-            return key;
-        }
-        // END SNIPPET: e1
-    }
-
-    public static class AttachmentProcessor {
-        // START SNIPPET: e2
-        public String doSomething(@AttachmentObjects Map<String, Attachment> 
attachments) {
-            Assert.assertNotNull(attachments);
-            Assert.assertEquals("The attache size is wrong", 1, 
attachments.size());
-            String key = attachments.keySet().iterator().next();
-            Assert.assertNotNull(key);
-            Assert.assertNotNull(attachments.get(key));
-            Attachment attachment = attachments.get(key);
-            Assert.assertNotNull(attachment);
-            DataHandler handler = attachment.getDataHandler();
-            Assert.assertNotNull(handler);
-            Assert.assertTrue("The data source should be a instance of 
FileDataSource", handler.getDataSource() instanceof FileDataSource);
-            return key;
-        }
-        // END SNIPPET: e2
-    }
-}
diff --git 
a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java
 
b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java
index ae8818d..088ca1f 100644
--- 
a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java
+++ 
b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java
@@ -30,8 +30,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.camel.AttachmentObjects;
-import org.apache.camel.Attachments;
 import org.apache.camel.Body;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
@@ -965,11 +963,7 @@ public class BeanInfo {
 
     private Expression 
createParameterUnmarshalExpressionForAnnotation(Class<?> clazz, Method method, 
             Class<?> parameterType, Annotation annotation) {
-        if (annotation instanceof AttachmentObjects) {
-            return ExpressionBuilder.attachmentObjectsExpression();
-        } else if (annotation instanceof Attachments) {
-            return ExpressionBuilder.attachmentsExpression();
-        } else if (annotation instanceof ExchangeProperty) {
+        if (annotation instanceof ExchangeProperty) {
             ExchangeProperty propertyAnnotation = (ExchangeProperty)annotation;
             return 
ExpressionBuilder.exchangePropertyExpression(propertyAnnotation.value());
         } else if (annotation instanceof ExchangeProperties) {
diff --git 
a/components/camel-bean/src/main/java/org/apache/camel/component/bean/MethodInfo.java
 
b/components/camel-bean/src/main/java/org/apache/camel/component/bean/MethodInfo.java
index bdc6a00..1fa3374 100644
--- 
a/components/camel-bean/src/main/java/org/apache/camel/component/bean/MethodInfo.java
+++ 
b/components/camel-bean/src/main/java/org/apache/camel/component/bean/MethodInfo.java
@@ -331,10 +331,6 @@ public class MethodInfo {
             old = exchange.getOut();
             // propagate headers
             
exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());
-            // propagate attachments
-            if (exchange.getIn().hasAttachments()) {
-                
exchange.getOut().getAttachments().putAll(exchange.getIn().getAttachments());
-            }
         } else {
             old = exchange.getIn();
         }
diff --git 
a/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockExpressionClause.java
 
b/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockExpressionClause.java
index c12f617..f21f86b 100644
--- 
a/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockExpressionClause.java
+++ 
b/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockExpressionClause.java
@@ -295,13 +295,6 @@ public class MockExpressionClause<T> implements 
Expression, Predicate {
     }
 
     /**
-     * An expression of the inbound message attachments
-     */
-    public T attachments() {
-        return delegate.attachments();
-    }
-
-    /**
      * An expression of an exchange property of the given name
      */
     public T exchangeProperty(String name) {
diff --git 
a/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockExpressionClauseSupport.java
 
b/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockExpressionClauseSupport.java
index 0f0bcb3..f06d764 100644
--- 
a/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockExpressionClauseSupport.java
+++ 
b/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockExpressionClauseSupport.java
@@ -147,13 +147,6 @@ public class MockExpressionClauseSupport<T> {
     }
 
     /**
-     * An expression of the inbound message attachments
-     */
-    public T attachments() {
-        return 
expression(ExpressionBuilder.attachmentObjectValuesExpression());
-    }
-
-    /**
      * An expression of the exchange pattern
      */
     public T exchangePattern() {
diff --git 
a/core/camel-api/src/main/java/org/apache/camel/AttachmentObjects.java 
b/core/camel-api/src/main/java/org/apache/camel/AttachmentObjects.java
deleted file mode 100644
index d8b879a..0000000
--- a/core/camel-api/src/main/java/org/apache/camel/AttachmentObjects.java
+++ /dev/null
@@ -1,33 +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.camel;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Marks a parameter as being Map of attachments as {@link Attachment} objects
- * of an inbound {@link Message}
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Documented
-@Target({ElementType.PARAMETER })
-public @interface AttachmentObjects {
-}
diff --git a/core/camel-api/src/main/java/org/apache/camel/Attachments.java 
b/core/camel-api/src/main/java/org/apache/camel/Attachments.java
deleted file mode 100644
index c7b18fc..0000000
--- a/core/camel-api/src/main/java/org/apache/camel/Attachments.java
+++ /dev/null
@@ -1,33 +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.camel;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Marks a parameter as being Map of attachments as
- * {@link javax.activation.DataHandler} objects of an inbound {@link Message}
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Documented
-@Target({ElementType.PARAMETER })
-public @interface Attachments {
-}

Reply via email to