camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From somnath <somnath...@gmail.com>
Subject Re: Assigning File names to exchanges generated from split
Date Mon, 09 Jul 2012 08:02:49 GMT
Thanks Claus,

I tried the below and it worked.

from("file:c:/somnath/camel/inbox?noop=true&delay=480000")
.autoStartup(true)
.aggregate(simple("hi"),(OMAggregationStrategy)context.getBean("om-aggregation-strategy")).completionFromBatchConsumer()
.beanRef("om-processor", "process")
.split(body()).parallelProcessing()
*
.setHeader(Exchange.FILE_NAME).simple("${body.getAttribute(levelIdentifier)}_${body.getAttribute(switchIdentifier)}_${body.getAttribute(duration)}_${body.getParsedExchange(${exchangeId})}.${body.getAttribute(fileExtension)}")
*
* .convertBodyTo(String.class)*
.to("file:c:/somnath/camel/outbox?flatten=true");

So instead of returning a list of Strings from the process method, I have
started returning a list of a new Class I called OutputLayout and then used
the technique that you mentioned. Thanks for your help. The new Class looks
like below and I instatiated it from the Processor

/**
 * Class - OutputLayout
 */
package mediation.config.genesys;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author esomnbh
 *
 */
public class OutputLayout implements Serializable {
private static final long serialVersionUID = 5077864600599328343L;
private static final Pattern EXCHANGE_ID_PATTERN =
Pattern.compile("(.*?)-(.*?)-(.*?)-(.*?)-(.*?)-(.*?)");

private Map<String,String> attributes;
private String data;
 /**
 * @param data the data to set
 */
public void setData(String data) {
this.data = data;
}

/**
 *
 * @param key
 * @param value
 */
public void setAttribute(String key, String value){
if(attributes == null)
 attributes = new HashMap<String, String>();
attributes.put(key, value);
}
 /**
 *
 * @param key
 * @return
 */
public String getAttribute(String key){
if(attributes == null)
 return null;
return attributes.get(key);
}
 public String getParsedExchange(String exchangeId){
// Format ID-EVB499BAEF386A-61454-1341819900659-0-934
Matcher matcher =EXCHANGE_ID_PATTERN.matcher(exchangeId);
if(matcher.matches()){
return matcher.group(2)+"_"+matcher.group(4);
}
return "EXCHANGE_FORMAT_UNKNOWN";
}
 /**
 *
 */
@Override
public String toString(){
return data;
}
}


On Fri, Jul 6, 2012 at 6:31 PM, Claus Ibsen-2 [via Camel] <
ml-node+s465427n5715619h26@n5.nabble.com> wrote:

> Hi
>
> You can call a bean in the setHeader so the result of the bean is the
> header value.
>
>
> On Fri, Jul 6, 2012 at 11:55 AM, somnath <[hidden email]<http://user/SendEmail.jtp?type=node&node=5715619&i=0>>
> wrote:
>
> > Hi,
> >
> > My Camel route looks like below
> >                 from("file:/camel/inbox?noop=true&delay=480000")
> >                 .autoStartup(true)
> >
> >
> .aggregate(simple(ANY_LITERAL),(OMAggregationStrategy)context.getBean("om-aggregation-strategy")).completionFromBatchConsumer()
>
> >                 .beanRef("om-processor", "process")
> >                 .split(body()).parallelProcessing()
> > *
> .setHeader(Exchange.FILE_NAME).simple("${exchangeId}.csv")*
> >                 .to("file:/camel/outbox?flatten=true");
> >
> > I want to be able to generate more meaningful names to the files rather
> than
> > the one assigned through the setHeader line which basically is the
> exchange
> > ID. The processor can spit out the various components of the name which
> I
> > can assign to a bean in the processor bean. Is there a way I can access
> this
> > bean in the setHeader section?
> >
> > -Somnath
> >
> > --
> > View this message in context:
> http://camel.465427.n5.nabble.com/Assigning-File-names-to-exchanges-generated-from-split-tp5715603.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: [hidden email]<http://user/SendEmail.jtp?type=node&node=5715619&i=1>
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://camel.465427.n5.nabble.com/Assigning-File-names-to-exchanges-generated-from-split-tp5715603p5715619.html
>  To unsubscribe from Assigning File names to exchanges generated from
> split, click here<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5715603&code=c29tbmF0aC5iNEBnbWFpbC5jb218NTcxNTYwM3wtOTE2ODc4MTcz>
> .
> NAML<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>


--
View this message in context: http://camel.465427.n5.nabble.com/Assigning-File-names-to-exchanges-generated-from-split-tp5715603p5715708.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message