You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by pr...@apache.org on 2008/04/03 11:27:52 UTC
svn commit: r644237 -
/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java
Author: pradine
Date: Thu Apr 3 02:27:52 2008
New Revision: 644237
URL: http://svn.apache.org/viewvc?rev=644237&view=rev
Log:
Move the toSOAPHeaderBlock() method from XMLUtils to ElementHelper as it may
also be useful to axiom users that don't require axis2.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java?rev=644237&r1=644236&r2=644237&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java Thu Apr 3 02:27:52 2008
@@ -24,10 +24,15 @@
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.ds.ByteArrayDataSource;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAPHeaderBlock;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamReader;
+
+import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Iterator;
@@ -178,7 +183,28 @@
documentElement.build();
return documentElement;
}
-
}
+ /**
+ * This is a method to convert regular OMElements to SOAPHeaderBlocks.
+ *
+ * @param omElement
+ * @param factory
+ * @return
+ * @throws Exception
+ */
+ public static SOAPHeaderBlock toSOAPHeaderBlock(OMElement omElement, SOAPFactory factory) throws Exception {
+ if (omElement instanceof SOAPHeaderBlock)
+ return (SOAPHeaderBlock) omElement;
+
+ QName name = omElement.getQName();
+ String localName = name.getLocalPart();
+ OMNamespace namespace = factory.createOMNamespace(name.getNamespaceURI(), name.getPrefix());
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ omElement.serialize(baos);
+ ByteArrayDataSource bads = new ByteArrayDataSource(baos.toByteArray(), "utf-8");
+ SOAPHeaderBlock block = factory.createSOAPHeaderBlock(localName, namespace, bads);
+
+ return block;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org