adding a AOP pointcut in spring at Run time - spring-aop

I have a requirement to specify a method name at run time to intercept using a common interceptor.Is there any way to add a new pointcut at runtime

You can solve problem in this way.
1) Always intercept same method
Example: Before Advice : public void preProcess() {}
2) Use method argument for calling target method at Runtime from AOP intercepted method #preProcess

Related

toD() - Dynamic URI formation in camel 2.23 scheduled via Quartz

I'm newbie to Apache camel and wanted to Implement the toD() which is to dynamically frame the URI and add request params values from Beans..
Code snippet below -
from("quartz2://timer?cron=0+0/1+++*+?")
.noAutoStartup().routeId(ROUTE_ID).log("Route Started")
.toD(http://localhost:3420/contextpath?from=${bean:bean.from} "+ "&size=${bean:bean.size}")
.process(processor)
Seems like, on every hit via Quartz the same URL is being triggered and hence I see duplicate values saved to DB.
Please suggest why Dynamic uri is not working as expected.
Am calling the processor, computing and setting the Bean values which i get from Response of Endpoint. But when the next time Quartz hits the url, the bean values are not updated and takes the default value
. Bean definition is usual getter setter, and registration is I have used Simple registry
SimpleRegistry simpleRegistry = new SimpleRegistry ();
// create CamelContext
context = new DefaultCamelContext (simpleRegistry);
simpleRegistry.put("bean", bean);
Thanks in Advance
In order to use dynamic URI on a camel-route you must include your variable inside a Simple expression.
Since Camel 2.16.0 release endpoint implementation toD() supports the Simple expression language so you can define a dynamic-URI as message-endpoint:
from("quartz2://timer?cron=0+0/1+++*+?")
.noAutoStartup()
.routeId(ROUTE_ID)
.log("Route Started")
.toD( "http://localhost:3420/contextpath?from=${bean:bean.from}&size=${bean:bean.size}" );
So the expressions ${bean:bean.from} and ${bean:bean.size} should get directly interpolated by using Bean language inside your URI-string. This bean-component bean: tells Camel to get the bean registered with your specified name bean and call the specified methods from and size.
Apache Camel: Rest DSL, section Using Dynamic to() has also a note:
Note: we need to use .endRest() to tell Camel where the route ends, so we can go back to the Rest DSL and continue defining REST services.
Otherwise you could implement that dynamic endpoint using simple inside your regular to(). See Apache Camel: How to use a dynamic URI in to().

How to call a method with parameters in Apache Camel using Java DSL

How to call a method in Camel Route using Java DSL? I want to get a compile time error in Eclipse if I am using the wrong signature for method.
.bean(Foo.class, "setDetails("1", "Camel")")
Here I won't get compile time error for the wrong method signature as method was defined in string.
This is, as far as I know, not possible because Camel calls the method through reflection API.
What you can do, is to create constants in Foo.class with the method names and then use the constants in the bean calls instead of the hard-coded method name Strings.
But even then, you are of course able to rename a method in the bean without adapting the constant. The functionality would be broken but the compiler would be still happy.
If the bean is dedicated to Camel routes and under your control, the best you can do is to refactor the bean.
Remove the method parameters, set them on the message exchange and inject them with #Header, #Property
Split the bean into very small beans with only one method to get rid of the method names
Try this
.bean(Foo.class, "setDetails(1, 'Camel')")
If your first parameter is of type int just put the number without quotes
Second parameter is String, so you should put String to single quotes.
According to the docs, from camel 2.9 onwards, you can do pass in an integer and a string as parameters in a method call (using your example) like this:
.bean(Foo.class, "setDetails(1, 'camel')")
OR
.to("bean:Foo?method=setDetails(1, 'camel')")
If I understand the question correctly, you want a compile-time error about something that is evaluated at runtime. This is simply not possible.

Unit testing (junit4) maven plugins

i am writing my first maven plugin and want to add unit tests for it. i read some about that and it seems that i need to extend AbstractMojoTestCase. But with this i only have JUnit3 style.
Is there any way to use Junit4 (i want it mainly because of the "#Rule"s) probably in conjunction with mockito and/or guice (=juckito)?
At first step i need to inject #Parameter. i tried System.setProperty("some.prop", "someValue"); but this isn't working (parameter are null).
thx in advance
I haven't tried this, but I think the following approach would work. (I have used it with another library that had a similar problem.)
Step 1 - create a subclass of AbstractMojoTestCase
I know what you are thinking. This class has the same problem - that it is a JUnit 3.8 class. But that's ok. You aren't going to run it. All you are going to do is make public methods that you need to call. For example:
public org.codehaus.plexus.PlexusContainer getContainer() {
return super.getContainer();
}
Step 2 - write your JUnit 4 test
Write your Junit 4 test giving it a "helper" instance variable of the class in step 1. Have a #Before and #After method call the helper variable's setUp and tearDown methods.

Can I call Cakephp validation via static methods?

I want to use the built in validations in cakephp 2. Just like password hashing:
AuthComponent::password()
I have tried:
Validation::email($email)
But that gives a fatal error (class not found etc.). Is there a quick way/hack of using it in a static way?
If the method is declared static (public static function) - which it is in your case - you can do so.
But you still need to tell Cake where to look for.
So if you havent used/included the class yet, you need
App::uses('Validation', 'Utility');
prior to calling any of its methods.

Using different methods of System.DirectoryServices.ActiveDirectory.Domain

The static method of GetCurrentDomain() works without issue but, when I try to use another method such as FindDomainController(), I receive a MethodNotFound exception error.
Use Domain.FindDomainController method to find all DC in the domain:
[System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain().DomainControllers
[System.DirectoryServices.ActiveDirectory.Domain] doesn't have a FindDomainController() method.
or use Domain.FindDomainController Method
[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().FindDomainController()
This one finds any domain controller in the domain. There is no guarantee that the same domain controller will be found by another call to this method.

Resources