小编Din*_*ora的帖子

Apache Camel合并来自不同路由的两个文件

这就是我想要做的.我必须阅读两个包含此内容的文件

<Person>
<Requestor>Dinesh</Requestor>
</Person>
Run Code Online (Sandbox Code Playgroud)

为此,我创建了一条路线

<route id="getPerson">
    <from uri="file:src/main/resources/xml?noop=true"/>
    </route>
Run Code Online (Sandbox Code Playgroud)

接下来我需要读取另一个名为Address的文件

<Address>
  <City>New York </City>
</Address>
Run Code Online (Sandbox Code Playgroud)

这是我的第二条路线

<route id="getAddress">
    <from uri="file:src/main/resources/xmlAddress?noop=true"/>
    </route>
Run Code Online (Sandbox Code Playgroud)

如何将这两个xmls合并为一个使用Enricher或Aggregate来使最终的xml消息看起来像这样

<Person>
  <Requestor>Dinesh</Requestor>
  <Address>
     <City>New York</City>
  </Address>
</Person>
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?我尝试按照文档进行操作,但所有内容都是发送给某些Web服务uri.

上面的场景是我真正想要做的版本.我的实际情况是这样做 - 步骤1.读取xml文件,步骤2:调用Web服务并获得响应.步骤3:在步骤2中合并响应并在步骤1中将其添加到Xml主体中

编辑1:我可以编写自定义的AggregatorStartegy类.我写了这样的东西

public class AggregationStrategy implements org.apache.camel.processor.aggregate.AggregationStrategy{

@Override
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
    newExchange.getOut().setBody("<all>" 
              + oldExchange.getIn().getBody(String.class) 
              + newExchange.getIn().getBody(String.class) 
              + "</all>");
            return newExchange;
}

   }
Run Code Online (Sandbox Code Playgroud)

我正在努力的是如何编写Spring xml,我可以告诉我的是我的消息或文件1+消息或文件2,加入他们.这是我的实际context.xml的样子

<camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring">
<route>
    <from uri="file:src/main/resources/xmlPerson?noop=true"/>

    <camel:to uri="direct:enrichMessage"></camel:to>
</route> 
<route  >
    <from uri="file:src/main/resources/xmlAddress?noop=true"/> 
    <log message="**************RESPONSE FROM CATASK DSS:: …
Run Code Online (Sandbox Code Playgroud)

java esb apache-camel java-ee

5
推荐指数
1
解决办法
8052
查看次数

使用基于Https的基本身份验证的Camel http4下载文件

我试图从Https网址下载一个文件,需要进行基本身份验证.我正在使用HTTP4我试图从网址下载 - https://ebc.cybersource.com/ebc/DownloadReport/xxx.csv?authMethod=Basic&authUsername=scott&authPassword=tiger

下载文件后,我需要将其保存到文件夹中.这是我的代码的样子

from(xxx)
.to("http4://ebc.cybersource.com/ebc/DownloadReport/xxx.csv?authMethod=Basic&authUsername=scott&authPassword=tiger")
.to("file:target/messages/download");
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误 -

java.lang.UnsupportedOperationException: Cannot consume from http endpoint
at org.apache.camel.component.http4.HttpEndpoint.createConsumer(HttpEndpoint.java:120)
at org.apache.camel.impl.EventDrivenConsumerRoute.addServices(EventDrivenConsumerRoute.java:65)
at org.apache.camel.impl.DefaultRoute.onStartingServices(DefaultRoute.java:85)
at org.apache.camel.impl.RouteService.warmUp(RouteService.java:158)
at org.apache.camel.impl.DefaultCamelContext.doWarmUpRoutes(DefaultCamelContext.java:3090)
at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:3020)
at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:2797)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:2653)
at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:167)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2467)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2463)
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:2486)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:2463)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2432)
at com.dinesh.MainApp.main(MainApp.java:29)
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:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Run Code Online (Sandbox Code Playgroud)

现在文档说我需要使用HttpContext,

    public class HttpContextFactory {

  private String httpHost = "localhost";
  private String httpPort = 9001;

  private BasicHttpContext httpContext = new …
Run Code Online (Sandbox Code Playgroud)

https apache-camel basic-authentication

5
推荐指数
1
解决办法
4023
查看次数

标签 统计

apache-camel ×2

basic-authentication ×1

esb ×1

https ×1

java ×1

java-ee ×1