Author: heiko.braun(a)jboss.com
Date: 2007-11-20 09:05:33 -0500 (Tue, 20 Nov 2007)
New Revision: 5074
Removed:
stack/native/branches/rest/src/main/java/org/jboss/rs/media/EntityProviderRegistry.java
stack/native/branches/rest/src/main/java/org/jboss/rs/media/JAXBEntityProvider.java
Modified:
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModelParser.java
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/RuntimeContext.java
stack/native/branches/rest/src/main/java/org/jboss/rs/util/Convert.java
stack/native/branches/rest/src/test/java/org/jboss/test/rs/Specification.java
stack/native/branches/rest/src/test/java/org/jboss/test/rs/Widget.java
stack/native/branches/rest/src/test/java/org/jboss/test/rs/WidgetList.java
stack/native/branches/rest/src/test/java/org/jboss/test/rs/invocation/InvocationBuilderTestCase.java
stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ModelParserTestCase.java
stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ResolverTestCase.java
stack/native/branches/rest/version.properties
Log:
Update to 0.5 API
Deleted:
stack/native/branches/rest/src/main/java/org/jboss/rs/media/EntityProviderRegistry.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/media/EntityProviderRegistry.java 2007-11-20
12:59:52 UTC (rev 5073)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/media/EntityProviderRegistry.java 2007-11-20
14:05:33 UTC (rev 5074)
@@ -1,64 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.rs.media;
-
-import javax.ws.rs.ext.EntityProvider;
-import javax.activation.MimeType;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * Register {@link javax.ws.rs.ext.EntityProvider} for MimeTypes
- *
- * @author Heiko.Braun(a)jboss.com
- * @version $Revision$
- */
-public class EntityProviderRegistry
-{
-
- private Map<MimeType, List<EntityProvider>> providers = new
HashMap<MimeType, List<EntityProvider>>();
-
- public void addProvider(EntityProvider provider, MimeType... mimeTypes)
- {
- for(MimeType m : mimeTypes)
- {
- if(null == providers.get(m))
- providers.put(m, new ArrayList<EntityProvider>());
-
- providers.get(m).add(provider);
- }
- }
-
- public List<EntityProvider> getProviders(MimeType mime)
- {
- List<EntityProvider> match = new ArrayList<EntityProvider>();
-
- if(providers.get(mime)!=null)
- match = providers.get(mime);
-
- return match;
- }
-
-
-}
Deleted:
stack/native/branches/rest/src/main/java/org/jboss/rs/media/JAXBEntityProvider.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/media/JAXBEntityProvider.java 2007-11-20
12:59:52 UTC (rev 5073)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/media/JAXBEntityProvider.java 2007-11-20
14:05:33 UTC (rev 5074)
@@ -1,83 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.rs.media;
-
-import javax.ws.rs.ext.EntityProvider;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-
-/**
- * TODO: Cache JAXBContext for better performance
- *
- * @author Heiko.Braun(a)jboss.com
- * @version $Revision$
- */
-public class JAXBEntityProvider implements EntityProvider
-{
-
- /**
- * Supports classes annotated with @XmlRootElement or JAXBElement's that wrap this
infomration.
- * @param aClass
- * @return
- */
- public boolean supports(Class aClass)
- {
- return aClass.isAnnotationPresent(XmlRootElement.class) || (JAXBElement.class ==
aClass);
- }
-
- public Object readFrom(Class aClass, MediaType mediaType, MultivaluedMap
multivaluedMap, InputStream inputStream) throws IOException
- {
- Object result = null;
- try
- {
- JAXBContext context = JAXBContext.newInstance(aClass);
- result = context.createUnmarshaller().unmarshal(inputStream);
- }
- catch (JAXBException e)
- {
- throw new IOException("Unmarshalling failed: " + e.getMessage());
- }
-
- return result;
-
- }
-
- public void writeTo(Object o, MediaType mediaType, MultivaluedMap multivaluedMap,
OutputStream outputStream) throws IOException
- {
- try
- {
- JAXBContext context = JAXBContext.newInstance(o.getClass());
- context.createMarshaller().marshal(o, outputStream);
- }
- catch (JAXBException e)
- {
- throw new IOException("Marshalling failed: " + e.getMessage());
- }
- }
-}
Modified:
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModelParser.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModelParser.java 2007-11-20
12:59:52 UTC (rev 5073)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModelParser.java 2007-11-20
14:05:33 UTC (rev 5074)
@@ -21,11 +21,12 @@
*/
package org.jboss.rs.model;
+import org.jboss.logging.Logger;
+import org.jboss.rs.MethodHTTP;
import org.jboss.rs.util.Convert;
-import org.jboss.logging.Logger;
+import javax.ws.rs.HttpMethod;
import javax.ws.rs.UriTemplate;
-import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
/**
@@ -85,22 +86,24 @@
ResourceMethod resourceMethod = null;
// subresource methods
- for(Class requestType : Convert.REQUEST_TYPES)
+
+ if(method.isAnnotationPresent(HttpMethod.class))
{
- if(method.isAnnotationPresent(requestType))
- {
- // sub resource method
- Annotation a = method.getAnnotation(requestType);
- resourceMethod = new ResourceMethod(
- parentResource,
- Convert.annotationToMethodHTTP(a), uri.value(), method
- );
+ // sub resource method
+ HttpMethod a = method.getAnnotation(HttpMethod.class);
+ MethodHTTP methodHttp = a.value().equals("") ?
+ Convert.prefixToMethodHTTP(method) : Convert.annotationToMethodHTTP(a);
- resourceMethod.freeze();
- parentResource.addSubResourceMethod(resourceMethod);
- }
+ resourceMethod = new ResourceMethod(
+ parentResource,
+ methodHttp, uri.value(), method
+ );
+
+ resourceMethod.freeze();
+ parentResource.addSubResourceMethod(resourceMethod);
}
+
// subresource locator
if(null == resourceMethod)
{
@@ -116,20 +119,20 @@
}
else
{
- for(Class requestType : Convert.REQUEST_TYPES)
+ if(method.isAnnotationPresent(HttpMethod.class))
{
- if(method.isAnnotationPresent(requestType))
- {
- // resource method
- Annotation a = method.getAnnotation(requestType);
- ResourceMethod resourceMethod = new ResourceMethod(
- parentResource,
- Convert.annotationToMethodHTTP(a), "", method
- );
+ // resource method
+ HttpMethod a = method.getAnnotation(HttpMethod.class);
+ MethodHTTP methodHttp = a.value().equals("") ?
+ Convert.prefixToMethodHTTP(method) : Convert.annotationToMethodHTTP(a);
- resourceMethod.freeze();
- parentResource.addResourceMethod(resourceMethod);
- }
+ ResourceMethod resourceMethod = new ResourceMethod(
+ parentResource,
+ methodHttp, "", method
+ );
+
+ resourceMethod.freeze();
+ parentResource.addResourceMethod(resourceMethod);
}
}
}
Modified:
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/RuntimeContext.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/RuntimeContext.java 2007-11-20
12:59:52 UTC (rev 5073)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/RuntimeContext.java 2007-11-20
14:05:33 UTC (rev 5074)
@@ -132,7 +132,7 @@
public MimeType getProvideMimeType()
{
- if(! (requestMethod == MethodHTTP.POST) )
+ if(! (requestMethod == MethodHTTP.POST || requestMethod == MethodHTTP.PUT) )
throw new IllegalArgumentException(requestMethod + " does not provide a
'Content-Type header'");
assert provideMimeType !=null;
Modified: stack/native/branches/rest/src/main/java/org/jboss/rs/util/Convert.java
===================================================================
--- stack/native/branches/rest/src/main/java/org/jboss/rs/util/Convert.java 2007-11-20
12:59:52 UTC (rev 5073)
+++ stack/native/branches/rest/src/main/java/org/jboss/rs/util/Convert.java 2007-11-20
14:05:33 UTC (rev 5074)
@@ -23,15 +23,13 @@
import org.jboss.rs.MethodHTTP;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.DELETE;
+import javax.ws.rs.HttpMethod;
import javax.ws.rs.ConsumeMime;
import javax.ws.rs.ProduceMime;
import javax.activation.MimeType;
import javax.activation.MimeTypeParseException;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
import java.util.List;
import java.util.ArrayList;
import java.util.StringTokenizer;
@@ -42,8 +40,7 @@
*/
public class Convert
{
- public static Class[] REQUEST_TYPES = new Class[] { GET.class, POST.class, PUT.class,
DELETE.class };
-
+
public static MimeType ANY_MIME;
static
@@ -58,21 +55,45 @@
}
}
- public static MethodHTTP annotationToMethodHTTP(Annotation a)
+ public static MethodHTTP prefixToMethodHTTP(Method m)
{
- MethodHTTP m = null;
+ MethodHTTP result = null;
- if(a instanceof GET)
- m = MethodHTTP.GET;
- else if(a instanceof POST)
- m = MethodHTTP.POST;
- else if(a instanceof PUT)
- m = MethodHTTP.PUT;
- else if(a instanceof DELETE)
- m = MethodHTTP.DELETE;
+ String methodName = m.getName();
+ if(methodName.startsWith("get"))
+ result = MethodHTTP.GET;
+ else if(methodName.startsWith("post"))
+ result = MethodHTTP.POST;
+ else if(methodName.startsWith("put"))
+ result = MethodHTTP.PUT;
+ else if(methodName.startsWith("delete"))
+ result = MethodHTTP.DELETE;
- return m;
+ if(null==result)
+ throw new IllegalArgumentException("Failed to match method by prefix:
" + methodName);
+
+ return result;
+ }
+ public static MethodHTTP annotationToMethodHTTP(HttpMethod a)
+ {
+ HttpMethod hm = (HttpMethod)a;
+ MethodHTTP result = null;
+
+ if(hm.value() == HttpMethod.GET)
+ result = MethodHTTP.GET;
+ else if(hm.value() == HttpMethod.POST)
+ result = MethodHTTP.POST;
+ else if(hm.value() == HttpMethod.PUT)
+ result = MethodHTTP.PUT;
+ else if(hm.value() == HttpMethod.DELETE)
+ result = MethodHTTP.DELETE;
+
+ if(null==result)
+ throw new IllegalArgumentException("Failed to match method by value: "
+ hm.value());
+
+ return result;
+
}
public static List<MimeType> annotationToMimeType(ConsumeMime consumeMime)
Modified: stack/native/branches/rest/src/test/java/org/jboss/test/rs/Specification.java
===================================================================
---
stack/native/branches/rest/src/test/java/org/jboss/test/rs/Specification.java 2007-11-20
12:59:52 UTC (rev 5073)
+++
stack/native/branches/rest/src/test/java/org/jboss/test/rs/Specification.java 2007-11-20
14:05:33 UTC (rev 5074)
@@ -21,6 +21,8 @@
*/
package org.jboss.test.rs;
+import javax.ws.rs.HttpMethod;
+
/**
* @author Heiko.Braun(a)jboss.com
* @version $Revision$
@@ -37,4 +39,10 @@
{
this.name = name;
}
+
+ @HttpMethod
+ public String getName()
+ {
+ return name;
+ }
}
Modified: stack/native/branches/rest/src/test/java/org/jboss/test/rs/Widget.java
===================================================================
--- stack/native/branches/rest/src/test/java/org/jboss/test/rs/Widget.java 2007-11-20
12:59:52 UTC (rev 5073)
+++ stack/native/branches/rest/src/test/java/org/jboss/test/rs/Widget.java 2007-11-20
14:05:33 UTC (rev 5074)
@@ -21,7 +21,7 @@
*/
package org.jboss.test.rs;
-import javax.ws.rs.GET;
+import javax.ws.rs.HttpMethod;
import javax.ws.rs.UriParam;
import javax.ws.rs.UriTemplate;
import javax.ws.rs.ProduceMime;
@@ -44,14 +44,14 @@
this.id = id;
}
- @GET
+ @HttpMethod
@UriTemplate("id")
@ProduceMime("text/plain")
public String getId() {
return this.id;
}
- @GET
+ @HttpMethod
@UriTemplate("spec")
public List<Specification> getSpecifications() {
List<Specification> specs = new ArrayList<Specification>();
@@ -59,7 +59,7 @@
return specs;
}
- @GET
+ @HttpMethod
@UriTemplate("spec/{name}")
public Specification getSpecByName(@UriParam("name")String name)
{
Modified: stack/native/branches/rest/src/test/java/org/jboss/test/rs/WidgetList.java
===================================================================
--- stack/native/branches/rest/src/test/java/org/jboss/test/rs/WidgetList.java 2007-11-20
12:59:52 UTC (rev 5073)
+++ stack/native/branches/rest/src/test/java/org/jboss/test/rs/WidgetList.java 2007-11-20
14:05:33 UTC (rev 5074)
@@ -21,10 +21,9 @@
*/
package org.jboss.test.rs;
-import javax.ws.rs.GET;
+import javax.ws.rs.HttpMethod;
import javax.ws.rs.UriParam;
import javax.ws.rs.UriTemplate;
-import javax.ws.rs.POST;
import javax.ws.rs.ConsumeMime;
import javax.ws.rs.ProduceMime;
import javax.ws.rs.core.HttpContext;
@@ -33,22 +32,22 @@
@UriTemplate("widgets")
public class WidgetList
{
- @GET
+ @HttpMethod
@ProduceMime({"text/plain"})
public String getDescription() {
return "A widgetlist";
}
- @GET
+ @HttpMethod
@UriTemplate("offers")
public WidgetList getDiscounted() {
return null;
}
- @POST
+ @HttpMethod
@UriTemplate("special")
@ConsumeMime({"text/xml", "application/xml"})
- public void setDiscounted(
+ public void putDiscounted(
@HttpContext HttpHeaders headers,
Widget special
)
Modified:
stack/native/branches/rest/src/test/java/org/jboss/test/rs/invocation/InvocationBuilderTestCase.java
===================================================================
---
stack/native/branches/rest/src/test/java/org/jboss/test/rs/invocation/InvocationBuilderTestCase.java 2007-11-20
12:59:52 UTC (rev 5073)
+++
stack/native/branches/rest/src/test/java/org/jboss/test/rs/invocation/InvocationBuilderTestCase.java 2007-11-20
14:05:33 UTC (rev 5074)
@@ -101,7 +101,7 @@
public void testHttpContextParamBinding() throws Exception
{
URI uri = new URI("/rest/widgets/special");
- RuntimeContext context = defaultRuntimeContext(MethodHTTP.POST, uri);
+ RuntimeContext context = defaultRuntimeContext(MethodHTTP.PUT, uri);
context.parseContentTypeHeader("text/xml");
StatefulResourceResolver resolver = StatefulResourceResolver.newInstance(context);
Modified:
stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ModelParserTestCase.java
===================================================================
---
stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ModelParserTestCase.java 2007-11-20
12:59:52 UTC (rev 5073)
+++
stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ModelParserTestCase.java 2007-11-20
14:05:33 UTC (rev 5074)
@@ -41,7 +41,7 @@
ResourceMethod match = null;
for(ResourceMethod m : root.getSubResourceMethods())
{
- if(m.getMethodHTTP() == MethodHTTP.POST
+ if(m.getMethodHTTP() == MethodHTTP.PUT
&& m.getUriTemplate().equals("special"))
{
match = m;
Modified:
stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ResolverTestCase.java
===================================================================
---
stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ResolverTestCase.java 2007-11-20
12:59:52 UTC (rev 5073)
+++
stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ResolverTestCase.java 2007-11-20
14:05:33 UTC (rev 5074)
@@ -67,7 +67,7 @@
public void testRegexResolver2() throws Exception
{
URI uri = new URI("/rest/widgets/special");
- RuntimeContext context = defaultRuntimeContext(MethodHTTP.POST, uri);
+ RuntimeContext context = defaultRuntimeContext(MethodHTTP.PUT, uri);
context.parseContentTypeHeader("text/xml");
StatefulResourceResolver resolver = StatefulResourceResolver.newInstance(context);
Modified: stack/native/branches/rest/version.properties
===================================================================
--- stack/native/branches/rest/version.properties 2007-11-20 12:59:52 UTC (rev 5073)
+++ stack/native/branches/rest/version.properties 2007-11-20 14:05:33 UTC (rev 5074)
@@ -67,7 +67,7 @@
jboss-vfs=2.0.0.Beta2
jbossas-core-libs=4.2.0.GA
junit=3.8.1
-jsr-311=0.3
+jsr-311=0.5
oswego-concurrent=1.3.4
qdox=1.4
sun-hudson=1.93