How to run java web application bundle in karaf runtime environment - osgi

I am trying to deploy a simple web application java bundle into karaf. I have created a bundle via the maven plugins: "maven-bundle-plugin" and "maven-scr-plugin". Everything seems to be ok, all dependencies have been added with tag. Just for reference this is how my plugins look:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>1.25.0</version>
<executions>
<execution>
<id>generate-scr-scrdescriptor</id>
<goals>
<goal>scr</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>
${project.groupId}.${project.artifactId}
</Bundle-SymbolicName>
<Bundle-Name>${project.name}</Bundle-Name>
<Bundle-Version>${project.version}</Bundle-Version>
<Bundle-Activator>
vaadin.visual.FrontEndActivator</Bundle-Activator>
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
</instructions>
</configuration>
</plugin>
However when i try to run the bundle in karaf it is always in state INSTALLED
12 | Installed | 80 | 0.0.1.SNAPSHOT | vaadin
23 | Active | 80 | 4.2.8 | Apache Karaf :: OSGi Services :: Event
63 | Active | 80 | 4.14.0 | Apache XBean OSGI Bundle Utilities
64 | Active | 80 | 4.14.0 | Apache XBean :: Classpath Resource Finder
85 | Active | 80 | 7.2.0 | org.objectweb.asm
86 | Active | 80 | 7.2.0 | org.objectweb.asm.commons
87 | Active | 80 | 7.2.0 | org.objectweb.asm.tree
and whenever i try to start the bundle with:
bundle:start vaadin
Then i get the following error:
Unresolved requirements: [[home.overtime.vaadin [12](R 12.0)] osgi.wiring.package; (osgi.wiring.package=com.bea.portlet.container)]
As from my understanding the container has fullfilled all dependencies that i have added to the pom but it requires some sort of web container which needs to provide stuff as the formentioned portlet container and some other web dependencies(Which i have not declared explicitly).
So my biggest concern is how do i start the web container to satisfy these dependencies?
Thanks in advance!

Related

Spring boot unpack application before executing

I got this error when running cucumber test via spring-boot jar
io.cucumber.core.exception.CompositeCucumberException: There were 2 exceptions:
io.cucumber.core.exception.CucumberException(The resource jar:file:/Users/XTZ/IdeaProjects/eq-data/target/eq-data-0.0.1.jar!/BOOT-INF/lib/xyz-service-starter-2.3.10-1.jar!/com/xyz is located in a nested jar.
This typically happens when trying to run Cucumber inside a Spring Boot Executable Jar.
Cucumber currently doesn't support classpath scanning in nested jars.
Feel free to send a pull request to make this possible!
You can avoid this error by unpacking your application before executing.)
My question is how to unpack before executing(unpacking your application before executing)?
The Spring Boot executable format describes how Spring packages its executable jar files. For example:
example.jar
|
+-META-INF
| +-MANIFEST.MF
+-org
| +-springframework
| +-boot
| +-loader
| +-<spring boot loader classes>
+-BOOT-INF
+-classes
| +-com
| +-example
| +-project
| +-StepDefinitions.class
+-lib
+-com.example:utilities:8.0.1.jar
+-com.example:models:4.2.0.jar
By default Cucumber scans the entire classpath for step definitions. This includes BOOT-INF/classes, com.example:utilities:8.0.1.jar and com.example:models:4.2.0.jar. Cucumber can not scan inside the latter two.
If your step definitions and features are located in BOOT-INF/classes you do not have to unpack anything. Rather you have to instruct Cucumber to look for step definitions in a specific package.
If for example you are using the io.cucumber.core.cli.Main you can do this by setting the cucumber.glue=com.example.project property in cucumber.properties or passing --glue com.example.project. Otherwise see the documentation for your test runner on how to configure properties.
If your step definitions are located in either or both of the libraries you have to instruct the spring-boot-maven-plugin to unpack these dependencies. Additionally you have to instruct cucumber to only scan the packages in that specific library i.e: com.example.utilities and/or com.example.models.
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<requiresUnpack>
<dependency>
<groupId>com.example</groupId>
<artifactId>utilities</artifactId>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>models</artifactId>
</dependency>
</requiresUnpack>
</configuration>
</plugin>
</plugins>
There is also a Gradle equivalent.

Got NoClassDefFoundError when invoking Axis2 webservice deployed with maven in weblogic

I'm trying to deploy axis2 webservices in weblogic server using maven. The project has maven modules and one of that is a war that i have defined the axis servlet in. The wsdl was there, so i used wsdl2code plugin to generate the xmlbean and schema and put that in a jar module. Structure is as below.
--lv-ear (ear with dependency on war)
|
--lv-ws
|
--lv-ws-ccid (jar module with skeleton and xmlbeans)
|
--lv-ws-ecs (jar module with skeleton and xmlbeans)
|
--lv-ws-web (war module with dep on jar modules)
|
--WEB-INF
|
--conf/axis2.xml
--services/ccid/services.xml
I built and deployed the ear to weblogic domain. The war was deployed successfully as part of ear and services were deployed. I am able to access wsdl files. When I tried to call the service, i got the below ClassNotFoundException for a schema file.
Caused by: java.lang.ClassNotFoundException: schemaorg_apache_xmlbeans.system.s2104B1E6E09A2A85656B3E630BA151C1.TypeSystemHolder
I saw that the random string in that path differed fo me. So I tried to call again and got below NoClassDefFoundError, which persists even after I tried with different approaches.
java.lang.NoClassDefFoundError: Could not initialize class com.lv.ws.ccid.xmlbean.InputDocument
at com.lv.ws.ccid.xmlbean.InputDocument$Factory.parse(InputDocument.java:463)
at com.lv.ws.ccid.CcidMessageReceiverInOut.fromOM(CcidMessageReceiverInOut.java:332)
at com.lv.ws.ccid.CcidMessageReceiverInOut.invokeBusinessLogic(CcidMessageReceiverInOut.java:46)
at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:173)
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:173)
at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:144)
I searched for this and found something that told to configure app server for axis2 based on http://axis.apache.org/axis2/java/core/docs/app_server.html . When I tried it I got below error.
weblogic.xml.stax.XmlStreamInputFactory can not be cast to javax.xml.stream.XmlInputFactory
After discarding that configuration, I did some other possible deployments by having the webservice skeleton and xmlbean files in an aar and put the aar inside WEB-INF/services. I also tried putting Class-Path entry in MANIFEST.MF in ear / war for the jar files, to no avail. Still I got the same NoClassDefFoundError. Can you please give me suggestions on fixing that?
Fixed it now. This was due to my lack of experience with Axis. Issue was that, I had the generated schema and xmlbean files moved to src folder and then just tried to use normal jar function and dependency to deploy.
Now, I removed them from src folder and use wsdl2code and axis2-aar plugins to generate the xmlbean and schema files dynamically and then package them in aar. Then I deployed the aar to webapp and it worked fine. I have listed the plugin configuration inside <build> below.
<plugins>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.5.4</version>
<executions>
<execution>
<id>ccid-ws</id>
<goals>
<goal>wsdl2code</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>com.lv.ws.ccid</packageName>
<wsdlFile>${basedir}/src/main/resources/META-INF/ccid.wsdl</wsdlFile>
<databindingName>xmlbeans</databindingName>
<syncMode>sync</syncMode>
<unpackClasses>true</unpackClasses>
<namespaceToPackages>https://mdm.com/portal/ws/services/ccid=com.lv.ws.ccid.xmlbean</namespaceToPackages>
<outputDirectory>${basedir}/target/generated-sources</outputDirectory> <generateServerSide>false</generateServerSide>
<generateServicesXml>true</generateServicesXml>
<skipWSDL>true</skipWSDL>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-aar-maven-plugin</artifactId>
<version>1.6.2</version>
<extensions>true</extensions>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>aar</goal>
</goals>
</execution>
</executions>
<configuration>
<aarName>ccid</aarName>
<includeDependencies>false</includeDependencies>
<outputDirectory>${project.build.directory}/aar</outputDirectory>
</configuration>
</plugin>
</plugins>

pax-provision unable to load org/eclipse/core/runtime/adaptor/EclipseStarter class to run equinox

I am running pax-provision to create a helloworld OSGI app. in the pom.xml I have added the below configuration
<plugin>
<groupId>org.ops4j</groupId>
<artifactId>maven-pax-plugin</artifactId>
<version>1.5</version>
<configuration>
<!--
| some example Pax-Runner settings
-->
<provision>
<param>--platform=equinox</param>
<param>--profiles=minimal</param>
<param>--version=3.3.2</param>
<param>--log=DEBUG</param>
<param>--bcp/p=file:///C:/mavenrepo/org/eclipse/equinox/simpleconfigurator/1.0.400/simpleconfigurator-1.0.400.jar</param>
<param>--bcp/p=file:///.</param>
</provision>
</configuration>
<executions>
<!--
| uncomment to auto-generate IDE files
-->
<execution>
<id>ide-support</id>
<goals>
<goal>eclipse</goal>
</goals>
</execution>
</executions>
</plugin>
the EclipseStarter file is part of simpleconfigurator jar file which is is the class path. The below are the logs before starting:
-> Using class org.ops4j.pax.runner.platform.DefaultJavaRunner [org.eclipse.core.runtime.adaptor.EclipseStarter]
-> VM options: [[-Dosgi.install.area=equinox]]
-> Classpath: [[bundles/org.eclipse.equinox.simpleconfigurator_1.0.400.v20130327-2119.jar, bundles/-855037795_0.0.0.jar, bundles/org.apache.felix.gogo.shell_0.10.0.jar]]
-> Platform options: [[-console, -configuration, equinox]]
-> Java home: [C:\Java\jdk1.6.0_22]
-> Working dir: [runner]
-> Environment options: [null]
-> Start command line [[C:\Java\jdk1.6.0_22/bin/java, -Dosgi.install.area=equinox, -cp, bundles/org.eclipse.equinox.simpleconfigurator_1.0.400.v20130327-2119.jar;bundles/-855037795_0.0.0.jar;bundles/org.apache.felix.gogo.shell_0.10.0.jar, org.eclipse.core.runtime.adaptor.EclipseStarter, -console, -configuration, equinox]]
-> Starting platform process.
-> Wrapping stream I/O.
-> Added shutdown hook.
-> Runner has successfully finished his job!
-> Waiting for framework exit.
java.lang.NoClassDefFoundError: org/eclipse/core/runtime/adaptor/EclipseStarter
I am unable to provide the jar file to it and thus not getting the osgi> prompt.
The issue was resolved by placing entry
link\:classpath\:runner-links/org.eclipse.osgi-3.3.2.link=org.eclipse.osgi_3.3.2.R33x_v20080105.jar
link\:classpath\:runner-links/org.apache.felix.gogo.shell-0.10.0=org.apache.felix.gogo.shell_0.10.0.jar
in the runner/bundles/downloaded_bundles.properties file . Also, the org.eclipse.osgi_3.3.2.R33x_v20080105.jar was placed in the bundles directory

Karaf OSGi: JAX-RS with CXF: ClassNotFoundException: org.apache.cxf.jaxrs.impl.RuntimeDelegateImpl

When installing a CXF web service bundle in Karaf OSGi (built with maven), the following error is logged:
2013-03-18 15:08:29,050 | ERROR | rint Extender: 2 | BlueprintContainerImpl | container.BlueprintContainerImpl 393 | 7 - org.apache.aries.blueprint.core - 1.1.0 | Unable to start blueprint container for bundle service-server
org.osgi.service.blueprint.container.ComponentDefinitionException: Error setting property: PropertyDescriptor <name: serviceBeans, getter: null, setter: [class org.apache.cxf.jaxrs.JAXRSServerFactoryBean.setServiceBeans(interface java.util.List)]
at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:941)[7:org.apache.aries.blueprint.core:1.1.0]
at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:907)[7:org.apache.aries.blueprint.core:1.1.0]
at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:888)[7:org.apache.aries.blueprint.core:1.1.0]
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:820)[7:org.apache.aries.blueprint.core:1.1.0]
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)[7:org.apache.aries.blueprint.core:1.1.0]
at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)[7:org.apache.aries.blueprint.core:1.1.0]
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)[:1.6.0_41]
at java.util.concurrent.FutureTask.run(FutureTask.java:138)[:1.6.0_41]
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)[7:org.apache.aries.blueprint.core:1.1.0]
at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:245)[7:org.apache.aries.blueprint.core:1.1.0]
at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:183)[7:org.apache.aries.blueprint.core:1.1.0]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:668)[7:org.apache.aries.blueprint.core:1.1.0]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:370)[7:org.apache.aries.blueprint.core:1.1.0]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:261)[7:org.apache.aries.blueprint.core:1.1.0]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)[:1.6.0_41]
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)[:1.6.0_41]
at java.util.concurrent.FutureTask.run(FutureTask.java:138)[:1.6.0_41]
at org.apache.aries.blueprint.container.ExecutorServiceWrapper.run(ExecutorServiceWrapper.java:106)[7:org.apache.aries.blueprint.core:1.1.0]
at org.apache.aries.blueprint.utils.threading.impl.DiscardableRunnable.run(DiscardableRunnable.java:48)[7:org.apache.aries.blueprint.core:1.1.0]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)[:1.6.0_41]
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)[:1.6.0_41]
at java.util.concurrent.FutureTask.run(FutureTask.java:138)[:1.6.0_41]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)[:1.6.0_41]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)[:1.6.0_41]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)[:1.6.0_41]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)[:1.6.0_41]
at java.lang.Thread.run(Thread.java:662)[:1.6.0_41]
Caused by: java.lang.ExceptionInInitializerError
at org.apache.cxf.jaxrs.utils.JAXRSUtils.<clinit>(JAXRSUtils.java:107)
at org.apache.cxf.jaxrs.model.ClassResourceInfo.getConsumeMime(ClassResourceInfo.java:239)
at org.apache.cxf.jaxrs.model.OperationResourceInfo.checkMediaTypes(OperationResourceInfo.java:171)
at org.apache.cxf.jaxrs.model.OperationResourceInfo.<init>(OperationResourceInfo.java:74)
at org.apache.cxf.jaxrs.utils.ResourceUtils.createOperationInfo(ResourceUtils.java:354)
at org.apache.cxf.jaxrs.utils.ResourceUtils.evaluateResourceClass(ResourceUtils.java:221)
at org.apache.cxf.jaxrs.utils.ResourceUtils.createClassResourceInfo(ResourceUtils.java:207)
at org.apache.cxf.jaxrs.JAXRSServiceFactoryBean.setResourceClassesFromBeans(JAXRSServiceFactoryBean.java:218)
at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.setServiceBeans(JAXRSServerFactoryBean.java:295)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.6.0_41]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)[:1.6.0_41]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)[:1.6.0_41]
at java.lang.reflect.Method.invoke(Method.java:597)[:1.6.0_41]
at org.apache.aries.blueprint.utils.ReflectionUtils$MethodPropertyDescriptor.internalSet(ReflectionUtils.java:628)
at org.apache.aries.blueprint.utils.ReflectionUtils$PropertyDescriptor.set(ReflectionUtils.java:378)
at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:939)
... 26 more
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.apache.cxf.jaxrs.impl.RuntimeDelegateImpl
at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:122)
at javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:91)
at javax.ws.rs.core.MediaType.<clinit>(MediaType.java:44)
... 42 more
Caused by: java.lang.ClassNotFoundException: org.apache.cxf.jaxrs.impl.RuntimeDelegateImpl
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)[:1.6.0_41]
at java.security.AccessController.doPrivileged(Native Method)[:1.6.0_41]
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)[:1.6.0_41]
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)[:1.6.0_41]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)[:1.6.0_41]
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)[:1.6.0_41]
at javax.ws.rs.ext.FactoryFinder.newInstance(FactoryFinder.java:37)
at javax.ws.rs.ext.FactoryFinder.find(FactoryFinder.java:133)
at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:105)
... 44 more
This changed from the previous Caused by: java.lang.ClassNotFoundException: com.sun.rs.ws.ext.RuntimeDelegateImpl when, based on the suggestion from several locations, I added the following line my ext/system.properties file:
javax.ws.rs.ext.RuntimeDelegate=org.apache.cxf.jaxrs.impl.RuntimeDelegateImpl
I'm also explicitly importing this package in my pom with:
<build>
...
<plugins>
...
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.6</version>
<extensions>true</extensions>
<configuration>
<instructions>
...
<Import-Package>org.apache.cxf.jaxrs.impl,*</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
The only bundles exporting anything related (as far as I can tell) are:
Apache ServiceMix :: Specs :: JSR-311 API 1.1.1(org.apache.servicemix.specs.jsr311-api-1.1.1)
Exporting:
javax.ws.rs,version=1.1.1
javax.ws.rs.core,version=1.1.1
javax.ws.rs.ext,version=1.1.1
Apache CXF Bundle Jar(org.apache.cxf.bundle)
Exporting
~25 org.apache.cxf.jaxrs.____ or so packages (including impl)
Can anyone help? I haven't managed to find any fixes that resolve the issue.
Not really an answer, but my solution was to drop CXF entirely. Now using simple servlets (javax.servlet)

Jboss Maven plugin takes too long to deploy

I use the Maven auto-deploy plugin to auto deploy to the Jboss application server.
The deployment plugin is configured as shown below:
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.0.2.Final</version>
<configuration>
<hostname>localhost</hostname>
<port>9999</port>
<filename>TestApp.war</filename>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
The deployment does work but the problem is that it takes quite a while for the deployment to take place. It is as though it is waiting for something to happen. I just stays there waiting and eventually it does complete.
When it gets to this point it gets stuck.
[INFO] --- jboss-as-maven-plugin:7.0.2.Final:deploy (default) # TestApp---
[INFO] Executing goal deploy on server localhost (127.0.0.1) port 9999.
29-Feb-2012 15:52:15 org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 3.2.0.Beta2
29-Feb-2012 15:52:15 org.xnio.Xnio <clinit>
INFO: XNIO Version 3.0.0.Beta2
29-Feb-2012 15:52:15 org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.0.0.Beta2
[INFO]
In some cases it just gets stuck at the above point and nothing happens unless i press the Carriage Return key on the Jboss console for something to happen.
Environment
Maven 3
Jboss 7.0.2
I just did some tests, with a small helloworld deployment, and didn't experience any slowness or hanging. The initial deployment took about 15 seconds and subsequent redploys took only a few seconds.
My test environment:
Windows 7 64-bit
Apache Maven 3.0.3 (r1075438; 2011-02-28 09:31:09-0800)
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
JBoss AS 7.0.2.Final certified web profile
JBoss AS Maven Plugin 7.0.2.Final

Resources