Author: ningjiang
Date: Mon Dec 7 12:50:12 2009
New Revision: 887914
URL: http://svn.apache.org/viewvc?rev=887914&view=rev
Log:
CAMEL-2264 support to specify the jndi properties file location in
org.apache.camel.guice.Main
Added:
camel/trunk/examples/camel-example-guice-jms/src/main/resources/guicejndi.properties
(props changed)
- copied unchanged from r887825,
camel/trunk/examples/camel-example-guice-jms/src/main/resources/jndi.properties
Removed:
camel/trunk/examples/camel-example-guice-jms/src/main/resources/jndi.properties
Modified:
camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/Main.java
camel/trunk/examples/camel-example-guice-jms/pom.xml
camel/trunk/examples/camel-example-guice-jms/src/main/java/org/apache/camel/example/guice/jms/OSGiCamelContextProvider.java
camel/trunk/examples/camel-example-guice-jms/src/test/java/org/apache/camel/example/guice/jms/IntegrationTest.java
Modified:
camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/Main.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/Main.java?rev=887914&r1=887913&r2=887914&view=diff
==============================================================================
---
camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/Main.java
(original)
+++
camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/Main.java
Mon Dec 7 12:50:12 2009
@@ -16,7 +16,10 @@
*/
package org.apache.camel.guice;
+import java.net.URL;
+import java.util.LinkedList;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;
import javax.naming.Context;
@@ -33,6 +36,7 @@
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.impl.MainSupport;
+import org.apache.camel.util.ObjectHelper;
import org.apache.camel.view.ModelFileGenerator;
import org.guiceyfruit.Injectors;
@@ -45,18 +49,28 @@
public class Main extends MainSupport {
private static Main instance;
private Injector injector;
-
-
+ private String jndiProperties;
+
public Main() {
-/*
- addOption(new ParameterOption("a", "applicationContext",
- "Sets the classpath based spring ApplicationContext",
"applicationContext") {
+
+ addOption(new ParameterOption("j", "jndiProperties",
+ "Sets the classpath based jndi properties file location",
"jndiProperties") {
+ @Override
protected void doProcess(String arg, String parameter,
LinkedList<String> remainingArgs) {
- setApplicationContextUri(parameter);
+ setJndiProperties(parameter);
+
}
});
-*/
+
+ }
+
+ public void setJndiProperties(String properties) {
+ this.jndiProperties = properties;
+ }
+
+ public String getJndiProperties() {
+ return this.jndiProperties;
}
public static void main(String... args) throws Exception {
@@ -88,7 +102,18 @@
// Implementation methods
//
-------------------------------------------------------------------------
protected Injector getInjectorFromContext() throws Exception {
- Context context = new InitialContext();
+ Context context = null;
+ URL jndiPropertiesUrl = null;
+ if (ObjectHelper.isNotEmpty(jndiProperties)) {
+ jndiPropertiesUrl = this.getClass().getResource(jndiProperties);
+ }
+ if (jndiPropertiesUrl != null) {
+ Properties properties = new Properties();
+ properties.load(jndiPropertiesUrl.openStream());
+ context = new InitialContext(properties);
+ } else {
+ context = new InitialContext();
+ }
return (Injector) context.lookup(Injector.class.getName());
}
Modified: camel/trunk/examples/camel-example-guice-jms/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-guice-jms/pom.xml?rev=887914&r1=887913&r2=887914&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-guice-jms/pom.xml (original)
+++ camel/trunk/examples/camel-example-guice-jms/pom.xml Mon Dec 7 12:50:12
2009
@@ -103,6 +103,8 @@
<arguments>
<argument>-duration</argument>
<argument>5s</argument>
+ <argument>-jndiProperties</argument>
+ <argument>/guicejndi.properties</argument>
</arguments>
</configuration>
</plugin>
Modified:
camel/trunk/examples/camel-example-guice-jms/src/main/java/org/apache/camel/example/guice/jms/OSGiCamelContextProvider.java
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-guice-jms/src/main/java/org/apache/camel/example/guice/jms/OSGiCamelContextProvider.java?rev=887914&r1=887913&r2=887914&view=diff
==============================================================================
---
camel/trunk/examples/camel-example-guice-jms/src/main/java/org/apache/camel/example/guice/jms/OSGiCamelContextProvider.java
(original)
+++
camel/trunk/examples/camel-example-guice-jms/src/main/java/org/apache/camel/example/guice/jms/OSGiCamelContextProvider.java
Mon Dec 7 12:50:12 2009
@@ -16,24 +16,21 @@
*/
package org.apache.camel.example.guice.jms;
-import java.net.URL;
import java.util.Properties;
import java.util.Set;
import javax.naming.Context;
-import javax.naming.NamingException;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Provider;
import com.google.inject.ProvisionException;
+
import org.apache.camel.CamelContext;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.JndiRegistry;
import org.apache.camel.osgi.CamelContextFactory;
-import org.apache.camel.osgi.CompositeRegistry;
-import org.apache.camel.spi.Registry;
import org.guiceyfruit.jndi.JndiBindings;
import org.guiceyfruit.jndi.internal.JndiContext;
import org.osgi.framework.BundleContext;
@@ -63,12 +60,9 @@
}
}
- // Add the JndiRegistry to the camel context
- protected void updateRegistry(DefaultCamelContext camelContext) {
- CompositeRegistry compositeRegistry = new CompositeRegistry();
- compositeRegistry.addRegistry(new JndiRegistry(getJndiContext()));
- compositeRegistry.addRegistry(camelContext.getRegistry());
- camelContext.setRegistry(compositeRegistry);
+ // set the JndiRegistry to the camel context
+ protected void updateRegistry(DefaultCamelContext camelContext) {
+ camelContext.setRegistry(new JndiRegistry(getJndiContext()));
}
public CamelContext get() {
Propchange:
camel/trunk/examples/camel-example-guice-jms/src/main/resources/guicejndi.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/examples/camel-example-guice-jms/src/main/resources/guicejndi.properties
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
camel/trunk/examples/camel-example-guice-jms/src/main/resources/guicejndi.properties
------------------------------------------------------------------------------
svn:mergeinfo =
Propchange:
camel/trunk/examples/camel-example-guice-jms/src/main/resources/guicejndi.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
camel/trunk/examples/camel-example-guice-jms/src/test/java/org/apache/camel/example/guice/jms/IntegrationTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-guice-jms/src/test/java/org/apache/camel/example/guice/jms/IntegrationTest.java?rev=887914&r1=887913&r2=887914&view=diff
==============================================================================
---
camel/trunk/examples/camel-example-guice-jms/src/test/java/org/apache/camel/example/guice/jms/IntegrationTest.java
(original)
+++
camel/trunk/examples/camel-example-guice-jms/src/test/java/org/apache/camel/example/guice/jms/IntegrationTest.java
Mon Dec 7 12:50:12 2009
@@ -26,6 +26,6 @@
public void testCamelRulesDeployCorrectlyInGuice() throws Exception {
// let's boot up the Guicey JNDI context for 2 seconds to check that
it works OK
- Main.main("-duration", "2s", "-o", "target/site/cameldoc");
+ Main.main("-duration", "2s", "-o", "target/site/cameldoc", "-j",
"/guicejndi.properties");
}
}
\ No newline at end of file