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 2009/03/05 10:16:40 UTC
svn commit: r750396 - in /camel/trunk:
camel-core/src/main/java/org/apache/camel/
camel-core/src/main/java/org/apache/camel/converter/stream/
camel-core/src/main/java/org/apache/camel/impl/
camel-core/src/main/java/org/apache/camel/model/config/ camel-...
Author: ningjiang
Date: Thu Mar 5 09:16:39 2009
New Revision: 750396
URL: http://svn.apache.org/viewvc?rev=750396&view=rev
Log:
CAMEL-1425 Added the properties to the camel context
Added:
camel/trunk/camel-core/src/main/java/org/apache/camel/model/config/PropertiesType.java (with props)
camel/trunk/camel-core/src/main/java/org/apache/camel/model/config/PropertyType.java (with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
camel/trunk/camel-core/src/main/resources/org/apache/camel/model/config/jaxb.index
camel/trunk/camel-core/src/test/java/org/apache/camel/converter/stream/StreamCacheConverterTest.java
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/CamelContextAwareTest.java
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextAwareBean.xml
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?rev=750396&r1=750395&r2=750396&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Thu Mar 5 09:16:39 2009
@@ -331,6 +331,16 @@
Map<String, DataFormatType> getDataFormats();
/**
+ * Sets the properties that can be referenced in the camel context
+ */
+ void setProperties(Map<String, String> properties);
+
+ /**
+ * Gets the properties that can be referenced in the camel context
+ */
+ Map<String, String> getProperties();
+
+ /**
* Create a FactoryFinder which will be used for the loading the factory class from META-INF
* @return the factory finder
*/
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java?rev=750396&r1=750395&r2=750396&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java Thu Mar 5 09:16:39 2009
@@ -28,6 +28,7 @@
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import org.apache.camel.StreamCache;
import org.apache.camel.converter.IOConverter;
@@ -35,34 +36,13 @@
import org.apache.camel.util.IOHelper;
public class CachedOutputStream extends OutputStream {
- private static final File DEFAULT_TEMP_DIR;
- private static final int DEFAULT_THRESHOLD;
- static {
- String s = System.getProperty("org.apache.camel.util.CachedOutputStream.Threshold",
- "-1");
- int i = Integer.parseInt(s);
- if (i <= 0) {
- i = 64 * 1024;
- }
- DEFAULT_THRESHOLD = i;
-
- s = System.getProperty("org.apache.camel.util.CachedOutputStream.OutputDirectory");
- if (s != null) {
- File f = new File(s);
- if (f.exists() && f.isDirectory()) {
- DEFAULT_TEMP_DIR = f;
- } else {
- DEFAULT_TEMP_DIR = null;
- }
- } else {
- DEFAULT_TEMP_DIR = null;
- }
- }
-
+ public static final String THRESHOLD = "CamelCachedOutputStreamThreshold";
+ public static final String TEMP_DIR = "CamelCachedOutputStreamOutputDirectory";
+
protected boolean outputLocked;
protected OutputStream currentStream;
- private long threshold = DEFAULT_THRESHOLD;
+ private long threshold = 64 * 1024;
private int totalLength;
@@ -70,7 +50,7 @@
private File tempFile;
- private File outputDir = DEFAULT_TEMP_DIR;
+ private File outputDir;
private List<Object> streamList = new ArrayList<Object>();
@@ -81,9 +61,30 @@
}
public CachedOutputStream(long threshold) {
- this.threshold = threshold;
- currentStream = new ByteArrayOutputStream(2048);
- inmem = true;
+ this();
+ this.threshold = threshold;
+ }
+
+ public CachedOutputStream(Map<String, String> properties) {
+ this();
+ String value = properties.get(THRESHOLD);
+ if (value != null) {
+ int i = Integer.parseInt(value);
+ if (i > 0) {
+ threshold = i;
+ }
+ }
+ value = properties.get(TEMP_DIR);
+ if (value != null) {
+ File f = new File(value);
+ if (f.exists() && f.isDirectory()) {
+ outputDir = f;
+ } else {
+ outputDir = null;
+ }
+ } else {
+ outputDir = null;
+ }
}
/**
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java?rev=750396&r1=750395&r2=750396&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java Thu Mar 5 09:16:39 2009
@@ -72,7 +72,8 @@
@Converter
public StreamCache convertToStreamCache(InputStream stream, Exchange exchange) throws IOException {
- CachedOutputStream cos = new CachedOutputStream();
+ // set up CachedOutputStream with the properties
+ CachedOutputStream cos = new CachedOutputStream(exchange.getContext().getProperties());
IOHelper.copyAndCloseInput(stream, cos);
return cos.getStreamCache();
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=750396&r1=750395&r2=750396&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Thu Mar 5 09:16:39 2009
@@ -101,6 +101,7 @@
private Long delay;
private ErrorHandlerBuilder errorHandlerBuilder;
private Map<String, DataFormatType> dataFormats = new HashMap<String, DataFormatType>();
+ private Map<String, String> properties = new HashMap<String, String>();
private Class<? extends FactoryFinder> factoryFinderClass = FactoryFinder.class;
private Map<String, RouteService> routeServices = new HashMap<String, RouteService>();
private ClassResolver classResolver;
@@ -909,6 +910,14 @@
public void setFactoryFinderClass(Class<? extends FactoryFinder> finderClass) {
factoryFinderClass = finderClass;
}
+
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, String> properties) {
+ this.properties = properties;
+ }
public FactoryFinder createFactoryFinder() {
try {
@@ -957,6 +966,5 @@
}
}
}
-
-
+
}
Added: camel/trunk/camel-core/src/main/java/org/apache/camel/model/config/PropertiesType.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/config/PropertiesType.java?rev=750396&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/config/PropertiesType.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/config/PropertiesType.java Thu Mar 5 09:16:39 2009
@@ -0,0 +1,63 @@
+/**
+ * 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.model.config;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.model.dataformat.DataFormatType;
+
+
+/**
+ * Represents the XML type for a collection of DataFormats.
+ */
+@XmlRootElement(name = "properties")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class PropertiesType {
+ @XmlElement(name = "property", required = false)
+ private List<PropertyType> properties;
+
+ public PropertiesType() {
+
+ }
+
+ public void setProperties(List<PropertyType> properties) {
+ this.properties = properties;
+ }
+
+ public List<PropertyType> getProperties() {
+ return properties;
+ }
+
+ /***
+ * @return A Map of the contained DataFormatType's indexed by id.
+ */
+ public Map<String, String> asMap() {
+ Map<String, String> propertiesAsMap = new HashMap<String, String>();
+ for (PropertyType propertyType : getProperties()) {
+ propertiesAsMap.put(propertyType.getKey(), propertyType.getValue());
+ }
+ return propertiesAsMap;
+ }
+
+}
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/model/config/PropertiesType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/model/config/PropertiesType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/camel-core/src/main/java/org/apache/camel/model/config/PropertyType.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/config/PropertyType.java?rev=750396&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/config/PropertyType.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/config/PropertyType.java Thu Mar 5 09:16:39 2009
@@ -0,0 +1,52 @@
+/**
+ * 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.model.config;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "property")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class PropertyType {
+ @XmlAttribute(required = true)
+ String key;
+ @XmlAttribute(required = true)
+ String value;
+
+ public PropertyType() {
+
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+}
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/model/config/PropertyType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/model/config/PropertyType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: camel/trunk/camel-core/src/main/resources/org/apache/camel/model/config/jaxb.index
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/config/jaxb.index?rev=750396&r1=750395&r2=750396&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/resources/org/apache/camel/model/config/jaxb.index (original)
+++ camel/trunk/camel-core/src/main/resources/org/apache/camel/model/config/jaxb.index Thu Mar 5 09:16:39 2009
@@ -14,5 +14,7 @@
## See the License for the specific language governing permissions and
## limitations under the License.
## ------------------------------------------------------------------------
+PropertyType
+PropertiesType
StreamResequencerConfig
BatchResequencerConfig
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/converter/stream/StreamCacheConverterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/stream/StreamCacheConverterTest.java?rev=750396&r1=750395&r2=750396&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/converter/stream/StreamCacheConverterTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/converter/stream/StreamCacheConverterTest.java Thu Mar 5 09:16:39 2009
@@ -17,6 +17,9 @@
package org.apache.camel.converter.stream;
import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
@@ -60,6 +63,24 @@
assertNotNull(IOConverter.toString(cache));
assertNotNull(IOConverter.toString(cache));
}
+
+ public void testConvertToStreamCacheInpuStreamWithFileCache() throws Exception {
+ // set up the properties
+ Map<String, String> properties = new HashMap<String, String>();
+ properties.put(CachedOutputStream.THRESHOLD, "1");
+ exchange.getContext().setProperties(properties);
+ InputStream is = getTestFileStream();
+ InputStream cache = (InputStream)converter.convertToStreamCache(is, exchange);
+ assertNotNull(IOConverter.toString(cache));
+ try {
+ // since the stream is closed you delete the temp file
+ // reset will not work any more
+ cache.reset();
+ fail("except the exception here");
+ } catch (Exception exception) {
+ // do nothing
+ }
+ }
protected InputStream getTestFileStream() {
Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=750396&r1=750395&r2=750396&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java Thu Mar 5 09:16:39 2009
@@ -42,6 +42,7 @@
import org.apache.camel.model.RouteBuilderRef;
import org.apache.camel.model.RouteContainer;
import org.apache.camel.model.RouteType;
+import org.apache.camel.model.config.PropertiesType;
import org.apache.camel.model.dataformat.DataFormatsType;
import org.apache.camel.processor.interceptor.Debugger;
import org.apache.camel.processor.interceptor.Delayer;
@@ -89,16 +90,18 @@
private String errorHandlerRef;
@XmlAttribute(required = false)
private Boolean shouldStartContext = Boolean.TRUE;
+ @XmlElement(name = "properties", required = false)
+ private PropertiesType properties;
@XmlElement(name = "package", required = false)
private String[] packages = {};
@XmlElement(name = "jmxAgent", type = CamelJMXAgentType.class, required = false)
- private CamelJMXAgentType camelJMXAgent;
+ private CamelJMXAgentType camelJMXAgent;
@XmlElements({
@XmlElement(name = "beanPostProcessor", type = CamelBeanPostProcessor.class, required = false),
@XmlElement(name = "template", type = CamelTemplateFactoryBean.class, required = false),
@XmlElement(name = "proxy", type = CamelProxyFactoryType.class, required = false),
@XmlElement(name = "export", type = CamelServiceExporterType.class, required = false)})
- private List beans;
+ private List beans;
@XmlElement(name = "routeBuilderRef", required = false)
private List<RouteBuilderRef> builderRefs = new ArrayList<RouteBuilderRef>();
@XmlElement(name = "endpoint", required = false)
@@ -110,7 +113,7 @@
@XmlElement(name = "intercept", required = false)
private List<InterceptType> intercepts = new ArrayList<InterceptType>();
@XmlElement(name = "route", required = false)
- private List<RouteType> routes = new ArrayList<RouteType>();
+ private List<RouteType> routes = new ArrayList<RouteType>();
@XmlTransient
private SpringCamelContext context;
@XmlTransient
@@ -151,7 +154,9 @@
public void afterPropertiesSet() throws Exception {
// TODO there should be a neater way to do this!
-
+ if (properties != null) {
+ getContext().setProperties(properties.asMap());
+ }
// set the resolvers first
PackageScanClassResolver packageResolver = getBeanForType(PackageScanClassResolver.class);
if (packageResolver != null) {
@@ -382,6 +387,14 @@
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
+
+ public PropertiesType getProperties() {
+ return properties;
+ }
+
+ public void setProperties(PropertiesType properties) {
+ this.properties = properties;
+ }
public String[] getPackages() {
return packages;
Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java?rev=750396&r1=750395&r2=750396&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java Thu Mar 5 09:16:39 2009
@@ -32,6 +32,7 @@
import org.apache.camel.builder.xml.Namespaces;
import org.apache.camel.model.FromType;
import org.apache.camel.model.SendType;
+import org.apache.camel.model.config.PropertiesType;
import org.apache.camel.model.dataformat.ArtixDSDataFormat;
import org.apache.camel.model.dataformat.JaxbDataFormat;
import org.apache.camel.model.dataformat.SerializationDataFormat;
@@ -167,7 +168,7 @@
classes.add(org.apache.camel.spring.CamelContextFactoryBean.class);
classes.add(ExchangePattern.class);
classes.add(org.apache.camel.model.RouteType.class);
- classes.add(org.apache.camel.model.config.StreamResequencerConfig.class);
+ classes.add(org.apache.camel.model.config.StreamResequencerConfig.class);
classes.add(org.apache.camel.model.dataformat.DataFormatType.class);
classes.add(org.apache.camel.model.language.ExpressionType.class);
classes.add(org.apache.camel.model.loadbalancer.LoadBalancerType.class);
@@ -201,6 +202,7 @@
builder.addPropertyValue("dataFormats", factoryBean.getDataFormats());
builder.addPropertyValue("exceptionClauses", factoryBean.getExceptionClauses());
builder.addPropertyValue("builderRefs", factoryBean.getBuilderRefs());
+ builder.addPropertyValue("properties", factoryBean.getProperties());
if (factoryBean.getPackages().length > 0) {
builder.addPropertyValue("packages", factoryBean.getPackages());
Modified: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/CamelContextAwareTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/CamelContextAwareTest.java?rev=750396&r1=750395&r2=750396&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/CamelContextAwareTest.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/CamelContextAwareTest.java Thu Mar 5 09:16:39 2009
@@ -16,6 +16,8 @@
*/
package org.apache.camel.spring;
+import java.util.Map;
+
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -27,6 +29,10 @@
public void testInjectionPoints() throws Exception {
assertNotNull("No CamelContext injected!", bean.getCamelContext());
+ Map<String, String> properties = bean.getCamelContext().getProperties();
+ assertNotNull("the properties should not been null", properties);
+ assertEquals("No properties injected", properties.size(), 1);
+ assertEquals("Should get the value of org.apache.camel.test", properties.get("org.apache.camel.test"), "this is a test");
}
@Override
Modified: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextAwareBean.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextAwareBean.xml?rev=750396&r1=750395&r2=750396&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextAwareBean.xml (original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextAwareBean.xml Thu Mar 5 09:16:39 2009
@@ -23,12 +23,9 @@
">
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
-<!--
- <route>
- <from uri="seda:a"/>
- <to uri="seda:b"/>
- </route>
--->
+ <properties>
+ <property key="org.apache.camel.test" value="this is a test"/>
+ </properties>
<beanPostProcessor/>
</camelContext>