Permalink
Browse files

git-svn-id: file:///Users/billburke/jboss/resteasy/resteasy-git/svn-s…

…erver-sync/resteasy/trunk/jaxrs@861 2b1ed4c4-5db3-0410-90e4-80a7a6204c25
  • Loading branch information...
1 parent 4c39d0d commit f7417c73f96f6098c80c55f7e4aadc6f748cd7df patriot1burke committed Oct 30, 2009
Showing with 277 additions and 29 deletions.
  1. +1 −1 examples/spring-hibernate-contacts/client/src/main/sql/hsqldb/contact.properties
  2. +1 −1 examples/spring-hibernate-contacts/persistence/src/main/sql/hsqldb/contact.properties
  3. +23 −0 resteasy-jaxrs/src/main/java/org/jboss/resteasy/annotations/StringParameterUnmarshallerBinder.java
  4. +3 −2 resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/CookieParamInjector.java
  5. +3 −2 resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/FormParamInjector.java
  6. +3 −2 resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/HeaderParamInjector.java
  7. +6 −6 resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/InjectorFactoryImpl.java
  8. +3 −2 resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/MatrixParamInjector.java
  9. +3 −2 resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/PathParamInjector.java
  10. +3 −2 resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/QueryParamInjector.java
  11. +40 −3 resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/StringParameterInjector.java
  12. +30 −4 resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/ThreadLocalResteasyProviderFactory.java
  13. +45 −1 resteasy-jaxrs/src/main/java/org/jboss/resteasy/spi/ResteasyProviderFactory.java
  14. +21 −0 resteasy-jaxrs/src/main/java/org/jboss/resteasy/spi/StringParameterUnmarshaller.java
  15. +91 −0 ...xrs/src/test/java/org/jboss/resteasy/test/finegrain/methodparams/StringParamUnmarshallerTest.java
  16. +1 −1 resteasy-spring/src/main/java/org/jboss/resteasy/springmvc/ResteasyWebArgumentResolver.java
@@ -1,5 +1,5 @@
#HSQL Database Engine 1.8.0.5
-#Fri Oct 30 10:23:29 EDT 2009
+#Fri Oct 30 11:24:18 EDT 2009
hsqldb.script_format=0
runtime.gc_interval=0
sql.enforce_strict_size=false
@@ -1,5 +1,5 @@
#HSQL Database Engine 1.8.0.5
-#Fri Oct 30 10:23:22 EDT 2009
+#Fri Oct 30 11:24:11 EDT 2009
hsqldb.script_format=0
runtime.gc_interval=0
sql.enforce_strict_size=false
@@ -0,0 +1,23 @@
+package org.jboss.resteasy.annotations;
+
+import org.jboss.resteasy.spi.StringParameterUnmarshaller;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Meta-annotation to be placed on another annotation that triggers a StringParameterUnmarshaller to be applied
+ * to a string based annotation injector i.e. @HeaderParam, @PathParam, @QueryParam
+ *
+ * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
+ * @version $Revision: 1 $
+ * @see org.jboss.resteasy.spi.StringParameterUnmarshaller
+ */
+@Target({ElementType.ANNOTATION_TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface StringParameterUnmarshallerBinder
+{
+ Class<? extends StringParameterUnmarshaller> value();
+}
@@ -6,6 +6,7 @@
import javax.ws.rs.CookieParam;
import javax.ws.rs.core.Cookie;
+import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Type;
@@ -16,7 +17,7 @@
public class CookieParamInjector extends StringParameterInjector implements ValueInjector
{
- public CookieParamInjector(Class type, Type genericType, AccessibleObject target, String cookieName, String defaultValue, ResteasyProviderFactory factory)
+ public CookieParamInjector(Class type, Type genericType, AccessibleObject target, String cookieName, String defaultValue, Annotation[] annotations, ResteasyProviderFactory factory)
{
if (type.equals(Cookie.class))
{
@@ -28,7 +29,7 @@ public CookieParamInjector(Class type, Type genericType, AccessibleObject target
}
else
{
- initialize(type, genericType, cookieName, CookieParam.class, defaultValue, target, factory);
+ initialize(type, genericType, cookieName, CookieParam.class, defaultValue, target, annotations, factory);
}
}
@@ -5,6 +5,7 @@
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import javax.ws.rs.FormParam;
+import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Type;
import java.util.List;
@@ -16,9 +17,9 @@
public class FormParamInjector extends StringParameterInjector implements ValueInjector
{
- public FormParamInjector(Class type, Type genericType, AccessibleObject target, String header, String defaultValue, ResteasyProviderFactory factory)
+ public FormParamInjector(Class type, Type genericType, AccessibleObject target, String header, String defaultValue, Annotation[] annotations, ResteasyProviderFactory factory)
{
- super(type, genericType, header, FormParam.class, defaultValue, target, factory);
+ super(type, genericType, header, FormParam.class, defaultValue, target, annotations, factory);
}
public Object inject(HttpRequest request, HttpResponse response)
@@ -5,6 +5,7 @@
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import javax.ws.rs.HeaderParam;
+import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Type;
import java.util.List;
@@ -16,9 +17,9 @@
public class HeaderParamInjector extends StringParameterInjector implements ValueInjector
{
- public HeaderParamInjector(Class type, Type genericType, AccessibleObject target, String header, String defaultValue, ResteasyProviderFactory factory)
+ public HeaderParamInjector(Class type, Type genericType, AccessibleObject target, String header, String defaultValue, Annotation[] annotations, ResteasyProviderFactory factory)
{
- super(type, genericType, header, HeaderParam.class, defaultValue, target, factory);
+ super(type, genericType, header, HeaderParam.class, defaultValue, target, annotations, factory);
}
public Object inject(HttpRequest request, HttpResponse response)
@@ -73,31 +73,31 @@ public static ValueInjector getParameterExtractor(Class injectTargetClass, Acces
if ((query = FindAnnotation.findAnnotation(annotations, QueryParam.class)) != null)
{
- return new QueryParamInjector(type, genericType, injectTarget, query.value(), defaultVal, encode, providerFactory);
+ return new QueryParamInjector(type, genericType, injectTarget, query.value(), defaultVal, encode, annotations, providerFactory);
}
else if ((header = FindAnnotation.findAnnotation(annotations, HeaderParam.class)) != null)
{
- return new HeaderParamInjector(type, genericType, injectTarget, header.value(), defaultVal, providerFactory);
+ return new HeaderParamInjector(type, genericType, injectTarget, header.value(), defaultVal, annotations, providerFactory);
}
else if ((formParam = FindAnnotation.findAnnotation(annotations, FormParam.class)) != null)
{
- return new FormParamInjector(type, genericType, injectTarget, formParam.value(), defaultVal, providerFactory);
+ return new FormParamInjector(type, genericType, injectTarget, formParam.value(), defaultVal, annotations, providerFactory);
}
else if ((cookie = FindAnnotation.findAnnotation(annotations, CookieParam.class)) != null)
{
- return new CookieParamInjector(type, genericType, injectTarget, cookie.value(), defaultVal, providerFactory);
+ return new CookieParamInjector(type, genericType, injectTarget, cookie.value(), defaultVal, annotations, providerFactory);
}
else if ((uriParam = FindAnnotation.findAnnotation(annotations, PathParam.class)) != null)
{
- return new PathParamInjector(type, genericType, injectTarget, uriParam.value(), defaultVal, encode, providerFactory);
+ return new PathParamInjector(type, genericType, injectTarget, uriParam.value(), defaultVal, encode, annotations, providerFactory);
}
else if ((form = FindAnnotation.findAnnotation(annotations, Form.class)) != null)
{
return new FormInjector(type, providerFactory);
}
else if ((matrix = FindAnnotation.findAnnotation(annotations, MatrixParam.class)) != null)
{
- return new MatrixParamInjector(type, genericType, injectTarget, matrix.value(), defaultVal, providerFactory);
+ return new MatrixParamInjector(type, genericType, injectTarget, matrix.value(), defaultVal, annotations, providerFactory);
}
else if ((suspend = FindAnnotation.findAnnotation(annotations, Suspend.class)) != null)
{
@@ -6,6 +6,7 @@
import javax.ws.rs.MatrixParam;
import javax.ws.rs.core.PathSegment;
+import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Type;
import java.util.ArrayList;
@@ -17,9 +18,9 @@
*/
public class MatrixParamInjector extends StringParameterInjector implements ValueInjector
{
- public MatrixParamInjector(Class type, Type genericType, AccessibleObject target, String paramName, String defaultValue, ResteasyProviderFactory factory)
+ public MatrixParamInjector(Class type, Type genericType, AccessibleObject target, String paramName, String defaultValue, Annotation[] annotations, ResteasyProviderFactory factory)
{
- super(type, genericType, paramName, MatrixParam.class, defaultValue, target, factory);
+ super(type, genericType, paramName, MatrixParam.class, defaultValue, target, annotations, factory);
}
public Object inject(HttpRequest request, HttpResponse response)
@@ -9,6 +9,7 @@
import javax.ws.rs.PathParam;
import javax.ws.rs.core.PathSegment;
+import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Type;
import java.util.ArrayList;
@@ -28,7 +29,7 @@
private boolean pathSegmentArray = false;
private boolean pathSegmentList = false;
- public PathParamInjector(Class type, Type genericType, AccessibleObject target, String paramName, String defaultValue, boolean encode, ResteasyProviderFactory factory)
+ public PathParamInjector(Class type, Type genericType, AccessibleObject target, String paramName, String defaultValue, boolean encode, Annotation[] annotations, ResteasyProviderFactory factory)
{
this.type = type;
if (isPathSegmentArray(type))
@@ -45,7 +46,7 @@ else if (type.equals(PathSegment.class))
}
else
{
- extractor = new StringParameterInjector(type, genericType, paramName, PathParam.class, defaultValue, target, factory);
+ extractor = new StringParameterInjector(type, genericType, paramName, PathParam.class, defaultValue, target, annotations, factory);
}
this.paramName = paramName;
this.encode = encode;
@@ -7,6 +7,7 @@
import javax.ws.rs.QueryParam;
import java.io.UnsupportedEncodingException;
+import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Type;
import java.net.URLDecoder;
@@ -21,9 +22,9 @@
private boolean encode;
private String encodedName;
- public QueryParamInjector(Class type, Type genericType, AccessibleObject target, String paramName, String defaultValue, boolean encode, ResteasyProviderFactory factory)
+ public QueryParamInjector(Class type, Type genericType, AccessibleObject target, String paramName, String defaultValue, boolean encode, Annotation[] annotations, ResteasyProviderFactory factory)
{
- super(type, genericType, paramName, QueryParam.class, defaultValue, target, factory);
+ super(type, genericType, paramName, QueryParam.class, defaultValue, target, annotations, factory);
this.encode = encode;
try
{
@@ -1,12 +1,15 @@
package org.jboss.resteasy.core;
+import org.jboss.resteasy.annotations.StringParameterUnmarshallerBinder;
import org.jboss.resteasy.spi.BadRequestException;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.spi.StringConverter;
+import org.jboss.resteasy.spi.StringParameterUnmarshaller;
import org.jboss.resteasy.util.StringToPrimitive;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.ext.RuntimeDelegate;
+import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
@@ -39,24 +42,25 @@
protected Class<? extends Collection> collectionType;
protected AccessibleObject target;
protected StringConverter converter;
+ protected StringParameterUnmarshaller unmarshaller;
protected RuntimeDelegate.HeaderDelegate delegate;
public StringParameterInjector()
{
}
- public StringParameterInjector(Class type, Type genericType, String paramName, Class paramType, String defaultValue, AccessibleObject target, ResteasyProviderFactory factory)
+ public StringParameterInjector(Class type, Type genericType, String paramName, Class paramType, String defaultValue, AccessibleObject target, Annotation[] annotations, ResteasyProviderFactory factory)
{
- initialize(type, genericType, paramName, paramType, defaultValue, target, factory);
+ initialize(type, genericType, paramName, paramType, defaultValue, target, annotations, factory);
}
public boolean isCollectionOrArray()
{
return isCollection || type.isArray();
}
- protected void initialize(Class type, Type genericType, String paramName, Class paramType, String defaultValue, AccessibleObject target, ResteasyProviderFactory factory)
+ protected void initialize(Class type, Type genericType, String paramName, Class paramType, String defaultValue, AccessibleObject target, Annotation[] annotations, ResteasyProviderFactory factory)
{
this.type = type;
this.paramName = paramName;
@@ -95,6 +99,35 @@ else if (Set.class.isAssignableFrom(type))
}
if (!baseType.isPrimitive())
{
+ unmarshaller = factory.createStringParameterUnmarshaller(baseType);
+ if (unmarshaller != null)
+ {
+ unmarshaller.setAnnotations(annotations);
+ return;
+ }
+
+ for (Annotation annotation : annotations)
+ {
+ StringParameterUnmarshallerBinder binder = annotation.annotationType().getAnnotation(StringParameterUnmarshallerBinder.class);
+ if (binder != null)
+ {
+ try
+ {
+ unmarshaller = binder.value().newInstance();
+ }
+ catch (InstantiationException e)
+ {
+ throw new RuntimeException(e.getCause());
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new RuntimeException(e);
+ }
+ unmarshaller.setAnnotations(annotations);
+ return;
+ }
+ }
+
converter = factory.getStringConverter(baseType);
if (converter != null) return;
@@ -194,6 +227,10 @@ public Object extractValue(String strVal)
{
return converter.fromString(strVal);
}
+ else if (unmarshaller != null)
+ {
+ return unmarshaller.fromString(strVal);
+ }
else if (delegate != null)
{
return delegate.fromString(strVal);
@@ -1,14 +1,16 @@
package org.jboss.resteasy.core;
-import org.jboss.resteasy.spi.interception.ClientExecutionInterceptor;
+import org.jboss.resteasy.client.core.ClientErrorInterceptor;
import org.jboss.resteasy.core.interception.InterceptorRegistry;
+import org.jboss.resteasy.spi.ProviderFactoryDelegate;
+import org.jboss.resteasy.spi.ResteasyProviderFactory;
+import org.jboss.resteasy.spi.StringConverter;
+import org.jboss.resteasy.spi.StringParameterUnmarshaller;
+import org.jboss.resteasy.spi.interception.ClientExecutionInterceptor;
import org.jboss.resteasy.spi.interception.MessageBodyReaderInterceptor;
import org.jboss.resteasy.spi.interception.MessageBodyWriterInterceptor;
import org.jboss.resteasy.spi.interception.PostProcessInterceptor;
import org.jboss.resteasy.spi.interception.PreProcessInterceptor;
-import org.jboss.resteasy.spi.ProviderFactoryDelegate;
-import org.jboss.resteasy.spi.ResteasyProviderFactory;
-import org.jboss.resteasy.spi.StringConverter;
import org.jboss.resteasy.util.ThreadLocalStack;
import javax.ws.rs.core.Application;
@@ -49,6 +51,30 @@ public ResteasyProviderFactory getDelegate()
}
@Override
+ public void addStringParameterUnmarshaller(Class<? extends StringParameterUnmarshaller> resolver)
+ {
+ getDelegate().addStringParameterUnmarshaller(resolver);
+ }
+
+ @Override
+ public void addClientErrorInterceptor(ClientErrorInterceptor handler)
+ {
+ getDelegate().addClientErrorInterceptor(handler);
+ }
+
+ @Override
+ public List<ClientErrorInterceptor> getClientErrorInterceptors()
+ {
+ return getDelegate().getClientErrorInterceptors();
+ }
+
+ @Override
+ public <T> StringParameterUnmarshaller<T> createStringParameterUnmarshaller(Class<T> clazz)
+ {
+ return super.createStringParameterUnmarshaller(clazz);
+ }
+
+ @Override
public boolean isBuiltinsRegistered()
{
return getDelegate().isBuiltinsRegistered();
Oops, something went wrong.

0 comments on commit f7417c7

Please sign in to comment.