exo-jcr SVN: r163 - jcr/trunk.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2009-09-10 06:38:41 -0400 (Thu, 10 Sep 2009)
New Revision: 163
Modified:
jcr/trunk/pom.xml
Log:
revert dummy commit
Modified: jcr/trunk/pom.xml
===================================================================
--- jcr/trunk/pom.xml 2009-09-10 10:32:54 UTC (rev 162)
+++ jcr/trunk/pom.xml 2009-09-10 10:38:41 UTC (rev 163)
@@ -22,7 +22,7 @@
<modelVersion>4.0.0</modelVersion>
- <parent>
+ <parent>
<groupId>org.exoplatform</groupId>
<artifactId>foundation-parent</artifactId>
<version>2</version>
14 years, 7 months
exo-jcr SVN: r162 - jcr/trunk.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2009-09-10 06:32:54 -0400 (Thu, 10 Sep 2009)
New Revision: 162
Modified:
jcr/trunk/pom.xml
Log:
dummy commit
Modified: jcr/trunk/pom.xml
===================================================================
--- jcr/trunk/pom.xml 2009-09-10 10:25:53 UTC (rev 161)
+++ jcr/trunk/pom.xml 2009-09-10 10:32:54 UTC (rev 162)
@@ -22,7 +22,7 @@
<modelVersion>4.0.0</modelVersion>
- <parent>
+ <parent>
<groupId>org.exoplatform</groupId>
<artifactId>foundation-parent</artifactId>
<version>2</version>
14 years, 7 months
exo-jcr SVN: r159 - in ws/trunk: rest/core and 2 other directories.
by do-not-reply@jboss.org
Author: max_shaposhnik
Date: 2009-09-10 04:58:25 -0400 (Thu, 10 Sep 2009)
New Revision: 159
Removed:
ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/servlet/
Modified:
ws/trunk/pom.xml
ws/trunk/rest/core/pom.xml
ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/AbstractResourceTest.java
ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletRequest.java
Log:
https://jira.jboss.org/jira/browse/EXOJCR-152
Modified: ws/trunk/pom.xml
===================================================================
--- ws/trunk/pom.xml 2009-09-10 07:39:31 UTC (rev 158)
+++ ws/trunk/pom.xml 2009-09-10 08:58:25 UTC (rev 159)
@@ -55,6 +55,7 @@
<module>commons</module>
<module>frameworks/json</module>
<module>frameworks/servlet</module>
+ <module>testframework</module>
<module>rest/core</module>
<module>rest/ext</module>
</modules>
@@ -77,6 +78,11 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.exoplatform.ws</groupId>
+ <artifactId>exo.ws.testframework</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.exoplatform.kernel</groupId>
<artifactId>exo.kernel.component.common</artifactId>
<version>${org.exoplatform.kernel.version}</version>
Modified: ws/trunk/rest/core/pom.xml
===================================================================
--- ws/trunk/rest/core/pom.xml 2009-09-10 07:39:31 UTC (rev 158)
+++ ws/trunk/rest/core/pom.xml 2009-09-10 08:58:25 UTC (rev 159)
@@ -46,6 +46,11 @@
<artifactId>exo.ws.frameworks.json</artifactId>
</dependency>
<dependency>
+ <groupId>org.exoplatform.ws</groupId>
+ <artifactId>exo.ws.testframework</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
Modified: ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/AbstractResourceTest.java
===================================================================
--- ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/AbstractResourceTest.java 2009-09-10 07:39:31 UTC (rev 158)
+++ ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/AbstractResourceTest.java 2009-09-10 08:58:25 UTC (rev 159)
@@ -23,11 +23,14 @@
import org.exoplatform.services.rest.impl.EnvironmentContext;
import org.exoplatform.services.rest.impl.InputHeadersMap;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
-import org.exoplatform.services.rest.servlet.mock.MockHttpServletRequest;
+import org.exoplatform.testframework.MockHttpServletRequest;
import org.exoplatform.services.rest.tools.DummyContainerResponseWriter;
import java.io.ByteArrayInputStream;
+import java.io.InputStream;
import java.net.URI;
+import java.util.HashMap;
+import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.MultivaluedMap;
@@ -54,13 +57,17 @@
if (data != null)
in = new ByteArrayInputStream(data);
+ HashMap<String, List> map = new HashMap();
+ map.putAll((HashMap)headers);
+
+
EnvironmentContext envctx = new EnvironmentContext();
HttpServletRequest httpRequest =
- new MockHttpServletRequest(in, in != null ? in.available() : 0, method, new InputHeadersMap(headers));
+ new MockHttpServletRequest("",in, in != null ? in.available() : 0, method, map);
envctx.put(HttpServletRequest.class, httpRequest);
EnvironmentContext.setCurrent(envctx);
ContainerRequest request =
- new ContainerRequest(method, new URI(requestURI), new URI(baseURI), in, new InputHeadersMap(headers));
+ new ContainerRequest(method, new URI(requestURI), new URI(baseURI), in, headers);
ContainerResponse response = new ContainerResponse(writer);
requestHandler.handleRequest(request, response);
return response;
Modified: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletRequest.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletRequest.java 2009-09-10 07:39:31 UTC (rev 158)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletRequest.java 2009-09-10 08:58:25 UTC (rev 159)
@@ -29,6 +29,7 @@
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
+import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -96,7 +97,7 @@
* @param headers
* the headers
*/
- public MockHttpServletRequest(String url, InputStream data, int length, String method, Map<String, ArrayList> headers)
+ public MockHttpServletRequest(String url, InputStream data, int length, String method, HashMap<String, List> headers)
{
this.requestURL = url;
this.data = data;
14 years, 7 months
exo-jcr SVN: r158 - ws/trunk/testframework.
by do-not-reply@jboss.org
Author: max_shaposhnik
Date: 2009-09-10 03:39:31 -0400 (Thu, 10 Sep 2009)
New Revision: 158
Modified:
ws/trunk/testframework/pom.xml
Log:
https://jira.jboss.org/jira/browse/EXOJCR-152
Modified: ws/trunk/testframework/pom.xml
===================================================================
--- ws/trunk/testframework/pom.xml 2009-09-09 09:26:41 UTC (rev 157)
+++ ws/trunk/testframework/pom.xml 2009-09-10 07:39:31 UTC (rev 158)
@@ -24,7 +24,7 @@
<parent>
<groupId>org.exoplatform.ws</groupId>
- <artifactId>config</artifactId>
+ <artifactId>ws-parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
</parent>
14 years, 7 months
exo-jcr SVN: r157 - ws/trunk/testframework/src/main/java/org/exoplatform/testframework.
by do-not-reply@jboss.org
Author: max_shaposhnik
Date: 2009-09-09 05:26:41 -0400 (Wed, 09 Sep 2009)
New Revision: 157
Modified:
ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletResponse.java
Log:
https://jira.jboss.org/jira/browse/EXOJCR-152
Modified: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletResponse.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletResponse.java 2009-09-09 09:22:51 UTC (rev 156)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletResponse.java 2009-09-09 09:26:41 UTC (rev 157)
@@ -63,7 +63,7 @@
private ArrayList cookies = new ArrayList();
/** The headers. */
- private HashMap<String, ArrayList> headers = new HashMap<String, ArrayList>();
+ private HashMap headers = new CaseInsensitiveMap();
/** The status. */
private int status = HttpServletResponse.SC_OK;
@@ -207,7 +207,7 @@
Iterator it = headers.keySet().iterator();
while (it.hasNext()){
String key = (String)it.next();
- if (key.equalsIgnoreCase(name)){
+ if (key.equals(name)){
ArrayList values = (ArrayList) headers.get(key);
if (values != null){
values = new ArrayList();
14 years, 7 months
exo-jcr SVN: r156 - ws/trunk/testframework/src/main/java/org/exoplatform/testframework.
by do-not-reply@jboss.org
Author: max_shaposhnik
Date: 2009-09-09 05:22:51 -0400 (Wed, 09 Sep 2009)
New Revision: 156
Modified:
ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletRequest.java
Log:
https://jira.jboss.org/jira/browse/EXOJCR-152
Modified: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletRequest.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletRequest.java 2009-09-09 09:13:21 UTC (rev 155)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletRequest.java 2009-09-09 09:22:51 UTC (rev 156)
@@ -62,7 +62,7 @@
private InputStream data;
/** Headers. */
- private Map<String, ArrayList> headers;
+ private Map headers = new CaseInsensitiveMap();
/** The parameters. */
private Map<String, ArrayList> parameters = new HashMap();
@@ -106,7 +106,7 @@
String queryString = getQueryString();
if (queryString != null)
{
- parameters.putAll(parseQueryString(queryString));
+ parameters.putAll(parseQueryString(queryString));
}
}
@@ -167,17 +167,8 @@
// return headers.getFirst("content-type");
synchronized (headers)
{
- Iterator<String> it = headers.keySet().iterator();
- while (it.hasNext())
- {
- String key = it.next();
- if (key.equalsIgnoreCase("content-type"))
- {
- ArrayList values = (ArrayList)headers.get(key);
- if (values != null)
- return (String)values.get(0);
- }
- }
+ if (headers.get("content-type") != null)
+ return (String)headers.get("content-type");
}
return (null);
}
@@ -209,17 +200,8 @@
// return Long.valueOf(headers.get(name));
synchronized (headers)
{
- Iterator<String> it = headers.keySet().iterator();
- while (it.hasNext())
- {
- String key = it.next();
- if (key.equalsIgnoreCase(name))
- {
- ArrayList values = (ArrayList)headers.get(key);
- if (values != null)
- return (Long)values.get(0);
- }
- }
+ if (headers.get(name) != null)
+ return (Long)headers.get(0);
}
return -1L;
}
@@ -232,17 +214,8 @@
// return headers.get(name);
synchronized (headers)
{
- Iterator<String> it = headers.keySet().iterator();
- while (it.hasNext())
- {
- String key = it.next();
- if (key.equalsIgnoreCase(name))
- {
- ArrayList values = (ArrayList)headers.get(key);
- if (values != null)
- return (String)values.get(0);
- }
- }
+ if (headers.get(name) != null)
+ return (String)headers.get(name);
}
return (null);
}
@@ -294,23 +267,14 @@
// return Integer.valueOf(headers.get(name));
synchronized (headers)
{
- Iterator<String> it = headers.keySet().iterator();
- while (it.hasNext())
- {
- String key = it.next();
- if (key.equalsIgnoreCase(name))
+ if (headers.get(name) != null)
+ try
{
- ArrayList values = (ArrayList)headers.get(key);
- if (values != null)
- try
- {
- return Integer.parseInt((String)values.get(0));
- }
- catch (NumberFormatException e)
- {
- }
+ return Integer.parseInt((String)headers.get(name));
}
- }
+ catch (NumberFormatException e)
+ {
+ }
}
return -1;
}
14 years, 7 months
exo-jcr SVN: r155 - ws/trunk/testframework/src/main/java/org/exoplatform/testframework.
by do-not-reply@jboss.org
Author: max_shaposhnik
Date: 2009-09-09 05:13:21 -0400 (Wed, 09 Sep 2009)
New Revision: 155
Removed:
ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockServletRequest.java
ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockServletResponse.java
Log:
https://jira.jboss.org/jira/browse/EXOJCR-152
Deleted: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockServletRequest.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockServletRequest.java 2009-09-07 13:11:14 UTC (rev 154)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockServletRequest.java 2009-09-09 09:13:21 UTC (rev 155)
@@ -1,670 +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.testframework;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.security.Principal;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Vector;
-
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletInputStream;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
-
-/**
- * Created by The eXo Platform SARL Author : Mestrallet Benjamin
- * benjmestrallet(a)users.sourceforge.net
- */
-public class MockServletRequest implements HttpServletRequest
-{
-
- /** The parameters. */
- private Map parameters;
-
- /** The attributes. */
- private Map attributes;
-
- /** The session. */
- private HttpSession session;
-
- /** The locale. */
- private Locale locale;
-
- /** The secure. */
- private boolean secure;
-
- /** The headers. */
- private Map headers;
-
- /** The enc. */
- private String enc = "ISO-8859-1";
-
- /** The path info_. */
- private String pathInfo_;
-
- /** The request ur i_. */
- private String requestURI_;
-
- /** The url. */
- private URL url;
-
- /** The method. */
- private String method = "GET";
-
- /** The context path. */
- private String contextPath = "";
-
- /** The remote user. */
- private String remoteUser = "REMOTE USER FROM MOCK";
-
- /**
- * Instantiates a new mock servlet request.
- *
- * @param session the session
- * @param locale the locale
- */
- public MockServletRequest(HttpSession session, Locale locale)
- {
-
- this(session, locale, false);
-
- }
-
- /**
- * Instantiates a new mock servlet request.
- *
- * @param session the session
- * @param locale the locale
- * @param secure the secure
- */
- public MockServletRequest(HttpSession session, Locale locale, boolean secure)
- {
-
- this(session, null, null, locale, secure);
- }
-
- /**
- * Instantiates a new mock servlet request.
- *
- * @param session the session
- * @param url the url
- * @param contextPath the context path
- * @param locale the locale
- * @param secure the secure
- */
- public MockServletRequest(HttpSession session, URL url, String contextPath, Locale locale, boolean secure)
- {
- this.session = session;
- this.locale = locale;
- headers = new HashMap();
- parameters = new HashMap();
- attributes = new HashMap();
- this.secure = secure;
- if (url == null)
- {
- try
- {
- this.url = new URL("http://localhost:8080/");
- this.contextPath = "/context";
- }
- catch (MalformedURLException e)
- {
- }
- }
- else
- {
- this.url = url;
- this.contextPath = contextPath;
- }
- }
-
- /**
- * Reset.
- */
- public void reset()
- {
- parameters = new HashMap();
- attributes = new HashMap();
- }
-
- /**
- * {@inheritDoc}
- */
- public String getAuthType()
- {
- return DIGEST_AUTH;
- }
-
- /**
- * {@inheritDoc}
- */
- public Cookie[] getCookies()
- {
- return new Cookie[0];
- }
-
- /**
- * {@inheritDoc}
- */
- public long getDateHeader(String s)
- {
- return 0L;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getHeader(String s)
- {
- return (String)headers.get(s);
- }
-
- /**
- * {@inheritDoc}
- */
- public Enumeration getHeaders(String s)
- {
- if (headers.get(s) instanceof Collection)
- return Collections.enumeration((Collection)headers.get(s));
- else
- {
- Vector v = new Vector();
- v.add(headers.get(s));
- return v.elements();
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public Enumeration getHeaderNames()
- {
- return Collections.enumeration(headers.keySet());
- }
-
- /**
- * {@inheritDoc}
- */
- public int getIntHeader(String s)
- {
- return 0;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getMethod()
- {
-
- return method;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getPathInfo()
- {
- return pathInfo_;
- }
-
- /**
- * Sets the path info.
- *
- * @param s the new path info
- */
- public void setPathInfo(String s)
- {
- pathInfo_ = s;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getPathTranslated()
- {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getContextPath()
- {
- return contextPath;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getQueryString()
- {
- return url.getQuery();
- }
-
- /**
- * {@inheritDoc}
- */
- public String getRemoteUser()
- {
- return remoteUser;
- }
-
- /**
- * Sets the remote user.
- *
- * @param remoteUser the new remote user
- */
- public void setRemoteUser(String remoteUser)
- {
- this.remoteUser = remoteUser;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isUserInRole(String s)
- {
- if ("auth-user".equals(s))
- return true;
- else
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- public Principal getUserPrincipal()
- {
- return new MockPrincipal();
- }
-
- /**
- * {@inheritDoc}
- */
- public String getRequestedSessionId()
- {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getRequestURI()
- {
- if (this.requestURI_ == null)
- return url.getPath();
- else
- return requestURI_;
- }
-
- /**
- * Sets the request uri.
- *
- * @param s the new request uri
- */
- public void setRequestURI(String s)
- {
- this.requestURI_ = s;
- }
-
- /**
- * {@inheritDoc}
- */
- public StringBuffer getRequestURL()
- {
- return new StringBuffer(url.toString());
- }
-
- /**
- * {@inheritDoc}
- */
- public String getServletPath()
- {
- return url.getPath();
- }
-
- /**
- * {@inheritDoc}
- */
- public HttpSession getSession(boolean b)
- {
- return session;
- }
-
- /**
- * {@inheritDoc}
- */
- public HttpSession getSession()
- {
- return session;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isRequestedSessionIdValid()
- {
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isRequestedSessionIdFromCookie()
- {
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isRequestedSessionIdFromURL()
- {
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- @Deprecated
- public boolean isRequestedSessionIdFromUrl()
- {
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object getAttribute(String s)
- {
- return attributes.get(s);
- }
-
- /**
- * {@inheritDoc}
- */
- public Enumeration getAttributeNames()
- {
- return new Vector(attributes.keySet()).elements();
- }
-
- /**
- * {@inheritDoc}
- */
- public String getCharacterEncoding()
- {
- return enc;
- }
-
- /**
- * {@inheritDoc}
- */
- public void setCharacterEncoding(String s) throws UnsupportedEncodingException
- {
- enc = s;
- }
-
- /**
- * {@inheritDoc}
- */
- public int getContentLength()
- {
- return 0;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getContentType()
- {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public ServletInputStream getInputStream() throws IOException
- {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getParameter(String s)
- {
- return (String)parameters.get(s);
- }
-
- /**
- * Sets the parameter.
- *
- * @param s the s
- * @param value the value
- */
- public void setParameter(String s, Object value)
- {
- parameters.put(s, value);
- }
-
- /**
- * {@inheritDoc}
- */
- public Enumeration getParameterNames()
- {
- return new Vector(parameters.keySet()).elements();
- }
-
- /**
- * {@inheritDoc}
- */
- public String[] getParameterValues(String s)
- {
-
- ArrayList<String> arr = new ArrayList<String>();
- Iterator it = parameters.keySet().iterator();
- while (it.hasNext())
- {
-
- String pname = (String)it.next();
- if (pname.equals(s))
- arr.add((String)parameters.get(s));
- }
- return arr.toArray(new String[arr.size()]);
-
- }
-
- /**
- * {@inheritDoc}
- */
- public Map getParameterMap()
- {
- return parameters;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getProtocol()
- {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getScheme()
- {
- return url.getProtocol();
- }
-
- /**
- * {@inheritDoc}
- */
- public String getServerName()
- {
- return url.getHost();
- }
-
- /**
- * {@inheritDoc}
- */
- public int getServerPort()
- {
- return url.getPort();
- }
-
- /**
- * {@inheritDoc}
- */
- public BufferedReader getReader() throws IOException
- {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getRemoteAddr()
- {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getRemoteHost()
- {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public void setAttribute(String s, Object o)
- {
- attributes.put(s, o);
- }
-
- /**
- * {@inheritDoc}
- */
- public void removeAttribute(String s)
- {
- attributes.remove(s);
- }
-
- /**
- * {@inheritDoc}
- */
- public Locale getLocale()
- {
- return locale;
- }
-
- /**
- * {@inheritDoc}
- */
- public Enumeration getLocales()
- {
- System.out.println("MOCK get Locale : " + locale);
- Vector v = new Vector();
- v.add(locale);
- return v.elements();
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isSecure()
- {
- return secure;
- }
-
- /**
- * {@inheritDoc}
- */
- public RequestDispatcher getRequestDispatcher(String s)
- {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getRealPath(String s)
- {
- return null;
- }
-
- //servlet 2.4 method
- /**
- * Gets the local port.
- *
- * @return the local port
- */
- public int getLocalPort()
- {
- return 0;
- }
-
- /**
- * Gets the local addr.
- *
- * @return the local addr
- */
- public String getLocalAddr()
- {
- return "127.0.0.1";
- }
-
- /**
- * Gets the local name.
- *
- * @return the local name
- */
- public String getLocalName()
- {
- return "localhost";
- }
-
- /**
- * Gets the remote port.
- *
- * @return the remote port
- */
- public int getRemotePort()
- {
- return 0;
- }
-}
Deleted: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockServletResponse.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockServletResponse.java 2009-09-07 13:11:14 UTC (rev 154)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockServletResponse.java 2009-09-09 09:13:21 UTC (rev 155)
@@ -1,177 +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.testframework;
-
-import javax.servlet.http.HttpServletResponseWrapper;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.ServletOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.PrintWriter;
-import java.io.IOException;
-import java.util.*;
-
-
-/**
- * Created by The eXo Platform SARL Author : Mestrallet Benjamin
- * benjmestrallet(a)users.sourceforge.net
- */
-public class MockServletResponse extends HttpServletResponseWrapper
-{
-
- /** The tmp writer. */
- private PrintWriter tmpWriter;
-
- /** The output. */
- private ByteArrayOutputStream output;
-
- /** The servlet output. */
- private ByteArrayServletOutputStream servletOutput;
-
- /** The locale. */
- private Locale locale_;
-
- /**
- * Instantiates a new mock servlet response.
- *
- * @param httpServletResponse the http servlet response
- */
- public MockServletResponse(HttpServletResponse httpServletResponse)
- {
- super(httpServletResponse);
- output = new ByteArrayOutputStream();
- tmpWriter = new PrintWriter(output);
- servletOutput = new ByteArrayServletOutputStream(output);
- }
-
- /**
- * {@inheritDoc}
- */
- public void finalize() throws Throwable
- {
- super.finalize();
- servletOutput.close();
- output.close();
- tmpWriter.close();
- }
-
- /**
- * Gets the portlet content.
- *
- * @return the portlet content
- */
- public String getPortletContent()
- {
- String s = output.toString();
- reset();
- return s;
- }
-
- /**
- * Converts output to byte array.
- *
- * @return the byte[]
- */
- public byte[] toByteArray()
- {
- return output.toByteArray();
- }
-
- /**
- * Gets the output content.
- *
- * @return the output content
- */
- public String getOutputContent()
- {
- return new String(output.toByteArray());
- }
-
- /**
- * {@inheritDoc}
- */
- public void flushBuffer() throws IOException
- {
- tmpWriter.flush();
- servletOutput.flush();
- }
-
- /**
- * {@inheritDoc}
- */
- public void reset()
- {
- output.reset();
- }
-
- /**
- * Close.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- */
- public void close() throws IOException
- {
- tmpWriter.close();
- }
-
- /**
- * The Class ByteArrayServletOutputStream.
- */
- private static class ByteArrayServletOutputStream extends ServletOutputStream
- {
-
- /** The baos. */
- ByteArrayOutputStream baos;
-
- /**
- * Instantiates a new byte array servlet output stream.
- *
- * @param baos the baos
- */
- public ByteArrayServletOutputStream(ByteArrayOutputStream baos)
- {
- this.baos = baos;
- }
-
- /**
- * {@inheritDoc}
- */
- public void write(int i) throws IOException
- {
- baos.write(i);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public Locale getLocale()
- {
- return locale_;
- }
-
- /**
- * {@inheritDoc}
- */
- public void setLocale(java.util.Locale loc)
- {
- locale_ = loc;
- }
-
-}
14 years, 7 months
exo-jcr SVN: r138 - in ws/trunk/rest/core/src: test/java/org/exoplatform/services/rest and 1 other directories.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2009-09-04 12:36:33 -0400 (Fri, 04 Sep 2009)
New Revision: 138
Modified:
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/ResourceBinder.java
ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/BaseTest.java
ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java
Log:
EXOJCR-151 : Filters may be setup from javax.ws.rs.core.Application
Modified: ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/ResourceBinder.java
===================================================================
--- ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/ResourceBinder.java 2009-09-04 12:17:16 UTC (rev 137)
+++ ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/ResourceBinder.java 2009-09-04 16:36:33 UTC (rev 138)
@@ -22,11 +22,15 @@
import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import org.exoplatform.services.rest.Filter;
import org.exoplatform.services.rest.ObjectFactory;
import org.exoplatform.services.rest.PerRequestObjectFactory;
+import org.exoplatform.services.rest.RequestFilter;
+import org.exoplatform.services.rest.ResponseFilter;
import org.exoplatform.services.rest.SingletonObjectFactory;
import org.exoplatform.services.rest.impl.resource.AbstractResourceDescriptorImpl;
import org.exoplatform.services.rest.impl.resource.ResourceDescriptorValidator;
+import org.exoplatform.services.rest.method.MethodInvokerFilter;
import org.exoplatform.services.rest.resource.AbstractResourceDescriptor;
import org.exoplatform.services.rest.resource.ResourceContainer;
import org.exoplatform.services.rest.resource.ResourceDescriptorVisitor;
@@ -101,8 +105,6 @@
*/
private final ResourceDescriptorVisitor rdv = ResourceDescriptorValidator.getInstance();
- private final ProviderBinder providers;
-
private int size = 0;
/**
@@ -122,7 +124,6 @@
// TODO better solution to initialize RuntimeDelegate
rd = new RuntimeDelegateImpl();
RuntimeDelegate.setInstance(rd);
- providers = ProviderBinder.getInstance();
ExoContainer container = containerContext.getContainer();
@@ -156,6 +157,7 @@
@SuppressWarnings("unchecked")
public void addApplication(Application application)
{
+ ProviderBinder providers = ProviderBinder.getInstance();
for (Object obj : application.getSingletons())
{
if (obj.getClass().getAnnotation(Provider.class) != null)
@@ -178,6 +180,22 @@
providers.addMessageBodyWriter((MessageBodyWriter)obj);
}
}
+ else if (obj.getClass().getAnnotation(Filter.class) != null)
+ {
+ // singleton filter
+ if (obj instanceof MethodInvokerFilter)
+ {
+ providers.addMethodInvokerFilter((MethodInvokerFilter)obj);
+ }
+ if (obj instanceof RequestFilter)
+ {
+ providers.addRequestFilter((RequestFilter)obj);
+ }
+ if (obj instanceof ResponseFilter)
+ {
+ providers.addResponseFilter((ResponseFilter)obj);
+ }
+ }
else
{
bind(obj); // singleton resource
@@ -205,6 +223,22 @@
providers.addMessageBodyWriter(clazz);
}
}
+ else if (clazz.getAnnotation(Filter.class) != null)
+ {
+ // per-request filter
+ if (MethodInvokerFilter.class.isAssignableFrom(clazz))
+ {
+ providers.addMethodInvokerFilter(clazz);
+ }
+ if (RequestFilter.class.isAssignableFrom(clazz))
+ {
+ providers.addRequestFilter(clazz);
+ }
+ if (ResponseFilter.class.isAssignableFrom(clazz))
+ {
+ providers.addResponseFilter(clazz);
+ }
+ }
else
{
bind(clazz); // per-request resource
Modified: ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/BaseTest.java
===================================================================
--- ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/BaseTest.java 2009-09-04 12:17:16 UTC (rev 137)
+++ ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/BaseTest.java 2009-09-04 16:36:33 UTC (rev 138)
@@ -47,6 +47,7 @@
container = StandaloneContainer.getInstance();
binder = (ResourceBinder)container.getComponentInstanceOfType(ResourceBinder.class);
requestHandler = (RequestHandlerImpl)container.getComponentInstanceOfType(RequestHandlerImpl.class);
+ // reset providers to be sure it is clean
ProviderBinder.setInstance(new ProviderBinder());
providers = ProviderBinder.getInstance();
// System.out.println("##########################"+providers);
Modified: ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java
===================================================================
--- ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java 2009-09-04 12:17:16 UTC (rev 137)
+++ ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java 2009-09-04 16:36:33 UTC (rev 138)
@@ -19,6 +19,14 @@
package org.exoplatform.services.rest.impl.resource;
import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.Filter;
+import org.exoplatform.services.rest.GenericContainerRequest;
+import org.exoplatform.services.rest.GenericContainerResponse;
+import org.exoplatform.services.rest.RequestFilter;
+import org.exoplatform.services.rest.ResponseFilter;
+import org.exoplatform.services.rest.impl.ContainerResponse;
+import org.exoplatform.services.rest.method.MethodInvokerFilter;
+import org.exoplatform.services.rest.resource.GenericMethodResource;
import java.util.HashSet;
import java.util.Set;
@@ -48,10 +56,13 @@
perreq.add(Resource1.class);
perreq.add(Resource2.class);
perreq.add(ExceptionMapper1.class);
+ perreq.add(MethodInvokerFilter1.class);
+ perreq.add(RequestFilter1.class);
singletons.add(new Resource3());
singletons.add(new Resource4());
singletons.add(new ExceptionMapper2());
+ singletons.add(new ResponseFilter1());
}
@Override
@@ -140,46 +151,92 @@
}
}
+
+ @Filter
+ public static class MethodInvokerFilter1 implements MethodInvokerFilter
+ {
+ public void accept(GenericMethodResource genericMethodResource)
+ {
+ invFilter = true;
+ }
+
+ }
+
+ @Filter
+ public static class RequestFilter1 implements RequestFilter
+ {
+
+ public void doFilter(GenericContainerRequest request)
+ {
+ requestFilter = true;
+ }
+
+ }
+
+ @Filter
+ public static class ResponseFilter1 implements ResponseFilter
+ {
+
+ public void doFilter(GenericContainerResponse response)
+ {
+ responseFilter = true;
+ }
+
+ }
+
public void testRegistry()
{
- // binder.addApplication(new Application1());
- // assertEquals(4, binder.getSize());
- // assertNotNull(rd.getExceptionMapper(RuntimeException.class));
+ binder.addApplication(new Application1());
+ assertEquals(4, binder.getSize());
+ assertEquals(1, providers.getRequestFilters(null).size());
+ assertEquals(1, providers.getResponseFilters(null).size());
+ assertEquals(1, providers.getMethodInvokerFilters(null).size());
+ assertNotNull(providers.getExceptionMapper(RuntimeException.class));
+ assertNotNull(providers.getExceptionMapper(IllegalStateException.class));
}
+ private static boolean requestFilter = false;
+ private static boolean responseFilter = false;
+ private static boolean invFilter = false;
+
public void testAsResources() throws Exception
{
- // binder.addApplication(new Application1());
- // // per-request
- // ContainerResponse resp = service("GET", "/a", "", null, null);
- // assertEquals(200, resp.getStatus());
- // String hash10 = (String) resp.getEntity();
- // resp = service("GET", "/a", "", null, null);
- // String hash11 = (String) resp.getEntity();
- // // new instance of resource for each request
- // assertFalse(hash10.equals(hash11));
- //
- // // singleton
- // resp = service("GET", "/c", "", null, null);
- // assertEquals(200, resp.getStatus());
- // String hash20 = (String) resp.getEntity();
- // resp = service("GET", "/c", "", null, null);
- // String hash21 = (String) resp.getEntity();
- // // singleton resource
- // assertTrue(hash20.equals(hash21));
- //
- // // check per-request ExceptionMapper as example of provider
- // resp = service("GET", "/b", "", null, null);
- // // should be 200 status instead 500 if ExceptionMapper works correct
- // assertEquals(200, resp.getStatus());
- // assertEquals("test Runtime Exception", resp.getEntity());
- //
- // // check singleton ExceptionMapper as example of provider
- // resp = service("GET", "/d", "", null, null);
- // // should be 200 status instead 500 if ExceptionMapper works correct
- // assertEquals(200, resp.getStatus());
- // assertEquals("test Illegal State Exception", resp.getEntity());
+ binder.addApplication(new Application1());
+ // per-request
+ ContainerResponse resp = service("GET", "/a", "", null, null);
+ assertEquals(200, resp.getStatus());
+ String hash10 = (String)resp.getEntity();
+ resp = service("GET", "/a", "", null, null);
+ String hash11 = (String)resp.getEntity();
+ // new instance of resource for each request
+ assertFalse(hash10.equals(hash11));
+
+ // singleton
+ resp = service("GET", "/c", "", null, null);
+ assertEquals(200, resp.getStatus());
+ String hash20 = (String)resp.getEntity();
+ resp = service("GET", "/c", "", null, null);
+ String hash21 = (String)resp.getEntity();
+ // singleton resource
+ assertTrue(hash20.equals(hash21));
+
+ // check per-request ExceptionMapper as example of provider
+ resp = service("GET", "/b", "", null, null);
+ // should be 200 status instead 500 if ExceptionMapper works correct
+ assertEquals(200, resp.getStatus());
+ assertEquals("test Runtime Exception", resp.getEntity());
+
+ // check singleton ExceptionMapper as example of provider
+ resp = service("GET", "/d", "", null, null);
+ // should be 200 status instead 500 if ExceptionMapper works correct
+ assertEquals(200, resp.getStatus());
+ assertEquals("test Illegal State Exception", resp.getEntity());
+
+ // check are filters were visited
+ assertTrue(requestFilter);
+ assertTrue(responseFilter);
+ assertTrue(invFilter);
}
}
14 years, 8 months
exo-jcr SVN: r137 - in ws/trunk/rest/core/src: main/java/org/exoplatform/services/rest/impl and 4 other directories.
by do-not-reply@jboss.org
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@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@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@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@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@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);
- }
-
-}
14 years, 8 months
exo-jcr SVN: r136 - in ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest: impl and 1 other directories.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2009-09-04 02:25:33 -0400 (Fri, 04 Sep 2009)
New Revision: 136
Added:
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/Property.java
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/PropertyResolver.java
Modified:
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java
Log:
EXOJCR-143 : Add property resolver
Added: ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/Property.java
===================================================================
--- ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/Property.java (rev 0)
+++ ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/Property.java 2009-09-04 06:25:33 UTC (rev 136)
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.exoplatform.services.rest.impl.RequestHandlerImpl;
+
+/**
+ * Useful for injection in service, provider or filter properties which
+ * is preset in {@link RequestHandlerImpl}.
+ *
+ * @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
+ * @version $Id$
+ *
+ */
+(a)Target({ElementType.PARAMETER, ElementType.FIELD})
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface Property {
+
+ String value();
+
+}
Property changes on: ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/Property.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
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-03 08:24:44 UTC (rev 135)
+++ ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java 2009-09-04 06:25:33 UTC (rev 136)
@@ -46,6 +46,7 @@
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;
@@ -61,8 +62,13 @@
* Logger.
*/
private static final Log LOG = ExoLogger.getLogger(RequestHandlerImpl.class.getName());
-
+
/**
+ * Application properties.
+ */
+ private static final MultivaluedMap<String, String> properties = new MultivaluedMapImpl();
+
+ /**
* See {@link RequestDispatcher}.
*/
private final RequestDispatcher dispatcher;
Added: 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 (rev 0)
+++ ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/PropertyResolver.java 2009-09-04 06:25:33 UTC (rev 136)
@@ -0,0 +1,59 @@
+/*
+ * 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.ApplicationContext;
+import org.exoplatform.services.rest.Property;
+import org.exoplatform.services.rest.method.TypeProducer;
+
+/**
+ * @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
+ * @version $Id$
+ *
+ */
+public class PropertyResolver extends ParameterResolver<Property>
+{
+
+ /**
+ * See {@link Property}
+ */
+ private final Property property;
+
+ /**
+ * @param property Property
+ */
+ PropertyResolver(Property property)
+ {
+ this.property = property;
+ }
+
+ /**
+ * @see org.exoplatform.services.rest.impl.method.ParameterResolver#resolve(org.exoplatform.services.rest.Parameter, org.exoplatform.services.rest.ApplicationContext)
+ */
+ @Override
+ public Object resolve(org.exoplatform.services.rest.Parameter parameter, ApplicationContext context)
+ throws Exception
+ {
+ String param = this.property.value();
+ TypeProducer typeProducer =
+ ParameterHelper.createTypeProducer(parameter.getParameterClass(), parameter.getGenericType());
+ return typeProducer.createValue(param, null, parameter.getDefaultValue());
+ }
+
+}
Property changes on: ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/PropertyResolver.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
14 years, 8 months