[jboss-cvs] jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/consumer ...
Chris Laprun
chris.laprun at jboss.com
Sat Aug 19 00:27:58 EDT 2006
User: claprun
Date: 06/08/19 00:27:58
Modified: wsrp/src/main/org/jboss/portal/wsrp/consumer
RenderHandler.java InvocationHandler.java
ActionHandler.java WSRPConsumerImpl.java
Log:
Re-factored InvocationHandlers, should be simpler now.
Revision Changes Path
1.9 +9 -32 jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/consumer/RenderHandler.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: RenderHandler.java
===================================================================
RCS file: /cvsroot/jboss/jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/consumer/RenderHandler.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- RenderHandler.java 2 Aug 2006 23:48:23 -0000 1.8
+++ RenderHandler.java 19 Aug 2006 04:27:58 -0000 1.9
@@ -24,7 +24,6 @@
import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.URLTools;
-import org.jboss.portal.portlet.InvokerUnavailableException;
import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.portlet.result.ErrorResult;
import org.jboss.portal.portlet.result.FragmentResult;
@@ -43,7 +42,7 @@
/**
* @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
- * @version $Revision: 1.8 $
+ * @version $Revision: 1.9 $
* @since 2.4 (May 31, 2006)
*/
public class RenderHandler extends InvocationHandler
@@ -57,43 +56,21 @@
super(consumer);
}
- public MarkupResponse performRenderRequest(GetMarkup markupRequest, PortletInvocation invocation, int retryCount)
- throws ServiceDescriptionUnavailableException
- {
- return (MarkupResponse)performRequest(markupRequest, invocation, retryCount);
- }
-
- void processRenderRequest(RequestPrecursor requestPrecursor, PortletInvocation invocation)
- throws InvokerUnavailableException
+ protected Object prepareRequest(RequestPrecursor requestPrecursor, PortletInvocation invocation)
{
// Create the markup request
- GetMarkup markupRequest = WSRPTypeFactory.createMarkupRequest(requestPrecursor.portletHandle,
+ return WSRPTypeFactory.createMarkupRequest(requestPrecursor.portletHandle,
requestPrecursor.runtimeContext, requestPrecursor.markupParams);
- markupRequest.setRegistrationContext(consumer.getRegistrationContext());
-
- // User context
- markupRequest.setUserContext(consumer.getUserContextFrom(invocation, requestPrecursor.runtimeContext));
-
- // Perform the request
- MarkupResponse response;
- try
- {
- response = performRenderRequest(markupRequest, invocation, 0);
- }
- catch (ServiceDescriptionUnavailableException e)
- {
- throw new InvokerUnavailableException(e.getMessage(), e);
}
- if (response == null)
+
+ protected void processResponse(Object response, PortletInvocation invocation, RequestPrecursor requestPrecursor)
{
- unwrapWSRPError(invocation);
- return;
- }
+ MarkupResponse markupResponse = (MarkupResponse)response;
// process the response
- consumer.getSessionHandler().updateSessionIfNeeded(response.getSessionContext(), invocation);
+ consumer.getSessionHandler().updateSessionIfNeeded(markupResponse.getSessionContext(), invocation);
- MarkupContext markupContext = response.getMarkupContext();
+ MarkupContext markupContext = markupResponse.getMarkupContext();
String markup = markupContext.getMarkupString();
byte[] binary = markupContext.getMarkupBinary();
if (markup != null && binary != null)
1.3 +58 -26 jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/consumer/InvocationHandler.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: InvocationHandler.java
===================================================================
RCS file: /cvsroot/jboss/jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/consumer/InvocationHandler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- InvocationHandler.java 10 Aug 2006 19:56:47 -0000 1.2
+++ InvocationHandler.java 19 Aug 2006 04:27:58 -0000 1.3
@@ -23,6 +23,8 @@
package org.jboss.portal.wsrp.consumer;
import org.jboss.logging.Logger;
+import org.jboss.portal.portlet.InvokerUnavailableException;
+import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.portlet.result.ErrorResult;
import org.jboss.portal.wsrp.core.InvalidCookieFault;
@@ -38,13 +40,12 @@
/**
* @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
* @since 2.4 (May 31, 2006)
*/
public abstract class InvocationHandler
{
protected WSRPConsumerImpl consumer;
-// protected SessionHandler sessionHandler;
protected Logger log = Logger.getLogger(getClass());
/**
@@ -62,42 +63,67 @@
this.consumer = consumer;
}
- protected Object performRequest(Object request, PortletInvocation invocation, int retryCount)
+ void handle(PortletInvocation invocation) throws PortletInvokerException
+ {
+ // Extracts basic required information from invocation
+ RequestPrecursor requestPrecursor = new RequestPrecursor(consumer, invocation);
+
+ // create the specific request
+ Object request = prepareRequest(requestPrecursor, invocation);
+
+ // Perform the request
+ Object response;
+ try
+ {
+ response = performRequest(request, invocation);
+ }
+ catch (ServiceDescriptionUnavailableException e)
+ {
+ throw new InvokerUnavailableException(e.getMessage(), e);
+ }
+ if (response == null)
+ {
+ unwrapWSRPError(invocation);
+ return;
+ }
+
+ processResponse(response, invocation, requestPrecursor);
+ }
+
+ protected Object performRequest(Object request, PortletInvocation invocation)
throws ServiceDescriptionUnavailableException
{
+ int retryCount = 0;
+ Object response = null;
+
+ // as long as we don't get a non-null response and we're allowed to try again, try to perform the request
+ while (response == null && retryCount != DO_NOT_RETRY && retryCount < MAXIMUM_RETRY_NUMBER)
+ {
+ // prepare everything for the request
SessionHandler sessionHandler = consumer.getSessionHandler();
sessionHandler.initCookieIfNeeded(invocation);
+ updateRegistrationContext(request);
+ RuntimeContext runtimeContext = getRuntimeContextFrom(request);
+ updateUserContext(request, consumer.getUserContextFrom(invocation, runtimeContext));
+ consumer.setTemplatesIfNeeded(invocation, runtimeContext);
- Object response = null;
try
{
// if we need cookies, set the current group id
sessionHandler.initPortletGroupIdIfNeeded(invocation);
response = performRequest(request);
-
}
catch (Exception e)
{
- RuntimeContext runtimeContext = getRuntimeContextFrom(request);
retryCount = dealWithError(e, invocation, runtimeContext, retryCount);
-
- if (retryCount != DO_NOT_RETRY && retryCount < MAXIMUM_RETRY_NUMBER)
- {
- // update the different parameters since they may have been modified
- updateRegistrationContext(request);
- updateUserContext(request, consumer.getUserContextFrom(invocation, runtimeContext));
- consumer.setTemplatesIfNeeded(invocation, runtimeContext);
-
- response = performRequest(request, invocation, retryCount);
- }
}
finally
{
// we're done: reset current group id
sessionHandler.resetPortletGroupIdIfNeeded();
}
-
+ }
return response;
}
@@ -120,12 +146,13 @@
// recoverable errors
if (error instanceof InvalidCookieFault)
{
- log.info("Re-initializing cookies after InvalidCookieFault");
+ log.debug("Re-initializing cookies after InvalidCookieFault.");
// we need to re-init the cookies
sessionHandler.initCookieIfNeeded(invocation);
}
else if (error instanceof InvalidSessionFault)
{
+ log.debug("Session invalidated afet InvalidSessionFault, will re-send session-stored information.");
sessionHandler.handleInvalidSessionFault(invocation, runtimeContext);
}
else if (error instanceof InvalidRegistrationFault)
@@ -199,4 +226,9 @@
protected abstract RuntimeContext getRuntimeContextFrom(Object request);
protected abstract Object performRequest(Object request) throws Exception;
+
+ protected abstract Object prepareRequest(RequestPrecursor requestPrecursor, PortletInvocation invocation);
+
+ protected abstract void processResponse(Object response, PortletInvocation invocation, RequestPrecursor requestPrecursor);
+
}
1.6 +9 -33 jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/consumer/ActionHandler.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ActionHandler.java
===================================================================
RCS file: /cvsroot/jboss/jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/consumer/ActionHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- ActionHandler.java 19 Aug 2006 01:49:31 -0000 1.5
+++ ActionHandler.java 19 Aug 2006 04:27:58 -0000 1.6
@@ -23,7 +23,6 @@
package org.jboss.portal.wsrp.consumer;
import org.jboss.portal.common.util.ParameterValidation;
-import org.jboss.portal.portlet.InvokerUnavailableException;
import org.jboss.portal.portlet.Parameters;
import org.jboss.portal.portlet.ParametersStateString;
import org.jboss.portal.portlet.StateString;
@@ -52,7 +51,7 @@
/**
* @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
* @since 2.4 (May 31, 2006)
*/
public class ActionHandler extends InvocationHandler
@@ -62,8 +61,7 @@
super(consumer);
}
- void processActionRequest(PortletInvocation invocation, RequestPrecursor requestPrecursor)
- throws InvokerUnavailableException
+ protected Object prepareRequest(RequestPrecursor requestPrecursor, PortletInvocation invocation)
{
// access mode
InstanceContext instanceContext = invocation.getInstanceContext();
@@ -111,31 +109,17 @@
// todo: need to deal with GET method in forms
// Create the blocking action request
- PerformBlockingInteraction actionRequest = WSRPTypeFactory.createPerformBlockingInteraction(
+ return WSRPTypeFactory.createPerformBlockingInteraction(
requestPrecursor.portletHandle, requestPrecursor.runtimeContext, requestPrecursor.markupParams,
interactionParams);
- actionRequest.setRegistrationContext(consumer.getRegistrationContext());
-
- // User context
- actionRequest.setUserContext(consumer.getUserContextFrom(invocation, requestPrecursor.runtimeContext));
-
- BlockingInteractionResponse response;
- try
- {
- response = performActionRequest(actionRequest, invocation, 0);
}
- catch (ServiceDescriptionUnavailableException e)
- {
- throw new InvokerUnavailableException(e.getMessage(), e);
- }
- if (response == null)
+
+ protected void processResponse(Object response, PortletInvocation invocation, RequestPrecursor requestPrecursor)
{
- unwrapWSRPError(invocation);
- return;
- }
+ BlockingInteractionResponse blockingInteractionResponse = (BlockingInteractionResponse)response;
- String redirectURL = response.getRedirectURL();
- UpdateResponse updateResponse = response.getUpdateResponse();
+ String redirectURL = blockingInteractionResponse.getRedirectURL();
+ UpdateResponse updateResponse = blockingInteractionResponse.getUpdateResponse();
if (redirectURL != null && updateResponse != null)
{
invocation.setResult(new ErrorResult(
@@ -185,7 +169,6 @@
}
}
-
protected void updateUserContext(Object request, UserContext userContext)
{
getActionRequest(request).setUserContext(userContext);
@@ -216,11 +199,4 @@
throw new IllegalArgumentException("ActionHandler: request is not a PerformBlockingInteraction request!");
}
-
- public BlockingInteractionResponse performActionRequest(PerformBlockingInteraction actionRequest,
- PortletInvocation invocation, int retryCount)
- throws ServiceDescriptionUnavailableException
- {
- return (BlockingInteractionResponse)performRequest(actionRequest, invocation, retryCount);
- }
}
1.54 +7 -6 jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: WSRPConsumerImpl.java
===================================================================
RCS file: /cvsroot/jboss/jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -b -r1.53 -r1.54
--- WSRPConsumerImpl.java 19 Aug 2006 03:24:32 -0000 1.53
+++ WSRPConsumerImpl.java 19 Aug 2006 04:27:58 -0000 1.54
@@ -68,7 +68,7 @@
/**
* @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
* @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
- * @version $Revision: 1.53 $
+ * @version $Revision: 1.54 $
* @since 2.4
*/
public class WSRPConsumerImpl extends AbstractJBossService implements WSRPConsumer
@@ -174,21 +174,22 @@
public void invoke(PortletInvocation invocation) throws PortletInvokerException
{
- // Extracts basic required information from invocation
- RequestPrecursor requestPrecursor = new RequestPrecursor(this, invocation);
+ InvocationHandler handler;
if (invocation instanceof RenderInvocation)
{
- renderHandler.processRenderRequest(requestPrecursor, invocation);
+ handler = renderHandler;
}
else if (invocation instanceof ActionInvocation)
{
- actionHandler.processActionRequest(invocation, requestPrecursor);
+ handler = actionHandler;
}
else
{
throw new InvocationException("Unknown invocation type: " + invocation);
}
+
+ handler.handle(invocation);
}
public String createClone(String portletId)
@@ -403,7 +404,7 @@
void handleInvalidRegistrationFault()
throws ServiceDescriptionUnavailableException
{
- log.info("Trying to re-register after InvalidRegistrationFault");
+ log.debug("Trying to re-register after InvalidRegistrationFault");
// get the service description again and try to register
getServiceDescriptionAndRegisterIfNeeded();
}
More information about the jboss-cvs-commits
mailing list