i tried to have aspectj for camel processor, but it is not working. My pointcut is below:
#Around("execution(* org.apache.camel.processor.UnmarshalProcessor.*(..))")
Will it possible to do aspect for camel processor?? if yes, help.
Yes, you can if you put the library on the inpath in a compile-time weaving scenario, creating modified versions of the 3rd party class files and using them during runtime.
In a load-time weaving scenario you can also do it dynamically if the weaving agent is loaded before the Camel classes, which should usually be the case.
As a work-around you can change the pointcut type from execution() to call(), intercepting the callers in your own code rather than the callee in the 3rd party library.
So you have at least three options, all of which work with AspectJ (not in an "AOP lite" variant like Spring AOP though).
Related
I want to implement some content-caching on my Camel 2.23.2 routes. While researching I came across Camel's JCache component which, according to the documentation, should have a JCachePolicy that would:
"The JCachePolicy is an interceptor around a route that caches the "result of the route" - the message body - after the route is completed. If next time the route is called with a "similar" Exchange, the cached value is used on the Exchange instead of executing the route."
Which is basically exactly what I'm looking for. However, as it turns out this policy is only available in Camel 3.x and higher.
So my question is, how might I recreate this functionality in Camel 2.23.2?
The solution was quite simple. In the Camel 3.x branch the policy package is available and in it are only two files. The actual policy and the processor.
As it turns out, pending more testing, these files work very well with little adjustment.
On the policy you need to change the method definition for the "wrap" and "beforeWrap" methods. These require the routeContext, not the Route. But moving from the RouteContext to the route is simple enough.
On the processor, the main change is using the correct package for "DelegateAsyncProcessor" it extends.
With those changes everything seemingly works as documented. I used the ehcache spring boot starter in my pom without any further change to have it work with ehcache as it's cachemanager.
One other remark, when you want to use this, the model you want to cache needs to be serializable.
Is there a way to get any Apache Camel component "metadata" using Java code, like the list of options and other parameters and their types? I think some automatic help builder was mentioned somewhere that might be of use for this task without using reflection.
A way to get the registered components of all types (including data formats and languages) with java code is also sought. Thanks
Yeah take a look at the camel-catalog JAR which includes all such details. This JAR is what the tooling uses such as some of the Maven tooling itself, or IDE plugs for IntelliJ or Eclipse etc. The JAR has both Java API and metadata files embedded in the JAR you can load.
At runtime you can also access this catalog via RuntimeCamelCatalog which you can access via CamelContext. The runtime catalog is a little bit more limited than CamelCatalog as it has a view of what actually is available at runtime in the current Camel application.
Also I cover this in my book Camel in Action 2nd edition where there is a full chapter devoted on Camel tooling and how to build custom tooling etc.
This is what I've found so far
http://camel.apache.org/componentconfiguration.html
I'm running a Camel application on Liberty Profile server. I'm taking a message from a queue, unmarshalling, mapping then marshalling. This was working fine but now I'm getting an error that JAXBDataBinding method getContextualNamespaceMap is not found.
I think this is because there is an older version of the jar in the server libs but I don't know why it started using it.
IBM Jar: com.ibm.ws.org.apache.cxf-rt-databinding-jaxb.2.6.2_1.0.12
The issue is resolved if I switch to parent last class loading but its a very hacky way to fix it and is not a great option. Any other ideas? I'm thinking some feature or other dependency in my build may have pulled this jar in.
So it does look like getContextualNamespaceMap is only available in newer versions of the org.apache.cxf-rt-databinding-jaxb JAR than what is available in Liberty.
It might be that parentLast is the best option then. (You already know how to do this but it's documented (here). If it leads to some other issues then do follow-up with another question.
I suppose it's conceivable you might be able to look at whatever is packaged within your application and try removing a set of things and picking them up from the Liberty runtime, to avoid running in parentLast mode. E.g. if you are only referencing getContextualNamespaceMap because you have other code in your app but there is some alternative path you could have gone down entirely in the Liberty-provided modules, then in theory you could be OK.
I'm not familiar enough with the code paths in the modules in the CXF or Camel "stack" to guess whether that's a real-world likelihood though.
The javaee7 feature contained a jaxsw version that clashed with the server version. Removing the javaee7 feature has resolved this issue. Remains to be seen whether or not I will to add it back in.
'org.apache.cxf.tools.wsdlto.WSDLToJava' converts wsdl to java classes.
Is it using JAXB internally?How come this command is able to generate classes like how 'xjc' creates?Can somebody explain me how it works?
CXF uses xjc internally for code generation.
Refer to following for more information (from CXF official page)
In CXF versions prior to 2.3.0, the xjc plugins were shaded directly into the big cxf bundle jar. In 2.3.0, they were removed from the jar and are placed individually into the lib directory of the distribution. The xjc plugins are only code generation utilities and not used at all at runtime which is why they were pulled out.
The Apache CXF XJC-Utils subproject provides a bunch of utilities for working with JAXB to generate better or more usable code.
Currently, it consists of the following modules:
cxf-xjc-plugin Provides a maven wrapper around the JAXB XJC utility
cxf-xjc-dv Initialize fields mapped from elements/attributes with their default values
cxf-xjc-ts Implements the toString() method
cxf-xjc-boolean Generate getters named getXXX() for Booleans instead of isXXX()
cxf-xjc-wsdlextension Adds extensions methods to allow generated beans to be used as WSDL4J extensors
cxf-xjc-bug671 Provides a workaround for https://jaxb.dev.java.net/issues/show_bug.cgi?id=671
- Not needed for JAXB >=2.1.12
WSDL2Java is a command line tool that generates Java classes from an existing WSDL document. Generated classes represent client stubs, server skeletons and data types that will helps you to write client side and server Java programs for Web services defined in the WSDL document.
DEFAULT_FRONTEND_NAME = "jaxws";
DEFAULT_DATABINDING_NAME = "jaxb";
For details,
http://cxf.apache.org/docs/wsdl-to-java.html http://grepcode.com/file/repo1.maven.org/maven2/org.apache.cxf/cxf-bundle/2.0.6/org/apache/cxf/tools/wsdlto/WSDLToJava.java
I'm using Spring 3.0.5, and was wondering if it's possible, to somehow exclude aspect classes from being loaded that have been annotated with the #Aspect stereotype, but at the same time, include other aspect annotated classes? It seems to be an all or nothing if you're going the annotation route(which I am) I've tried looking at the and but can;t seem to find anything that hints at this.
The reason for this is that I have a central core library which contains aspects, but I may not want to include these aspects in every project I create using this central library.
Thanks.
This is a long time for an answer...
If you are using AspectJ annotations with Spring AOP and not AspectJ runtime or compile-time weaving then you're in luck. Spring will only pick up #Aspect annotated classes if they're annotated with something like #Component as well. Spring does not consider #Aspect a candidate for component scanning. If you're using XML configuration, simply remove that bean from your config.
I would suggest NOT using component scanning that would hit a core library. For example, if your app is com.example.myapp1 and your core library is com.example.corelibrary.* make sure your component scanning is looking at com.example.myapp1 ONLY and not com.example.
It is not safe to component scan outside of your app's base package because of this exact reason. Pull in the individual aspects with an XML config for the bean.