You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by Akshay Ahooja <ak...@gmail.com> on 2006/07/17 17:46:38 UTC

Passing values to Apps outside of Jetspeed

Hi,

I have some external previously made apps that I would like users to be able
access from Jetspeed. Instead of just creating a link to the page, I would
like to pass the external app some user information that can be used for
attribute purposes.

How would I pass values from a Jetspeed-2 Portlet to a new regular web app
window? (both Struts Based)

I don't think that setAttribute would work since it would open up a whole
new session right?

Thanks,

Akshay

Re: Passing values to Apps outside of Jetspeed

Posted by Akshay Ahooja <ak...@gmail.com>.
Yeah I changed the crossContext for both the portal and the external app.

The getAttribute("user",PortletSession.APPLICATION_SCOPE) you had suggested
is a PortletSession only method. The "request" in the previous email was not
a PortletRequest...

Since I am retreving "user" from an external non-portlet Struts app I cannot
create a PortletSession to use this method.

Is there something I'm missing out?? From what I've read till now, the
PortletSession is just an interface, and also is valid within the http
request context. I need to use an http request session object to get the
attribute.

-Akshay


myportal.xml:
<Context path="/myportal" docBase="myportal" crossContext="true">

  <Realm className="org.apache.catalina.realm.JAASRealm"
         appName="Jetspeed"
         userClassNames="org.apache.jetspeed.security.impl.UserPrincipalImpl
"
         roleClassNames="org.apache.jetspeed.security.impl.RolePrincipalImpl
"
         useContextClassLoader="false"
         d...

sheet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/rapsheet" docBase="rapsheet" crossContext="true"/>

Re: Passing values to Apps outside of Jetspeed

Posted by Aaron Evans <aa...@gmail.com>.
On 7/18/06, Akshay Ahooja <ak...@gmail.com> wrote:
> Hi,
>
> I followed the steps as you suggested but the value does not seem to pass to
> the external app...
>
> In J2 Struts Portlet:
>
>             PortletRequest prequest = (PortletRequest)request.getAttribute("
> javax.portlet.request");
>             prequest.getPortletSession().setAttribute("user",firstName,
> PortletSession.APPLICATION_SCOPE);
>
>             ...
>             <%=(String)request.getSession().getAttribute("user")%>   //works
> here in j2 - therefore it is stored in scope
>

Hmm, that's funny, you should get null. The correct call would be:

request.getSession().getAttribute("user",PortletSession.APPLICATION_SCOPE);

> ...
> <a href="http://bsmith:8080/sheet/search.jsp" target="_blank"> Search </a>
> //to the external APP
>
> //note: using html:link wont open an external app but rather one in context
> - thats why I used <a href
>
>
> In External App - search.jsp
>
> <%=(String)request.getSession().getAttribute("user")%>
>
> The value is coming out to be null.
>
>
>
> In myportal.xml:
> <Context path="/myportal" docBase="myportal" crossContext="true">
>
>
> Any ideas why the value isn't in external scope?

Make sure that *all* contexts involved (jetspeed and your other apps)
have crossContext set to true.

>
> Thanks,
>
> Akshay
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Re: Passing values to Apps outside of Jetspeed

Posted by Akshay Ahooja <ak...@gmail.com>.
Hi,

I followed the steps as you suggested but the value does not seem to pass to
the external app...

In J2 Struts Portlet:

            PortletRequest prequest = (PortletRequest)request.getAttribute("
javax.portlet.request");
            prequest.getPortletSession().setAttribute("user",firstName,
PortletSession.APPLICATION_SCOPE);

            ...
            <%=(String)request.getSession().getAttribute("user")%>   //works
here in j2 - therefore it is stored in scope

...
<a href="http://bsmith:8080/sheet/search.jsp" target="_blank"> Search </a>
//to the external APP

//note: using html:link wont open an external app but rather one in context
- thats why I used <a href


In External App - search.jsp

<%=(String)request.getSession().getAttribute("user")%>

The value is coming out to be null.



In myportal.xml:
<Context path="/myportal" docBase="myportal" crossContext="true">


Any ideas why the value isn't in external scope?

Thanks,

Akshay

Re: Passing values to Apps outside of Jetspeed

Posted by Aaron Evans <aa...@gmail.com>.
Right, that's true. :)

On 7/17/06, David Sean Taylor <da...@bluesunrise.com> wrote:
> Aaron Evans wrote:
> > Anton is absolutely correct.  When you use APPLICATION_SCOPE for your
> > portlet session scope, it stores it in the same place as the
> > session.setAttribute of HttpServlet session.  But you have to turn on
> > cross context as Anton suggests...
>
> If you package the servlet and portlet in the same portlet/servlet web
> application, you can share application scope state between portlets and
> servlets. In this case, cross context is not required.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Re: Passing values to Apps outside of Jetspeed

Posted by David Sean Taylor <da...@bluesunrise.com>.
Aaron Evans wrote:
> Anton is absolutely correct.  When you use APPLICATION_SCOPE for your
> portlet session scope, it stores it in the same place as the
> session.setAttribute of HttpServlet session.  But you have to turn on
> cross context as Anton suggests...

If you package the servlet and portlet in the same portlet/servlet web 
application, you can share application scope state between portlets and 
servlets. In this case, cross context is not required.

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Re: Passing values to Apps outside of Jetspeed

Posted by Aaron Evans <aa...@gmail.com>.
Anton is absolutely correct.  When you use APPLICATION_SCOPE for your
portlet session scope, it stores it in the same place as the
session.setAttribute of HttpServlet session.  But you have to turn on
cross context as Anton suggests...

On 7/17/06, Anton <ja...@yahoo.com> wrote:
> Of cause PortletSession is available only inside of J2. But APPLICATION_SCOPE actually refers to the same session as application outside of J2.
>
> In my applications I use something like:
> if (session instanceof PortletSession) {
>     PortletSession porteltSession = (PortletSession)session;
>     ....
> } else {
>     ....
> }
> This si actuallyu rear case when you need to execute the same code inside portlet and as a standalone webapp.
>
> Akshay Ahooja <ak...@gmail.com> wrote: Hi,
>
> Yeah I realized that the servlet context wont work out in this case.
>
> As for the Portlet Session in APPLICATION_SCOPE - Isn't that only applicable
> to all portlets inside J2 and not to applications outside of J2?
>
> If not - How are you casting in: PortletSession portletSession =
> (PortletSession)session;
> Is session from httprequest (request.getSession() ) or from portlet request?
>
>
> And when you call it outside of J2 it would have to be using httprequest (
> session.getAttribute ("a"); where session is request.getSession())
>
> Thanks,
>
> Akshay
>
>
>
> ---------------------------------
> Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls.  Great rates starting at 1¢/min.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Re: Passing values to Apps outside of Jetspeed

Posted by Anton <ja...@yahoo.com>.
Of cause PortletSession is available only inside of J2. But APPLICATION_SCOPE actually refers to the same session as application outside of J2.

In my applications I use something like:
if (session instanceof PortletSession) {
    PortletSession porteltSession = (PortletSession)session;
    ....
} else {
    ....
}
This si actuallyu rear case when you need to execute the same code inside portlet and as a standalone webapp.

Akshay Ahooja <ak...@gmail.com> wrote: Hi,

Yeah I realized that the servlet context wont work out in this case.

As for the Portlet Session in APPLICATION_SCOPE - Isn't that only applicable
to all portlets inside J2 and not to applications outside of J2?

If not - How are you casting in: PortletSession portletSession =
(PortletSession)session;
Is session from httprequest (request.getSession() ) or from portlet request?


And when you call it outside of J2 it would have to be using httprequest (
session.getAttribute ("a"); where session is request.getSession())

Thanks,

Akshay


 		
---------------------------------
Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls.  Great rates starting at 1¢/min.

Re: Passing values to Apps outside of Jetspeed

Posted by Akshay Ahooja <ak...@gmail.com>.
Hi,

Yeah I realized that the servlet context wont work out in this case.

As for the Portlet Session in APPLICATION_SCOPE - Isn't that only applicable
to all portlets inside J2 and not to applications outside of J2?

If not - How are you casting in: PortletSession portletSession =
(PortletSession)session;
Is session from httprequest (request.getSession() ) or from portlet request?


And when you call it outside of J2 it would have to be using httprequest (
session.getAttribute ("a"); where session is request.getSession())

Thanks,

Akshay

Re: Passing values to Apps outside of Jetspeed

Posted by Anton <ja...@yahoo.com>.
I guess in this case you will be setting variables on Servlet Context, which is shared by all sessions. Thus several users accessing this functionality will be overwriting each other's values (concurrency problem). The better solution is to use 

inside of JetSpeed application:
PortletSession portletSession = (PortletSession)session;
portletSession.setAttribute("a", "a", PortletSession.APPLICATION_SCOPE);

outside of JetSpeed:
session.getAttribute ("a");

For this to work you also need to enable crossContext feature in the Context configuration for jetspeed applications.
Probably in $TOMCAT_HOME/conf/Catalina/localhost/jetspeed.xml
<Context path="/ifs" docBase="ifs" crossContext="true">

Hope this helps.
Anton

Akshay Ahooja <ak...@gmail.com> wrote: I figured it out...

If someone else is looking to do this:

Since you are opening a new session you need to go one level back and get
the servlet context itself before setting any attributes.

This can be done using:
request.getSession().getServletContext().setAttribute("a",a);
...
request.getSession().getServletContext().getAttribute("a"); //external
webapp in a new window

Thanks,
Akshay

On 7/17/06, Akshay Ahooja  wrote:
>
> Hi,
>
> I have some external previously made apps that I would like users to be
> able access from Jetspeed. Instead of just creating a link to the page, I
> would like to pass the external app some user information that can be used
> for attribute purposes.
>
> How would I pass values from a Jetspeed-2 Portlet to a new regular web app
> window? (both Struts Based)
>
> I don't think that setAttribute would work since it would open up a whole
> new session right?
>
> Thanks,
>
> Akshay
>


 		
---------------------------------
Do you Yahoo!?
 Everyone is raving about the  all-new Yahoo! Mail Beta.

Re: Passing values to Apps outside of Jetspeed

Posted by Akshay Ahooja <ak...@gmail.com>.
I figured it out...

If someone else is looking to do this:

Since you are opening a new session you need to go one level back and get
the servlet context itself before setting any attributes.

This can be done using:
request.getSession().getServletContext().setAttribute("a",a);
...
request.getSession().getServletContext().getAttribute("a"); //external
webapp in a new window

Thanks,
Akshay

On 7/17/06, Akshay Ahooja <ak...@gmail.com> wrote:
>
> Hi,
>
> I have some external previously made apps that I would like users to be
> able access from Jetspeed. Instead of just creating a link to the page, I
> would like to pass the external app some user information that can be used
> for attribute purposes.
>
> How would I pass values from a Jetspeed-2 Portlet to a new regular web app
> window? (both Struts Based)
>
> I don't think that setAttribute would work since it would open up a whole
> new session right?
>
> Thanks,
>
> Akshay
>