Author: chris.laprun(a)jboss.com
Date: 2011-04-14 07:11:52 -0400 (Thu, 14 Apr 2011)
New Revision: 6216
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ActionRequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/EventRequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProcessorFactory.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProducerHelper.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RenderRequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ResourceRequestProcessor.java
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessorTestCase.java
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java
Log:
- GTNWSRP-221: Fixed language processing logic.
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ActionRequestProcessor.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ActionRequestProcessor.java 2011-04-14
10:20:53 UTC (rev 6215)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ActionRequestProcessor.java 2011-04-14
11:11:52 UTC (rev 6216)
@@ -47,6 +47,7 @@
import org.oasis.wsrp.v2.RegistrationContext;
import org.oasis.wsrp.v2.RuntimeContext;
import org.oasis.wsrp.v2.StateChange;
+import org.oasis.wsrp.v2.UnsupportedLocale;
import org.oasis.wsrp.v2.UnsupportedMimeType;
import org.oasis.wsrp.v2.UnsupportedMode;
import org.oasis.wsrp.v2.UnsupportedWindowState;
@@ -63,7 +64,7 @@
ActionRequestProcessor(ProducerHelper producer, PerformBlockingInteraction
performBlockingInteraction)
throws UnsupportedMimeType, UnsupportedWindowState, InvalidHandle, UnsupportedMode,
MissingParameters,
- InvalidRegistration, OperationFailed, ModifyRegistrationRequired
+ InvalidRegistration, OperationFailed, ModifyRegistrationRequired,
UnsupportedLocale
{
super(producer);
this.performBlockingInteraction = performBlockingInteraction;
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/EventRequestProcessor.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/EventRequestProcessor.java 2011-04-14
10:20:53 UTC (rev 6215)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/EventRequestProcessor.java 2011-04-14
11:11:52 UTC (rev 6216)
@@ -50,6 +50,7 @@
import org.oasis.wsrp.v2.RegistrationContext;
import org.oasis.wsrp.v2.RuntimeContext;
import org.oasis.wsrp.v2.StateChange;
+import org.oasis.wsrp.v2.UnsupportedLocale;
import org.oasis.wsrp.v2.UnsupportedMimeType;
import org.oasis.wsrp.v2.UnsupportedMode;
import org.oasis.wsrp.v2.UnsupportedWindowState;
@@ -66,7 +67,7 @@
{
private HandleEvents handleEvents;
- public EventRequestProcessor(ProducerHelper producer, HandleEvents handleEvents)
throws OperationFailed, UnsupportedMode, InvalidHandle, MissingParameters,
UnsupportedMimeType, UnsupportedWindowState, InvalidRegistration, OperationNotSupported,
ModifyRegistrationRequired
+ public EventRequestProcessor(ProducerHelper producer, HandleEvents handleEvents)
throws OperationFailed, UnsupportedMode, InvalidHandle, MissingParameters,
UnsupportedMimeType, UnsupportedWindowState, InvalidRegistration, OperationNotSupported,
ModifyRegistrationRequired, UnsupportedLocale
{
super(producer);
this.handleEvents = handleEvents;
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProcessorFactory.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProcessorFactory.java 2011-04-14
10:20:53 UTC (rev 6215)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProcessorFactory.java 2011-04-14
11:11:52 UTC (rev 6216)
@@ -34,6 +34,7 @@
import org.oasis.wsrp.v2.OperationFailed;
import org.oasis.wsrp.v2.OperationNotSupported;
import org.oasis.wsrp.v2.PerformBlockingInteraction;
+import org.oasis.wsrp.v2.UnsupportedLocale;
import org.oasis.wsrp.v2.UnsupportedMimeType;
import org.oasis.wsrp.v2.UnsupportedMode;
import org.oasis.wsrp.v2.UnsupportedWindowState;
@@ -46,7 +47,7 @@
{
public static RequestProcessor getProcessorFor(ProducerHelper producer, Object
request)
throws OperationFailed, UnsupportedMode, InvalidHandle, MissingParameters,
UnsupportedMimeType,
- UnsupportedWindowState, InvalidRegistration, ModifyRegistrationRequired
+ UnsupportedWindowState, InvalidRegistration, ModifyRegistrationRequired,
UnsupportedLocale
{
if (request instanceof GetMarkup)
{
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProducerHelper.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProducerHelper.java 2011-04-14
10:20:53 UTC (rev 6215)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProducerHelper.java 2011-04-14
11:11:52 UTC (rev 6216)
@@ -46,7 +46,5 @@
PortletDescription getPortletDescription(PortletContext portletContext,
List<String> locales, Registration registration) throws InvalidHandle,
OperationFailed;
- PortletDescription getPortletDescription(Portlet portlet, List<String>
locales);
-
Registration getRegistrationOrFailIfInvalid(RegistrationContext registrationContext)
throws InvalidRegistration, OperationFailed, ModifyRegistrationRequired;
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RenderRequestProcessor.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RenderRequestProcessor.java 2011-04-14
10:20:53 UTC (rev 6215)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RenderRequestProcessor.java 2011-04-14
11:11:52 UTC (rev 6216)
@@ -41,6 +41,7 @@
import org.oasis.wsrp.v2.PortletContext;
import org.oasis.wsrp.v2.RegistrationContext;
import org.oasis.wsrp.v2.RuntimeContext;
+import org.oasis.wsrp.v2.UnsupportedLocale;
import org.oasis.wsrp.v2.UnsupportedMimeType;
import org.oasis.wsrp.v2.UnsupportedMode;
import org.oasis.wsrp.v2.UnsupportedWindowState;
@@ -55,7 +56,7 @@
private final GetMarkup getMarkup;
public RenderRequestProcessor(ProducerHelper producer, GetMarkup getMarkup) throws
UnsupportedMimeType,
- UnsupportedWindowState, InvalidHandle, UnsupportedMode, MissingParameters,
InvalidRegistration, OperationFailed, ModifyRegistrationRequired
+ UnsupportedWindowState, InvalidHandle, UnsupportedMode, MissingParameters,
InvalidRegistration, OperationFailed, ModifyRegistrationRequired, UnsupportedLocale
{
super(producer);
this.getMarkup = getMarkup;
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RequestProcessor.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RequestProcessor.java 2011-04-14
10:20:53 UTC (rev 6215)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RequestProcessor.java 2011-04-14
11:11:52 UTC (rev 6216)
@@ -43,8 +43,11 @@
import org.gatein.registration.RegistrationLocal;
import org.gatein.wsrp.UserContextConverter;
import org.gatein.wsrp.WSRPConstants;
+import org.gatein.wsrp.WSRPExceptionFactory;
+import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.WSRPUtils;
import org.gatein.wsrp.producer.Utils;
+import org.gatein.wsrp.producer.WSRPValidator;
import org.gatein.wsrp.servlet.ServletAccess;
import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
import org.oasis.wsrp.v2.InvalidHandle;
@@ -61,6 +64,7 @@
import org.oasis.wsrp.v2.RegistrationContext;
import org.oasis.wsrp.v2.RuntimeContext;
import org.oasis.wsrp.v2.SessionParams;
+import org.oasis.wsrp.v2.UnsupportedLocale;
import org.oasis.wsrp.v2.UnsupportedMimeType;
import org.oasis.wsrp.v2.UnsupportedMode;
import org.oasis.wsrp.v2.UnsupportedWindowState;
@@ -72,6 +76,7 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -102,7 +107,7 @@
}
void prepareInvocation() throws InvalidRegistration, OperationFailed, InvalidHandle,
- UnsupportedMimeType, UnsupportedWindowState, UnsupportedMode, MissingParameters,
ModifyRegistrationRequired
+ UnsupportedMimeType, UnsupportedWindowState, UnsupportedMode, MissingParameters,
ModifyRegistrationRequired, UnsupportedLocale
{
Registration registration =
producer.getRegistrationOrFailIfInvalid(getRegistrationContext());
@@ -121,6 +126,20 @@
WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(wsrpPC,
"PortletContext", getContextName());
org.gatein.pc.api.PortletContext portletContext =
WSRPUtils.convertToPortalPortletContext(wsrpPC);
+ // check locales
+ final List<String> desiredLocales = params.getLocales();
+ for (String locale : desiredLocales)
+ {
+ try
+ {
+ WSRPUtils.getLocale(locale);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(UnsupportedLocale.class,
e.getLocalizedMessage(), null);
+ }
+ }
+
// retrieve the portlet
try
{
@@ -133,8 +152,7 @@
}
// get portlet description for the desired portlet...
- final List<String> desiredLocales = params.getLocales();
- portletDescription = producer.getPortletDescription(portlet, desiredLocales);
+ portletDescription = producer.getPortletDescription(wsrpPC, null, registration);
if (Boolean.TRUE.equals(portletDescription.isUsesMethodGet()))
{
throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class,
"Portlets using GET method in forms are not currently supported.", null);
@@ -226,7 +244,7 @@
* @return a MarkupRequest containing the most appropriate information to base markup
generation for this request
*/
private MarkupRequest createMarkupRequestFrom(List<MarkupType> markupTypes,
MimeRequest params, Portlet portlet)
- throws UnsupportedMimeType, UnsupportedMode, UnsupportedWindowState
+ throws UnsupportedMimeType, UnsupportedMode, UnsupportedWindowState,
UnsupportedLocale
{
List<String> desiredMIMETypes = params.getMimeTypes();
MarkupType markupType = null;
@@ -279,49 +297,24 @@
}
// use user-desired locales
- List<String> locales = params.getLocales();
+ List<String> desiredLocales = new
ArrayList<String>(params.getLocales());
List<String> supportedLocales = new
ArrayList<String>(markupType.getLocales());
- if (supportedLocales != null)
- {
- // reset markup type locales
- markupType.getLocales().clear();
- boolean found = false;
+ desiredLocales.retainAll(supportedLocales);
- // find the best match
- for (String locale : locales)
- {
- for (String supportedLocale : supportedLocales)
- {
- if (locale.equals(supportedLocale))
- {
- markupType.getLocales().add(locale);
- found = true;
- break;
- }
- }
-
- if (found)
- {
- break;
- }
- }
-
- // if no best match was found, use whatever the user gave us
- if (!found)
- {
- markupType.getLocales().addAll(locales);
- }
- }
- else
+ if (desiredLocales.isEmpty())
{
- markupType.getLocales().addAll(locales);
+ desiredLocales = params.getLocales();
}
+ // copy MarkupType as this is one shared instance
+ MarkupType markupTypeCopy =
WSRPTypeFactory.createMarkupType(markupType.getMimeType(), markupType.getModes(),
markupType.getWindowStates(), desiredLocales);
+ markupTypeCopy.getExtensions().addAll(markupType.getExtensions());
+
// get the mode
String mode;
try
{
- mode = getMatchingOrFailFrom(markupType.getModes(), params.getMode(),
PORTLET_MODE);
+ mode = getMatchingOrFailFrom(markupTypeCopy.getModes(), params.getMode(),
PORTLET_MODE);
}
catch (IllegalArgumentException e)
{
@@ -332,7 +325,7 @@
String windowState;
try
{
- windowState = getMatchingOrFailFrom(markupType.getWindowStates(),
params.getWindowState(), WINDOW_STATE);
+ windowState = getMatchingOrFailFrom(markupTypeCopy.getWindowStates(),
params.getWindowState(), WINDOW_STATE);
}
catch (IllegalArgumentException e)
{
@@ -342,7 +335,7 @@
// get the character set
String characterSet =
getMatchingOrDefaultFrom(Collections.<String>emptyList(),
params.getMarkupCharacterSets(), WSRPConstants.DEFAULT_CHARACTER_SET);
- return new MarkupRequest(markupType, mode, windowState, characterSet, portlet);
+ return new MarkupRequest(markupTypeCopy, mode, windowState, characterSet,
portlet);
}
/**
@@ -516,7 +509,7 @@
private SecurityContext createSecurityContext(final MimeRequest params, final
RuntimeContext runtimeContext,
final org.oasis.wsrp.v2.UserContext
wsrpUserContext)
{
-
+
final HttpServletRequest request = ServletAccess.getRequest();
final boolean useSecurity;
if (request != null && request.getRemoteUser() != null)
@@ -527,7 +520,7 @@
{
useSecurity = false;
}
-
+
return new SecurityContext()
{
public boolean isSecure()
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ResourceRequestProcessor.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ResourceRequestProcessor.java 2011-04-14
10:20:53 UTC (rev 6215)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ResourceRequestProcessor.java 2011-04-14
11:11:52 UTC (rev 6216)
@@ -43,6 +43,7 @@
import org.oasis.wsrp.v2.ResourceParams;
import org.oasis.wsrp.v2.ResourceResponse;
import org.oasis.wsrp.v2.RuntimeContext;
+import org.oasis.wsrp.v2.UnsupportedLocale;
import org.oasis.wsrp.v2.UnsupportedMimeType;
import org.oasis.wsrp.v2.UnsupportedMode;
import org.oasis.wsrp.v2.UnsupportedWindowState;
@@ -56,7 +57,7 @@
{
private final GetResource getResource;
- public ResourceRequestProcessor(ProducerHelper producer, GetResource getResource)
throws InvalidRegistration, OperationFailed, MissingParameters, InvalidHandle,
UnsupportedMimeType, UnsupportedWindowState, UnsupportedMode, ModifyRegistrationRequired
+ public ResourceRequestProcessor(ProducerHelper producer, GetResource getResource)
throws InvalidRegistration, OperationFailed, MissingParameters, InvalidHandle,
UnsupportedMimeType, UnsupportedWindowState, UnsupportedMode, ModifyRegistrationRequired,
UnsupportedLocale
{
super(producer);
this.getResource = getResource;
Modified:
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessorTestCase.java
===================================================================
---
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessorTestCase.java 2011-04-14
10:20:53 UTC (rev 6215)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessorTestCase.java 2011-04-14
11:11:52 UTC (rev 6216)
@@ -44,6 +44,7 @@
import org.oasis.wsrp.v2.OperationFailed;
import org.oasis.wsrp.v2.PortletDescription;
import org.oasis.wsrp.v2.RegistrationContext;
+import org.oasis.wsrp.v2.UnsupportedLocale;
import org.oasis.wsrp.v2.UnsupportedMimeType;
import org.oasis.wsrp.v2.UnsupportedMode;
import org.oasis.wsrp.v2.UnsupportedWindowState;
@@ -59,7 +60,7 @@
{
private static final String PORTLET_HANDLE = "/app.portletHandle";
- public void testShouldUseProvidedNamespace() throws OperationFailed, UnsupportedMode,
InvalidHandle, MissingParameters, UnsupportedMimeType, UnsupportedWindowState,
InvalidRegistration, ModifyRegistrationRequired
+ public void testShouldUseProvidedNamespace() throws OperationFailed, UnsupportedMode,
InvalidHandle, MissingParameters, UnsupportedMimeType, UnsupportedWindowState,
InvalidRegistration, ModifyRegistrationRequired, UnsupportedLocale
{
String namespace = "namespace";
ServletAccess.setRequestAndResponse(MockHttpServletRequest.createMockRequest(MockHttpSession.createMockSession()),
MockHttpServletResponse.createMockResponse());
@@ -72,7 +73,7 @@
assertEquals("namespace",
processor.invocation.getWindowContext().getNamespace());
}
- public void testShouldProperlyHandleWildCardsInRequestedMimeTypes() throws
OperationFailed, UnsupportedMode, InvalidHandle, MissingParameters, UnsupportedMimeType,
ModifyRegistrationRequired, UnsupportedWindowState, InvalidRegistration
+ public void testShouldProperlyHandleWildCardsInRequestedMimeTypes() throws
OperationFailed, UnsupportedMode, InvalidHandle, MissingParameters, UnsupportedMimeType,
ModifyRegistrationRequired, UnsupportedWindowState, InvalidRegistration,
UnsupportedLocale
{
List<String> mimeTypes = new ArrayList<String>(1);
mimeTypes.add("*/*");
@@ -122,7 +123,7 @@
}
}
- public void testShouldReturnFirstMimeTypeMatching() throws OperationFailed,
UnsupportedMode, InvalidHandle, MissingParameters, UnsupportedMimeType,
ModifyRegistrationRequired, UnsupportedWindowState, InvalidRegistration
+ public void testShouldReturnFirstMimeTypeMatching() throws OperationFailed,
UnsupportedMode, InvalidHandle, MissingParameters, UnsupportedMimeType,
ModifyRegistrationRequired, UnsupportedWindowState, InvalidRegistration,
UnsupportedLocale
{
List<String> mimeTypes = new ArrayList<String>(2);
mimeTypes.add("text/xml");
@@ -176,11 +177,6 @@
public PortletDescription getPortletDescription(org.oasis.wsrp.v2.PortletContext
portletContext, List<String> locales, Registration registration) throws
InvalidHandle, OperationFailed
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
- }
-
- public PortletDescription getPortletDescription(Portlet portlet, List<String>
locales)
- {
List<String> modeNames = new ArrayList<String>(1);
modeNames.add(WSRPConstants.VIEW_MODE);
@@ -194,9 +190,15 @@
return WSRPTypeFactory.createPortletDescription(PORTLET_HANDLE, markupTypes);
}
+ public PortletDescription getPortletDescription(Portlet portlet, List<String>
locales)
+ {
+ throw new UnsupportedOperationException();
+ }
+
public Registration getRegistrationOrFailIfInvalid(RegistrationContext
registrationContext) throws InvalidRegistration, OperationFailed
{
return null; //To change body of implemented methods use File | Settings | File
Templates.
}
+
}
}
Modified:
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java 2011-04-14
10:20:53 UTC (rev 6215)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java 2011-04-14
11:11:52 UTC (rev 6216)
@@ -65,6 +65,7 @@
import org.oasis.wsrp.v2.SessionContext;
import org.oasis.wsrp.v2.SessionParams;
import org.oasis.wsrp.v2.StateChange;
+import org.oasis.wsrp.v2.UnsupportedLocale;
import org.oasis.wsrp.v2.UnsupportedMode;
import org.oasis.wsrp.v2.UpdateResponse;
@@ -249,7 +250,6 @@
}
// fix-me: add more tests
-
@Test
public void testGetMarkupSession() throws Exception
{
@@ -436,10 +436,9 @@
try
{
producer.getMarkup(getMarkup);
- //fail("Should have thrown an UnsupportetLocaleFault"); // ideally cf
http://jira.jboss.com/jira/browse/JBPORTAL-857
- ExtendedAssert.fail("Should have thrown an exception"); // right now
+ ExtendedAssert.fail("Should have thrown an exception");
}
- catch (Exception expected)
+ catch (UnsupportedLocale expected)
{
// expected
}
@@ -468,7 +467,7 @@
producer.usingStrictModeChangedTo(false);
// markup should be properly generated
- checkMarkupResponse(producer.getMarkup(getMarkup), "English (United
States)");
+ checkMarkupResponse(producer.getMarkup(getMarkup), Locale.US.getDisplayName());
undeploy(getLocalesPortletArchive);
}
@@ -503,6 +502,7 @@
try
{
List<String> locales = getMarkup.getMarkupParams().getLocales();
+ locales.clear();
locales.add("en");
locales.add("fr");
MarkupResponse response = producer.getMarkup(getMarkup);
@@ -663,12 +663,6 @@
}
}
- private NamedString createNamedString(String name, String value)
- {
- NamedString namedString = WSRPTypeFactory.createNamedString(name, value);
- return namedString;
- }
-
@Test
public void testGetMarkupWithResource() throws Exception
{
@@ -1113,6 +1107,12 @@
return markupContext;
}
+ private NamedString createNamedString(String name, String value)
+ {
+ NamedString namedString = WSRPTypeFactory.createNamedString(name, value);
+ return namedString;
+ }
+
protected String getMostUsedPortletWARFileName()
{
return DEFAULT_MARKUP_PORTLET_WAR;