You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2015/02/25 13:33:56 UTC
[1/3] camel git commit: [CAMEL-8349] Context should be started with
defined TCCL
Repository: camel
Updated Branches:
refs/heads/master 48d7f606f -> db94b7836
[CAMEL-8349] Context should be started with defined TCCL
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e1ad4267
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e1ad4267
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e1ad4267
Branch: refs/heads/master
Commit: e1ad426716d13f1fb08f1f9f2ab0f6a137f264d8
Parents: 48d7f60
Author: Thomas Diesler <th...@jboss.com>
Authored: Mon Feb 23 15:03:53 2015 +0100
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Feb 25 14:39:42 2015 +0800
----------------------------------------------------------------------
.../apache/camel/impl/DefaultCamelContext.java | 101 +++++++++++--------
1 file changed, 59 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/e1ad4267/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 29128bc..143b58c 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -33,10 +33,12 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
+import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
+
import javax.naming.Context;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
@@ -150,17 +152,16 @@ import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.ServiceHelper;
import org.apache.camel.util.StopWatch;
import org.apache.camel.util.StringHelper;
+import org.apache.camel.util.StringQuoteHelper;
import org.apache.camel.util.TimeUtils;
import org.apache.camel.util.URISupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.apache.camel.util.StringQuoteHelper.doubleQuote;
-
/**
* Represents the context used to configure routes and the policies to use.
*
- * @version
+ * @version
*/
@SuppressWarnings("deprecation")
public class DefaultCamelContext extends ServiceSupport implements ModelCamelContext, SuspendableService {
@@ -285,7 +286,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
// [TODO] Remove in 3.0
Container.Instance.manage(this);
}
-
+
/**
* Creates the {@link CamelContext} using the given JNDI context as the registry
*
@@ -597,7 +598,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
if (endpointType.isInstance(endpoint)) {
return endpointType.cast(endpoint);
} else {
- throw new IllegalArgumentException("The endpoint is not of type: " + endpointType
+ throw new IllegalArgumentException("The endpoint is not of type: " + endpointType
+ " but is: " + endpoint.getClass().getCanonicalName());
}
}
@@ -722,9 +723,14 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
}
}
- public void addRoutes(RoutesBuilder builder) throws Exception {
+ public void addRoutes(final RoutesBuilder builder) throws Exception {
log.debug("Adding routes from builder: {}", builder);
- builder.addRoutesToCamelContext(this);
+ doWithDefinedClassLoader(new Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ builder.addRoutesToCamelContext(DefaultCamelContext.this);
+ return null;
+ }});
}
public synchronized RoutesDefinition loadRoutesDefinition(InputStream is) throws Exception {
@@ -892,10 +898,10 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
startRouteService(routeService, false);
}
return completed;
- }
+ }
return false;
}
-
+
public synchronized void stopRoute(String routeId) throws Exception {
RouteService routeService = routeServices.get(routeId);
if (routeService != null) {
@@ -945,7 +951,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
getShutdownStrategy().shutdown(this, routes, timeout, timeUnit);
// must stop route service as well (and remove the routes from management)
stopRouteService(routeService, true);
- }
+ }
}
public synchronized boolean removeRoute(String routeId) throws Exception {
@@ -1445,7 +1451,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
String description = row[9];
// add json of the option
- buffer.append(doubleQuote(name)).append(": { ");
+ buffer.append(StringQuoteHelper.doubleQuote(name)).append(": { ");
CollectionStringBuffer csb = new CollectionStringBuffer();
if (kind != null) {
csb.append("\"kind\": \"" + kind + "\"");
@@ -1600,7 +1606,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
String description = row[9];
// add json of the option
- buffer.append(doubleQuote(name)).append(": { ");
+ buffer.append(StringQuoteHelper.doubleQuote(name)).append(": { ");
CollectionStringBuffer csb = new CollectionStringBuffer();
if (kind != null) {
csb.append("\"kind\": \"" + kind + "\"");
@@ -1758,7 +1764,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
String description = row[9];
// add json of the option
- buffer.append(doubleQuote(name)).append(": { ");
+ buffer.append(StringQuoteHelper.doubleQuote(name)).append(": { ");
CollectionStringBuffer csb = new CollectionStringBuffer();
if (kind != null) {
csb.append("\"kind\": \"" + kind + "\"");
@@ -1909,20 +1915,20 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
return answer;
}
-
+
public String getPropertyPrefixToken() {
PropertiesComponent pc = getPropertiesComponent();
-
+
if (pc != null) {
return pc.getPrefixToken();
} else {
return null;
}
}
-
+
public String getPropertySuffixToken() {
PropertiesComponent pc = getPropertiesComponent();
-
+
if (pc != null) {
return pc.getSuffixToken();
} else {
@@ -1948,14 +1954,14 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
// the parser will throw exception if property key was not found
String answer = pc.parseUri(text);
log.debug("Resolved text: {} -> {}", text, answer);
- return answer;
+ return answer;
}
}
// return original text as is
return text;
}
-
+
// Properties
// -----------------------------------------------------------------------
@@ -2287,7 +2293,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
public ServicePool<Endpoint, Producer> getProducerServicePool() {
return producerServicePool;
}
-
+
public ServicePool<Endpoint, PollingConsumer> getPollingConsumerServicePool() {
return pollingConsumerServicePool;
}
@@ -2453,26 +2459,37 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
// -----------------------------------------------------------------------
protected synchronized void doStart() throws Exception {
+ doWithDefinedClassLoader(new Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ try {
+ doStartCamel();
+ return null;
+ } catch (Exception e) {
+ // fire event that we failed to start
+ EventHelper.notifyCamelContextStartupFailed(DefaultCamelContext.this, e);
+ // rethrow cause
+ throw e;
+ }
+ }
+ });
+ }
+
+ private <T> T doWithDefinedClassLoader(Callable<T> callable) throws Exception {
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
- doStartCamel();
- } catch (Exception e) {
- // fire event that we failed to start
- EventHelper.notifyCamelContextStartupFailed(this, e);
- // rethrow cause
- throw e;
+ // Using the ApplicationClassLoader as the default for TCCL
+ if (applicationContextClassLoader != null) {
+ Thread.currentThread().setContextClassLoader(applicationContextClassLoader);
+ }
+ return callable.call();
+ } finally {
+ Thread.currentThread().setContextClassLoader(tccl);
}
}
private void doStartCamel() throws Exception {
- if (applicationContextClassLoader == null) {
- // Using the TCCL as the default value of ApplicationClassLoader
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if (cl == null) {
- // use the classloader that loaded this class
- cl = this.getClass().getClassLoader();
- }
- setApplicationContextClassLoader(cl);
- }
+
if (classResolver instanceof CamelContextAware) {
((CamelContextAware) classResolver).setCamelContext(this);
}
@@ -2507,7 +2524,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
if (getDelayer() != null && getDelayer() > 0) {
log.info("Delayer is enabled with: {} ms. on CamelContext: {}", getDelayer(), getName());
}
-
+
// register debugger
if (getDebugger() != null) {
log.info("Debugger: {} is enabled on CamelContext: {}", getDebugger(), getName());
@@ -2850,7 +2867,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
service.start();
}
-
+
private void startServices(Collection<?> services) throws Exception {
for (Object element : services) {
if (element instanceof Service) {
@@ -2936,7 +2953,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
routeService.setRemovingRoutes(removingRoutes);
stopRouteService(routeService);
}
-
+
protected void logRouteState(Route route, String state) {
if (log.isInfoEnabled()) {
if (route.getConsumer() != null) {
@@ -2946,7 +2963,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
}
}
}
-
+
protected synchronized void stopRouteService(RouteService routeService) throws Exception {
routeService.stop();
for (Route route : routeService.getRoutes()) {
@@ -3105,7 +3122,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
throw new FailedToStartRouteException(routeService.getId(),
"Multiple consumers for the same endpoint is not allowed: " + endpoint);
}
-
+
// check for multiple consumer violations with existing routes which
// have already been started, or is currently starting
List<Endpoint> existingEndpoints = new ArrayList<Endpoint>();
@@ -3313,7 +3330,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
protected boolean shouldStartRoutes() {
return isStarted() && !isStarting();
}
-
+
/**
* Gets the properties component in use.
* Returns {@code null} if no properties component is in use.
@@ -3638,7 +3655,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
public void setDebugger(Debugger debugger) {
this.debugger = debugger;
}
-
+
public UuidGenerator getUuidGenerator() {
return uuidGenerator;
}
[3/3] camel git commit: CAMEL-8401 Added the header check on the
RemoteFileProduceOverruleOnlyOnceTest
Posted by ni...@apache.org.
CAMEL-8401 Added the header check on the RemoteFileProduceOverruleOnlyOnceTest
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/db94b783
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/db94b783
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/db94b783
Branch: refs/heads/master
Commit: db94b78362dbf49d99924964e7e4b6f4a103d1cb
Parents: a1bbf2b
Author: Willem Jiang <wi...@gmail.com>
Authored: Wed Feb 25 20:33:39 2015 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Feb 25 20:33:39 2015 +0800
----------------------------------------------------------------------
.../file/remote/RemoteFileProduceOverruleOnlyOnceTest.java | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/db94b783/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileProduceOverruleOnlyOnceTest.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileProduceOverruleOnlyOnceTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileProduceOverruleOnlyOnceTest.java
index 176306d..7d7933c 100644
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileProduceOverruleOnlyOnceTest.java
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileProduceOverruleOnlyOnceTest.java
@@ -37,6 +37,7 @@ public class RemoteFileProduceOverruleOnlyOnceTest extends FtpServerTestSupport
template.sendBodyAndHeaders("direct:input", "Hello World", headers);
MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedHeaderReceived(Exchange.FILE_NAME, "/sub/hello.txt");
mock.expectedFileExists(FTP_ROOT_DIR + "/out/sub/ruled.txt", "Hello World");
mock.expectedFileExists("target/out/sub/hello.txt", "Hello World");
[2/3] camel git commit: CAMEL-8401 Restore original CamelFileName
when using CamelOverruleFileName with remote file producer
Posted by ni...@apache.org.
CAMEL-8401 Restore original CamelFileName when using CamelOverruleFileName with remote file producer
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a1bbf2bf
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a1bbf2bf
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a1bbf2bf
Branch: refs/heads/master
Commit: a1bbf2bf5f3f9c54ce2330b88b7fc312b0b033d1
Parents: e1ad426
Author: Chris Pimlott <ch...@spartansoftwareinc.com>
Authored: Tue Feb 24 16:47:19 2015 -0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Feb 25 14:46:38 2015 +0800
----------------------------------------------------------------------
.../file/remote/RemoteFileProducer.java | 15 ++++-
.../RemoteFileProduceOverruleOnlyOnceTest.java | 64 ++++++++++++++++++++
2 files changed, 78 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/a1bbf2bf/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java
index d1ed723..ab10254 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java
@@ -44,9 +44,22 @@ public class RemoteFileProducer<T> extends GenericFileProducer<T> implements Ser
return name;
}
+ @Override
public void process(Exchange exchange) throws Exception {
+ // store any existing file header which we want to keep and propagate
+ final String existing = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class);
+
+ // create the target file name
String target = createFileName(exchange);
- processExchange(exchange, target);
+
+ try {
+ processExchange(exchange, target);
+ } finally {
+ // remove the write file name header as we only want to use it once (by design)
+ exchange.getIn().removeHeader(Exchange.OVERRULE_FILE_NAME);
+ // and restore existing file name
+ exchange.getIn().setHeader(Exchange.FILE_NAME, existing);
+ }
}
protected RemoteFileOperations<T> getOperations() {
http://git-wip-us.apache.org/repos/asf/camel/blob/a1bbf2bf/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileProduceOverruleOnlyOnceTest.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileProduceOverruleOnlyOnceTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileProduceOverruleOnlyOnceTest.java
new file mode 100644
index 0000000..176306d
--- /dev/null
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileProduceOverruleOnlyOnceTest.java
@@ -0,0 +1,64 @@
+/**
+ * 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.file.remote;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class RemoteFileProduceOverruleOnlyOnceTest extends FtpServerTestSupport {
+
+ @Test
+ public void testFileToFtp() throws Exception {
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put(Exchange.FILE_NAME, "/sub/hello.txt");
+ headers.put(Exchange.OVERRULE_FILE_NAME, "/sub/ruled.txt");
+ template.sendBodyAndHeaders("direct:input", "Hello World", headers);
+
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedFileExists(FTP_ROOT_DIR + "/out/sub/ruled.txt", "Hello World");
+ mock.expectedFileExists("target/out/sub/hello.txt", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ deleteDirectory("target/out");
+ super.setUp();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:input")
+ .to("ftp://admin:admin@localhost:" + getPort()
+ + "/out/")
+ .to("file://target/out", "mock:result");
+ }
+ };
+ }
+}