summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk/modules')
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java25
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/WSDLHelper.java117
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java6
3 files changed, 124 insertions, 24 deletions
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java
index ba96644134..8e5e3f5dc7 100644
--- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java
@@ -31,9 +31,6 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import javax.wsdl.Definition;
-import javax.wsdl.WSDLException;
-import javax.wsdl.xml.WSDLReader;
import javax.wsdl.xml.WSDLWriter;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
@@ -82,7 +79,6 @@ import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
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.invocation.Interceptor;
@@ -115,7 +111,6 @@ import org.apache.tuscany.sca.runtime.RuntimeWireProcessor;
import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint;
import org.apache.tuscany.sca.work.WorkScheduler;
import org.oasisopen.sca.ServiceRuntimeException;
-import org.xml.sax.InputSource;
/**
* Runtime model for Endpoint that supports java serialization
@@ -1067,24 +1062,12 @@ public class RuntimeEndpointImpl extends EndpointImpl implements RuntimeEndpoint
if (wsdl == null || wsdl.length() < 1) {
return;
}
- try {
- InterfaceContract ic = 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.setNormalizedWSDLContract(wsdlIC);
- } catch (WSDLException e) {
- throw new RuntimeException(e);
+ InterfaceContract ic = getComponentServiceInterfaceContract();
+ if (ic != null) {
+ ic.setNormalizedWSDLContract(WSDLHelper.createWSDLInterfaceContract(registry, wsdl));
}
}
-
+
public InterfaceContract getGeneratedWSDLContract(InterfaceContract interfaceContract) {
if ( interfaceContract.getNormalizedWSDLContract() == null){
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/WSDLHelper.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/WSDLHelper.java
new file mode 100644
index 0000000000..18dd21220b
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/WSDLHelper.java
@@ -0,0 +1,117 @@
+/*
+ * 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.tuscany.sca.core.assembly.impl;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.net.URI;
+
+import javax.wsdl.PortType;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+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.interfacedef.wsdl.impl.InvalidWSDLException;
+
+public class WSDLHelper {
+
+ /**
+ * This creates a WSDLInterfaceContract from a WSDL document
+ * TODO: Presently this writes the wsdl string to a temporary file which is then used by the Tuscany contribution
+ * code to turn the wsdl into the correctly populated Tuscany model objects. There must/should be a way to have
+ * that happen without needing the external file but i've not been able to find the correct configuration to
+ * get that to happen with all the schema objects created correctly.
+ */
+ public static WSDLInterfaceContract createWSDLInterfaceContract(ExtensionPointRegistry registry, String wsdl) {
+ File wsdlFile = null;
+ try {
+
+ wsdlFile = writeToFile(wsdl);
+ System.out.println("wsdl: " + wsdlFile);
+
+ FactoryExtensionPoint fep = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ URLArtifactProcessorExtensionPoint apep = registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ ExtensibleURLArtifactProcessor aproc = new ExtensibleURLArtifactProcessor(apep);
+ ProcessorContext ctx = new ProcessorContext();
+
+ ContributionFactory cf = fep.getFactory(ContributionFactory.class);
+ final Contribution c = cf.createContribution();
+ c.setURI("temp");
+ c.setLocation(wsdlFile.toURI().toURL().toString());
+ c.setModelResolver(new ExtensibleModelResolver(c, registry.getExtensionPoint(ModelResolverExtensionPoint.class), fep));
+
+ WSDLDefinition wd = aproc.read(null, new URI("temp.wsdl"), wsdlFile.toURI().toURL(), ctx, WSDLDefinition.class);
+ c.getModelResolver().addModel(wd, ctx);
+ c.getModelResolver().resolveModel(WSDLDefinition.class, wd, ctx);
+ PortType pt = (PortType)wd.getDefinition().getAllPortTypes().values().iterator().next();
+
+ WSDLFactory wsdlFactory = registry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(WSDLFactory.class);
+ WSDLInterface nwi = wsdlFactory.createWSDLInterface(pt, wd, c.getModelResolver(), null);
+ nwi.setWsdlDefinition(wd);
+ WSDLInterfaceContract wsdlIC = wsdlFactory.createWSDLInterfaceContract();
+ wsdlIC.setInterface(nwi);
+
+ wsdlFile.delete();
+
+ return wsdlIC;
+
+ } catch (InvalidWSDLException e) {
+ //* TODO: Also, this doesn't seem to work reliably and sometimes the schema objects don't get built correctly
+ //* org.apache.tuscany.sca.interfacedef.wsdl.impl.InvalidWSDLException: Element cannot be resolved: {http://sample/}sayHello
+ //* at org.apache.tuscany.sca.interfacedef.wsdl.impl.WSDLOperationIntrospectorImpl$WSDLPart.<init>(WSDLOperationIntrospectorImpl.java:276)
+ //* It seems like it works ok for me with IBM JDK but not with a Sun one
+ // I'm still trying to track this down but committing like this to see if anyone has any ideas
+ e.printStackTrace();
+ return null;
+ } catch(Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (wsdlFile != null) {
+ wsdlFile.delete();
+ }
+ }
+ }
+
+ private static File writeToFile(String wsdl) throws FileNotFoundException, IOException {
+ File f = File.createTempFile("endpoint", ".wsdl");
+ Writer out = new OutputStreamWriter(new FileOutputStream(f));
+ try {
+ out.write(wsdl);
+ }
+ finally {
+ out.close();
+ }
+ return f;
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
index e14c8287d9..99d9cb464f 100644
--- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
@@ -915,9 +915,9 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder {
return true;
}
- // TODO - is there a better test for this. Would have to cast to the
- // correct iface type to get to the resolved flag
- // We need to rely on normailzed interfaces in this case!!
+// // TODO - is there a better test for this. Would have to cast to the
+// // correct iface type to get to the resolved flag
+// // We need to rely on normailzed interfaces in this case!!
if (endpointContract.getInterface().getOperations().size() == 0){
// the interface contract is likely remote but unresolved
// we discussed this on the ML and decided that we could