3

私はラクダの世界に不慣れで、jcr コンポーネントとの接続に問題があります。私のテストコードを見てください:

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」で試しました/ホーム/テスト"

rmi を使用してリポジトリ エクスプローラー ( http: //www.subshel​​l.com/en/toromiro/index.html ) で jackrabbit をテストしたところ、接続は成功しました。

よろしくお願いします。

私のjackrabitサーバーは次のとおりです。

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

Apache Jackrabbit へようこそ!

リポジトリ ディレクトリ jackrabbit の使用

jackrabbit/log へのログ メッセージの書き込み

サーバーを起動しています...

Apache Jackrabbit は現在、http://localhost:8080/

ポン設定

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

1 に答える 1

5

Camel URL のホスト部分はjcr:、実際のネットワーク ホストを参照するのではなくjavax.jcr.Repository、Camel レジストリで定義されているオブジェクト インスタンスを参照する必要があります。ほとんどの場合、これは Spring または Blueprint XML ファイルで Bean として定義されることを意味します。

単体テストで同じことを行うには、createRegistryBean を Camel レジストリに追加するメソッドをオーバーライドできます。以下のコード例では、JackRabbitURLRemoteRegistryが Camel レジストリに name で追加されますMyJCR

ルート自体は URL を使用していますjcr://admin:admin@MyJCR/default/home/test/defaultURL の一部は、ノードを追加する JCR リポジトリ ワークスペースを指すように追加されていることに注意してください。

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);
  }
}
于 2013-03-08T07:58:37.843 に答える