SecurityContext issue when running subreport



since running subreports involves multithreading, I am running into an issue when producing certain reports, but not all, that include SUBREPORTS. The point is that the host platform (CUBA Platform) throws an IllegalStateException when calling Service methods from a subreport thread. I presume that for one-level reports the main thread is the same main thread running the middleware and therefore it arises no problem for subreport-less reports. However this is not 100% true, then I have one report with nested subreports which calls Service methods as well, but no problem arises.

For the affected reports, when running a subreport (presuming from a subreport thread) the following exception arises:

java.lang.SecurityException: No security context bound to the current thread
    at com.haulmont.cuba.core.sys.AppContext.getSecurityContextNN(
    at com.haulmont.cuba.core.sys.ServiceInterceptor.aroundInvoke(
    at sun.reflect.GeneratedMethodAccessor108.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(
    at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(
    at com.sun.proxy.$Proxy256.getFechaDevuelto(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(
    at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(
    at net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(
    at java.util.concurrent.ThreadPoolExecutor.runWorker(
    at java.util.concurrent.ThreadPoolExecutor$

As I said, this doesn't happen with all reports that contain subreports, but this cause seems to be the main one. So either the report containing subreports uses only the main thread, or the failure is due to any other reason.

Is there the possibility to some how include a couple of lines of code in the thread to apply a securitycontext provided by the host platform? Additionally, is there another besides setting Jasperreports to single-threaded mode, to prevent from multithreading? Or something in the report I can somehow tweak? I have inspected reports (all including subreports) both working and failing, and at first sight nothing seems to affect the usage of a separate thread.

Deactivating multithreading is not an option then in parallel I have read performance degrades substantially.

Many thanks for your time and attention.


Carlos Conti.

carloscz25's picture
Joined: Mar 31 2010 - 8:56am
Last seen: 7 months 2 days ago

0 Answers:

No answers yet