java.lang.IllegalStateException: No thread-bound request found + #JaversSpringDataAuditable - java

I'm getting java.lang.IllegalStateException: No thread-bound request found, when I use Javers Audit feature in my JPA repository class.
#JaversSpringDataAuditable
My service method(create/Update) is defined with #Async and it's handled using Future.
Future<T> updateEmployee(Employee employee) {
//some code here
return new AsyncResult<T>(employeeDTO);
}
Am I missing anything here?
java.util.concurrent.ExecutionException: java.lang.IllegalStateException: No
thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at java.util.concurrent.FutureTask.report(Unknown Source) ~[na:1.8.0_112]
at java.util.concurrent.FutureTask.get(Unknown Source) ~[na:1.8.0_112]
Caused by: java.lang.IllegalStateException: No thread-bound request found:
Are you referring to request attributes outside of an actual web request, or
processing a request outside of the originally receiving thread? If you are
actually operating within a web request and still receive this message, your
code is probably running outside of DispatcherServlet/DispatcherPortlet: In
this case, use RequestContextListener or RequestContextFilter to expose the
current request.at
org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131) ~[spring-web-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.web.context.support.WebApplicationContextUtils.currentRequestAttributes(WebApplicationContextUtils.java:275) ~[spring-web-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.web.context.support.WebApplicationContextUtils.access$400(WebApplicationContextUtils.java:64) ~[spring-web-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.web.context.support.WebApplicationContextUtils$RequestObjectFactory.getObject(WebApplicationContextUtils.java:291) ~[spring-web-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.web.context.support.WebApplicationContextUtils$RequestObjectFactory.getObject(WebApplicationContextUtils.java:286) ~[spring-web-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.beans.factory.support.AutowireUtils$ObjectFactoryDelegatingInvocationHandler.invoke(AutowireUtils.java:307) ~[spring-beans-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at com.sun.proxy.$Proxy146.getHeader(Unknown Source) ~[na:na]
at com.vz.uiam.common.audit.javers.ServletRequestAuthorProvider.provide(ServletRequestAuthorProvider.java:15) ~[uiam_common_cloud-1.0.11.jar:1.0.11]
at org.javers.spring.auditable.aspect.OnSaveAuditChangeHandler.handle(OnSaveAuditChangeHandler.java:17) ~[javers-spring-1.6.4.jar:na]
at org.javers.spring.auditable.aspect.JaversAuditableRepositoryAspect.applyVersionChange(JaversAuditableRepositoryAspect.java:94) ~[javers-spring-1.6.4.jar:na]
at org.javers.spring.auditable.aspect.JaversAuditableRepositoryAspect.applyVersionChanges(JaversAuditableRepositoryAspect.java:89) ~[javers-spring-1.6.4.jar:na]
at org.javers.spring.auditable.aspect.JaversAuditableRepositoryAspect.onVersionEvent(JaversAuditableRepositoryAspect.java:71) ~[javers-spring-1.6.4.jar:na]
at org.javers.spring.auditable.aspect.JaversAuditableRepositoryAspect.onSaveExecuted(JaversAuditableRepositoryAspect.java:59) ~[javers-spring-1.6.4.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_112]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_112]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_112]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_112]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:603) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.aop.aspectj.AspectJAfterReturningAdvice.afterReturning(AspectJAfterReturningAdvice.java:61) ~[spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:53) ~[spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at com.vz.uiam.common.audit.aspect.JPAIdFieldNullifyAspect.monitor(JPAIdFieldNullifyAspect.java:55) ~[uiam_common_cloud-1.0.11.jar:1.0.11]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_112]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_112]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_112]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_112]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at com.sun.proxy.$Proxy149.save(Unknown Source) ~[na:na]

Javers is trying to find the author of the modification in the current web request. However, since you seems not to be in the context of a web request this fail.
If you are truly not in a web request, it seems you need to provide another AuthorProvider bean than ServletRequestAuthorProvider (which may be the default).

The answer given by Nyamiou The Galeanthrope is right, but just to clarify:
com.vz.uiam.common.audit.javers.ServletRequestAuthorProvider is definetly not a JaVers class but some implementation of the AuthorProvider interface.
By default (if you are using spring-boot-starter-data-jpa), JaVers gives you SpringSecurityAuthorProvider.

Related

TomEE encountering "a non-application exception", but only on windows, not on mac

We have a database that, among other entries, contain a "Lecturer" entry. We are trying to query this, but for some reason it only works on macs. Any windows PC we try it on instead returns the error log pasted below.
Our server is a TomEE (Apache Tomcat 7.0) server using postgreSQL JDBC 1212 and it's a dynamic web project using javabeans.
This is for a school project, and none of us have any experience with these kinds of projects, so any help would be greatly appreciated!
Complete errorlogs:
type Exception report
message The bean encountered a non-application exception; nested exception is:
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.ejb.EJBException: The bean encountered a non-application exception; nested exception is:
<openjpa-2.4.0-r422266:1674604 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: null
FailedObject: test [org.apache.openjpa.util.StringId] [java.lang.String]
org.apache.openejb.core.ivm.BaseEjbProxyHandler.convertException(BaseEjbProxyHandler.java:427)
org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:329)
EAO.EAO$$LocalBeanProxy.findLecturer(EAO/EAO.java)
controller.test.doGet(test.java:40)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
<openjpa-2.4.0-r422266:1674604 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: null
FailedObject: test [org.apache.openjpa.util.StringId] [java.lang.String]
org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:1029)
org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:923)
org.apache.openjpa.kernel.DelegatingBroker.find(DelegatingBroker.java:230)
org.apache.openjpa.persistence.EntityManagerImpl.find(EntityManagerImpl.java:486)
org.apache.openejb.persistence.JtaEntityManager.find(JtaEntityManager.java:180)
EAO.EAO.findLecturer(EAO.java:93)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:192)
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:173)
org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:181)
org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:100)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:192)
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:173)
org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:85)
org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:227)
org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:194)
org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(EjbObjectProxyHandler.java:317)
org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:312)
org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:92)
org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:325)
EAO.EAO$$LocalBeanProxy.findLecturer(EAO/EAO.java)
controller.test.doGet(test.java:40)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.NullPointerException
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.setInverseRelation(JDBCStoreManager.java:452)
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initializeState(JDBCStoreManager.java:412)
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initialize(JDBCStoreManager.java:305)
org.apache.openjpa.kernel.DelegatingStoreManager.initialize(DelegatingStoreManager.java:112)
org.apache.openjpa.kernel.ROPStoreManager.initialize(ROPStoreManager.java:57)
org.apache.openjpa.kernel.BrokerImpl.initialize(BrokerImpl.java:1048)
org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:1006)
org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:923)
org.apache.openjpa.kernel.DelegatingBroker.find(DelegatingBroker.java:230)
org.apache.openjpa.persistence.EntityManagerImpl.find(EntityManagerImpl.java:486)
org.apache.openejb.persistence.JtaEntityManager.find(JtaEntityManager.java:180)
EAO.EAO.findLecturer(EAO.java:93)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:192)
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:173)
org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:181)
org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:100)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:192)
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:173)
org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:85)
org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:227)
org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:194)
org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(EjbObjectProxyHandler.java:317)
org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:312)
org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:92)
org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:325)
EAO.EAO$$LocalBeanProxy.findLecturer(EAO/EAO.java)
controller.test.doGet(test.java:40)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
We found an answer!
Turns out, we lacked the statement
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
in our XML document (right underneath the "persistence-unit" section).
In addition, we needed to get an eclipselink.jar file and put it in the lib folder in our TomEE install directory. This solved it!

Error when passing values to other view in eclipse e4

I am using IEventBroker to send the events to other view synchronously
#Inject
private IEventBroker eventBroker;
The sender part has the following code:
Map<String,List<TreeMap<Timestamp, Long>>> StatisticValue = new HashMap<String,List<TreeMap<Timestamp, Long>>>();
//some code to add values in statisticValue
eventBroker.send("value", StatisticValue);
The receiver side has the following code snippet.
#Inject
#Optional
public void getEvent(#UIEventTopic("value")HashMap<String,List<TreeMap<Timestamp, Long>>> entriesForTs)
{
System.out.println("size"+entriesForTs.size());
}
I am getting the following error in the receiving end:
Exception while dispatching event org.osgi.service.event.Event [topic=value] to handler org.eclipse.e4.ui.internal.di.UIEventObjectSupplier$UIEventHandler#6d79dea2
!STACK 0
org.eclipse.e4.core.di.InjectionException: java.lang.NullPointerException
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
at org.eclipse.e4.ui.internal.di.UIEventObjectSupplier$UIEventHandler$1.run(UIEventObjectSupplier.java:49)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:180)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4688)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:205)
at org.eclipse.e4.ui.internal.di.UIEventObjectSupplier$UIEventHandler.handleEvent(UIEventObjectSupplier.java:47)
at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:80)
at com.xyz.abc.project.parts.StatisticsPart.processFiles(StatisticsPart.java:270)
at com.xyz.abc.project.parts.StatisticsPart$5.selectionChanged(StatisticsPart.java:205)
at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:164)
at org.eclipse.jface.util.SafeRunnable$1.run(SafeRunnable.java:128)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:162)
at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:2188)
at org.eclipse.jface.viewers.StructuredViewer.handleSelect(StructuredViewer.java:1211)
at org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected(StructuredViewer.java:1241)
at org.eclipse.jface.util.OpenStrategy.fireSelectionEvent(OpenStrategy.java:239)
at org.eclipse.jface.util.OpenStrategy.access$4(OpenStrategy.java:233)
at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:403)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1057)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4170)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3759)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1113)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:997)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:138)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:162)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
at org.eclipse.equinox.launcher.Main.main(Main.java:1426)
Caused by: java.lang.NullPointerException
at com.xyz.abc.project.parts.showGraph.getEvent(showGraph.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
... 48 more
I am confused why am I getting this error. I have checked the size(size = 2) of the StatisticValue in the sender side. But it is showing some nullpointer exception. Can anyone please help me?
The exception is reporting a NullPointerException in your getEvent method because the entriesForTs is null.
The #UIEventTopic handling code seems to call the event handler once with a null value the first time it is used (and then calls it again with the correct value). So just check for null in your getEvent.
Update:
You could try using org.osgi.service.event.Event as the type of the getEvent argument in case there is some problem with resolving the argument type:
public void getEvent(#UIEventTopic("value") Event event)
{
data = event.getProperty(IEventBroker.DATA);
You could also try IEventBroker.subscribe if the #UIEventTopic refuses to work.
Update 2:
The event broker send (and post) methods treat Map specially and assumes it is a map containing the values you want to send. So it will be looking in the Map for an IEventBroker.DATA key. It would be best to wrap your map in a container class.

Persist list of Entities with <int-jpa:outbound-channel-adapter

I may be missing something here but I cannot seem to find any docs about persisting a List of Entities using Spring Integration JPA Outbound Channel Adapter. I have an extremely simple scenario that should poll a database and copy new data across to another database. Thus:
<int-jpa:inbound-channel-adapter channel="myChannel"
entity-class="my.package.MyClass"
entity-manager="mysqlEntityManager"
auto-startup="true">
<int:poller fixed-rate="5000">
<int:transactional propagation="REQUIRED" transaction-manager="mysqlTransactionManager"/>
</int:poller>
</int-jpa:inbound-channel-adapter>
<int:channel id="myChannel" />
<int-jpa:outbound-channel-adapter channel="myChannel"
entity-class="my.package.MyClass"
entity-manager="hsqldbEntityManager">
<int-jpa:transactional transaction-manager="hsqldbTransactionManager" />
</int-jpa:outbound-channel-adapter>
The inbound-channel-adapter returns a List<MyClass> and then the outbound-channel-adapter throws the stack trace below...
How do I configure the adapter to accept a list of entites? I do not want to set max messages per poll in the inbound adapter/poller, as I would prefer minimal database operations.
Any help appreciated.
Spring docs:
http://static.springsource.org/spring-integration/docs/3.0.0.M1/reference/html/jpa.html
[task-scheduler-1] ERROR org.springframework.integration.handler.LoggingHandler - org.springframework.integration.MessageHandlingException: error occurred in message handler [org.springframework.integration.jpa.outbound.JpaOutboundGateway#165d2be]
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy24.handleMessage(Unknown Source)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:115)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:102)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:157)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:128)
at org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:288)
at org.springframework.integration.core.MessagingTemplate.send(MessagingTemplate.java:149)
at org.springframework.integration.endpoint.SourcePollingChannelAdapter.handleMessage(SourcePollingChannelAdapter.java:97)
at org.springframework.integration.endpoint.AbstractTransactionSynchronizingPollingEndpoint.doPoll(AbstractTransactionSynchronizingPollingEndpoint.java:82)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:146)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:144)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy23.call(Unknown Source)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller$1.run(AbstractPollingEndpoint.java:236)
at org.springframework.integration.util.ErrorHandlingTaskExecutor$1.run(ErrorHandlingTaskExecutor.java:52)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:48)
at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:49)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller.run(AbstractPollingEndpoint.java:231)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:53)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: Unknown entity: java.util.ArrayList
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:692)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
at $Proxy18.merge(Unknown Source)
at org.springframework.integration.jpa.core.DefaultJpaOperations.merge(DefaultJpaOperations.java:175)
at org.springframework.integration.jpa.core.JpaExecutor.executeOutboundJpaOperation(JpaExecutor.java:223)
at org.springframework.integration.jpa.outbound.JpaOutboundGateway.handleRequestMessage(JpaOutboundGateway.java:81)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:134)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)
... 48 more
Caused by: org.hibernate.MappingException: Unknown entity: java.util.ArrayList
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:693)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1485)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:232)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:84)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:867)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:851)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:855)
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:686)
... 59 more
I have created a Jira in order to make that improvement:
https://jira.springsource.org/browse/INT-3029
As a work-around you could also extend DefaultJpaOperations (org.springframework.integration.jpa.core) and customize the persist() method, allowing you to handle a Collection type parameters. For some details see:
Batch inserts with JPA/EJB3
The adapters have an XML namespace attribute jpa-operations, allowing you to provide a reference to custom implementations. For more details, please see http://static.springsource.org/spring-integration/docs/latest-ga/reference/html/jpa.html#jpa-namespace-support-common-attributes
The outbound JPA adapter doesn't currently support persisting a list of entities; feel free to open a new JIRA Issue. You can add a simple <splitter/> before the outbound adapter (no attributes, just input and output channels) and it will bust the list into individual entitities.
However, with your current configuration, each persist will be done in a separate transaction.
Regardless, you probably want to synchronize the two transactions anyway so you should really start the hsql transaction at the same time as the mysql transaction so that Spring will make best efforts to synchronize the two transactions (commit them as close together as possible).
To do that, you'd need something like the ChainedTransactionManager in the 'Best Efforts 1PC' section of Dave Syer's excellent article on this subject.
This way, each of the split entities will be committed in the same transaction.

Ouucre Error:java.io.IOException: invalid header field

I am getting error when i run my application using tomcat 6.0 server...
I don't understand what exactly I'm missing?
Here, I have developed a resteasy Webservice example in which I have a Studentclass with getters and setters
Also I have a List<Student>also with a getter setter and finally i have one Service class that contain business logic..all class is up to date..
But Still i m getting : :java.io.IOException: invalid header field ....
java.io.IOException: invalid header field
at java.util.jar.Attributes.read(Unknown Source)
at java.util.jar.Manifest.read(Unknown Source)
at java.util.jar.Manifest.<init>(Unknown Source)
at org.apache.catalina.util.ExtensionValidator.validateApplication(ExtensionValidator.java:149)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4296)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Please tell me what i have actual missing....?
This error is causing by the mismatch order between “m” and “f” Jar options. Refer this link Link

Is it possible to use a #XmlJavaTypeAdapter annotation to unmarshal a method's return value?

Basically, I'm trying to implement JAXB's XML adapter pattern (#XmlJavaTypeAdapter) in order to transfer Map-style (key-value pair, no SOAP equivalent) objects between a CXF [Java] and .NET [Microsoft] solution (Using WSI Basic 1.1, doc/lit).
To do so, I followed Martin Lansler's adapater example. However, I'm trying to unmarshall my Java method's return type (i.e. MAP, see below). My 'XmlAdapter' class's 'unmarshal' method is never called I get the exception in fig2.
Any ideas what I'm doing wrong?
//From PriceService interface
//We want to unmarshal the 'Map<Integer, Double>' return type
#WebMethod(action="getPriceBreak")
#XmlJavaTypeAdapter(type=java.util.Map.class, value=WSMapAdapter.class)
public Map<Integer, Double> getPriceBreak(#WebParam(name="productCode") String productCode) {
}
//Fig2
INFO: Interceptor has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Unmarshalling Error: unexpected element (uri:"", local:"return"). Expected elements are (none)
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:622)
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:527)
at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:114)
at org.apache.cxf.interceptor.DocLiteralInInterceptor.getPara(DocLiteralInInterceptor.java:240)
at org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:117)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:645)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:2132)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:2015)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1940)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:627)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:471)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:301)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:253)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:121)
at $Proxy36.getPriceBreak(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.doInvoke(JaxWsPortClientInterceptor.java:416)
at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.doInvoke(JaxWsPortClientInterceptor.java:392)
at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.invoke(JaxWsPortClientInterceptor.java:379)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy37.getPriceBreak(Unknown Source)
at fisher.insight.service.TestLocalWSPriceServiceII.testGetPriceBreak(TestLocalWSPriceServiceII.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: javax.xml.bind.UnmarshalException

Categories