0

I created an excel file with poi apache. So I used in ExportController.java :

    @RestController
    @RequestMapping("/export")
    @Produces("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
    @Consumes({ "application/json" })

    public class ExportController {

    private static final Logger LOGGER = 
    LoggerFactory.getLogger(ExportController.class);

    @RequestMapping(method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @PreAuthorize(value = "hasRole('AK_M_ADMIN')")
    @ResponseBody
    public Response save(@RequestBody ResultatToExportDto resultToExport, HttpServletResponse response) throws ErosCommonsException {

    final String FILE_NAME = "PlanningExcel.xlsx";
    final XSSFWorkbook workbook = new XSSFWorkbook();
    /*
     *
     * Other code poi apache
     *
     */
    StreamingOutput stream = new StreamingOutput() {
            @Override
            public void write(OutputStream outputStream) throws IOException, WebApplicationException {
                String home = System.getProperty("user.home");
                File excelFile = new File(home + "/Downloads/" + FILE_NAME);
                outputStream = new FileOutputStream(excelFile);
                Writer writer = new BufferedWriter(new OutputStreamWriter(outputStream));
                writer.flush();
                writer.close();
            }
        };

        LOGGER.info("Export Excel Planning Done !!!");

        return Response.ok(stream).build();

    } catch (DefaultErosException e) {
        throwDefaultErosException("Error", e.getErrorResource().getDetailMessage(), HttpStatus.INTERNAL_SERVER_ERROR, e);
    }
    return Response.status(Response.Status.BAD_REQUEST).build();

After that I used in javascript file "planning.js" this rest call in order to save in a folder (or download) my excel file "PlanningExcel.xlsx", using the method saveAs of the library "Filesaver.js"

      $http({
            method: 'POST',
            url: '/dockaWeb/api/rest/resources/export',
            data: resultat
          }).then(function successCallback(resp) {
            console.log("Call ExportController passed");
            var blob = new Blob([resp], {
                type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
            });
            saveAs(blob, 'text.xlsx');
            return data;
          }, function errorCallback(response) {
            console.log("Call ExportController failed: " + response);
          });

But when I try to export my file "PlanningExcel.xlsx", it returns this error in the browser : http://localhost:8080/dockaWeb/api/rest/resources/export 500 (Erreur Interne de Servlet)

{"label":"Internal Server Error","detailMessage":"Could not write content: No serializer found for class com.afklm.docka.web.rest.controllers.ExportController$2 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: org.glassfish.jersey.message.internal.OutboundJaxrsResponse[\"context\"]->org.glassfish.jersey.message.internal.OutboundMessageContext[\"entity\"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class com.afklm.eros.web.rest.controllers.ExportController$2 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: org.glassfish.jersey.message.internal.OutboundJaxrsResponse[\"context\"]->org.glassfish.jersey.message.internal.OutboundMessageContext[\"entity\"])","statusCode":500}

I can't fix this problem. Any help please !

Samounaz
  • 11
  • 1
  • 4
  • 1
    if `com.afklm.docka.web.rest.controllers.ExportController` is your class, then try with implementing `Serializable` – XtremeBaumer Apr 10 '18 at 14:07
  • Its a jackson serialization exception. This post is linked to your problem https://stackoverflow.com/questions/41609163/no-serializer-found-for-class-java-util-logging-errormanager-and-no-properties-d – AbdulAli Apr 10 '18 at 14:24
  • Thank you for your response. for @XtremeBaumer I implemented Serializable but i doesn't work – Samounaz Apr 10 '18 at 14:28
  • thank you AbdulAli. I already tried to use this solution for the object StreamingOutput stream but it doesn't work. – Samounaz Apr 10 '18 at 14:30
  • stream.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); it returns this error : The method configure(SerializationFeature, boolean) is undefined for the type StreamingOutput – Samounaz Apr 10 '18 at 14:35
  • Any help for the error: Could not write content: No serializer found for class com.afklm.docka.web.rest.controllers.ExportController$2 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) ? thank you in advance – Samounaz Apr 10 '18 at 15:08

0 Answers0