问题
I'm new in camel world and I have problems making a connection with the jcr component. look at my test code:
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jcr.JcrConstants;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
public class ObjectToJCRRouteTest extends CamelTestSupport {
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:a")
.setProperty(JcrConstants.JCR_NODE_NAME,
constant("node"))
.setProperty("my.contents.property", body())
.to("jcr://admin:admin@localhost:8080/home/test");
}
};
}
@Test
public void putJCRNode() throws Exception {
template.sendBodyAndHeader("direct:a", null, null, null);
Thread.sleep(1000);
}
}
I tried wiht jcr://admin:admin@localhost/home/test", "jcr://admin:admin@localhost:8080/home/test" , "jcr://admin:admin@localhost:8080/repository/home/test"
I tested jackrabbit with a repository explorer (http://www.subshell.com/en/toromiro/index.html) using rmi and the connection was succesfull
thanks in advance by any help!!!
my jackrabit server is:
jmartinez@jmartinez:~/software/jackrabbit$ java -jar jackrabbit-standalone-2.4.3.jar
Welcome to Apache Jackrabbit!
Using repository directory jackrabbit
Writing log messages to jackrabbit/log
Starting the server...
Apache Jackrabbit is now running at http://localhost:8080/
pom configuration
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jcr</artifactId>
<version>2.10.4</version>
</dependency>
the exception code is
org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> To[jcr://admin:admin@localhost:8080/rmi/home/test] <<< in route: Route[[From[direct:a]] -> [SetProperty[CamelJcrNodeName, {no... **because of Failed to resolve endpoint: jcr://admin:admin@localhost:8080/rmi/home/test due to: No JCR repository defined under 'localhost'**
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:879)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:172)
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:722)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1789)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1575)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1444)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1412)
at org.apache.camel.test.junit4.CamelTestSupport.startCamelContext(CamelTestSupport.java:184)
at org.apache.camel.test.junit4.CamelTestSupport.setUp(CamelTestSupport.java:115)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: jcr://admin:admin@localhost:8080/rmi/home/test due to: No JCR repository defined under 'localhost'
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:479)
at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:50)
at org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:187)
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:108)
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:114)
at org.apache.camel.model.SendDefinition.resolveEndpoint(SendDefinition.java:61)
at org.apache.camel.model.SendDefinition.createProcessor(SendDefinition.java:55)
at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:461)
at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:179)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:876)
... 32 more
Caused by: org.apache.camel.RuntimeCamelException: No JCR repository defined under 'localhost'
at org.apache.camel.component.jcr.JcrEndpoint.<init>(JcrEndpoint.java:65)
at org.apache.camel.component.jcr.JcrComponent.createEndpoint(JcrComponent.java:31)
at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:91)
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:461)
... 41 more
回答1:
The host part of a Camel jcr:
url should not refer to an actual network host, but to a javax.jcr.Repository
object instance that is defined in the Camel registry. Most of the times, this means it will be defined as a bean in a Spring or Blueprint XML file.
To do the same thing in a unit test, you can override the createRegistry
method to add beans to the Camel registry. In the code example below, a JackRabbit URLRemoteRegistry
is added to the Camel registry with name MyJCR
.
The route itself is using the URL jcr://admin:admin@MyJCR/default/home/test
. Note that /default
part of the URL was added to point to the JCR repository workspace to add nodes to.
public class ObjectToJCRRouteTest extends CamelTestSupport {
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:a")
.setProperty(JcrConstants.JCR_NODE_NAME,
constant("node"))
.setProperty("my.contents.property", body())
.to("jcr://admin:admin@MyJCR/default/home/test");
}
};
}
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry registry = super.createRegistry();
registry.bind("MyJCR", new URLRemoteRepository("http://localhost:8080/rmi"));
return registry;
}
@Test
public void putJCRNode() throws Exception {
template.sendBody("direct:a", "Some contents");
Thread.sleep(1000);
}
}
来源:https://stackoverflow.com/questions/15233420/apache-camel-jcr-jackrabbit