Create a new servlet to be used along Vaadin 8

Hello folks,

this is my first post here, so my apologies if this is not the right place to put this question, or if the technical terms are not the most accurate.

I need to create a servlet that should be used within a vaadin 8 + spring-boot application. I have already found out how to create a custom servlet to replace the vaadin one, but what a really need is to develop another servlet that will send a response to the requester in a very specific way. Bellow you can find the code of the test servlet i’ve created. Please bear in mind that this is a test Servlet, so the code is a little bit ugly. As soon as I get it to work (i.e. get registered and available), it will properly rewritten.


import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Session;
import org.hibernate.jdbc.Work;
import org.springframework.stereotype.Component;

import com.flexmonster.compressor.Compressor;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinServlet;
import com.vaadin.spring.server.SpringVaadinServlet;

import cl.vmetrix.persistencelayer.database.DatabaseBO;
import cl.vmetrix.vcube.viewlayer.flexmonster.FlexmonsterUI;
import cl.vmetrix.vcube.viewlayer.ui.VCubeUI;

@WebServlet(value = "/vqueryPivotData/*", asyncSupported = true)
//@VaadinServletConfiguration(productionMode = true, ui = FlexmonsterUI.class)
public class FlexmonsterCompressorServlet extends  VaadinServlet {

	private static final long serialVersionUID = -4997305985202070360L;
    protected void servletInitialized() throws ServletException {
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
		try {
			DatabaseBO db = DatabaseBO.getDatabaseFromPool( "VCUBE" );
			Session session = db.getConnection();
			session.doWork(new Work() {
			    public void execute(Connection connection) throws SQLException {
			    	String query = "Select * from  VCUBE_USER.MAPPINGTEST1";
			    	Statement statement = connection.createStatement();
					ResultSet resultSet = statement.executeQuery(query);
					InputStream inputStream = Compressor.compressDb(resultSet);

					try {
						OutputStream outputStream = response.getOutputStream();
						int length = 0;
						byte[] buffer = new byte[102400]
; //100mb
						while ((length = > 0) {
							outputStream.write(buffer, 0, length);
					} catch (Throwable e) {


		} catch (Exception e) {

Thanks in advance

An additional info: In the logs I can see the following line, meaning (according to my understanding) that the servlet is loaded, but not with the expected context:

2018-09-06 13:49:47 INFO  ServletRegistrationBean:190 - Mapping servlet: 'flexmonsterServlet' to 

Got it working… Here’s the approach in case someone needs it in the future:

1- Implemented a Servlet extending VaadinServlet, overriding the service method:

public class CustomServlet extends  VaadinServlet {

    protected void service(HttpServletRequest request,
            HttpServletResponse response)
            throws ServletException, IOException {}

2- Created a dummy UI

public class CustomServletUI extends UI{

	protected void init(VaadinRequest request) {
		System.out.println( "init" );


3- Registered the servlet manually in one of my configuration classes:

public class ApplicationConfiguration {

	public ServletRegistrationBean flexmonsterServlet() {
		   ServletRegistrationBean servRegBean = new ServletRegistrationBean();
		   servRegBean.setServlet(new FlexmonsterCompressorServlet());
		   servRegBean.addInitParameter("UI", "com.custom.CustomServletUI");
		   return servRegBean;

Thanks! it worked!