Author: gnodet
Date: Fri Jan 4 11:59:35 2008
New Revision: 608976
URL: http://svn.apache.org/viewvc?rev=608976&view=rev
Log:
Handle endpoint descriptions, jbi endpoint queries and other things
Added:
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/DocumentRepository.java
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/Resource.java
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/DocumentRepositoryImpl.java
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/XmlUtils.java
servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/impl/
servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/impl/DocumentRepositoryImplTest.java
Removed:
servicemix/smx4/nmr/trunk/jbi/offline/src/test/resources/org.apache.servicemix.api-4.0-SNAPSHOT.jar
Modified:
servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/JbiCommandSupport.java
servicemix/smx4/nmr/trunk/jbi/deployer/pom.xml
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractBundleWatcher.java
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/JBIDeploymentListener.java
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/META-INF/spring/servicemix-jbi-deployer.xml
servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/META-INF/spring/servicemix-jbi.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/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/DeliveryChannelImpl.java
servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/EndpointRegistry.java
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/EndpointRegistryImpl.java
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ExchangeImpl.java
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/InternalEndpointWrapper.java
Modified:
servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/JbiCommandSupport.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/JbiCommandSupport.java?rev=608976&r1=608975&r2=608976&view=diff
==============================================================================
---
servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/JbiCommandSupport.java
(original)
+++
servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/JbiCommandSupport.java
Fri Jan 4 11:59:35 2008
@@ -31,8 +31,6 @@
*/
public abstract class JbiCommandSupport extends OsgiCommandSupport {
- protected List<ServiceReference> usedReferences;
-
protected List<SharedLibrary> getSharedLibraries() throws Exception {
return getAllServices(SharedLibrary.class, null);
}
@@ -59,46 +57,6 @@
return assemblies.get(0);
}
return null;
- }
-
- public Object doExecute(final Object... args) throws Exception {
- try {
- return super.doExecute(args);
- } finally {
- ungetServices();
- }
- }
-
- protected <T> List<T> getAllServices(Class<T> clazz, String filter) throws
Exception {
- ServiceReference[] references =
getBundleContext().getAllServiceReferences(clazz.getName(), filter);
- if (references == null) {
- return null;
- }
- List<T> services = new ArrayList<T>();
- for (ServiceReference ref : references) {
- T t = getService(clazz, ref);
- services.add(t);
- }
- return services;
- }
-
- protected <T> T getService(Class<T> clazz, ServiceReference reference) {
- T t = (T) getBundleContext().getService(reference);
- if (t != null) {
- if (usedReferences == null) {
- usedReferences = new ArrayList<ServiceReference>();
- }
- usedReferences.add(reference);
- }
- return t;
- }
-
- protected void ungetServices() {
- if (usedReferences != null) {
- for (ServiceReference ref : usedReferences) {
- getBundleContext().ungetService(ref);
- }
- }
}
}
Modified: servicemix/smx4/nmr/trunk/jbi/deployer/pom.xml
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/pom.xml?rev=608976&r1=608975&r2=608976&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/pom.xml Fri Jan 4 11:59:35 2008
@@ -90,6 +90,7 @@
<Private-Package>org.apache.xbean*</Private-Package>
<Export-Package>${pom.artifactId}*</Export-Package>
<DynamicImport-Package>*</DynamicImport-Package>
+
<Spring-Context>*;publish-context:=false;create-asynchronously:=false</Spring-Context>
</instructions>
</configuration>
</plugin>
Modified:
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractBundleWatcher.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractBundleWatcher.java?rev=608976&r1=608975&r2=608976&view=diff
==============================================================================
---
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractBundleWatcher.java
(original)
+++
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractBundleWatcher.java
Fri Jan 4 11:59:35 2008
@@ -45,9 +45,6 @@
}
public void afterPropertiesSet() throws Exception {
-
- bundleContext.registerService(DeploymentListener.class.getName(), new
JBIDeploymentListener(), null);
-
bundleContext.addBundleListener(bundleListener = new
SynchronousBundleListener() {
public void bundleChanged(BundleEvent event) {
switch (event.getType()) {
Modified:
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java?rev=608976&r1=608975&r2=608976&view=diff
==============================================================================
---
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
(original)
+++
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
Fri Jan 4 11:59:35 2008
@@ -79,7 +79,7 @@
services = new ConcurrentHashMap<Bundle, List<ServiceRegistration>>();
pendingBundles = new ArrayList<Bundle>();
// TODO: control that using properties
- jbiRootDir = new File(System.getProperty("servicemix.base"), "jbi");
+ jbiRootDir = new File(System.getProperty("servicemix.base"),
"data/jbi");
jbiRootDir.mkdirs();
}
Modified:
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/JBIDeploymentListener.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/JBIDeploymentListener.java?rev=608976&r1=608975&r2=608976&view=diff
==============================================================================
---
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/JBIDeploymentListener.java
(original)
+++
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/JBIDeploymentListener.java
Fri Jan 4 11:59:35 2008
@@ -41,16 +41,25 @@
private static final Log Logger =
LogFactory.getLog(JBIDeploymentListener.class);
public boolean canHandle(File artifact) {
- if (!artifact.getName().endsWith(".zip")) {
- return false;
- }
try {
+ // Accept jars and zips
+ if (!artifact.getName().endsWith(".zip") &&
+ !artifact.getName().endsWith(".jar")) {
+ return false;
+ }
JarFile jar = new JarFile(artifact);
JarEntry entry = jar.getJarEntry("META-INF/jbi.xml");
- if (entry == null) {
+ // Only handle JBI artifacts
+ if (entry == null) {
return false;
}
- return true;
+ // Only handle non OSGi bundles
+ Manifest m = jar.getManifest();
+ if (m.getMainAttributes().getValue(new
Attributes.Name("Bundle-SymbolicName")) != null &&
+ m.getMainAttributes().getValue(new
Attributes.Name("Bundle-Version")) != null) {
+ return false;
+ }
+ return true;
} catch (Exception e) {
return false;
}
Modified:
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/META-INF/spring/servicemix-jbi-deployer.xml
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/META-INF/spring/servicemix-jbi-deployer.xml?rev=608976&r1=608975&r2=608976&view=diff
==============================================================================
---
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/META-INF/spring/servicemix-jbi-deployer.xml
(original)
+++
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/META-INF/spring/servicemix-jbi-deployer.xml
Fri Jan 4 11:59:35 2008
@@ -33,4 +33,9 @@
<bean id="deployer"
class="org.apache.servicemix.jbi.deployer.impl.Deployer">
</bean>
+ <!-- Deployment listener -->
+ <bean id="listener"
class="org.apache.servicemix.jbi.deployer.impl.JBIDeploymentListener" />
+
+ <osgi:service ref="listener"
interface="org.apache.servicemix.runtime.filemonitor.DeploymentListener" />
+
</beans>
Modified:
servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/META-INF/spring/servicemix-jbi.xml
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/META-INF/spring/servicemix-jbi.xml?rev=608976&r1=608975&r2=608976&view=diff
==============================================================================
---
servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/META-INF/spring/servicemix-jbi.xml
(original)
+++
servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/META-INF/spring/servicemix-jbi.xml
Fri Jan 4 11:59:35 2008
@@ -32,6 +32,11 @@
<!-- JBI Component Registry -->
<bean id="componentRegistry"
class="org.apache.servicemix.jbi.runtime.impl.ComponentRegistryImpl">
<property name="nmr" ref="nmr" />
+ <property name="documentRepository" ref="documentRepository" />
+ </bean>
+
+ <!-- URL handler for in memory documents -->
+ <bean id="documentRepository"
class="org.apache.servicemix.jbi.runtime.impl.DocumentRepositoryImpl">
</bean>
<!-- Service tracker for JBI components -->
@@ -50,6 +55,17 @@
<osgi:interfaces>
<value>org.apache.servicemix.jbi.runtime.ComponentRegistry</value>
</osgi:interfaces>
+ </osgi:service>
+
+ <!-- Expose the Document Registry / URL Handler -->
+ <osgi:service ref="documentRepository" >
+ <osgi:interfaces>
+ <value>org.apache.servicemix.jbi.runtime.DocumentRepository</value>
+ <value>org.osgi.service.url.URLStreamHandlerService</value>
+ </osgi:interfaces>
+ <osgi:service-properties>
+ <entry key="url.handler.protocol" value="document" />
+ </osgi:service-properties>
</osgi:service>
</beans>
Modified: servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml?rev=608976&r1=608975&r2=608976&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml Fri Jan 4 11:59:35 2008
@@ -57,6 +57,12 @@
</exclusions>
</dependency>
<dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${felix.osgi.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.apache.servicemix</groupId>
<artifactId>servicemix-common</artifactId>
<version>${smx3.version}</version>
Added:
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/DocumentRepository.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/DocumentRepository.java?rev=608976&view=auto
==============================================================================
---
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/DocumentRepository.java
(added)
+++
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/DocumentRepository.java
Fri Jan 4 11:59:35 2008
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+/**
+ * Registers an existing document so that it can be accessed from OSGi using
the given url.
+ */
+public interface DocumentRepository {
+
+ String register(Resource res);
+
+ String register(InputStream is) throws IOException;
+
+ String register(byte[] data);
+
+ void unregister(String url);
+
+}
Added:
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/Resource.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/Resource.java?rev=608976&view=auto
==============================================================================
---
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/Resource.java
(added)
+++
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/Resource.java
Fri Jan 4 11:59:35 2008
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * A resource which is capable of creating an input stream
+ */
+public interface Resource {
+
+ InputStream open() throws IOException;
+
+}
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=608976&r1=608975&r2=608976&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
Fri Jan 4 11:59:35 2008
@@ -16,6 +16,9 @@
*/
package org.apache.servicemix.jbi.runtime.impl;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -35,11 +38,13 @@
import javax.management.MBeanServer;
import javax.naming.InitialContext;
import javax.xml.namespace.QName;
+import javax.xml.transform.dom.DOMSource;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.apache.servicemix.jbi.runtime.ComponentRegistry;
+import org.apache.servicemix.jbi.runtime.DocumentRepository;
import org.apache.servicemix.nmr.api.Endpoint;
import org.apache.servicemix.nmr.api.Exchange;
import org.apache.servicemix.nmr.api.NMR;
@@ -56,6 +61,7 @@
public int DEFAULT_QUEUE_CAPACITY = 100;
private NMR nmr;
+ private DocumentRepository documentRepository;
private Component component;
private Map<String,?> properties;
private BlockingQueue<Exchange> queue;
@@ -64,8 +70,9 @@
private EndpointImpl componentEndpoint;
private String name;
- public ComponentContextImpl(NMR nmr, Component component, Map<String,?>
properties) {
+ public ComponentContextImpl(NMR nmr, DocumentRepository
documentRepository, Component component, Map<String,?> properties) {
this.nmr = nmr;
+ this.documentRepository = documentRepository;
this.component = component;
this.properties = properties;
this.endpoints = new ArrayList<EndpointImpl>();
@@ -82,16 +89,22 @@
}
public synchronized ServiceEndpoint activateEndpoint(QName serviceName,
String endpointName) throws JBIException {
- 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);
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);
+ }
nmr.getEndpointRegistry().register(endpoint, props);
- return endpoint;
+ return new SimpleServiceEndpoint(props, endpoint);
}
public synchronized void deactivateEndpoint(ServiceEndpoint endpoint)
throws JBIException {
@@ -120,20 +133,65 @@
return dc;
}
- public ServiceEndpoint getEndpoint(QName service, String name) {
- return null; //To change body of implemented methods use File |
Settings | File Templates.
+ public ServiceEndpoint getEndpoint(QName serviceName, String endpointName)
{
+ Map<String, Object> props = new HashMap<String, Object>();
+ props.put(Endpoint.SERVICE_NAME, serviceName);
+ props.put(Endpoint.ENDPOINT_NAME, endpointName);
+ List<Endpoint> endpoints = nmr.getEndpointRegistry().query(props);
+ if (endpoints.isEmpty()) {
+ return null;
+ }
+ Map<String, ?> p =
nmr.getEndpointRegistry().getProperties(endpoints.get(0));
+ return new SimpleServiceEndpoint(p);
}
public Document getEndpointDescriptor(ServiceEndpoint endpoint) throws
JBIException {
+ if (endpoint instanceof SimpleServiceEndpoint) {
+ Map<String, ?> props = ((SimpleServiceEndpoint)
endpoint).getProperties();
+ String url = (String) props.get(Endpoint.WSDL_URL);
+ if (url != null) {
+ InputStream is = null;
+ try {
+ is = new URL(url).openStream();
+ return XmlUtils.parseDocument(is);
+ } catch (Exception e) {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e2) {
+ // Ignore
+ }
+ }
+ }
+ }
+ }
return null; //To change body of implemented methods use File |
Settings | File Templates.
}
public ServiceEndpoint[] getEndpoints(QName interfaceName) {
- return new ServiceEndpoint[0]; //To change body of implemented
methods use File | Settings | File Templates.
+ Map<String, Object> props = new HashMap<String, Object>();
+ props.put(Endpoint.INTERFACE_NAME, interfaceName);
+ return internalQueryEndpoints(props);
+ }
+
+ protected SimpleServiceEndpoint[] internalQueryEndpoints(Map<String,
Object> props) {
+ List<Endpoint> endpoints = nmr.getEndpointRegistry().query(props);
+ List<ServiceEndpoint> ses = new ArrayList<ServiceEndpoint>();
+ for (Endpoint endpoint : endpoints) {
+ Map<String, ?> epProps =
nmr.getEndpointRegistry().getProperties(endpoint);
+ QName serviceName = (QName) epProps.get(Endpoint.SERVICE_NAME);
+ String endpointName = (String) epProps.get(Endpoint.ENDPOINT_NAME);
+ if (serviceName != null && endpointName != null) {
+ ses.add(new SimpleServiceEndpoint(epProps));
+ }
+ }
+ return ses.toArray(new SimpleServiceEndpoint[ses.size()]);
}
public ServiceEndpoint[] getEndpointsForService(QName serviceName) {
- return new ServiceEndpoint[0]; //To change body of implemented
methods use File | Settings | File Templates.
+ Map<String, Object> props = new HashMap<String, Object>();
+ props.put(Endpoint.SERVICE_NAME, serviceName);
+ return internalQueryEndpoints(props);
}
public ServiceEndpoint[] getExternalEndpoints(QName interfaceName) {
@@ -170,5 +228,44 @@
public String getWorkspaceRoot() {
return null; //To change body of implemented methods use File |
Settings | File Templates.
+ }
+
+ protected static class SimpleServiceEndpoint implements ServiceEndpoint {
+
+ private Map<String, ?> properties;
+ private EndpointImpl endpoint;
+
+ public SimpleServiceEndpoint(Map<String, ?> properties) {
+ this.properties = properties;
+ }
+
+ public SimpleServiceEndpoint(Map<String, ?> properties, EndpointImpl
endpoint) {
+ this.properties = properties;
+ this.endpoint = endpoint;
+ }
+
+ public Map<String, ?> getProperties() {
+ return properties;
+ }
+
+ public EndpointImpl getEndpoint() {
+ return endpoint;
+ }
+
+ public DocumentFragment getAsReference(QName operationName) {
+ return null; //To change body of implemented methods use File |
Settings | File Templates.
+ }
+
+ public String getEndpointName() {
+ return (String) properties.get(Endpoint.ENDPOINT_NAME);
+ }
+
+ public QName[] getInterfaces() {
+ return new QName[0]; //To change body of implemented methods use
File | Settings | File Templates.
+ }
+
+ public QName getServiceName() {
+ return (QName) properties.get(Endpoint.SERVICE_NAME);
+ }
}
}
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=608976&r1=608975&r2=608976&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
Fri Jan 4 11:59:35 2008
@@ -16,8 +16,8 @@
*/
package org.apache.servicemix.jbi.runtime.impl;
-import java.util.Map;
import java.util.HashMap;
+import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.jbi.JBIException;
@@ -25,6 +25,7 @@
import javax.jbi.component.ComponentContext;
import org.apache.servicemix.jbi.runtime.ComponentRegistry;
+import org.apache.servicemix.jbi.runtime.DocumentRepository;
import org.apache.servicemix.nmr.api.NMR;
import org.apache.servicemix.nmr.api.ServiceMixException;
import org.apache.servicemix.nmr.core.ServiceRegistryImpl;
@@ -39,6 +40,7 @@
public class ComponentRegistryImpl extends ServiceRegistryImpl<Component>
implements ComponentRegistry {
private NMR nmr;
+ private DocumentRepository documentRepository;
private Map<String, Component> components;
public ComponentRegistryImpl() {
@@ -53,6 +55,14 @@
this.nmr = nmr;
}
+ public DocumentRepository getDocumentRepository() {
+ return documentRepository;
+ }
+
+ public void setDocumentRepository(DocumentRepository documentRepository) {
+ this.documentRepository = documentRepository;
+ }
+
/**
* Register a service with the given metadata.
*
@@ -69,7 +79,7 @@
properties = new HashMap<String, Object>();
}
String name = (String) properties.get(NAME);
- ComponentContext context = new ComponentContextImpl(nmr,
component, properties);
+ ComponentContext context = new ComponentContextImpl(nmr,
documentRepository, component, properties);
component.getLifeCycle().init(context);
if (name != null) {
components.put(name, component);
Modified:
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/DeliveryChannelImpl.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/DeliveryChannelImpl.java?rev=608976&r1=608975&r2=608976&view=diff
==============================================================================
---
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/DeliveryChannelImpl.java
(original)
+++
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/DeliveryChannelImpl.java
Fri Jan 4 11:59:35 2008
@@ -177,7 +177,8 @@
if (exchange.getTarget() == null) {
Map<String, Object> props = new HashMap<String, Object>();
if (messageExchange.getEndpoint() != null) {
- // TODO: handle explicit addressing
+ props.put(Endpoint.SERVICE_NAME,
messageExchange.getEndpoint().getServiceName());
+ props.put(Endpoint.ENDPOINT_NAME,
messageExchange.getEndpoint().getEndpointName());
} else {
QName serviceName = messageExchange.getService();
if (serviceName != null) {
Added:
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/DocumentRepositoryImpl.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/DocumentRepositoryImpl.java?rev=608976&view=auto
==============================================================================
---
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/DocumentRepositoryImpl.java
(added)
+++
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/DocumentRepositoryImpl.java
Fri Jan 4 11:59:35 2008
@@ -0,0 +1,97 @@
+/*
+ * 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;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.servicemix.jbi.runtime.DocumentRepository;
+import org.apache.servicemix.jbi.runtime.Resource;
+import org.osgi.service.url.AbstractURLStreamHandlerService;
+
+/**
+ * Simple document repository
+ */
+public class DocumentRepositoryImpl extends AbstractURLStreamHandlerService
implements DocumentRepository {
+
+ public static final String PROTOCOL = "document";
+ public static final String PROTOCOL_COLUMN = PROTOCOL + ":";
+
+ private volatile long index = 0;
+ private Map<Long, Resource> documents = new ConcurrentHashMap<Long,
Resource>();
+
+ public String register(InputStream in) throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] buffer = new byte[8192];
+ int len = in.read(buffer);
+ while (len >= 0) {
+ out.write(buffer, 0, len);
+ len = in.read(buffer);
+ }
+ out.close();
+ return register(out.toByteArray());
+ }
+
+ public String register(final byte[] data) {
+ return register(new Resource() {
+ public InputStream open() throws IOException {
+ return new ByteArrayInputStream(data);
+ }
+ });
+
+ }
+
+ public String register(Resource res) {
+ long idx = ++index;
+ documents.put(idx, res);
+ return PROTOCOL + ":" + idx;
+ }
+
+ public void unregister(String url) {
+ if (url.startsWith(PROTOCOL_COLUMN)) {
+ String idx = url.substring(PROTOCOL_COLUMN.length());
+ documents.remove(Long.parseLong(idx));
+ }
+ }
+
+ public URLConnection openConnection(URL url) throws IOException {
+ return new URLConnection(url) {
+ @Override
+ public void connect() throws IOException {
+ }
+ @Override
+ public InputStream getInputStream() throws IOException {
+ connect();
+ Long idx = Long.parseLong(getURL().getPath());
+ Resource res = documents.get(idx);
+ if (res == null) {
+ throw new FileNotFoundException(getURL().toString());
+ }
+ return res.open();
+ }
+ };
+ }
+
+}
Added:
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/XmlUtils.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/XmlUtils.java?rev=608976&view=auto
==============================================================================
---
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/XmlUtils.java
(added)
+++
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/XmlUtils.java
Fri Jan 4 11:59:35 2008
@@ -0,0 +1,69 @@
+/*
+ * 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;
+
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.io.IOException;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+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.Document;
+import org.w3c.dom.Node;
+
+import org.xml.sax.SAXException;
+
+/**
+ * Utility class for Xml
+ */
+public class XmlUtils {
+
+ public static String toString(Node node) {
+ try {
+ Transformer transformer =
TransformerFactory.newInstance().newTransformer();
+ StringWriter buffer = new StringWriter();
+ transformer.transform(new DOMSource(node), new
StreamResult(buffer));
+ return buffer.toString();
+ } catch (TransformerException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static Document parseDocument(InputStream is) {
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ return dbf.newDocumentBuilder().parse(is);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } catch (ParserConfigurationException e) {
+ throw new RuntimeException(e);
+ } catch (SAXException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
Added:
servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/impl/DocumentRepositoryImplTest.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/impl/DocumentRepositoryImplTest.java?rev=608976&view=auto
==============================================================================
---
servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/impl/DocumentRepositoryImplTest.java
(added)
+++
servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/impl/DocumentRepositoryImplTest.java
Fri Jan 4 11:59:35 2008
@@ -0,0 +1,48 @@
+/*
+ * 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;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import junit.framework.TestCase;
+import org.apache.servicemix.jbi.runtime.DocumentRepository;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gnodet
+ * Date: Jan 4, 2008
+ * Time: 4:44:37 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class DocumentRepositoryImplTest extends TestCase {
+
+ private DocumentRepository repository;
+
+ protected void setUp() {
+ repository = new DocumentRepositoryImpl();
+ }
+
+ public void testRegisterUnregister() throws Exception {
+ byte[] data = new byte[] { 1, 2, 3, 4 };
+
+ String url = repository.register(data);
+ assertNotNull(url);
+ assertTrue(url.startsWith(DocumentRepositoryImpl.PROTOCOL_COLUMN));
+
+ }
+}
Modified:
servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/EndpointRegistry.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/EndpointRegistry.java?rev=608976&r1=608975&r2=608976&view=diff
==============================================================================
---
servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/EndpointRegistry.java
(original)
+++
servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/EndpointRegistry.java
Fri Jan 4 11:59:35 2008
@@ -16,11 +16,12 @@
*/
package org.apache.servicemix.nmr.api;
-import org.apache.servicemix.nmr.api.service.ServiceRegistry;
+import java.util.List;
+import java.util.Map;
import org.w3c.dom.Document;
-import java.util.Map;
+import org.apache.servicemix.nmr.api.service.ServiceRegistry;
/**
* The Registry is used to register endpoints, unregister them, query endpoints
@@ -47,15 +48,26 @@
* In an OSGi world, this would be performed automatically by a
ServiceTracker.
*
* @param endpoint the endpoint to unregister
+ * @param properties the metadata associated with this endpoint
*/
void unregister(Endpoint endpoint, Map<String, ?> properties);
/**
+ * Query the registry for a list of registered endpoints.
+ *
+ * @param properties filtering data
+ * @return the list of endpoints matching the filters
+ */
+ List<Endpoint> query(Map<String, ?> properties);
+
+ /**
* From a given amount of metadata which could include interface name,
service name
* policy data and so forth, choose an available endpoint reference to use
* for invocations.
*
* This could return actual endpoints, or a dynamic proxy to a number of
endpoints
+ *
+ * @param properties filtering data
*/
Reference lookup(Map<String, ?> properties);
Modified:
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/EndpointRegistryImpl.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/EndpointRegistryImpl.java?rev=608976&r1=608975&r2=608976&view=diff
==============================================================================
---
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/EndpointRegistryImpl.java
(original)
+++
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/EndpointRegistryImpl.java
Fri Jan 4 11:59:35 2008
@@ -20,6 +20,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
@@ -108,8 +109,9 @@
*
* @return the registered services
*/
+ @SuppressWarnings("unchecked")
public Set<Endpoint> getServices() {
- return null; // TODO
+ return (Set<Endpoint>) (Set) registry.getServices();
}
/**
@@ -128,6 +130,18 @@
return registry.getProperties(wrapper);
}
+
+ /**
+ * Query the registry for a list of registered endpoints.
+ *
+ * @param properties filtering data
+ * @return the list of endpoints matching the filters
+ */
+ @SuppressWarnings("unchecked")
+ public List<Endpoint> query(Map<String, ?> properties) {
+ return (List<Endpoint>) (List) internalQuery(properties);
+ }
+
/**
* From a given amount of metadata which could include interface name,
service name
* policy data and so forth, choose an available endpoint reference to use
@@ -136,19 +150,7 @@
* This could return actual endpoints, or a dynamic proxy to a number of
endpoints
*/
public Reference lookup(Map<String, ?> properties) {
- List<InternalEndpoint> endpoints = new ArrayList<InternalEndpoint>();
- for (InternalEndpoint e : registry.getServices()) {
- boolean match = true;
- for (String name : properties.keySet()) {
- if
(!properties.get(name).equals(registry.getProperties(e).get(name))) {
- match = false;
- break;
- }
- }
- if (match) {
- endpoints.add(e);
- }
- }
+ List<InternalEndpoint> endpoints = internalQuery(properties);
if (endpoints.isEmpty()) {
throw new ServiceMixException("No matching endpoints");
}
@@ -165,6 +167,23 @@
public synchronized Reference lookup(Document xml) {
// TODO: implement
return null;
+ }
+
+ protected List<InternalEndpoint> internalQuery(Map<String, ?> properties) {
+ List<InternalEndpoint> endpoints = new ArrayList<InternalEndpoint>();
+ for (InternalEndpoint e : registry.getServices()) {
+ boolean match = true;
+ for (String name : properties.keySet()) {
+ if
(!properties.get(name).equals(registry.getProperties(e).get(name))) {
+ match = false;
+ break;
+ }
+ }
+ if (match) {
+ endpoints.add(e);
+ }
+ }
+ return endpoints;
}
}
Modified:
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ExchangeImpl.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ExchangeImpl.java?rev=608976&r1=608975&r2=608976&view=diff
==============================================================================
---
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ExchangeImpl.java
(original)
+++
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ExchangeImpl.java
Fri Jan 4 11:59:35 2008
@@ -231,7 +231,7 @@
}
public Message getIn(boolean lazyCreate) {
- if (this.in == null) {
+ if (this.in == null && lazyCreate) {
this.in = createMessage();
}
return this.in;
@@ -252,7 +252,7 @@
}
public Message getOut(boolean lazyCreate) {
- if (this.out == null) {
+ if (this.out == null && lazyCreate) {
if (this.pattern != Pattern.InOnly && this.pattern !=
Pattern.RobustInOnly) {
this.out = createMessage();
}
@@ -274,7 +274,7 @@
}
public Message getFault(boolean lazyCreate) {
- if (this.fault == null) {
+ if (this.fault == null && lazyCreate) {
if (this.pattern != Pattern.InOnly) {
this.fault = createMessage();
}
Modified:
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/InternalEndpointWrapper.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/InternalEndpointWrapper.java?rev=608976&r1=608975&r2=608976&view=diff
==============================================================================
---
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/InternalEndpointWrapper.java
(original)
+++
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/InternalEndpointWrapper.java
Fri Jan 4 11:59:35 2008
@@ -38,6 +38,10 @@
return channel;
}
+ public Endpoint getEndpoint() {
+ return endpoint;
+ }
+
/**
* Set the channel so that the endpoint can send exchanges back
* when they are processed or act as a consumer itself.