问题描述
我在骆驼世界的新,我有做与JCR组件的连接问题。看看我的测试code:
进口org.apache.camel.builder.RouteBuilder;
进口org.apache.camel.component.jcr.JcrConstants;
进口org.apache.camel.test.junit4.CamelTestSupport;
进口org.junit.Test;
公共类ObjectToJCRRouteTest扩展CamelTestSupport { @覆盖
保护RouteBuilder createRouteBuilder()抛出异常{
返回新RouteBuilder(){
@覆盖
公共无效配置()抛出异常{
从(直接:一个)
.setProperty(JcrConstants.JCR_NODE_NAME,
常数(节点))
.setProperty(my.contents.property,主体())
。要(JCR://管理:管理@本地:8080 /家/测试);
}
};
} @测试
公共无效putJCRNode()抛出异常{
template.sendBodyAndHeader(直接:一个,NULL,NULL,NULL);
视频下载(1000);
}
}
我试过JCR室内用://管理:管理@本地的/ home /测试,JCR://管理:管理@本地:8080 /家/测试,JCR://管理:管理@本地: 8080 /库/家/测试
我测试兔崽子一个库资源管理器()使用RMI和连接是succesfull
提前任何帮助!
谢谢我jackrabit服务器是:
jmartinez @ jmartinez:〜/软件/兔崽子$ Java的罐子兔崽子,独立-2.4.3.jar
欢迎到Apache兔崽子!
使用库目录兔崽子
写日志消息兔崽子/日志
启动服务器...
阿帕奇兔崽子,现在是在运行的http://本地主机:8080 /
配置POM
<&依赖性GT;
<&的groupId GT; org.apache.camel< /的groupId>
<&的artifactId GT;骆驼JCR< / artifactId的>
<&版GT; 2.10.4< /版本>
< /依赖性>
例外code是
org.apache.camel.FailedToCreateRouteException:无法在创建航线ROUTE1:>>>为[JCR://管理:管理@本地:8080 / RMI /家庭/测试] - LT;<<在路线:路线[从[直接:一] - > [的SetProperty [CamelJcrNodeName,{不...... **因无法解析端点:JCR://管理:管理@本地:8080 / RMI /家庭/测试,因为:在没有定义JCR资源库'localhost'的**
在org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:879)
在org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:172)
在org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:722)
在org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1789)
在org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1575)
在org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1444)
在org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
在org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1412)
在org.apache.camel.test.junit4.CamelTestSupport.startCamelContext(CamelTestSupport.java:184)
在org.apache.camel.test.junit4.CamelTestSupport.setUp(CamelTestSupport.java:115)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
在java.lang.reflect.Method.invoke(Method.java:601)
在org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:44)
在org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
在org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
在org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
在org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:193)
在org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:52)
在org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
在org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:42)
在org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:184)
在org.junit.runners.ParentRunner.run(ParentRunner.java:236)
在org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
在org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
org.apache.camel.ResolveEndpointFailedException:引起无法解析端点:JCR://管理:管理@本地:8080 / RMI /家庭/测试,因为:在'localhost'的定义没有JCR资源库
在org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:479)
在org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:50)
在org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:187)
在org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:108)
在org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:114)
在org.apache.camel.model.SendDefinition.resolveEndpoint(SendDefinition.java:61)
在org.apache.camel.model.SendDefinition.createProcessor(SendDefinition.java:55)
在org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:461)
在org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:179)
在org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:876)
... 32更多
org.apache.camel.RuntimeCamelException:产生的原因在'localhost'的定义没有JCR资源库
在org.apache.camel.component.jcr.JcrEndpoint<&初始化GT;(JcrEndpoint.java:65)
在org.apache.camel.component.jcr.JcrComponent.createEndpoint(JcrComponent.java:31)
在org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:91)
在org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:461)
...... 41多
骆驼 JCR的主机部分:
链接不应该是指实际的网络主机,但即在骆驼注册表中定义的 javax.jcr.Repository
对象实例。大部分的时间,这意味着它会被定义为在春季或蓝图XML文件的bean。
要做到同样的事情在一个单元测试,可以覆盖 createRegistry
方法豆添加到注册表骆驼。在下面的code例如,JackRabbit用 URLRemoteRegistry
添加到具有名称骆驼注册表 MyJCR
。
本身是使用URL 路线JCR://管理:管理员@ MyJCR /缺省的/ home /测试
。需要注意的是添加指向JCR存储库工作区添加节点到 /默认
URL的一部分。
公共类ObjectToJCRRouteTest扩展CamelTestSupport { @覆盖
保护RouteBuilder createRouteBuilder()抛出异常{
返回新RouteBuilder(){
@覆盖
公共无效配置()抛出异常{
从(直接:一个)
.setProperty(JcrConstants.JCR_NODE_NAME,
常数(节点))
.setProperty(my.contents.property,主体())
。要(JCR://管理:管理员@ MyJCR /缺省的/ home /测试);
}
};
} @覆盖
保护JndiRegistry createRegistry()抛出异常{
JndiRegistry注册表= super.createRegistry();
registry.bind(MyJCR,新URLRemoteRepository(HTTP://本地主机:8080 / RMI));
返回注册表;
} @测试
公共无效putJCRNode()抛出异常{
template.sendBody(直接:一个,一些内容);
视频下载(1000);
}
}
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
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);
}
}
这篇关于Apache的骆驼JCR兔崽子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!