本文介绍了阿帕奇骆驼 jcr 长耳兔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是骆驼世界的新手,在与 jcr 组件建立连接时遇到问题.看看我的测试代码:

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);
    }
}

我试过 jcr://admin:admin@localhost/home/test", "jcr://admin:admin@localhost:8080/home/test", "jcr://admin:admin@localhost:8080/repository/home/test"

I tried wiht jcr://admin:admin@localhost/home/test", "jcr://admin:admin@localhost:8080/home/test" , "jcr://admin:admin@localhost:8080/repository/home/test"

我使用存储库资源管理器 (http://www.subshel​​l.com/en/toromiro/index.html) 使用 rmi 并且连接成功

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!!!

我的 jackrabit 服务器是:

jmartinez@jmartinez:~/software/jackrabbit$ java -jar jackrabbit-standalone-2.4.3.jar

jmartinez@jmartinez:~/software/jackrabbit$ java -jar jackrabbit-standalone-2.4.3.jar

欢迎使用 Apache Jackrabbit!

Welcome to Apache Jackrabbit!

使用仓库目录 jackrabbit

Using repository directory jackrabbit

将日志消息写入 jackrabbit/log

Writing log messages to jackrabbit/log

正在启动服务器...

Apache Jackrabbit 现在运行在 http://localhost:8080/

Apache Jackrabbit is now running at http://localhost:8080/

pom 配置

  <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jcr</artifactId>
        <version>2.10.4</version>
      </dependency>

异常代码是

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

推荐答案

Camel jcr: url 的主机部分不应引用实际的网络主机,而应引用javax.在 Camel 注册表中定义的 jcr.Repository 对象实例.大多数情况下,这意味着它将被定义为 Spring 或 Blueprint XML 文件中的 bean.

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.

要在单元测试中执行相同的操作,您可以覆盖 createRegistry 方法以将 bean 添加到 Camel 注册表.在下面的代码示例中,JackRabbit URLRemoteRegistry 被添加到 Camel 注册表中,名称为 MyJCR.

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.

路由本身使用 URL jcr://admin:admin@MyJCR/default/home/test.请注意,添加了 URL 的 /default 部分以指向要向其中添加节点的 JCR 存储库工作区.

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);
  }
}

这篇关于阿帕奇骆驼 jcr 长耳兔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-27 18:20