0

I am comparatively newbie to apache camel. I am working on route called 'Upgrade' using Java DSL. I have java bean called 'Action' which has an enum,

public enum bundle{
AAA("Monthly AAA Bundle"),
BBB("Monthly BBB Bundle");
private String upbundle;
private bundle(String upBundle) {this.upbundle = upBundle;}
private getBundle() {return upbundle;}
}

From route I want to call 'valueOf()' on enum to get BundleName. I have enum value 'AAA' in exchange header. Using 'AAA' i want to retrieve enum value i.e. 'Monthly AAA Bundle' and store it in exchange header name 'destBundleName'

I used

.setHeader("destBundleName", simple(Action.bundle.valueOf(header("bm").toString()).getBundle()))

is given me runtime error "No enum constant Action.bundle.header{bm} at java.lang.Enum.valueOf

but if i use

.setHeader("destBundleName", simple(Action.bundle.valueOf("AAA")).getBundle())) it works fine.

It means in 1st e.g. header("bm").toString() is not replacing it with String.

I can write process() or bean method which calls enum valueof & from my route i can use that bean method but Is there any way to access enum valueOf() directly from route using value from camel header as a valueOf() param.

Thank you so much for help.

heta shah
  • 11
  • 2
  • There are some issues with your code (e.g. getBundle() does not return anything). Maybe post a very simple class that demonstrates the problem. – Darius X. Aug 05 '16 at 13:01
  • "bm" needs to be declared within the bundle enum otherwise an IllegalArgumentException will be thrown. You may be able to handle this with onException (http://camel.apache.org/exception-clause.html) if you don't want to use a processor. – Andy Longwill Aug 05 '16 at 13:04
  • @DariusX you are correct. I made mistake in editing enum while pasting here. In my actual code enum has more values but to make it simple, made some edits here, as a result, code was incorrect. – heta shah Aug 05 '16 at 17:32
  • @MrGravity yes you are correct. I have yet not implemented exception handling part for it. I am taking baby steps so wanted to get through existing problem first. But thanks for the url, i will implement illegalArgumentException handle for it. – heta shah Aug 05 '16 at 17:35

0 Answers0