Author: chris.laprun(a)jboss.com
Date: 2010-11-25 09:26:46 -0500 (Thu, 25 Nov 2010)
New Revision: 5271
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/DirectResourceServingHandler.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/handler/RequestHeaderClientHandler.java
Log:
- GTNWSRP-171: Properly send cookies when retrieving a resource directly. Thanks, Matt!
- Added RequestHeaderClientHandler.createCookie method to avoid code duplication.
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/DirectResourceServingHandler.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/DirectResourceServingHandler.java 2010-11-25
12:25:10 UTC (rev 5270)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/DirectResourceServingHandler.java 2010-11-25
14:26:46 UTC (rev 5271)
@@ -34,6 +34,7 @@
import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.consumer.WSRPConsumerImpl;
import org.gatein.wsrp.handler.CookieUtil;
+import org.gatein.wsrp.handler.RequestHeaderClientHandler;
import org.oasis.wsrp.v2.GetResource;
import org.oasis.wsrp.v2.ResourceContext;
import org.oasis.wsrp.v2.ResourceResponse;
@@ -63,6 +64,18 @@
URL url = new URL(resourceURL);
URLConnection urlConnection = url.openConnection();
+
+ ProducerSessionInformation sessionInfo =
RequestHeaderClientHandler.getCurrentProducerSessionInformation();
+ if (sessionInfo != null)
+ {
+ String cookie = RequestHeaderClientHandler.createCookie(sessionInfo);
+
+ if (cookie.length() != 0)
+ {
+ urlConnection.addRequestProperty(CookieUtil.COOKIE, cookie);
+ }
+ }
+
String contentType = urlConnection.getContentType();
// init ResponseProperties for ContentResponse result
@@ -105,7 +118,7 @@
ResourceContext resourceContext;
MediaType type = MediaType.create(contentType);
-
+
//TODO: handle this better, we should probably have a class in the common module to
determine if the MediaType should be treated as a text
// file or as binary content. We also need to implement the algorithm to determine
the character encoding.
if (TypeDef.TEXT.equals(type.getType()) ||
(TypeDef.APPLICATION.equals(type.getType()) &&
(type.getSubtype().getName().contains("javascript"))))
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/handler/RequestHeaderClientHandler.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/handler/RequestHeaderClientHandler.java 2010-11-25
12:25:10 UTC (rev 5270)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/handler/RequestHeaderClientHandler.java 2010-11-25
14:26:46 UTC (rev 5271)
@@ -47,6 +47,7 @@
public class RequestHeaderClientHandler implements SOAPHandler<SOAPMessageContext>
{
private static final ThreadLocal<CurrentInfo> local = new
ThreadLocal<CurrentInfo>();
+ private static final String EMPTY = "";
public Set<QName> getHeaders()
{
@@ -92,7 +93,33 @@
SOAPMessage message = msgContext.getMessage();
MimeHeaders mimeHeaders = message.getMimeHeaders();
- StringBuffer cookie = new StringBuffer(64);
+
+ String cookie = createCookie(info, sessionInfo);
+
+ if (cookie.length() != 0)
+ {
+ mimeHeaders.setHeader(CookieUtil.COOKIE, cookie);
+ }
+
+ return true;
+ }
+
+ public static String createCookie(ProducerSessionInformation sessionInformation)
+ {
+ CurrentInfo currentInfo = getCurrentInfo(false);
+ if (currentInfo != null)
+ {
+ return createCookie(currentInfo, sessionInformation);
+ }
+ else
+ {
+ return EMPTY;
+ }
+ }
+
+ private static String createCookie(CurrentInfo info, ProducerSessionInformation
sessionInfo)
+ {
+ StringBuilder cookie = new StringBuilder(128);
if (sessionInfo.isPerGroupCookies())
{
if (info.groupId == null)
@@ -116,13 +143,7 @@
}
cookie.append(userCookie);
}
-
- if (cookie.length() != 0)
- {
- mimeHeaders.setHeader(CookieUtil.COOKIE, cookie.toString());
- }
-
- return true;
+ return cookie.toString();
}
public boolean handleResponse(MessageContext msgContext)
Show replies by date