Foros de discusión

portletbridge

thumbnail
Eric Devlin, modificado hace 16 años.

portletbridge

Regular Member Mensajes: 154 Fecha de incorporación: 19/02/08 Mensajes recientes
Hey,
I think I've gotten the post to work using the portletbridge i.e. web proxy. Below are the steps to fix. If anybody can confirm this I would be appreciative. I'm using liferay-portal-jboss-tomcat-4.2.2.zip.

In summary, PortletBridgeServlet needs the input stream in order to pass it to commons-httpclient.jar. The input stream was empty because it had already been accessed. Added a filter which got the input stream before it could be read by others (filters?). Saved that to a file. Added a reference to the session. PortletBridgeServlet checks for the reference in the session and uses that instead of the empty input stream.
Eric

1. Download portlet bridge from cvs
2. Patch PortletBridgeServlet.java (see below)
3. Compiled portletbridge-portlet
4. Jar portletbridge-portlet
5. Deploy portletbridge-portlet.jar
6. Added filters/bridge/src/com/liferay/filters/bridge to my liferay source
7. Added BridgeFilter.java to same (see below)
8. Added build.xml (see below)
9. Compled bridge-filter
10. Jar bridge-filter
11. Deploy bridge-filter
12. Added filter to web.xml (see below)
13. Added filter-mapping to web.xml (see below)

emoticon

--- PortletBridgeServlet.java 2006-04-25 09:37:35.000000000 -0400
+++ portletbridge-portlet/src/java/org/portletbridge/portlet/PortletBridgeServlet.java 2008-04-23 16:16:51.652086700 -0400
@@ -15,6 +15,9 @@
*/
package org.portletbridge.portlet;

+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URI;
@@ -360,8 +363,13 @@
try {
PostMethod postMethod = new PostMethod(url.toString());
copyRequestHeaders(request, postMethod);
- postMethod.setRequestEntity(new InputStreamRequestEntity(request
- .getInputStream()));
+ File bridgeTempFile = null;
+ InputStream inputStream = request.getInputStream();
+ if ( session.getAttribute( "bridgeTempFile" ) != null ) {
+ bridgeTempFile = (File)session.getAttribute( "bridgeTempFile" );
+ inputStream = new FileInputStream( bridgeTempFile );
+ }
+ postMethod.setRequestEntity( new InputStreamRequestEntity( inputStream ) );
httpClientTemplate.service(postMethod, perPortletMemento,
new HttpClientCallback() {
public Object doInHttpClient(int statusCode,
@@ -428,6 +436,11 @@
return null;
}
});
+ if ( bridgeTempFile != null ) {
+ inputStream.close();
+ bridgeTempFile.delete();
+ session.removeAttribute( "bridgeTempFile" );
+ }
} catch (ResourceException resourceException) {
String format = MessageFormat.format(resourceBundle
.getString(resourceException.getMessage()),



/**
* Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.liferay.filters.bridge;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.servlet.BaseFilter;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


public class BridgeFilter extends BaseFilter {

public void doFilter(
ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {

_log.info( "PortletBridge filtering" );

HttpServletRequest httpReq = (HttpServletRequest)req;
HttpServletResponse httpRes = (HttpServletResponse)res;

if ( httpReq.getMethod().equals( "POST" ) )
{
File file = File.createTempFile( "bridge", "tmp" );
_log.debug( file.getAbsolutePath() );

FileOutputStream fos = new FileOutputStream( file );

InputStream inputStream = httpReq.getInputStream();
byte[] buf = new byte[ 1024 ];
int amountRead = 0;
while( ( amountRead = inputStream.read( buf, 0, buf.length ) ) != -1 )
{
fos.write( buf, 0, amountRead );
}
fos.flush();
fos.close();

HttpSession session = httpReq.getSession();
if (session == null)
{
throw new ServletException( "error.nosession" );
}

session.setAttribute( "bridgeTempFile", file );
}

doFilter(BridgeFilter.class, req, res, chain);
}

private static Log _log = LogFactoryUtil.getLog(BridgeFilter.class);

}

<?xml version="1.0"?>

<project name="bridge" basedir="." default="compile">
<property name="project.dir" value="../.." />

<property name="java2html.dir" value="${project.dir}/api/filters/${ant.project.name}" />
<property name="javadoc.dir" value="${java2html.dir}" />

<import file="${project.dir}/build-common-java.xml" />

<property name="deploy.dir" value="${app.server.lib.portal.dir}" />
<property name="jar.file" value="${ant.project.name}-filter" />
</project>

<filter>
<filter-name>Bridge Filter</filter-name>
<filter-class>com.liferay.filters.bridge.BridgeFilter</filter-class>
</filter>


<filter-mapping>
<filter-name>Bridge Filter</filter-name>
<url-pattern>/pbhs/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
thumbnail
Eric Devlin, modificado hace 15 años.

RE: portletbridge

Regular Member Mensajes: 154 Fecha de incorporación: 19/02/08 Mensajes recientes
Hey,
Found a minor Liferay PortletBridgeServlet incompatibility. The paths to the css based resources are not getting translated correctly. PortletBridgeServlet uses the servlet-name instead of the url-pattern. Liferay comes with url-pattern set to pbhs instead of using the servlet-name. The patch below is for portletbridge-portlet/src/java/org/portletbridge/portlet/PortletBridgeServlet.java
Hope it helps
Eric

18,20d17
< import java.io.File;
< import java.io.FileInputStream;
< import java.io.InputStream;
263,264c260
< // getServletName(),
< request.getServletPath().length() != 0 ? request.getServletPath().substring( 1 ) : getServletName(),
---
> getServletName(),
283,284c279
< // getServletName(),
< request.getServletPath().length() != 0 ? request.getServletPath().substring( 1 ) : getServletName(),
---
> getServletName(),
368,374c363,364
< File bridgeTempFile = null;
< InputStream inputStream = request.getInputStream();
< if ( session.getAttribute( "bridgeTempFile" ) != null ) {
< bridgeTempFile = (File)session.getAttribute( "bridgeTempFile" );
< inputStream = new FileInputStream( bridgeTempFile );
< }
< postMethod.setRequestEntity( new InputStreamRequestEntity( inputStream ) );
---
> postMethod.setRequestEntity(new InputStreamRequestEntity(request
> .getInputStream()));
441,445d430
< if ( bridgeTempFile != null ) {
< inputStream.close();
< bridgeTempFile.delete();
< session.removeAttribute( "bridgeTempFile" );
< }
Riju John, modificado hace 15 años.

RE: portletbridge

New Member Mensaje: 1 Fecha de incorporación: 25/09/08 Mensajes recientes
Hi,

I've got the Web Proxy Portlet (PortletBridge) to work using POST requests in liferay-portal-tomcat-5.5-5.1.0.


The steps are :-


1. Patch PortletBridgeServlet.java in org/portletbridge/portlet folder in portletbridge-portlet.jar as shown below:

PortletBridgeServlet.java

package org.portletbridge.portlet;

+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URI;

try {
PostMethod postMethod = new PostMethod(url.toString());
copyRequestHeaders(request, postMethod);
- postMethod.setRequestEntity(new InputStreamRequestEntity(request
- .getInputStream()));
+ File bridgeTempFile = null;
+ InputStream inputStream = request.getInputStream();

+ if ( session.getAttribute( "bridgeTempFile" ) != null ) {
+ bridgeTempFile = (File)session.getAttribute( "bridgeTempFile" );
+ inputStream = new FileInputStream( bridgeTempFile );
+ }
+ postMethod.setRequestEntity( new InputStreamRequestEntity( inputStream ) );

httpClientTemplate.service(postMethod, perPortletMemento,
new HttpClientCallback() {
public Object doInHttpClient(int statusCode,
@@ -428,6 +436,11 @@
return null;
}
});
+ if ( bridgeTempFile != null ) {
+ inputStream.close();
+ bridgeTempFile.delete();
+ session.removeAttribute( "bridgeTempFile" );
+ }
} catch (ResourceException resourceException) {
String format = MessageFormat.format(resourceBundle
.getString(resourceException.getMessage()),




2. Compiled PortletBridgeServlet.java


3. Jar portletbridge-portlet


4. Deploy portletbridge-portlet.jar in the liferay webapps/ROOT/WEB-INF/lib/ folder


5. Added BridgeFilter.java to same as shown below

/**
* Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.liferay.portal.servlet.filters.bridge;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.servlet.filters.BasePortalFilter;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


public class BridgeFilter extends BasePortalFilter {

protected void processFilter(
HttpServletRequest httpReq, HttpServletResponse httpRes, FilterChain chain)
throws IOException, ServletException {

_log.info( "PortletBridge filtering" );

//HttpServletRequest httpReq = (HttpServletRequest)req;
//HttpServletResponse httpRes = (HttpServletResponse)res;

if ( httpReq.getMethod().equals( "POST" ) )
{
File file = File.createTempFile( "bridge", "tmp" );
_log.debug( file.getAbsolutePath() );

FileOutputStream fos = new FileOutputStream( file );

InputStream inputStream = httpReq.getInputStream();
byte[] buf = new byte[ 1024 ];
int amountRead = 0;
while( ( amountRead = inputStream.read( buf, 0, buf.length ) ) != -1 )
{
fos.write( buf, 0, amountRead );
}
fos.flush();
fos.close();

HttpSession session = httpReq.getSession();
if (session == null)
{
throw new ServletException( "error.nosession" );
}

session.setAttribute( "bridgeTempFile", file );
}

processFilter(BridgeFilter.class, httpReq, httpRes, chain);
}
private static Log _log = LogFactoryUtil.getLog(BridgeFilter.class);

}



6. Compile BridgeFilter.java


7. Add the resulting BridgeFilter.java in com/liferay/portal/servlet/filters/bridge/ folder in portal-impl.jar which is deployed in liferay webapps/ROOT/WEB-INF/lib folder.


8. Added filter to web.xml (see below)

<filter>
<filter-name>Bridge Filter</filter-name>
<filter-class>com.liferay.filters.bridge.BridgeFilter</filter-class>
</filter>



9. Added filter-mapping to web.xml (see below)

<filter-mapping>
<filter-name>Bridge Filter</filter-name>
<url-pattern>/pbhs/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
Martin Ronky, modificado hace 15 años.

RE: portletbridge

New Member Mensajes: 21 Fecha de incorporación: 6/06/08 Mensajes recientes
Hi,
there are several web.xml files. To which one should I add the <filter> and <filter-mapping>? Thanks in advance.
Martin
thumbnail
Eric Devlin, modificado hace 15 años.

RE: portletbridge

Regular Member Mensajes: 154 Fecha de incorporación: 19/02/08 Mensajes recientes
Hey,
I'm using an exploded directory so it's ROOT.war/WEB-INF/web.xml, but it should be in the web.xml used by the portal application.
Eric
Martin Ronky, modificado hace 15 años.

RE: portletbridge

New Member Mensajes: 21 Fecha de incorporación: 6/06/08 Mensajes recientes
Hi,
it works for me on liferay 5.1.2. I just had to write this in web.xml:
<filter>
<filter-name>Bridge Filter</filter-name>
<filter-class>com.liferay.portal.servlet.filters.bridge.BridgeFilter</filter-class>
</filter>
because the path for the filter was slightly different.

Thank you for your help I really appreciate it.

Regards,
Martin
Dilip Mahajan, modificado hace 9 años.

RE: portletbridge

New Member Mensaje: 1 Fecha de incorporación: 2/04/13 Mensajes recientes
Hi Eric,


I am having one web application which i want to access in web proxy portlet. If the application contains form having method=get it works fine for me but when the form contains method=post its form parameters are not passed. Can you please upload updated files of both i.e. (PortletBridgeServlet and BridgeFilter)




Thanks & Regards,
Dilip Mahajan