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 Ate Douma <at...@douma.nu> on 2005/10/19 14:02:04 UTC

Re: Struts Bridge and Inter Portlet Communication

Jonathan,
First of all, I cc'd this to the bridges-user mailing list so we can continue
the discussion there.
(if you haven't subscribed yet: http://portals.apache.org/bridges/mail-lists.html)

It is not clear to me *what* is not working with the example you provided.
Do you get an exception/stacktrace or is the ContainerConstants.PORTLET_REQUEST not
set?

In the latter case, it might be a case of which version of the struts-bridge you
are using. Since august 8, the struts-bridge trunk now *does* provide the
"javax.portlet.request" attribute, even when accessed from an ActionRequest.
See: http://issues.apache.org/jira/browse/PB-2.
To be able to use it, you need to checkout and build the bridges yourself.

If you get an exception, could you please provide that?

Note: Using ContainerConstants.PORTLET_REQUEST (instead of "javax.portlet.request")
binds you to the jetspeed-commons jar. If you really want to be JSR-168 compliant,
you should *not* use jetspeed-commons.

Regards,

Ate


jonathan.hawkins@hawkinsweb.co.uk wrote:
> I am trying integrate a Struts Portlet using Struts Bridge and an
> InterPortlet Communication library,
> http://www.doc.ic.ac.uk/~mo197/portlets/portlet_messaging/crosscontext.php ,
> which works well with ordinary portlets.
> 
> The library requires that I retrieve the PortletRequest / ActionRequest /
> RenderRequest. However within my Struts Portlet I only action and form
> classes and with execute I only have httpServletRequest available. Given
> that my action classes are running within s struts portlet how can I
> retrieve the PortletRequest that I need.
> 
> The following code shows a simple portlet that works fine.
> 
> public class Portlet1 extends GenericPortlet{
> 
> 
> 	protected void doEdit(RenderRequest request, RenderResponse response)
> throws PortletException, IOException {
> 		String id = this.getInstanceID(request);
>         String msg_session_id = MessageHelper.getSessionID(request);
> 		MessageHelper.loadPrefs(request, id, msg_session_id);
> 		MessageUtils.prepareMappingForm(request, id, msg_session_id);
> 
> getPortletContext().getRequestDispatcher("/WEB-INF/pages/edit_mappings.jsp").include(request,response);
> 	}
> 
> 
> 	protected void doView(RenderRequest request, RenderResponse response)
> throws PortletException, IOException {
> 		String id = this.getInstanceID(request);
>         String msg_session_id = MessageHelper.getSessionID(request);
> 		MessageHelper.loadPrefs(request, id, msg_session_id);
> 
> 		response.setContentType("text/html");
> 		PrintWriter out = response.getWriter();
> 
> 		PortletURL aURL = response.createActionURL();
> 		aURL.setParameter("ACTION", "sendmsg");
> 
> 		out.println("<b>Message Session ID:</b> "+msg_session_id+"<br/>");
> 		out.println("<b>Portlet App:</b> "+request.getContextPath()+"<br/>");
> 
> 		out.println("<b>Portlet1</b>:<br/>");
> 		out.println("<a href=\""+aURL+"\">send message</a><br/><br/>");
> 
> 		MessageHelper msgh = new MessageHelper(request.getPortletSession(true),
> id, msg_session_id);
> 		String msg = (String)msgh.get("a_val");
> 		out.println("my a_val msg: "+msg);
> 
> 	}
> 
> 	public void processAction(ActionRequest request, ActionResponse response)
> throws PortletException, IOException {
> 		String id = this.getInstanceID(request);
>         String msg_session_id = MessageHelper.getSessionID(request);
> 		MessageHelper.loadPrefs(request, id, msg_session_id);
> 
> 
> 		if (request.getPortletMode().equals(PortletMode.EDIT)) {
> 				MessageUtils.processMappingForm(request, response, id, msg_session_id);
> 		}
> 
> 		if ("sendmsg".equals(request.getParameter("ACTION"))){
> 			System.out.println("try sending message from Portlet 1 in webapp
> "+request.getContextPath());
> 			MessageHelper msgh = new MessageHelper(request.getPortletSession(true),
> id, msg_session_id);
> 			msgh.send("a_val", "this is a message from Portlet1 in portlet webapp
> "+request.getContextPath());
> 		}
> 	}
> 
> 	public String getInstanceID(PortletRequest request){
> 		return "Portlet1."+MessageHelper.getPortletID(request);
> 	}
> 
> 
> }
> 
> 
> Hopefully from that you can see what I am trying to retrieve from within my
> action class. The following is my current execute method
> 
> logger = Logger.getLogger("Cedar-Portlets");
> 
> 		logger.debug("SetURLAction::execute - starting");
> 
> 		try {
> 
> 
> 			ActionRequest actionRequest = (ActionRequest) request
> 					.getAttribute(ContainerConstants.PORTLET_REQUEST);
> 			String id = this.getInstanceID(actionRequest);
> 			String msg_session_id = MessageHelper.getSessionID(actionRequest);
> 			MessageHelper.loadPrefs(actionRequest, id, msg_session_id);
> 			MessageHelper msgh = new MessageHelper(actionRequest
> 					.getPortletSession(true), id, msg_session_id);
> 			msgh.send("a_val",
> 					"this is a message from SetURLAction in portlet webapp "
> 							+ actionRequest.getContextPath());
> 
> 		} catch (RuntimeException e) {
> 			// TODO Auto-generated catch block
> 			e.printStackTrace();
> 			return mapping.findForward("failure");
> 		}
> 		return mapping.findForward("success");
> 
> 
> 
> 
> Which doesn't work, any ideas would be greatly appreciated.
> 
> Jon Hawkins
> 
> 
> 
> ---------------------------------------------------------------------
> 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: Struts Bridge and Inter Portlet Communication

Posted by jo...@hawkinsweb.co.uk.
Thanks Ate,

I was getting null pointer exceptions. I'll subscribe to the other list as
well andbuild the struts bridge and see what I can get hold of this time.

I've created my own constants file with an entry for javax.portlet.request.

All assistance is very much appreciated.

Jonathan


> Jonathan,
> First of all, I cc'd this to the bridges-user mailing list so we can
> continue the discussion there.
> (if you haven't subscribed yet:
> http://portals.apache.org/bridges/mail-lists.html)
>
> It is not clear to me *what* is not working with the example you
> provided. Do you get an exception/stacktrace or is the
> ContainerConstants.PORTLET_REQUEST not set?
>
> In the latter case, it might be a case of which version of the
> struts-bridge you are using. Since august 8, the struts-bridge trunk
> now *does* provide the "javax.portlet.request" attribute, even when
> accessed from an ActionRequest. See:
> http://issues.apache.org/jira/browse/PB-2.
> To be able to use it, you need to checkout and build the bridges
> yourself.
>
> If you get an exception, could you please provide that?
>
> Note: Using ContainerConstants.PORTLET_REQUEST (instead of
> "javax.portlet.request") binds you to the jetspeed-commons jar. If you
> really want to be JSR-168 compliant, you should *not* use
> jetspeed-commons.
>
> Regards,
>
> Ate
>
>
> jonathan.hawkins@hawkinsweb.co.uk wrote:
>> I am trying integrate a Struts Portlet using Struts Bridge and an
>> InterPortlet Communication library,
>> http://www.doc.ic.ac.uk/~mo197/portlets/portlet_messaging/crosscontext.php
>> , which works well with ordinary portlets.
>>
>> The library requires that I retrieve the PortletRequest /
>> ActionRequest / RenderRequest. However within my Struts Portlet I only
>> action and form classes and with execute I only have
>> httpServletRequest available. Given that my action classes are running
>> within s struts portlet how can I retrieve the PortletRequest that I
>> need.
>>
>> The following code shows a simple portlet that works fine.
>>
>> public class Portlet1 extends GenericPortlet{
>>
>>
>> 	protected void doEdit(RenderRequest request, RenderResponse response)
>> throws PortletException, IOException {
>> 		String id = this.getInstanceID(request);
>>         String msg_session_id = MessageHelper.getSessionID(request);
>> 		MessageHelper.loadPrefs(request, id, msg_session_id);
>> 		MessageUtils.prepareMappingForm(request, id, msg_session_id);
>>
>>
getPortletContext().getRequestDispatcher("/WEB-INF/pages/edit_mappings.jsp").include(request,response);>> 	}
>>
>>
>> 	protected void doView(RenderRequest request, RenderResponse response)
>> throws PortletException, IOException {
>> 		String id = this.getInstanceID(request);
>>         String msg_session_id = MessageHelper.getSessionID(request);
>> 		MessageHelper.loadPrefs(request, id, msg_session_id);
>>
>> 		response.setContentType("text/html");
>> 		PrintWriter out = response.getWriter();
>>
>> 		PortletURL aURL = response.createActionURL();
>> 		aURL.setParameter("ACTION", "sendmsg");
>>
>> 		out.println("<b>Message Session ID:</b> "+msg_session_id+"<br/>");
>> 		out.println("<b>Portlet App:</b>
>> 		"+request.getContextPath()+"<br/>");
>>
>> 		out.println("<b>Portlet1</b>:<br/>");
>> 		out.println("<a href=\""+aURL+"\">send message</a><br/><br/>");
>>
>> 		MessageHelper msgh = new
>> 		MessageHelper(request.getPortletSession(true),
>> id, msg_session_id);
>> 		String msg = (String)msgh.get("a_val");
>> 		out.println("my a_val msg: "+msg);
>>
>> 	}
>>
>> 	public void processAction(ActionRequest request, ActionResponse
>> 	response)
>> throws PortletException, IOException {
>> 		String id = this.getInstanceID(request);
>>         String msg_session_id = MessageHelper.getSessionID(request);
>> 		MessageHelper.loadPrefs(request, id, msg_session_id);
>>
>>
>> 		if (request.getPortletMode().equals(PortletMode.EDIT)) {
>> 				MessageUtils.processMappingForm(request, response, id,
>> 				msg_session_id);
>> 		}
>>
>> 		if ("sendmsg".equals(request.getParameter("ACTION"))){
>> 			System.out.println("try sending message from Portlet 1 in webapp
>> "+request.getContextPath());
>> 			MessageHelper msgh = new
>> 			MessageHelper(request.getPortletSession(true),
>> id, msg_session_id);
>> 			msgh.send("a_val", "this is a message from Portlet1 in portlet
>> 			webapp
>> "+request.getContextPath());
>> 		}
>> 	}
>>
>> 	public String getInstanceID(PortletRequest request){
>> 		return "Portlet1."+MessageHelper.getPortletID(request);
>> 	}
>>
>>
>> }
>>
>>
>> Hopefully from that you can see what I am trying to retrieve from
>> within my action class. The following is my current execute method
>>
>> logger = Logger.getLogger("Cedar-Portlets");
>>
>> 		logger.debug("SetURLAction::execute - starting");
>>
>> 		try {
>>
>>
>> 			ActionRequest actionRequest = (ActionRequest) request
>> 					.getAttribute(ContainerConstants.PORTLET_REQUEST);
>> 			String id = this.getInstanceID(actionRequest);
>> 			String msg_session_id = MessageHelper.getSessionID(actionRequest);
>> 			MessageHelper.loadPrefs(actionRequest, id, msg_session_id);
>> 			MessageHelper msgh = new MessageHelper(actionRequest
>> 					.getPortletSession(true), id, msg_session_id);
>> 			msgh.send("a_val",
>> 					"this is a message from SetURLAction in portlet webapp "
>> 							+ actionRequest.getContextPath());
>>
>> 		} catch (RuntimeException e) {
>> 			// TODO Auto-generated catch block
>> 			e.printStackTrace();
>> 			return mapping.findForward("failure");
>> 		}
>> 		return mapping.findForward("success");
>>
>>
>>
>>
>> Which doesn't work, any ideas would be greatly appreciated.
>>
>> Jon Hawkins
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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




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


Re: Struts Bridge and Inter Portlet Communication

Posted by jo...@hawkinsweb.co.uk.
Thanks Ate,

I was getting null pointer exceptions. I'll subscribe to the other list as
well andbuild the struts bridge and see what I can get hold of this time.

I've created my own constants file with an entry for javax.portlet.request.

All assistance is very much appreciated.

Jonathan


> Jonathan,
> First of all, I cc'd this to the bridges-user mailing list so we can
> continue the discussion there.
> (if you haven't subscribed yet:
> http://portals.apache.org/bridges/mail-lists.html)
>
> It is not clear to me *what* is not working with the example you
> provided. Do you get an exception/stacktrace or is the
> ContainerConstants.PORTLET_REQUEST not set?
>
> In the latter case, it might be a case of which version of the
> struts-bridge you are using. Since august 8, the struts-bridge trunk
> now *does* provide the "javax.portlet.request" attribute, even when
> accessed from an ActionRequest. See:
> http://issues.apache.org/jira/browse/PB-2.
> To be able to use it, you need to checkout and build the bridges
> yourself.
>
> If you get an exception, could you please provide that?
>
> Note: Using ContainerConstants.PORTLET_REQUEST (instead of
> "javax.portlet.request") binds you to the jetspeed-commons jar. If you
> really want to be JSR-168 compliant, you should *not* use
> jetspeed-commons.
>
> Regards,
>
> Ate
>
>
> jonathan.hawkins@hawkinsweb.co.uk wrote:
>> I am trying integrate a Struts Portlet using Struts Bridge and an
>> InterPortlet Communication library,
>> http://www.doc.ic.ac.uk/~mo197/portlets/portlet_messaging/crosscontext.php
>> , which works well with ordinary portlets.
>>
>> The library requires that I retrieve the PortletRequest /
>> ActionRequest / RenderRequest. However within my Struts Portlet I only
>> action and form classes and with execute I only have
>> httpServletRequest available. Given that my action classes are running
>> within s struts portlet how can I retrieve the PortletRequest that I
>> need.
>>
>> The following code shows a simple portlet that works fine.
>>
>> public class Portlet1 extends GenericPortlet{
>>
>>
>> 	protected void doEdit(RenderRequest request, RenderResponse response)
>> throws PortletException, IOException {
>> 		String id = this.getInstanceID(request);
>>         String msg_session_id = MessageHelper.getSessionID(request);
>> 		MessageHelper.loadPrefs(request, id, msg_session_id);
>> 		MessageUtils.prepareMappingForm(request, id, msg_session_id);
>>
>>
getPortletContext().getRequestDispatcher("/WEB-INF/pages/edit_mappings.jsp").include(request,response);>> 	}
>>
>>
>> 	protected void doView(RenderRequest request, RenderResponse response)
>> throws PortletException, IOException {
>> 		String id = this.getInstanceID(request);
>>         String msg_session_id = MessageHelper.getSessionID(request);
>> 		MessageHelper.loadPrefs(request, id, msg_session_id);
>>
>> 		response.setContentType("text/html");
>> 		PrintWriter out = response.getWriter();
>>
>> 		PortletURL aURL = response.createActionURL();
>> 		aURL.setParameter("ACTION", "sendmsg");
>>
>> 		out.println("<b>Message Session ID:</b> "+msg_session_id+"<br/>");
>> 		out.println("<b>Portlet App:</b>
>> 		"+request.getContextPath()+"<br/>");
>>
>> 		out.println("<b>Portlet1</b>:<br/>");
>> 		out.println("<a href=\""+aURL+"\">send message</a><br/><br/>");
>>
>> 		MessageHelper msgh = new
>> 		MessageHelper(request.getPortletSession(true),
>> id, msg_session_id);
>> 		String msg = (String)msgh.get("a_val");
>> 		out.println("my a_val msg: "+msg);
>>
>> 	}
>>
>> 	public void processAction(ActionRequest request, ActionResponse
>> 	response)
>> throws PortletException, IOException {
>> 		String id = this.getInstanceID(request);
>>         String msg_session_id = MessageHelper.getSessionID(request);
>> 		MessageHelper.loadPrefs(request, id, msg_session_id);
>>
>>
>> 		if (request.getPortletMode().equals(PortletMode.EDIT)) {
>> 				MessageUtils.processMappingForm(request, response, id,
>> 				msg_session_id);
>> 		}
>>
>> 		if ("sendmsg".equals(request.getParameter("ACTION"))){
>> 			System.out.println("try sending message from Portlet 1 in webapp
>> "+request.getContextPath());
>> 			MessageHelper msgh = new
>> 			MessageHelper(request.getPortletSession(true),
>> id, msg_session_id);
>> 			msgh.send("a_val", "this is a message from Portlet1 in portlet
>> 			webapp
>> "+request.getContextPath());
>> 		}
>> 	}
>>
>> 	public String getInstanceID(PortletRequest request){
>> 		return "Portlet1."+MessageHelper.getPortletID(request);
>> 	}
>>
>>
>> }
>>
>>
>> Hopefully from that you can see what I am trying to retrieve from
>> within my action class. The following is my current execute method
>>
>> logger = Logger.getLogger("Cedar-Portlets");
>>
>> 		logger.debug("SetURLAction::execute - starting");
>>
>> 		try {
>>
>>
>> 			ActionRequest actionRequest = (ActionRequest) request
>> 					.getAttribute(ContainerConstants.PORTLET_REQUEST);
>> 			String id = this.getInstanceID(actionRequest);
>> 			String msg_session_id = MessageHelper.getSessionID(actionRequest);
>> 			MessageHelper.loadPrefs(actionRequest, id, msg_session_id);
>> 			MessageHelper msgh = new MessageHelper(actionRequest
>> 					.getPortletSession(true), id, msg_session_id);
>> 			msgh.send("a_val",
>> 					"this is a message from SetURLAction in portlet webapp "
>> 							+ actionRequest.getContextPath());
>>
>> 		} catch (RuntimeException e) {
>> 			// TODO Auto-generated catch block
>> 			e.printStackTrace();
>> 			return mapping.findForward("failure");
>> 		}
>> 		return mapping.findForward("success");
>>
>>
>>
>>
>> Which doesn't work, any ideas would be greatly appreciated.
>>
>> Jon Hawkins
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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




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