summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/implementation-jaxrs
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2010-05-19 00:53:52 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2010-05-19 00:53:52 +0000
commitd683dc4b30c79348b5e73f0f11b1cfd8ce4b9812 (patch)
tree3b64741b708c3e13a6a301f7df21bec070547bfc /sca-java-2.x/trunk/modules/implementation-jaxrs
parenta0bfd24b7af22df3174e1c1e4e6d2eb913f41d2f (diff)
Merge branch 'jaxrs' into trunk
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@945980 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/implementation-jaxrs')
-rw-r--r--sca-java-2.x/trunk/modules/implementation-jaxrs/META-INF/MANIFEST.MF6
-rw-r--r--sca-java-2.x/trunk/modules/implementation-jaxrs/pom.xml14
-rw-r--r--sca-java-2.x/trunk/modules/implementation-jaxrs/src/main/java/org/apache/tuscany/sca/implementation/jaxrs/impl/JAXRSImplementationImpl.java9
-rw-r--r--sca-java-2.x/trunk/modules/implementation-jaxrs/src/main/java/org/apache/tuscany/sca/implementation/jaxrs/xml/JAXRSImplementationProcessor.java55
4 files changed, 73 insertions, 11 deletions
diff --git a/sca-java-2.x/trunk/modules/implementation-jaxrs/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/implementation-jaxrs/META-INF/MANIFEST.MF
index f768396eb2..b2920bf5a6 100644
--- a/sca-java-2.x/trunk/modules/implementation-jaxrs/META-INF/MANIFEST.MF
+++ b/sca-java-2.x/trunk/modules/implementation-jaxrs/META-INF/MANIFEST.MF
@@ -8,7 +8,9 @@ Bundle-Version: 2.0.0
Bundle-ManifestVersion: 2
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
Bundle-Description: Apache Tuscany SCA Implementation JAXRS Model
-Import-Package: javax.xml.stream;resolution:=optional,
+Import-Package: javax.ws.rs;version="1.0.0",
+ javax.ws.rs.core;version="1.0.0",
+ javax.xml.stream;resolution:=optional,
org.apache.tuscany.sca.assembly;version="2.0.0",
org.apache.tuscany.sca.assembly.builder;version="2.0.0",
org.apache.tuscany.sca.assembly.impl;version="2.0.0",
@@ -18,6 +20,8 @@ Import-Package: javax.xml.stream;resolution:=optional,
org.apache.tuscany.sca.contribution.resolver;version="2.0.0",
org.apache.tuscany.sca.core;version="2.0.0",
org.apache.tuscany.sca.implementation.jaxrs;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.java;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.runtime;version="2.0.0",
diff --git a/sca-java-2.x/trunk/modules/implementation-jaxrs/pom.xml b/sca-java-2.x/trunk/modules/implementation-jaxrs/pom.xml
index 7f5f47f8da..23dce9ab5c 100644
--- a/sca-java-2.x/trunk/modules/implementation-jaxrs/pom.xml
+++ b/sca-java-2.x/trunk/modules/implementation-jaxrs/pom.xml
@@ -57,14 +57,26 @@
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface-java</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-monitor</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-binding-rest</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
- <version>1.0</version>
+ <version>1.1</version>
</dependency>
<dependency>
diff --git a/sca-java-2.x/trunk/modules/implementation-jaxrs/src/main/java/org/apache/tuscany/sca/implementation/jaxrs/impl/JAXRSImplementationImpl.java b/sca-java-2.x/trunk/modules/implementation-jaxrs/src/main/java/org/apache/tuscany/sca/implementation/jaxrs/impl/JAXRSImplementationImpl.java
index 99f6f8df59..4c19f1b52e 100644
--- a/sca-java-2.x/trunk/modules/implementation-jaxrs/src/main/java/org/apache/tuscany/sca/implementation/jaxrs/impl/JAXRSImplementationImpl.java
+++ b/sca-java-2.x/trunk/modules/implementation-jaxrs/src/main/java/org/apache/tuscany/sca/implementation/jaxrs/impl/JAXRSImplementationImpl.java
@@ -18,10 +18,6 @@
*/
package org.apache.tuscany.sca.implementation.jaxrs.impl;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.tuscany.sca.assembly.Service;
import org.apache.tuscany.sca.assembly.impl.ImplementationImpl;
import org.apache.tuscany.sca.implementation.jaxrs.JAXRSImplementation;
@@ -40,11 +36,6 @@ public class JAXRSImplementationImpl extends ImplementationImpl implements JAXRS
super(TYPE);
}
- public List<Service> getServices() {
- // The Web implementation does not offer services
- return Collections.emptyList();
- }
-
public String getApplication() {
return application;
}
diff --git a/sca-java-2.x/trunk/modules/implementation-jaxrs/src/main/java/org/apache/tuscany/sca/implementation/jaxrs/xml/JAXRSImplementationProcessor.java b/sca-java-2.x/trunk/modules/implementation-jaxrs/src/main/java/org/apache/tuscany/sca/implementation/jaxrs/xml/JAXRSImplementationProcessor.java
index 037d8f385a..da25b6edd5 100644
--- a/sca-java-2.x/trunk/modules/implementation-jaxrs/src/main/java/org/apache/tuscany/sca/implementation/jaxrs/xml/JAXRSImplementationProcessor.java
+++ b/sca-java-2.x/trunk/modules/implementation-jaxrs/src/main/java/org/apache/tuscany/sca/implementation/jaxrs/xml/JAXRSImplementationProcessor.java
@@ -20,11 +20,17 @@ package org.apache.tuscany.sca.implementation.jaxrs.xml;
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Application;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.binding.rest.RESTBinding;
+import org.apache.tuscany.sca.binding.rest.RESTBindingFactory;
import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
@@ -37,6 +43,11 @@ import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.implementation.jaxrs.JAXRSImplementation;
import org.apache.tuscany.sca.implementation.jaxrs.JAXRSImplementationFactory;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+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.oasisopen.sca.ServiceRuntimeException;
/**
* Implements a StAX artifact processor for Web implementations.
@@ -45,11 +56,17 @@ public class JAXRSImplementationProcessor extends BaseStAXArtifactProcessor impl
StAXArtifactProcessor<JAXRSImplementation> {
private static final QName IMPLEMENTATION_JAXRS = JAXRSImplementation.TYPE;
+ private AssemblyFactory assemblyFactory;
private JAXRSImplementationFactory implementationFactory;
+ private RESTBindingFactory restBindingFactory;
+ private JavaInterfaceFactory javaInterfaceFactory;
public JAXRSImplementationProcessor(ExtensionPointRegistry extensionPoints) {
FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
+ this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
this.implementationFactory = modelFactories.getFactory(JAXRSImplementationFactory.class);
+ this.restBindingFactory = modelFactories.getFactory(RESTBindingFactory.class);
+ this.javaInterfaceFactory = modelFactories.getFactory(JavaInterfaceFactory.class);
}
public QName getArtifactType() {
@@ -91,6 +108,44 @@ public class JAXRSImplementationProcessor extends BaseStAXArtifactProcessor impl
classReference = resolver.resolveModel(ClassReference.class, classReference, context);
implementation.setApplicationClass(classReference.getJavaClass());
implementation.setUnresolved(false);
+
+ Application application;
+ try {
+ application = (Application) implementation.getApplicationClass().newInstance();
+ } catch (Exception e) {
+ throw new ContributionResolveException(e);
+ }
+
+ for(Class<?> rootResourceClass: application.getClasses()) {
+ addService(implementation, rootResourceClass);
+ }
+ for(Object rootResource: application.getSingletons()) {
+ addService(implementation, rootResource.getClass());
+ }
+
+ }
+
+ private void addService(JAXRSImplementation implementation, Class<?> rootResourceClass) {
+ Service service = assemblyFactory.createService();
+ JavaInterfaceContract contract = javaInterfaceFactory.createJavaInterfaceContract();
+ JavaInterface javaInterface;
+ try {
+ javaInterface = javaInterfaceFactory.createJavaInterface(rootResourceClass);
+ } catch (InvalidInterfaceException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ contract.setInterface(javaInterface);
+ service.setInterfaceContract(contract);
+ RESTBinding binding = restBindingFactory.createRESTBinding();
+ // FIXME: The @ApplicationPath is available for JAX-RS 1.1
+ // binding.setURI("/");
+ Path path = rootResourceClass.getAnnotation(Path.class);
+ if (path != null) {
+ binding.setURI(path.value());
+ }
+ service.getBindings().add(binding);
+ service.setName(rootResourceClass.getSimpleName());
+ implementation.getServices().add(service);
}
public void write(JAXRSImplementation implementation, XMLStreamWriter writer, ProcessorContext context)