RE: CMS - Struts

2002-10-31 Thread Joe Barefoot
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:

  
your.package.ServletProxyPortlet



  


 

// 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
 *   org.apache.turbine.util.RunData 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 t

Re: CMS - Struts

2002-10-31 Thread David
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>




Re: CMS - Struts

2002-10-31 Thread Christophe
> 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:   
For additional commands, e-mail: 




Re: CMS - Struts

2002-10-30 Thread Werner Ramaekers

Christophe wrote:


I must say that i agree on the matter that it should be possible to use
Struts as MVC within Jetspeed instead of velocity,
there has been an attempt at integrating JSP based templates but they
are setup in a wrong way.
I have already addressed this to the Jetspeed-dev mailing list in the
following message :
http://www.mail-archive.com/jetspeed-dev@;jakarta.apache.org/msg04605.html
but have seen no reply.
The reason i favor JSP based templates over velocity is that they are
easier to teach to a learning Java programmer
then velocity.
So i would like to propose to make a first step at reworking the JSP
templates to use or Struts or the JSTL, if there is enough interest from
the jetspeed-dev group.
   


It is possible to learn Velocity in 2 hours. That's not possible with JSP
which are unreadable.
 

if you use the available tag libraries and use your JSP's as the View in 
the MVC approach it can be very readable ...
and the i18n you get is very important and easy to manage (as in Velocity)

Anyway I understand your point of view. Unfortunatly customers are using
JSP/Struts.
So I'm also interesting for this kind of integration between Jetspeed and
Struts :-
 

ok, there is two of us then,  what about the rest ?


Werner, do you have some ideas for that ?
What about accessing Jetspeed services or the Rundata from a Struts action
classes or form ?
I have no idea on the Struts flexibility for this kind of integration.

 

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 ?

Werner

--
--
ir. Werner Ramaekers
Enterprise Java Solutions Architect - Shift@
Sun Certified Java Programmer - BeJUG steering commitee member

"May the source be with you."

Read my Blog at http://www.werner.be
--



--
To unsubscribe, e-mail:   
For additional commands, e-mail: 



Re: CMS - Struts

2002-10-30 Thread Christophe
> I must say that i agree on the matter that it should be possible to use
> Struts as MVC within Jetspeed instead of velocity,
> there has been an attempt at integrating JSP based templates but they
> are setup in a wrong way.
> I have already addressed this to the Jetspeed-dev mailing list in the
> following message :
> http://www.mail-archive.com/jetspeed-dev@;jakarta.apache.org/msg04605.html
> but have seen no reply.
> The reason i favor JSP based templates over velocity is that they are
> easier to teach to a learning Java programmer
> then velocity.
> So i would like to propose to make a first step at reworking the JSP
> templates to use or Struts or the JSTL, if there is enough interest from
> the jetspeed-dev group.

It is possible to learn Velocity in 2 hours. That's not possible with JSP
which are unreadable.
Anyway I understand your point of view. Unfortunatly customers are using
JSP/Struts.
So I'm also interesting for this kind of integration between Jetspeed and
Struts :-

Werner, do you have some ideas for that ?
What about accessing Jetspeed services or the Rundata from a Struts action
classes or form ?
I have no idea on the Struts flexibility for this kind of integration.


Christophe


--
To unsubscribe, e-mail:   
For additional commands, e-mail: