diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2010-08-09 13:47:15 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2010-08-09 13:47:15 +0000 |
commit | c1b8b3abd0aee06fd2e575a03be290bbfc44ffd3 (patch) | |
tree | 746b7c3641bc7aca4f815a8cea92ba32fc67b401 /sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef | |
parent | 5b5f7b81057e0808e491104e3d89da1f625d9491 (diff) |
TUSCANY-3641 - process an @WebService(wsdlLocation="") annotation by reading the wsdl, identified by the location, from the current contribution. The WSDL is associated with the Java component type service by attaching it to the JavaInterface normalized interface slot. This is not ideal but does allow us to pull things out of the WSDL, such a as policy. The spec state that the component type should have interface.wsdl but this messes up our databinding code which expects the component service to exhibit an interface suitable for the actual implementation.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@983647 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef')
-rw-r--r-- | sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLInterfaceProcessor.java | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLInterfaceProcessor.java b/sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLInterfaceProcessor.java index 4f838e92e8..46a2475fe7 100644 --- a/sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLInterfaceProcessor.java +++ b/sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLInterfaceProcessor.java @@ -21,6 +21,9 @@ package org.apache.tuscany.sca.interfacedef.wsdl.xml; import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import java.net.URI; +import java.util.List; + import javax.wsdl.PortType; import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; @@ -28,6 +31,7 @@ import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.assembly.xml.PolicySubjectProcessor; +import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; @@ -362,8 +366,73 @@ public class WSDLInterfaceProcessor extends BaseStAXArtifactProcessor implements */ public void resolve(WSDLInterfaceContract wsdlInterfaceContract, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { Monitor monitor = context.getMonitor(); + + WSDLInterface wsdlInterface = (WSDLInterface)wsdlInterfaceContract.getInterface(); + + // if the contract has a location but no WSDL definition yet we need to read the WSDL + // from the specified location and create an interface based on the first port type + // this is required if the user uses the @WebService(wsdlLocatio="") annotation in a + // Java component implementation. + if (wsdlInterfaceContract.getLocation() != null && + wsdlInterface.getWsdlDefinition() == null){ + + WSDLDefinition wsdlDefinition = null; + + URI wsdlFileURI = null; + + try { + wsdlFileURI = new URI(wsdlInterfaceContract.getLocation()); + } catch (Exception ex) { + ex.printStackTrace(); + // TODO - raise error + } + + if (wsdlFileURI.isAbsolute()){ + // use the wsdli:wsdlLocation mechanism in the WSDLModelResolver to + // load the WSDL from an absolute location + wsdlDefinition = wsdlFactory.createWSDLDefinition(); + wsdlDefinition.setUnresolved(true); + wsdlDefinition.setNamespace("nonamespace"); + wsdlDefinition.getWsdliLocations().put("nonamespace", wsdlInterfaceContract.getLocation()); + } else { + // Find the wsdl in the contribution ready for further resolution + try { + URI contributionLocation = new URI(context.getContribution().getLocation()); + URI wsdlLocation = contributionLocation.resolve(wsdlFileURI); + for (Artifact artifact : context.getContribution().getArtifacts()) { + // TODO - SL a hack while I work out if the bigger picture will hang together + // need more intelligence when applying a relative URI to an existing URI. + if (artifact.getLocation().endsWith(wsdlInterfaceContract.getLocation())){ + //URI artifactLocation = new URI(artifact.getLocation()).normalize(); + //if (artifactLocation.equals(wsdlLocation)){ + wsdlDefinition = artifact.getModel(); + break; + //} + } + } + + } catch (Exception ex) { + ex.printStackTrace(); + // TODO - raise error + } + } + + if (wsdlDefinition == null){ + // TODO raise an error + } + + wsdlInterface.setWsdlDefinition(wsdlDefinition); + PortType portType = (PortType)wsdlDefinition.getDefinition().getAllPortTypes().values().iterator().next(); + if(portType != null){ + wsdlInterface.setName(portType.getQName()); + } else { + // raise an error + } + + } + // Resolve the interface and callback interface - WSDLInterface wsdlInterface = resolveWSDLInterface((WSDLInterface)wsdlInterfaceContract.getInterface(), resolver, context); + wsdlInterface = resolveWSDLInterface(wsdlInterface, resolver, context); wsdlInterfaceContract.setInterface(wsdlInterface); // The forward interface (portType) may have a callback interface declared on it using an sca:callback attribute |