I am search the web without luck about something I thought would be simple but apparently it is not.
All I want to do is to do, is create a HashSet in a method that is called in a camel route and then pass this HashSet to a method in another camel route.
What my search returned is that I should use a cache but I can't find any example (a simple one) that will show me how implement this.
Method "findProperties" in first route creates a HashSet which I want to use in the second route in "parseFile" method.
from("file:{{List}}?noop=true")
.autoStartup(true)
.unmarshal().csv()
.to("bean:ParserUtils?method=findProperties")
.end();
from("file:{{Path}}?move={{processedPath}}")
.autoStartup(true)
.unmarshal().csv()
.to("bean:Parser?method=parseFile")
.end()
I would really appreciate a simple example of getting and setting an object in cache or another solution maybe.
since your first route doesn't invoke your second route, there is no messaging between them to pass data around...so yes, you need to use some external means to access data that is shared between routes/threads...
this can be as simple as a class/static level variable in your ParserUtils instance or using camel-cache (ehcache, etc), camel-hazelcast, etc...the choice is yours
here are some examples using camel-cache...
https://svn.apache.org/repos/asf/camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/CacheProducerTest.java
Related
I'm trying to write a REST interface to manage one of the resources in my application. Following best practice only I want to only use nouns as resource names.
I need the ability update the resource (a PUT operation) in one of several different ways. I imagine my user would call something like:
/resource/{name}?Operation=DO&time=1&Unit=HOUR
/resource/{name}?Operation=REDO&time=1&Unit=HOUR
/resource/{name}?Operation=UNDO
(I'll probably have more then 3 operations, but this is enough to show what's going on). One of the important things that the operations have different arguments. Logically time and Unit do not make sense to the UNDO operation.
In my Java back end I'd like to implement this with two different methods each of which will have it's own #RequestMapping annotation. The differentiator will be the value of the Operation parameter. I can't find any documentation that tells me how to do this
The alternative is to have a single method at the backend, but this is really ugly as I'll have to work out what combination of parameters is valid and throw my own 404 errors if they don't match!
If you absolutely need 2 controllers then do something like
/resource/do/{name}/{time}/{unit}
/resource/undo/{name}
I have a pretty simple purpose
URIs of form ->/random/* go to /*. For example /random/users goes to /users.
I don't wish to use redirect() to solve the problem.
I have a tried a few ways but not sure about implementation -
Intercept the request before it reaches the router. And change the URI somehow. I am trying to Override the onRequest method, but unable to proceed as I don't know the implementation. (possible issue with: should routing really be here?)
Have an entry in routes which is like /random/*, make it point to a controller method. From inside the controller call the router method again with the modified URI. Again here unable to proceed as stuck with implementation.
Double the routes file or put a regex in routes file. For each entry, copy it and append /random to it. I dont want to do this, since it makes the file difficult to manage. Last resort really.
Please help regarding how to implementation Point 1 or Point 2.
If there is any other much simpler way please help..
Add a new Random-controller and create an action which forwards the calls to the proper controllers.
Use the following route:
GET /random/:controller controllers.Random.handleRandom(controller:String)
Let the handleRandom-action forward the calls accordingly (with or without redirect). You can either do some reflection-magic to forward the call to other controllers, or use a if-then-else- or switch-clause.
I'm a newbie in Spring Integration. In the current scenario, I was trying to call methods like this:
MyObject.setMyList();
MyObject.setMyList1();
MyObject.setMyList2();
MyObject.setMyList3();
I had a interface to define the gateway, but my problem is how could i run this multiple methods at once using the spring integration and return MyObject. All the methods are interdependent here.
Second case: I had a method which is dependent on the another method result. Method2 depends on Method1 result.
method2.getMethod2Result(method1_String).
How can I handle this situation using Spring Integration?
I know how can handle it Java, but not in Spring Integration.
There's no bean in spring integration, you only have messages. Assuming your bean is actually the payload of some message, you could achieve both your use-cases by writing custom transformers (like payload enrichers) which return the same object after invoking some sequence of methods on it.
If your use-case is so tight, I don't see reason to decouple that using message channels and a bunch of service-activators.
Looks like it's just enough to write some custom POJO and refer to it from one <service-activator>.
That custom POJO should encapsulate method invocations on your MyObject.
From here your MyObject will be the same and can be an inbound as well as an outbound payload.
Read more Docs, please.
For first case may be you can use Splitter-Aggregator pattern where you can call different methods for each path and combine the results at aggregator. For second case where result of one invocation goes to other, you can simply use
<service-activator>
with mutliple in and out channels
Suppose I am writing a class, which is controlling third party remote server with remote calls. Each call is asynchronous, i.e. the answer for it returns into separate function.
What is the best pattern or algorithm to wrap that remote calls?
Write wrapper method for each call with callback object as last parameter?
Each wrapper method should return "Future" object to wait for result
Make listener for results which should be added to an instance
something else?
I'm not sure there's a lot of difference across the possible solutions you're suggesting above. I would recommend using existing classes and patterns as much as possible (e.g. you mention the Future class above).
One thing that may influence your solution (and that you don't mention) is whether you need to process the results in the same order as you issue the requests, and/or if you're able to process the results in parallel or whether this needs to be synchronous.
I want to create endpoints that can be local in one setup and remote (via jms) in another.
What is the best approach?
I thought of creating my own component, 'abstract', then send to abstract:foo and in one setup have abstract:foo behave like direct:foo and in another setup behave like jms:queue:foo.
However, I'm not sure this is the cookbook approach and how to implement it exactly (how to do the "in one setup behave like X and in another behave like Y"), without being fragile (relying on different contents of META-INF/services/org/apache/camel/component/abstract in each setup)
So, what is the best approach?
You can use the camel PropertiesComponent for this. This allows to use placeholders in endpoints. See http://camel.apache.org/properties.html
E.g.
from("{{myendpoint}}")...
You can use a properties file in setup A to define "myendpoint=direct:foo" and "myendpoint=jms:queue:foo" in another case.
I found the best approach was to create a bean with my own schema name and have it create the desired endpoint (DirectEndpoint or other) according to properties