Pax Exam: resolving project dependencies with bundles and wrapped bundles - pax-exam

I'm aware of this answer: Pax Exam: provisioning bundle with all dependencies
But it feels like I'm doing something wrong when I have to include bundles that are part of bundles that are external to my project.
Here is the error I'm getting:
java.lang.Exception: Could not start bundle wrap:mvn:org.apache.cxf/cxf-bundle-jaxrs/2.7.14 in feature(s) test-dependencies-0.0.0: Unresolved constraint in bundle org.apache.cxf.bundle-jaxrs [80]: Unable to resolve 80.0: missing requirement [80.0] osgi.wiring.package; (&(osgi.wiring.package=com.ctc.wstx.stax)(version>=4.4.0)(!(version>=5.0.0)))
Here is my configuration code for my pax exam test:
#Configuration
public Option[] config() {
MavenArtifactUrlReference karafUrl = maven()
.groupId("org.apache.karaf")
.artifactId("apache-karaf")
.version(karafVersion())
.type("tar.gz");
MavenUrlReference karafStandardRepo = maven()
.groupId("org.apache.karaf.features")
.artifactId("standard")
.classifier("features")
.version(karafVersion())
.type("xml");
return new Option[] {
// KarafDistributionOption.debugConfiguration("5005", true),
karafDistributionConfiguration()
.frameworkUrl(karafUrl)
.unpackDirectory(new File("target/exam"))
.useDeployFolder(false),
keepRuntimeFolder(),
KarafDistributionOption.features(karafStandardRepo , "scr"),
//**Do I seriously need to do this?**
wrappedBundle(mavenBundle("org.codehaus.woodstox", "wstx-lgpl")).noStart(),
//**Why am I doing this?**
wrappedBundle(mavenBundle("org.apache.cxf", "cxf-bundle-jaxrs").version("2.7.14")).noStart(),
//**Some of my bundles use this so I guess this makes sense**
wrappedBundle(mavenBundle("org.apache.commons", "commons-lang3")),
mavenBundle("com.company.project", "common-core").versionAsInProject().start(),
mavenBundle("com.company.project", "common-properties", "1.3.1").start(),
mavenBundle("com.company.project", "rev-common-core", "1.3.1").start(),
mavenBundle("com.company.project", "rev-common-properties", "1.3.1").start(),
mavenBundle("com.company.project", "maintenance-core", "1.3.1").start(),
};
}
So my questions are: why am I getting the error about unresolved constraints, do I have to include even external bundles, and what do I need to do to get my tests to run?

Yes, you have to include all required bundles, Karaf container is running empty, you have to provide all bundles required in your test.
You can create a feature for the module you want to test as a way to supply all required bundles. Then you can use it in your test, e.g:
KarafDistributionOption.features("mvn:group/artifact-id/version/xml", "feature-name")

Related

symfony fatal error after removing bundle

I created a bundle named UserBundle and when I needed to remove it I did this exacly :
Unregister the Bundle in the AppKernel
Remove Bundle Configuration
2.1 Remove Bundle Routing
2.2 Remove Bundle Configuration
Remove the Bundle from the Filesystem
3.1 Remove Bundle Assets
Remove Integration in other Bundles
but when I try to exec soms command this is what I Get :
[Symfony\Component\Config\Exception\FileLoaderLoadException]
Bundle "UserBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file? in #UserBundle/Resources/config/s
ervices.yml (which is being imported from "C:\xampp\htdocs\MT\app/config\config.yml"). Make sure the "UserBundle/Resources/config/services.yml" bundle is correctly registered an
d loaded in the application kernel class. If the bundle is registered, make sure the bundle path "#UserBundle/Resources/config/services.yml" is not empty.
[InvalidArgumentException]
Bundle "UserBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file?
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception
[RuntimeException]
An error occurred when executing the ""cache:clear --no-warmup"" command:
[Symfony\Component\Config\Exception\FileLoaderLoadException]
Bundle "UserBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file? in #UserBundle/Resources/config/services.yml (which is being imported from "C:\xampp\htdocs\MT\app/config\config.yml").
Make sure the "UserBundle/Resources/config/services.yml" bundle is correctly registered and loaded in the application kernel class. If the bundle is registered, make sure the bundle path "#UserBundle/Resources/config/services.yml" is not empty.
When I Refresh the server 'http://127.0.0.1/mt/web/' I get :
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Bundle "UserBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file?' in C:\xampp\htdocs\MT\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php:198 Stack trace: #0 C:\xampp\htdocs\MT\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php(232): Symfony\Component\HttpKernel\Kernel->getBundle('UserBundle', false) #1 C:\xampp\htdocs\MT\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Config\FileLocator.php(51): Symfony\Component\HttpKernel\Kernel->locateResource('#UserBundle/Res...', NULL, false) #2 C:\xampp\htdocs\MT\vendor\symfony\symfony\src\Symfony\Component\Config\Loader\FileLoader.php(147): Symfony\Component\HttpKernel\Config\FileLocator->locate('#UserBundle/Res...', 'C:\xampp\htdocs...', false) #3 C:\xampp\htdocs\MT\vendor\symfony\symfony\src\Symfony\Component\Config\Loader\FileLoader.php(101): Symfony\Component\Config\Loader\FileLoader-> in C:\xampp\htdocs\MT\vendor\symfony\symfony\src\Symfony\Component\Config\Loader\FileLoader.php on line 179
In C:\xampp\htdocs\MT\app\config\config.yml you may have something like:
imports:
- { resource: #UserBundle/Resources/config/services.yml }
and possibly a configuration section related to the user bundle, i.e.
user_bundle:
...
You have to manually remove both to make everything working again.
Can you check if you use this bundle in app/config/service.yml
If it's not working, try to search with your IDE (integrated development environment) your bundle inside your project. If you find some results, just remove them.
Clear the cache
Try to clear cache manually by removing those folders : "var\cache\dev" and "var\cache\prod" for Symfony 3.x or "app\cache\dev" and "app\cache\prod" for Symfony 2.x .

SBT support for custom ivy module status?

In my SBT build I have a dependency on an ivy artifact that makes use of a custom module status. This causes the following error in SBT:
[error] (*:update) sbt.ResolveException: unresolved dependency: my-org#myapp-core_2.11;1.0: java.text.ParseException: inconsistent module descriptor file found in 'http://artifacts.myorg.com/libs-snapshots-local/myapp-core_2.11/1.0/myapp-ivy.xml': bad status: 'snapshot';
I can work around this by telling SBT to use an external ivy settings, like so:
externalIvySettings(baseDirectory(_ / "ivySettings.xml"))
And then create an ivySettings.xml containing the following:
<statuses default="release">
<status name="release" integration="false"/>
<status name="snapshot" integration="false"/>
</statuses>
But surely there must be a better way? The problem with this work around is that now all my settings (such as resolvers) have to be in the ivy file too, because (IFAIK) it's all or nothing when you use externalIvySettings.
Is there a way to specify a set of custom statuses within my build.sbt? Or alternatively is there a way to tell sbt to combine external ivy settings with the ones it generates from the build.sbt.
Since specifying custom module statuses is a valid thing to do in ivy, this should really be supported in sbt too.
This is because for some repositories, they use non-standard status which fails the consistency check. We addressed this by constructing the customized resolver which doesn't do consistency check. You can also construct resolver with the custom status using the same approach. The following is the working snippet.
resolvers += {
val resolver = new org.apache.ivy.plugins.resolver.IBiblioResolver
resolver.setName("Custom Ivy Snapshots")
resolver.setRoot("http://Custom/snapshots/")
val settings = new org.apache.ivy.core.settings.IvySettings()
settings.setVariable("ivy.local.default.ivy.pattern", Pattern)
settings.setVariable("ivy.local.default.artifact.pattern", Pattern)
resolver.setSettings(settings)
resolver.setM2compatible(true)
resolver.setCheckconsistency(false)
new RawRepository(resolver)
}

Export package in OSGi Bundle

I have an OSGi Bundle and a servlet. Now I want to access the bundle from the servlet. For that purpose I use the following in the servlet:
#Resource
BundleContext context
...
ServiceReference ref = context.getServiceReference("package.MyOSGiServiceInterface");
MyOSGiServiceInterface service = context.getService(ref);
The Problem is that my servlet doesn't know MyOSGiServiceInterface 'cause that is defined in the OSGiBundle. In Eclipse I added a reference to the bundle Project in my Build Path. But at runtime it obviously can't find it.
To solve that Problem I played around with
(in bundle manifest)
Export-Package: package-of-osgi-service-interface
(in servlet manifest)
Import-Package: package-of-osgi-service-Interface
Dependencies: ...,deployment.MyBundle
But I couldn't solve it.
Whats the missing step? How can I tell JBoss to add the package containing MyOSGiServiceInterface in OSGiBundle to the class path?
Thanks for answers!
(JBoss AS 7.1.1)
--> error message <--
Eventually I solved it. I had to put the right combination of settings together to reach my goal:
Deploy the bundle per: File - Export - "Deployable plug-ins and fragments" into folder: "jboss/standalone/deployments"
Bundle-Manifest:
Bundle-SymbolicName: TestBundle
Bundle-Version: 1.0.0
Export-Package: "package-which-includes-my-service"
Servlet-Manifest:
Dependencies: org.osgi.core,org.jboss.osgi.framework,deployment.TestBundle:1.0.0
Import-Package: "package-which-includes-my-service"

Pax Exam: provisioning bundle with all dependencies

Currently, to set up configuration for Pax Exam, I find that I need to include all dependencies. E.g. something like
#Configuration
public Option[] сonfig() {
MavenArtifactProvisionOption commonsDbcp = mavenBundle("commons-dbcp",
"commons-dbcp");
MavenArtifactProvisionOption commonsPool = mavenBundle("commons-pool",
"commons-pool");
...
return options(
felix(),
provision(commonsDbcp, commonsPool));
}
But since commons-dbcp depends on commons-pool, this feels like duplicate information. Is it possible for Pax Exam to figure out that commons-dbcp is needed without adding it explicitly?
Not really...
Not every Maven dependency of an OSGi bundle is an OSGi bundle.
A dependency may be an interface-only, and at run-time, you want to provision an implementation bundle instead.
Listing all bundles explicitly is the only safe way of provisioning your framework. At least, you can use the versionAsInPom() option method to avoid duplicating the artifact versions.

seam solder (former weld-extensions project) is not initialized

I want to use logger in my java web application.
I'm using JBossAS 6.0.0.final, cdi (weld), jsf ... etc. Seam solder proposes to use an abstract logger is not tying to a concrete implementation (slf4j, log4j, etc) using jboss-logging api.
In order to get this logger in your code will need to write
# Inject
org.jboss.logging.Logger log
seam-solder.jar has the producer for this logger.
package org.jboss.seam.solder.log;
...
class LoggerProducers
{
# Produces
org.jboss.logging.Logger produceLog (InjectionPoint injectionPoint) {}
}
When I deploying my application, I get an error
15:51:18,300 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] Error installing to Start: name=vfs:///C:/Java/jboss-6.0.0.Final/server/default/deploy/kamis-web-client.5.0.0-SNAPSHOT.ear_WeldBootstrapBean state=Create: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Logger] with qualifiers [#Default] at injection point [[field] #Inject private ru.kamis.suite.webclient.web.breadcrumbs.BreadcrumbsManager.log]
This is due to the seam-solder.jar has not META-INF/beans.xml file, and it is necessary for cdi container.
If to add beans.xml file in seam-solder.jar manually, then the application works WELL.
How to do without hacks?
To build my application I use maven, so my solution is not comfortable and NOT fine.
PS: Former weld-extensions project contained META-INF/beans.xml file in jar.
with seam-solder-3.0.0.Beta1 there should be no need to modify the jar

Resources