Spring boot - Eclipelink scanning orm.xml - spring

I'm converting an existing application to spring boot, when I run the application using the created jar I get an exception when it scans and finds an orm.xml inside my entities jar (included as a dependency).
org.eclipse.persistence.exceptions.PersistenceUnitLoadingException:
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: org.springframework.boot.loader.LaunchedURLClassLoader#38cdedfd
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [UAccessPersistenceUnit] failed.
Internal Exception: java.lang.RuntimeException: java.io.IOException: Unable to open root Jar file 'jar:file:everything-jar.jar'
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:107)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:177)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [UAccessPersistenceUnit] failed.
Internal Exception: java.lang.RuntimeException: java.io.IOException: Unable to open root Jar file 'jar:file:everything-jar.jar'
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createPredeployFailedPersistenceException(EntityManagerSetupImpl.java:1954)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1945)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.callPredeploy(JPAInitializer.java:98)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:96)
... 46 common frames omitted
Caused by: org.eclipse.persistence.exceptions.EntityManagerSetupException:
Exception Description: Predeployment of PersistenceUnit [UAccessPersistenceUnit] failed.
Internal Exception: java.lang.RuntimeException: java.io.IOException: Unable to open root Jar file 'jar:file:everything-jar.jar'
at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:230)
... 50 common frames omitted
This isn't using spring data, i'm building the datasources from a external properties file at the moment. It's the scanning that seems to cause issues.
This is spring boot 1.1.5-RELEASE with eclipselink 2.5.1
everything-jar.jar is a spring boot packed jar. With my compiles classes, the spring boot loader and the entities packaged in a jar. I've marked the dependency to be unpacked and it works, but it's not ideal.
This problem keeps coming up, now if I try to load persistence.xml from another jar it throws this same exception.

After a lot of investigation it seems there are two parts to the problem here.
The spring boot loader supports urls that look something like this :
jar:file:!/!/
Eclipselink generates urls for embedded orm.xml files like so
jar:jar:file:!/!/
I've got a fix in spring boot to make it better at opening the eclipselink URLs, but for an immediate fix we need to create a custom ArchiveFactoryImpl and override the createArchive method to return a custom JarInputStreamURLArchive when the protocol is jar.
In this custom class override the get entry as URL to check for a url with a protocol of jar that starts with jar and create a new URL from the file of the original (this cuts off the protocol part from the original url giving us jar:url instead of jar:url:url
public URL getEntryAsURL(String entryPath) throws IOException {
URL entryUrl = super.getEntryAsURL(entryPath);
if(entryUrl == null) {
return null;
}
if("jar".equals(entryUrl.getProtocol()) && entryUrl.getFile().startsWith("jar:")) {
//cut off the jar portions
String file = entryUrl.getFile();
return new URL(file);
} else {
return entryUrl;
}
}

Related

dropwizard and hive/hiverunner integration with maven

most of the dropwizard:0.9.2 maven dependencies use glassfish jersey 2:
org.glassfish.jersey.media:jersey-media-multipart:jar:2.22.1:compile
org.apache.hive:hive-service:1.2.1 and com.klarna.hiverunner:3.1.0 both use com.sun.jersey 1:
com.sun.jersey:jersey-client:jar:1.9:runtime
I keep getting the following error:
java.lang.RuntimeException: javax.servlet.ServletException: io.dropwizard.jersey.setup.JerseyServletContainer-2acbc859#570b3305==io.dropwizard.jersey.setup.JerseyServletContainer,1,false
Caused by: A MultiException has 3 exceptions. They are:
1. java.lang.NullPointerException
2. java.lang.IllegalStateException: Unable to perform operation: method inject on com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$App
3. java.lang.IllegalStateException: Unable to perform operation: create on org.glassfish.jersey.message.internal.MessageBodyFactory
I get the following if I exclude jersey-core from hive:
java.lang.NoSuchMethodError: org.apache.hive.service.server.HiveServer2.init(Lorg/apache/hadoop/hive/conf/HiveConf;)V
The goal is to set up an in-memory hive using hiverunner then write stuff to hiveDB (Derby) using dropwizard API endpoints.
Looks like jersey 2 stopped using jersey 1's JSONJAXBContext.
Is there a proper way to get around this jersey 1 & 2 dependency conflict?

Error running CXF REST web service on Apache Tomee

I'm trying to build a RESTful web service using the "org.apache.cxf.archetype:cxf-jaxrs-service" maven archetype. When I deploy it on Apache Tomee I get the following error:
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'services': Invocation of init method failed; nested exception is org.apache.cxf.service.factory.ServiceConstructionException
...
...
Caused by: org.apache.cxf.service.factory.ServiceConstructionException
at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:219)
...
...
Caused by: java.lang.ClassCastException: Cannot cast org.apache.cxf.management.jmx.InstrumentationManagerImpl to org.apache.cxf.management.InstrumentationManager*
My guess is I'm missing some configuration but I thought the archetype would 'just work'.
Any ideas?
this error means you have a conflict between cxf in the webapp (WEB-INF/lib) and tomee. You either have to configure the classloading to do that or (recommanded and expected by EE) just remove CXF from the webapp since it is in tomee and tomee does the job for you.
Side note: you will also likely need to clean up the web.xml since tomee will handle the deployment without the need to register a servlet.

Invalid bundle when starting Apache Karaf

I have a curious behavior when I start my Karaf.
My JAR bundle contains a simple camel spring xml route that transforms an incoming xml fragment to text with an xslt. I use a BridgePropertyPlaceholderConfigurer to externalize my properties into {karaf.base}/etc/karaf-invalid-bundle.cfg.
To illustrate my post, I created a github repository https://github.com/johanlelan/Karaf-invalid-bundle-example.
Occasionally, my bundle fails to start for a strange cause:
karaf#root> log:display-exception
org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToCreateRouteException: Failed to create route error.sample at: >>> To[xslt:xslt/template.xslt] <
<< in route: Route(error.sample)[[From[ref:incoming.endpoint]] -> [SetHea... because of java.lang.IllegalStateException: Invalid BundleContext.
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1352)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:120)[121:org.apache.camel.camel-spring:2.12.2]
at org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:301)[121:org.apache.camel.camel-spring:2.12.2]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:96)[78:org.springframework.context:3.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:334)[78:org.springframework.context:3.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:948)[78:org.springframework.context:3.2.4.RELEASE]
at org.springframework.osgi.context.support.AbstractOsgiBundleApplicationContext.finishRefresh(AbstractOsgiBundleApplicationContext.java:235)[117:org.springframework.osgi.core:1.2.1]
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:358)[117:org.springframework.osgi.core:1.2.1]
at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)[117:org.springframework.osgi.core:1.2.1]
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)[117:org.springframework.osgi.core:1.2.1]
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)[118:org.springframework.osgi.extender:1.2.1]
at java.lang.Thread.run(Thread.java:662)[:1.6.0_45]
Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route error.sample at: >>> To[xslt:xslt/template.xslt] <<< in route: Route(error.sample)[[From[ref:incoming.endpoint]] -> [SetHea... because of java.lang.IllegalStateException: Invalid BundleContext.
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:912)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:177)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:770)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1914)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1670)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1544)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.spring.SpringCamelContext.doStart(SpringCamelContext.java:179)[121:org.apache.camel.camel-spring:2.12.2]
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1512)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.spring.SpringCamelContext.maybeStart(SpringCamelContext.java:228)[121:org.apache.camel.camel-spring:2.12.2]
at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:118)[121:org.apache.camel.camel-spring:2.12.2]
... 10 more
Caused by: org.apache.camel.RuntimeCamelException: java.lang.IllegalStateException: Invalid BundleContext.
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1352)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.core.osgi.OsgiServiceRegistry.findByTypeWithName(OsgiServiceRegistry.java:110)[121:org.apache.camel.camel-spring:2.12.2]
at org.apache.camel.impl.CompositeRegistry.findByTypeWithName(CompositeRegistry.java:87)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.impl.PropertyPlaceholderDelegateRegistry.findByTypeWithName(PropertyPlaceholderDelegateRegistry.java:70)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.processor.interceptor.DefaultChannel.getOrCreateBacklogTracer(DefaultChannel.java:339)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.processor.interceptor.DefaultChannel.initChannel(DefaultChannel.java:202)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.model.ProcessorDefinition.wrapChannel(ProcessorDefinition.java:269)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.model.ProcessorDefinition.wrapProcessor(ProcessorDefinition.java:251)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:507)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:213)[113:org.apache.camel.camel-core:2.12.2]
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:909)[113:org.apache.camel.camel-core:2.12.2]
... 20 more
Caused by: java.lang.IllegalStateException: Invalid BundleContext.
at org.apache.felix.framework.BundleContextImpl.checkValidity(BundleContextImpl.java:514)[org.apache.felix.framework-4.0.3.jar:]
at org.apache.felix.framework.BundleContextImpl.getAllServiceReferences(BundleContextImpl.java:411)[org.apache.felix.framework-4.0.3.jar:]
at org.apache.camel.core.osgi.OsgiServiceRegistry.findByTypeWithName(OsgiServiceRegistry.java:94)[121:org.apache.camel.camel-spring:2.12.2]
... 29 more
karaf#root>
I think that this error is linked to my properties or to my BundleActivator class.
Any ideas on the way to stop this behavior?
Johan
Not sure about your concrete problem in spring. I stopped using spring on OSGi a long time ago.
A much easier solution would be to just use blueprint instead of spring. You can then use the config admin support of blueprint to attach to the config file in etc. BLueprint runs much smoother in OSGi than spring dm.
You also have the advantage that config admin properties configured by blueprint are automatically available as camel properties.

Can't start application in IDE with <jar-find> error, but 'gradle bootRun' - works fine

So, i have a problem that can't solve.
I have a multi module gradle project with spring boot runners. With Jpa, Elastic, OrientDb and another configurations provided by spring-data and spring-integration. And i try to start my web application! Write web starter, make annotation scan, so when I use task 'gradle bootRun' - everything start perfectly - app works, all contexts up and life is good.BUT, when i try use my favorite IDE like Intellij idea, or colleague use Eclipse - get an error :
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with
name 'org.springframework.integration.config.IdGenerato rConfigurer#0':
BeanPostProcessor before instantiation of bean failed; nested exception is
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with
name org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration':
Initialization of bean failed; nested exception is java.lang.NoSuchMethodError:
org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration.setBeanFactory(Lo rg/springframework/beans/factory/BeanFactoryV
That cause by (projectName - is fake):
java.lang.RuntimeException: error trying to scan <jar-file>:
file:/home/<user>/project/<projectName>/classes/production/<projectName>-system-webapp/
But i have NO /projectName/classes/production/ folder! Anyway - with gradle it's work fine.
And to be honestly, before this another error catched:
Error creating bean with name 'entityManagerFactory' defined in class com.project.system.jpa.PepperJpaConfiguration: Invocation of init method failed
caused by:
error trying to scan <jar-file>: file:/home/<user>/project/<projectName>/classes/production/<projectName>-system-webapp/
Thank you for advice! Can give additional info.
P.S : Edited
So, the problem was solved:
I do not provide important error stacktrace like:
at org.hibernate.ejb.packaging.NativeScanner.getFilesInJar(NativeScanner.java:195)
at org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:506)
at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:861)
... 21 more
Caused by: java.io.IOException: invalid constant type: 18 at 50
And this was and JDK8-Hibernate-javassist problem https://hibernate.atlassian.net/browse/HHH-8286
When upgrade javassist version to 3.18.1-GA - all problems was solved(but why run through gradle worked perfectly...)

FileNotFound exception thrown when trying to create application-context object using ClassPathXmlApplicationContext on Weblogic server

Scenario
There was a requirement in my project to multi-thread calls made to a Webservice. This is implemented using ThreadPoolTaskExecutor (Spring).
As the thread class required values to be fed at runtime, had implemented the code as below -
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("application-context.xml");
for (DocumentData documentData : documentDataList){
MinerThread minerThread = applicationContext.getBean("minerThread",MinerThread.class);
minerThread.setHeader(header);
minerThread.setDocumentData(documentData);
minerThread.setBatchSize(batchSize);
minerThreadExecutor.execute(minerThread);
}
Issue
In local I have tomcat server and this implementation works as expected. However on Weblogic (on the client machine, I don't have access to Weblogic) when the war is deployed it throws FileNotFound Exception.
As the application context object is created via ClassPathXmlApplicationContext API thought the error was thrown because the location was not under the Weblogic classpath. There was nothing set in the Weblogic server classpath. However even after including WEB-INF/classes in the classpath the same exception is thrown.
Exception
2013/01/29 09:19:12,853 [ERROR] RequestQueueListener - org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [../shared-common-context.xml]
Offending resource: class path resource [application-context.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [../shared-common-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [../shared-common-context.xml] cannot be opened because it does not exist
BeanDefinitionParsingException is caused because of the relative path that was added in the Weblogic classpath.
On the Weblogic the file is at the location -
./wls10.3.4/ColorisPPT1/user_projects/domains/Coloris_PPT1_Domain/servers/Coloris_PPT1_AdminServer/tmp/.appmergegen_1336142780924_documentservice.war/WEB-INF/classes
When the war if built (Maven is used) the application-context.xml is placed under WEB-INF/classes folder.
Could someone please suggest how to proceed with this.

Resources