Buongiorno a tutti, sto tentando di inviare un' immagine dopo la sua creazione su richiesta dell' utente, tramite form.
Questo è l'HomeController.java:
codice:
package org.drawweb.demo.controller;
import org.drawweb.demo.model.InfoDraw;
import org.drawweb.demo.service.InfoDrawService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
@Controller
publicclass HomeController {
@Autowired
private InfoDrawService infoDrawService;
@GetMapping("/draw")
public String getDrawWeb() {
return"DrawWeb"; //Pagina Web che contiene il grafico
//con l'immagine vuota e gli inpute per le coordinate X,Y,Z inserite dall'utente.
}
@PostMapping("/save")
public String postDrawWeb(@ModelAttribute InfoDraw infoDraw) {
System.out.println(infoDraw.getX()+","+infoDraw.getY()+","+infoDraw.getZ());
infoDrawService.setInfoDraw(infoDraw);
return"DrawWebEdit"; //Pagina Web che contiene il grafico
//modificato su richiesta dal form in DrawWeb.
}
}
Invece questo è l'infoDrawServices.java (Che si occupa di lanciare l'APP Draw che disegna in background e successivamente salvarla in un file ricghiamato dopo dal form DrawWebEdit)
codice:
package org.drawweb.demo.service;
import java.io.File;
import java.io.IOException;
import org.drawweb.demo.model.InfoDraw;
importorg.springframework.stereotype.Service;
import draw3d.*;
@Service
publicclass InfoDrawService {
String getPathImage(){
String filename = "ass-isometrica.png";
filename = System.getProperty("user.dir")+File.separator+filename;
returnfilename;
}
String getPathImageSave(){
String filename = "ass-isometrica-saved.png";
String sub_folder = "src/main/resources/static/img/";
filename = System.getProperty("user.dir")+File.separator+sub_folder+filename;
returnfilename;
}
publicvoid setInfoDraw(InfoDraw infoDraw) {
Immagine img = new Immagine(getPathImage());
new Draw(infoDraw, img);
try {
img.saveImage(getPathImageSave());
} catch (IOException ioex) {
System.out.println("Errore nel salvataggio dell' immagine elaborata");
};
}
}
Il problema è nella sincronizzazione dei processi?
Viene visualizza l'immagine elaborata precedentemente e non quella attuale!
L'immagine viene creata...ma successivamente non viene in "tempo" visualizzata.