You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/01/19 19:49:19 UTC

[1/3] camel git commit: CAMEL-9522: Fixed potential NPE

Repository: camel
Updated Branches:
  refs/heads/master c0561ed7c -> a4b611d7c


CAMEL-9522: Fixed potential NPE


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/85ad128f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/85ad128f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/85ad128f

Branch: refs/heads/master
Commit: 85ad128f237a684b9a183c54ad2d5318a4299e12
Parents: c0561ed
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jan 19 18:49:04 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jan 19 18:49:04 2016 +0100

----------------------------------------------------------------------
 .../org/apache/camel/model/language/ExpressionDefinition.java | 7 +++++++
 1 file changed, 7 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/85ad128f/camel-core/src/main/java/org/apache/camel/model/language/ExpressionDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/language/ExpressionDefinition.java b/camel-core/src/main/java/org/apache/camel/model/language/ExpressionDefinition.java
index cf8b1a5..e77f454 100644
--- a/camel-core/src/main/java/org/apache/camel/model/language/ExpressionDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/language/ExpressionDefinition.java
@@ -33,6 +33,7 @@ import org.apache.camel.AfterPropertiesConfigured;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
+import org.apache.camel.NoSuchLanguageException;
 import org.apache.camel.Predicate;
 import org.apache.camel.model.OtherAttributesAware;
 import org.apache.camel.spi.Language;
@@ -156,6 +157,9 @@ public class ExpressionDefinition implements Expression, Predicate, OtherAttribu
             } else if (getExpression() != null) {
                 ObjectHelper.notNull("language", getLanguage());
                 Language language = camelContext.resolveLanguage(getLanguage());
+                if (language == null) {
+                    throw new NoSuchLanguageException(getLanguage());
+                }
                 String exp = getExpression();
                 // should be true by default
                 boolean isTrim = getTrim() == null || getTrim();
@@ -184,6 +188,9 @@ public class ExpressionDefinition implements Expression, Predicate, OtherAttribu
             } else if (getExpression() != null) {
                 ObjectHelper.notNull("language", getLanguage());
                 Language language = camelContext.resolveLanguage(getLanguage());
+                if (language == null) {
+                    throw new NoSuchLanguageException(getLanguage());
+                }
                 String exp = getExpression();
                 // should be true by default
                 boolean isTrim = getTrim() == null || getTrim();


[3/3] camel git commit: CAMEL-9462: Added unit test

Posted by da...@apache.org.
CAMEL-9462: Added unit test


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a4b611d7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a4b611d7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a4b611d7

Branch: refs/heads/master
Commit: a4b611d7caf52eace3233c8cfee00bdf601c47e5
Parents: 5f58e20
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jan 19 19:49:02 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jan 19 19:49:02 2016 +0100

----------------------------------------------------------------------
 .../jetty/JettyBridgeHostHeaderIssueTest.java   | 78 ++++++++++++++++++++
 1 file changed, 78 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a4b611d7/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyBridgeHostHeaderIssueTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyBridgeHostHeaderIssueTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyBridgeHostHeaderIssueTest.java
new file mode 100644
index 0000000..72074db
--- /dev/null
+++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyBridgeHostHeaderIssueTest.java
@@ -0,0 +1,78 @@
+/**
+ * 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.itest.jetty;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class JettyBridgeHostHeaderIssueTest extends CamelTestSupport {
+
+    private int port;
+    private int port2;
+    private int port3;
+
+    @Test
+    public void testHostHeader() throws Exception {
+        // TODO: the host header is removed in bridgeEndpoint in the http4 producer, that seems wrong
+        // as Camel as a reverse-proxy should update the host header accordingly
+
+
+        Exchange reply = template.request("http4:localhost:" + port + "/myapp", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody("Hello World");
+            }
+        });
+        assertNotNull(reply);
+        assertEquals("foo", reply.getOut().getBody(String.class));
+
+        Exchange reply2 = template.request("http4:localhost:" + port + "/myapp", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody("Bye World");
+            }
+        });
+        assertNotNull(reply2);
+        assertEquals("bar", reply2.getOut().getBody(String.class));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        port = AvailablePortFinder.getNextAvailable(12000);
+        port2 = AvailablePortFinder.getNextAvailable(12100);
+        port3 = AvailablePortFinder.getNextAvailable(12200);
+
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("jetty:http://localhost:" + port + "/myapp?matchOnUriPrefix=true")
+                    .loadBalance().roundRobin()
+                        .to("http4://localhost:" + port2 + "/foo?bridgeEndpoint=true&throwExceptionOnFailure=false")
+                        .to("http4://localhost:" + port3 + "/bar?bridgeEndpoint=true&throwExceptionOnFailure=false");
+
+                from("jetty:http://localhost:" + port2 + "/foo").transform().constant("foo");
+
+                from("jetty:http://localhost:" + port3 + "/bar").transform().constant("bar");
+            }
+        };
+    }
+}
+


[2/3] camel git commit: CAMEL-9524: file consumer - Allow to turn on|off probe content type

Posted by da...@apache.org.
CAMEL-9524: file consumer - Allow to turn on|off probe content type


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5f58e203
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5f58e203
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5f58e203

Branch: refs/heads/master
Commit: 5f58e203eba001a77e90bf035169406cda3cf158
Parents: 85ad128
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jan 19 19:17:52 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jan 19 19:17:52 2016 +0100

----------------------------------------------------------------------
 .../apache/camel/component/file/FileConsumer.java | 18 ++++++++++++++++--
 .../apache/camel/component/file/FileEndpoint.java | 16 ++++++++++++++++
 .../apache/camel/component/file/GenericFile.java  | 16 +++++++++++++---
 .../camel/component/file/FileConfigureTest.java   |  2 +-
 .../component/file/GenericFileMessageTest.java    |  8 +++-----
 .../camel/language/FileLanguageExtSingleTest.java |  2 +-
 .../apache/camel/language/FileLanguageTest.java   |  4 ++--
 7 files changed, 52 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5f58e203/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java b/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
index 3d55e70..11aaf05 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
@@ -80,7 +80,7 @@ public class FileConsumer extends GenericFileConsumer<File> {
             }
 
             // creates a generic file
-            GenericFile<File> gf = asGenericFile(endpointPath, file, getEndpoint().getCharset());
+            GenericFile<File> gf = asGenericFile(endpointPath, file, getEndpoint().getCharset(), getEndpoint().isProbeContentType());
 
             if (file.isDirectory()) {
                 if (endpoint.isRecursive() && depth < endpoint.getMaxDepth() && isValidFile(gf, true, files)) {
@@ -124,9 +124,23 @@ public class FileConsumer extends GenericFileConsumer<File> {
      * @param endpointPath the starting directory the endpoint was configured with
      * @param file the source file
      * @return wrapped as a GenericFile
+     * @deprecated use {@link #asGenericFile(String, File, String, boolean)}
      */
+    @Deprecated
     public static GenericFile<File> asGenericFile(String endpointPath, File file, String charset) {
-        GenericFile<File> answer = new GenericFile<File>();
+        return asGenericFile(endpointPath, file, charset, false);
+    }
+
+    /**
+     * Creates a new GenericFile<File> based on the given file.
+     *
+     * @param endpointPath the starting directory the endpoint was configured with
+     * @param file the source file
+     * @param probeContentType whether to probe the content type of the file or not
+     * @return wrapped as a GenericFile
+     */
+    public static GenericFile<File> asGenericFile(String endpointPath, File file, String charset, boolean probeContentType) {
+        GenericFile<File> answer = new GenericFile<File>(probeContentType);
         // use file specific binding
         answer.setBinding(new FileBinding());
 

http://git-wip-us.apache.org/repos/asf/camel/blob/5f58e203/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
index 94802f6..2d51753 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
@@ -18,9 +18,11 @@ package org.apache.camel.component.file;
 
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.nio.file.Files;
 
 import org.apache.camel.Component;
 import org.apache.camel.Exchange;
+import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.processor.idempotent.MemoryIdempotentRepository;
 import org.apache.camel.spi.Metadata;
@@ -46,6 +48,8 @@ public class FileEndpoint extends GenericFileEndpoint<File> {
     private boolean renameUsingCopy;
     @UriParam(label = "producer,advanced", defaultValue = "true")
     private boolean forceWrites = true;
+    @UriParam(label = "consumer,advanced")
+    private boolean probeContentType;
 
     public FileEndpoint() {
         // use marker file as default exclusive read locks
@@ -209,4 +213,16 @@ public class FileEndpoint extends GenericFileEndpoint<File> {
     public void setForceWrites(boolean forceWrites) {
         this.forceWrites = forceWrites;
     }
+
+    public boolean isProbeContentType() {
+        return probeContentType;
+    }
+
+    /**
+     * Whether to enable probing of the content type. If enable then the consumer uses {@link Files#probeContentType(java.nio.file.Path)} to
+     * determine the content-type of the file, and store that as a header with key {@link Exchange#FILE_CONTENT_TYPE} on the {@link Message}.
+     */
+    public void setProbeContentType(boolean probeContentType) {
+        this.probeContentType = probeContentType;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/5f58e203/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java b/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
index e517550..9c8bc46 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
@@ -35,6 +35,8 @@ import org.slf4j.LoggerFactory;
 public class GenericFile<T> implements WrappedFile<T>  {
     private static final Logger LOG = LoggerFactory.getLogger(GenericFile.class);
 
+    private final boolean probeContentType;
+
     private String copyFromAbsoluteFilePath;
     private String endpointPath;
     private String fileName;
@@ -49,6 +51,14 @@ public class GenericFile<T> implements WrappedFile<T>  {
     private boolean directory;
     private String charset;
 
+    public GenericFile() {
+        this(false);
+    }
+
+    public GenericFile(boolean probeContentType) {
+        this.probeContentType = probeContentType;
+    }
+
     public char getFileSeparator() {
         return File.separatorChar;
     }
@@ -135,13 +145,13 @@ public class GenericFile<T> implements WrappedFile<T>  {
             message.setHeader(Exchange.FILE_NAME_CONSUMED, getFileName());
             message.setHeader("CamelFileAbsolute", isAbsolute());
             message.setHeader("CamelFileAbsolutePath", getAbsoluteFilePath());
-            
-            if (file instanceof File) {
+
+            if (probeContentType && file instanceof File) {
                 File f = (File) file;
                 Path path = f.toPath();
                 try {
                     message.setHeader(Exchange.FILE_CONTENT_TYPE, Files.probeContentType(path));
-                } catch (Exception ex) {
+                } catch (Throwable e) {
                     // just ignore the exception
                 }
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/5f58e203/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java b/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java
index 3e1f8c0..89939a6 100644
--- a/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java
@@ -122,7 +122,7 @@ public class FileConfigureTest extends ContextTestSupport {
             assertDirectoryEquals("For uri: " + endpointUri + " the file is not equal", expectedPath, path);
 
             file = new File(expectedPath + (expectedPath.endsWith(File.separator) ? "" : File.separator) + EXPECT_FILE);
-            GenericFile<File> consumedFile = FileConsumer.asGenericFile(endpoint.getFile().getPath(), file, null);
+            GenericFile<File> consumedFile = FileConsumer.asGenericFile(endpoint.getFile().getPath(), file, null, false);
 
             assertEquals(EXPECT_FILE, consumedFile.getRelativeFilePath());
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/5f58e203/camel-core/src/test/java/org/apache/camel/component/file/GenericFileMessageTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/GenericFileMessageTest.java b/camel-core/src/test/java/org/apache/camel/component/file/GenericFileMessageTest.java
index 5382622..6108029 100644
--- a/camel-core/src/test/java/org/apache/camel/component/file/GenericFileMessageTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/file/GenericFileMessageTest.java
@@ -28,7 +28,7 @@ public class GenericFileMessageTest extends ContextTestSupport {
         GenericFileMessage<File> message = new GenericFileMessage<File>(); 
         assertStringContains(message.toString(), "org.apache.camel.component.file.GenericFileMessage@");
         
-        GenericFile<File> file = new GenericFile<File>();
+        GenericFile<File> file = new GenericFile<File>(true);
         file.setFileName("target/test.txt");
         file.setFile(new File("target/test.txt"));
         message = new GenericFileMessage<File>(file); 
@@ -37,13 +37,11 @@ public class GenericFileMessageTest extends ContextTestSupport {
     }
     
     public void testGenericFileContentType() throws Exception {
-        GenericFileMessage<File> message = new GenericFileMessage<File>(); 
-        
-        GenericFile<File> file = new GenericFile<File>();
+        GenericFile<File> file = new GenericFile<File>(true);
         file.setEndpointPath("target");
         file.setFileName("target");
         file.setFile(new File("target/camel-core-test.log"));
-        message = new GenericFileMessage<File>(file); 
+        GenericFileMessage<File> message = new GenericFileMessage<File>(file);
         file.populateHeaders(message);
         assertEquals("Get a wrong file content type", "txt", message.getHeader(Exchange.FILE_CONTENT_TYPE));
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/5f58e203/camel-core/src/test/java/org/apache/camel/language/FileLanguageExtSingleTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/language/FileLanguageExtSingleTest.java b/camel-core/src/test/java/org/apache/camel/language/FileLanguageExtSingleTest.java
index ccdc314..3d82dfe 100644
--- a/camel-core/src/test/java/org/apache/camel/language/FileLanguageExtSingleTest.java
+++ b/camel-core/src/test/java/org/apache/camel/language/FileLanguageExtSingleTest.java
@@ -54,7 +54,7 @@ public class FileLanguageExtSingleTest extends LanguageTestSupport {
 
         // get the file handle
         file = new File("target/filelanguage/test/bye.def.txt");
-        GenericFile<File> gf = FileConsumer.asGenericFile("target/filelanguage", file, null);
+        GenericFile<File> gf = FileConsumer.asGenericFile("target/filelanguage", file, null, false);
 
         FileEndpoint endpoint = getMandatoryEndpoint(uri, FileEndpoint.class);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/5f58e203/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java b/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
index 1e98e1d..b108a60 100644
--- a/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
+++ b/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
@@ -169,7 +169,7 @@ public class FileLanguageTest extends LanguageTestSupport {
         file = new File("target/filelanguage/test/bigfile.tar.gz");
 
         String uri = "file://target/filelanguage?fileExist=Override";
-        GenericFile<File> gf = FileConsumer.asGenericFile("target/filelanguage", file, null);
+        GenericFile<File> gf = FileConsumer.asGenericFile("target/filelanguage", file, null, false);
 
         FileEndpoint endpoint = getMandatoryEndpoint(uri, FileEndpoint.class);
 
@@ -188,7 +188,7 @@ public class FileLanguageTest extends LanguageTestSupport {
 
         // get the file handle
         file = new File("target/filelanguage/test/hello.txt");
-        GenericFile<File> gf = FileConsumer.asGenericFile("target/filelanguage", file, null);
+        GenericFile<File> gf = FileConsumer.asGenericFile("target/filelanguage", file, null, false);
 
         FileEndpoint endpoint = getMandatoryEndpoint(uri, FileEndpoint.class);