Using the web viewer in a Spring Boot applicatin

Stimulsoft Reports.JAVA discussion
Post Reply
evmcl
Posts: 5
Joined: Wed Dec 09, 2020 5:19 am

Using the web viewer in a Spring Boot applicatin

Post by evmcl »

I am trying to use the web viewer for a report in a Spring Boot application and getting an exception regarding trying to serialize an StiReport object to a byte array.

The start of the stack trace is:

Code: Select all

org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.Object] to type [byte[]] for value 'com.stimulsoft.report.StiReport@14e89d9f'; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.io.NotSerializableException: com.stimulsoft.report.events.StiBeginRenderEvent
	at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:47) ~[spring-core-5.2.9.RELEASE.jar:5.2.9.RELEASE]
	at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:191) ~[spring-core-5.2.9.RELEASE.jar:5.2.9.RELEASE]
	at org.springframework.session.jdbc.JdbcIndexedSessionRepository.serialize(JdbcIndexedSessionRepository.java:589) ~[spring-session-jdbc-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.session.jdbc.JdbcIndexedSessionRepository.lambda$insertSessionAttributes$5(JdbcIndexedSessionRepository.java:486) ~[spring-session-jdbc-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.jdbc.core.JdbcTemplate.lambda$update$0(JdbcTemplate.java:865) ~[spring-jdbc-5.2.10.RELEASE.jar:5.2.10.RELEASE]
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:617) ~[spring-jdbc-5.2.10.RELEASE.jar:5.2.10.RELEASE]
The full (and lengthy) stack trace is available in this pastebin.

The method in the controller is:

Code: Select all

@RequestMapping( "/reports/stimulsofttest" )
public String viewStimulsoftReportTest( Model model )
  throws IOException, SAXException, StiDeserializationException
{
  final StiReport report = StiSerializeManager
      .deserializeReport(new File("/path/to/report.mrt"));
  final StiJDBCDatabase dbLMSv3 = (StiJDBCDatabase) report.getDictionary().getDatabases().get("MyDb");
  dbLMSv3.setConnectionString(stimulsoftConnection);
  report.render();
  final StiWebViewerOptions options = new StiWebViewerOptions();
  model.addAttribute("report", report);
  model.addAttribute("options", options);
  return "jsp/reports/stimulsofttest";
}
And the JSP file is:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://stimulsoft.com/webviewer" prefix="stiwebviewer"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test Stimulsoft Report Embedding</title>
</head>
<body>
  <p>Report embedded in page here.</p>

  <stiwebviewer:webviewer report="${report}" options="${options}"/>

</body>
</html>
So when I try and access ni my browser, seems as part of rendering the JSP page, Spring tries to serialize the StiReport object to a byte stream and fails, throwing the above stacktrace.

Any idea how to get this to work?
Vadim
Posts: 362
Joined: Tue Apr 23, 2013 11:23 am

Re: Using the web viewer in a Spring Boot applicatin

Post by Vadim »

Hello.

Spring tries to serialise StiReport (exception not in Stimulsoft libs)

org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.Object] to type [byte[]] for value 'com.stimulsoft.report.StiReport@14e89d9f'; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.io.NotSerializableException: com.stimulsoft.report.events.StiBeginRenderEvent

You should check why it happens.
evmcl
Posts: 5
Joined: Wed Dec 09, 2020 5:19 am

Re: Using the web viewer in a Spring Boot applicatin

Post by evmcl »

Spring tries to serialise StiReport (exception not in Stimulsoft libs)
Yeah, I already understood that that is what was happening. Was hoping someone had perhaps run across this problem before, or could provide a working example with Spring Boot that I could compare to to try and figure out why we are having this issue.
Lech Kulikowski
Posts: 6198
Joined: Tue Mar 20, 2018 5:34 am

Re: Using the web viewer in a Spring Boot applicatin

Post by Lech Kulikowski »

Hello,

Sorry, we do not have Spring Boot samples.
We have only these samples https://www.stimulsoft.com/en/samples/java

Please send your sample to support@stimulsoft.com

Thank you.
evmcl
Posts: 5
Joined: Wed Dec 09, 2020 5:19 am

Re: Using the web viewer in a Spring Boot applicatin

Post by evmcl »

I've mostly got this sorted. In my Spring application I am serialising session variables to be cached in the database (spring-session-jdbc). This overrides the standard Tomcat HttpSession.

It looks like the stiwebviewer stashes the StiReport object into the session object, which is when the exception occurs. If I switch to purely in-memory session management then it all works.

I'm assuming there's no easy way to get stiwebviewer to not use the session object?
Vadim
Posts: 362
Joined: Tue Apr 23, 2013 11:23 am

Re: Using the web viewer in a Spring Boot applicatin

Post by Vadim »

Hello.

We use HTTP session to store StiReport & other objects, there is no way to turn it off.
Post Reply