I'm getting 2 requests on a JSP page, then I process data in Util class. But how can I keep data from first request ? It seems like second request deletes all content of first request I save in vars.
Request are issued by 2 different send() in my orbeon process.
Here is how I would like to save my data on JSP :
// read request parameters
String documentId = request.getParameter("document");
String pdfUrl = "";
String base64Data = "";
// read request content (XML data entered by the user)
String data = Utils.readRequestBody(request);
if (Utils.isUrl(data)) {
pdfUrl = Utils.getUrl(data);
} else {
base64Data = Utils.encodeb64(data);
}
Here are my methods in Utils class :
public static boolean isUrl(String data) {
boolean isUrl = false;
String urlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><uri>";
if (data.toLowerCase().contains(urlString.toLowerCase())) {
isUrl = true;
}
return isUrl;
}
public static String getUrl(String data) {
String urlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><uri>";
data = data.substring(urlString.length(), data.length()-7);
return data;
}
public static String readRequestBody(HttpServletRequest req) throws IOException {
StringBuilder sb = new StringBuilder();
String line = null;
BufferedReader reader = req.getReader();
while ((line = reader.readLine()) != null) {
// important to add lineSeparator to preserve line feeds in multiline text fields
sb.append(line).append(System.lineSeparator());
}
return sb.toString();
}
public static String encodeb64(String s) {
return new String(Base64.getEncoder().encode(s.getBytes()));
}
So I think I didn't understand something so I need help to learn how to handle this case.
Best regards,
Joseph
I just had to create HttpSession in the JSP to make it work. Thank you @Jacek Cz for the reminder about this.