servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r399877 - in /incubator/servicemix/trunk/servicemix-core/src: main/java/org/apache/servicemix/jbi/resolver/ test/java/org/apache/servicemix/jbi/config/ test/resources/org/apache/servicemix/jbi/config/
Date Thu, 04 May 2006 23:06:37 GMT
Author: gnodet
Date: Thu May  4 16:06:36 2006
New Revision: 399877

URL: http://svn.apache.org/viewcvs?rev=399877&view=rev
Log:
SM-245: Support URIs to address a JBI exchange and resolution of WS-Addressing EPR

Added:
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/resolver/URIResolver.java
    incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/jbi/config/URIRouteTest.java
    incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/jbi/config/example-uri-route.xml

Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/resolver/URIResolver.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/resolver/URIResolver.java?rev=399877&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/resolver/URIResolver.java
(added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/resolver/URIResolver.java
Thu May  4 16:06:36 2006
@@ -0,0 +1,125 @@
+package org.apache.servicemix.jbi.resolver;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+import org.w3c.dom.Text;
+
+public class URIResolver extends EndpointResolverSupport {
+
+    /**
+     * The uri to resolve
+     */
+    private String uri;
+    
+    public URIResolver() {
+    }
+    
+    public URIResolver(String uri) {
+        this.uri = uri;
+    }
+    
+    protected JBIException createServiceUnavailableException() {
+        return new JBIException("Unable to resolve uri: " + uri);
+    }
+
+    public ServiceEndpoint[] resolveAvailableEndpoints(ComponentContext context, MessageExchange
exchange)
+            throws JBIException {
+        if (uri.startsWith("interface:")) {
+            String uri = this.uri.substring(10);
+            String[] parts = split2(uri);
+            return context.getEndpoints(new QName(parts[0], parts[1]));
+        } else if (uri.startsWith("operation:")) {
+            // ignore operation
+            String uri = this.uri.substring(10);
+            String[] parts = split3(uri);
+            return context.getEndpoints(new QName(parts[0], parts[1]));
+        } else if (uri.startsWith("service:")) {
+            String uri = this.uri.substring(8);
+            String[] parts = split2(uri);
+            return context.getEndpointsForService(new QName(parts[0], parts[1]));
+        } else if (uri.startsWith("endpoint:")) {
+            String uri = this.uri.substring(9);
+            String[] parts = split3(uri);
+            ServiceEndpoint se = context.getEndpoint(new QName(parts[0], parts[1]), parts[2]);
+            if (se != null) {
+                return new ServiceEndpoint[] { se };
+            }
+        // Try an EPR resolution
+        } else {
+            DocumentFragment epr = createWSAEPR(uri);
+            ServiceEndpoint se = context.resolveEndpointReference(epr);
+            if (se != null) {
+                return new ServiceEndpoint[] { se };
+            }
+        }
+        return null;
+    }
+
+    /**
+     * @return the uri
+     */
+    public String getUri() {
+        return uri;
+    }
+
+    /**
+     * @param uri the uri to set
+     */
+    public void setUri(String uri) {
+        this.uri = uri;
+    }
+
+    public static DocumentFragment createWSAEPR(String uri) {
+        Document doc;
+        try {
+            doc = new SourceTransformer().createDocument();            
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        DocumentFragment epr = doc.createDocumentFragment();
+        Element root = doc.createElement("epr");
+        Element address = doc.createElementNS("http://www.w3.org/2005/08/addressing", "wsa:Address");
+        Text txt = doc.createTextNode(uri);
+        address.appendChild(txt);
+        root.appendChild(address);
+        epr.appendChild(root);
+        return epr;
+    }
+    
+    public static String[] split3(String uri) {
+        char sep;
+        if (uri.indexOf('/') > 0) {
+            sep = '/';
+        } else {
+            sep = ':';
+        }
+        int idx1 = uri.lastIndexOf(sep);
+        int idx2 = uri.lastIndexOf(sep, idx1 - 1);
+        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;
+        if (uri.indexOf('/') > 0) {
+            sep = '/';
+        } else {
+            sep = ':';
+        }
+        int idx1 = uri.lastIndexOf(sep);
+        String svcName = uri.substring(idx1 + 1);
+        String nsUri   = uri.substring(0, idx1);
+        return new String[] { nsUri, svcName };
+    }
+    
+}

Added: incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/jbi/config/URIRouteTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/jbi/config/URIRouteTest.java?rev=399877&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/jbi/config/URIRouteTest.java
(added)
+++ incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/jbi/config/URIRouteTest.java
Thu May  4 16:06:36 2006
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.config;
+
+import org.apache.servicemix.examples.AbstractSpringTestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+/**
+ * @version $Revision: 376451 $
+ */
+public class URIRouteTest extends AbstractSpringTestSupport {
+
+    protected AbstractXmlApplicationContext createBeanFactory() {
+        return new ClassPathXmlApplicationContext("org/apache/servicemix/jbi/config/example-uri-route.xml");
+    }
+
+}

Added: incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/jbi/config/example-uri-route.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/jbi/config/example-uri-route.xml?rev=399877&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/jbi/config/example-uri-route.xml
(added)
+++ incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/jbi/config/example-uri-route.xml
Thu May  4 16:06:36 2006
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+	   xmlns:foo="http://servicemix.org/cheese/">
+
+	<!-- the JBI container -->
+	<container id="jbi" xmlns="http://servicemix.apache.org/config/1.0">
+		<activationSpecs>
+
+			<activationSpec componentName="sender" 
+							destinationUri="service:http://servicemix.org/cheese//transformer">
+				<component>
+					<SenderComponent xmlns="java://org.apache.servicemix.tck"/>
+				</component>
+			</activationSpec>
+
+			<activationSpec componentName="transformer" 
+							service="foo:transformer"
+							destinationUri="endpoint:http://servicemix.org/cheese//receiver/receiver">
+				<component>
+					<MockServiceComponent xmlns="java://org.apache.servicemix.components.util">
+						<property xmlns="" name="responseProperties">
+							<map>
+								<entry key="foo" value="hello"/>
+								<entry key="someList">
+									<list>
+										<value type="java.lang.Integer">1</value>
+										<value type="java.lang.Integer">2</value>
+										<value type="java.lang.Integer">3</value>
+									</list>
+								</entry>
+							</map>
+						</property>
+						<property xmlns="" name="responseXml">
+							<value><![CDATA[ <hello/> ]]></value>
+						</property>
+					</MockServiceComponent>
+				</component>
+			</activationSpec>
+
+			<activationSpec componentName="receiver" service="foo:receiver" endpoint="receiver">
+				<component>
+					<bean xmlns="" class="org.apache.servicemix.tck.ReceiverComponent" />
+				</component>
+			</activationSpec>
+
+		</activationSpecs>
+	</container>
+
+</beans>



Mime
View raw message