Home
Analytics
Session handler in birt report
krabu
Hi,
I have a problem with sending session atribute from my aplication to birt. In my aplication I set the atribute in the following way:
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();
HttpSession httpSession = request.getSession(false);
httpSession.setAttribute("login", this.login);
In my report I try to access the httpsession atribute by:
login = reportContext.getHttpServletRequest().getAttribute("login").getReportTitle();
When I execute my report I receive the null values of "login" variable.
I don't know how to make it works ... please help
Find more posts tagged with
Comments
JasonW
Can you try:
var request = reportContext.getHttpServletRequest();
var login = request.getSession().getAttribute("login");
Also run this report to see what is currently loaded
krabu
Thanks for the response,<br />
<br />
I've executed report you sent me, but I don't have any attribute called login in the report, so I think that the problem is somewhere in my application.<br />
<br />
So what i'm doing in my application .... in one of my method which is executing during authentication proces I set the login attribute by:<br />
<br />
<em class='bbc'>public void setSession(){<br />
// Set session Object in Session <br />
FacesContext context = FacesContext.getCurrentInstance(); <br />
HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest(); <br />
HttpSession httpSession = request.getSession(false); <br />
httpSession.setAttribute("login", this.login); <br />
}</em><br />
<br />
After the authentication process the user can see some links on his page. When the user clicks on one of the links I redirect him the exact report by url:<br />
http://"+"ip_addr"+":8080/Files/frameset?__report="+report.reportPath<br
/>
<br />
When I execute in this way the report you sent me , as i said, I see no "login" attribute.<br />
<br />
I'm using the birt developer and the birt runtime engine version 2.2.2<br />
<br />
Any suggestion?
JasonW
The problem is that session is not shared across contexts. You will need to decide how you want to pass the information from one context to the other. There are alot of options out there, including session sharing, using a cookie, JNDI, etc.
Jason
JasonW
You may also want to read over this:<br />
<a class='bbc_url' href='
http://www.fwd.at/tomcat/sharing-session-data-howto.html'>The
Tomcat 4 Servlet/JSP Container - Sharing session data between contexts HOW-TO</a>
JasonW
Another option may be to add a jsp page to the BIRT Viewer that gets information from the request and adds it to the viewers session and then forwards to the /frameset mapping.
krabu
Okey, thanks for the response
In my report, inside the beforeFactory method I've created the following code:
var request = reportContext.getHttpServletRequest();
cookys = request.getCookies();
if( cookys ) {
testcook = "Cookies:: ";
for( uu=0; uu < cookys.length; uu++ ){
testcook += cookys[uu].getName() + " :: " +
cookys[uu].getValue();
}
}else{
testcook = "No cookies";
}
reportContext.setPersistentGlobalVariable("testcook", testcook);
So .. at the end I've received the testcook variable, which contains all my cookies.
Inside the fetch method I've put the following code:
row["testcook"] = reportContext.getPersistentGlobalVariable('testcook');
When I run the report I receive the blank report .... no data ... no cokies
Any suggestion?
JasonW
How are you setting the cookie? Verify domain and path.<br />
<br />
Try this in the before factory and then check what gets created in the file.<br />
<br />
importPackage( Packages.java.io );<br />
importPackage( Packages.javax.servlet.http );<br />
<br />
var cookies = reportContext.getHttpServletRequest( ).getCookies();<br />
<br />
out = new PrintWriter( new FileWriter( "c:/temp/cookies.txt", true ) );<br />
var login;<br />
var password;<br />
out.println("fetching cookies");<br />
out.println("cookies.length : " + cookies.length);<br />
for(var i=0; i < cookies.length; i++) {<br />
var monCookie = cookies
;<br />
out.println("cookie found : " + monCookie.getName());<br />
}<br />
out.close(); <br />
<br />
Jason
krabu
Jason thanks for the response one more time!
According to code you sent I receive the correct data in the c:/temp/cookies.txt .... so I set the cookie in the correct way.
How can I present the value of cookie in my report or set it as parametr?
All I want to do is make some authentication ... read the cookie ("login" from my application ) value and parameterize the report in some way to deny access or visibility of data for unauthenticated users ...
JasonW
Since you are only using the cookie at generation time you should be able to put an if statement in the for loop that checks for your login cookie:<br />
<br />
if (monCookie.getName().equals("login")) {<br />
loginglobal = cookies
.getValue();<br />
}<br />
<br />
Do not use the var keyword with the loginglobal. You should be able to use this variable in any of the oncreate, expressions, etc. You should even be able to use loginglobal on filter for the dataset.<br />
<br />
Jason
krabu
Thanks for the response one more time!
Now I know how to read the login value from the cookie but the problem is something more ...
I have an application based on JSF pages, during the authentication process I set a cookie and read it in the beforeFactory method inside the report (as you described before). As a result I receive the variable in beforeFactory method, which contains login cookie value.
Is there any way to redirect/block the report page when the user is not logged in?
The only sollution I've found is creating Data Set which present the cookie login value (e.g. if set login = "login_from_cookie" else login = "none")
In my report I've created one big table with the visibility condition:
if(row["propValue"] =="none"){
true
}else{
false
}
Every object I put inside this table ... so when the user is logged in, he sees complete report, if not a blank page. It works but I'm not sure is it the right and elegant sollution ...
Do you know any other simplier sollution how to parameterize the report in some way to deny access or visibility of data for unauthenticated users ??
JasonW
You could use a text element contianing some client javascript that checks the value and redirects them to your login page. In both solutions the report will still run. Another option would be to check the value and drop the table from the report (so it does not run). You could also use the text element in combination with this solution.
Jason
krabu
thanks Jason for response,<br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="JasonW"><p>Another option would be to check the value and drop the table from the report (so it does not run). <br />
Jason</p></blockquote>
<br />
How can I do that? What do you mean by "dropping table"??
JasonW
yes you can. In the beforeFactory event get the design handle like:
var rdh = reportContext.getDesignHandle();
If you have named the table, say mytable (general properties for the table).
You can then drop it like:
rdh.findElement("mytable").drop();
Jason