Referencing a Declarative Service on Karaf via Annotations - apache-camel

I fail to correctly reference a service interface with the #Reference Annotation.
public class TestServiceProcessor implements Processor {
#Reference
private TestService testService;
The Service is up and running on the Karaf Instance and i can reference it with the blueprint file which does work fine.
<bean id="translateOIDs"
class="com.test.TestServiceProcessor">
<property name="TestService" ref="testservice" />
</bean>
<reference id="testservice"
interface="com.test.TestService"/>
The Service has been set up with the OSGI Component Annotations.
I already installed the scr feature and camel-scr on Karaf.
I tried using the field strategy as well as the Event Strategy.
Do i need to further configure the Karaf Instance or am i using the #Reference Annotation in a wrong way?

First you need to install the scr feature to enable declarative services. I guess you mean this with "src" feature.
Apart from this #Reference only works in DS components. So you class TestServiceProcessor must be annotated with #Component ... but then it can not be used in blueprint. DS and blueprint are mutually exclusive.
What you can do instead is leverage the http://aries.apache.org/modules/blueprint-maven-plugin.html.
In this case you need to annotate the bean class with #Named and do the inject with #Inject. You can then also reference annotated beans from the regular blueprint context by their id which can be set using #Named("yourid").

Related

WELD-001408: Unsatisfied dependencies for type CdiCamelExtension with qualifiers #Default

We are migrating from EAP 6 to EAP 7 one project that uses Apache Camel. In this project, we are using dependency injection using the CDI 2.0 specification provided by EAP 7. We are migrating from EAP 6.4 which is using CDI 1.X specification. The Apache Camel version that we are using is 2.17.6
We have updated our project with the appropiate changes in the code, but in the moment of deploying the application in the server, we are getting this error, coming from the Camel dependency:
Exception 0 :
org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type CdiCamelExtension with qualifiers #Default
at injection point [BackedAnnotatedParameter] Parameter 3 of [BackedAnnotatedMethod] #Produces private static org.apache.camel.cdi.CdiCamelFactory.typeConverter(InjectionPoint, #Any Instance<CamelContext>, CdiCamelExtension)
at org.apache.camel.cdi.CdiCamelFactory.typeConverter(CdiCamelFactory.java:0)
It seems that it is a problem related with Apache Camel, with the 3rd parameter of the signature, that cannot find the way to obtain an object to inject it here.
The camel library camel-cdi-2.17.6jar file that contains the class org.apache.camel.cdi.CdiCamelExtension, and the service configuration in this jar is indicating to use this CdiCamelExtension.
We can see also that within this library the beans.xml file contains:
<beans version="1.0" bean-discovery-mode="all">
<scan>
<exclude name="org.apache.camel.cdi.Main"/>
</scan>
</beans>
With all this, we cannot see why CdiCamelContext cannot be obtained.
Could this be because EAP 7 is using CDI 2.0, and Camel 2.17.6 could not be compatible with this specification? We don't have much experience with Camel, so we are not sure if we could be missing something with it.
Thanks for your help
adding <module name="org.apache.camel" annotations="true" meta-inf="true"/> to global-modules of standalone.xml worked for me.

Using non Static Java Class in Mule

I'm trying to implement some custom Java code in a non-static manor. I've used the "NEW" component under Java modules, so I can use the "INVOKE" component later.
XML for Component
<java:new doc:name="New" doc:id="b45f35b5-d524-45df-b006-a962d0a8ce69" class="com.company.LockComponent" constructor="LockComponent()"/>
I then added a classLoaderModelLoaderDescriptor to my mule-artifact.json, as shown below.
{
"minMuleVersion": "4.1.5",
"classLoaderModelLoaderDescriptor": {
"id": "mule",
"attributes": {
"exportedPackages":[
"com.company.LockComponent"
]
}
}
}
I'm getting JAVA:CLASS_NOT_FOUND error. I'm not sure what I'm missing...
Ensure that:
The applications uses the latest Java Module version.
The application uses the latest Mule Maven Plugin version.
The Java source for the class is included with your project (src/main/java) or as a dependency in Maven.
You should not need to modify mule-artifact.json with above steps.

How to use OSGi service reference into whole other classes?

I have one bundle Activator class and some of codes there.
I need to use #Autowired inside my bundle activator class. It is not working.
Here is my bundle Activator class,
public class ProviderActivator implements BundleActivator {
#Autowired
public TestingClass testingClass;
public void start(final BundleContext bundleContext) throws Exception {
System.out.println("bundle starter!!!!!!!!!!!!!!" +testingClass );
}
}
testingClass SOP is null. Spring context scanning added in spring-context.xml.
here my suggestion is,
the bean injected after bundleActivator class loaded.
How to prevent that? why the bean is null when startup bundle class?
Why would you even expect this to work? The activator class is instantiated by the OSGi Framework, and #Autowired is not an OSGi feature.

Could not load extension class org.apache.cxf.ws.policy.AssertionBuilderRegistryImpl

I'm running junit on a class that is configured for cxf. I get this error
Caused by: org.apache.cxf.bus.extension.ExtensionException: Could not load extension class org.apache.cxf.ws.policy.AssertionBuilderRegistryImpl.
when I ask Spring to retrieve the instance on he class. maven dependency includes cxf 2.7.4 (cxf-rt-ws-policy-2.7.4.jar) and I see neethi 3.0.2.jar is also included. Another post mentioned an issue if neethi 2.x was used with cxf 2.x. but this is not my case.
Use mvn dependency:tree to find out which dependency also has the org.apache.neethi:neethi:{version}. In my case it was the org.wso2.carbon.core.
To fix this I added the neethi dependency needed, first in my dependency pom tree.

Building Maven Plugin - API to resolve maven properties

I am creating a plugin that reads information from the pom and I'm encountering some properties such as ${basedir} etc when it comes to the elements that specifies directories. I was wondering if Maven have a API that I can use where I can just pass on that properties and they can resolve it for me.
preferably not having to run another plugin first. Its possible to do the crude way but was just wondering if there's anything "fancier" that i could use.
thanks!
Declare a property which maven will inject the MavenProject model into:
/** #parameter default-value="${project}" */
private org.apache.maven.project.MavenProject mavenProject;
Then you can access properties via getProperties() as described here:
http://docs.codehaus.org/display/MAVENUSER/Mojo+Developer+Cookbook#MojoDeveloperCookbook-StoringProperties
You'll also need to declare a dependency on org.apache.maven:maven-project:${version of maven} in your mojo's POM.
I hope that was what you were asking about...
-tim

Resources