[exo-jcr-commits] exo-jcr SVN: r137 - in ws/trunk/rest/core/src: main/java/org/exoplatform/services/rest/impl and 4 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Sep 4 08:17:16 EDT 2009
Author: aparfonov
Date: 2009-09-04 08:17:16 -0400 (Fri, 04 Sep 2009)
New Revision: 137
Added:
ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/impl/method/ParametersInjectionTest.java
Removed:
ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/impl/method/PatametersInjectionTest.java
Modified:
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/RequestHandler.java
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterHelper.java
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterResolverFactory.java
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/PropertyResolver.java
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/provider/DataSourceEntityProvider.java
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/provider/MultipartFormDataEntityProvider.java
ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java
Log:
EXOJCR-143 :
Modified: ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/RequestHandler.java
===================================================================
--- ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/RequestHandler.java 2009-09-04 06:25:33 UTC (rev 136)
+++ ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/RequestHandler.java 2009-09-04 12:17:16 UTC (rev 137)
@@ -41,6 +41,11 @@
public static final String WS_RS_BUFFER_SIZE = "ws.rs.buffersize";
/**
+ * Max buffer size attribute value. See {@link WS_RS_BUFFER_SIZE}.
+ */
+ public static final int WS_RS_BUFFER_SIZE_VALUE = 204800;
+
+ /**
* Handle the HTTP request by dispatching request to appropriate resource. If
* no one appropriate resource found then error response will be produced.
*
Modified: ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java
===================================================================
--- ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java 2009-09-04 06:25:33 UTC (rev 136)
+++ ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java 2009-09-04 12:17:16 UTC (rev 137)
@@ -18,11 +18,25 @@
*/
package org.exoplatform.services.rest.impl;
+import java.io.File;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.StreamingOutput;
+import javax.ws.rs.ext.ExceptionMapper;
+
import org.exoplatform.container.component.ComponentPlugin;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.container.xml.ValueParam;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import org.exoplatform.services.rest.ApplicationContext;
import org.exoplatform.services.rest.FilterDescriptor;
import org.exoplatform.services.rest.GenericContainerRequest;
import org.exoplatform.services.rest.GenericContainerResponse;
@@ -36,21 +50,6 @@
import org.exoplatform.services.rest.provider.EntityProvider;
import org.picocontainer.Startable;
-import java.io.File;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.StreamingOutput;
-import javax.ws.rs.ext.ExceptionMapper;
-
/**
* @author <a href="mailto:andrew00x at gmail.com">Andrey Parfonov</a>
* @version $Id: $
@@ -62,34 +61,36 @@
* Logger.
*/
private static final Log LOG = ExoLogger.getLogger(RequestHandlerImpl.class.getName());
-
+
/**
- * Application properties.
+ * Application properties. Properties from this map will be copied to ApplicationContext
+ * and may be accessible via method {@link ApplicationContext#getAttributes()}.
*/
private static final MultivaluedMap<String, String> properties = new MultivaluedMapImpl();
-
+
/**
* See {@link RequestDispatcher}.
*/
private final RequestDispatcher dispatcher;
+
+ public static final String getProperty(String name)
+ {
+ return properties.getFirst(name);
+ }
+
+ public static final void setProperty(String name, String value)
+ {
+ if (value == null)
+ properties.remove(name);
+ properties.putSingle(name, value);
+ }
- // /**
- // * See {@link ProviderBinder}.
- // */
- // private final ProviderBinder providers;
-
/**
- * Application properties.
- */
- private final Map<String, Object> applicationProperties = new HashMap<String, Object>();
-
- /**
* Constructs new instance of {@link RequestHandler}.
*
* @param dispatcher See {@link RequestDispatcher}
* @param params init parameters
*/
- @SuppressWarnings("unchecked")
public RequestHandlerImpl(RequestDispatcher dispatcher, InitParams params)
{
if (params != null)
@@ -97,14 +98,7 @@
for (Iterator<ValueParam> i = params.getValueParamIterator(); i.hasNext();)
{
ValueParam vp = i.next();
- String name = vp.getName();
- String value = vp.getValue();
- if (name.equals(WS_RS_BUFFER_SIZE))
- applicationProperties.put(name, Integer.parseInt(value));
- else if (name.equals(WS_RS_TMP_DIR))
- applicationProperties.put(name, new File(value));
- else
- applicationProperties.put(name, value);
+ properties.putSingle(vp.getName(), vp.getValue());
}
}
@@ -123,7 +117,15 @@
try
{
ApplicationContextImpl context = new ApplicationContextImpl(request, response, ProviderBinder.getInstance());
- context.getAttributes().putAll(applicationProperties);
+ for (String propName : properties.keySet())
+ {
+ String value = properties.getFirst(propName);
+ if (value != null)
+ {
+ context.getAttributes().put(propName, value);
+
+ }
+ }
ApplicationContextImpl.setCurrent(context);
for (ObjectFactory<FilterDescriptor> factory : ProviderBinder.getInstance().getRequestFilters(
@@ -207,7 +209,7 @@
}
if (excmap != null)
{
- if (LOG.isDebugEnabled())
+ if (LOG.isDebugEnabled())
{
// Hide error message if exception mapper exists.
LOG.warn("Internal error occurs.", cause);
@@ -302,13 +304,16 @@
{
// Directory for temporary files
final File tmpDir;
- if (applicationProperties.containsKey(WS_RS_TMP_DIR))
- tmpDir = (File)applicationProperties.get(WS_RS_TMP_DIR);
- else
+ String tmpDirName = properties.getFirst(WS_RS_TMP_DIR);
+ if (tmpDirName == null)
{
tmpDir = new File(System.getProperty("java.io.tmpdir") + File.separator + "ws_jaxrs");
- applicationProperties.put(WS_RS_TMP_DIR, tmpDir);
+ properties.putSingle(WS_RS_TMP_DIR, tmpDir.getPath());
}
+ else
+ {
+ tmpDir = new File(tmpDirName);
+ }
if (!tmpDir.exists())
tmpDir.mkdirs();
@@ -327,13 +332,6 @@
}
});
- Integer bufferSize = (Integer)applicationProperties.get(WS_RS_BUFFER_SIZE);
- if (bufferSize == null)
- {
- bufferSize = 204800; // TODO move somewhere as const
- applicationProperties.put(WS_RS_BUFFER_SIZE, bufferSize);
- }
-
}
/**
Modified: ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterHelper.java
===================================================================
--- ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterHelper.java 2009-09-04 06:25:33 UTC (rev 136)
+++ ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterHelper.java 2009-09-04 12:17:16 UTC (rev 137)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.rest.impl.method;
+import org.exoplatform.services.rest.Property;
import org.exoplatform.services.rest.method.TypeProducer;
import java.lang.annotation.Annotation;
@@ -27,12 +28,14 @@
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import javax.ws.rs.CookieParam;
+import javax.ws.rs.FormParam;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.MatrixParam;
import javax.ws.rs.PathParam;
@@ -84,20 +87,25 @@
static
{
- PROVIDER_FIELDS_ANNOTATIONS = Collections.singletonList(Context.class.getName());
- PROVIDER_CONSTRUCTOR_PARAMETER_ANNOTATIONS = Collections.singletonList(Context.class.getName());
- List<String> tmp1 = new ArrayList<String>(6);
+ PROVIDER_FIELDS_ANNOTATIONS =
+ Collections.unmodifiableList(Arrays.asList(Context.class.getName(), Property.class.getName()));
+
+ PROVIDER_CONSTRUCTOR_PARAMETER_ANNOTATIONS =
+ Collections.unmodifiableList(Arrays.asList(Context.class.getName(), Property.class.getName()));
+
+ List<String> tmp1 = new ArrayList<String>(7);
tmp1.add(CookieParam.class.getName());
tmp1.add(Context.class.getName());
tmp1.add(HeaderParam.class.getName());
tmp1.add(MatrixParam.class.getName());
tmp1.add(PathParam.class.getName());
tmp1.add(QueryParam.class.getName());
+ tmp1.add(Property.class.getName());
RESOURCE_FIELDS_ANNOTATIONS = Collections.unmodifiableList(tmp1);
RESOURCE_CONSTRUCTOR_PARAMETER_ANNOTATIONS = Collections.unmodifiableList(tmp1);
List<String> tmp2 = new ArrayList<String>(tmp1);
- tmp2.add(javax.ws.rs.FormParam.class.getName());
+ tmp2.add(FormParam.class.getName());
RESOURCE_METHOD_PARAMETER_ANNOTATIONS = Collections.unmodifiableList(tmp2);
}
Modified: ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterResolverFactory.java
===================================================================
--- ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterResolverFactory.java 2009-09-04 06:25:33 UTC (rev 136)
+++ ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterResolverFactory.java 2009-09-04 12:17:16 UTC (rev 137)
@@ -28,6 +28,8 @@
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
+import org.exoplatform.services.rest.Property;
+
/**
* @author <a href="mailto:andrew00x at gmail.com">Andrey Parfonov</a>
* @version $Id: $
@@ -66,7 +68,8 @@
return new PathParameterResolver((PathParam)annotation);
if (clazz == QueryParam.class)
return new QueryParameterResolver((QueryParam)annotation);
-
+ if (clazz == Property.class)
+ return new PropertyResolver((Property)annotation);
return null;
}
Modified: ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/PropertyResolver.java
===================================================================
--- ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/PropertyResolver.java 2009-09-04 06:25:33 UTC (rev 136)
+++ ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/PropertyResolver.java 2009-09-04 12:17:16 UTC (rev 137)
@@ -20,7 +20,6 @@
import org.exoplatform.services.rest.ApplicationContext;
import org.exoplatform.services.rest.Property;
-import org.exoplatform.services.rest.method.TypeProducer;
/**
* @author <a href="mailto:andrew00x at gmail.com">Andrey Parfonov</a>
@@ -50,10 +49,20 @@
public Object resolve(org.exoplatform.services.rest.Parameter parameter, ApplicationContext context)
throws Exception
{
+ if (parameter.getParameterClass() != String.class)
+ {
+ throw new IllegalArgumentException(
+ "Only parameters and fields with string type may be annotated by @Property.");
+ }
String param = this.property.value();
- TypeProducer typeProducer =
- ParameterHelper.createTypeProducer(parameter.getParameterClass(), parameter.getGenericType());
- return typeProducer.createValue(param, null, parameter.getDefaultValue());
+
+ Object value = context.getAttributes().get(param);
+ if (value == null)
+ {
+ return parameter.getDefaultValue();
+ }
+
+ return value;
}
}
Modified: ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/provider/DataSourceEntityProvider.java
===================================================================
--- ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/provider/DataSourceEntityProvider.java 2009-09-04 06:25:33 UTC (rev 136)
+++ ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/provider/DataSourceEntityProvider.java 2009-09-04 12:17:16 UTC (rev 137)
@@ -117,7 +117,9 @@
byte[] buffer = new byte[8192];
ApplicationContext context = ApplicationContextImpl.getCurrent();
- int bufferSize = (Integer)context.getAttributes().get(RequestHandler.WS_RS_BUFFER_SIZE);
+ int bufferSize =
+ context.getAttributes().get(RequestHandler.WS_RS_BUFFER_SIZE) == null ? RequestHandler.WS_RS_BUFFER_SIZE_VALUE
+ : Integer.parseInt((String)context.getAttributes().get(RequestHandler.WS_RS_BUFFER_SIZE));
ByteArrayOutputStream bout = new ByteArrayOutputStream(bufferSize);
int bytes = -1;
Modified: ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/provider/MultipartFormDataEntityProvider.java
===================================================================
--- ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/provider/MultipartFormDataEntityProvider.java 2009-09-04 06:25:33 UTC (rev 136)
+++ ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/provider/MultipartFormDataEntityProvider.java 2009-09-04 12:17:16 UTC (rev 137)
@@ -96,8 +96,11 @@
try
{
ApplicationContext context = ApplicationContextImpl.getCurrent();
- int bufferSize = (Integer)context.getAttributes().get(RequestHandler.WS_RS_BUFFER_SIZE);
- File repo = (File)context.getAttributes().get(RequestHandler.WS_RS_TMP_DIR);
+ int bufferSize =
+ context.getAttributes().get(RequestHandler.WS_RS_BUFFER_SIZE) == null
+ ? RequestHandler.WS_RS_BUFFER_SIZE_VALUE : Integer.parseInt((String)context.getAttributes().get(
+ RequestHandler.WS_RS_BUFFER_SIZE));
+ File repo = new File((String)context.getAttributes().get(RequestHandler.WS_RS_TMP_DIR));
DefaultFileItemFactory factory = new DefaultFileItemFactory(bufferSize, repo);
FileUpload upload = new FileUpload(factory);
Modified: ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java
===================================================================
--- ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java 2009-09-04 06:25:33 UTC (rev 136)
+++ ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java 2009-09-04 12:17:16 UTC (rev 137)
@@ -20,6 +20,7 @@
import org.exoplatform.services.rest.AbstractResourceTest;
import org.exoplatform.services.rest.GenericContainerResponse;
+import org.exoplatform.services.rest.Property;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Encoded;
@@ -381,5 +382,40 @@
assertNotNull(header);
}
}
+
+ // -----------------------------------------------
+
+ public void testPropertyInjection() throws Exception
+ {
+ registry(Resource6.class);
+ RequestHandlerImpl.setProperty("prop1", "hello");
+ RequestHandlerImpl.setProperty("prop2", "test");
+ service("GET", "/a", "", null, null);
+ unregistry(Resource6.class);
+
+ }
+ @Path("a")
+ public static class Resource6
+ {
+
+ @Property("prop1")
+ private String prop1;
+
+ private final String prop2;
+
+ public Resource6(@Property("prop2") String cProp)
+ {
+ this.prop2 = cProp;
+ }
+
+ @GET
+ public void m1()
+ {
+ assertEquals("hello", prop1);
+ assertEquals("test", prop2);
+ }
+
+ }
+
}
Copied: ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/impl/method/ParametersInjectionTest.java (from rev 136, ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/impl/method/PatametersInjectionTest.java)
===================================================================
--- ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/impl/method/ParametersInjectionTest.java (rev 0)
+++ ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/impl/method/ParametersInjectionTest.java 2009-09-04 12:17:16 UTC (rev 137)
@@ -0,0 +1,268 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * 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.exoplatform.services.rest.impl.method;
+
+import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.Property;
+import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
+import org.exoplatform.services.rest.impl.RequestHandlerImpl;
+
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+
+import javax.ws.rs.CookieParam;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.MatrixParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Cookie;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.UriInfo;
+
+/**
+ * @author <a href="mailto:andrew00x at gmail.com">Andrey Parfonov</a>
+ * @version $Id: $
+ */
+public class ParametersInjectionTest extends AbstractResourceTest
+{
+
+ @Path("/a/{x}")
+ public static class Resource1
+ {
+
+ @GET
+ @Path("/0/{y}/")
+ public void m0(@PathParam("x") String x, @PathParam("y") String y)
+ {
+ assertNotNull(x);
+ assertNotNull(y);
+ assertEquals(x, y);
+ }
+
+ @GET
+ @Path("/1/{y}/")
+ public void m1(@PathParam("x") List<String> x, @PathParam("y") List<String> y)
+ {
+ assertNotNull(x);
+ assertEquals(1, x.size());
+ assertNotNull(y);
+ assertEquals(1, y.size());
+ assertEquals(x, y);
+ }
+
+ @GET
+ @Path("/2/{y}/")
+ public void m2(@PathParam("x") Set<String> x, @PathParam("y") Set<String> y)
+ {
+ assertNotNull(x);
+ assertEquals(1, x.size());
+ assertNotNull(y);
+ assertEquals(1, y.size());
+ assertEquals(x, y);
+ }
+
+ @GET
+ @Path("/3/{y}/")
+ public void m3(@PathParam("x") SortedSet<String> x, @PathParam("y") SortedSet<String> y)
+ {
+ assertNotNull(x);
+ assertEquals(1, x.size());
+ assertNotNull(y);
+ assertEquals(1, y.size());
+ assertEquals(x, y);
+ }
+
+ @GET
+ @Path("/4/{y}/")
+ public void m4(@PathParam("x") Integer x, @PathParam("y") Integer y)
+ {
+ assertNotNull(x);
+ assertNotNull(y);
+ assertEquals(1111, x - y);
+ }
+
+ @GET
+ @Path("/5/{y}/")
+ public void m5(@PathParam("x") long x, @PathParam("y") long y)
+ {
+ assertNotNull(x);
+ assertNotNull(y);
+ assertEquals(1111, x - y);
+ }
+
+ @GET
+ @Path("/6/{y}/")
+ public void m6(@PathParam("x") Test x, @PathParam("y") Test y)
+ {
+ assertNotNull(x);
+ assertNotNull(y);
+ assertEquals(x.toString(), y.toString());
+ }
+
+ @GET
+ @Path("/7/{y}/")
+ public void m7(@QueryParam("x") List<String> x, @QueryParam("y") List<String> y)
+ {
+ assertNotNull(x);
+ assertEquals(3, x.size());
+ assertNotNull(y);
+ assertEquals(2, y.size());
+ assertEquals("1", x.get(0));
+ assertEquals("3", x.get(1));
+ assertEquals("5", x.get(2));
+ assertEquals("2", y.get(0));
+ assertEquals("4", y.get(1));
+ }
+
+ @GET
+ @Path("/8/{y}/")
+ public void m8(@HeaderParam("foo") String x, @HeaderParam("bar") String y)
+ {
+ assertNotNull(x);
+ assertNotNull(y);
+ assertEquals(x, y);
+ }
+
+ @POST
+ @Path("/9/{y}/")
+ public void m9(@FormParam("foo") String x, @FormParam("bar") String y)
+ {
+ assertNotNull(x);
+ assertNotNull(y);
+ assertEquals(x, y);
+ }
+
+ @GET
+ @Path("/10/{y}/")
+ public void m10(@MatrixParam("foo") int x, @MatrixParam("bar") int y)
+ {
+ assertNotNull(x);
+ assertNotNull(y);
+ assertEquals(1111, x - y);
+ }
+
+ @GET
+ @Path("/11/{y}/")
+ public void m11(@CookieParam("foo") Cookie x, @CookieParam("bar") Cookie y)
+ {
+ assertNotNull(x);
+ assertNotNull(y);
+ assertEquals(x.getDomain(), y.getDomain());
+ assertEquals(x.getPath(), y.getPath());
+ }
+
+ @GET
+ @Path("/12/{y}/")
+ public void m12(@Context UriInfo uriInfo)
+ {
+ assertNotNull(uriInfo);
+ assertEquals(2, uriInfo.getPathParameters().size());
+ }
+
+ @GET
+ @Path("/13")
+ public String m13(@QueryParam("query") @DefaultValue("111") String param)
+ {
+ assertNotNull(param);
+
+ return param;
+ }
+
+ @GET
+ @Path("/14")
+ public String m14(@Property("prop1") @DefaultValue("hello") String prop)
+ {
+
+ assertNotNull(prop);
+
+ return prop;
+ }
+
+ }
+
+ public static class Test
+ {
+ private final String s;
+
+ public Test(String s)
+ {
+ this.s = s;
+ }
+
+ public String toString()
+ {
+ return s;
+ }
+ }
+
+ public void testParameterTypes() throws Exception
+ {
+ Resource1 r1 = new Resource1();
+ registry(r1);
+ assertEquals(204, service("GET", "/a/test/0/test", "", null, null).getStatus());
+ assertEquals(204, service("GET", "/a/test/1/test", "", null, null).getStatus());
+ assertEquals(204, service("GET", "/a/test/2/test", "", null, null).getStatus());
+ assertEquals(204, service("GET", "/a/test/3/test", "", null, null).getStatus());
+ assertEquals(204, service("GET", "/a/3333/4/2222", "", null, null).getStatus());
+ assertEquals(204, service("GET", "/a/5555/5/4444", "", null, null).getStatus());
+ assertEquals(204, service("GET", "/a/test/6/test", "", null, null).getStatus());
+ assertEquals(204, service("GET", "/a/test/7/test?x=1&y=2&x=3&y=4&x=5", "", null, null).getStatus());
+
+ MultivaluedMap<String, String> h = new MultivaluedMapImpl();
+ h.putSingle("foo", "to be or not to be");
+ h.putSingle("bar", "to be or not to be");
+ assertEquals(204, service("GET", "/a/test/8/test", "", h, null).getStatus());
+
+ h.clear();
+ h.putSingle("Content-Type", "application/x-www-form-urlencoded");
+ assertEquals(204, service("POST", "/a/test/9/test", "", h,
+ "bar=to%20be%20or%20not%20to%20be&foo=to%20be%20or%20not%20to%20be".getBytes("UTF-8")).getStatus());
+
+ h.clear();
+ h.putSingle("Cookie",
+ "$Version=1;foo=foo;$Domain=exo.com;$Path=/exo,$Version=1;bar=ar;$Domain=exo.com;$Path=/exo");
+ assertEquals(204, service("GET", "/a/test/11/test", "", h, null).getStatus());
+
+ assertEquals(204, service("GET", "/a/111/12/222", "", null, null).getStatus());
+
+ assertEquals("111", service("GET", "/a/111/13", "", null, null).getEntity());
+ assertEquals("222", service("GET", "/a/111/13?query=222", "", null, null).getEntity());
+
+ try
+ {
+ assertEquals("hello", service("GET", "/a/111/14", "", null, null).getEntity());
+ RequestHandlerImpl.setProperty("prop1", "to be or not to be");
+ assertEquals("to be or not to be", service("GET", "/a/111/14", "", null, null).getEntity());
+ }
+ finally
+ {
+ RequestHandlerImpl.setProperty("prop1", null);
+ }
+
+ unregistry(r1);
+ }
+
+}
Deleted: ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/impl/method/PatametersInjectionTest.java
===================================================================
--- ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/impl/method/PatametersInjectionTest.java 2009-09-04 06:25:33 UTC (rev 136)
+++ ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/impl/method/PatametersInjectionTest.java 2009-09-04 12:17:16 UTC (rev 137)
@@ -1,245 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * 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.exoplatform.services.rest.impl.method;
-
-import org.exoplatform.services.rest.AbstractResourceTest;
-import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
-
-import java.util.List;
-import java.util.Set;
-import java.util.SortedSet;
-
-import javax.ws.rs.CookieParam;
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.FormParam;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.MatrixParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Cookie;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.UriInfo;
-
-/**
- * @author <a href="mailto:andrew00x at gmail.com">Andrey Parfonov</a>
- * @version $Id: $
- */
-public class PatametersInjectionTest extends AbstractResourceTest
-{
-
- @Path("/a/{x}")
- public static class Resource1
- {
-
- @GET
- @Path("/0/{y}/")
- public void m0(@PathParam("x") String x, @PathParam("y") String y)
- {
- assertNotNull(x);
- assertNotNull(y);
- assertEquals(x, y);
- }
-
- @GET
- @Path("/1/{y}/")
- public void m1(@PathParam("x") List<String> x, @PathParam("y") List<String> y)
- {
- assertNotNull(x);
- assertEquals(1, x.size());
- assertNotNull(y);
- assertEquals(1, y.size());
- assertEquals(x, y);
- }
-
- @GET
- @Path("/2/{y}/")
- public void m2(@PathParam("x") Set<String> x, @PathParam("y") Set<String> y)
- {
- assertNotNull(x);
- assertEquals(1, x.size());
- assertNotNull(y);
- assertEquals(1, y.size());
- assertEquals(x, y);
- }
-
- @GET
- @Path("/3/{y}/")
- public void m3(@PathParam("x") SortedSet<String> x, @PathParam("y") SortedSet<String> y)
- {
- assertNotNull(x);
- assertEquals(1, x.size());
- assertNotNull(y);
- assertEquals(1, y.size());
- assertEquals(x, y);
- }
-
- @GET
- @Path("/4/{y}/")
- public void m4(@PathParam("x") Integer x, @PathParam("y") Integer y)
- {
- assertNotNull(x);
- assertNotNull(y);
- assertEquals(1111, x - y);
- }
-
- @GET
- @Path("/5/{y}/")
- public void m5(@PathParam("x") long x, @PathParam("y") long y)
- {
- assertNotNull(x);
- assertNotNull(y);
- assertEquals(1111, x - y);
- }
-
- @GET
- @Path("/6/{y}/")
- public void m6(@PathParam("x") Test x, @PathParam("y") Test y)
- {
- assertNotNull(x);
- assertNotNull(y);
- assertEquals(x.toString(), y.toString());
- }
-
- @GET
- @Path("/7/{y}/")
- public void m7(@QueryParam("x") List<String> x, @QueryParam("y") List<String> y)
- {
- assertNotNull(x);
- assertEquals(3, x.size());
- assertNotNull(y);
- assertEquals(2, y.size());
- assertEquals("1", x.get(0));
- assertEquals("3", x.get(1));
- assertEquals("5", x.get(2));
- assertEquals("2", y.get(0));
- assertEquals("4", y.get(1));
- }
-
- @GET
- @Path("/8/{y}/")
- public void m8(@HeaderParam("foo") String x, @HeaderParam("bar") String y)
- {
- assertNotNull(x);
- assertNotNull(y);
- assertEquals(x, y);
- }
-
- @POST
- @Path("/9/{y}/")
- public void m9(@FormParam("foo") String x, @FormParam("bar") String y)
- {
- assertNotNull(x);
- assertNotNull(y);
- assertEquals(x, y);
- }
-
- @GET
- @Path("/10/{y}/")
- public void m10(@MatrixParam("foo") int x, @MatrixParam("bar") int y)
- {
- assertNotNull(x);
- assertNotNull(y);
- assertEquals(1111, x - y);
- }
-
- @GET
- @Path("/11/{y}/")
- public void m11(@CookieParam("foo") Cookie x, @CookieParam("bar") Cookie y)
- {
- assertNotNull(x);
- assertNotNull(y);
- assertEquals(x.getDomain(), y.getDomain());
- assertEquals(x.getPath(), y.getPath());
- }
-
- @GET
- @Path("/12/{y}/")
- public void m12(@Context UriInfo uriInfo)
- {
- assertNotNull(uriInfo);
- assertEquals(2, uriInfo.getPathParameters().size());
- }
-
- @GET
- @Path("/13")
- public String m13(@QueryParam("query") @DefaultValue("111") String param)
- {
- assertNotNull(param);
-
- return param;
- }
-
- }
-
- public static class Test
- {
- private final String s;
-
- public Test(String s)
- {
- this.s = s;
- }
-
- public String toString()
- {
- return s;
- }
- }
-
- public void testParameterTypes() throws Exception
- {
- Resource1 r1 = new Resource1();
- registry(r1);
- assertEquals(204, service("GET", "/a/test/0/test", "", null, null).getStatus());
- assertEquals(204, service("GET", "/a/test/1/test", "", null, null).getStatus());
- assertEquals(204, service("GET", "/a/test/2/test", "", null, null).getStatus());
- assertEquals(204, service("GET", "/a/test/3/test", "", null, null).getStatus());
- assertEquals(204, service("GET", "/a/3333/4/2222", "", null, null).getStatus());
- assertEquals(204, service("GET", "/a/5555/5/4444", "", null, null).getStatus());
- assertEquals(204, service("GET", "/a/test/6/test", "", null, null).getStatus());
- assertEquals(204, service("GET", "/a/test/7/test?x=1&y=2&x=3&y=4&x=5", "", null, null).getStatus());
-
- MultivaluedMap<String, String> h = new MultivaluedMapImpl();
- h.putSingle("foo", "to be or not to be");
- h.putSingle("bar", "to be or not to be");
- assertEquals(204, service("GET", "/a/test/8/test", "", h, null).getStatus());
-
- h.clear();
- h.putSingle("Content-Type", "application/x-www-form-urlencoded");
- assertEquals(204, service("POST", "/a/test/9/test", "", h,
- "bar=to%20be%20or%20not%20to%20be&foo=to%20be%20or%20not%20to%20be".getBytes("UTF-8")).getStatus());
-
- h.clear();
- h.putSingle("Cookie",
- "$Version=1;foo=foo;$Domain=exo.com;$Path=/exo,$Version=1;bar=ar;$Domain=exo.com;$Path=/exo");
- assertEquals(204, service("GET", "/a/test/11/test", "", h, null).getStatus());
-
- assertEquals(204, service("GET", "/a/111/12/222", "", null, null).getStatus());
-
- assertEquals("111", service("GET", "/a/111/13", "", null, null).getEntity());
- assertEquals("222", service("GET", "/a/111/13?query=222", "", null, null).getEntity());
-
- unregistry(r1);
- }
-
-}
More information about the exo-jcr-commits
mailing list