You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-commits@ws.apache.org by da...@apache.org on 2007/02/01 18:49:55 UTC
svn commit: r502300 -
/webservices/muse/trunk/modules/muse-wsa-soap/src/org/apache/muse/ws/addressing/MessageHeaders.java
Author: danj
Date: Thu Feb 1 09:49:54 2007
New Revision: 502300
URL: http://svn.apache.org/viewvc?view=rev&rev=502300
Log:
Added getCustomHeader*() methods for request in MUSE-189 - we can now read *all* SOAP
headers in a platform-independent way.
Modified:
webservices/muse/trunk/modules/muse-wsa-soap/src/org/apache/muse/ws/addressing/MessageHeaders.java
Modified: webservices/muse/trunk/modules/muse-wsa-soap/src/org/apache/muse/ws/addressing/MessageHeaders.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsa-soap/src/org/apache/muse/ws/addressing/MessageHeaders.java?view=diff&rev=502300&r1=502299&r2=502300
==============================================================================
--- webservices/muse/trunk/modules/muse-wsa-soap/src/org/apache/muse/ws/addressing/MessageHeaders.java (original)
+++ webservices/muse/trunk/modules/muse-wsa-soap/src/org/apache/muse/ws/addressing/MessageHeaders.java Thu Feb 1 09:49:54 2007
@@ -17,12 +17,16 @@
package org.apache.muse.ws.addressing;
import java.net.URI;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
import javax.xml.namespace.QName;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.apache.muse.util.MultiMap;
import org.apache.muse.util.messages.Messages;
import org.apache.muse.util.messages.MessagesFactory;
import org.apache.muse.util.uuid.RandomUuidFactory;
@@ -65,6 +69,11 @@
//
private String _action = null;
+
+ //
+ // all non-WS-A headers are made available separately
+ //
+ private Map _customHeadersByQName = new MultiMap();
private EndpointReference _faultTo = null;
@@ -159,28 +168,38 @@
Element[] children = XmlUtils.getAllElements(soapHeaders);
//
- // NOTE: add all elements to the ReferenceProperties, since WS-A
- // provides no way to distinguish between properties and
- // parameters in the SOAP header.
+ // look at all SOAP headers to determine if they're WS-A reference
+ // parameters or not
//
for (int n = 0; n < children.length; ++n)
{
- String attr = children[n].getAttributeNS(WsaConstants.NAMESPACE_URI, WsaConstants.IS_REFERENCE_PARAMETER);
+ QName qname = XmlUtils.getElementQName(children[n]);
+
+ //
+ // check to see if its a WS-A reference parameter
+ //
+ String wsaAttr = children[n].getAttributeNS(WsaConstants.NAMESPACE_URI, WsaConstants.IS_REFERENCE_PARAMETER);
- if (Boolean.valueOf(attr) == Boolean.TRUE)
+ if (Boolean.valueOf(wsaAttr) == Boolean.TRUE)
{
//
- // remove SOAP junk from property XML - this is especially
+ // remove SOAP junk from parameter XML - this is especially
// important when you start moving the EPR XML to other
// messages/fragments that may not have the SOAP prefixes
//
children[n].removeAttributeNS(SoapConstants.NAMESPACE_URI, SoapConstants.ACTOR);
children[n].removeAttributeNS(SoapConstants.NAMESPACE_URI, SoapConstants.MUST_UNDERSTAND);
-
- QName qname = XmlUtils.getElementQName(children[n]);
+
_to.addParameter(qname, children[n]);
}
+
+ //
+ // if not, make sure it's not a WS-A element and add it to
+ // the 'custom headers' collection
+ //
+ else if (!qname.getNamespaceURI().equals(WsaConstants.NAMESPACE_URI))
+ _customHeadersByQName.put(qname, children[n]);
}
}
@@ -356,6 +375,52 @@
public String getAction()
{
return _action;
+ }
+
+ /**
+ *
+ * This method is useful if you are only expecting one instance of a given
+ * SOAP header element and do not want to sort through a Collection or
+ * Iterator just to get one item.
+ *
+ * @param elementName
+ * The name of the non-WS-A SOAP header to return.
+ *
+ * @return The <b>first</b> DOM Element found with the given name, or
+ * null if no such element was found.
+ *
+ */
+ public Element getCustomHeader(QName elementName)
+ {
+ Collection headers = getCustomHeaders(elementName);
+ return headers.isEmpty() ? null : (Element)headers.iterator().next();
+ }
+
+ /**
+ *
+ * @param elementName
+ * The name of the non-WS-A SOAP header(s) to return.
+ *
+ * @return A collection of DOM Elements with the given name. The collection
+ * may be empty.
+ *
+ */
+ public Collection getCustomHeaders(QName elementName)
+ {
+ Collection headers = (Collection)_customHeadersByQName.get(elementName);
+ return headers != null ? headers : Collections.EMPTY_LIST;
+ }
+
+ /**
+ *
+ * @return A collection of QNames, one for each SOAP header that a) does
+ * not have the WS-A namespace, and b) is not a WS-A reference
+ * parameter. The collection may be empty.
+ *
+ */
+ public Collection getCustomHeaderNames()
+ {
+ return Collections.unmodifiableSet(_customHeadersByQName.keySet());
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org