diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2011-05-09 20:27:03 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2011-05-09 20:27:03 +0000 |
commit | 99490e913ff81fd269a6f5e64494f6a0c4a63e80 (patch) | |
tree | 1d02ed42dd5961c0199e8d7e60009c4e0806bd28 | |
parent | 1b830fd16cde7f5c8645e530d68f12faa0607853 (diff) |
Update hazelcast registry to store and use the wsdl interface contract for endpoints in the domain so that remote endpoints include the interface information
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1101207 13f79535-47bb-0310-9956-ffa450edef68
2 files changed, 115 insertions, 3 deletions
diff --git a/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java b/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java index cefbcd73d1..aa9abdf45f 100644 --- a/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java +++ b/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java @@ -19,7 +19,9 @@ package org.apache.tuscany.sca.endpoint.hazelcast; +import java.io.ByteArrayOutputStream; import java.io.FileNotFoundException; +import java.io.StringReader; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collection; @@ -31,6 +33,10 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; import java.util.logging.Logger; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.xml.WSDLReader; +import javax.wsdl.xml.WSDLWriter; import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.AssemblyFactory; @@ -40,11 +46,17 @@ import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.LifeCycleListener; import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract; import org.apache.tuscany.sca.runtime.BaseEndpointRegistry; import org.apache.tuscany.sca.runtime.EndpointRegistry; import org.apache.tuscany.sca.runtime.RuntimeEndpoint; import org.apache.tuscany.sca.runtime.RuntimeProperties; import org.oasisopen.sca.ServiceRuntimeException; +import org.xml.sax.InputSource; import com.hazelcast.config.Config; import com.hazelcast.config.NearCacheConfig; @@ -71,15 +83,15 @@ public class HazelcastEndpointRegistry extends BaseEndpointRegistry implements E private HazelcastInstance hazelcastInstance; protected Map<Object, Object> endpointMap; + protected Map<Object, Object> endpointWsdls; + protected Map<QName, Composite> runningComposites; protected Map<String, Endpoint> localEndpoints = new ConcurrentHashMap<String, Endpoint>(); protected MultiMap<String, String> endpointOwners; - protected Map<QName, Composite> runningComposites; protected AssemblyFactory assemblyFactory; protected Object shutdownMutex = new Object(); protected Properties properties; - public HazelcastEndpointRegistry(ExtensionPointRegistry registry, Properties properties, String endpointRegistryURI, String domainURI) { super(registry, null, endpointRegistryURI, domainURI); this.assemblyFactory = registry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(AssemblyFactory.class); @@ -112,6 +124,7 @@ public class HazelcastEndpointRegistry extends BaseEndpointRegistry implements E endpointMap = imap; endpointOwners = hazelcastInstance.getMultiMap(domainURI + "/EndpointOwners"); + endpointWsdls = hazelcastInstance.getMap(domainURI + "/EndpointWsdls"); // TODO: get going in-JVM first then fix this which needs to serialize/deserialize the composite // runningComposites = hazelcastInstance.getMap(domainURI + "/composites"); @@ -128,6 +141,7 @@ public class HazelcastEndpointRegistry extends BaseEndpointRegistry implements E hazelcastInstance = null; endpointMap = null; endpointOwners = null; + endpointWsdls = null; } } } @@ -233,10 +247,12 @@ public class HazelcastEndpointRegistry extends BaseEndpointRegistry implements E String localMemberAddr = hazelcastInstance.getCluster().getLocalMember().getInetSocketAddress().toString(); String endpointURI = endpoint.getURI(); + String wsdl = getWsdl(endpoint); Transaction txn = hazelcastInstance.getTransaction(); txn.begin(); try { endpointMap.put(endpointURI, endpoint); + endpointWsdls.put(endpointURI, wsdl); endpointOwners.put(localMemberAddr, endpointURI); txn.commit(); } catch (Throwable e) { @@ -247,6 +263,23 @@ public class HazelcastEndpointRegistry extends BaseEndpointRegistry implements E logger.info("Add endpoint - " + endpoint); } + private String getWsdl(Endpoint endpoint) { + WSDLInterfaceContract wsdlIC = (WSDLInterfaceContract)((RuntimeEndpoint)endpoint).getGeneratedWSDLContract(endpoint.getComponentServiceInterfaceContract()); + if (wsdlIC == null) { + return ""; + } + WSDLInterface wsdl = (WSDLInterface)wsdlIC.getInterface(); + WSDLDefinition d = wsdl.getWsdlDefinition(); + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + try { + WSDLWriter writer = javax.wsdl.factory.WSDLFactory.newInstance().newWSDLWriter(); + writer.writeWSDL(d.getDefinition(), outStream); + } catch (Exception e){ + throw new RuntimeException(e); + } + return outStream.toString(); + } + public List<Endpoint> findEndpoint(String uri) { List<Endpoint> foundEndpoints = new ArrayList<Endpoint>(); for (Object v : endpointMap.values()) { @@ -266,6 +299,11 @@ public class HazelcastEndpointRegistry extends BaseEndpointRegistry implements E if (!isLocal(endpoint)) { endpoint.setRemote(true); ((RuntimeEndpoint)endpoint).bind(registry, this); + try { + setNormailizedWSDLContract(endpoint); + } catch (WSDLException e) { + throw new RuntimeException(e); + } } else { // get the local version of the endpoint // this local version won't have been serialized @@ -277,6 +315,25 @@ public class HazelcastEndpointRegistry extends BaseEndpointRegistry implements E } + private void setNormailizedWSDLContract(Endpoint endpoint) throws WSDLException { + String wsdl = endpointWsdls == null ? null : (String)endpointWsdls.get(endpoint.getURI()); + if (wsdl == null || wsdl.length() < 1) { + return; + } + InterfaceContract ic = endpoint.getComponentServiceInterfaceContract(); + WSDLFactory wsdlFactory = registry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(WSDLFactory.class); + WSDLInterfaceContract wsdlIC = wsdlFactory.createWSDLInterfaceContract(); + WSDLInterface wsdlIface = wsdlFactory.createWSDLInterface(); + WSDLDefinition wsdlDef = wsdlFactory.createWSDLDefinition(); + WSDLReader reader = javax.wsdl.factory.WSDLFactory.newInstance().newWSDLReader(); + InputSource inputSource = new InputSource(new StringReader(wsdl)); + Definition def = reader.readWSDL("", inputSource); + wsdlDef.setDefinition(def); + wsdlIface.setWsdlDefinition(wsdlDef); + wsdlIC.setInterface(wsdlIface); + ic.setNormailizedWSDLContract(wsdlIC); + } + private boolean isLocal(Endpoint endpoint) { return localEndpoints.containsKey(endpoint.getURI()); } @@ -306,6 +363,7 @@ public class HazelcastEndpointRegistry extends BaseEndpointRegistry implements E try { endpointOwners.remove(localMemberAddr, endpointURI); endpointMap.remove(endpointURI); + endpointWsdls.remove(endpointURI); txn.commit(); } catch (Throwable e) { txn.rollback(); @@ -373,6 +431,7 @@ public class HazelcastEndpointRegistry extends BaseEndpointRegistry implements E Collection<String> keys = endpointOwners.remove(memberAddr); for (Object k : keys) { endpointMap.remove(k); + endpointWsdls.remove(k); } } } finally { @@ -406,7 +465,6 @@ public class HazelcastEndpointRegistry extends BaseEndpointRegistry implements E } return null; } - @Override public void addRunningComposite(Composite composite) { runningComposites.put(composite.getName(), composite); diff --git a/sca-java-2.x/trunk/modules/domain-hazelcast/src/test/java/org/apache/tuscany/sca/endpoint/hazelcast/MultiRegTestCase.java b/sca-java-2.x/trunk/modules/domain-hazelcast/src/test/java/org/apache/tuscany/sca/endpoint/hazelcast/MultiRegTestCase.java index c4f51d1675..dcdf1a94e0 100644 --- a/sca-java-2.x/trunk/modules/domain-hazelcast/src/test/java/org/apache/tuscany/sca/endpoint/hazelcast/MultiRegTestCase.java +++ b/sca-java-2.x/trunk/modules/domain-hazelcast/src/test/java/org/apache/tuscany/sca/endpoint/hazelcast/MultiRegTestCase.java @@ -30,6 +30,9 @@ import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; import org.apache.tuscany.sca.runtime.RuntimeEndpoint; import org.apache.tuscany.sca.runtime.RuntimeProperties; import org.junit.Assert; @@ -154,10 +157,61 @@ public class MultiRegTestCase { Component comp = assemblyFactory.createComponent(); ep.setComponent(comp); ep.setService(assemblyFactory.createComponentService()); + ep.getService().setInterfaceContract(getIC()); Binding b = scaBindingFactory.createSCABinding(); ep.setBinding(b); ep.setURI(uri); return ep; } + + private InterfaceContract getIC() { + InterfaceContract ic = new JavaInterfaceContract(){ + + public Object clone() throws CloneNotSupportedException { + return null; + } + @Override + public Interface getInterface() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setInterface(Interface callInterface) { + // TODO Auto-generated method stub + + } + + @Override + public Interface getCallbackInterface() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setCallbackInterface(Interface callbackInterface) { + // TODO Auto-generated method stub + + } + + @Override + public InterfaceContract makeUnidirectional(boolean isCallback) { + // TODO Auto-generated method stub + return null; + } + + @Override + public InterfaceContract getNormalizedWSDLContract() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setNormailizedWSDLContract(InterfaceContract wsdlInterfaceContract) { + // TODO Auto-generated method stub + + }}; + return ic; + } } |