Hello,
I have the beginning of a solution !
My code is based on Liferay's struts support with some adaptations.

At this time, Guestbook portlet sample is ok, and I've made a modification in wicket to get Navomatic and other bookmarkablePage working.

The main point is that Liferay want a new HttpServletRequest (from theirs object) in ServletContextProvider implementation of ServletContextProvider and we must copy the request's parameters from the original request to the new one.
I translate also the "_wu" (WicketPortlet.WICKET_URL_PORTLET_PARAMETER) parameter into differents parameters

You can have a look to my 3 classes at the end of this mail.

I've got a problem for all bookmarkablePage, because the argument are encoded by Wicket, and Liferay encode it second time.
The parameter received is like "%3Aorg.apache.wicket.examples.navomatic.Page2". So I add a call to decode function from "org.apache.wicket.protocol.http.RequestUtils"

Here is my code modification (it's maybe possible to find a another solution too)
in the class "org.apache.wicket.protocol.http.request.WebRequestCodingStrategy", method addBookmarkablePageParameters(final Request request, final RequestParameters parameters)
(line : 521 / SVN revision : 585043)
I change from
            final String[] components = Strings.split(requestString, Component.PATH_SEPARATOR);

to
            final String[] components = Strings.split(RequestUtils.decode(requestString),Component.PATH_SEPARATOR);

(Note: I test it with jetspeed and it works)

The main remaining problem is about Ajax portlet. I have this Error :

=======================================
15:38:53,248 ERROR [[default]:731] "Servlet.service()" pour la servlet default a lancé une exception
java.lang.NullPointerException
    at org.apache.wicket.protocol.http.WebResponse.redirect(WebResponse.java:204)
    at org.apache.wicket.protocol.http.BufferedWebResponse.close(BufferedWebResponse.java:66)
    at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:336)
    at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:175)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:691)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:594)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:505)
    at com.liferay.portlet.PortletRequestDispatcherImpl.include(PortletRequestDispatcherImpl.java:245)
    at com.liferay.portlet.PortletRequestDispatcherImpl.include(PortletRequestDispatcherImpl.java:87)
    at org.apache.wicket.protocol.http.portlet.WicketPortlet.processRequest(WicketPortlet.java:519)
    at org.apache.wicket.protocol.http.portlet.WicketPortlet.doView(WicketPortlet.java:416)
    at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:235)
(....)
=======================================

How can I go forward ? any suggestion ?????




=======================================
Here is my 3 implementation classes :
=======================================
package com.liferay.portlet;

import java.util.Map;

import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.apache.portals.bridges.common.PortletResourceURLFactory;

public class LiferayToPortalBridgePortletResourceURLFactory implements PortletResourceURLFactory
{
    public static final String    WICKET_PREFIX    = "org.apache.wicket_";

    public String createResourceURL( PortletConfig portletConfig, RenderRequest renderRequest, RenderResponse renderResponse, Map portletArg ) throws PortletException
    {
        String retval = "";

        final long plid = ( (RenderResponseImpl)renderResponse ).getPlid();
        final PortletURLImpl portletUrl = new PortletURLImpl( (RenderRequestImpl)renderRequest, portletConfig.getPortletName(), plid, true );
        retval = portletUrl.toString();
        return retval;
    }

}
=======================================
package com.liferay.portlet;

import java.io.IOException;
import java.util.Iterator;
import java.util.Map;

import javax.portlet.GenericPortlet;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.portals.bridges.common.ServletContextProvider;
import org.apache.wicket.protocol.http.portlet.WicketPortlet;

import com.liferay.portal.kernel.servlet.HttpHeaders;
import com.liferay.portal.kernel.util.ContentTypes;
import com.liferay.portlet.ActionRequestImpl;
import com.liferay.portlet.ActionResponseImpl;
import com.liferay.portlet.PortletContextImpl;
import com.liferay.portlet.RenderRequestImpl;
import com.liferay.portlet.RenderResponseImpl;
import com.liferay.util.HttpUtil;
import com.liferay.util.servlet.UploadServletRequest;

public class LiferayToPortalBridgeServletContextProvider implements ServletContextProvider
{

    public ServletContext getServletContext( GenericPortlet portlet )
    {
        return ( (PortletContextImpl)portlet.getPortletContext() ).getServletContext();
    }

    public HttpServletRequest getHttpServletRequest( GenericPortlet portlet, PortletRequest req )
    {

        HttpServletRequest httpReq = null;

        if ( req instanceof ActionRequestImpl )
        {
            httpReq = ( (ActionRequestImpl)req ).getHttpServletRequest();

            final String contentType = httpReq.getHeader( HttpHeaders.CONTENT_TYPE );

            if ( contentType != null && contentType.startsWith( ContentTypes.MULTIPART_FORM_DATA ) )
            {

                try
                {
                    httpReq = new UploadServletRequest( httpReq );
                }
                catch( final IOException ioe )
                {}

                httpReq = new LiferayWicketRequestImpl( httpReq );
            }
            else
            {
                httpReq = new LiferayWicketRequestImpl( (ActionRequestImpl)req );
            }
        }
        else
        {
            httpReq = new LiferayWicketRequestImpl( (RenderRequestImpl)req );
        }

        // Put the request parameters into the new request
        final Map otherParameters = req.getParameterMap();
        for ( final Iterator paramIteraror = otherParameters.keySet().iterator() ; paramIteraror.hasNext() ; )
        {
            final String paramKey = (String)paramIteraror.next();
            final Object paramValue = otherParameters.get( paramKey );
            if ( paramKey.equals( WicketPortlet.WICKET_URL_PORTLET_PARAMETER ) )
            {
                // if it's a URL Parameter, parse it and put all values into the request
                final String urlParameter = req.getParameter( WicketPortlet.WICKET_URL_PORTLET_PARAMETER );
                final Map queryStringArgs = HttpUtil.parameterMapFromString( urlParameter.substring( urlParameter.indexOf( '?' ) + 1 ) );
                for ( final Iterator keyIterator = queryStringArgs.keySet().iterator() ; keyIterator.hasNext() ; )
                {
                    final String aKey = (String)keyIterator.next();
                    final Object valueObject = queryStringArgs.get( aKey );

                    // Put all portlet's URL arguments into request attributes with a prefix
                    // they'll be loaded as a request parameter later
                    httpReq.setAttribute( LiferayToPortalBridgePortletResourceURLFactory.WICKET_PREFIX + aKey, valueObject );
                }
            }
            else
            {
                // put std parameter
                httpReq.setAttribute( LiferayToPortalBridgePortletResourceURLFactory.WICKET_PREFIX + paramKey, paramValue );
            }
        }
        return httpReq;
    }

    public HttpServletResponse getHttpServletResponse( GenericPortlet portlet, PortletResponse res )
    {
        HttpServletResponse httpResp = null;

        if ( res instanceof RenderResponseImpl )
            httpResp = ( (RenderResponseImpl)res ).getHttpServletResponse();
        else httpResp = ( (ActionResponseImpl)res ).getHttpServletResponse();

        return httpResp;
    }

}
=======================================
package com.liferay.portlet;

import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

import com.liferay.portal.util.PortalUtil;
import com.liferay.portlet.ActionRequestImpl;
import com.liferay.portlet.RenderRequestImpl;
import com.liferay.util.CollectionFactory;
import com.liferay.util.servlet.UploadServletRequest;

public class LiferayWicketRequestImpl extends HttpServletRequestWrapper
{
    public static final String    WICKET_BRIDGES_ATTRIBUTES    = "WICKET_BRIDGES_ATTRIBUTES";

    public LiferayWicketRequestImpl( ActionRequestImpl req )
    {
        this( req.getHttpServletRequest() );
    }

    public LiferayWicketRequestImpl( RenderRequestImpl req )
    {
        this( req.getHttpServletRequest() );
    }

    @Override
    public Object getAttribute( String name )
    {
        Object value = null;

        if ( name.startsWith( LiferayToPortalBridgePortletResourceURLFactory.WICKET_PREFIX ) )
        {
            value = this._wicketAttributes.get( name );
        }
        else
        {
            value = super.getAttribute( name );
        }

        return value;
    }

    @Override
    public void setAttribute( String name, Object value )
    {
        if ( name.startsWith( LiferayToPortalBridgePortletResourceURLFactory.WICKET_PREFIX ) )
        {
            this._wicketAttributes.put( name, value );
        }
        else
        {
            super.setAttribute( name, value );
        }
    }

    @Override
    public Enumeration getAttributeNames()
    {
        final List attributeNames = new Vector();

        final Enumeration enu = super.getAttributeNames();

        while ( enu.hasMoreElements() )
        {
            final String name = (String)enu.nextElement();

            if ( !name.startsWith( LiferayToPortalBridgePortletResourceURLFactory.WICKET_PREFIX ) )
            {
                attributeNames.add( name );
            }
        }

        final Iterator itr = this._wicketAttributes.keySet().iterator();

        while ( itr.hasNext() )
        {
            final String name = (String)itr.next();

            attributeNames.add( name );
        }

        return Collections.enumeration( attributeNames );
    }

    @Override
    public String getParameter( String name )
    {
        Object attrval;
        // we try to get the parameter in wicket's attributes first
        if ( ( attrval = this._wicketAttributes.get( LiferayToPortalBridgePortletResourceURLFactory.WICKET_PREFIX + name ) ) != null )
        {
            if ( attrval instanceof String )
                return (String)attrval;
            else if ( attrval instanceof String[] )
                return ( (String[])attrval )[0];
        }
        if ( this._multipartParams.get( name ) != null )
            return null;
        else return super.getParameter( name );
    }

    @Override
    public Map getParameterMap()
    {
        final Map params = CollectionFactory.getHashMap();

        final Enumeration enu = this.getParameterNames();

        while ( enu.hasMoreElements() )
        {
            final String name = (String)enu.nextElement();

            final String[] values = super.getParameterValues( name );

            params.put( name, values );
        }

        return params;
    }

    @Override
    public Enumeration getParameterNames()
    {
        final List parameterNames = new Vector();

        final Enumeration enu = super.getParameterNames();

        while ( enu.hasMoreElements() )
        {
            final String name = (String)enu.nextElement();

            if ( !this._multipartParams.containsKey( name ) )
            {
                parameterNames.add( name );
            }
        }

        return Collections.enumeration( parameterNames );
    }

    @Override
    public String[] getParameterValues( String name )
    {
        if ( this._multipartParams.get( name ) != null )
            return null;
        else return super.getParameterValues( name );
    }

    protected LiferayWicketRequestImpl( HttpServletRequest req )
    {
        super( req );

        this._wicketAttributes = (Map)req.getAttribute( LiferayWicketRequestImpl.WICKET_BRIDGES_ATTRIBUTES );

        if ( this._wicketAttributes == null )
        {
            this._wicketAttributes = CollectionFactory.getHashMap();

            req.setAttribute( LiferayWicketRequestImpl.WICKET_BRIDGES_ATTRIBUTES, this._wicketAttributes );
        }

        final UploadServletRequest uploadReq = PortalUtil.getUploadServletRequest( req );

        if ( uploadReq != null )
        {
            this._multipartParams = uploadReq.getMultipartParameterMap();
        }
    }

    private Map    _wicketAttributes;
    private Map    _multipartParams    = CollectionFactory.getHashMap();

}
=======================================


And From my previous mail I change the <TC_HOME>/webapp/wicket-exemples/WEB-INF/classes/org/apache/wicket/protocol/http/portlet/WicketPortlet.properties like this
    org.apache.portals.bridges.common.ServletContextProvider=com.liferay.portlet.LiferayToPortalBridgeServletContextProvider
    org.apache.portals.bridges.common.PortletResourceURLFactory=com.liferay.portlet.LiferayToPortalBridgePortletResourceURLFactory



Charly



Patrick Gill a écrit :

Ate Douma wrote:
  
That was my initial attempt at it.
For Jetspeed, I have much improved/simplyfied this after I added
ResourceURL handling natively to the portal (internally), and I only need
to set a predefined 
flag/parameter to tell it to use it (instead of creating a plain RenderURL
which simply won't do):

   public class PortletResourceURLFactoryImpl implements
PortletResourceURLFactory
   {
       /*
        * (non-Javadoc)
        *
        * @see
org.apache.portals.bridges.common.PortletResourceURLFactory#createResourceURL(javax.portlet.PortletConfig,
        *      javax.portlet.RenderRequest, javax.portlet.RenderResponse,
        *      java.util.Map)
        */
       public String createResourceURL(PortletConfig config, RenderRequest
request, RenderResponse response, Map parameters)
               throws PortletException
       {
           PortletURL url = ""
           if (parameters != null)
           {
               url.setParameters(parameters);
           }
          
url.setParameter(PortalReservedParameters.PORTLET_RESOURCE_URL_REQUEST_PARAMETER,
"");
           return url.toString();
       }
   }

    

Yes, I saw this implementation and tried looking for a parameter like this
in Liferay, but couldn't find any.


Ate Douma wrote:
  
Well, you'll have to check the Liferay portal/container internals for it
as it must be told not to create a plain RenderURL (as your current
implementation 
does) but instead switch to this pre-JSR-286 ResourceURL handling. How to
do that (if it is already supported) I can't tell you as I don't know
anything about 
Liferay's internals.

Well, yes. Without the ResourceURL support you're out of luck I'm afraid.
I suggest just keep pinging the Liferay devs (maybe they use IRC?).

    

Indeed. The issue has been open for almost 2 weeks now and there's been no
reply. I will try updating it with what you mention here, see if that
simplifies it for them, but I don't want to be a pain since Liferay is free
and open source... If only they pointed me in the right direction I'm sure I
could do something with it. It's cold and lonely out here! :D

Patrick
  
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to