Echo2 as a Portlet

Last week I was studing how to adapt an Echo2 application for portlet. (Obviously avoiding IFRAME).
I managed to do it by creating a bridge.portlet. I didn't finish the work, because it was only a study, but I get a proof of concept.
I would like to share with you my conclusions.

I wrote this simple bridge-portlet:

public class PortletEcho2 extends GenericPortlet {

public static final String SERVLET_ECHO2_PARAM = "Echo2Servlet";

@Override
protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {

String servletName=getInitParameter(SERVLET_ECHO2_PARAM);
if(servletName==null) {
servletName="Echo2Servlet";
}
try {
PortletRequestDispatcher dispatcher=request.getPortletSession()
.getPortletContext().getNamedDispatcher(servletName);
if(dispatcher!=null) {
request.setAttribute(Connection.ECHO2_PORTLET_ATT, "true");
dispatcher.forward(request, response);
}
} catch(Exception e) {
throw new PortletException(e);
}
}
}

This way, when the portal calls us as portlet, then we derive the request to the servlet. We must do some other work :

We have to change the Connection class in order to register de absolute URL of our application, this way:

public static final String ECHO2_PORTLET_ATT = "ECHO2_PORTLET_ATT";

void initUserInstance(UserInstance userInstance) {
this.userInstance = userInstance;

if(request.getAttribute(ECHO2_PORTLET_ATT)!=null) {
userInstance.setServletUri(request.getContextPath());
} else {
userInstance.setServletUri(request.getRequestURI());
}
HttpSession session = request.getSession(true);
session.setAttribute(getSessionKey(), userInstance);
}

When an application acts as a porltet it have to avoid reponse with all HTML, but only the fragment we need, so we had to change some other classes of echo2 to avoid render html headers, body, and so on. But, I thing it not will be difficult.

Best Regards, Luis.