Skip to content

Commit

Permalink
Bugfix KNOWAGE-8140
Browse files Browse the repository at this point in the history
  • Loading branch information
davide-zerbetto authored Sep 11, 2023
2 parents 315174a + c3e32c7 commit eb94189
Show file tree
Hide file tree
Showing 6 changed files with 554 additions and 640 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,18 @@ public class KnowageCaptchaServlet extends HttpServlet {
*
*/
private static final long serialVersionUID = -1268155968745374787L;
protected int width;
protected int height;

public KnowageCaptchaServlet() {
width = 200;
height = 50;
}

@Override
public void init() throws ServletException {
public void doGet(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse) throws ServletException, IOException {
int width = 200;
int height = 50;

if (getInitParameter("height") != null)
height = Integer.valueOf(getInitParameter("height")).intValue();
if (getInitParameter("width") != null)
width = Integer.valueOf(getInitParameter("width")).intValue();
}

@Override
public void doGet(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse) throws ServletException, IOException {

ImageCaptcha imageCaptcha = new ImageCaptcha.Builder(width, height).addContent().addBackground().addFilter(new FishEyeImageFilter()).addBackground()
// .addBackground(new SquigglesBackgroundProducer())
.build();
writeImage(httpservletresponse, imageCaptcha.getImage());
httpservletrequest.getSession().setAttribute("simpleCaptcha", imageCaptcha);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ public class AdapterHTTP extends HttpServlet {

private static final String SERIALIZE_SESSION_ATTRIBUTE = "COMMON.SERIALIZE_SESSION";

// Atributo della configurazione che indica se serializzare il contenuto
// della sessione
private boolean serializeSession = false;

private void handleQueryStringField(HttpServletRequest request, SourceBean serviceReq, String queryStringFieldName) throws SourceBeanException {

String queryString = queryStringFieldName.substring(queryStringFieldName.indexOf("{") + 1, queryStringFieldName.indexOf("}"));
Expand Down Expand Up @@ -288,6 +284,8 @@ private void handleSimpleForm(HttpServletRequest request, RequestContextIFace re

@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
boolean serializeSession = this.getSerializedSession();

Monitor monitor = null;
IEventNotifier eventNotifier = null;
RequestContextIFace requestContext = null;
Expand Down Expand Up @@ -579,19 +577,11 @@ private void setHttpRequestData(HttpServletRequest request, RequestContainer req

// RequestContainer requestContainer)

/*
* (non-Javadoc)
*
* @see javax.servlet.GenericServlet#init()
*/
@Override
public void init() throws ServletException {
super.init();

private boolean getSerializedSession() {
String serializeSessionStr = (String) ConfigSingleton.getInstance().getAttribute(SERIALIZE_SESSION_ATTRIBUTE);
if ((serializeSessionStr != null) && (serializeSessionStr.equalsIgnoreCase("TRUE"))) {
serializeSession = true;
return true;
}
return false;
}

} // public class ActionServlet extends HttpServlet
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

public class BirtImageServlet extends HttpServlet {

private transient Logger logger = Logger.getLogger(this.getClass());
private static final Logger logger = Logger.getLogger(BirtImageServlet.class);
private static final String CHART_LABEL = "chart_label";

/*
Expand Down Expand Up @@ -161,12 +161,11 @@ public void run() {

/**
* This method execute the engine chart and returns its image in byte[]
*
*
* @param userId
* @param session
*
* @param request
* the httpRequest
* @param request the httpRequest
* @return the chart in inputstream form
*/
private InputStream executeEngineChart(Map parametersMap, HttpSession session, String userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
**/
public class BirtReportServlet extends HttpServlet {

private IReportEngine birtReportEngine = null;
// private IReportEngine birtReportEngine = null;
protected static Logger logger = Logger.getLogger(BirtReportServlet.class);
private static final String CONNECTION_NAME = "connectionName";
public static final String JS_EXT_ZIP = ".zip";
Expand Down Expand Up @@ -287,7 +287,7 @@ protected String handleImage(IImage image, Object context, String prefix, boolea
return renderOption;
}

private InputStream getTemplateContent(HttpServletRequest servletRequest) throws IOException {
private InputStream getTemplateContent(HttpServletRequest servletRequest, IReportEngine birtReportEngine) throws IOException {
logger.debug("IN");
HttpSession session = servletRequest.getSession();
IEngUserProfile profile = (IEngUserProfile) session.getAttribute(IEngUserProfile.ENG_USER_PROFILE);
Expand Down Expand Up @@ -358,14 +358,14 @@ private InputStream getTemplateContent(HttpServletRequest servletRequest) throws
}
String resourcePath = getBirtExecutionTempDirName(executionId);
if (resourcePath != null) {
this.birtReportEngine.getConfig().setResourcePath(resourcePath);
birtReportEngine.getConfig().setResourcePath(resourcePath);
}

} else {
String resPath = BirtEngineConfig.getEngineResourcePath();
if (resPath != null) {
logger.debug("Resource path is [" + resPath + "]");
this.birtReportEngine.getConfig().setResourcePath(resPath);
birtReportEngine.getConfig().setResourcePath(resPath);
} else {
logger.debug("Resource path is null");
// TODO: should I throw an exception here?
Expand All @@ -376,7 +376,7 @@ private InputStream getTemplateContent(HttpServletRequest servletRequest) throws
return is;
}

protected Map findReportParams(HttpServletRequest request, IReportRunnable design) throws ConnectionDefinitionException {
protected Map findReportParams(HttpServletRequest request, IReportRunnable design, IReportEngine birtReportEngine) throws ConnectionDefinitionException {
logger.debug("IN");
String dateformat = request.getParameter("dateformat");
if (dateformat != null) {
Expand Down Expand Up @@ -502,11 +502,11 @@ protected void runReport(HttpServletRequest request, HttpServletResponse respons
logger.debug("documentId=" + documentId);

ServletContext servletContext = getServletContext();
this.birtReportEngine = BirtEngine.getBirtEngine(request, servletContext);
IReportEngine birtReportEngine = BirtEngine.getBirtEngine(request, servletContext);
IReportRunnable design = null;

// retrieve once in order to convert into string and check if contains javascript for progressive view
InputStream isToString = getTemplateContent(request);
InputStream isToString = getTemplateContent(request, birtReportEngine);
int n = isToString.available();
byte[] bytes = new byte[n];
isToString.read(bytes, 0, n);
Expand All @@ -515,7 +515,7 @@ protected void runReport(HttpServletRequest request, HttpServletResponse respons

// reds again in order to make template

InputStream is = getTemplateContent(request);
InputStream is = getTemplateContent(request, birtReportEngine);
logger.debug("runReport(): template document retrieved.");
// Open the report design
design = birtReportEngine.openReportDesign(is);
Expand Down Expand Up @@ -600,7 +600,7 @@ protected void runReport(HttpServletRequest request, HttpServletResponse respons
logger.debug("runReport(): RunAndRenderTask created successfully.");

// Set parameters for the report
Map reportParams = findReportParams(request, design);
Map reportParams = findReportParams(request, design, birtReportEngine);

String requestConnectionName = request.getParameter(CONNECTION_NAME);
logger.debug("requestConnectionName:" + requestConnectionName);
Expand Down Expand Up @@ -711,7 +711,7 @@ protected void runReport(HttpServletRequest request, HttpServletResponse respons
response.setHeader("Content-disposition", "inline; filename=" + templateFileName + ".ps");
} else if (outputFormat != null && outputFormat.equalsIgnoreCase(DataExtractionParameterUtil.EXTRACTION_FORMAT_CSV)) {
logger.debug(" Output format parameter is CSV. Create document obj .");
prepareCSVRender(reportParams, request, design, userId, documentId, profile, kpiUrl, response, context);
prepareCSVRender(reportParams, request, design, userId, documentId, profile, kpiUrl, response, context, birtReportEngine);
return;

} else {
Expand All @@ -726,7 +726,7 @@ protected void runReport(HttpServletRequest request, HttpServletResponse respons
IRunAndRenderTask runAndRenderTask = null;
IRunTask runTask = null;

if (progressiveViewing == false) { // Traditional run and rendering
if (!progressiveViewing) { // Traditional run and rendering
// Create task to run and render the report,
runAndRenderTask = birtReportEngine.createRunAndRenderTask(design);
runAndRenderTask.setLocale(locale);
Expand All @@ -737,7 +737,7 @@ protected void runReport(HttpServletRequest request, HttpServletResponse respons
runAndRenderTask.setRenderOption(renderOption);
logger.debug("runReport(): RunAndRenderTask created successfully.");
} else { // progressive run
ProgressiveCustomPageHandler myPageHandler = new ProgressiveCustomPageHandler((String) context.get(REPORT_EXECUTION_ID));
ProgressiveCustomPageHandler myPageHandler = new ProgressiveCustomPageHandler((String) context.get(REPORT_EXECUTION_ID), birtReportEngine);
runTask = birtReportEngine.createRunTask(design);
runTask.setLocale(locale);
runTask.setPageHandler(myPageHandler);
Expand All @@ -756,7 +756,7 @@ protected void runReport(HttpServletRequest request, HttpServletResponse respons
logger.debug("Execution id is : " + reportExecutionId);

try {
if (progressiveViewing == false) {
if (!progressiveViewing) {
runAndRenderTask.run();
} else {
String file = OUTPUT_FOLDER + reportExecutionId + ".rptdocument";
Expand Down Expand Up @@ -911,15 +911,15 @@ private Map getTaskContext(String userId, Map reportParams, HttpServletRequest r
*/

private void prepareCSVRender(Map reportParams, HttpServletRequest request, IReportRunnable design, String userId, String documentId,
IEngUserProfile profile, String kpiUrl, HttpServletResponse response, Map context) throws Exception {
IEngUserProfile profile, String kpiUrl, HttpServletResponse response, Map context, IReportEngine birtReportEngine) throws Exception {

logger.debug("IN");

IReportDocument reportDocument = null;

try {

reportDocument = getReportDocument(design, reportParams, context);
reportDocument = getReportDocument(design, reportParams, context, birtReportEngine);

logger.debug("Report document obtained for report " + design.getReportName() + "; pages count = " + reportDocument.getPageCount());

Expand Down Expand Up @@ -1086,7 +1086,7 @@ protected String getCSVEncoding() {
return encoding;
}

protected IReportDocument getReportDocument(IReportRunnable design, Map reportParams, Map context) throws EngineException {
protected IReportDocument getReportDocument(IReportRunnable design, Map reportParams, Map context, IReportEngine birtReportEngine) throws EngineException {
logger.debug("IN");
IReportDocument toReturn = null;
IRunTask runTask = null;
Expand Down Expand Up @@ -1165,12 +1165,13 @@ public class ProgressiveCustomPageHandler implements IPageHandler {
// Define local variables for the callback class
private int lastCheckpoint = 0;
private String reportExecutionId = null;
private IReportEngine birtReportEngine = null;

public ProgressiveCustomPageHandler(String reportExecutionId) {
public ProgressiveCustomPageHandler(String reportExecutionId, IReportEngine birtReportEngine) {
this.reportExecutionId = reportExecutionId;
this.birtReportEngine = birtReportEngine;
}

// @Override
@Override
public void onPage(int pageNumber, boolean readyForViewing, IReportDocumentInfo reportDocument) {
// we only want to do something if this is a checkpoint event
Expand Down
Loading

0 comments on commit eb94189

Please sign in to comment.