Reputation: 566
The code:
from("file://files")
.split()
.tokenize("\n")
.split()
.method(SplitToken.class, "hashTokens")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
Set<Map.Entry<String, Integer>> oldSet = (Set<Map.Entry<String, Integer>>) exchange.getIn().getBody(Set.class);
StringBuilder fin = new StringBuilder();
for (Map.Entry<String, Integer> entry : oldSet) {
fin.append(entry.getValue() + " " + entry.getKey() + "\n");
}
exchange.getIn().setBody(fin.toString());
}
})
.to("file://files/Merged.txt");
}
And:
public class SplitToken {
@SuppressWarnings("unchecked")
public static Set<Map.Entry<String, Integer>> hashTokens(final Exchange exchange, @Body List<String> body) {
Pattern p = Pattern.compile("(\\w+)\\s(\\d+)");
HashMap<String, Integer> exrate = new HashMap<String, Integer>();
for (String line : body) {
Matcher m = p.matcher(line);
if (m.find())
exrate.put(m.group(1), Integer.parseInt(m.group(2)));
}
return exrate.entrySet();
}
}
The input data consists of serveral files with good names and their respective price tags.
But it just returns so many errors:
[org.apache.camel.impl.converter.AnnotationTypeConverterLoader] : Ignoring converter type: org.apache.camel.component.mina.MinaConverter as a dependent class could not be found: java.lang.NoClassDefFoundError: org/apache/mina/common/ByteBuffer
java.lang.NoClassDefFoundError: org/apache/mina/common/ByteBuffer
It returns this error even though I have imported the mina in my pom.xml
And:
[org.apache.camel.processor.DefaultErrorHandler] : Redelivery enabled: false on error handler: DefaultErrorHandler[Channel[Splitter[on: BeanExpression[ method: hashTokens] to: Pipeline[[Channel[DelegateSync[main$1$1@5bd7d30f]], Channel[sendTo(Endpoint[file://files/Merged.txt])]]] aggregate: null]]]
]
]
Message History
----------------------------------------------------------------------------- ----------------------------------------------------------
RouteId ProcessorId Processor Elapsed (ms)
[route1 ] [route1 ] [file://files ] [ 45]
[route1 ] [split1 ] [split[bean{SplitToken, method=hashTokens}] ] [ 19]
Exchange
----------------------------------------------------------------------------- ----------------------------------------------------------
Exchange[
Id ID-ALI-PC-8060-1451994155551-0-4
ExchangePattern InOnly
Headers {breadcrumbId=ID-ALI-PC-8060-1451994155551-0-1, CamelFileAbsolute=false, CamelFileAbsolutePath=C:\Users\ali25\Documents\IdeaProjects\files\1.txt, CamelFileContentType=text/plain, CamelFileLastModified=1451993202700, CamelFileLength=111, CamelFileName=1.txt, CamelFileNameConsumed=1.txt, CamelFileNameOnly=1.txt, CamelFileParent=files, CamelFilePath=files\1.txt, CamelFileRelativePath=1.txt, CamelRedelivered=false, CamelRedeliveryCounter=0}
BodyType String
Body Good1 450
]
Stacktrace
----------------------------------------------------------------------------- ----------------------------------------------------------
]
at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1658)
And:
[org.apache.camel.processor.DefaultErrorHandler] : Failed delivery for (MessageId: ID-ALI-PC-8060-1451994155551-0-5 on ExchangeId: ID-ALI-PC-8060-1451994155551-0-6). On delivery attempt: 0 caught: org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[][Message: Good1 450]
[org.apache.camel.processor.DefaultErrorHandler] : Failed delivery for (MessageId: ID-ALI-PC-8060-1451994155551-0-5 on ExchangeId: ID-ALI-PC-8060-1451994155551-0-6). Exhausted after delivery attempt: 1 caught: org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[][Message: Good1 450]
And the error just keeps repeating. I have no idea why this error has happened since I'm absolutely sure that a set is iteratable, or is it?
EDIT: contents of pom.xml:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>apache-camel</artifactId>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-stream</artifactId>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-mina2</artifactId>
<version>2.16.1</version>
</dependency>
Upvotes: 1
Views: 2978
Reputation: 1771
I think the problem is in the SplitToken
class.
After first splitter you will get one String (one line of the file), not a list of Strings. And here you receive exception, then Camel trying to convert String
to List<String>
, because you have @Body List<String> body
.
You do not need any Mina dependencies...
Upvotes: 1