HTTP output without JSF page

gmehra764's picture

I need very simple output right from the script task, but the only way to do that is to create variable and populate it with the data in the script task and then create web page task in Studio with all JSF related stuff just to display content of that variable. Is there a way to do it easier? Much appreciated!

squeakywheel's picture

I had the same problem.

I had the same problem. Actually it turned out that as long as you have access to HTTPServletResponse object that is easy. Try this code as an example.

HttpServletResponse response = bpContext.getHTTPResponse();
response.setContentType("text/plain");

PrintWriter out = response.getWriter();

out.println(“My simple output here”);

response.setStatus(HttpServletResponse.SC_OK);

response.flushBuffer();
 

gmehra764's picture

Great! Did not know that

Great! Did not know that HTTPServletResponse is available through bpContext.

emily23m's picture

Can I totally substitute JSF

Can I totally substitute JSF web form tasks with script task?

squeakywheel's picture

You can try, just put two

You can try, just put two script tasks one by one, but I suspect that it will be impossible. So the first script task with such output will effectively end web session.

Let me know how the result.

emily23m's picture

You were right. I've got a

You were right. I've got a page with the output from both script tasks. Apparently system executes second script task as soon as it finishes with the first. It does not wait until form is submitted. I guess because script task is not the web form. Anyway using script task at the end of the process when just one output is required is still lightweight and useful. Thank you for your tip squeakywheel!

ameshkov's picture

The right code will

The right code will be:

 

HttpServletResponse response = bpContext.getHTTPResponse();
response.setContentType("text/plain");

PrintWriter out = response.getWriter();

out.println(“My simple output here”);

response.setStatus(HttpServletResponse.SC_OK);

response.getWriter().close();

 

Last line closes connection, which may be important.