Author: chris.laprun(a)jboss.com
Date: 2010-08-23 15:37:25 -0400 (Mon, 23 Aug 2010)
New Revision: 3891
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessor.java
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java
Log:
- GTNWSRP-59: for now, assume that if we've got char content, it needs to be
rewritten. Cleaned-up WSRPResourceURL and adapted test cases.
Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java
===================================================================
---
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java 2010-08-23
13:07:47 UTC (rev 3890)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java 2010-08-23
19:37:25 UTC (rev 3891)
@@ -24,7 +24,6 @@
package org.gatein.wsrp;
import org.gatein.common.net.URLTools;
-import org.gatein.common.net.media.MediaType;
import org.gatein.pc.api.Mode;
import org.gatein.pc.api.ResourceURL;
import org.gatein.pc.api.StateString;
@@ -56,23 +55,7 @@
private URL resourceURL;
private boolean preferOperation = false;
- private static final Map<String, MediaType> SUPPORTED_RESOURCE_TYPES = new
HashMap<String, MediaType>(11);
- static
- {
- SUPPORTED_RESOURCE_TYPES.put("html", MediaType.TEXT_HTML);
- SUPPORTED_RESOURCE_TYPES.put("htm", MediaType.TEXT_HTML);
- SUPPORTED_RESOURCE_TYPES.put("css", MediaType.TEXT_CSS);
- SUPPORTED_RESOURCE_TYPES.put("js", MediaType.TEXT_JAVASCRIPT);
- SUPPORTED_RESOURCE_TYPES.put("png",
MediaType.create("image/png"));
- MediaType jpeg = MediaType.create("image/jpeg");
- SUPPORTED_RESOURCE_TYPES.put("jpg", jpeg);
- SUPPORTED_RESOURCE_TYPES.put("jpeg", jpeg);
- SUPPORTED_RESOURCE_TYPES.put("gif",
MediaType.create("image/gif"));
- SUPPORTED_RESOURCE_TYPES.put("pdf",
MediaType.create("application/pdf"));
- SUPPORTED_RESOURCE_TYPES.put("txt",
MediaType.create("text/plain"));
- }
-
public WSRPResourceURL()
{
}
@@ -141,14 +124,6 @@
{
url = URLTools.decodeXWWWFormURL(url);
this.resourceURL = new URL(url);
- String extension = URLTools.getFileExtensionOrNullFrom(resourceURL);
- MediaType mediaType = SUPPORTED_RESOURCE_TYPES.get(extension);
- if (mediaType == null)
- {
- log.debug("Couldn't determine (based on extension) MIME type of
file: " + resourceURL.getPath()
- + "\nRetrieving the associated resource will probably
fail.");
- }
-
params.remove(WSRPRewritingConstants.RESOURCE_URL);
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessor.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessor.java 2010-08-23
13:07:47 UTC (rev 3890)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessor.java 2010-08-23
19:37:25 UTC (rev 3891)
@@ -69,10 +69,12 @@
String itemString = null;
byte[] itemBinary = null;
String contentType = content.getContentType();
+ Boolean requiresRewriting = Boolean.FALSE;
switch (content.getType())
{
case ContentResponse.TYPE_CHARS:
itemString = processFragmentString(content.getChars());
+ requiresRewriting = Boolean.TRUE; // assume that if we got chars, we'll
need to rewrite content
break;
case ContentResponse.TYPE_BYTES:
itemBinary = content.getBytes(); // fix-me: might need to convert to Base64?
@@ -87,8 +89,7 @@
mimeResponse.setLocale(markupRequest.getLocale());
- //TODO: figure out requiresRewriting and useCachedItem
- Boolean requiresRewriting = true;
+ //TODO: figure out useCachedItem
Boolean useCachedItem = false;
mimeResponse.setRequiresRewriting(requiresRewriting);
mimeResponse.setUseCachedItem(useCachedItem);
Modified:
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java 2010-08-23
13:07:47 UTC (rev 3890)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java 2010-08-23
19:37:25 UTC (rev 3891)
@@ -1,35 +1,36 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2010, Red Hat Middleware, LLC, 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. *
- ******************************************************************************/
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, 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.gatein.wsrp.protocol.v1;
+import org.gatein.common.util.ParameterValidation;
import org.gatein.wsrp.WSRPActionURL;
import org.gatein.wsrp.WSRPConstants;
import org.gatein.wsrp.WSRPPortletURL;
import org.gatein.wsrp.WSRPRenderURL;
import org.gatein.wsrp.producer.WSRPProducerBaseTest;
+import org.gatein.wsrp.servlet.ServletAccess;
import org.gatein.wsrp.spec.v1.WSRP1TypeFactory;
-import org.gatein.wsrp.servlet.ServletAccess;
import org.gatein.wsrp.test.ExtendedAssert;
import org.gatein.wsrp.test.support.MockHttpServletRequest;
import org.gatein.wsrp.test.support.MockHttpServletResponse;
@@ -100,7 +101,7 @@
//hack to get around having to have a httpservletrequest when accessing the
producer services
//I don't know why its really needed, seems to be a dependency where wsrp
connects with the pc module
ServletAccess.setRequestAndResponse(MockHttpServletRequest.createMockRequest(null),
MockHttpServletResponse
- .createMockResponse());
+ .createMockResponse());
}
}
@@ -663,7 +664,7 @@
String localhostMarkup = markupStart + "localhost" + markupEnd;
String homeIPMarkup = markupStart + "127.0.0.1" + markupEnd;
boolean result = localhostMarkup.equals(markupString) ||
homeIPMarkup.equals(markupString);
- ExtendedAssert.assertTrue("Expectd '" + localhostMarkup +
"' or '" + homeIPMarkup + "' but received '" +
markupString + "'." , result);
+ ExtendedAssert.assertTrue("Expectd '" + localhostMarkup +
"' or '" + homeIPMarkup + "' but received '" +
markupString + "'.", result);
}
finally
{
@@ -841,7 +842,14 @@
ExtendedAssert.assertNotNull(markupContext);
ExtendedAssert.assertEquals("text/html", markupContext.getMimeType());
ExtendedAssert.assertEquals("title", markupContext.getPreferredTitle());
- ExtendedAssert.assertTrue(markupContext.isRequiresUrlRewriting());
+ if (!ParameterValidation.isNullOrEmpty(markupString))
+ {
+ ExtendedAssert.assertTrue(markupContext.isRequiresUrlRewriting());
+ }
+ else
+ {
+ ExtendedAssert.assertFalse(markupContext.isRequiresUrlRewriting());
+ }
ExtendedAssert.assertEquals(markupString, markupContext.getMarkupString());
// Session context
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 2010-08-23
13:07:47 UTC (rev 3890)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java 2010-08-23
19:37:25 UTC (rev 3891)
@@ -1,33 +1,28 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2010, Red Hat Middleware, LLC, 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. *
- ******************************************************************************/
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, 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.gatein.wsrp.protocol.v2;
-import java.rmi.RemoteException;
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
-
-import org.gatein.pc.api.ParametersStateString;
+import org.gatein.common.util.ParameterValidation;
import org.gatein.pc.api.StateString;
import org.gatein.wsrp.WSRPActionURL;
import org.gatein.wsrp.WSRPConstants;
@@ -67,18 +62,22 @@
import org.oasis.wsrp.v2.UnsupportedMode;
import org.oasis.wsrp.v2.UpdateResponse;
+import java.rmi.RemoteException;
+import java.util.List;
+import java.util.Locale;
+
/**
* @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
* @version $Revision$
*/
-(a)RunWith(Arquillian.class)
+(a)RunWith(Arquillian.class)
public class MarkupTestCase extends org.gatein.wsrp.protocol.v2.NeedPortletHandleTest
{
private static final String DEFAULT_VIEW_MARKUP = "<p>symbol unset stock
value: value unset</p>";
private static final String DEFAULT_MARKUP_PORTLET_WAR =
"test-markup-portlet.war";
public MarkupTestCase()
- throws Exception
+ throws Exception
{
super("MarkupTestCase", DEFAULT_MARKUP_PORTLET_WAR);
}
@@ -102,7 +101,7 @@
//hack to get around having to have a httpservletrequest when accessing the
producer services
//I don't know why its really needed, seems to be a dependency where wsrp
connects with the pc module
ServletAccess.setRequestAndResponse(MockHttpServletRequest.createMockRequest(null),
MockHttpServletResponse
- .createMockResponse());
+ .createMockResponse());
}
}
@@ -171,8 +170,8 @@
MarkupResponse response = producer.getMarkup(getMarkup);
checkMarkupResponse(response, "<form method='post'
action='wsrp_rewrite?wsrp-urlType=blockingAction&wsrp" +
- "-interactionState=JBPNS_/wsrp_rewrite'
id='wsrp_rewrite_portfolioManager'><table><tr><td>Stock
symbol</t" +
- "d><td><input
name='symbol'/></td></tr><tr><td><input
type='submit'
value='Submit'></td></tr></table></form>");
+ "-interactionState=JBPNS_/wsrp_rewrite'
id='wsrp_rewrite_portfolioManager'><table><tr><td>Stock
symbol</t" +
+ "d><td><input
name='symbol'/></td></tr><tr><td><input
type='submit'
value='Submit'></td></tr></table></form>");
}
@Test
@@ -528,7 +527,7 @@
MarkupResponse response = producer.getMarkup(getMarkup);
checkMarkupResponse(response,
"wsrp_rewrite?wsrp-urlType=blockingAction&wsrp-interactionState=JBPNS_/wsrp_rewrite\n"
+
-
"wsrp_rewrite?wsrp-urlType=render&wsrp-navigationalState=JBPNS_/wsrp_rewrite");
+
"wsrp_rewrite?wsrp-urlType=render&wsrp-navigationalState=JBPNS_/wsrp_rewrite");
}
finally
{
@@ -672,7 +671,7 @@
String localhostMarkup = markupStart + "localhost" + markupEnd;
String homeIPMarkup = markupStart + "127.0.0.1" + markupEnd;
boolean result = localhostMarkup.equals(markupString) ||
homeIPMarkup.equals(markupString);
- ExtendedAssert.assertTrue("Expectd '" + localhostMarkup +
"' or '" + homeIPMarkup + "' but received '" +
markupString + "'." , result);
+ ExtendedAssert.assertTrue("Expectd '" + localhostMarkup +
"' or '" + homeIPMarkup + "' but received '" +
markupString + "'.", result);
}
finally
{
@@ -850,7 +849,14 @@
ExtendedAssert.assertNotNull(markupContext);
ExtendedAssert.assertEquals("text/html", markupContext.getMimeType());
ExtendedAssert.assertEquals("title", markupContext.getPreferredTitle());
- ExtendedAssert.assertTrue(markupContext.isRequiresRewriting());
+ if (!ParameterValidation.isNullOrEmpty(markupString))
+ {
+ ExtendedAssert.assertTrue(markupContext.isRequiresRewriting());
+ }
+ else
+ {
+ ExtendedAssert.assertFalse(markupContext.isRequiresRewriting());
+ }
ExtendedAssert.assertEquals(markupString, markupContext.getItemString());
// Session context