Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Debugging 如何在EclipseIDE中调试驼峰路由生成器?_Debugging_Apache Camel - Fatal编程技术网

Debugging 如何在EclipseIDE中调试驼峰路由生成器?

Debugging 如何在EclipseIDE中调试驼峰路由生成器?,debugging,apache-camel,Debugging,Apache Camel,我已经在JavaDSL中编写了驼峰路由构建,现在我想在EclipseIDE中调试它,我的类看起来像 public class PMRouteBuilder extends RouteBuilder { UserProfileResponseProcessor responseProcessor=new UserProfileResponseProcessor(); System.out.println("\n"); System.out.println("

我已经在JavaDSL中编写了驼峰路由构建,现在我想在EclipseIDE中调试它,我的类看起来像



public class PMRouteBuilder extends RouteBuilder {
UserProfileResponseProcessor responseProcessor=new UserProfileResponseProcessor();
         System.out.println("\n");
         System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
         System.out.println("           STARTED PROCESS MANAGER ROUTEBUILDER                          ");
         System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
try{
             from("cxf:bean:process-manager-ws?dataFormat=POJO").routeId("process-manager-route-userprofile").log( "This is ${in.header.operationName} operation called...." )
                    .log( "Entering inside the Choice with operation....${in.header.operationName}")
                    //.wireTap(RouterEndPoints.ENDPOINT_AUDITOR_QUEUE.value(),true, new PreWireTapProcessor())
                    .choice()
                        /**
                         * ##################################### ROUTE FOR USER PROFILE REQUEST ###########################################
                         */
                        .when(simple("${in.header.operationName} == 'retrieveUserProfile'"))
                            .to("log:?showAll=true&multiline=true")
                            .setHeader("OPERATION_NAME", constant("retrieveUserProfile") )
                            .process(pmRequestProcessor)
                            .log( "Setting header value to...."+constant(AuditActions.Actions.ACTION_GET_USER_PROFILE.desc()) )
                            .setHeader(RouteActions.Actions.OMGMEAT_ACTION_ID.desc(), constant(AuditActions.Actions.ACTION_GET_USER_PROFILE.desc())).convertBodyTo(UserProfile.class)
                            .to(RouterEndPoints.ENDPOINT_USERPROFILE_QUEUE.value()).process(responseProcessor)
                        .when(simple("${in.header.operationName} == 'addUserProfile'"))
                            .log( "Setting header value to...."+constant(AuditActions.Actions.ACTION_ADD_PROFILE.desc()) )
                            .setHeader(RouteActions.Actions.OMGMEAT_ACTION_ID.desc(), constant(AuditActions.Actions.ACTION_ADD_PROFILE.desc())).convertBodyTo(UserProfile.class)
                            .to(RouterEndPoints.ENDPOINT_USERPROFILE_QUEUE.value()).process(responseProcessor)
.end()
 }catch(Exception exc){
             ApplicationLogger.error("PMRouteBuilder.configure():Exception while configure the route for 'cxf:bean:process-manager-ws?dataFormat=POJO'",exc);
         }


我可以看到日志正在打印,但是有没有办法放置调试点(断点)并调试此路由生成器?

除了克劳斯提供的链接中描述的技术外,我们还使用带有驼峰插件的控制台

使用此插件,您可以:

  • 所有正在运行的Camel应用程序的列表
  • 每个Camel上下文的详细信息,例如Camel版本号、运行时静态
  • 每个Camel应用程序中的所有路由及其运行时统计信息的列表
  • 管理所有Camel应用程序及其路由的生命周期,以便您可以重新启动/停止/暂停/恢复等
  • 运行路线的图形表示以及实时指标
  • 运行路线的实时跟踪和调试
  • 使用实时运行时静态数据分析运行路线;每个处理器指定的详细信息
  • 浏览并向Camel端点发送消息

我知道您要求Eclipse,但我认为现在不可能一步一步地调试DSL,这就是为什么我们主要使用支持跟踪程序的模式,最后使用Hawtio控制台进行一步一步的调试

另一种技术是使用IDE的JUnit,但您应该稍微修改类以使其更易于测试:

使用端点的属性,如更改

from("cxf:bean:process-manager-ws?dataFormat=POJO")
...
.to(RouterEndPoints.ENDPOINT_USERPROFILE_QUEUE.value()) // the two instances 

并使用spring或Blupprint文件中的原始值设置属性(取决于您使用的是哪一个)

可以在测试文件夹(src/test,如果使用maven)中创建名为PMRouteBuilderTest的测试后,使用扩展的CamelTestSupport和以下内容:

@EndpointInject(uri = "direct:test")
protected Endpoint inputTest;

@EndpointInject(uri = "mock:userEndpointOne")
protected MockEndpoint destinationOne;

@EndpointInject(uri = "mock:userEndpointTwo")
protected MockEndpoint destinationTwo;

@Test
public void testRoutingSampleToDestOne() throws Exception {

    destinationOne.expectedMessageCount(1);
    destinationTewo.expectedMessageCount(1);

    String body = "Anything that can make your test useful"
    sendBody(inputTest.getEndpointUri(), body);
    assertMockEndpointsSatisfied();
}

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new PMRouteBuilder();
}

@Override
protected Properties useOverridePropertiesWithPropertiesComponent() {
    Properties props = new Properties();

    // Set your test properties here, those are examples
    props.put("from.endpoint", "direct:test");
    props.put("user.profile.endpoint.1", "mock:userEndpointOne");
    props.put("user.profile.endpoint.2", "mock:userEndpointTwo");

    return props;
}
您必须尽可能多地使用真正的bean进行测试,但有时如果不能,您必须使用类似Mockito的模拟框架来模拟方法调用。 之后,您可以从IDE以调试模式执行测试,并将断点放在路由中使用的实际处理器上

我强烈推荐阅读


为了简单起见,我用test修改了测试类名,但通常它应该命名为
PMRouteBuilderIT
,因为它测试多个类,并且应该在集成测试阶段执行(mvn验证,使用failsafe插件)。

查看此常见问题解答:我们可以有任何插件与Eclipse IDE集成吗?我们没有找到任何插件(免费/非商业),对于调试路线,正如我所解释的,我们处于OSGI/ServiceMix上下文中,这有助于使用HawtIO。
@EndpointInject(uri = "direct:test")
protected Endpoint inputTest;

@EndpointInject(uri = "mock:userEndpointOne")
protected MockEndpoint destinationOne;

@EndpointInject(uri = "mock:userEndpointTwo")
protected MockEndpoint destinationTwo;

@Test
public void testRoutingSampleToDestOne() throws Exception {

    destinationOne.expectedMessageCount(1);
    destinationTewo.expectedMessageCount(1);

    String body = "Anything that can make your test useful"
    sendBody(inputTest.getEndpointUri(), body);
    assertMockEndpointsSatisfied();
}

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new PMRouteBuilder();
}

@Override
protected Properties useOverridePropertiesWithPropertiesComponent() {
    Properties props = new Properties();

    // Set your test properties here, those are examples
    props.put("from.endpoint", "direct:test");
    props.put("user.profile.endpoint.1", "mock:userEndpointOne");
    props.put("user.profile.endpoint.2", "mock:userEndpointTwo");

    return props;
}