Author: chris.laprun(a)jboss.com
Date: 2008-03-27 10:33:09 -0400 (Thu, 27 Mar 2008)
New Revision: 10392
Modified:
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/RegistrationUtils.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/consumer/ProducerSessionInformationTestCase.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/handler/RequestHeaderClientHandlerTestCase.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPConstants.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/handler/RequestHeaderClientHandler.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/resources/portal-wsrp-sar/META-INF/jboss-service.xml
Log:
- Multiple cookies were not properly escaped (used ';' instead of ',').
- WSRPConstants.DEFAULT_LOCALES now uses the default locale instead of hardcoding en-US.
- JBPORTAL-1963: Added support for multiple Set-Cookie headers. Needs more testing.
- JBPORTAL-1964: Added strict mode on producer configuration. Need to work on GUI and
consumer configuration.
Modified:
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/RegistrationUtils.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/RegistrationUtils.java 2008-03-27
10:49:24 UTC (rev 10391)
+++
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/RegistrationUtils.java 2008-03-27
14:33:09 UTC (rev 10392)
@@ -23,6 +23,7 @@
package org.jboss.portal.registration;
+import org.jboss.logging.Logger;
import org.jboss.portal.common.util.ParameterValidation;
/**
@@ -32,6 +33,15 @@
*/
public class RegistrationUtils
{
+ private static boolean strict = true;
+ private static Logger log = Logger.getLogger(RegistrationUtils.class);
+
+ public static void setStrict(boolean strict)
+ {
+ RegistrationUtils.strict = strict;
+ log.debug("Using " + (strict ? "strict" : "lenient")
+ " Consumer Agent validation mode.");
+ }
+
/**
* @param consumerAgent
* @throws IllegalArgumentException
@@ -52,6 +62,15 @@
return;
}
}
- throw new IllegalArgumentException("'" + consumerAgent + "'
is not a valid Consumer Agent.");
+
+ String msg = "'" + consumerAgent + "' is not a valid
Consumer Agent. Please notify your Consumer provider that it is not
WSRP-compliant.";
+ if (strict)
+ {
+ throw new IllegalArgumentException(msg);
+ }
+ else
+ {
+ log.debug(msg);
+ }
}
}
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/consumer/ProducerSessionInformationTestCase.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/consumer/ProducerSessionInformationTestCase.java 2008-03-27
10:49:24 UTC (rev 10391)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/consumer/ProducerSessionInformationTestCase.java 2008-03-27
14:33:09 UTC (rev 10392)
@@ -59,7 +59,7 @@
cookies = new Cookie[]{createCookie("name1", "value1", 1),
createCookie("name2", "value2", 3)};
info.setUserCookie(cookies);
- assertEquals("name1=value1;name2=value2", info.getUserCookie());
+ assertEquals("name1=value1,name2=value2", info.getUserCookie());
Thread.sleep(1000);
assertEquals("name2=value2", info.getUserCookie());
@@ -93,7 +93,7 @@
info.setGroupCookieFor(groupId, new Cookie[]{createCookie("name1",
"value1", 1),
createCookie("name2", "value2",
WSRPConstants.SESSION_NEVER_EXPIRES)});
- assertEquals("name1=value1;name2=value2",
info.getGroupCookieFor(groupId));
+ assertEquals("name1=value1,name2=value2",
info.getGroupCookieFor(groupId));
Thread.sleep(1000);
assertEquals("name2=value2", info.getGroupCookieFor(groupId));
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/handler/RequestHeaderClientHandlerTestCase.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/handler/RequestHeaderClientHandlerTestCase.java 2008-03-27
10:49:24 UTC (rev 10391)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/handler/RequestHeaderClientHandlerTestCase.java 2008-03-27
14:33:09 UTC (rev 10392)
@@ -116,7 +116,7 @@
MimeHeaders headers = message.getMimeHeaders();
String[] cookie = headers.getHeader("Cookie");
assertEquals(1, cookie.length);
- assertEquals("name=value;usercookie=uservalue", cookie[0]);
+ assertEquals("name=value,usercookie=uservalue", cookie[0]);
}
public void testCookieWithoutInitHandleResponse()
@@ -134,6 +134,21 @@
assertFalse(info.isPerGroupCookies());
}
+ public void testMultipleCookiesInResponse()
+ {
+ MockSOAPMessage message = new MockSOAPMessage();
+ SOAPMessageContext msgContext =
MockSOAPMessageContext.createMessageContext(message, getClass().getClassLoader());
+ MimeHeaders headers = new MimeHeaders();
+ headers.addHeader("Set-Cookie", "name1=value1");
+ headers.addHeader("Set-Cookie", "name2=value2");
+ headers.addHeader("Set-Cookie", "name3=value3");
+ message.setMimeHeaders(headers);
+
+ handler.handleResponse(msgContext);
+ ProducerSessionInformation info =
RequestHeaderClientHandler.getCurrentProducerSessionInformation();
+ assertEquals("name1=value1,name2=value2,name3=value3",
info.getUserCookie());
+ }
+
public void testCurrentInfo()
{
assertNull(RequestHeaderClientHandler.getCurrentProducerSessionInformation());
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPConstants.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPConstants.java 2008-03-27
10:49:24 UTC (rev 10391)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPConstants.java 2008-03-27
14:33:09 UTC (rev 10392)
@@ -28,6 +28,7 @@
import javax.xml.namespace.QName;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.util.Locale;
import java.util.Random;
/**
@@ -116,8 +117,16 @@
/** Default character set used to generate markup. */
public static final String DEFAULT_CHARACTER_SET = "UTF-8";
+
/** Default locales. */
- public static final String[] DEFAULT_LOCALES = new String[]{"en-US",
"en"};
+ public static final String[] DEFAULT_LOCALES;
+
+ static
+ {
+ String defaultLocale = WSRPUtils.toString(Locale.getDefault());
+ DEFAULT_LOCALES = new String[]{defaultLocale, "en"};
+ }
+
/** Default MIME types. */
public static final String[] DEFAULT_MIME_TYPES = new
String[]{"text/html"};
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java 2008-03-27
10:49:24 UTC (rev 10391)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java 2008-03-27
14:33:09 UTC (rev 10392)
@@ -340,13 +340,14 @@
{
if (cookies != null && cookies.length != 0)
{
- StringBuffer sb = new StringBuffer(64);
- for (int i = 0; i < cookies.length; i++)
+ int cookieNumber = cookies.length;
+ StringBuffer sb = new StringBuffer(128 * cookieNumber);
+ for (int i = 0; i < cookieNumber; i++)
{
sb.append(cookies[i].toExternalForm());
- if (i != cookies.length - 1)
+ if (i != cookieNumber - 1)
{
- sb.append(";");
+ sb.append(","); // multiple cookies are separated by commas:
http://www.ietf.org/rfc/rfc2109.txt, 4.2.2
}
}
return sb.toString();
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/handler/RequestHeaderClientHandler.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/handler/RequestHeaderClientHandler.java 2008-03-27
10:49:24 UTC (rev 10391)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/handler/RequestHeaderClientHandler.java 2008-03-27
14:33:09 UTC (rev 10392)
@@ -48,6 +48,7 @@
{
private static final ThreadLocal local = new ThreadLocal();
private static final RFC2109Spec cookieParser = new RFC2109Spec();
+ private static final Logger log = Logger.getLogger(RequestHeaderClientHandler.class);
public QName[] getHeaders()
{
@@ -91,7 +92,7 @@
{
if (cookie.length() != 0)
{
- cookie.append(";");
+ cookie.append(','); // multiple cookies are separated by commas:
http://www.ietf.org/rfc/rfc2109.txt, 4.2.2
}
cookie.append(userCookie);
}
@@ -113,20 +114,10 @@
if (cookieValues != null)
{
- if (cookieValues.length > 1)
- {
- StringBuffer sb = new StringBuffer(128);
- sb.append("Cookie headers:\n");
- for (int i = 0; i < cookieValues.length; i++)
- {
-
sb.append("\t").append(i).append(":\t").append(cookieValues[i]).append("\n");
+ String cookieValue = coalesceCookies(cookieValues);
- }
- throw new IllegalArgumentException("Too many cookie headers!\n" +
sb.toString());
- }
+ Cookie[] cookies =
extractCookies((String)msgContext.getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY),
cookieValue);
- Cookie[] cookies =
extractCookies((String)msgContext.getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY),
cookieValues);
-
CurrentInfo info = getCurrentInfo(true);
ProducerSessionInformation sessionInfo = info.sessionInfo;
@@ -148,8 +139,53 @@
return super.handleResponse(msgContext);
}
- private Cookie[] extractCookies(String endpointAddress, String[] cookieValues)
+ /**
+ * Coalesce several Set-Cookie headers into one and returning the resulting
concatenated String.
+ *
+ * @param cookieValues the array containing the values of the different Set-Cookie
headers to be coalesced
+ * @return the concatenated value that could be used as one Set-Cookie header
+ */
+ private String coalesceCookies(String[] cookieValues)
{
+ assert cookieValues != null;
+
+ StringBuffer logBuffer = null;
+ if (log.isDebugEnabled())
+ {
+ logBuffer = new StringBuffer(128);
+ logBuffer.append("Cookie headers:\n");
+ }
+
+ int cookieNumber = cookieValues.length;
+ StringBuffer cookieBuffer = new StringBuffer(cookieNumber * 128);
+ String cookieValue;
+ for (int i = 0; i < cookieNumber; i++)
+ {
+ cookieValue = cookieValues[i];
+ cookieBuffer.append(cookieValue);
+
+ // multiple cookies are separated by commas:
http://www.ietf.org/rfc/rfc2109.txt, 4.2.2
+ if (i < cookieNumber - 1)
+ {
+ cookieBuffer.append(',');
+ }
+
+ if (log.isDebugEnabled())
+ {
+
logBuffer.append("\t").append(i).append(":\t").append(cookieValue).append("\n");
+ }
+ }
+
+ if (log.isDebugEnabled())
+ {
+ log.debug(logBuffer.toString());
+ }
+
+ return cookieBuffer.toString();
+ }
+
+ private Cookie[] extractCookies(String endpointAddress, String cookieValue)
+ {
if (endpointAddress == null)
{
throw new NullPointerException("Was expecting an endpoint address but none
was provided in the MessageContext");
@@ -166,7 +202,6 @@
throw new IllegalArgumentException(endpointAddress + " is not a valid URL
for the endpoint address.");
}
- String cookie = cookieValues[0];
Cookie[] cookies;
try
{
@@ -179,16 +214,16 @@
String path = hostURL.getPath();
boolean secure = hostURL.getProtocol().endsWith("s"); // todo: is that
correct?
- cookies = cookieParser.parse(host, port, path, secure, cookie);
+ cookies = cookieParser.parse(host, port, path, secure, cookieValue);
- for (int i = 0; i < cookies.length; i++)
+ for (Cookie cookie : cookies)
{
- cookieParser.validate(host, port, path, secure, cookies[i]);
+ cookieParser.validate(host, port, path, secure, cookie);
}
}
catch (MalformedCookieException e)
{
- throw new IllegalArgumentException("Malformed cookie: " + cookie);
+ throw new IllegalArgumentException("Malformed cookie: " +
cookieValue);
}
return cookies;
}
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java 2008-03-27
10:49:24 UTC (rev 10391)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java 2008-03-27
14:33:09 UTC (rev 10392)
@@ -33,6 +33,7 @@
import org.jboss.portal.registration.Registration;
import org.jboss.portal.registration.RegistrationLocal;
import org.jboss.portal.registration.RegistrationManager;
+import org.jboss.portal.registration.RegistrationUtils;
import org.jboss.portal.wsrp.ResponseDebugFactory;
import org.jboss.portal.wsrp.WSRPExceptionFactory;
import org.jboss.portal.wsrp.WSRPProducer;
@@ -92,7 +93,7 @@
public class WSRPProducerImpl extends AbstractJBossService implements WSRPProducer
{
/** logger used for logging ;) */
- private final Logger log = Logger.getLogger(getClass());
+ private static final Logger log = Logger.getLogger(WSRPProducerImpl.class);
/** The invoker used to retrieve portlet information and invoke methods. */
private PortletInvoker invoker;
@@ -267,6 +268,11 @@
return configurationService;
}
+ public void setUseStrictMode(boolean strict)
+ {
+ RegistrationUtils.setStrict(strict);
+ }
+
protected void startService() throws Exception
{
super.startService();
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/resources/portal-wsrp-sar/META-INF/jboss-service.xml
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/resources/portal-wsrp-sar/META-INF/jboss-service.xml 2008-03-27
10:49:24 UTC (rev 10391)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/resources/portal-wsrp-sar/META-INF/jboss-service.xml 2008-03-27
14:33:09 UTC (rev 10392)
@@ -38,6 +38,8 @@
<depends optional-attribute-name="ProducerConfigurationService"
proxy-type="attribute">
portal.wsrp:service=ProducerConfiguration
</depends>
+ <attribute name="UseStrictMode">true</attribute>
+ <!-- Set to false to switch to lenient mode -->
</mbean>
<!-- Registration manager -->
@@ -76,10 +78,12 @@
<attribute name="DTDMapping">
<properties>
<entry
- key="-//JBoss Portal//DTD WSRP Remote Producer Configuration
2.6//EN">dtd/jboss-wsrp-consumer_2_6.dtd
+ key="-//JBoss Portal//DTD WSRP Remote Producer Configuration
2.6//EN">
+ dtd/jboss-wsrp-consumer_2_6.dtd
</entry>
<entry
- key="-//JBoss Portal//DTD WSRP Local Producer Configuration
2.6//EN">dtd/jboss-wsrp-producer_2_6.dtd
+ key="-//JBoss Portal//DTD WSRP Local Producer Configuration
2.6//EN">
+ dtd/jboss-wsrp-producer_2_6.dtd
</entry>
<entry
key="urn:jboss:portal:wsrp:consumer:v2_6">/xsd/jboss-wsrp-consumer_2_6.xsd</entry>
<entry
key="urn:jboss:portal:wsrp:producer:v2_6">/xsd/jboss-wsrp-consumer_2_6.xsd</entry>
@@ -107,8 +111,8 @@
<xmbean/>
<depends>jboss.jca:service=DataSourceBinding,name=@portal.datasource.name@</depends>
<!-- Uncomment in clustered mode : hibernate depends on its tree cache service
@portal.single.xml.close@
- <depends>portal:service=TreeCacheProvider,type=hibernate</depends>
- @portal.single.xml.open@ -->
+ <depends>portal:service=TreeCacheProvider,type=hibernate</depends>
+ @portal.single.xml.open@ -->
<attribute name="DoChecking">true</attribute>
<attribute
name="ConfigLocation">conf/hibernate/consumer/hibernate.cfg.xml</attribute>
<attribute
name="JNDIName">java:/portal/WSRPConsumerSessionFactory</attribute>