📜 ⬆️ ⬇️

Undocumented feature in WebSphere Portal 5.1 (shared session for portlet and servlet)

Was the following task:

write a portlet that displays a graph of the report stored in Cognos. The Cognos report can be built very, very long, from a few seconds to 20.
Making the user wait so much time is a terrible decision.

I decided to put a servlet in the portlet application. When loading, the portlet sends xmlHttpRequest with the path to the report, and in response it receives a relative link to the report picture that the servlet received from Cognos and saved on the server.
It would seem that everything is very, very simple, but the problem is that when refreshing the page or accessing any portlet on the page, Cognos portlet will send a new request to the servlet. This is not necessary, because The picture is already uploaded and you do not need to update it every five minutes.
It is no secret that the visitor of the portal (any other container) has a session. The session is usually put so-called StateBean, bin, which stores all the trash that the user may need while working with the portal. We make in bin field
String pathToImage;
and two methods:
public String getPathToCognosImage(){ return pathToImage}
public void setPathToCognosImage(String path){ pathToImage = path;}


The problem is that when receiving a servlet response, JavaScript cannot call the bean method. I think you understand why.
There is only one way out - to write to the bin on the servlet. But is it possible? As they say, it was impossible to get up on portal 5.0. Unfortunately, I did not find Portal 5.0, and I do not have the opportunity to check this rumor.

The method of accessing a session bean is as follows:
public class GetPathToChartImageServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
//bla-bla-bla
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//getting aditional parameters for Cognos.
//Try to get it from StateBean
Enumeration en = request.getSession().getAttributeNames();
while(en.hasMoreElements()){
attrName = (String)en.nextElement();
Object o = request.getSession().getAttribute(attrName);
System.out.println("attr name " + attrName + " = " + o.toString());
if(o instanceof ru.habr.bean.ChartDataStateBean){
System.out.println("attr name = " + attrName + ". Is my StateBean");
statebean = (ru.habr.bean.ChartDataStateBean)o;
break;
}
}
}//doPost
}//class


The following lines can be found in the console:
[04.06.08 11: 04: 25: 495 MSD] 5A9899ea SystemOut O attr name PC_PRIVATE_5_0_CSI_PortletSessionData = {caiid = 5_0_CSI [PORTLET_ENTITY: 13202], creationTime = 1212562835246, lastAccessedTime = 12126

[04.06.08 11: 04: 25: 495 MSD] 5a9899ea SystemOut O attr name PC_5_0_CSI_en.habr.bean.ChartDataStateBean = ru.habr.bean.ChartDataStateBean@7dc1d9b7

[04.06.08 11: 04: 25: 495 MSD] 5a9899ea SystemOut O attr name = PC_5_0_CSI_en.habr.bean.ChartDataStateBean. Is my statebean

')
Cheers, bin is available!

Before the body of the method ends, you need to remember to write the changes:
String newRelativePathToImageFromCognos = CognosFacadeAdapter.getInstance().runReport(reportStringForCognos);
statebean.setPathToImage(newRelativePathToImageFromCognos);
request.getSession().setAttribute(attrName, statebean);


This possibility is easily explained by the fact that:

Externally, it looks like this:


PS
habracut text = “What should I do?” is displayed not once, but several. Is this a glitch or such a joke?

Source: https://habr.com/ru/post/26790/


All Articles