Karaf package import error - osgi

I'm trying to import a package to a (.kar) bundle within the Karaf runtime that is being exported by another bundle. When I reference this package from within a bean in my .kar file I get an error.
I have a bundle which is exporting a package namely "com.sample"
When I run packages:exports I can see the bundle that is being exported in the list, but when I reference it from my .kar file I get the following error:
The import com.sample cannot be resolved
at beans.testBean.<init>(testBean.java:5)
at bios.testdabean_0_1.testdabean$1.getCamelContextMap(testdabean.java:146)
at org.apache.camel.main.MainSupport.postProcessContext(MainSupport.java:386)
at bios.testdabean_0_1.testdabean$1.doStart(testdabean.java:161)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.main.MainSupport.run(MainSupport.java:148)
at bios.testdabean_0_1.testdabean.run(testdabean.java:194)
at bios.testdabean_0_1.testdabean.runJobInTOS(testdabean.java:290)
at org.talend.esb.job.controller.internal.RouteAdapter.run(RouteAdapter.java:78)[189:org.talen
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)[:1.7.0_51]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)[:1.7.0_51]
My manifest looks as follows
Manifest-Version: 1.0
Export-Package: ...
Bundle-ClassPath: ...
Bundle-Name: ...
Export-Service: ...
Require-Bundle: ...
Bundle-Vendor: ...
Bundle-Version: 0.1
Bundle-ManifestVersion: 2
Bundle-SymbolicName: .....
Import-Package: com.sample,org.osgi.service.blueprint,javax.xml.bind.annotation,
...
Any help would be greatly appreciated! Thanks

I found the solution to this if anyone is interested.
What I had to do was edit the route Manifest file to import the package that was being exported in the OSGi container.
After that I had to reference the service through the Spring DM editor within the Studio.
I changed the namespace to look as follows.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/bean/spring- beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
After that I could reference the service through the tag
<osgi:reference id="myUDPService" interface="com.myosgi.UDPService"/>
Once I had done this I just dropped a cBean, and referenced the bean through the Id "myUDPService", selected the method and was set to go!

Related

How to fix "Configuration Problem: Unable to locate Spring NamespaceHandler for XML schema namespace context"?

I was trying to run application in eclipse, it was running fine. I created jar using Maven install, and while running the jar I am getting the error "Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]
Offending resource: class path resource [appContext.xml]"
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="package"></context:component-scan>
...
Snap of project structure

No Internet access, Spring XSD's reqeuired?

I am trying to run some Citrus tests in an environment without Internet access. My test is a subclass of TestNGCitrusTestBuilder. Now, when I run the tests, I am getting this error message:
INFO: Loading XML bean definitions from class path resource [com/consol/citrus/spring/root-application-ctx.xml]
Mär 01, 2018 9:50:18 AM org.springframework.util.xml.SimpleSaxErrorHandler warning
WARNING: Ignored XML validation warning
org.xml.sax.SAXParseException; lineNumber: 26; columnNumber: 29; schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/aop/spring-aop.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
The XML document causing the problem is located in citrus-core-1.4.jar. The root element looks like this:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
So, the XML parser is right to request access to this documents. Question: How can I activate some Resolver, or whatever, which makes the XML parser load from a local resource?
Citrus 1.4? This is almost four years old. No chance to update to a newer version? 2.7.3 is the latest Citrus version. I am positive that the issues are gone with newer versions of Citrus and Spring.
However make sure that you have spring-aop dependency in your project classpath. Usually Spring will resolve the schema locations within the classpath as spring.handlers and spring.schemas are packaged in META-INF within the Spring jar files. Although I am not sure how the old versions of Spring behave on this.

No setter found for property 'kBaseName' in class 'org.kie.spring.factorybeans.KBaseFactoryBean'

This is an integration issue of Drools KIE and Spring MVC Web V 3.2.3 where google just isn't finding any references to so I'll try my luck here ...
I'm integrating Drools KIE and Spring 3.2.3.RELEASE (MVC Web)- and I'm getting the following error:
No setter found for property 'kBaseName' in class 'org.kie.spring.factorybeans.KBaseFactoryBean'
[config set: maven-spring-drools/web-context application-config.xml
/maven-spring-drools/src/main/resources/spring
The Project is a pure Maven project w/out any outside natures imposed upon it (aka. Drools/Spring).
It's complaining that it can't find the setters for the kBaseName', which is set here:
I'm using a kmodule.xml found in the META-INF dir under the src/main/resources dir.
Can anyone help me discover the disconnect?
Moreover - do I have to do it this way? The project executes the SPring MVC Web App just fine and the Drools KIE test case runs perfectly in the same Maven project. Can't I just integrate them programmatically instead?
Many thanks in advance ... :-)
The offending file: application.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:kie="http://drools.org/schema/kie-spring"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://drools.org/schema/kie-spring http://drools.org/schema/kie-spring.xsd">
<context:component-scan base-package="com.versaggi.springweb"/>
<kie:kmodule id="ksession-rules">
<kie:kbase name="rules" packages="rules">
</kie:kbase>
</kie:kmodule>
<bean id="kiePostProcessor" class="org.kie.spring.KModuleBeanFactoryPostProcessor" />
</beans>

Register a OSGI service and get that OSGI service refrence using WSO2 Product

Actually i want to migrate my application from FUSE ESB to WSO2esb.
In my FUSE application, i have created a OSGI bundle for Logger and register Logger service in OSGI registry.Other OSGI bundle can get that OSGI service through reference of it.
I have created one OSGI maven Project for Logger using servicemix-camel-osgi artifactId.
I've using Apache Camel Approach so created one MainRoute xml file.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<bean id="Logger" class="com.logging.LoggerImpl" factory-method="getInstance"></bean>
<osgi:service id="LoggerService" ref="Logger" interface="com.logging.Logger"></osgi:service>
<camelContext autoStartup="true" xmlns="http://camel.apache.org/schema/spring"/>
</beans>
In this file i've created Spring bean of LoggerImpl Class and register it as OSGI service using SpringDM.
Then i've created other Maven Project of ABC using servicemix-camel-osgi artifactId and in that project i've created one route file.
it's looks like :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:camel="http://camel.apache.org/schema/spring" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<import resource="classpath:spring-beans.xml" />
<osgi:reference id="util_logger" interface="com.logging.Logger" bean-name="Logger"></osgi:reference>
<camelContext trace="false" xmlns="http://camel.apache.org/schema/spring"/>
</bean>
so as shown in above file i've getting Logger service using OSGI Refrence.
Main motive for doing this is when i Register Logger OSGI service in Registry then any OSGI bundle can use that service using Reference of it rather than importing the package.
Same thing want to implement in WSO2 but can't get any solution.
If any solution or suggestion then please suggest me, so i can achieve it.
Thanks.

getting error Invalid NamespaceHandler class org.springframework.data.jpa.repository.config.JpaRepositoryNameSpaceHandler

While running spring i am getting error that
Unexpected exception parsing XML document from class path resource
[spring/tx-annotation-app-context.xml]; nested exception
is org.springframework.beans.FatalBeanException: Invalid NamespaceHandler class
[org.springframework.data.jpa.repository.config.JpaRepositoryNameSpaceHandler]
for namespace [http://www.springframework.org/schema/data/jpa]: problem with
handler class file or dependent class; nested exception is
java.lang.NoClassDefFoundError:
org/springframework/data/repository/config/RepositoryConfigurationExtension
Here is my file
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa-1.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<description>Example configuration to get you started.</description>
....
</beans>
Here is the screen shot of my included jars
What i am doing wrong with the namespace ?
Thanks
I think the problem is your using spring-data-commons-core version 1.1 and spring-data-jpa version 1.2. Align the versions of these libraries.
Looking at a pom.xml file from one of my projects I see.
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.2.0.RELEASE</version>
</dependency>
and it uses spring-data-commons-core-1.4.0.RELEASE.jar
If you switch the packaging of spring-data-jpa to pom, it should download the necessary dependencies, then switch it back to jar.

Resources