You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wink.apache.org by bl...@apache.org on 2010/09/10 00:43:21 UTC

svn commit: r995599 - in /incubator/wink/trunk: wink-common/src/test/java/org/apache/wink/common/internal/registry/metadata/ wink-server/src/main/java/org/apache/wink/server/internal/ wink-server/src/main/java/org/apache/wink/server/internal/registry/ ...

Author: bluk
Date: Thu Sep  9 22:43:21 2010
New Revision: 995599

URL: http://svn.apache.org/viewvc?rev=995599&view=rev
Log:
Smarter interpretation of @Consumes/@Produces

Thanks to Raymond Feng for reporting the issue.

See [WINK-286]

Added:
    incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/ServerCustomProperties.java
    incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceDefaultTest.java
    incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceFalseTest.java
    incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceTrueTest.java
    incubator/wink/trunk/wink-server/src/test/resources/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceFalseTest.properties
    incubator/wink/trunk/wink-server/src/test/resources/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceTrueTest.properties
Modified:
    incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/registry/metadata/ResourceMetadataCollectorTest.java
    incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/DeploymentConfiguration.java
    incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRecordFactory.java
    incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java
    incubator/wink/trunk/wink-server/src/main/resources/META-INF/wink-default.properties

Modified: incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/registry/metadata/ResourceMetadataCollectorTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/registry/metadata/ResourceMetadataCollectorTest.java?rev=995599&r1=995598&r2=995599&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/registry/metadata/ResourceMetadataCollectorTest.java (original)
+++ incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/registry/metadata/ResourceMetadataCollectorTest.java Thu Sep  9 22:43:21 2010
@@ -46,6 +46,16 @@ public class ResourceMetadataCollectorTe
         }
     }
 
+    @Path("/myotherresource")
+    @Consumes(MediaType.APPLICATION_XML)
+    @Produces(MediaType.APPLICATION_JSON)
+    public class MyResource2 {
+
+        @GET
+        public void getString() {
+        }
+    }
+
     @Path("superclassvalue")
     public static class SuperResource {
 
@@ -67,14 +77,14 @@ public class ResourceMetadataCollectorTe
     public static class MySuperInterfaceImpl extends SuperResource implements MyInterface {
 
     }
-    
+
     @Path("abstractclass")
     public static abstract class MyAbstractClass {
-        
+
     }
-    
+
     public static class MyBaseClass extends MyAbstractClass {
-        
+
     }
 
     /**
@@ -153,4 +163,26 @@ public class ResourceMetadataCollectorTe
         Set<MediaType> mediaTypes = classMetadata.getResourceMethods().get(0).getProduces();
         assertEquals(3, mediaTypes.size());
     }
+
+    /**
+     * Tests that the classes inherited consumes annotation is found in
+     * ResourceMetadataCollector.
+     */
+    public void testConsumesAnnotationParsingForNoEntityArgument() throws Exception {
+        ClassMetadata classMetadata = ResourceMetadataCollector.collectMetadata(MyResource2.class);
+        Set<MediaType> mediaTypes = classMetadata.getResourceMethods().get(0).getConsumes();
+        assertEquals(mediaTypes.toString(), 1, mediaTypes.size());
+        assertTrue(mediaTypes.toString(), mediaTypes.contains(MediaType.APPLICATION_XML_TYPE));
+    }
+
+    /**
+     * Tests that the classes inherited produces annotation is found in
+     * ResourceMetadataCollector.
+     */
+    public void testProducesAnnotationParsingForNoReturnedEntity() throws Exception {
+        ClassMetadata classMetadata = ResourceMetadataCollector.collectMetadata(MyResource2.class);
+        Set<MediaType> mediaTypes = classMetadata.getResourceMethods().get(0).getProduces();
+        assertEquals(mediaTypes.toString(), 1, mediaTypes.size());
+        assertTrue(mediaTypes.toString(), mediaTypes.contains(MediaType.APPLICATION_JSON_TYPE));
+    }
 }

Modified: incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/DeploymentConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/DeploymentConfiguration.java?rev=995599&r1=995598&r2=995599&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/DeploymentConfiguration.java (original)
+++ incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/DeploymentConfiguration.java Thu Sep  9 22:43:21 2010
@@ -300,7 +300,7 @@ public class DeploymentConfiguration imp
         }
         ApplicationValidator applicationValidator = new ApplicationValidator();
         providersRegistry = new ProvidersRegistry(ofFactoryRegistry, applicationValidator);
-        resourceRegistry = new ResourceRegistry(ofFactoryRegistry, applicationValidator);
+        resourceRegistry = new ResourceRegistry(ofFactoryRegistry, applicationValidator, properties);
     }
 
     /**

Added: incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/ServerCustomProperties.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/ServerCustomProperties.java?rev=995599&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/ServerCustomProperties.java (added)
+++ incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/ServerCustomProperties.java Thu Sep  9 22:43:21 2010
@@ -0,0 +1,52 @@
+/*
+ * 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.wink.server.internal;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+
+public enum ServerCustomProperties {
+
+    /**
+     * A strict interpretation of the {@link Consumes} and {@link Produces}
+     * annotation inheritance. If this is enabled, then resource methods without
+     * an entity parameter will ignore inherited {@link Consumes} values. Also,
+     * resource methods with a "void" return type will ignore the inherited
+     * {@link Produces} values.
+     */
+    STRICT_INTERPRET_CONSUMES_PRODUCES_SPEC_CUSTOM_PROPERTY(
+        "org.apache.wink.server.resources.strictInterpretConsumesAndProduces", "true");
+
+    final private String propertyName;
+    final private String defaultValue;
+
+    private ServerCustomProperties(String propertyName, String defaultValue) {
+        this.propertyName = propertyName;
+        this.defaultValue = defaultValue;
+    }
+
+    public String getPropertyName() {
+        return propertyName;
+    }
+
+    public String getDefaultValue() {
+        return defaultValue;
+    }
+
+}

Modified: incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRecordFactory.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRecordFactory.java?rev=995599&r1=995598&r2=995599&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRecordFactory.java (original)
+++ incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRecordFactory.java Thu Sep  9 22:43:21 2010
@@ -20,20 +20,33 @@
 
 package org.apache.wink.server.internal.registry;
 
+import java.lang.reflect.Method;
 import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
 import org.apache.wink.common.DynamicResource;
 import org.apache.wink.common.RuntimeContext;
 import org.apache.wink.common.internal.i18n.Messages;
 import org.apache.wink.common.internal.lifecycle.LifecycleManagersRegistry;
 import org.apache.wink.common.internal.lifecycle.ObjectFactory;
+import org.apache.wink.common.internal.registry.Injectable;
+import org.apache.wink.common.internal.registry.Injectable.ParamType;
 import org.apache.wink.common.internal.registry.metadata.ClassMetadata;
+import org.apache.wink.common.internal.registry.metadata.MethodMetadata;
 import org.apache.wink.common.internal.registry.metadata.ResourceMetadataCollector;
 import org.apache.wink.common.internal.uritemplate.UriTemplateProcessor;
+import org.apache.wink.server.internal.ServerCustomProperties;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -49,7 +62,14 @@ public class ResourceRecordFactory {
     private Lock                                readersLock;
     private Lock                                writersLock;
 
+    final private boolean                       isStrictConsumesProduces;
+
     public ResourceRecordFactory(LifecycleManagersRegistry lifecycleManagerRegistry) {
+        this(lifecycleManagerRegistry, new Properties());
+    }
+
+    public ResourceRecordFactory(LifecycleManagersRegistry lifecycleManagerRegistry,
+                                 Properties customProperties) {
         if (lifecycleManagerRegistry == null) {
             throw new NullPointerException("lifecycleManagerRegistry"); //$NON-NLS-1$
         }
@@ -58,6 +78,18 @@ public class ResourceRecordFactory {
         ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
         readersLock = readWriteLock.readLock();
         writersLock = readWriteLock.writeLock();
+
+        if (customProperties == null) {
+            customProperties = new Properties();
+        }
+
+        String value =
+            customProperties
+                .getProperty(ServerCustomProperties.STRICT_INTERPRET_CONSUMES_PRODUCES_SPEC_CUSTOM_PROPERTY
+                                 .getPropertyName(),
+                             ServerCustomProperties.STRICT_INTERPRET_CONSUMES_PRODUCES_SPEC_CUSTOM_PROPERTY
+                                 .getDefaultValue());
+        isStrictConsumesProduces = Boolean.valueOf(value);
     }
 
     /**
@@ -190,7 +222,9 @@ public class ResourceRecordFactory {
     }
 
     private ClassMetadata createMetadata(Class<? extends Object> cls) {
-        return ResourceMetadataCollector.collectMetadata(cls);
+        ClassMetadata md = ResourceMetadataCollector.collectMetadata(cls);
+        md = fixConsumesAndProduces(md);
+        return md;
     }
 
     private UriTemplateProcessor createUriTemplateProcessor(ClassMetadata metadata) {
@@ -265,6 +299,83 @@ public class ResourceRecordFactory {
         return classMetadata;
     }
 
+    /**
+     * This method will go through each method and "fix" the method metadata to
+     * "ignore" inherited {@link Consumes} and {@link Produces} annotations when
+     * appropriate. For Produces, if the return type is void, then ignore the
+     * Produces annotation. For Consumes, if there are no entity parameters,
+     * ignore the Consumes annotation.
+     * 
+     * @param classMetadata
+     * @return
+     */
+    ClassMetadata fixConsumesAndProduces(ClassMetadata classMetadata) {
+        logger.trace("fixConsumesAndProduces({}) entry", classMetadata);
+        if (isStrictConsumesProduces) {
+            logger
+                .trace("fixConsumesAndProduces() exit returning because custom property {} is set to true.",
+                       ServerCustomProperties.STRICT_INTERPRET_CONSUMES_PRODUCES_SPEC_CUSTOM_PROPERTY
+                           .getPropertyName());
+            return classMetadata;
+        }
+
+        Set<MediaType> produces = classMetadata.getProduces();
+        Set<MediaType> consumes = classMetadata.getConsumes();
+
+        Set<MethodMetadata> allMethodMetadata = new HashSet<MethodMetadata>();
+        allMethodMetadata.addAll(classMetadata.getResourceMethods());
+        allMethodMetadata.addAll(classMetadata.getSubResourceMethods());
+
+        /*
+         * Ignore subresource locators because a) they have to return a non-void
+         * and b) they aren't allowed to have an entity parameter.
+         */
+
+        /* fix the produces */
+        for (MethodMetadata methodMetadata : allMethodMetadata) {
+            Method method = methodMetadata.getReflectionMethod();
+            if (Void.TYPE.equals(method.getReturnType())) {
+                if (produces.size() > 0 && methodMetadata.getProduces().equals(produces)) {
+                    /*
+                     * let's assume this was inherited now. weird case would be
+                     * they repeated the annotation values in both the class and
+                     * method.
+                     */
+                    methodMetadata.addProduces(MediaType.WILDCARD_TYPE);
+                    logger
+                        .trace("Method has a @Produces value but also a void return type so adding a */* to allow any response: {} ",
+                               methodMetadata);
+                }
+            }
+        }
+
+        /* fix the consumes */
+        for (MethodMetadata methodMetadata : allMethodMetadata) {
+            if (consumes.size() > 0 && methodMetadata.getConsumes().equals(consumes)) {
+                List<Injectable> params = methodMetadata.getFormalParameters();
+                boolean isEntityParamFound = false;
+                for (Injectable p : params) {
+                    if (ParamType.ENTITY.equals(p.getParamType())) {
+                        isEntityParamFound = true;
+                    }
+                }
+                /*
+                 * let's assume this was inherited now. weird case would be they
+                 * repeated the annotation values in both the class and method.
+                 */
+                if (!isEntityParamFound) {
+                    methodMetadata.addConsumes(MediaType.WILDCARD_TYPE);
+                    logger
+                        .trace("Method has a @Consumes value but no entity parameter so adding a */* to allow any request: {} ",
+                               methodMetadata);
+                }
+            }
+        }
+
+        logger.trace("fixConsumesAndProduces() exit returning {}", classMetadata);
+        return classMetadata;
+    }
+
     private static class InstanceObjectFactory<T> implements ObjectFactory<T> {
 
         private final T object;

Modified: incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java?rev=995599&r1=995598&r2=995599&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java (original)
+++ incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java Thu Sep  9 22:43:21 2010
@@ -28,6 +28,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
@@ -61,10 +62,10 @@ import org.slf4j.LoggerFactory;
  * the dispatch method of a request, following the JAX-RS spec.
  */
 public class ResourceRegistry {
-
-    private static final Logger                                                    logger             =
-                                                                                                          LoggerFactory
-                                                                                                              .getLogger(ResourceRegistry.class);
+    
+    private static final Logger                                                    logger                              =
+                                                                                                                           LoggerFactory
+                                                                                                                               .getLogger(ResourceRegistry.class);
 
     private List<ResourceRecord>                                                   rootResources;
 
@@ -74,14 +75,20 @@ public class ResourceRegistry {
     private Lock                                                                   writersLock;
     private final ApplicationValidator                                             applicationValidator;
 
-    private HashMap<Boolean, SoftConcurrentMap<String, ArrayList<ResourceRecord>>> uriToResourceCache =
-                                                                                                          new HashMap<Boolean, SoftConcurrentMap<String, ArrayList<ResourceRecord>>>();
+    private HashMap<Boolean, SoftConcurrentMap<String, ArrayList<ResourceRecord>>> uriToResourceCache                  =
+                                                                                                                           new HashMap<Boolean, SoftConcurrentMap<String, ArrayList<ResourceRecord>>>();
 
     public ResourceRegistry(LifecycleManagersRegistry factoryRegistry,
                             ApplicationValidator applicationValidator) {
+        this(factoryRegistry, applicationValidator, new Properties());
+    }
+
+    public ResourceRegistry(LifecycleManagersRegistry factoryRegistry,
+                            ApplicationValidator applicationValidator,
+                            Properties properties) {
         this.applicationValidator = applicationValidator;
         rootResources = new LinkedList<ResourceRecord>();
-        resourceRecordsFactory = new ResourceRecordFactory(factoryRegistry);
+        resourceRecordsFactory = new ResourceRecordFactory(factoryRegistry, properties);
         ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
         readersLock = readWriteLock.readLock();
         writersLock = readWriteLock.writeLock();

Modified: incubator/wink/trunk/wink-server/src/main/resources/META-INF/wink-default.properties
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/resources/META-INF/wink-default.properties?rev=995599&r1=995598&r2=995599&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/resources/META-INF/wink-default.properties (original)
+++ incubator/wink/trunk/wink-server/src/main/resources/META-INF/wink-default.properties Thu Sep  9 22:43:21 2010
@@ -55,3 +55,10 @@ wink.response.defaultCharset=false
 # true: use highest q-valued Accept-Charset value as the charset in the response Content-Type header
 # false: do not use Accept-Charset values as a default on the response Content-Type header
 wink.response.useAcceptCharset=false
+
+# A strict interpretation of the Consumes and Produces
+# annotation inheritance. If this is enabled, then resource methods without
+# an entity parameter will ignore inherited Consumes values. Also,
+# resource methods with a "void" return type will ignore the inherited
+# Produces values.
+org.apache.wink.server.resources.strictInterpretConsumesAndProduces=false

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceDefaultTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceDefaultTest.java?rev=995599&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceDefaultTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceDefaultTest.java Thu Sep  9 22:43:21 2010
@@ -0,0 +1,86 @@
+/*
+ * 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.wink.server.internal.registry;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+import org.apache.wink.test.mock.MockRequestConstructor;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+/**
+ * Tests a custom property that relaxes the inherited Consumes and Produces from
+ * classes to methods. This tests the default behavior.
+ */
+public class StrictConsumesProducesInheritanceDefaultTest extends MockServletInvocationTest {
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {ResourceSimpleProducesInheritance.class,
+            ResourceSimpleConsumesInheritance.class};
+    }
+
+    @Path("/simpleConsumes")
+    @Consumes("application/json")
+    public static class ResourceSimpleConsumesInheritance {
+
+        @GET
+        public void postSet() {
+            return;
+        }
+
+    }
+
+    @Path("/simpleProduces")
+    @Produces("application/json")
+    public static class ResourceSimpleProducesInheritance {
+
+        @GET
+        public void postSet() {
+            return;
+        }
+
+    }
+
+    public void testFindResourceStrictConsumesInheritance() throws Exception {
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/simpleConsumes",
+                                                        "application/xml",
+                                                        "application/xml",
+                                                        new byte[] {});
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(204, response.getStatus());
+    }
+
+    public void testFindResourceStrictProducesInheritance() throws Exception {
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/simpleProduces",
+                                                        "application/xml",
+                                                        "application/xml",
+                                                        new byte[] {});
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(204, response.getStatus());
+    }
+}

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceFalseTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceFalseTest.java?rev=995599&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceFalseTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceFalseTest.java Thu Sep  9 22:43:21 2010
@@ -0,0 +1,93 @@
+/*
+ * 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.wink.server.internal.registry;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+import org.apache.wink.test.mock.MockRequestConstructor;
+import org.apache.wink.test.mock.TestUtils;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+/**
+ * This is a test with the property turned false for strict interpretation of
+ * inherited Consumes/Produces values. This tests the property set to false.
+ */
+public class StrictConsumesProducesInheritanceFalseTest extends MockServletInvocationTest {
+
+    @Override
+    protected String getPropertiesFile() {
+        return TestUtils.packageToPath(StrictConsumesProducesInheritanceFalseTest.class
+            .getPackage().getName()) + "/StrictConsumesProducesInheritanceFalseTest.properties";
+    }
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {ResourceSimpleProducesInheritance.class,
+            ResourceSimpleConsumesInheritance.class};
+    }
+
+    @Path("/simpleConsumes")
+    @Consumes("application/json")
+    public static class ResourceSimpleConsumesInheritance {
+
+        @GET
+        public void postSet() {
+            return;
+        }
+
+    }
+
+    @Path("/simpleProduces")
+    @Produces("application/json")
+    public static class ResourceSimpleProducesInheritance {
+
+        @GET
+        public void postSet() {
+            return;
+        }
+
+    }
+
+    public void testFindResourceStrictConsumesInheritance() throws Exception {
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/simpleConsumes",
+                                                        "application/xml",
+                                                        "application/xml",
+                                                        new byte[] {});
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(204, response.getStatus());
+    }
+
+    public void testFindResourceStrictProducesInheritance() throws Exception {
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/simpleProduces",
+                                                        "application/xml",
+                                                        "application/xml",
+                                                        new byte[] {});
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(204, response.getStatus());
+    }
+}

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceTrueTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceTrueTest.java?rev=995599&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceTrueTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceTrueTest.java Thu Sep  9 22:43:21 2010
@@ -0,0 +1,94 @@
+/*
+ * 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.wink.server.internal.registry;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+import org.apache.wink.test.mock.MockRequestConstructor;
+import org.apache.wink.test.mock.TestUtils;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+/**
+ * This is a test with the property turned true for strict interpretation of
+ * inherited Consumes/Produces values. This tests the property set to true.
+ */
+public class StrictConsumesProducesInheritanceTrueTest extends MockServletInvocationTest {
+
+    @Override
+    protected String getPropertiesFile() {
+        return TestUtils.packageToPath(StrictConsumesProducesInheritanceTrueTest.class.getPackage()
+            .getName()) + "/StrictConsumesProducesInheritanceFalseTest.properties";
+    }
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {ResourceSimpleProducesInheritance.class,
+            ResourceSimpleConsumesInheritance.class};
+    }
+
+    @Path("/simpleConsumes")
+    @Consumes("application/json")
+    public static class ResourceSimpleConsumesInheritance {
+
+        @GET
+        public void postSet() {
+            return;
+        }
+
+    }
+
+    @Path("/simpleProduces")
+    @Produces("application/json")
+    public static class ResourceSimpleProducesInheritance {
+
+        @GET
+        public void postSet() {
+            return;
+        }
+
+    }
+
+    public void testFindResourceStrictConsumesInheritance() throws Exception {
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/simpleConsumes",
+                                                        "application/xml",
+                                                        "application/xml",
+                                                        new byte[] {});
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(204, response.getStatus());
+    }
+
+    public void testFindResourceStrictProducesInheritance() throws Exception {
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/simpleProduces",
+                                                        "application/xml",
+                                                        "application/xml",
+                                                        new byte[] {});
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(204, response.getStatus());
+    }
+
+}

Added: incubator/wink/trunk/wink-server/src/test/resources/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceFalseTest.properties
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/resources/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceFalseTest.properties?rev=995599&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/resources/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceFalseTest.properties (added)
+++ incubator/wink/trunk/wink-server/src/test/resources/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceFalseTest.properties Thu Sep  9 22:43:21 2010
@@ -0,0 +1,19 @@
+#
+#     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.
+#
+org.apache.wink.server.resources.strictInterpretConsumesAndProduces=false
\ No newline at end of file

Added: incubator/wink/trunk/wink-server/src/test/resources/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceTrueTest.properties
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/resources/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceTrueTest.properties?rev=995599&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/resources/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceTrueTest.properties (added)
+++ incubator/wink/trunk/wink-server/src/test/resources/org/apache/wink/server/internal/registry/StrictConsumesProducesInheritanceTrueTest.properties Thu Sep  9 22:43:21 2010
@@ -0,0 +1,19 @@
+#
+#     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.
+#
+org.apache.wink.server.resources.strictInterpretConsumesAndProduces=true
\ No newline at end of file