Author: mriou
Date: Wed Oct 18 15:36:50 2006
New Revision: 465400

URL: http://svn.apache.org/viewvc?view=rev&rev=465400
Log:
ODE-66 Replicating xmlns="" from the DOM tree to Axiom to avoid losing these 
empty namespace definitions. This is only enabled when setting a configuration 
property as it impacts performance (have to traverse both the DOM and the AXIOM 
tree).

Removed:
    
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/AxisInvoker.java
Modified:
    
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java
    
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEConfigProperties.java
    incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java
    incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEService.java
    
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/OMUtils.java

Modified: 
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java?view=diff&rev=465400&r1=465399&r2=465400
==============================================================================
--- 
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java
 (original)
+++ 
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java
 Wed Oct 18 15:36:50 2006
@@ -60,6 +60,7 @@
     private QName _serviceName;
     private String _portName;
     private AxisConfiguration _axisConfig;
+    private boolean _isReplicateEmptyNS = false;
 
     public ExternalService(Definition definition, QName serviceName,
                            String portName, ExecutorService executorService, 
AxisConfiguration axisConfig) {
@@ -77,7 +78,7 @@
             Element msgContent = 
SOAPUtils.wrap(odeMex.getRequest().getMessage(), _definition, _serviceName,
                     odeMex.getOperation(), 
odeMex.getOperation().getInput().getMessage());
 
-            final OMElement payload = OMUtils.toOM(msgContent);
+            final OMElement payload = OMUtils.toOM(msgContent, 
_isReplicateEmptyNS);
 
             Options options = new Options();
             EndpointReference axisEPR = new 
EndpointReference(((MutableEndpoint)odeMex.getEndpointReference()).getUrl());
@@ -182,5 +183,9 @@
 
     public void close() {
         // TODO Auto-generated method stub
+    }
+
+    public void setReplicateEmptyNS(boolean isReplicateEmptyNS) {
+        _isReplicateEmptyNS = isReplicateEmptyNS;
     }
 }

Modified: 
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEConfigProperties.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEConfigProperties.java?view=diff&rev=465400&r1=465399&r2=465400
==============================================================================
--- 
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEConfigProperties.java
 (original)
+++ 
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEConfigProperties.java
 Wed Oct 18 15:36:50 2006
@@ -43,6 +43,7 @@
     private static final String PROP_POOL_MIN = "ode-axis2.db.pool.min";
     private static final String PROP_CONNECTOR_PORT = "ode-axis2.jca.port";
     private static final String PROP_WORKING_DIR = "ode-axis2.working.dir";
+    private static final String PROP_REPLICATE_EMPTYNS = 
"ode-axis2.message.replicate.emptyns";
 
     private File _installDir;
 
@@ -131,6 +132,10 @@
 
     public String getTxFactoryClass() {
         return getProperty(ODEConfigProperties.PROP_TX_FACTORY_CLASS, 
"org.apache.ode.axis2.util.JotmFactory");
+    }
+
+    public boolean isReplicateEmptyNS() {
+        return 
Boolean.valueOf(getProperty(ODEConfigProperties.PROP_REPLICATE_EMPTYNS, 
"false"));
     }
 
 }

Modified: 
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java?view=diff&rev=465400&r1=465399&r2=465400
==============================================================================
--- incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java 
(original)
+++ incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java 
Wed Oct 18 15:36:50 2006
@@ -201,6 +201,11 @@
                 def, serviceName, portName);
         ODEService odeService = new ODEService(axisService, def, serviceName, 
portName,
                 _server, _txMgr);
+        if (_odeConfig.isReplicateEmptyNS()) {
+            __log.debug("Setting service with empty namespace replication");
+            odeService.setReplicateEmptyNS(true);
+        }
+
         _services.put(serviceName, portName, odeService);
 
         // Setting our new service on the receiver, the same receiver handles 
all
@@ -221,6 +226,10 @@
             return extService;
 
         extService = new ExternalService(def, serviceName, portName, 
_executorService, _axisConfig);
+        if (_odeConfig.isReplicateEmptyNS()) {
+            __log.debug("Setting external service with empty namespace 
replication");
+            extService.setReplicateEmptyNS(true);
+        }
         _externalServices.put(serviceName, portName, extService);
         __log.debug("Created external service " + serviceName);
         return extService;
@@ -252,10 +261,6 @@
 
     public ExternalService getExternalService(QName serviceName, String 
portName) {
         return (ExternalService) _externalServices.get(serviceName, portName);
-    }
-
-    public AxisInvoker createInvoker() {
-        return new AxisInvoker(_executorService);
     }
 
     private void initTxMgr() throws ServletException {

Modified: 
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEService.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEService.java?view=diff&rev=465400&r1=465399&r2=465400
==============================================================================
--- 
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEService.java 
(original)
+++ 
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEService.java 
Wed Oct 18 15:36:50 2006
@@ -61,24 +61,17 @@
 public class ODEService {
 
     private static final Log __log = LogFactory.getLog(ODEService.class);
-
     private static final int TIMEOUT = 2 * 60 * 1000;
 
     private AxisService _axisService;
-
     private BpelServer _server;
-
     private TransactionManager _txManager;
-
     private Definition _wsdlDef;
-
     private QName _serviceName;
-
     private String _portName;
-
     private Map<String, ResponseCallback> _waitingCallbacks;
-
     private WSAEndpoint _serviceRef;
+    private boolean _isReplicateEmptyNS = false;
 
     public ODEService(AxisService axisService, Definition def, QName 
serviceName, String portName, BpelServer server,
                       TransactionManager txManager) {
@@ -235,14 +228,15 @@
         switch (mex.getStatus()) {
             case FAULT:
                 throw new AxisFault(mex.getResponse().getType(), 
mex.getFaultExplanation(), null, null,
-                        mex.getFaultResponse().getMessage() == null ? null : 
OMUtils.toOM(mex.getFaultResponse().getMessage()));
+                        mex.getFaultResponse().getMessage() == null ? null :
+                                
OMUtils.toOM(mex.getFaultResponse().getMessage(), _isReplicateEmptyNS));
             case ASYNC:
             case RESPONSE:
                 Element response = 
SOAPUtils.wrap(mex.getResponse().getMessage(), _wsdlDef, _serviceName, mex
                         .getOperation(), 
mex.getOperation().getOutput().getMessage());
                 if (__log.isDebugEnabled()) __log.debug("Received response 
message " +
                         DOMUtils.domToString(response));
-                
msgContext.getEnvelope().getBody().addChild(OMUtils.toOM(response));
+                
msgContext.getEnvelope().getBody().addChild(OMUtils.toOM(response, 
_isReplicateEmptyNS));
                 writeHeader(msgContext, mex);
                 break;
             case FAILURE:
@@ -335,8 +329,7 @@
     /**
      * Return the service-ref element that will be used to represent this
      * endpoint.
-     * 
-     * @return
+     * @return my service endpoint
      */
     public EndpointReference getMyServiceRef() {
         return _serviceRef;
@@ -404,4 +397,7 @@
         return EndpointFactory.createEndpoint(doc.getDocumentElement());
     }
 
+    public void setReplicateEmptyNS(boolean isReplicateEmptyNS) {
+        _isReplicateEmptyNS = isReplicateEmptyNS;
+    }
 }

Modified: 
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/OMUtils.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/OMUtils.java?view=diff&rev=465400&r1=465399&r2=465400
==============================================================================
--- 
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/OMUtils.java 
(original)
+++ 
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/OMUtils.java 
Wed Oct 18 15:36:50 2006
@@ -30,10 +30,13 @@
 
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axis2.AxisFault;
 import org.apache.ode.utils.DOMUtils;
 import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Node;
 
 /**
  * Utility methods to convert from/to AxiOM and DOM.
@@ -52,14 +55,16 @@
         }
     }
 
-    public static OMElement toOM(Element element) throws AxisFault {
+    public static OMElement toOM(Element element, boolean replicateEmptyNS) 
throws AxisFault {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         try {
             DOMUtils.serialize(element, baos);
             ByteArrayInputStream bais = new 
ByteArrayInputStream(baos.toByteArray());
             XMLStreamReader parser = 
XMLInputFactory.newInstance().createXMLStreamReader(bais);
             StAXOMBuilder builder = new StAXOMBuilder(parser);
-            return builder.getDocumentElement();
+            OMElement result =  builder.getDocumentElement();
+            if (replicateEmptyNS) reproduceEmptyNS(element, element, result);
+            return result;
         } catch (Exception e) {
             throw new AxisFault("Unable to read Axis input message.", e);
         }
@@ -85,6 +90,39 @@
     }
 
     /**
+     * Translation from DOM to AXIOM loses empty namespace definitions. So if 
you have something
+     * like:
+     * <pre>
+     *   <foo xmlns="ns:foo">
+     *     <bar xmlns="">
+     *   </pr:foo>
+     * </pre>
+     * After translation bar will be in the same namespace as foo. This is due 
to Woodstox (the
+     * stax parser behind AXIOM) that considers xmlns="" as being a null 
namespace, hence it is
+     * ignored.
+     * @param root
+     * @param elmt
+     * @param omelmt
+     */
+    private static void reproduceEmptyNS(Element root, Element elmt, OMElement 
omelmt) {
+        if (root.getNamespaceURI() != null && elmt.getNamespaceURI() == null) {
+            OMAttribute emptynsa = 
omelmt.getOMFactory().createOMAttribute("xmlns", null, "");
+            omelmt.addAttribute(emptynsa);
+        }
+
+        NodeList children = elmt.getChildNodes();
+        Iterator omchildren = omelmt.getChildElements();
+        for (int m = 0; m < children.getLength(); m++) {
+            Node child = children.item(m);
+            if (child.getNodeType() == Node.ELEMENT_NODE) {
+                OMElement omchild = (OMElement) omchildren.next();
+                reproduceEmptyNS(root, (Element) child, omchild);
+            }
+        }
+
+    }
+
+    /**
      * Copy namespaces found on parent elements on the element itself.
      * This is useful when detaching an element from its parent to maintain
      * namespace context.
@@ -100,7 +138,7 @@
             copyParentNamespaces(target, (OMElement) target.getParent(), 
declaredNS);
         }
     }
-    
+
     private static void copyParentNamespaces(OMElement target, OMElement 
parent, HashSet<String> declaredNS) {
         Iterator iter = parent.getAllDeclaredNamespaces();
         while (iter.hasNext()) {
@@ -115,5 +153,5 @@
         if (parent.getParent() instanceof OMElement) {
             copyParentNamespaces(target, (OMElement) parent.getParent(), 
declaredNS);
         }
-    }        
+    }
 }


Reply via email to