[jboss-cvs] jboss-portal/portlet/src/main/org/jboss/portal/portlet/aspects/portlet ...
Julien Viet
julien at jboss.com
Tue Jul 11 19:09:18 EDT 2006
User: julien
Date: 06/07/11 19:09:18
Added: portlet/src/main/org/jboss/portal/portlet/aspects/portlet
ContextDispatcherInterceptor.java
ContextTrackerInterceptor.java
ModesInterceptor.java
SecureTransportInterceptor.java
ValveInterceptor.java WindowStatesInterceptor.java
Log:
- removed old portlet.war and portlet.sar that is unused
- in portlet module move interceptors from component to portlet package
Revision Changes Path
1.1 date: 2006/07/11 23:09:18; author: julien; state: Exp;jboss-portal/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/ContextDispatcherInterceptor.java
Index: ContextDispatcherInterceptor.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.portal.portlet.aspects.portlet;
import org.jboss.portal.common.invocation.InvocationException;
import org.jboss.portal.portlet.container.PortletContainer;
import org.jboss.portal.portlet.container.PortletApplication;
import org.jboss.portal.portlet.container.info.ContainerPortletInfo;
import org.jboss.portal.portlet.invocation.PortletInterceptor;
import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.portlet.spi.RequestContext;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.server.servlet.CommandServlet;
import org.jboss.portal.server.servlet.ServletCommand;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* This interceptor dispatch the call to the target web application.
*
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
public class ContextDispatcherInterceptor extends PortletInterceptor
{
public static final String REQ_ATT_COMPONENT_INVOCATION = "org.jboss.portal.attribute.component_invocation";
private static final ThreadLocal localEx = new ThreadLocal();
protected void invoke(PortletInvocation invocation) throws Exception, InvocationException
{
PortletContainer container = ((ContainerPortletInfo)invocation.getInfo()).getContainer();
PortletApplication portletApplication = container.getApplication();
ServletContext targetCtx = portletApplication.getContext().getServletContext();
try
{
// Get command servlet and dispatch
final RequestContext requestContext = invocation.getRequestContext();
CommandServlet.Dispatcher dispatcher = new CommandServlet.Dispatcher()
{
public void include(RequestDispatcher rd) throws IOException, ServletException
{
requestContext.include(rd);
}
};
//
ServletCommand cmd = new InvokeNextCommand(invocation);
CommandServlet.include(dispatcher, cmd, targetCtx);
// Rethrow any InvocationException
Exception ex = (Exception)localEx.get();
if (ex != null)
{
throw ex;
}
}
catch (IOException e)
{
throw new PortletInvokerException(e);
}
catch (ServletException e)
{
throw new PortletInvokerException(e);
}
finally
{
localEx.set(null);
}
}
public static class InvokeNextCommand implements ServletCommand
{
private PortletInvocation invocation;
public InvokeNextCommand(PortletInvocation invocation)
{
this.invocation = invocation;
}
public PortletInvocation getInvocation()
{
return invocation;
}
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
try
{
// Set dispatched request and response and invocation
invocation.setDispatchedRequest(req);
invocation.setDispatchedResponse(resp);
invocation.getDispatchedRequest().setAttribute(REQ_ATT_COMPONENT_INVOCATION, invocation);
//
try
{
invocation.invokeNext();
}
catch (Exception e)
{
localEx.set(e);
}
}
finally
{
// Clear dispatched request and response
invocation.getDispatchedRequest().setAttribute(REQ_ATT_COMPONENT_INVOCATION, null);
invocation.setDispatchedRequest(null);
invocation.setDispatchedResponse(null);
}
}
}
}
1.1 date: 2006/07/11 23:09:18; author: julien; state: Exp;jboss-portal/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/ContextTrackerInterceptor.java
Index: ContextTrackerInterceptor.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.portal.portlet.aspects.portlet;
import org.jboss.portal.portlet.invocation.PortletInterceptor;
import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.portlet.container.PortletContainer;
import org.jboss.portal.portlet.container.info.ContainerPortletInfo;
import org.jboss.portal.common.invocation.InvocationException;
/**
* This interceptor get the current webapp context path and adds it to the set of the collected
* context path.
*
*
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
public class ContextTrackerInterceptor extends PortletInterceptor
{
protected void invoke(PortletInvocation invocation) throws Exception, InvocationException
{
// Get the context path we have been dispatched to
PortletContainer container = ((ContainerPortletInfo)invocation.getInfo()).getContainer();
String contextPath = container.getApplication().getContext().getContextPath();
// Add it to the request context path set
org.jboss.portal.server.aspects.server.SessionInvalidatorInterceptor.getSet().add(contextPath);
// Invoke next command
invocation.invokeNext();
}
}
1.1 date: 2006/07/11 23:09:18; author: julien; state: Exp;jboss-portal/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/ModesInterceptor.java
Index: ModesInterceptor.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.portal.portlet.aspects.portlet;
import org.jboss.portal.common.invocation.InvocationException;
import org.jboss.portal.portlet.info.CapabilitiesInfo;
import org.jboss.portal.portlet.info.ModeInfo;
import org.jboss.portal.portlet.info.PortletInfo;
import org.jboss.portal.portlet.invocation.PortletInterceptor;
import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.server.util.HTTPStreamInfo;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
/**
* The ModesInterceptor computes the mode for the request as well as the supported modes.
*
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
public class ModesInterceptor extends PortletInterceptor
{
protected void invoke(PortletInvocation invocation) throws Exception, InvocationException
{
if (invocation.getContext().getMode() == null)
{
throw new InvocationException("No mode has been provided");
}
// Compute the supported modes.
Set modes = getModes(invocation);
// Set the modes on the invocation
invocation.setSupportedModes(modes);
// Continue the invocation
invocation.invokeNext();
}
/**
* Compute the supported modes for this invocation.
*/
protected Set getModes(PortletInvocation invocation)
{
// Get content type
HTTPStreamInfo si = invocation.getContext().getStreamInfo();
String contentType = si.getContentType().toString();
// Get the modes for this content type
PortletInfo containerInfo = invocation.getInfo();
CapabilitiesInfo capabilities = containerInfo.getCapabilities();
// Add all the modes
Set modes = new HashSet();
for (Iterator i = capabilities.getModes(contentType).iterator(); i.hasNext();)
{
ModeInfo modeInfo = (ModeInfo)i.next();
modes.add(modeInfo.getMode());
}
// Restrict with what the portal can provide
Set portalModes = invocation.getPortalContext().getModes();
modes.retainAll(portalModes);
// If user is not logged in then remove the edit mode
// commenting out for now since it breaks tests
/*AccessMode accessMode = invocation.getInstanceContext().getAccessMode();
if (accessMode == AccessMode.READ_ONLY)
{
modes.remove(Mode.EDIT);
}*/
//
return modes;
}
}
1.1 date: 2006/07/11 23:09:18; author: julien; state: Exp;jboss-portal/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/SecureTransportInterceptor.java
Index: SecureTransportInterceptor.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.portal.portlet.aspects.portlet;
import org.jboss.portal.portlet.invocation.PortletInterceptor;
import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.portlet.spi.SecurityContext;
import org.jboss.portal.server.util.TransportGuarantee;
import org.jboss.portal.portlet.result.InsufficientTransportGuaranteeResult;
import org.jboss.portal.common.invocation.InvocationException;
import org.jboss.portal.portlet.info.PortletInfo;
import org.jboss.portal.portlet.info.SecurityInfo;
/**
* Implement security constaint defined by the portlet spec.
*
*
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
public class SecureTransportInterceptor extends PortletInterceptor
{
protected void invoke(PortletInvocation invocation) throws Exception, InvocationException
{
PortletInfo containerInfo = invocation.getInfo();
SecurityInfo securityInfo = containerInfo.getSecurity();
SecurityContext securityContext = invocation.getSecurityContext();
boolean invoke = true;
if (!securityContext.isSecure())
{
if (securityInfo.containsTransportGuarantee(TransportGuarantee.CONFIDENTIAL))
{
invoke = false;
}
else if (securityInfo.containsTransportGuarantee(TransportGuarantee.INTEGRAL))
{
invoke = false;
}
}
//
if (invoke)
{
// Invoke
invocation.invokeNext();
}
else
{
// Significate to the caller that this component should be executed with an higher security level
invocation.setResult(new InsufficientTransportGuaranteeResult());
}
}
}
1.1 date: 2006/07/11 23:09:18; author: julien; state: Exp;jboss-portal/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/ValveInterceptor.java
Index: ValveInterceptor.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.portal.portlet.aspects.portlet;
import org.jboss.portal.portlet.invocation.PortletInterceptor;
import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.portlet.result.Result;
import org.jboss.portal.portlet.result.UnavailableResult;
import org.jboss.portal.common.invocation.InvocationException;
import org.jboss.portal.portlet.container.PortletContainer;
import org.jboss.portal.portlet.container.info.ContainerPortletInfo;
import org.jboss.portal.portlet.container.PortletApplicationImpl;
import org.jboss.portal.common.concurrent.Valve;
/**
* This aspect has two responsabilities :<br/>
* <ul>
* <li>continue the request only if the portlet container valve is open.
* When the valle is closed, it will return an unavailable response to the caller.
* When the valve is open then the current thread of execution enters the valve
* for the duration of the call.</li>
* <li> if the response from the next aspect is an unavailable result, stop the container
* in order to destroy the portlet and implement this part of the portlet specification.</li>
* </ul>
*
*
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
public class ValveInterceptor extends PortletInterceptor
{
protected void invoke(PortletInvocation invocation) throws Exception, InvocationException
{
PortletContainer container = ((ContainerPortletInfo)invocation.getInfo()).getContainer();
Valve valve = container.getValve();
// Try to aquire the valve
if (valve.beforeInvocation())
{
try
{
invocation.invokeNext();
}
finally
{
// Release the valve
valve.afterInvocation();
}
// Stop the container if necessary
Result result = invocation.getResult();
if (result instanceof UnavailableResult)
{
// This call will wait until all the current threads have exited the component valve.
// Perhaps this should be done asynchronously as it may lead to a long delay ?
// It could be made parametrizable too, so the deployer can choose what mode is preferable
PortletApplicationImpl pwa = (PortletApplicationImpl)container.getApplication();
pwa.stop(container.getName());
}
}
else
{
UnavailableResult res = new UnavailableResult();
invocation.setResult(res);
}
}
}
1.1 date: 2006/07/11 23:09:18; author: julien; state: Exp;jboss-portal/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/WindowStatesInterceptor.java
Index: WindowStatesInterceptor.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.portal.portlet.aspects.portlet;
import org.jboss.portal.portlet.invocation.PortletInterceptor;
import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.common.invocation.InvocationException;
import java.util.HashSet;
import java.util.Set;
/**
* The WindowStatesInterceptor computes the window state for the request as well as the supported window states.
*
*
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
public class WindowStatesInterceptor extends PortletInterceptor
{
protected void invoke(PortletInvocation invocation) throws Exception, InvocationException
{
if (invocation.getContext().getWindowState() == null)
{
throw new InvocationException("No window state has been provided");
}
// Compute the supported window states
Set windowStates = getWindowStates(invocation);
//
invocation.setSupportedWindowStates(windowStates);
// Continue the invocation
invocation.invokeNext();
}
/**
* Compute the supported window states for this invocation.
*/
protected Set getWindowStates(PortletInvocation invocation) throws InvocationException
{
return new HashSet(invocation.getPortalContext().getWindowStates());
}
}
More information about the jboss-cvs-commits
mailing list