Guice, Peaberry and ServletModule - servlets

I am having an issue getting Peaberry/Guice/OSGi/Servlets to place nice. To begin, I have been migrating a Jetty-based, WAR deployed webapp over to OSGi to leverage the plugin architecture. My original application was using guice everywhere.
I have broken everything into modules and Maven-iszed the build. Everything seems to be working except for the pesky installation of the ServletModule.
I receive the following exception when I attempt to install a ServletModule:
java.lang.NoClassDefFoundError: com/google/inject/internal/util/$Preconditions
at com.google.inject.servlet.ServletModule.configure(ServletModule.java:44)
at com.google.inject.AbstractModule.configure(AbstractModule.java:59)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223)
at com.google.inject.AbstractModule.install(AbstractModule.java:118)
at com.payplum.CoreActivator$CoreImportModule.configure(CoreActivator.java:145)
at com.google.inject.AbstractModule.configure(AbstractModule.java:59)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223)
at com.google.inject.spi.Elements.getElements(Elements.java:101)
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:133)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103)
at com.google.inject.Guice.createInjector(Guice.java:95)
at com.google.inject.Guice.createInjector(Guice.java:72)
at com.google.inject.Guice.createInjector(Guice.java:62)
at com.payplum.CoreActivator.start(CoreActivator.java:53)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645)
So I'm not quite clear on why it's failing to find these bundles. I have added the guice-servlet dependency and have verified that it is making it into my deployed bundles.
I guess the other piece of importance is registering the GuiceFilter. I use the ServiceTracker to get the ExtHttpService, as I'm using Jetty. When that Tracker returns, I add register it out using the typical call
service.registerFilter( this.guiceFilter, "/*", null, 0, null );
And that seems to work fine. I'm really struggling to get these things working and I'm a little caught in the middle between the Guice/OSGi/Peaberry part. Any help is much appreciated.
Thanks!

The exception means you're missing a class on your classpath, so you're either missing a jar or one of the jars (surprisingly) doesn't include its required classes. Check the JARs that are included in your final war file e.g. using 'jar -tf thejar.jar' on whether they include the $Preconditions class.

Related

The transaction currently built is missing an attachment for class - Attempted to find a suitable attachment but could not find any in the storage

Full Error:
transactions.TransactionBuilder. - The transaction currently built is missing an attachment for class: com/gibtn/corda/printutilities/PrintLedgerTransaction. Attempted to find a suitable attachment but could not find any in the storage.
This has been asked here and here but I hope to get better clarification.
Problem:
I have built a set of libraries to perform common tasks in my Flows that I include in all my CorDapps. For now I just copy the JARs into each project, make some changes to the gradle files and everything works great.
I recently put together a small library for performing common tasks in Contracts and added the JAR the same way.
This works fine with MockNodes. But when I test with real nodes I will get this error in the CRaSH shell and the transaction will fail with a NoClassDefFoundError exception.
Question:
Is what I am doing even possible? Or do I always have to keep my utility classes inside the Contracts module in IntelliJ so they are bundled together with the Contracts into a single JAR? That way when the node starts the JAR (containing the Contracts and any utilities) is added to Attachment storage as a single Attachment.
I found a way to solve this. It's a bit dirty but initial testing seems to work. I just created a blank class in my utilities JAR that implements Contract. It's verify() method is empty. Now when the Corda node starts it sees this Contract and adds the JAR to Attachment storage. So from the CRaSH shell if I run:
attachments trustInfo
...my utility JAR will be listed (it wasn't before). I see when I use one of the utility methods in a Contract the utility JAR will be included as a separate Attachment in the WireTransaction.
I'm not crazy about this solution and will probably stop using a utility JAR for Contracts. I'll go back to copying the classes into each project. Nevertheless there is a way to do it. I would just need a more experienced Corda developer to give it their blessing before I'd go forward into production with it.

Error while issuing a state in Postgres Corda 4.6 OS

Following are the error I got when trying to initiate a state in Corda 4.6OS using Postgres:
"net.corda.core.CordaRuntimeException: com.esotericsoftware.kryo.KryoException: java.lang.UnsupportedOperationException: net.corda.nodeapi.internal.persistence.CordaPersistence, which is a closeable resource, has been detected during flow checkpointing. Restoring such resources across node restarts is not supported. Make sure code accessing it is confined to a private method or the reference is nulled out."
unfortunately with just this information it's hard to know what exactly happened.
Here's some examples of what could be happening.
look carefully through the stacktrace, if you're getting an unsupported runtime exception or other exceptions from code that's not in your control look around and make sure you're using packages / resources that line up with the cordapp template.
For example I had something like this for a couple hours because I was using the wrong junit package in my imports and the tests weren't initializing properly so you can get errors like this one and it won't be obvious at all why unfortunately.
Here's a link to the cordapp template, try to carefully check your flow / state to make sure all the imports are reasonable and you're using the right packages / gradle dependencies.
https://github.com/corda/cordapp-template-java
https://github.com/corda/cordapp-template-kotlin
good luck

Jasper Reports NoClassDefFoundError

I'm getting a NoClassDefFoundError error when trying to compile or run a Jasper report.
2012-06-13 14:46:26,710 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/jahtest].[jahtest]] Servlet.service() for servlet jahtest threw exception
java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.xml.JRXmlDigesterFactory
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:207)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:172)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:156)
I have a set of java classes wrapped up in a war file and deployed in JBoss default/deploy folder.
I have the jasperreports-4.1.2.jar file in the JBoss default/lib folder so I can't see how there can be a classpath problem because all other jars in the lib folder can be seen.
My front-end app calls a HTTPServlet class which then uses reflection to call the class containing the Jasper code. Everything works fine up until the point where this line is called -
JasperDesign jasperDesign = JRXmlLoader.load(strCompiledReportFile);
The strCompiledReportFile is correct and exists. This all works when I run it through Eclipse, just not when called from my HTTPServlet class.
I'm at the point where I want to ditch Jasper because I've had so many issues with it so this is the last chance saloon.
Cheers for any help you might be able to offer.
I think you are missing few jars that jasper depends on at runtime. Check this thread and make sure you have those jars in your classpath as well.
I'm not sure if it would also apply to your case, but I had a similar problem recently, where after failing to load a font ("problem reading font data"), Jasper Reports would start giving spurious java.lang.NoClassDefFoundError for many of its classes; this problem was caused because java.awt.Font.createFont(int fontFormat, InputStream fontStream) tried and failed to create a temporary file. The error happened inside Tomcat, but not inside Eclipse; what was happening was that Tomcat automatically configures its JVM to point to its temp folder instead of the default one, and Tomcat's temp folder had been deleted.
If you are trying to integrate jasper with springboot application check whether the .jrxml is in the resources folder.

CDI on GlassFish 3.1.1 b12 generates error "WELD-001408 Unsatisfied dependencies"

I'm trying to evaluate CDI on Glassfish 3.1 and even though I have accomplished to make it work well, when I'm trying to split my code in separate deployment modules I get a weird error. More specifically:
I have two classes bundled in the same utility project (let's say the CommonLib.jar); the classnames are UserDatabase and UserDatabaseEntityManager and their definitions are as below (in the PS at the end of this message).
I also have an EAR with an EJB3.1 module in it.
When I choose to deploy the CommonLib.jar as a "Bundled Library" of the EAR, then I get the following error:
Error occurred during deployment: Exception while loading the app : WELD-001408 Unsatisfied dependencies for type [EntityManager] with qualifiers [#UserDatabase] at injection point [[field] #UserDatabase #Inject com.test.TestEJB.itemPersistenceEm]. Please see server.log for more details.
Same error as above I get also when I deploy the CommonLib.jar as a shared library (jar file copied under $glasshfish_installation_path/domains/domain1/lib)
BUT, if I choose to just have the two classes (UserDatabase and UserDatabaseEntityManager) in the EJB project (thus they are compiled within the EJB module), then the injection works fine.
Am I facing a classloader issue? Any ideas how I can get past this issue?
Just a guess, because I faced a very similar problem with Glassfish and CDI a few days ago: Do you have a beans.xml in every JAR, i.e. in the CommonLib.jar and the EJB JAR, so that CDI scans both of them?
My problem resulted from the fact that I thought placing a beans.xml into the EAR would be sufficient, which is not the case.
Sounds like you're running into some of the Glassfish CDI integration issues we've found while working on Seam 3. It could be a couple of them, so you'll have to take a look at see which one it may be. Try testing on JBoss AS7 or Apache TomEE and see if you still have problems.

org.drools.RuntimeDroolsException: Unable to resolve class

I have this seam project that a colleague built. I am trying to get it to build in Jboss dev Studio. He uses ant and builds manually. I got the project built in JBDS and deployed on the JBoss server. When i try to run the app, when it is time for the rules to fire, I get this error
Caused by: org.drools.RuntimeDroolsException: Unable to resolve class 'dne.nmst.ciscoconfig.model.ConfigParams_$$_javassist_seam_4'
The offending code is in the drools config file which includes 2 imports
package Config;
import dne.nmst.ciscoconfig.model.ConfigParams;
import dne.nmst.ciscoconfig.action.ConfigSelector;
Perhaps I need more detail here, I don't know what would be useful to post. I'm not even sure I know how to ask the question other than how do I fix this. Advice anyone?
Are you 100% sure the jar containing those imports is available at runtime, rather than just at compile time?

Resources