Well, I never managed to satisfactorily integrate Struts/Jetspeed, and would love to
see it happen, but I did figure out a workaround so that you can use struts-mapped
URLs for portlet content via proxy (any time I tried to access them directly using the
standard ServletPortlet, the Struts Action controller would blow up as some point or
the other).
The ServletProxyPortlet class below uses a java.net.URL to get the content from the
struts-mapped URL (actually, any URL will work AFAIK) and return it as an ECS
StringElement. It appends the sessionID to the URL correctly for Tomcat, but you will
probably have to tweak the code for other containers. If using Tomcat, all you have
to do is put the class in a package and create an entry for it in one of your xreg
files, then test with one of your struts-mapped URLs. Thought this might be useful to
someone.
peace,
Joe
// Use .xreg entries like so:
<portlet-entry name="ServletProxy" hidden="false" type="abstract"
application="false">
<classname>your.package.ServletProxyPortlet</classname>
<media-type ref="html"/>
</portlet-entry>
<portlet-entry name="Test" hidden="false" type="ref" parent="ServletProxy"
application="false">
<parameter name="URL" value="/someRelativePath/someAction.do" hidden="false"/>
</portlet-entry>
// portlet source code:
import org.apache.jetspeed.portal.portlets.AbstractPortlet;
import org.apache.jetspeed.util.servlet.EcsServletElement;
import org.apache.ecs.ConcreteElement;
import org.apache.ecs.ClearElement;
import org.apache.ecs.StringElement;
import org.apache.turbine.util.RunData;
import java.net.URL;
import java.net.URLConnection;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
/*
* Created by IntelliJ IDEA.
* User: Joe.Barefoot
* Date: Oct 16, 2002
* Time: 3:17:30 PM
* To change this template use Options | File Templates.
*/
/** This Portlet class uses an application context-relative URL as an input
parameter. It uses data obtained from
* <code>org.apache.turbine.util.RunData</code> to construct an absolute URL and
append the session id to it. Using this
* URL, it constructs a java.net.URL object, retrieves the content from it, and
converts the content to a String. Finally,
* it returns an ECS StringElement created with this String for Jetspeed to render
as a portlet. Content is returned as-is;
* no filtering is performed on the html before returning it.
*
*
* @author Joe Barefoot
*/
//TODO: Append the session ID in a web container-specific way. Right now, it just
uses jsessionid, which will work for Tomcat but probably not anything else.
public class ServletProxyPortlet extends AbstractPortlet
{
private static final String CAT = ServletProxyPortlet.class.getName();
private final static int BUFFER_SIZE = 2048;
/** The name of the parameter to hold our application context-relative URL */
public static final String URL_PARAMETER_NAME = "URL";
public ConcreteElement getContent(RunData rundata)
{
String servletURL = processURL(rundata);
String content;
// This is not robust for large content returns, but should work okay within
an application context with small amounts of content. We'll see.
try
{
URL url = new URL(servletURL);
URLConnection connection = url.openConnection();
InputStream stream = connection.getInputStream();
BufferedInputStream in = new BufferedInputStream(stream);
int length = 0;
byte[] buf = new byte[BUFFER_SIZE];
ByteArrayOutputStream out = new ByteArrayOutputStream();
while( (in != null) && ((length = in.read(buf)) != -1) )
{
// the data has already been read into buf
out.write(buf, 0, length);
}
content = out.toString();
return new StringElement(content);
}
catch( Exception e )
{
String message = "ServletInvokerPortlet: Error invoking " + servletURL +
": " + e.getMessage();
return new StringElement(message);
}
}
protected String processURL(RunData rundata)
{
String servletURL = getPortletConfig().getInitParameter(URL_PARAMETER_NAME);
servletURL = "http://" + rundata.getServerName() + ":" +
rundata.getServerPort() + rundata.getContextPath() + servletURL + ";" + "jsessionid="
+ rundata.getSession().getId();
return servletURL;
}
}
> -----Original Message-----
> From: David [mailto:dreed10@;neo.rr.com]
> Sent: Thursday, October 31, 2002 3:13 PM
> To: Jetspeed Users List
> Subject: Re: CMS - Struts
>
>
> I too would like to see a Jetspeed/Struts integration
>
>
> ----- Original Message -----
> From: "Christophe" <[EMAIL PROTECTED]>
> To: "Jetspeed Users List" <[EMAIL PROTECTED]>
> Sent: Thursday, October 31, 2002 3:31 AM
> Subject: Re: CMS - Struts
>
>
> > > Struts Action and Form classes have access to the
> HttpServletRequest so
> > > what could be the problem to access the RunData
> > > or Jetspeed Services ? ... i don't see a problem ...
> could you elaborate
> > > a little on what you think is the problem ?
> >
> > I don't know Struts, it is just a question. I don't know if
> there is a
> > issue.
> > My question was there just to know how do you plan to make this
> integration.
> >
> >
> > Christophe
> >
> >
> > --
> > To unsubscribe, e-mail:
> <mailto:jetspeed-user-unsubscribe@;jakarta.apache.org>
> > For additional commands, e-mail:
> <mailto:jetspeed-user-help@;jakarta.apache.org>
> >
> >
>
>
> --
> To unsubscribe, e-mail:
<mailto:jetspeed-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:jetspeed-user-help@;jakarta.apache.org>
--
To unsubscribe, e-mail: <mailto:jetspeed-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:jetspeed-user-help@;jakarta.apache.org>