Author: aparfonov
Date: 2009-10-28 02:47:29 -0400 (Wed, 28 Oct 2009)
New Revision: 436
Added:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationPublisher.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/StandaloneRestServlet.java
ws/branches/2.2.x/rest/exo.ws.rest.deploy/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/pom.xml
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/exoplatform/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/exoplatform/services/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/exoplatform/services/rest/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/exoplatform/services/rest/impl/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/exoplatform/services/rest/impl/ExoJAXRSApplication.java
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/exoplatform/services/rest/impl/StartableApplicationPublisher.java
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/exoplatform/services/rest/servlet/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/exoplatform/services/rest/servlet/RestServlet.java
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/resources/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/resources/conf/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/resources/conf/portal/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/resources/conf/portal/configuration.xml
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/org/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/org/exoplatform/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/org/exoplatform/services/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/org/exoplatform/services/rest/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/org/exoplatform/services/rest/impl/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/org/exoplatform/services/rest/impl/BaseTest.java
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/org/exoplatform/services/rest/impl/DependencySupplierTest.java
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/org/exoplatform/services/rest/impl/StartableApplicationPublisherTest.java
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/resources/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/resources/conf/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/resources/conf/standalone/
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/resources/conf/standalone/test-configuration.xml
Removed:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationDeployer.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RestComponentDeployer.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/BaseRestServlet.java
ws/branches/2.2.x/rest/ext/src/main/java/conf/portal/
ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/impl/
ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/servlet/
ws/branches/2.2.x/rest/ext/src/test/java/conf/standalone/
ws/branches/2.2.x/rest/ext/src/test/java/org/exoplatform/services/rest/impl/
Modified:
ws/branches/2.2.x/pom.xml
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/DependencySupplier.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ConstructorDescriptorImpl.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/FieldInjectorImpl.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/SimpleDependencySupplier.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/InjectableProvider.java
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/RestInitializedListener.java
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java
ws/branches/2.2.x/rest/ext/pom.xml
Log:
EXOJCR-214 : created deploy sub-project, made required changes in exo.ws.rest.core and
exo.ws.res.ext
Modified: ws/branches/2.2.x/pom.xml
===================================================================
--- ws/branches/2.2.x/pom.xml 2009-10-27 15:02:22 UTC (rev 435)
+++ ws/branches/2.2.x/pom.xml 2009-10-28 06:47:29 UTC (rev 436)
@@ -58,6 +58,7 @@
<module>testframework</module>
<module>rest/core</module>
<module>rest/ext</module>
+ <module>rest/exo.ws.rest.deploy</module>
<module>packaging/module</module>
</modules>
@@ -80,6 +81,11 @@
</dependency>
<dependency>
<groupId>org.exoplatform.ws</groupId>
+ <artifactId>exo.ws.rest.ext</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.ws</groupId>
<artifactId>exo.ws.testframework</artifactId>
<version>${project.version}</version>
</dependency>
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/DependencySupplier.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/DependencySupplier.java 2009-10-27
15:02:22 UTC (rev 435)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/DependencySupplier.java 2009-10-28
06:47:29 UTC (rev 436)
@@ -35,6 +35,6 @@
* @return object of required type or null if instance described by
* <code>parameter</code> may not be produced
*/
- Object getInstanceOfType(Parameter parameter);
+ Object getComponent(Parameter parameter);
}
Deleted:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationDeployer.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationDeployer.java 2009-10-27
15:02:22 UTC (rev 435)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationDeployer.java 2009-10-28
06:47:29 UTC (rev 436)
@@ -1,50 +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;
-
-import org.exoplatform.services.rest.ResourceBinder;
-
-import javax.ws.rs.core.Application;
-
-/**
- * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey
Parfonov</a>
- * @version $Id: $
- */
-public class ApplicationDeployer extends RestComponentDeployer
-{
-
- public ApplicationDeployer(ResourceBinder resources, ProviderBinder providers)
- {
- super(resources, providers);
- }
-
- @SuppressWarnings("unchecked")
- public void deploy(Application application)
- {
- for (Object instance : application.getSingletons())
- {
- deploy(instance);
- }
- for (Class clazz : application.getClasses())
- {
- deploy(clazz);
- }
- }
-
-}
Copied:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationPublisher.java
(from rev 435,
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationDeployer.java)
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationPublisher.java
(rev 0)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationPublisher.java 2009-10-28
06:47:29 UTC (rev 436)
@@ -0,0 +1,58 @@
+/*
+ * 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;
+
+import java.util.Set;
+
+import org.exoplatform.services.rest.ResourceBinder;
+
+import javax.ws.rs.core.Application;
+
+/**
+ * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey
Parfonov</a>
+ * @version $Id$
+ */
+public class ApplicationPublisher
+{
+
+ protected RestComponentResolver resolver;
+
+ public ApplicationPublisher(ResourceBinder resources, ProviderBinder providers)
+ {
+ resolver = new RestComponentResolver(resources, providers);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void publish(Application application)
+ {
+ Set<Object> singletons = application.getSingletons();
+ if (singletons != null)
+ {
+ for (Object instance : singletons)
+ resolver.addSingleton(instance);
+ }
+ Set<Class<?>> perRequests = application.getClasses();
+ if (perRequests != null)
+ {
+ for (Class clazz : perRequests)
+ resolver.addPerRequest(clazz);
+ }
+ }
+
+}
Property changes on:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationPublisher.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ConstructorDescriptorImpl.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ConstructorDescriptorImpl.java 2009-10-27
15:02:22 UTC (rev 435)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ConstructorDescriptorImpl.java 2009-10-28
06:47:29 UTC (rev 436)
@@ -254,7 +254,7 @@
.type(MediaType.TEXT_PLAIN).build());
}
- Object tmp = context.getDependencySupplier().getInstanceOfType(cp);
+ Object tmp = context.getDependencySupplier().getComponent(cp);
if (tmp == null)
{
String msg =
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/FieldInjectorImpl.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/FieldInjectorImpl.java 2009-10-27
15:02:22 UTC (rev 435)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/FieldInjectorImpl.java 2009-10-28
06:47:29 UTC (rev 436)
@@ -228,7 +228,7 @@
{
if (context.getDependencySupplier() != null)
{
- Object tmp = context.getDependencySupplier().getInstanceOfType(this);
+ Object tmp = context.getDependencySupplier().getComponent(this);
if (tmp != null)
{
try
Deleted:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RestComponentDeployer.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RestComponentDeployer.java 2009-10-27
15:02:22 UTC (rev 435)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RestComponentDeployer.java 2009-10-28
06:47:29 UTC (rev 436)
@@ -1,48 +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;
-
-import org.exoplatform.services.rest.ResourceBinder;
-
-/**
- * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey
Parfonov</a>
- * @version $Id: $
- */
-public abstract class RestComponentDeployer
-{
-
- protected RestComponentResolver resolver;
-
- public RestComponentDeployer(ResourceBinder resources, ProviderBinder providers)
- {
- resolver = new RestComponentResolver(resources, providers);
- }
-
- public void deploy(Object instance)
- {
- resolver.addSingleton(instance);
- }
-
- @SuppressWarnings("unchecked")
- public void deploy(Class clazz)
- {
- resolver.addPerRequest(clazz);
- }
-
-}
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/SimpleDependencySupplier.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/SimpleDependencySupplier.java 2009-10-27
15:02:22 UTC (rev 435)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/SimpleDependencySupplier.java 2009-10-28
06:47:29 UTC (rev 436)
@@ -38,7 +38,7 @@
/**
* {@inheritDoc}
*/
- public Object getInstanceOfType(Parameter parameter)
+ public Object getComponent(Parameter parameter)
{
if (parameter instanceof FieldInjector)
{
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/InjectableProvider.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/InjectableProvider.java 2009-10-27
15:02:22 UTC (rev 435)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/InjectableProvider.java 2009-10-28
06:47:29 UTC (rev 436)
@@ -25,6 +25,7 @@
/**
* @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey
Parfonov</a>
* @version $Id$
+ * @deprecated
*/
public class InjectableProvider extends ParameterResolver<Inject>
{
@@ -40,7 +41,7 @@
public Object resolve(Parameter parameter, ApplicationContext context) throws
Exception
{
if (context.getDependencySupplier() != null)
- return context.getDependencySupplier().getInstanceOfType(parameter);
+ return context.getDependencySupplier().getComponent(parameter);
return null;
}
Deleted:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/BaseRestServlet.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/BaseRestServlet.java 2009-10-27
15:02:22 UTC (rev 435)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/BaseRestServlet.java 2009-10-28
06:47:29 UTC (rev 436)
@@ -1,89 +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.servlet;
-
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-import org.exoplatform.services.rest.RequestHandler;
-import org.exoplatform.services.rest.impl.ContainerResponse;
-import org.exoplatform.services.rest.impl.EnvironmentContext;
-import java.io.IOException;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * @author <a href="mailto:andrew00x@gmail.com">Andrey
Parfonov</a>
- * @version $Id$
- */
-public class BaseRestServlet extends HttpServlet
-{
-
- private static final long serialVersionUID = -8234561611241680339L;
-
- private static final Log LOG = ExoLogger.getLogger(BaseRestServlet.class.getName());
-
- private RequestHandler requestHandler;
-
- private ServletConfig servletConfig;
-
- protected RequestHandler getRequestHandler()
- {
- return requestHandler;
- }
-
- public void init(ServletConfig servletConfig)
- {
- this.servletConfig = servletConfig;
- requestHandler =
(RequestHandler)servletConfig.getServletContext().getAttribute(RequestHandler.class.getName());
- }
-
- public void service(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
throws IOException,
- ServletException
- {
-
- EnvironmentContext env = new EnvironmentContext();
- env.put(HttpServletRequest.class, httpRequest);
- env.put(HttpServletResponse.class, httpResponse);
- env.put(ServletConfig.class, servletConfig);
- env.put(ServletContext.class, servletConfig.getServletContext());
-
- try
- {
- EnvironmentContext.setCurrent(env);
- ServletContainerRequest request = new ServletContainerRequest(httpRequest);
- ContainerResponse response = new ContainerResponse(new
ServletContainerResponseWriter(httpResponse));
- getRequestHandler().handleRequest(request, response);
- }
- catch (Exception e)
- {
- LOG.error(e);
- throw new ServletException(e);
- }
- finally
- {
- EnvironmentContext.setCurrent(null);
- }
- }
-
-}
Modified:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/RestInitializedListener.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/RestInitializedListener.java 2009-10-27
15:02:22 UTC (rev 435)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/RestInitializedListener.java 2009-10-28
06:47:29 UTC (rev 436)
@@ -25,7 +25,7 @@
import org.exoplatform.services.rest.Filter;
import org.exoplatform.services.rest.RequestHandler;
import org.exoplatform.services.rest.ResourceBinder;
-import org.exoplatform.services.rest.impl.ApplicationDeployer;
+import org.exoplatform.services.rest.impl.ApplicationPublisher;
import org.exoplatform.services.rest.impl.ProviderBinder;
import org.exoplatform.services.rest.impl.ResourceBinderImpl;
import org.exoplatform.services.rest.impl.RequestHandlerImpl;
@@ -35,6 +35,7 @@
import java.io.IOException;
import java.lang.reflect.Modifier;
import java.net.URL;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -71,7 +72,7 @@
String dependencyInjectorFQN =
event.getServletContext().getInitParameter(DependencySupplier.class.getName());
ResourceBinder resources = new ResourceBinderImpl();
- ApplicationDeployer deployer = new ApplicationDeployer(resources,
ProviderBinder.getInstance());
+ ApplicationPublisher publisher = new ApplicationPublisher(resources,
ProviderBinder.getInstance());
String applicationFQN =
event.getServletContext().getInitParameter("javax.ws.rs.Application");
if (applicationFQN != null)
@@ -85,7 +86,7 @@
{
Class<?> cl =
Thread.currentThread().getContextClassLoader().loadClass(applicationFQN.trim());
Application application = (Application)cl.newInstance();
- deployer.deploy(application);
+ publisher.publish(application);
}
catch (ClassNotFoundException cnfe)
{
@@ -113,6 +114,7 @@
annotationDB.scanArchives(classes);
annotationDB.scanArchives(libs);
+ final Set<Class<?>> scanned = new
HashSet<Class<?>>();
Map<String, Set<String>> results =
annotationDB.getAnnotationIndex();
for (String annotation : new String[]{Path.class.getName(),
Provider.class.getName(),
Filter.class.getName()})
@@ -129,8 +131,7 @@
LOG.info("Skip abstract class or interface " +
fqn);
continue;
}
- deployer.deploy(cl);
- LOG.info("Deployed component: " + fqn);
+ scanned.add(cl);
}
catch (ClassNotFoundException e)
{
@@ -139,6 +140,14 @@
}
}
}
+ publisher.publish(new Application()
+ {
+ @Override
+ public Set<Class<?>> getClasses()
+ {
+ return scanned;
+ }
+ });
}
catch (IOException e)
{
Copied:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/StandaloneRestServlet.java
(from rev 435,
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/BaseRestServlet.java)
===================================================================
---
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/StandaloneRestServlet.java
(rev 0)
+++
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/StandaloneRestServlet.java 2009-10-28
06:47:29 UTC (rev 436)
@@ -0,0 +1,89 @@
+/*
+ * 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.servlet;
+
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.exoplatform.services.rest.RequestHandler;
+import org.exoplatform.services.rest.impl.ContainerResponse;
+import org.exoplatform.services.rest.impl.EnvironmentContext;
+import java.io.IOException;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author <a href="mailto:andrew00x@gmail.com">Andrey
Parfonov</a>
+ * @version $Id$
+ */
+public class StandaloneRestServlet extends HttpServlet
+{
+
+ private static final long serialVersionUID = -8234561611241680339L;
+
+ private static final Log LOG =
ExoLogger.getLogger(StandaloneRestServlet.class.getName());
+
+ private RequestHandler requestHandler;
+
+ private ServletConfig servletConfig;
+
+ protected RequestHandler getRequestHandler()
+ {
+ return requestHandler;
+ }
+
+ public void init(ServletConfig servletConfig)
+ {
+ this.servletConfig = servletConfig;
+ requestHandler =
(RequestHandler)servletConfig.getServletContext().getAttribute(RequestHandler.class.getName());
+ }
+
+ public void service(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
throws IOException,
+ ServletException
+ {
+
+ EnvironmentContext env = new EnvironmentContext();
+ env.put(HttpServletRequest.class, httpRequest);
+ env.put(HttpServletResponse.class, httpResponse);
+ env.put(ServletConfig.class, servletConfig);
+ env.put(ServletContext.class, servletConfig.getServletContext());
+
+ try
+ {
+ EnvironmentContext.setCurrent(env);
+ ServletContainerRequest request = new ServletContainerRequest(httpRequest);
+ ContainerResponse response = new ContainerResponse(new
ServletContainerResponseWriter(httpResponse));
+ getRequestHandler().handleRequest(request, response);
+ }
+ catch (Exception e)
+ {
+ LOG.error(e);
+ throw new ServletException(e);
+ }
+ finally
+ {
+ EnvironmentContext.setCurrent(null);
+ }
+ }
+
+}
Property changes on:
ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/StandaloneRestServlet.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified:
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java
===================================================================
---
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java 2009-10-27
15:02:22 UTC (rev 435)
+++
ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java 2009-10-28
06:47:29 UTC (rev 436)
@@ -24,7 +24,7 @@
import org.exoplatform.services.rest.RequestFilter;
import org.exoplatform.services.rest.ResponseFilter;
import org.exoplatform.services.rest.impl.AbstractResourceTest;
-import org.exoplatform.services.rest.impl.ApplicationDeployer;
+import org.exoplatform.services.rest.impl.ApplicationPublisher;
import org.exoplatform.services.rest.impl.ContainerResponse;
import org.exoplatform.services.rest.method.MethodInvokerFilter;
import org.exoplatform.services.rest.resource.GenericMethodResource;
@@ -188,8 +188,8 @@
public void testRegistry()
{
- ApplicationDeployer deployer = new ApplicationDeployer(resources, providers);
- deployer.deploy(new Application1());
+ ApplicationPublisher deployer = new ApplicationPublisher(resources, providers);
+ deployer.publish(new Application1());
assertEquals(4, resources.getSize());
assertEquals(1, providers.getRequestFilters(null).size());
assertEquals(1, providers.getResponseFilters(null).size());
@@ -204,8 +204,8 @@
public void testAsResources() throws Exception
{
- ApplicationDeployer deployer = new ApplicationDeployer(resources, providers);
- deployer.deploy(new Application1());
+ ApplicationPublisher deployer = new ApplicationPublisher(resources, providers);
+ deployer.publish(new Application1());
// per-request
ContainerResponse resp = service("GET", "/a", "",
null, null);
assertEquals(200, resp.getStatus());
Added: ws/branches/2.2.x/rest/exo.ws.rest.deploy/pom.xml
===================================================================
--- ws/branches/2.2.x/rest/exo.ws.rest.deploy/pom.xml (rev 0)
+++ ws/branches/2.2.x/rest/exo.ws.rest.deploy/pom.xml 2009-10-28 06:47:29 UTC (rev 436)
@@ -0,0 +1,45 @@
+<!--
+
+ 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.
+
+-->
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.exoplatform.ws</groupId>
+ <artifactId>ws-parent</artifactId>
+ <version>2.2.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>exo.ws.rest.deploy</artifactId>
+
+ <name>eXo WS :: REST :: Deploy</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.exoplatform.ws</groupId>
+ <artifactId>exo.ws.rest.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.container</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Added:
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/exoplatform/services/rest/impl/ExoJAXRSApplication.java
===================================================================
---
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/exoplatform/services/rest/impl/ExoJAXRSApplication.java
(rev 0)
+++
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/exoplatform/services/rest/impl/ExoJAXRSApplication.java 2009-10-28
06:47:29 UTC (rev 436)
@@ -0,0 +1,104 @@
+/*
+ * 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;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.exoplatform.services.rest.resource.ResourceContainer;
+import org.picocontainer.Startable;
+
+/**
+ * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey
Parfonov</a>
+ * @version $Id$
+ */
+public class ExoJAXRSApplication extends Application implements Startable
+{
+
+ /**
+ * Logger.
+ */
+ private static final Log LOG = ExoLogger.getLogger(ExoJAXRSApplication.class);
+
+ private ExoContainer container;
+
+ private Set<Class<?>> cls = new HashSet<Class<?>>();
+
+ private Set<Object> singletons = new HashSet<Object>();
+
+ public ExoJAXRSApplication(InitParams initParams, ExoContainerContext
containerContext)
+ {
+ if (initParams != null)
+ {
+ for (Object cl :
initParams.getValuesParam("ws.rest.components").getValues())
+ {
+ try
+ {
+ cls.add(Class.forName((String)cl));
+ }
+ catch (ClassNotFoundException e)
+ {
+ LOG.error("Failed load class " + cl, e);
+ }
+ }
+ }
+ container = containerContext.getContainer();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<Class<?>> getClasses()
+ {
+ return cls;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<Object> getSingletons()
+ {
+ return singletons;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void start()
+ {
+ for (Object resource :
container.getComponentInstancesOfType(ResourceContainer.class))
+ singletons.add(resource);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void stop()
+ {
+ }
+
+}
Property changes on:
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/exoplatform/services/rest/impl/ExoJAXRSApplication.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added:
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/exoplatform/services/rest/impl/StartableApplicationPublisher.java
===================================================================
---
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/exoplatform/services/rest/impl/StartableApplicationPublisher.java
(rev 0)
+++
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/exoplatform/services/rest/impl/StartableApplicationPublisher.java 2009-10-28
06:47:29 UTC (rev 436)
@@ -0,0 +1,90 @@
+/*
+ * 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;
+
+import java.lang.annotation.Annotation;
+import java.util.List;
+
+import javax.ws.rs.core.Application;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.services.rest.DependencySupplier;
+import org.exoplatform.services.rest.FieldInjector;
+import org.exoplatform.services.rest.Inject;
+import org.exoplatform.services.rest.Parameter;
+import org.exoplatform.services.rest.ResourceBinder;
+import org.picocontainer.Startable;
+
+/**
+ * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey
Parfonov</a>
+ * @version $Id$
+ */
+public class StartableApplicationPublisher extends ApplicationPublisher implements
DependencySupplier, Startable
+{
+
+ private ExoContainer container;
+
+ public StartableApplicationPublisher(ResourceBinder resources, ExoContainerContext
containerContext)
+ {
+ super(resources, ProviderBinder.getInstance());
+ container = containerContext.getContainer();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object getComponent(Parameter parameter)
+ {
+ // Container can different.
+ ExoContainer container = ExoContainerContext.getCurrentContainer();
+
+ if (parameter instanceof FieldInjector)
+ {
+ for (Annotation a : parameter.getAnnotations())
+ {
+ // Do not process fields without annotation Inject
+ if (a.annotationType() == Inject.class)
+ {
+ return
container.getComponentInstanceOfType(parameter.getParameterClass());
+ }
+ }
+ }
+ return container.getComponentInstanceOfType(parameter.getParameterClass());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ public void start()
+ {
+ List<Application> applications =
container.getComponentInstancesOfType(Application.class);
+ for (Application application : applications)
+ publish(application);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void stop()
+ {
+ }
+
+}
Property changes on:
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/exoplatform/services/rest/impl/StartableApplicationPublisher.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added:
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/exoplatform/services/rest/servlet/RestServlet.java
===================================================================
---
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/exoplatform/services/rest/servlet/RestServlet.java
(rev 0)
+++
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/exoplatform/services/rest/servlet/RestServlet.java 2009-10-28
06:47:29 UTC (rev 436)
@@ -0,0 +1,87 @@
+/*
+ * 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.servlet;
+
+import java.io.IOException;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.web.AbstractHttpServlet;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.exoplatform.services.rest.Connector;
+import org.exoplatform.services.rest.RequestHandler;
+import org.exoplatform.services.rest.impl.ContainerResponse;
+import org.exoplatform.services.rest.impl.EnvironmentContext;
+
+/**
+ * This servlet is front-end for the REST engine.
+ *
+ * @author <a href="mailto:andrew00x@gmail.com">Andrey
Parfonov</a>
+ * @version $Id$
+ */
+public class RestServlet extends AbstractHttpServlet implements Connector
+{
+
+ private static final Log LOG = ExoLogger.getLogger(RestServlet.class.getName());
+
+ /**
+ * Generated by Eclipse.
+ */
+ private static final long serialVersionUID = 2152962763071591181L;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onService(ExoContainer container, HttpServletRequest httpRequest,
HttpServletResponse httpResponse)
+ throws IOException, ServletException
+ {
+
+ RequestHandler requestHandler =
(RequestHandler)container.getComponentInstanceOfType(RequestHandler.class);
+
+ EnvironmentContext env = new EnvironmentContext();
+ env.put(HttpServletRequest.class, httpRequest);
+ env.put(HttpServletResponse.class, httpResponse);
+ env.put(ServletConfig.class, config);
+ env.put(ServletContext.class, getServletContext());
+
+ try
+ {
+ EnvironmentContext.setCurrent(env);
+ ServletContainerRequest request = new ServletContainerRequest(httpRequest);
+ ContainerResponse response = new ContainerResponse(new
ServletContainerResponseWriter(httpResponse));
+ requestHandler.handleRequest(request, response);
+ }
+ catch (Exception e)
+ {
+ LOG.error(e);
+ throw new ServletException(e);
+ }
+ finally
+ {
+ EnvironmentContext.setCurrent(null);
+ }
+ }
+}
Property changes on:
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/java/org/exoplatform/services/rest/servlet/RestServlet.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added:
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/resources/conf/portal/configuration.xml
===================================================================
---
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/resources/conf/portal/configuration.xml
(rev 0)
+++
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/main/resources/conf/portal/configuration.xml 2009-10-28
06:47:29 UTC (rev 436)
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ 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.
+
+-->
+
+<configuration
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd
http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
+
+ <component>
+ <key>org.exoplatform.services.log.LogConfigurationInitializer</key>
+ <type>org.exoplatform.services.log.LogConfigurationInitializer</type>
+ <init-params>
+ <value-param>
+ <name>logger</name>
+ <value>org.slf4j.Logger</value>
+ </value-param>
+ <value-param>
+ <name>configurator</name>
+
<value>org.exoplatform.services.log.impl.Log4JConfigurator</value>
+ </value-param>
+ <properties-param>
+ <name>properties</name>
+ <description>Log4J properties</description>
+ <property name="log4j.rootLogger" value="INFO, stdout"
/>
+ <property name="log4j.appender.stdout"
value="org.apache.log4j.ConsoleAppender" />
+ <property name="log4j.appender.stdout.threshold"
value="DEBUG" />
+ <property name="log4j.appender.stdout.layout"
value="org.apache.log4j.PatternLayout" />
+ <property name="log4j.appender.stdout.layout.ConversionPattern"
value="%d{dd.MM.yyyy HH:mm:ss} *%-5p* [%t] %c{1}: %m (%F, line %L) %n" />
+ <property name="log4j.appender.file"
value="org.apache.log4j.FileAppender" />
+ <property name="log4j.appender.file.File"
value="target/container.log" />
+ <property name="log4j.appender.file.layout"
value="org.apache.log4j.PatternLayout" />
+ <property name="log4j.appender.file.layout.ConversionPattern"
value="%d{dd.MM.yyyy HH:mm:ss} *%-5p* [%t] %c{1}: %m (%F, line %L) %n" />
+ </properties-param>
+ </init-params>
+ </component>
+ <component>
+ <type>org.exoplatform.services.rest.impl.ExoJAXRSApplication</type>
+ <init-params>
+ <values-param>
+ <name>ws.rest.components</name>
+
<value>org.exoplatform.services.rest.ext.provider.HierarchicalPropertyEntityProvider</value>
+
<value>org.exoplatform.services.rest.ext.filter.MethodOverrideFilter</value>
+
<value>org.exoplatform.services.rest.ext.method.filter.MethodAccessFilter</value>
+ </values-param>
+ </init-params>
+ </component>
+ <component>
+
<type>org.exoplatform.services.rest.impl.StartableApplicationPublisher</type>
+ </component>
+ <component>
+ <type>org.exoplatform.services.rest.impl.RequestHandlerImpl</type>
+ </component>
+ <component>
+ <type>org.exoplatform.services.rest.impl.ResourceBinderImpl</type>
+ </component>
+
+</configuration>
\ No newline at end of file
Added:
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/org/exoplatform/services/rest/impl/BaseTest.java
===================================================================
---
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/org/exoplatform/services/rest/impl/BaseTest.java
(rev 0)
+++
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/org/exoplatform/services/rest/impl/BaseTest.java 2009-10-28
06:47:29 UTC (rev 436)
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+import org.exoplatform.container.StandaloneContainer;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey
Parfonov</a>
+ * @version $Id$
+ */
+public abstract class BaseTest extends TestCase
+{
+
+ protected StandaloneContainer container;
+
+ public void setUp() throws Exception
+ {
+
StandaloneContainer.setConfigurationPath("src/test/resources/conf/standalone/test-configuration.xml");
+ container = StandaloneContainer.getInstance();
+ }
+
+ protected void setContext()
+ {
+ ApplicationContextImpl.setCurrent(new ApplicationContextImpl(null, null,
ProviderBinder.getInstance()));
+ }
+
+}
Property changes on:
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/org/exoplatform/services/rest/impl/BaseTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added:
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/org/exoplatform/services/rest/impl/DependencySupplierTest.java
===================================================================
---
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/org/exoplatform/services/rest/impl/DependencySupplierTest.java
(rev 0)
+++
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/org/exoplatform/services/rest/impl/DependencySupplierTest.java 2009-10-28
06:47:29 UTC (rev 436)
@@ -0,0 +1,54 @@
+/*
+ * 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;
+
+import java.lang.annotation.Annotation;
+
+import org.exoplatform.services.rest.DependencySupplier;
+import org.exoplatform.services.rest.Parameter;
+
+/**
+ * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey
Parfonov</a>
+ * @version $Id$
+ */
+public class DependencySupplierTest extends BaseTest
+{
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ setContext();
+ }
+
+ public static class Component1
+ {
+ // For testing DependencySupplier.
+ }
+
+ public void testDependencySupplier()
+ {
+ DependencySupplier depSupplier =
+
(DependencySupplier)container.getComponentInstanceOfType(DependencySupplier.class);
+ assertNotNull(depSupplier);
+ container.registerComponentInstance(new Component1());
+ Parameter t = new ConstructorParameterImpl(null, new Annotation[0],
Component1.class, null, null, false);
+ assertNotNull(depSupplier.getComponent(t));
+ }
+
+}
Property changes on:
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/org/exoplatform/services/rest/impl/DependencySupplierTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added:
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/org/exoplatform/services/rest/impl/StartableApplicationPublisherTest.java
===================================================================
---
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/org/exoplatform/services/rest/impl/StartableApplicationPublisherTest.java
(rev 0)
+++
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/org/exoplatform/services/rest/impl/StartableApplicationPublisherTest.java 2009-10-28
06:47:29 UTC (rev 436)
@@ -0,0 +1,179 @@
+/*
+ * 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;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.net.URI;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.Provider;
+
+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.RequestHandler;
+import org.exoplatform.services.rest.ResponseFilter;
+import org.exoplatform.services.rest.method.MethodInvokerFilter;
+import org.exoplatform.services.rest.provider.EntityProvider;
+import org.exoplatform.services.rest.resource.GenericMethodResource;
+import org.exoplatform.services.rest.resource.ResourceContainer;
+import org.exoplatform.services.rest.tools.ByteArrayContainerResponseWriter;
+
+/**
+ * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey
Parfonov</a>
+ * @version $Id$
+ */
+public class StartableApplicationPublisherTest extends BaseTest
+{
+
+ private RequestHandler handler;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ setContext();
+ handler =
(RequestHandler)container.getComponentInstanceOfType(RequestHandler.class);
+ assertNotNull(handler);
+ }
+
+ // Check does we get all additional component specified in configuration.
+ public void testDeployAdditionalComponents()
+ {
+ ProviderBinder providers = ProviderBinder.getInstance();
+ // XXX Able (no NPE) to use null instead "path" because UriPattern
+ // for filters is null and path will be never checked.
+ assertEquals(1, providers.getRequestFilters(null).size());
+ assertEquals(1, providers.getMethodInvokerFilters(null).size());
+ // -----
+ assertNotNull(providers.getMessageBodyReader(FakeEntity.class, null, null,
MediaType.APPLICATION_XML_TYPE));
+ assertNotNull(providers.getMessageBodyWriter(FakeEntity.class, null, null,
MediaType.APPLICATION_XML_TYPE));
+ }
+
+ public void testResource() throws Exception
+ {
+ ContainerRequest request =
+ new ContainerRequest("GET", new
URI("http://localhost:8080/rest/a/b"), new
URI("http://localhost:8080/rest"),
+ new ByteArrayInputStream("to be or not to
be".getBytes("UTF-8")), new MultivaluedMapImpl());
+ ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
+ ContainerResponse response = new ContainerResponse(writer);
+ handler.handleRequest(request, response);
+ assertEquals(200, response.getStatus());
+ assertEquals("echo: to be or not to be", new String(writer.getBody()));
+ }
+
+ @Provider
+ @Produces(MediaType.APPLICATION_XML)
+ @Consumes(MediaType.APPLICATION_XML)
+ public static class FakeEntityProvider implements EntityProvider<FakeEntity>
+ {
+
+ public boolean isReadable(Class<?> type, Type genericType, Annotation[]
annotations, MediaType mediaType)
+ {
+ return type == FakeEntity.class;
+ }
+
+ public FakeEntity readFrom(Class<FakeEntity> type, Type genericType,
Annotation[] annotations,
+ MediaType mediaType, MultivaluedMap<String, String> httpHeaders,
InputStream entityStream) throws IOException,
+ WebApplicationException
+ {
+ return new FakeEntity();
+ }
+
+ public long getSize(FakeEntity t, Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType)
+ {
+ return 0;
+ }
+
+ public boolean isWriteable(Class<?> type, Type genericType, Annotation[]
annotations, MediaType mediaType)
+ {
+ return type == FakeEntity.class;
+ }
+
+ public void writeTo(FakeEntity t, Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType,
+ MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
throws IOException,
+ WebApplicationException
+ {
+ entityStream.write("fake-entity".getBytes("UTF-8"));
+ }
+
+ }
+
+ public static class FakeEntity
+ {
+
+ }
+
+ // --------------
+
+ @Filter
+ public static class FakeRequestFilter implements RequestFilter
+ {
+ public void doFilter(GenericContainerRequest request)
+ {
+ }
+ }
+
+ // --------------
+
+ @Filter
+ public static class FakeResponseFilter implements ResponseFilter
+ {
+ public void doFilter(GenericContainerResponse response)
+ {
+ }
+ }
+
+ // --------------
+
+ @Filter
+ public static class FakeMethodInvokerFilter implements MethodInvokerFilter
+ {
+ public void accept(GenericMethodResource genericMethodResource)
+ {
+ }
+ }
+
+ // -------------- Component of exo-container. It will become to be singleton resource.
+
+ @Path("a")
+ public static class Resource1 implements ResourceContainer
+ {
+
+ @GET
+ @Path("b")
+ public String m0(String s)
+ {
+ return "echo: " + s;
+ }
+
+ }
+
+}
Property changes on:
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/java/org/exoplatform/services/rest/impl/StartableApplicationPublisherTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added:
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/resources/conf/standalone/test-configuration.xml
===================================================================
---
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/resources/conf/standalone/test-configuration.xml
(rev 0)
+++
ws/branches/2.2.x/rest/exo.ws.rest.deploy/src/test/resources/conf/standalone/test-configuration.xml 2009-10-28
06:47:29 UTC (rev 436)
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ 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.
+
+-->
+
+<configuration
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd
http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
+
+ <component>
+ <key>org.exoplatform.services.log.LogConfigurationInitializer</key>
+ <type>org.exoplatform.services.log.LogConfigurationInitializer</type>
+ <init-params>
+ <value-param>
+ <name>logger</name>
+ <value>org.slf4j.Logger</value>
+ </value-param>
+ <value-param>
+ <name>configurator</name>
+
<value>org.exoplatform.services.log.impl.Log4JConfigurator</value>
+ </value-param>
+ <properties-param>
+ <name>properties</name>
+ <description>Log4J properties</description>
+ <property name="log4j.rootLogger" value="INFO, stdout"
/>
+ <property name="log4j.appender.stdout"
value="org.apache.log4j.ConsoleAppender" />
+ <property name="log4j.appender.stdout.threshold"
value="DEBUG" />
+ <property name="log4j.appender.stdout.layout"
value="org.apache.log4j.PatternLayout" />
+ <property name="log4j.appender.stdout.layout.ConversionPattern"
value="%d{dd.MM.yyyy HH:mm:ss} *%-5p* [%t] %c{1}: %m (%F, line %L) %n" />
+ <property name="log4j.appender.file"
value="org.apache.log4j.FileAppender" />
+ <property name="log4j.appender.file.File"
value="target/container.log" />
+ <property name="log4j.appender.file.layout"
value="org.apache.log4j.PatternLayout" />
+ <property name="log4j.appender.file.layout.ConversionPattern"
value="%d{dd.MM.yyyy HH:mm:ss} *%-5p* [%t] %c{1}: %m (%F, line %L) %n" />
+ </properties-param>
+ </init-params>
+ </component>
+ <component>
+ <type>org.exoplatform.services.rest.impl.ExoJAXRSApplication</type>
+ <init-params>
+ <values-param>
+ <name>ws.rest.components</name>
+
<value>org.exoplatform.services.rest.impl.StartableApplicationPublisherTest$FakeEntityProvider</value>
+
<value>org.exoplatform.services.rest.impl.StartableApplicationPublisherTest$FakeRequestFilter</value>
+
<value>org.exoplatform.services.rest.impl.StartableApplicationPublisherTest$FakeResponseFilter</value>
+
<value>org.exoplatform.services.rest.impl.StartableApplicationPublisherTest$FakeMethodInvokerFilter</value>
+ </values-param>
+ </init-params>
+ </component>
+ <component>
+
<type>org.exoplatform.services.rest.impl.StartableApplicationPublisher</type>
+ </component>
+ <component>
+ <type>org.exoplatform.services.rest.impl.RequestHandlerImpl</type>
+ </component>
+ <component>
+ <type>org.exoplatform.services.rest.impl.ResourceBinderImpl</type>
+ </component>
+
+ <component>
+
<type>org.exoplatform.services.rest.impl.StartableApplicationPublisherTest$Resource1</type>
+ </component>
+
+</configuration>
\ No newline at end of file
Modified: ws/branches/2.2.x/rest/ext/pom.xml
===================================================================
--- ws/branches/2.2.x/rest/ext/pom.xml 2009-10-27 15:02:22 UTC (rev 435)
+++ ws/branches/2.2.x/rest/ext/pom.xml 2009-10-28 06:47:29 UTC (rev 436)
@@ -34,10 +34,6 @@
<dependencies>
<dependency>
- <groupId>org.exoplatform.kernel</groupId>
- <artifactId>exo.kernel.container</artifactId>
- </dependency>
- <dependency>
<groupId>org.exoplatform.ws</groupId>
<artifactId>exo.ws.commons</artifactId>
</dependency>
@@ -46,10 +42,6 @@
<artifactId>exo.ws.rest.core</artifactId>
</dependency>
<dependency>
- <groupId>org.exoplatform.kernel</groupId>
- <artifactId>exo.kernel.container</artifactId>
- </dependency>
- <dependency>
<groupId>org.exoplatform.core</groupId>
<artifactId>exo.core.component.xml-processing</artifactId>
</dependency>