Author: objectiser
Date: 2010-11-16 17:50:58 -0500 (Tue, 16 Nov 2010)
New Revision: 1111
Modified:
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/ws/WebServiceClient.java
trunk/runtime/engine/src/main/java/org/jboss/soa/si/ws/SOAPMessageAdapter.java
Log:
Removed more ODE specific classes from SOAPMessageAdapter.
Modified:
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/ws/WebServiceClient.java
===================================================================
---
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/ws/WebServiceClient.java 2010-11-16
22:06:58 UTC (rev 1110)
+++
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/ws/WebServiceClient.java 2010-11-16
22:50:58 UTC (rev 1111)
@@ -237,7 +237,8 @@
if(log.isDebugEnabled())
log.debug( "ODE outbound message: \n"
+DOMWriter.printNode(mex.getRequest().getMessage(), true) );
- String soapAction=messageAdapter.createSoapRequest(soapRequestMessage,
mex.getRequest(), mex.getOperation());
+ String soapAction=messageAdapter.createSoapRequest(soapRequestMessage,
+ new ODEMessageAdapter(mex.getRequest()), mex.getOperation());
if (log.isDebugEnabled()) {
log.debug("Riftsaw soap request message: \n" +
JavaUtils.getSoapMessageASString(soapRequestMessage));
@@ -338,7 +339,8 @@
if(log.isDebugEnabled())
log.debug( "ODE outbound message: \n"
+DOMWriter.printNode(mex.getRequest().getMessage(), true) );
- messageAdapter.createSoapRequest(soapRequestMessage, mex.getRequest(),
mex.getOperation());
+ messageAdapter.createSoapRequest(soapRequestMessage,
+ new ODEMessageAdapter(mex.getRequest()), mex.getOperation());
if (log.isDebugEnabled()) {
log.debug("Riftsaw soap request message: \n" +
JavaUtils.getSoapMessageASString(soapRequestMessage));
Modified: trunk/runtime/engine/src/main/java/org/jboss/soa/si/ws/SOAPMessageAdapter.java
===================================================================
---
trunk/runtime/engine/src/main/java/org/jboss/soa/si/ws/SOAPMessageAdapter.java 2010-11-16
22:06:58 UTC (rev 1110)
+++
trunk/runtime/engine/src/main/java/org/jboss/soa/si/ws/SOAPMessageAdapter.java 2010-11-16
22:50:58 UTC (rev 1111)
@@ -23,21 +23,25 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.ode.bpel.iapi.Message;
-import org.apache.ode.utils.DOMUtils;
import org.apache.ode.utils.stl.CollectionsX;
import org.apache.ode.utils.wsdl.WsdlUtils;
+import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl;
import org.jboss.soa.si.MessageAdapter;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
import javax.wsdl.*;
import javax.wsdl.extensions.ElementExtensible;
import javax.wsdl.extensions.soap.SOAPBinding;
import javax.wsdl.extensions.soap.SOAPHeader;
import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
import javax.xml.soap.*;
import java.util.*;
@@ -52,7 +56,7 @@
*/
public class SOAPMessageAdapter
{
- protected final Log log = LogFactory.getLog(getClass());
+ protected static final Log log = LogFactory.getLog(SOAPMessageAdapter.class);
private Definition wsdl;
private QName serviceName;
@@ -113,7 +117,7 @@
* @param wsdlOperation
* @return The SOAP action
*/
- public String createSoapRequest(SOAPMessage soapMessage, Message odeRequestMessage,
Operation wsdlOperation)
+ public String createSoapRequest(SOAPMessage soapMessage, MessageAdapter
odeRequestMessage, Operation wsdlOperation)
{
String ret=null;
@@ -222,7 +226,7 @@
List<Part> parts = wsdlMessageDef.getOrderedParts(wsdlSoapBody.getParts());
for(Part part : parts)
{
- Element srcPartEl = DOMUtils.findChildByName(message, new QName(null,
part.getName()));
+ Element srcPartEl = findChildByName(message, new QName(null, part.getName()));
if (srcPartEl == null)
throw new RuntimeException("Part is missing: " +part.getName());
@@ -271,7 +275,7 @@
//Add soap header according to binding.
for (SOAPHeader header : headers) {
- Element headerEl = DOMUtils.findChildByName(message, new QName(null,
header.getPart()));
+ Element headerEl = findChildByName(message, new QName(null, header.getPart()));
if (headerEl != null) {
// RIFTSAW-305 - don't think the part name should be added to the SOAP header
@@ -352,10 +356,10 @@
Part p = (Part)f.getMessage().getParts().values().iterator().next();
if (p == null)
return toFaultDetail(faultName, message);
- Element partEl= DOMUtils.findChildByName(message,new QName(null,p.getName()));
+ Element partEl= findChildByName(message,new QName(null,p.getName()));
if (partEl == null)
return toFaultDetail(faultName, message);
- Element detail = DOMUtils.findChildByName(partEl, p.getElementName());
+ Element detail = findChildByName(partEl, p.getElementName());
if (detail == null)
return toFaultDetail(faultName, message);
@@ -364,9 +368,9 @@
private Element toFaultDetail(QName fault, Element message) {
if (message == null) return null;
- Element firstPart = DOMUtils.getFirstChildElement(message);
+ Element firstPart = getFirstChildElement(message);
if (firstPart == null) return null;
- Element detail = DOMUtils.getFirstChildElement(firstPart);
+ Element detail = getFirstChildElement(firstPart);
if (detail == null) return firstPart;
return detail;
}
@@ -391,7 +395,7 @@
if (obj instanceof javax.xml.soap.SOAPHeaderElement) {
javax.xml.soap.SOAPHeaderElement headerElem =
(javax.xml.soap.SOAPHeaderElement) obj;
String partName = findHeaderPartName(headerDefs,
headerElem.getElementQName());
- Document doc = DOMUtils.newDocument();
+ Document doc = newDocument();
// RIFTSAW-74 - slight modification to avoid jbossws exception when
reconstructing the
// SOAP message.
@@ -508,7 +512,7 @@
for(Part part : parts)
{
SOAPElement srcPart = srcParts.next();
- Document doc = DOMUtils.newDocument();
+ Document doc = newDocument();
Element destPart = doc.createElementNS(null, part.getName());
destPart.appendChild(doc.importNode(srcPart, true));
odeMessage.setPart(part.getName(), destPart);
@@ -581,7 +585,7 @@
Element partel =
odeMessage.getOwnerDocument().createElementNS(null,pdef.getName());
odeMessage.appendChild(partel);
- Element childByName = DOMUtils.findChildByName(detail, pdef.getElementName());
+ Element childByName = findChildByName(detail, pdef.getElementName());
if (childByName != null)
{
partel.appendChild(odeMessage.getOwnerDocument().importNode(childByName,
true));
@@ -614,7 +618,7 @@
Element partel =
odeMessage.getOwnerDocument().createElementNS(null,pdef.getName());
odeMessage.appendChild(partel);
- Element childByName = DOMUtils.findChildByName(detail, pdef.getElementName());
+ Element childByName = findChildByName(detail, pdef.getElementName());
if (childByName != null)
{
partel.appendChild(odeMessage.getOwnerDocument().importNode(childByName,
true));
@@ -632,7 +636,7 @@
if (!flt.hasDetail())
return null;
// The detail is a dummy <detail> node containing the interesting fault
element
- Element element = DOMUtils.getFirstChildElement(flt.getDetail());
+ Element element = getFirstChildElement(flt.getDetail());
if (element == null) {
return(null);
@@ -641,4 +645,123 @@
QName elName=new QName(element.getNamespaceURI(), element.getLocalName());
return WsdlUtils.inferFault(operation, elName);
}
+
+
+ // Code taken from Apache ODE util module
+
+ private static ThreadLocal<DocumentBuilder> __builders = new ThreadLocal();
+
+ private static DocumentBuilderFactory __documentBuilderFactory ;
+
+ static {
+ initDocumentBuilderFactory();
+ }
+
+ /**
+ * Initialize the document-builder factory.
+ */
+ private static void initDocumentBuilderFactory() {
+ DocumentBuilderFactory f = new DocumentBuilderFactoryImpl();
+ f.setNamespaceAware(true);
+ __documentBuilderFactory = f;
+ }
+
+ private static DocumentBuilder getBuilder() {
+ DocumentBuilder builder = __builders.get();
+ if (builder == null) {
+ synchronized (__documentBuilderFactory) {
+ try {
+ builder = __documentBuilderFactory.newDocumentBuilder();
+ builder.setErrorHandler(new org.xml.sax.ErrorHandler() {
+
+ public void error(SAXParseException arg0)
+ throws SAXException {
+ log.error("Parser error", arg0);
+ }
+
+ public void fatalError(SAXParseException arg0)
+ throws SAXException {
+ log.error("Parser fatal error", arg0);
+ }
+
+ public void warning(SAXParseException arg0)
+ throws SAXException {
+ log.warn("Parser warning", arg0);
+ }
+
+ });
+ } catch (ParserConfigurationException e) {
+ log.error(e);
+ throw new RuntimeException(e);
+ }
+ }
+ __builders.set(builder);
+ }
+ return builder;
+ }
+
+ public static Document newDocument() {
+ DocumentBuilder db = getBuilder();
+ return db.newDocument();
+ }
+
+ /**
+ * Return the first child element of the given element. Null if no children
+ * are found.
+ *
+ * @param elem Element whose child is to be returned
+ *
+ * @return the first child element.
+ */
+ public static Element getFirstChildElement(Element elem) {
+ return (Element) findChildByType(elem, Node.ELEMENT_NODE);
+ }
+
+ public static Element findChildByName(Element parent, QName name) {
+ return findChildByName(parent, name, false);
+ }
+
+ public static Element findChildByName(Element parent, QName name, boolean recurse) {
+ if (parent == null)
+ throw new IllegalArgumentException("null parent");
+ if (name == null)
+ throw new IllegalArgumentException("null name");
+
+ NodeList nl = parent.getChildNodes();
+ for (int i = 0; i < nl.getLength(); ++i) {
+ Node c = nl.item(i);
+ if(c.getNodeType() != Node.ELEMENT_NODE)
+ continue;
+ // For a reason that I can't fathom, when using in-mem DAO we actually get
elements with
+ // no localname.
+ String nodeName = c.getLocalName() != null ? c.getLocalName() :
c.getNodeName();
+ if (new QName(c.getNamespaceURI(),nodeName).equals(name))
+ return (Element) c;
+ }
+
+ if(recurse){
+ NodeList cnl = parent.getChildNodes();
+ for (int i = 0; i < cnl.getLength(); ++i) {
+ Node c = cnl.item(i);
+ if(c.getNodeType() != Node.ELEMENT_NODE)
+ continue;
+ Element result = findChildByName((Element)c, name, recurse);
+ if(result != null)
+ return result;
+ }
+ }
+ return null;
+ }
+
+ public static Node findChildByType(Element elem, int type) {
+ if (elem == null)
+ throw new NullPointerException("elem parameter must not be null!");
+
+ for (Node n = elem.getFirstChild(); n != null; n = n.getNextSibling()) {
+ if (n.getNodeType() == type) {
+ return n;
+ }
+ }
+ return null;
+ }
}