[jbossws-commits] JBossWS SVN: r2700 - in branches/jbossws-1.2.1: jbossws-core/src/java/org/jboss/ws/core/server and 3 other directories.
jbossws-commits at lists.jboss.org
jbossws-commits at lists.jboss.org
Wed Mar 28 05:17:06 EDT 2007
Author: thomas.diesler at jboss.com
Date: 2007-03-28 05:17:06 -0400 (Wed, 28 Mar 2007)
New Revision: 2700
Added:
branches/jbossws-1.2.1/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/handlerchain/MimeHeaderHandler.java
Modified:
branches/jbossws-1.2.1/jbossws-core/src/java/javax/xml/soap/MimeHeaders.java
branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/server/AbstractServiceEndpointServlet.java
branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/server/EndpointContext.java
branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/server/ServiceEndpointManager.java
branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPMessageUnMarshaller.java
branches/jbossws-1.2.1/jbossws-tests/src/java/org/jboss/test/ws/jaxrpc/samples/handler/ClientSideHandler.java
branches/jbossws-1.2.1/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/handlerchain/HandlerChainTestCase.java
Log:
[JBWS-1515] Regression: Set-Cookie MIME headers not available anymore
Modified: branches/jbossws-1.2.1/jbossws-core/src/java/javax/xml/soap/MimeHeaders.java
===================================================================
--- branches/jbossws-1.2.1/jbossws-core/src/java/javax/xml/soap/MimeHeaders.java 2007-03-28 03:56:44 UTC (rev 2699)
+++ branches/jbossws-1.2.1/jbossws-core/src/java/javax/xml/soap/MimeHeaders.java 2007-03-28 09:17:06 UTC (rev 2700)
@@ -21,6 +21,8 @@
*/
package javax.xml.soap;
+// $Id$
+
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
@@ -32,42 +34,47 @@
* This class is used primarily when an application wants to retrieve specific
* attachments based on certain MIME headers and values. This class will most
* likely be used by implementations of AttachmentPart and other MIME dependent
- * parts of the SAAJ API.
-
+ * parts of the SAAJ API.
+ *
* @author Scott.Stark at jboss.org
- * @version $Revision$
+ * @author Thomas.Diesler at jboss.org
*/
public class MimeHeaders
{
private LinkedList headers = new LinkedList();
- public MimeHeaders()
- {
- }
-
/**
+ * Adds a MimeHeader object with the specified name and value to this MimeHeaders object's list of headers.
*
- * @param name
- * @param value
- * @throws IllegalArgumentException - if name is null or empty.
+ * Note that RFC822 headers can contain only US-ASCII characters.
+ *
+ * @param name a String with the name of the header to be added
+ * @param value a String with the value of the header to be added
+ * @throws IllegalArgumentException - if there was a problem in the mime header name or value being added
*/
public void addHeader(String name, String value) throws IllegalArgumentException
{
if (name == null || name.length() == 0)
throw new IllegalArgumentException("Invalid null or empty header name");
+
MimeHeader header = new MimeHeader(name, value);
headers.add(header);
}
+ /**
+ * Returns all the MimeHeaders in this MimeHeaders object.
+ * @return an Iterator object over this MimeHeaders object's list of MimeHeader objects
+ */
public Iterator getAllHeaders()
{
return headers.iterator();
}
/**
+ * Returns all of the values for the specified header as an array of String objects.
*
- * @param name
- * @return All matching header values if found, null otherwise
+ * @param name the name of the header for which values will be returned
+ * @return a String array with all of the values for the specified header
*/
public String[] getHeader(String name)
{
@@ -87,23 +94,40 @@
return values;
}
+ /**
+ * Returns all the MimeHeader objects whose name matches a name in the given array of names.
+ * @param names an array of String objects with the names for which to search
+ * @return an Iterator object over the MimeHeader objects whose name matches one of the names in the given list
+ */
public Iterator getMatchingHeaders(String[] names)
{
- MatchingIter iter = new MatchingIter(headers, names, true);
+ MatchingIterator iter = new MatchingIterator(headers, names, true);
return iter;
}
+ /**
+ * Returns all of the MimeHeader objects whose name does not match a name in the given array of names.
+ * @param names an array of String objects with the names for which to search
+ * @return an Iterator object over the MimeHeader objects whose name does not match one of the names in the given list
+ */
public Iterator getNonMatchingHeaders(String[] names)
{
- MatchingIter iter = new MatchingIter(headers, names, false);
+ MatchingIterator iter = new MatchingIterator(headers, names, false);
return iter;
}
+ /**
+ * Removes all the header entries from this MimeHeaders object.
+ */
public void removeAllHeaders()
{
headers.clear();
}
+ /**
+ * Remove all MimeHeader objects whose name matches the given name.
+ * @param name a String with the name of the header for which to search
+ */
public void removeHeader(String name)
{
Iterator iter = headers.iterator();
@@ -115,11 +139,17 @@
}
}
- /** Replaces the current value of the first header entry whose name matches
+ /**
+ * Replaces the current value of the first header entry whose name matches
* the given name with the given value, adding a new header if no existing
* header name matches. This method also removes all matching headers after
* the first one.
*
+ * Note that RFC822 headers can contain only US-ASCII characters.
+ *
+ * @param name a String with the name of the header for which to search
+ * @param value a String with the value that will replace the current value of the specified header
+ * @throws IllegalArgumentException if there was a problem in the mime header name or the value being set
*/
public void setHeader(String name, String value)
{
@@ -149,7 +179,7 @@
}
}
- private static class MatchingIter implements Iterator
+ private static class MatchingIterator implements Iterator
{
private LinkedList headers;
private HashSet names;
@@ -157,7 +187,7 @@
private int index;
private MimeHeader mh;
- MatchingIter(LinkedList headers, String[] names, boolean match)
+ MatchingIterator(LinkedList headers, String[] names, boolean match)
{
this.headers = headers;
this.index = 0;
Modified: branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/server/AbstractServiceEndpointServlet.java
===================================================================
--- branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/server/AbstractServiceEndpointServlet.java 2007-03-28 03:56:44 UTC (rev 2699)
+++ branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/server/AbstractServiceEndpointServlet.java 2007-03-28 09:17:06 UTC (rev 2700)
@@ -106,7 +106,7 @@
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
- if(log.isDebugEnabled()) log.debug("doPost: " + req.getRequestURI());
+ log.debug("doPost: " + req.getRequestURI());
try
{
Modified: branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/server/EndpointContext.java
===================================================================
--- branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/server/EndpointContext.java 2007-03-28 03:56:44 UTC (rev 2699)
+++ branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/server/EndpointContext.java 2007-03-28 09:17:06 UTC (rev 2700)
@@ -51,7 +51,7 @@
public HttpSession getHttpSession()
{
- return request.getSession();
+ return request.getSession(true);
}
public MessageContext getMessageContext()
Modified: branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/server/ServiceEndpointManager.java
===================================================================
--- branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/server/ServiceEndpointManager.java 2007-03-28 03:56:44 UTC (rev 2699)
+++ branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/server/ServiceEndpointManager.java 2007-03-28 09:17:06 UTC (rev 2700)
@@ -37,9 +37,11 @@
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.activation.DataHandler;
@@ -47,8 +49,10 @@
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import javax.servlet.ServletContext;
+import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
@@ -148,13 +152,13 @@
{
if (host == null || host.trim().length() == 0)
{
- if(log.isDebugEnabled()) log.debug("Using undefined host: " + UNDEFINED_HOSTNAME);
+ log.debug("Using undefined host: " + UNDEFINED_HOSTNAME);
host = UNDEFINED_HOSTNAME;
}
if ("0.0.0.0".equals(host))
{
InetAddress localHost = InetAddress.getLocalHost();
- if(log.isDebugEnabled()) log.debug("Using local host: " + localHost.getHostName());
+ log.debug("Using local host: " + localHost.getHostName());
host = localHost.getHostName();
}
this.webServiceHost = host;
@@ -394,6 +398,8 @@
public void processSOAPRequest(ObjectName sepID, InputStream inStream, OutputStream outStream, EndpointContext context) throws Exception
{
+ final String SESSION_COOKIES = "org.jboss.ws.cookies";
+
ServiceEndpoint wsEndpoint = getServiceEndpointByID(sepID);
if (wsEndpoint == null)
throw new WSException("Cannot obtain endpoint for: " + sepID);
@@ -402,12 +408,32 @@
ServerEndpointMetaData sepMetaData = wsEndpoint.getServiceEndpointInfo().getServerEndpointMetaData();
Type type = sepMetaData.getType();
- PropertyCallback httpSessionCallback = new HttpSessionPropertyCallback(context);
ServletContext servletContext = context.getServletContext();
HttpServletRequest httpRequest = context.getHttpServletRequest();
HttpServletResponse httpResponse = context.getHttpServletResponse();
ServletHeaderSource headerSource = new ServletHeaderSource(httpRequest, httpResponse);
-
+
+ // Default to does not create a new HTTPSession
+ Object lasySession = new HttpSessionPropertyCallback(context);
+
+ Cookie[] cookies = httpRequest.getCookies();
+ if (cookies != null)
+ {
+ HttpSession httpSession = httpRequest.getSession(true);
+ lasySession = httpSession;
+
+ Set<Cookie> sessionCoookies = (Set<Cookie>)httpSession.getAttribute(SESSION_COOKIES);
+ if (sessionCoookies == null)
+ {
+ sessionCoookies = new HashSet<Cookie>();
+ httpSession.setAttribute(SESSION_COOKIES, sessionCoookies);
+ }
+ for (Cookie cookie : cookies)
+ {
+ sessionCoookies.add(cookie);
+ }
+ }
+
// Associate a message context with the current thread
CommonMessageContext msgContext;
if (type == EndpointMetaData.Type.JAXRPC)
@@ -416,7 +442,7 @@
msgContext.put(MessageContextJAXRPC.SERVLET_CONTEXT, servletContext);
msgContext.put(MessageContextJAXRPC.SERVLET_REQUEST, httpRequest);
msgContext.put(MessageContextJAXRPC.SERVLET_RESPONSE, httpResponse);
- msgContext.put(MessageContextJAXRPC.SERVLET_SESSION, httpSessionCallback);
+ msgContext.put(MessageContextJAXRPC.SERVLET_SESSION, lasySession);
}
else
{
@@ -466,6 +492,15 @@
httpResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
+ // Copy the cookies to the response
+ HttpSession httpSession = httpRequest.getSession();
+ Set<Cookie> sessionCoookies = httpSession != null ? (Set<Cookie>)httpSession.getAttribute(SESSION_COOKIES) : null;
+ if (sessionCoookies != null)
+ {
+ for (Cookie cookie : sessionCoookies)
+ httpResponse.addCookie(cookie);
+ }
+
sendResponse(outStream, msgContext, isFault);
}
finally
@@ -497,7 +532,7 @@
}
if (wsaTo != null)
{
- if(log.isDebugEnabled()) log.debug("Sending response to addressing destination: " + wsaTo);
+ log.debug("Sending response to addressing destination: " + wsaTo);
new SOAPConnectionImpl().callOneWay(resMessage, wsaTo);
}
else
@@ -510,7 +545,7 @@
*/
public String processSOAPRequest(ObjectName sepID, String inMessage) throws Exception
{
- if(log.isDebugEnabled()) log.debug("processSOAPRequest: " + sepID);
+ log.debug("processSOAPRequest: " + sepID);
ByteArrayInputStream inputStream = new ByteArrayInputStream(inMessage.getBytes("UTF-8"));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(512);
@@ -620,7 +655,7 @@
// Register the endpoint with the MBeanServer
registry.put(sepID, wsEndpoint);
- if(log.isDebugEnabled()) log.debug("WebService created: " + sepID);
+ log.debug("WebService created: " + sepID);
}
/** Start a service endpoint
@@ -671,7 +706,7 @@
registry.remove(sepID);
ServiceEndpointInfo seInfo = wsEndpoint.getServiceEndpointInfo();
- if(log.isDebugEnabled()) log.debug("WebService destroyed: " + seInfo.getServerEndpointMetaData().getEndpointAddress());
+ log.debug("WebService destroyed: " + seInfo.getServerEndpointMetaData().getEndpointAddress());
}
public void create() throws Exception
@@ -686,7 +721,7 @@
public void destroy() throws Exception
{
- if(log.isDebugEnabled()) log.debug("Destroy service endpoint manager");
+ log.debug("Destroy service endpoint manager");
MBeanServer server = getJMXServer();
if (server != null)
{
Modified: branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPMessageUnMarshaller.java
===================================================================
--- branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPMessageUnMarshaller.java 2007-03-28 03:56:44 UTC (rev 2699)
+++ branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPMessageUnMarshaller.java 2007-03-28 09:17:06 UTC (rev 2700)
@@ -102,7 +102,7 @@
private MimeHeaders getMimeHeaders(Map metadata)
{
- if(log.isDebugEnabled()) log.debug("getMimeHeaders from: " + metadata);
+ log.debug("getMimeHeaders from: " + metadata);
MimeHeaders headers = new MimeHeaders();
Iterator i = metadata.keySet().iterator();
Modified: branches/jbossws-1.2.1/jbossws-tests/src/java/org/jboss/test/ws/jaxrpc/samples/handler/ClientSideHandler.java
===================================================================
--- branches/jbossws-1.2.1/jbossws-tests/src/java/org/jboss/test/ws/jaxrpc/samples/handler/ClientSideHandler.java 2007-03-28 03:56:44 UTC (rev 2699)
+++ branches/jbossws-1.2.1/jbossws-tests/src/java/org/jboss/test/ws/jaxrpc/samples/handler/ClientSideHandler.java 2007-03-28 09:17:06 UTC (rev 2700)
@@ -1,32 +1,38 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., 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, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., 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.jboss.test.ws.jaxrpc.samples.handler;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
import javax.xml.namespace.QName;
import javax.xml.rpc.JAXRPCException;
import javax.xml.rpc.handler.GenericHandler;
import javax.xml.rpc.handler.HandlerInfo;
import javax.xml.rpc.handler.MessageContext;
import javax.xml.rpc.handler.soap.SOAPMessageContext;
+import javax.xml.soap.MimeHeader;
+import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPException;
@@ -71,6 +77,9 @@
SOAPBodyElement soapBodyElement = (SOAPBodyElement)soapBody.getChildElements().next();
String rpcName = soapBodyElement.getElementName().getLocalName();
+ MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
+ mimeHeaders.setHeader("Cookie", "username=kermit");
+
// testInHeader
if (rpcName.equals("testInHeader"))
{
@@ -107,4 +116,22 @@
return true;
}
+
+ @Override
+ public boolean handleResponse(MessageContext msgContext)
+ {
+ log.info("handleResponse");
+
+ SOAPMessage soapMessage = ((SOAPMessageContext)msgContext).getMessage();
+ MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
+ String[] cookieValues = mimeHeaders.getHeader("Set-Cookie");
+ if (cookieValues == null)
+ throw new JAXRPCException("Cannot obtain cookie values");
+
+ List<String> cookieList = Arrays.asList(cookieValues);
+ if (!cookieList.contains("username=kermit"))
+ throw new JAXRPCException("Cannot obtain expected cookie value in: " + cookieList);
+
+ return true;
+ }
}
Modified: branches/jbossws-1.2.1/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/handlerchain/HandlerChainTestCase.java
===================================================================
--- branches/jbossws-1.2.1/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/handlerchain/HandlerChainTestCase.java 2007-03-28 03:56:44 UTC (rev 2699)
+++ branches/jbossws-1.2.1/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/handlerchain/HandlerChainTestCase.java 2007-03-28 09:17:06 UTC (rev 2700)
@@ -63,6 +63,7 @@
handlerChain.add(new LogHandler());
handlerChain.add(new AuthorizationHandler());
handlerChain.add(new RoutingHandler());
+ handlerChain.add(new MimeHeaderHandler());
bindingProvider.getBinding().setHandlerChain(handlerChain);
String resStr = port.echo("Kermit");
Added: branches/jbossws-1.2.1/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/handlerchain/MimeHeaderHandler.java
===================================================================
--- branches/jbossws-1.2.1/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/handlerchain/MimeHeaderHandler.java (rev 0)
+++ branches/jbossws-1.2.1/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/handlerchain/MimeHeaderHandler.java 2007-03-28 09:17:06 UTC (rev 2700)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., 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.jboss.test.ws.jaxws.samples.handlerchain;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.xml.rpc.JAXRPCException;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+import org.jboss.logging.Logger;
+import org.jboss.ws.core.jaxws.handler.GenericSOAPHandler;
+
+/**
+ * A client side handler
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @since 08-Oct-2005
+ */
+public class MimeHeaderHandler extends GenericSOAPHandler
+{
+ // Provide logging
+ private static Logger log = Logger.getLogger(MimeHeaderHandler.class);
+
+ protected boolean handleInbound(MessageContext msgContext)
+ {
+ log.info("handleInbound");
+
+ SOAPMessage soapMessage = ((SOAPMessageContext)msgContext).getMessage();
+ MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
+ String[] cookieValues = mimeHeaders.getHeader("Set-Cookie");
+ if (cookieValues == null)
+ throw new JAXRPCException("Cannot obtain cookie values");
+
+ List<String> cookieList = Arrays.asList(cookieValues);
+ if (!cookieList.contains("username=kermit"))
+ throw new JAXRPCException("Cannot obtain expected cookie value in: " + cookieList);
+
+ return true;
+ }
+
+ protected boolean handleOutbound(MessageContext msgContext)
+ {
+ log.info("handleOutbound");
+
+ SOAPMessage soapMessage = ((SOAPMessageContext)msgContext).getMessage();
+
+ MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
+ mimeHeaders.setHeader("Cookie", "username=kermit");
+
+ return true;
+ }
+}
Property changes on: branches/jbossws-1.2.1/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/handlerchain/MimeHeaderHandler.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
More information about the jbossws-commits
mailing list