Author: alessio.soldano(a)jboss.com
Date: 2012-09-17 07:15:30 -0400 (Mon, 17 Sep 2012)
New Revision: 16732
Modified:
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/samples/handlerchain/ClientMimeHandler.java
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/samples/handlerchain/HandlerChainTestCase.java
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/samples/handlerchain/ServerMimeHandler.java
Log:
[JBWS-3547] Fix cookies handling in HandlerChainTestCase
Modified:
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/samples/handlerchain/ClientMimeHandler.java
===================================================================
---
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/samples/handlerchain/ClientMimeHandler.java 2012-09-14
16:18:22 UTC (rev 16731)
+++
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/samples/handlerchain/ClientMimeHandler.java 2012-09-17
11:15:30 UTC (rev 16732)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
@@ -21,7 +21,10 @@
*/
package org.jboss.test.ws.jaxws.samples.handlerchain;
-import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPMessage;
@@ -35,6 +38,7 @@
* A client side handler
*
* @author Thomas.Diesler(a)jboss.org
+ * @author alessio.soldano(a)jboss.com
* @since 08-Oct-2005
*/
public class ClientMimeHandler extends GenericSOAPHandler
@@ -48,9 +52,15 @@
{
log.info("handleOutbound");
+ // legacy JBossWS-Native approach
SOAPMessage soapMessage = ((SOAPMessageContext)msgContext).getMessage();
MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
mimeHeaders.setHeader("Cookie", "client-cookie=true");
+
+ // proper approach through MessageContext.HTTP_REQUEST_HEADERS
+ Map<String, List<String>> httpHeaders = new HashMap<String,
List<String>>();
+ httpHeaders.put("Cookie",
Collections.singletonList("client-cookie=true"));
+ msgContext.put(MessageContext.HTTP_REQUEST_HEADERS, httpHeaders);
inboundCookie = null;
@@ -61,9 +71,21 @@
{
log.info("handleInbound");
+ //legacy JBossWS-Native approach
SOAPMessage soapMessage = ((SOAPMessageContext)msgContext).getMessage();
MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
String[] cookies = mimeHeaders.getHeader("Set-Cookie");
+
+ // proper approach through MessageContext.HTTP_RESPONSE_HEADERS
+ if (cookies == null) {
+ @SuppressWarnings("unchecked")
+ Map<String, List<String>> httpHeaders = (Map<String,
List<String>>) msgContext.get(MessageContext.HTTP_RESPONSE_HEADERS);
+ List<String> l = httpHeaders.get("Set-Cookie");
+ if (l != null && !l.isEmpty()) {
+ cookies = l.toArray(new String[l.size()]);
+ }
+ }
+
if (cookies != null && cookies.length == 1)
inboundCookie = cookies[0];
Modified:
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/samples/handlerchain/HandlerChainTestCase.java
===================================================================
---
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/samples/handlerchain/HandlerChainTestCase.java 2012-09-14
16:18:22 UTC (rev 16731)
+++
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/samples/handlerchain/HandlerChainTestCase.java 2012-09-17
11:15:30 UTC (rev 16732)
@@ -88,12 +88,6 @@
private void assertCookies() throws Exception
{
- if (isIntegrationCXF())
- {
- System.out.println("FIXME: [CXF-1507] CXF client handler cannot set mime
header");
- return;
- }
-
assertEquals("server-cookie=true", ClientMimeHandler.inboundCookie);
}
}
Modified:
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/samples/handlerchain/ServerMimeHandler.java
===================================================================
---
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/samples/handlerchain/ServerMimeHandler.java 2012-09-14
16:18:22 UTC (rev 16731)
+++
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/samples/handlerchain/ServerMimeHandler.java 2012-09-17
11:15:30 UTC (rev 16732)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
@@ -21,6 +21,11 @@
*/
package org.jboss.test.ws.jaxws.samples.handlerchain;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.MessageContext;
@@ -33,6 +38,7 @@
* A server side handler
*
* @author Thomas.Diesler(a)jboss.org
+ * @author alessio.soldano(a)jboss.com
* @since 08-Oct-2005
*/
public class ServerMimeHandler extends GenericSOAPHandler
@@ -46,9 +52,21 @@
{
log.info("handleInbound");
+ // legacy JBossWS-Native approach...
SOAPMessage soapMessage = ((SOAPMessageContext)msgContext).getMessage();
MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
String[] cookies = mimeHeaders.getHeader("Cookie");
+
+ // proper approach through MessageContext.HTTP_REQUEST_HEADERS
+ if (cookies == null) {
+ @SuppressWarnings("unchecked")
+ Map<String, List<String>> httpHeaders = (Map<String,
List<String>>) msgContext.get(MessageContext.HTTP_REQUEST_HEADERS);
+ List<String> l = httpHeaders.get("Cookie");
+ if (l != null && !l.isEmpty()) {
+ cookies = l.toArray(new String[l.size()]);
+ }
+ }
+
if (cookies != null && cookies.length == 1 &&
cookies[0].equals("client-cookie=true"))
setCookieOnResponse = true;
@@ -62,9 +80,16 @@
if (setCookieOnResponse)
{
+ // legacy JBossWS-Native approach
SOAPMessage soapMessage = ((SOAPMessageContext)msgContext).getMessage();
MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
mimeHeaders.setHeader("Set-Cookie", "server-cookie=true");
+
+ // proper approach through MessageContext.HTTP_REQUEST_HEADERS
+ Map<String, List<String>> httpHeaders = new HashMap<String,
List<String>>();
+ httpHeaders.put("Set-Cookie",
Collections.singletonList("server-cookie=true"));
+ msgContext.put(MessageContext.HTTP_REQUEST_HEADERS, httpHeaders);
+
setCookieOnResponse = false;
}