Author: rfeng
Date: Fri Jul 16 17:49:20 2010
New Revision: 964880

URL: http://svn.apache.org/viewvc?rev=964880&view=rev
Log:
Align the JAX-RS resource class/method checks with the spec
Allow the binding.rest client to issue RPC over GET calls

Added:
    
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/JAXRSHelper.java
   (with props)
Modified:
    
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/DataBindingJAXRSReader.java
    
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/DataBindingJAXRSWriter.java
    
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingInvoker.java
    
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java
    
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatServiceProvider.java
    
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatServiceProvider.java
    
tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/JAXRSJavaInterfaceProcessor.java

Modified: 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/DataBindingJAXRSReader.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/DataBindingJAXRSReader.java?rev=964880&r1=964879&r2=964880&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/DataBindingJAXRSReader.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/DataBindingJAXRSReader.java
 Fri Jul 16 17:49:20 2010
@@ -66,7 +66,10 @@ public class DataBindingJAXRSReader<T> e
         // FIXME: [rfeng] This is a hack to handle application/json
         if (MediaType.APPLICATION_JSON_TYPE.equals(mediaType)) {
             dataBinding = mediaType.toString() + "#" + 
InputStream.class.getName();
-        } else if (MediaType.APPLICATION_XML_TYPE.equals(mediaType) || 
MediaType.TEXT_XML_TYPE.equals(mediaType)) {
+        } else if ("application/x-protobuf".equals(mediaType.toString())) {
+            dataBinding = mediaType.toString() + "#" + 
InputStream.class.getName();
+        }
+        else if (MediaType.APPLICATION_XML_TYPE.equals(mediaType) || 
MediaType.TEXT_XML_TYPE.equals(mediaType)) {
             dataBinding = InputStream.class.getName();
         } else {
             dataBinding = targetDataType.getDataBinding();

Modified: 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/DataBindingJAXRSWriter.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/DataBindingJAXRSWriter.java?rev=964880&r1=964879&r2=964880&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/DataBindingJAXRSWriter.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/DataBindingJAXRSWriter.java
 Fri Jul 16 17:49:20 2010
@@ -69,7 +69,10 @@ public class DataBindingJAXRSWriter<T> e
             dataBinding = mediaType.toString() + "#" + 
OutputStream.class.getName();
         } else if (MediaType.APPLICATION_XML_TYPE.equals(mediaType) || 
MediaType.TEXT_XML_TYPE.equals(mediaType)) {
             dataBinding = OutputStream.class.getName();
-        } else {
+        } else if ("application/x-protobuf".equals(mediaType.toString())) {
+            dataBinding = mediaType.toString() + "#" + 
OutputStream.class.getName();
+        }
+        else {
             dataBinding = dataType.getDataBinding();
             write(entityStream, t, type);
             return;

Added: 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/JAXRSHelper.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/JAXRSHelper.java?rev=964880&view=auto
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/JAXRSHelper.java
 (added)
+++ 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/JAXRSHelper.java
 Fri Jul 16 17:49:20 2010
@@ -0,0 +1,80 @@
+/*
+ * 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.binding.rest.provider;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.Path;
+
+/**
+ * A utility class that deals with JAX-RS annotations
+ */
+public class JAXRSHelper {
+    private JAXRSHelper() {
+
+    }
+
+    /**
+     * A resource class is a Java class that uses JAX-RS annotations to 
implement a corresponding Web resource.
+     * Resource classes are POJOs that have at least one method annotated with 
@Path or a request method designator.
+     * @param cls
+     * @return
+     */
+    public static boolean isJAXRSResource(Class<?> cls) {
+        for (Method method : cls.getMethods()) {
+            if (method.isAnnotationPresent(Path.class)) {
+                return true;
+            }
+            if (isResourceMethod(method)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Root resource class is a resource class annotated with @Path. Root 
resource classes provide the roots of the
+     * resource class tree and provide access to sub-resources
+     * @param cls
+     * @return
+     */
+    public static boolean isJAXRSRootResource(Class<?> cls) {
+        return cls.isAnnotationPresent(Path.class) && isJAXRSResource(cls);
+    }
+
+    public static boolean isResourceMethod(Method method) {
+        for (Annotation a : method.getAnnotations()) {
+            Class<?> annotationType = a.annotationType();
+            if (annotationType == HttpMethod.class) {
+                return true;
+            }
+            // Http method related annotations such as @GET, @POST will have 
itself annotated with
+            // @HttpMethod
+            HttpMethod m = a.annotationType().getAnnotation(HttpMethod.class);
+            if (m != null) {
+                return true;
+            }
+        }
+        return false;
+
+    }
+}

Propchange: 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/JAXRSHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/JAXRSHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingInvoker.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingInvoker.java?rev=964880&r1=964879&r2=964880&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingInvoker.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingInvoker.java
 Fri Jul 16 17:49:20 2010
@@ -43,6 +43,7 @@ import javax.ws.rs.MatrixParam;
 import javax.ws.rs.OPTIONS;
 import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
@@ -107,9 +108,9 @@ public class RESTBindingInvoker implemen
 
     private RestClient createRestClient() {
         ClientConfig config = new ClientConfig();
-        
+
         // configureBasicAuth(config, userName, password);
-        
+
         config.applications(new Application() {
 
             @Override
@@ -127,6 +128,9 @@ public class RESTBindingInvoker implemen
 
         });
         RestClient client = new RestClient(config);
+        
+        // Default to GET for RPC
+        httpMethod = HttpMethod.GET;
 
         for (Map.Entry<Class<?>, String> e : mapping.entrySet()) {
             if (operation.getAttributes().get(e.getKey()) != null) {
@@ -154,12 +158,21 @@ public class RESTBindingInvoker implemen
 
         Object entity = null;
         Object[] args = msg.getBody();
-        
+
         URI uri = URI.create(binding.getURI());
         UriBuilder uriBuilder = UriBuilder.fromUri(uri);
 
         Method method = ((JavaOperation)operation).getJavaMethod();
-        uriBuilder.path(method);
+
+        if (method.isAnnotationPresent(Path.class)) {
+            // Only for resource method
+            uriBuilder.path(method);
+        }
+
+        if (!JAXRSHelper.isResourceMethod(method)) {
+            // This is RPC over GET
+            uriBuilder.replaceQueryParam("method", method.getName());
+        }
 
         Map<String, Object> pathParams = new HashMap<String, Object>();
         Map<String, Object> matrixParams = new HashMap<String, Object>();
@@ -168,8 +181,8 @@ public class RESTBindingInvoker implemen
         Map<String, Object> formParams = new HashMap<String, Object>();
         Map<String, Object> cookieParams = new HashMap<String, Object>();
 
-        boolean isEntity = true;
         for (int i = 0; i < method.getParameterTypes().length; i++) {
+            boolean isEntity = true;
             Annotation[] annotations = method.getParameterAnnotations()[i];
             PathParam pathParam = getAnnotation(annotations, PathParam.class);
             if (pathParam != null) {
@@ -201,7 +214,7 @@ public class RESTBindingInvoker implemen
                 isEntity = false;
                 cookieParams.put(cookieParam.value(), args[i]);
             }
-            if(isEntity) {
+            if (isEntity) {
                 entity = args[i];
             }
         }
@@ -212,10 +225,10 @@ public class RESTBindingInvoker implemen
         for (Map.Entry<String, Object> p : matrixParams.entrySet()) {
             uriBuilder.replaceMatrixParam(p.getKey(), p.getValue());
         }
-        
+
         uri = uriBuilder.buildFromMap(pathParams);
         Resource resource = restClient.resource(uri);
-        
+
         for (Map.Entry<String, Object> p : headerParams.entrySet()) {
             resource.header(p.getKey(), String.valueOf(p.getValue()));
         }
@@ -226,18 +239,18 @@ public class RESTBindingInvoker implemen
         }
 
         resource.contentType(getContentType());
-        resource.accept(getAccepts());        
-        
+        resource.accept(getAccepts());
+
         //handles declarative headers configured on the composite
-        for(HTTPHeader header : binding.getHttpHeaders()) {
+        for (HTTPHeader header : binding.getHttpHeaders()) {
             //treat special headers that need to be calculated
-            if(header.getName().equalsIgnoreCase("Expires")) {
+            if (header.getName().equalsIgnoreCase("Expires")) {
                 GregorianCalendar calendar = new GregorianCalendar();
                 calendar.setTime(new Date());
 
                 calendar.add(Calendar.HOUR, 
Integer.parseInt(header.getValue()));
 
-                resource.header("Expires", 
HTTPCacheContext.RFC822DateFormat.format( calendar.getTime() ));
+                resource.header("Expires", 
HTTPCacheContext.RFC822DateFormat.format(calendar.getTime()));
             } else {
                 //default behaviour to pass the header value to HTTP response
                 resource.header(header.getName(), header.getValue());

Modified: 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java?rev=964880&r1=964879&r2=964880&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java
 Fri Jul 16 17:49:20 2010
@@ -19,8 +19,6 @@
 
 package org.apache.tuscany.sca.binding.rest.provider;
 
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
 import java.net.URI;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -114,7 +112,8 @@ public class RESTServiceBindingProvider 
         if (binding.getOperationSelector() != null) {
             // Configure the interceptors for operation selection
             OperationSelectorProviderFactory osProviderFactory =
-                
(OperationSelectorProviderFactory)providerFactories.getProviderFactory(binding.getOperationSelector().getClass());
+                
(OperationSelectorProviderFactory)providerFactories.getProviderFactory(binding.getOperationSelector()
+                    .getClass());
             if (osProviderFactory != null) {
                 this.osProvider = 
osProviderFactory.createServiceOperationSelectorProvider(endpoint);
             }
@@ -123,16 +122,18 @@ public class RESTServiceBindingProvider 
         if (binding.getRequestWireFormat() != null) {
             // Configure the interceptors for wire format
             WireFormatProviderFactory wfProviderFactory =
-                
(WireFormatProviderFactory)providerFactories.getProviderFactory(binding.getRequestWireFormat().getClass());
+                
(WireFormatProviderFactory)providerFactories.getProviderFactory(binding.getRequestWireFormat()
+                    .getClass());
             if (wfProviderFactory != null) {
                 this.wfProvider = 
wfProviderFactory.createServiceWireFormatProvider(endpoint);
             }
         }
 
-        if (binding.getResponseWireFormat() != null ) {
+        if (binding.getResponseWireFormat() != null) {
             // Configure the interceptors for wire format
             WireFormatProviderFactory wfProviderFactory =
-                
(WireFormatProviderFactory)providerFactories.getProviderFactory(binding.getResponseWireFormat().getClass());
+                
(WireFormatProviderFactory)providerFactories.getProviderFactory(binding.getResponseWireFormat()
+                    .getClass());
             if (wfProviderFactory != null) {
                 this.wfResponseProvider = 
wfProviderFactory.createServiceWireFormatProvider(endpoint);
             }
@@ -143,11 +144,11 @@ public class RESTServiceBindingProvider 
             this.serviceContract = 
(InterfaceContract)service.getInterfaceContract().clone();
 
             // configure data binding
-            if (wfProvider != null ) {
+            if (wfProvider != null) {
                 
wfProvider.configureWireFormatInterfaceContract(serviceContract);
             }
 
-            if(wfResponseProvider != null) {
+            if (wfResponseProvider != null) {
                 
wfResponseProvider.configureWireFormatInterfaceContract(serviceContract);
             }
         } catch (CloneNotSupportedException e) {
@@ -239,7 +240,6 @@ public class RESTServiceBindingProvider 
         return false;
     }
 
-
     /**
      * Register a Tuscany REST Servlet to handle JAX-RS Resources on a binding 
endpoint
      * @return
@@ -251,7 +251,8 @@ public class RESTServiceBindingProvider 
             JavaInterface javaInterface = 
(JavaInterface)endpoint.getComponentServiceInterfaceContract().getInterface();
             Class<?> interfaze = javaInterface.getJavaClass();
 
-            boolean isJAXRS = isJAXRSResource(interfaze);
+            // The @Path annotation can be from the binding uri
+            boolean isJAXRS = JAXRSHelper.isJAXRSResource(interfaze);
             if (isJAXRS) {
                 application = new SimpleApplication(interfaze);
 
@@ -314,7 +315,7 @@ public class RESTServiceBindingProvider 
                 String path = URI.create(uri).getPath();
 
                 // FIXME: [rfeng] We need to have a better way to deal with 
URI template for bindings
-                if(path.startsWith(servletHost.getContextPath())) {
+                if (path.startsWith(servletHost.getContextPath())) {
                     path = 
path.substring(servletHost.getContextPath().length());
                 }
                 Class<?> cls =
@@ -336,24 +337,6 @@ public class RESTServiceBindingProvider 
         }
     }
 
-    public static boolean isJAXRSResource(Class<?> cls) {
-        for (Annotation a : cls.getAnnotations()) {
-            if (a.annotationType().getName().startsWith("javax.ws.rs.")) {
-                return true;
-            }
-        }
-        for (Method method : cls.getMethods()) {
-            for (Annotation a : method.getAnnotations()) {
-                if (a.annotationType().getName().startsWith("javax.ws.rs.")) {
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
-
-
-
     /**
      * Add specific rest interceptor to invocation chain
      */

Modified: 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatServiceProvider.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatServiceProvider.java?rev=964880&r1=964879&r2=964880&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatServiceProvider.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatServiceProvider.java
 Fri Jul 16 17:49:20 2010
@@ -22,7 +22,7 @@ package org.apache.tuscany.sca.binding.r
 import java.util.List;
 
 import org.apache.tuscany.sca.assembly.Binding;
-import org.apache.tuscany.sca.binding.rest.provider.RESTServiceBindingProvider;
+import org.apache.tuscany.sca.binding.rest.provider.JAXRSHelper;
 import org.apache.tuscany.sca.binding.rest.wireformat.json.JSONWireFormat;
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
 import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding;
@@ -60,7 +60,7 @@ public class JSONWireFormatServiceProvid
     private boolean isJAXRSResource() {
         Interface interfaze = 
endpoint.getComponentServiceInterfaceContract().getInterface();
         if (interfaze instanceof JavaInterface) {
-            if 
(RESTServiceBindingProvider.isJAXRSResource(((JavaInterface)interfaze).getJavaClass()))
 {
+            if 
(JAXRSHelper.isJAXRSResource(((JavaInterface)interfaze).getJavaClass())) {
                 return true;
             }
         }

Modified: 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatServiceProvider.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatServiceProvider.java?rev=964880&r1=964879&r2=964880&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatServiceProvider.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatServiceProvider.java
 Fri Jul 16 17:49:20 2010
@@ -24,7 +24,7 @@ import java.util.List;
 import javax.xml.stream.XMLStreamReader;
 
 import org.apache.tuscany.sca.assembly.Binding;
-import org.apache.tuscany.sca.binding.rest.provider.RESTServiceBindingProvider;
+import org.apache.tuscany.sca.binding.rest.provider.JAXRSHelper;
 import org.apache.tuscany.sca.binding.rest.wireformat.xml.XMLWireFormat;
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
 import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding;
@@ -65,7 +65,7 @@ public class XMLWireFormatServiceProvide
     private boolean isJAXRSResource() {
         Interface interfaze = 
endpoint.getComponentServiceInterfaceContract().getInterface();
         if (interfaze instanceof JavaInterface) {
-            if 
(RESTServiceBindingProvider.isJAXRSResource(((JavaInterface)interfaze).getJavaClass()))
 {
+            if 
(JAXRSHelper.isJAXRSResource(((JavaInterface)interfaze).getJavaClass())) {
                 return true;
             }
         }

Modified: 
tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/JAXRSJavaInterfaceProcessor.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/JAXRSJavaInterfaceProcessor.java?rev=964880&r1=964879&r2=964880&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/JAXRSJavaInterfaceProcessor.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/JAXRSJavaInterfaceProcessor.java
 Fri Jul 16 17:49:20 2010
@@ -19,6 +19,7 @@
 
 package org.apache.tuscany.sca.interfacedef.java.jaxrs;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -54,22 +55,26 @@ public class JAXRSJavaInterfaceProcessor
         Method method = operation.getJavaMethod();
 
         String methodName = null;
-        HttpMethod httpMethod = method.getAnnotation(HttpMethod.class);
-        if (httpMethod != null) {
-            methodName = httpMethod.value();
-        }
-        if (method.isAnnotationPresent(GET.class)) {
-            methodName = HttpMethod.GET;
-        } else if (method.isAnnotationPresent(POST.class)) {
-            methodName = HttpMethod.POST;
-        } else if (method.isAnnotationPresent(PUT.class)) {
-            methodName = HttpMethod.PUT;
-        } else if (method.isAnnotationPresent(DELETE.class)) {
-            methodName = HttpMethod.DELETE;
-        } else if (method.isAnnotationPresent(HEAD.class)) {
-            methodName = HttpMethod.HEAD;
-        } else if (method.isAnnotationPresent(OPTIONS.class)) {
-            methodName = HttpMethod.OPTIONS;
+
+        /**
+         * A request method designator is a runtime annotation that is 
annotated with the @HttpMethod annotation.
+         * JAX-RS defines a set of request method designators for the common 
HTTP methods: @GET, @POST, @PUT,
+         * @DELETE, @HEAD. Users may define their own custom request method 
designators including alternate 
+         * designators for the common HTTP methods.
+         */
+        for (Annotation a : method.getAnnotations()) {
+            Class<?> annotationType = a.annotationType();
+            if (annotationType == HttpMethod.class) {
+                methodName = ((HttpMethod)a).value();
+                break;
+            }
+            // Http method related annotations such as @GET, @POST will have 
itself annotated with
+            // @HttpMethod
+            HttpMethod m = a.annotationType().getAnnotation(HttpMethod.class);
+            if (m != null) {
+                methodName = m.value();
+                break;
+            }
         }
 
         boolean jaxrs = false;


Reply via email to