On Tue, Aug 9, 2011 at 2:50 PM, Simon Laws <simonsl...@googlemail.com> wrote: > On Tue, Jul 26, 2011 at 7:38 PM, <antel...@apache.org> wrote: >> Author: antelder >> Date: Tue Jul 26 18:38:46 2011 >> New Revision: 1151203 >> >> URL: http://svn.apache.org/viewvc?rev=1151203&view=rev >> Log: >> Add some code to try to convert the wsdl string from the remote endpoint >> back into a WSDLInterfaceContract. This doesn't work properly and throws an >> InvalidWSDLException with some JDKs. Committing as-is to see if anyone has >> any ideas why >> >> Added: >> >> tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/WSDLHelper.java >> Modified: >> >> tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java >> >> tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java >> >> Modified: >> tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java >> URL: >> http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java?rev=1151203&r1=1151202&r2=1151203&view=diff >> ============================================================================== >> --- >> tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java >> (original) >> +++ >> tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java >> Tue Jul 26 18:38:46 2011 >> @@ -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.interfaced >> 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.Ru >> 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 >> 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){ >> >> Added: >> tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/WSDLHelper.java >> URL: >> http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/WSDLHelper.java?rev=1151203&view=auto >> ============================================================================== >> --- >> tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/WSDLHelper.java >> (added) >> +++ >> tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/WSDLHelper.java >> Tue Jul 26 18:38:46 2011 >> @@ -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; >> + } >> +} >> >> Modified: >> tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java >> URL: >> http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java?rev=1151203&r1=1151202&r2=1151203&view=diff >> ============================================================================== >> --- >> tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java >> (original) >> +++ >> tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java >> Tue Jul 26 18:38:46 2011 >> @@ -915,9 +915,9 @@ public class EndpointReferenceBinderImpl >> 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 >> >> >> > > Ant > > Have been looking into this and I have a concern about writing the > WSDL as is as WSDL4J as we have it configured flattens any top level > includes/imports but leaves any nested includes/imports intact. These > will not resolve correctly on the reference side. > > Now this may be a configuration issue (will look at it) but if this is > just how it is we need to pass the interface information via the > registry in some more complete form. An alternative would be to > provide more information in the registry about which contribution owns > the endpoint and hence load the artifacts directly but this is another > layer of complexity which I'd avoid if possible. >
Yep imports will be an issue. As the simple case of wsdl with no imports doesn't work yet though so i didn't code anything for dealing with it yet. ...ant