summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-08-09 13:47:15 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-08-09 13:47:15 +0000
commitc1b8b3abd0aee06fd2e575a03be290bbfc44ffd3 (patch)
tree746b7c3641bc7aca4f815a8cea92ba32fc67b401 /sca-java-2.x
parent5b5f7b81057e0808e491104e3d89da1f625d9491 (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 '')
-rw-r--r--sca-java-2.x/trunk/itest/scdl/src/test/java/org/apache/tuscany/sca/itest/scdl/ValidateDependenciesTestCase.java13
-rw-r--r--sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java3
-rw-r--r--sca-java-2.x/trunk/modules/implementation-java/META-INF/MANIFEST.MF1
-rw-r--r--sca-java-2.x/trunk/modules/implementation-java/pom.xml15
-rw-r--r--sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JAXWSProcessor.java90
-rw-r--r--sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java89
-rw-r--r--sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JAXWSProcessorTestCase.java36
-rw-r--r--sca-java-2.x/trunk/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLInterfaceProcessor.java71
8 files changed, 273 insertions, 45 deletions
diff --git a/sca-java-2.x/trunk/itest/scdl/src/test/java/org/apache/tuscany/sca/itest/scdl/ValidateDependenciesTestCase.java b/sca-java-2.x/trunk/itest/scdl/src/test/java/org/apache/tuscany/sca/itest/scdl/ValidateDependenciesTestCase.java
index 475586f016..e8bdc48eb7 100644
--- a/sca-java-2.x/trunk/itest/scdl/src/test/java/org/apache/tuscany/sca/itest/scdl/ValidateDependenciesTestCase.java
+++ b/sca-java-2.x/trunk/itest/scdl/src/test/java/org/apache/tuscany/sca/itest/scdl/ValidateDependenciesTestCase.java
@@ -31,7 +31,11 @@ import org.junit.Test;
* Uses maven-dependency-plugin config in the pom.xml
*
* Current required jars are:
+ *
+ * activation-1.1.jar
* geronimo-stax-api_1.0_spec-1.0.1.jar
+ * jaxb-api-2.1.jar
+ * jaxb-impl-2.1.12.jar
* jsr181-api-1.0-MR1.jar
* junit-4.8.1.jar
* tuscany-assembly-2.0-SNAPSHOT.jar
@@ -44,13 +48,20 @@ import org.junit.Test;
* tuscany-common-java-2.0-SNAPSHOT.jar
* tuscany-common-xml-2.0-SNAPSHOT.jar
* tuscany-contribution-2.0-SNAPSHOT.jar
+ * tuscany-core-spi-2.0-SNAPSHOT.jar
+ * tuscany-databinding-2.0-SNAPSHOT.jar
+ * tuscany-databinding-jaxb-2.0-SNAPSHOT.jar
* tuscany-deployment-2.0-SNAPSHOT.jar
* tuscany-extensibility-2.0-SNAPSHOT.jar
* tuscany-implementation-java-2.0-SNAPSHOT.jar
* tuscany-interface-java-2.0-SNAPSHOT.jar
+ * tuscany-interface-wsdl-2.0-SNAPSHOT.jar
* tuscany-monitor-2.0-SNAPSHOT.jar
* tuscany-sca-api-2.0-SNAPSHOT.jar
+ * tuscany-xsd-2.0-SNAPSHOT.jar
+ * wsdl4j-1.6.2.jar
* wstx-asl-3.2.4.jar
+ * XmlSchema-1.4.3.jar
*
* TODO: WS binding drags in all runtime
*/
@@ -63,6 +74,6 @@ public class ValidateDependenciesTestCase {
Assert.assertTrue(dependenciesDir.exists());
File[] dependencyFiles = dependenciesDir.listFiles();
- Assert.assertEquals(28, dependencyFiles.length);
+ Assert.assertEquals(30, dependencyFiles.length);
}
}
diff --git a/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java b/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java
index 49de13cddf..ea9aec5238 100644
--- a/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java
+++ b/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java
@@ -292,7 +292,8 @@ public class JavaComponentContextProvider {
Class<?> implClass = instanceFactoryProvider.getImplementationClass();
Method method = JavaInterfaceUtil.findMethod(implClass, operation);
- if( ((JavaOperation) operation).isAsyncServer() ) {
+ if (operation instanceof JavaOperation &&
+ ((JavaOperation) operation).isAsyncServer() ) {
return new JavaAsyncImplementationInvoker(operation, method, component);
} else {
return new JavaImplementationInvoker(operation, method, component);
diff --git a/sca-java-2.x/trunk/modules/implementation-java/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/implementation-java/META-INF/MANIFEST.MF
index 7850a30f48..650e78dbbe 100644
--- a/sca-java-2.x/trunk/modules/implementation-java/META-INF/MANIFEST.MF
+++ b/sca-java-2.x/trunk/modules/implementation-java/META-INF/MANIFEST.MF
@@ -36,6 +36,7 @@ Import-Package: javax.jws,
org.apache.tuscany.sca.interfacedef.java;version="2.0.0",
org.apache.tuscany.sca.interfacedef.java.impl;version="2.0.0";resolution:=optional,
org.apache.tuscany.sca.interfacedef.util;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.wsdl;version="2.0.0",
org.apache.tuscany.sca.monitor;version="2.0.0",
org.apache.tuscany.sca.policy;version="2.0.0",
org.apache.tuscany.sca.policy.util;version="2.0.0",
diff --git a/sca-java-2.x/trunk/modules/implementation-java/pom.xml b/sca-java-2.x/trunk/modules/implementation-java/pom.xml
index 5ea97da3b4..7b4a62e6f6 100644
--- a/sca-java-2.x/trunk/modules/implementation-java/pom.xml
+++ b/sca-java-2.x/trunk/modules/implementation-java/pom.xml
@@ -40,6 +40,12 @@
<artifactId>tuscany-interface-java</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface-wsdl</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ </dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
@@ -83,7 +89,14 @@
<artifactId>tuscany-binding-sca-runtime</artifactId>
<version>2.0-SNAPSHOT</version>
<scope>test</scope>
- </dependency>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-binding-ws</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
diff --git a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JAXWSProcessor.java b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JAXWSProcessor.java
index f8b087662b..dfa3ac0a56 100644
--- a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JAXWSProcessor.java
+++ b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JAXWSProcessor.java
@@ -35,6 +35,9 @@ import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper;
+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.policy.Intent;
import org.apache.tuscany.sca.policy.PolicyFactory;
import org.oasisopen.sca.annotation.Remotable;
@@ -46,16 +49,15 @@ import org.oasisopen.sca.annotation.Remotable;
public class JAXWSProcessor extends BaseJavaClassVisitor {
private PolicyFactory policyFactory;
-
- public JAXWSProcessor(AssemblyFactory assemblyFactory, JavaInterfaceFactory javaFactory, PolicyFactory policyFactory) {
- super(assemblyFactory);
- this.javaInterfaceFactory = javaFactory;
- this.policyFactory = policyFactory;
- }
+ private WSDLFactory wsdlFactory;
public JAXWSProcessor(ExtensionPointRegistry registry) {
super(registry);
- this.policyFactory = registry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(PolicyFactory.class);
+ FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ this.wsdlFactory = factories.getFactory(WSDLFactory.class);
+ this.assemblyFactory = factories.getFactory(AssemblyFactory.class);
+ this.policyFactory = factories.getFactory(PolicyFactory.class);
+ this.javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
}
@Override
@@ -72,22 +74,22 @@ public class JAXWSProcessor extends BaseJavaClassVisitor {
// JCA 11015
}
- WebService webService = clazz.getAnnotation(WebService.class);
+ WebService webServiceAnnotation = clazz.getAnnotation(WebService.class);
+ org.oasisopen.sca.annotation.Service serviceAnnotation = clazz.getAnnotation(org.oasisopen.sca.annotation.Service.class);
String tns = JavaXMLMapper.getNamespace(clazz);
String localName = clazz.getSimpleName();
Class<?> interfaze = clazz;
- if (webService != null) {
- tns = getValue(webService.targetNamespace(), tns);
- localName = getValue(webService.name(), localName);
+ if (webServiceAnnotation != null &&
+ serviceAnnotation == null) {
+ tns = getValue(webServiceAnnotation.targetNamespace(), tns);
+ localName = getValue(webServiceAnnotation.name(), localName);
- String serviceInterfaceName = webService.endpointInterface();
- // TODO - how to resolve this interface name
- // needs to be done higher up where we have
- // access to the resolver.
+ String serviceInterfaceName = webServiceAnnotation.endpointInterface();
+ String wsdlLocation = webServiceAnnotation.wsdlLocation();
Service service;
try {
- service = createService(clazz, interfaze, localName);
+ service = createService(clazz, localName, serviceInterfaceName, wsdlLocation);
} catch (InvalidInterfaceException e) {
throw new IntrospectionException(e);
}
@@ -106,32 +108,48 @@ public class JAXWSProcessor extends BaseJavaClassVisitor {
return "".equals(value) ? defaultValue : value;
}
- public Service createService(Class<?> clazz, Class<?> interfaze, String name) throws InvalidInterfaceException {
+ public Service createService(Class<?> clazz, String serviceName, String javaInterfaceName, String wsdlFileName) throws InvalidInterfaceException, IntrospectionException {
Service service = assemblyFactory.createService();
- JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
- service.setInterfaceContract(interfaceContract);
- if (name == null) {
- service.setName(interfaze.getSimpleName());
+ if (serviceName != null) {
+ service.setName(serviceName);
+ } else if (javaInterfaceName != null){
+ service.setName(javaInterfaceName.substring(javaInterfaceName.lastIndexOf('.')));
+ }
+
+ // create the physical Java interface contract
+ JavaInterfaceContract javaInterfaceContract = javaInterfaceFactory.createJavaInterfaceContract();;
+ service.setInterfaceContract(javaInterfaceContract);
+
+ if (javaInterfaceName != null &&
+ javaInterfaceName.length() > 0){
+ JavaInterface callInterface = javaInterfaceFactory.createJavaInterface();
+ callInterface.setName(javaInterfaceName);
+ callInterface.setRemotable(true);
+ callInterface.setUnresolved(true);
+ javaInterfaceContract.setInterface(callInterface);
} else {
- service.setName(name);
- }
-
- JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(interfaze);
- boolean remotable = clazz.getAnnotation(Remotable.class) != null;
- if (remotable){
+ // we use the bean class as the service interface
+ JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(clazz);
callInterface.setRemotable(true);
+ callInterface.setUnresolved(false); // this will already be false but this makes it easy to follow the logic
+ javaInterfaceContract.setInterface(callInterface);
}
- service.getInterfaceContract().setInterface(callInterface);
- if (callInterface.getCallbackClass() != null) {
- JavaInterface callbackInterface = javaInterfaceFactory.createJavaInterface(callInterface.getCallbackClass());
- if (remotable){
- callbackInterface.setRemotable(true);
- }
- service.getInterfaceContract().setCallbackInterface(callbackInterface);
- }
- return service;
+ // create the logical WSDL interface if it's specified in
+ // the @WebService annotation
+ if (wsdlFileName != null &&
+ wsdlFileName.length() > 0){
+ WSDLInterface callInterface = wsdlFactory.createWSDLInterface();
+ callInterface.setUnresolved(true);
+ callInterface.setRemotable(true);
+
+ WSDLInterfaceContract wsdlInterfaceContract = wsdlFactory.createWSDLInterfaceContract();
+ wsdlInterfaceContract.setInterface(callInterface);
+ wsdlInterfaceContract.setLocation(wsdlFileName);
+ javaInterfaceContract.setNormailizedWSDLContract(wsdlInterfaceContract);
+ }
+ return service;
}
}
diff --git a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java
index efb4a37143..3fdbc19e0e 100644
--- a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java
+++ b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java
@@ -50,14 +50,24 @@ import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.resolver.ClassReference;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+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.implementation.java.IntrospectionException;
import org.apache.tuscany.sca.implementation.java.JavaElementImpl;
import org.apache.tuscany.sca.implementation.java.JavaImplementation;
import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
import org.apache.tuscany.sca.implementation.java.introspect.JavaIntrospectionHelper;
+import org.apache.tuscany.sca.interfacedef.Compatibility;
+import org.apache.tuscany.sca.interfacedef.IncompatibleInterfaceContractException;
import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.monitor.Problem.Severity;
@@ -74,13 +84,18 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
private AssemblyFactory assemblyFactory;
private PolicyFactory policyFactory;
private PolicySubjectProcessor policyProcessor;
-
+ private StAXArtifactProcessor<Object> extensionProcessor;
+ private transient InterfaceContractMapper interfaceContractMapper;
- public JavaImplementationProcessor(FactoryExtensionPoint modelFactories) {
+ public JavaImplementationProcessor(ExtensionPointRegistry registry, StAXArtifactProcessor<?> staxProcessor) {
+ FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
this.policyFactory = modelFactories.getFactory(PolicyFactory.class);
this.javaFactory = modelFactories.getFactory(JavaImplementationFactory.class);
this.policyProcessor = new PolicySubjectProcessor(policyFactory);
+ this.extensionProcessor = (StAXArtifactProcessor<Object>)staxProcessor;
+ UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
+ this.interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class);
}
/**
@@ -190,7 +205,10 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
checkNoStaticAnnotations(monitor, javaImplementation);
+ postJAXWSProcessorResolve(resolver, javaImplementation, context);
+
javaImplementation.setUnresolved(false);
+
mergeComponentType(resolver, javaImplementation, context);
// FIXME the introspector should always create at least one service
@@ -309,6 +327,73 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
}
}
+
+// private void postJAXWSProcessorResolve(ModelResolver resolver, JavaImplementation impl, ProcessorContext context)
+// throws ContributionResolveException {
+// for(Service service : impl.getServices()){
+// InterfaceContract interfaceContract = service.getInterfaceContract();
+//
+// // InterfaceContract not marked as resolved so have to look
+// // at each type and work it out
+// if (interfaceContract instanceof JavaInterfaceContract){
+// JavaInterfaceContract javaInterfaceContract = (JavaInterfaceContract)interfaceContract;
+// JavaInterface javaInterface = (JavaInterface)javaInterfaceContract.getInterface();
+// if (javaInterface.isUnresolved()){
+// extensionProcessor.resolve(javaInterfaceContract, resolver, context);
+// }
+// } else {
+// WSDLInterfaceContract wsdlInterfaceContract = (WSDLInterfaceContract)interfaceContract;
+// WSDLInterface wsdlInterface = (WSDLInterface)wsdlInterfaceContract.getInterface();
+// if (wsdlInterface.isUnresolved()){
+// //WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, wsdlInterface.getWsdlDefinition(), context);
+// extensionProcessor.resolve(wsdlInterfaceContract, resolver, context);
+// }
+// }
+// }
+// }
+
+ private void postJAXWSProcessorResolve(ModelResolver resolver, JavaImplementation impl, ProcessorContext context)
+ throws ContributionResolveException, IncompatibleInterfaceContractException {
+ for(Service service : impl.getServices()){
+ JavaInterfaceContract javaInterfaceContract = (JavaInterfaceContract)service.getInterfaceContract();
+
+ JavaInterface javaInterface = (JavaInterface)javaInterfaceContract.getInterface();
+ if (javaInterface.isUnresolved()){
+ extensionProcessor.resolve(javaInterfaceContract, resolver, context);
+ }
+
+ WSDLInterfaceContract wsdlInterfaceContract = (WSDLInterfaceContract)javaInterfaceContract.getNormalizedWSDLContract();
+ if(wsdlInterfaceContract != null){
+ // The user has explicitly associated a WSDL with the Java implementation
+ // using a @WebService(wsdlLocation="...") annotation
+ WSDLInterface wsdlInterface = (WSDLInterface)wsdlInterfaceContract.getInterface();
+ if (wsdlInterface.isUnresolved()){
+ //WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, wsdlInterface.getWsdlDefinition(), context);
+ extensionProcessor.resolve(wsdlInterfaceContract, resolver, context);
+
+ // check that the Java and WSDL contracts are compatible
+ interfaceContractMapper.checkCompatibility(javaInterfaceContract,
+ wsdlInterfaceContract,
+ Compatibility.MUTUAL,
+ false,
+ false);
+
+ // retrieve the resolved WSDL interface
+ wsdlInterface = (WSDLInterface)wsdlInterfaceContract.getInterface();
+
+ // copy policy from the WSDL interface to the Java interface
+ javaInterface.getPolicySets().addAll(wsdlInterface.getPolicySets());
+ javaInterface.getRequiredIntents().addAll(wsdlInterface.getRequiredIntents());
+
+ // copy policy from the WSDL interface to the component type service
+ service.getPolicySets().addAll(wsdlInterface.getPolicySets());
+ service.getRequiredIntents().addAll(wsdlInterface.getRequiredIntents());
+
+ // TODO - is there anything else to be copied from the user specified WSDL?
+ }
+ }
+ }
+ }
private ComponentType getComponentType(ModelResolver resolver, JavaImplementation impl, ProcessorContext context) {
String className = impl.getJavaClass().getName();
diff --git a/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JAXWSProcessorTestCase.java b/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JAXWSProcessorTestCase.java
index 7fb07713c6..2e6ef50996 100644
--- a/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JAXWSProcessorTestCase.java
+++ b/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JAXWSProcessorTestCase.java
@@ -55,11 +55,19 @@ public class JAXWSProcessorTestCase {
@Before
public void setUp() throws Exception {
ExtensionPointRegistry registry = new DefaultExtensionPointRegistry();
- processor = new JAXWSProcessor(new DefaultAssemblyFactory(), new DefaultJavaInterfaceFactory(registry), new DefaultPolicyFactory());
+ processor = new JAXWSProcessor(registry);
javaImplementationFactory = new DefaultJavaImplementationFactory();
}
@Test
+ public void testWebServiceNoName() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(Foo0Impl.class, type);
+ org.apache.tuscany.sca.assembly.Service service = getService(type, "Foo0Impl");
+ assertNotNull(service);
+ }
+
+ @Test
public void testWebServiceName() throws Exception {
JavaImplementation type = javaImplementationFactory.createJavaImplementation();
processor.visitClass(Foo1Impl.class, type);
@@ -75,6 +83,21 @@ public class JAXWSProcessorTestCase {
assertNotNull(service);
}
+ @Test
+ public void testWebServiceWSDL() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(Foo3Impl.class, type);
+ org.apache.tuscany.sca.assembly.Service service = getService(type, "Foo3");
+ assertNotNull(service);
+ }
+
+ @WebService()
+ private static class Foo0Impl{
+ public String doSomething(String aParam){
+ return null;
+ }
+ }
+
@WebService(name="Foo1")
private static class Foo1Impl{
public String doSomething(String aParam){
@@ -86,12 +109,19 @@ public class JAXWSProcessorTestCase {
public String doSomething(String aParam);
}
- @WebService(name="Foo2", endpointInterface="Foo2")
+ @WebService(name="Foo2", endpointInterface="org.apache.tuscany.sca.implementation.java.introspect.impl.JAXWSProcessorTestCase.Foo2")
private static class Foo2Impl{
public String doSomething(String aParam){
return null;
}
- }
+ }
+
+ @WebService(name="Foo3", wsdlLocation="foo3.wsdl")
+ private static class Foo3Impl{
+ public String doSomething(String aParam){
+ return null;
+ }
+ }
}
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