servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r611600 - in /servicemix/smx4/nmr/trunk: jbi/osgi/ jbi/runtime/ jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/utils/ nmr/osgi/
Date Sun, 13 Jan 2008 17:17:33 GMT
Author: gnodet
Date: Sun Jan 13 09:17:30 2008
New Revision: 611600

URL: http://svn.apache.org/viewvc?rev=611600&view=rev
Log:
Fix EPR resolution and endpoint lookups

Added:
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/utils/
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/utils/DOMUtil.java
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/utils/URIResolver.java
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/utils/WSAddressingConstants.java
Removed:
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/XmlUtils.java
Modified:
    servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml
    servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentRegistryImpl.java
    servicemix/smx4/nmr/trunk/nmr/osgi/pom.xml

Modified: servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml?rev=611600&r1=611599&r2=611600&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml Sun Jan 13 09:17:30 2008
@@ -55,7 +55,7 @@
                     <instructions>
                         <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
                         <Import-Package>org.apache.servicemix.jbi.runtime,org.apache.servicemix.jbi.runtime.impl</Import-Package>
-                        <Spring-Context>*;publish-context:=false;create-asynchronously:=false</Spring-Context>
+                        <Spring-Context>*;publish-context:=false;create-asynchronously:=true</Spring-Context>
                     </instructions>
                 </configuration>
             </plugin>

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml?rev=611600&r1=611599&r2=611600&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml Sun Jan 13 09:17:30 2008
@@ -63,6 +63,12 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+            <version>${commons.logging.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.servicemix</groupId>
             <artifactId>servicemix-common</artifactId>
 		    <version>${smx3.version}</version>

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java?rev=611600&r1=611599&r2=611600&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java
(original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java
Sun Jan 13 09:17:30 2008
@@ -38,29 +38,36 @@
 import javax.management.MBeanServer;
 import javax.naming.InitialContext;
 import javax.xml.namespace.QName;
-import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.TransformerException;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.jbi.runtime.ComponentRegistry;
 import org.apache.servicemix.jbi.runtime.DocumentRepository;
+import org.apache.servicemix.jbi.runtime.impl.utils.DOMUtil;
+import org.apache.servicemix.jbi.runtime.impl.utils.URIResolver;
+import org.apache.servicemix.jbi.runtime.impl.utils.WSAddressingConstants;
 import org.apache.servicemix.nmr.api.Endpoint;
 import org.apache.servicemix.nmr.api.Exchange;
 import org.apache.servicemix.nmr.api.NMR;
 
 /**
- * Created by IntelliJ IDEA.
- * User: gnodet
- * Date: Oct 4, 2007
- * Time: 10:36:40 PM
- * To change this template use File | Settings | File Templates.
+ * The ComponentContext implementation
  */
 public class ComponentContextImpl implements ComponentContext {
 
     public int DEFAULT_QUEUE_CAPACITY = 100;
 
+    private static final Log LOG = LogFactory.getLog(ComponentContextImpl.class);
+
     private NMR nmr;
+    private ComponentRegistry componentRegistry;
     private DocumentRepository documentRepository;
     private Component component;
     private Map<String,?> properties;
@@ -70,8 +77,9 @@
     private EndpointImpl componentEndpoint;
     private String name;
 
-    public ComponentContextImpl(NMR nmr, DocumentRepository documentRepository, Component
component, Map<String,?> properties) {
+    public ComponentContextImpl(NMR nmr, ComponentRegistry componentRegistry, DocumentRepository
documentRepository, Component component, Map<String,?> properties) {
         this.nmr = nmr;
+        this.componentRegistry = componentRegistry;
         this.documentRepository = documentRepository;
         this.component = component;
         this.properties = properties;
@@ -89,22 +97,26 @@
     }
 
     public synchronized ServiceEndpoint activateEndpoint(QName serviceName, String endpointName)
throws JBIException {
-        EndpointImpl endpoint = new EndpointImpl();
-        endpoint.setQueue(queue);
-        endpoint.setServiceName(serviceName);
-        endpoint.setEndpointName(endpointName);
-        Map<String, Object> props = new HashMap<String, Object>();
-        props.put(Endpoint.NAME, serviceName.toString() + ":" + endpointName);
-        props.put(Endpoint.SERVICE_NAME, serviceName);
-        props.put(Endpoint.ENDPOINT_NAME, endpointName);
-        Document doc = component.getServiceDescription(endpoint);
-        if (doc != null) {
-            String data = XmlUtils.toString(doc);
-            String url = documentRepository.register(data.getBytes());
-            props.put(Endpoint.WSDL_URL, url);
+        try {
+            EndpointImpl endpoint = new EndpointImpl();
+            endpoint.setQueue(queue);
+            endpoint.setServiceName(serviceName);
+            endpoint.setEndpointName(endpointName);
+            Map<String, Object> props = new HashMap<String, Object>();
+            props.put(Endpoint.NAME, serviceName.toString() + ":" + endpointName);
+            props.put(Endpoint.SERVICE_NAME, serviceName);
+            props.put(Endpoint.ENDPOINT_NAME, endpointName);
+            Document doc = component.getServiceDescription(endpoint);
+            if (doc != null) {
+                String data = DOMUtil.asXML(doc);
+                String url = documentRepository.register(data.getBytes());
+                props.put(Endpoint.WSDL_URL, url);
+            }
+            nmr.getEndpointRegistry().register(endpoint,  props);
+            return new SimpleServiceEndpoint(props, endpoint);
+        } catch (TransformerException e) {
+            throw new JBIException(e);
         }
-        nmr.getEndpointRegistry().register(endpoint,  props);
-        return new SimpleServiceEndpoint(props, endpoint);
     }
 
     public synchronized void deactivateEndpoint(ServiceEndpoint endpoint) throws JBIException
{
@@ -122,7 +134,17 @@
     }
 
     public ServiceEndpoint resolveEndpointReference(DocumentFragment epr) {
-        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+        for (Component component : componentRegistry.getServices()) {
+            ServiceEndpoint se = component.resolveEndpointReference(epr);
+            if (se != null) {
+                return se;
+            }
+        }
+        ServiceEndpoint se = resolveInternalEPR(epr);
+        if (se != null) {
+            return se;
+        }
+        return resolveStandardEPR(epr);
     }
 
     public String getComponentName() {
@@ -153,7 +175,7 @@
                 InputStream is = null;
                 try {
                     is = new URL(url).openStream();
-                    return XmlUtils.parseDocument(is);
+                    return DOMUtil.parseDocument(is);
                 } catch (Exception e) {
                     if (is != null) {
                         try {
@@ -229,6 +251,136 @@
     public String getWorkspaceRoot() {
         return null;  //To change body of implemented methods use File | Settings | File
Templates.
     }
+
+    /**
+     * <p>
+     * Resolve an internal JBI EPR conforming to the format defined in the JBI specification.
+     * </p>
+     *
+     * <p>The EPR would look like:
+     * <pre>
+     * <jbi:end-point-reference xmlns:jbi="http://java.sun.com/xml/ns/jbi/end-point-reference"
+     *      jbi:end-point-name="endpointName"
+     *      jbi:service-name="foo:serviceName"
+     *      xmlns:foo="urn:FooNamespace"/>
+     * </pre>
+     * </p>
+     *
+     * @author Maciej Szefler m s z e f l e r @ g m a i l . c o m
+     * @param epr EPR fragment
+     * @return internal service endpoint corresponding to the EPR, or <code>null</code>
+     *         if the EPR is not an internal EPR or if the EPR cannot be resolved
+     */
+    public ServiceEndpoint resolveInternalEPR(DocumentFragment epr) {
+        if (epr == null) {
+            throw new NullPointerException("resolveInternalEPR(epr) called with null epr.");
+        }
+        NodeList nl = epr.getChildNodes();
+        for (int i = 0; i < nl.getLength(); ++i) {
+            Node n = nl.item(i);
+            if (n.getNodeType() != Node.ELEMENT_NODE) {
+                continue;
+            }
+            Element el = (Element) n;
+            // Namespace should be "http://java.sun.com/jbi/end-point-reference"
+            if (el.getNamespaceURI() == null || !el.getNamespaceURI().equals("http://java.sun.com/jbi/end-point-reference"))
{
+                continue;
+            }
+            if (el.getLocalName() == null || !el.getLocalName().equals("end-point-reference"))
{
+                continue;
+            }
+            String serviceName = el.getAttributeNS(el.getNamespaceURI(), "service-name");
+            // Now the DOM pain-in-the-you-know-what: we need to come up with QName for this;
+            // fortunately, there is only one place where the xmlns:xxx attribute could be,
on
+            // the end-point-reference element!
+            QName serviceQName = DOMUtil.createQName(el, serviceName);
+            String endpointName = el.getAttributeNS(el.getNamespaceURI(), "end-point-name");
+            return getEndpoint(serviceQName, endpointName);
+        }
+        return null;
+    }
+
+    /**
+     * Resolve a standard EPR understood by ServiceMix container.
+     * Currently, the supported syntax is the WSA one, the address uri
+     * being parsed with the following possiblities:
+     *    jbi:endpoint:service-namespace/service-name/endpoint
+     *    jbi:endpoint:service-namespace:service-name:endpoint
+     *
+     * The full EPR will look like:
+     *   <epr xmlns:wsa="http://www.w3.org/2005/08/addressing">
+     *     <wsa:Address>jbi:endpoint:http://foo.bar.com/service/endpoint</wsa:Address>
+     *   </epr>
+     *
+     * BCs should also be able to resolve such EPR but using their own URI parsing,
+     * for example:
+     *   <epr xmlns:wsa="http://www.w3.org/2005/08/addressing">
+     *     <wsa:Address>http://foo.bar.com/myService?http.soap=true</wsa:Address>
+     *   </epr>
+     *
+     * or
+     *   <epr xmlns:wsa="http://www.w3.org/2005/08/addressing">
+     *     <wsa:Address>jms://activemq/queue/FOO.BAR?persistent=true</wsa:Address>
+     *   </epr>
+     *
+     * Note that the separator should be same as the one used in the namespace
+     * depending on the namespace:
+     *     http://foo.bar.com  => '/'
+     *     urn:foo:bar         => ':'
+     *
+     * The syntax is the same as the one that can be used to specifiy a target
+     * for a JBI exchange with the restriction that it only allows the
+     * endpoint subprotocol to be used.
+     *
+     * @param epr the xml fragment to resolve
+     * @return the resolved endpoint or <code>null</code>
+     */
+    public ServiceEndpoint resolveStandardEPR(DocumentFragment epr) {
+        try {
+            NodeList children = epr.getChildNodes();
+            for (int i = 0; i < children.getLength(); ++i) {
+                Node n = children.item(i);
+                if (n.getNodeType() != Node.ELEMENT_NODE) {
+                    continue;
+                }
+                Element elem = (Element) n;
+                String[] namespaces = new String[] { WSAddressingConstants.WSA_NAMESPACE_200508,
+                                                     WSAddressingConstants.WSA_NAMESPACE_200408,
+                                                     WSAddressingConstants.WSA_NAMESPACE_200403,
+                                                     WSAddressingConstants.WSA_NAMESPACE_200303
};
+                NodeList nl = null;
+                for (String ns : namespaces) {
+                    NodeList tnl = elem.getElementsByTagNameNS(ns, WSAddressingConstants.EL_ADDRESS);
+                    if (tnl.getLength() == 1) {
+                        nl = tnl;
+                        break;
+                    }
+                }
+                if (nl != null) {
+                    Element address = (Element) nl.item(0);
+                    String uri = DOMUtil.getElementText(address);
+                    if (uri != null) {
+                        uri = uri.trim();
+                        if (uri.startsWith("endpoint:")) {
+                            uri = uri.substring("endpoint:".length());
+                            String[] parts = URIResolver.split3(uri);
+                            return getEndpoint(new QName(parts[0], parts[1]), parts[2]);
+                        } else if (uri.startsWith("service:")) {
+                            uri = uri.substring("service:".length());
+                            String[] parts = URIResolver.split2(uri);
+                            return getEndpoint(new QName(parts[0], parts[1]), parts[1]);
+                        }
+                    }
+                    // TODO should we support interface: and operation: here?
+                }
+            }
+        } catch (Exception e) {
+            LOG.debug("Unable to resolve EPR: " + e);
+        }
+        return null;
+    }
+
+    
 
     protected static class SimpleServiceEndpoint implements ServiceEndpoint {
 

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentRegistryImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentRegistryImpl.java?rev=611600&r1=611599&r2=611600&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentRegistryImpl.java
(original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentRegistryImpl.java
Sun Jan 13 09:17:30 2008
@@ -31,11 +31,7 @@
 import org.apache.servicemix.nmr.core.ServiceRegistryImpl;
 
 /**
- * Created by IntelliJ IDEA.
- * User: gnodet
- * Date: Oct 4, 2007
- * Time: 10:30:30 PM
- * To change this template use File | Settings | File Templates.
+ * Registry of JBI components objects
  */
 public class ComponentRegistryImpl extends ServiceRegistryImpl<Component>  implements
ComponentRegistry {
 
@@ -81,7 +77,7 @@
                 properties = new HashMap<String, Object>();
             }
             String name = (String) properties.get(NAME);
-            ComponentContext context = new ComponentContextImpl(nmr, documentRepository,
component, properties);
+            ComponentContext context = new ComponentContextImpl(nmr, this, documentRepository,
component, properties);
             component.getLifeCycle().init(context);
             if (name != null) {
                 components.put(name, component);
@@ -101,14 +97,10 @@
      * @param component the component to unregister
      */
     public void unregister(Component component, Map<String, ?> properties) {
-        //try {
-            String name = properties != null ? (String) properties.get(NAME) : null;
-            if (name != null) {
-                components.remove(name);
-            }
-        //} catch (JBIException e) {
-        //    throw new ServiceMixException(e);
-        //}
+        String name = properties != null ? (String) properties.get(NAME) : null;
+        if (name != null) {
+            components.remove(name);
+        }
     }
 
     public Component getComponent(String name) {

Added: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/utils/DOMUtil.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/utils/DOMUtil.java?rev=611600&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/utils/DOMUtil.java
(added)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/utils/DOMUtil.java
Sun Jan 13 09:17:30 2008
@@ -0,0 +1,264 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.runtime.impl.utils;
+
+import java.io.StringWriter;
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.xml.sax.SAXException;
+
+/**
+ * A collection of W3C DOM helper methods
+ *
+ * @version $Revision: 564607 $
+ */
+public final class DOMUtil {
+    
+    private static final Log LOG = LogFactory.getLog(DOMUtil.class);
+    private static DocumentBuilderFactory dbf;
+    private static Queue builders = new ConcurrentLinkedQueue();
+
+    
+    private DOMUtil() {
+    }
+
+    /**
+     * Returns the text of the element
+     */
+    public static String getElementText(Element element) {
+        StringBuffer buffer = new StringBuffer();
+        NodeList nodeList = element.getChildNodes();
+        for (int i = 0; i < nodeList.getLength(); i++) {
+            Node node = nodeList.item(i);
+            if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE)
{
+                buffer.append(node.getNodeValue());
+            }
+        }
+        return buffer.toString();
+    }
+
+    /**
+     * Moves the content of the given element to the given element
+     */
+    public static void moveContent(Element from, Element to) {
+        // lets move the child nodes across
+        NodeList childNodes = from.getChildNodes();
+        while (childNodes.getLength() > 0) {
+            Node node = childNodes.item(0);
+            from.removeChild(node);
+            to.appendChild(node);
+        }
+    }
+
+    /**
+     * Copy the attribues on one element to the other
+     */
+    public static void copyAttributes(Element from, Element to) {
+        // lets copy across all the remainingattributes
+        NamedNodeMap attributes = from.getAttributes();
+        for (int i = 0; i < attributes.getLength(); i++) {
+            Attr node = (Attr) attributes.item(i);
+            to.setAttributeNS(node.getNamespaceURI(), node.getName(), node.getValue());
+        }
+    }
+
+    /**
+     * A helper method useful for debugging and logging which will convert the given DOM
node into XML text
+     */
+    public static String asXML(Node node) throws TransformerException {
+        Transformer transformer = TransformerFactory.newInstance().newTransformer();
+        StringWriter buffer = new StringWriter();
+        transformer.transform(new DOMSource(node), new StreamResult(buffer));
+        return buffer.toString();
+    }
+
+    /**
+     * A helper method useful for debugging and logging which will convert the given DOM
node into XML text
+     */
+    public static String asIndentedXML(Node node) throws TransformerException {
+        Transformer transformer = TransformerFactory.newInstance().newTransformer();
+        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+        StringWriter buffer = new StringWriter();
+        transformer.transform(new DOMSource(node), new StreamResult(buffer));
+        return buffer.toString();
+    }
+
+    /**
+     * Adds the child element with the given text
+     */
+    public static void addChildElement(Element element, String name, Object textValue) {
+        Document document = element.getOwnerDocument();
+        Element child = document.createElement(name);
+        element.appendChild(child);
+        if (textValue != null) {
+            String text = textValue.toString();
+            child.appendChild(document.createTextNode(text));
+        }
+    }
+
+    /**
+     * Creates a QName instance from the given namespace context for the given qualifiedName
+     *
+     * @param element       the element to use as the namespace context
+     * @param qualifiedName the fully qualified name
+     * @return the QName which matches the qualifiedName
+     */
+    public static QName createQName(Element element, String qualifiedName) {
+        int index = qualifiedName.indexOf(':');
+        if (index >= 0) {
+            String prefix = qualifiedName.substring(0, index);
+            String localName = qualifiedName.substring(index + 1);
+            String uri = recursiveGetAttributeValue(element, "xmlns:" + prefix);
+            return new QName(uri, localName, prefix);
+        } else {
+            String uri = recursiveGetAttributeValue(element, "xmlns");
+            if (uri != null) {
+                return new QName(uri, qualifiedName);
+            }
+            return new QName(qualifiedName);
+        }
+    }
+
+    /**
+     * Recursive method to find a given attribute value
+     */
+    public static String recursiveGetAttributeValue(Element element, String attributeName)
{
+        String answer = null;
+        try {
+            answer = element.getAttribute(attributeName);
+        } catch (Exception e) {
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Caught exception looking up attribute: " + attributeName + " on
element: " + element + ". Cause: " + e, e);
+            }
+        }
+        if (answer == null || answer.length() == 0) {
+            Node parentNode = element.getParentNode();
+            if (parentNode instanceof Element) {
+                return recursiveGetAttributeValue((Element) parentNode, attributeName);
+            }
+        }
+        return answer;
+    }
+
+    /**
+     * Get the first child element
+     * @param parent
+     * @return
+     */
+    public static Element getFirstChildElement(Node parent) {
+        NodeList childs = parent.getChildNodes();
+        for (int i = 0; i < childs.getLength(); i++) {
+            Node child = childs.item(i);
+            if (child instanceof Element) {
+                return (Element) child;
+            }
+        }
+        return null;
+    }
+    
+    /**
+     * Get the next sibling element
+     * @param el
+     * @return
+     */
+    public static Element getNextSiblingElement(Element el) {
+        for (Node n = el.getNextSibling(); n != null; n = n.getNextSibling()) {
+            if (n instanceof Element) {
+                return (Element) n;
+            }
+        }
+        return null;
+    }
+    
+    /**
+     * Build a QName from the element name
+     * @param el
+     * @return
+     */
+    public static QName getQName(Element el) {
+        if (el == null) {
+            return null;
+        } else if (el.getPrefix() != null) {
+            return new QName(el.getNamespaceURI(), el.getLocalName(), el.getPrefix());
+        } else {
+            return new QName(el.getNamespaceURI(), el.getLocalName());
+        }
+    }
+
+    public static DocumentBuilder getBuilder() throws ParserConfigurationException {
+        DocumentBuilder builder = (DocumentBuilder) builders.poll();
+        if (builder == null) {
+            if (dbf == null) {
+                dbf = DocumentBuilderFactory.newInstance();
+                dbf.setNamespaceAware(true);
+            }
+            builder = dbf.newDocumentBuilder();
+        }
+        return builder;
+    }
+
+    public static void releaseBuilder(DocumentBuilder builder) {
+        if (builder != null) {
+            builders.add(builder);
+        }
+    }
+
+    /**
+     * Return a new document, ready to populate.
+     * @return
+     * @throws ParserConfigurationException
+     */
+    public static Document newDocument() throws ParserConfigurationException {
+        DocumentBuilder builder = getBuilder();
+        Document doc = builder.newDocument();
+        releaseBuilder(builder);
+        return doc;
+    }
+
+    public static Document parseDocument(InputStream is) throws IOException, SAXException,
ParserConfigurationException {
+        DocumentBuilder builder = getBuilder();
+        try {
+            return builder.parse(is);
+        } finally {
+            releaseBuilder(builder);
+        }
+    }
+
+}

Added: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/utils/URIResolver.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/utils/URIResolver.java?rev=611600&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/utils/URIResolver.java
(added)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/utils/URIResolver.java
Sun Jan 13 09:17:30 2008
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.runtime.impl.utils;
+
+import javax.jbi.component.ComponentContext;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+import org.w3c.dom.Text;
+
+public class URIResolver {
+
+    public static DocumentFragment createWSAEPR(String uri) {
+        Document doc;
+        try {
+            doc = DOMUtil.newDocument();            
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        DocumentFragment epr = doc.createDocumentFragment();
+        Element root = doc.createElement("epr");
+        Element address = doc.createElementNS(WSAddressingConstants.WSA_NAMESPACE_200508,

+                                              WSAddressingConstants.WSA_PREFIX + ":" + WSAddressingConstants.EL_ADDRESS);
+        Text txt = doc.createTextNode(uri);
+        address.appendChild(txt);
+        root.appendChild(address);
+        epr.appendChild(root);
+        return epr;
+    }
+    
+    /**
+     * Configure a JBI exchange with the given URI as the target
+     * 
+     * @param exchange the exchange to configure
+     * @param context a component context used to resolve endpoints
+     * @param uri the target uri
+     */
+    public static void configureExchange(MessageExchange exchange, ComponentContext context,
String uri) {
+        if (exchange == null) {
+            throw new NullPointerException("exchange is null");
+        }
+        if (context == null) {
+            throw new NullPointerException("context is null");
+        }
+        if (uri == null) {
+            throw new NullPointerException("uri is null");
+        }
+        if (uri.startsWith("interface:")) {
+            String uri2 = uri.substring(10);
+            String[] parts = URIResolver.split2(uri2);
+            exchange.setInterfaceName(new QName(parts[0], parts[1]));
+        } else if (uri.startsWith("operation:")) {
+            String uri2 = uri.substring(10);
+            String[] parts = URIResolver.split3(uri2);
+            exchange.setInterfaceName(new QName(parts[0], parts[1]));
+            exchange.setOperation(new QName(parts[0], parts[2]));
+        } else if (uri.startsWith("service:")) {
+            String uri2 = uri.substring(8);
+            String[] parts = URIResolver.split2(uri2);
+            exchange.setService(new QName(parts[0], parts[1]));
+        } else if (uri.startsWith("endpoint:")) {
+            String uri2 = uri.substring(9);
+            String[] parts = URIResolver.split3(uri2);
+            ServiceEndpoint se = context.getEndpoint(new QName(parts[0], parts[1]), parts[2]);
+            exchange.setEndpoint(se);
+        } else {
+            DocumentFragment epr = URIResolver.createWSAEPR(uri);
+            ServiceEndpoint se = context.resolveEndpointReference(epr);
+            exchange.setEndpoint(se);
+        }
+    }
+    
+    public static String[] split3(String uri) {
+        char sep;
+        uri = uri.trim();
+        if (uri.indexOf('/') > 0) {
+            sep = '/';
+        } else {
+            sep = ':';
+        }
+        int idx1 = uri.lastIndexOf(sep);
+        int idx2 = uri.lastIndexOf(sep, idx1 - 1);
+        if (idx1 < 0 || idx2 < 0) {
+            throw new IllegalArgumentException("Bad syntax: expected [part0][sep][part1][sep][part2]");
+        }
+        String epName = uri.substring(idx1 + 1);
+        String svcName = uri.substring(idx2 + 1, idx1);
+        String nsUri   = uri.substring(0, idx2);
+        return new String[] {nsUri, svcName, epName };
+    }
+    
+    public static String[] split2(String uri) {
+        char sep;
+        uri = uri.trim();
+        if (uri.indexOf('/') > 0) {
+            sep = '/';
+        } else {
+            sep = ':';
+        }
+        int idx1 = uri.lastIndexOf(sep);
+        if (idx1 < 0) {
+            throw new IllegalArgumentException("Bad syntax: expected [part0][sep][part1]");
+        }
+        String svcName = uri.substring(idx1 + 1);
+        String nsUri   = uri.substring(0, idx1);
+        return new String[] {nsUri, svcName };
+    }
+    
+}

Added: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/utils/WSAddressingConstants.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/utils/WSAddressingConstants.java?rev=611600&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/utils/WSAddressingConstants.java
(added)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/utils/WSAddressingConstants.java
Sun Jan 13 09:17:30 2008
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.runtime.impl.utils;
+
+public interface WSAddressingConstants {
+
+    String WSA_NAMESPACE_200303 = "http://schemas.xmlsoap.org/ws/2003/03/addressing";
+    String WSA_NAMESPACE_200403 = "http://schemas.xmlsoap.org/ws/2004/03/addressing";
+    String WSA_NAMESPACE_200408 = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
+    String WSA_NAMESPACE_200508 = "http://www.w3.org/2005/08/addressing";
+    
+    String WSA_PREFIX = "wsa";
+    
+    String EL_ACTION = "Action";
+    String EL_ADDRESS = "Address";
+    String EL_FAULT_TO = "FaultTo";
+    String EL_FROM = "From";
+    String EL_MESSAGE_ID = "MessageID";
+    String EL_METADATA = "Metadata";
+    String EL_REFERENCE_PARAMETERS = "ReferenceParameters";
+    String EL_RELATES_TO = "RelatesTo";
+    String EL_REPLY_TO = "ReplyTo";
+    String EL_TO = "To";
+
+}

Modified: servicemix/smx4/nmr/trunk/nmr/osgi/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/osgi/pom.xml?rev=611600&r1=611599&r2=611600&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/osgi/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/nmr/osgi/pom.xml Sun Jan 13 09:17:30 2008
@@ -83,7 +83,7 @@
                     <instructions>
                         <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
                         <Import-Package>org.apache.servicemix.nmr.api,org.apache.servicemix.nmr.core</Import-Package>
-                        <Spring-Context>*;publish-context:=false;create-asynchronously:=false</Spring-Context>
+                        <Spring-Context>*;publish-context:=false;create-asynchronously:=true</Spring-Context>
                     </instructions>
                 </configuration>
             </plugin>



Mime
View raw message