[exo-jcr-commits] exo-jcr SVN: r279 - in ws/branches/2.2.x/rest: core/src/main/java/org/exoplatform/services/rest and 8 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Oct 14 11:58:07 EDT 2009


Author: aparfonov
Date: 2009-10-14 11:58:06 -0400 (Wed, 14 Oct 2009)
New Revision: 279

Added:
   ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ComponentLifecycleScope.java
   ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/Inject.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/ServletContainerResponseWriter.java
   ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/ContainerObjectFactory.java
   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/impl/ExoContainerResourceBinder.java
   ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/servlet/
   ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/servlet/RestServlet.java
Removed:
   ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ComponentLifecycleScope.java
   ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ContainerObjectFactory.java
   ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/RestServlet.java
Modified:
   ws/branches/2.2.x/rest/core/pom.xml
   ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationContextImpl.java
   ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/BaseResourceBinder.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/method/ParameterHelper.java
   ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterResolverFactory.java
   ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/PropertyResolver.java
   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/test/java/org/exoplatform/services/rest/impl/BaseTest.java
   ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java
   ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/provider/JAXBEntityProviderTest.java
Log:
EXOJCR-185 : 

Modified: ws/branches/2.2.x/rest/core/pom.xml
===================================================================
--- ws/branches/2.2.x/rest/core/pom.xml	2009-10-14 15:18:48 UTC (rev 278)
+++ ws/branches/2.2.x/rest/core/pom.xml	2009-10-14 15:58:06 UTC (rev 279)
@@ -33,10 +33,10 @@
    <name>eXo WS :: REST :: Core</name>
 
    <dependencies>
-      <dependency>
+      <!--dependency>
          <groupId>org.exoplatform.kernel</groupId>
          <artifactId>exo.kernel.component.common</artifactId>
-      </dependency>
+      </dependency-->
       <dependency>
          <groupId>org.exoplatform.core</groupId>
          <artifactId>exo.core.component.xml-processing</artifactId>

Deleted: ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ComponentLifecycleScope.java
===================================================================
--- ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ComponentLifecycleScope.java	2009-10-14 15:18:48 UTC (rev 278)
+++ ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ComponentLifecycleScope.java	2009-10-14 15:58:06 UTC (rev 279)
@@ -1,38 +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;
-
-/**
- * Object scope identifier.
- */
- at Deprecated
-public enum ComponentLifecycleScope {
-   /**
-    * New instance of object created foe each request.
-    */
-   PER_REQUEST,
-   /**
-    * Singleton lifecycle.
-    */
-   SINGLETON,
-   /**
-    * Inversion-of-control framework controls component's lifecycle.
-    */
-   CONTAINER
-}

Added: ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ComponentLifecycleScope.java
===================================================================
--- ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ComponentLifecycleScope.java	                        (rev 0)
+++ ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ComponentLifecycleScope.java	2009-10-14 15:58:06 UTC (rev 279)
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+/**
+ * Object scope identifier.
+ */
+public enum ComponentLifecycleScope {
+   /**
+    * New instance of object created foe each request.
+    */
+   PER_REQUEST,
+   /**
+    * Singleton lifecycle.
+    */
+   SINGLETON,
+   /**
+    * Inversion-of-control framework controls component's lifecycle.
+    */
+   IOC
+}


Property changes on: ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ComponentLifecycleScope.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Deleted: ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ContainerObjectFactory.java
===================================================================
--- ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ContainerObjectFactory.java	2009-10-14 15:18:48 UTC (rev 278)
+++ ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ContainerObjectFactory.java	2009-10-14 15:58:06 UTC (rev 279)
@@ -1,66 +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;
-
-import org.exoplatform.container.ExoContainerContext;
-
-/**
- * Factory provides object that is created and is manageable by
- * inversion-of-control container, PicoContainer.
- * 
- * @param <T> any extension of {@link ObjectModel}
- * @author <a href="mailto:andrew00x at gmail.com">Andrey Parfonov</a>
- * @version $Id: $
- */
- at Deprecated
-public class ContainerObjectFactory<T extends ObjectModel> implements ObjectFactory<T>
-{
-
-   /**
-    * Object model.
-    */
-   protected final T model;
-
-   /**
-    * @param model object model
-    * @see ObjectModel
-    */
-   public ContainerObjectFactory(T model)
-   {
-      this.model = model;
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public Object getInstance(ApplicationContext context)
-   {
-      Class<?> clazz = model.getObjectClass();
-      return ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(clazz);
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public T getObjectModel()
-   {
-      return model;
-   }
-
-}

Added: ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/Inject.java
===================================================================
--- ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/Inject.java	                        (rev 0)
+++ ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/Inject.java	2009-10-14 15:58:06 UTC (rev 279)
@@ -0,0 +1,38 @@
+/*
+ * 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;
+
+/**
+ * Used to annotate fields that should be injected with instances 
+ * provided by {@link DependencyInjector}. If DependencyInjector
+ * is not available than field will be not initialized
+
+ * @author <a href="mailto:andrey.parfonov at exoplatform.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+ at Target(ElementType.FIELD)
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface Inject {
+
+}


Property changes on: ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/Inject.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/main/java/org/exoplatform/services/rest/impl/ApplicationContextImpl.java
===================================================================
--- ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationContextImpl.java	2009-10-14 15:18:48 UTC (rev 278)
+++ ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ApplicationContextImpl.java	2009-10-14 15:58:06 UTC (rev 279)
@@ -159,6 +159,8 @@
     */
    private MultivaluedMap<String, String> queryParameters;
 
+   private DependencyInjector depInjector;
+
    /**
     * Constructs new instance of ApplicationContext.
     * 
@@ -250,10 +252,12 @@
       return response;
    }
 
+   /**
+    * {@inheritDoc}
+    */
    public DependencyInjector getDependencyInjector()
    {
-      // TODO Auto-generated method stub
-      return null;
+      return depInjector;
    }
 
    /**
@@ -477,10 +481,12 @@
       return this;
    }
 
+   /**
+    * {@inheritDoc}
+    */
    public void setDependencyInjector(DependencyInjector depInjector)
    {
-      // TODO Auto-generated method stub
-      
+      this.depInjector = depInjector;
    }
 
    /**

Modified: ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/BaseResourceBinder.java
===================================================================
--- ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/BaseResourceBinder.java	2009-10-14 15:18:48 UTC (rev 278)
+++ ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/BaseResourceBinder.java	2009-10-14 15:58:06 UTC (rev 279)
@@ -59,7 +59,7 @@
    /**
     * Logger.
     */
-   private static final Log LOG = ExoLogger.getLogger("ws.rest.core.ResourceBinder");
+   private static final Log LOG = ExoLogger.getLogger(BaseResourceBinder.class.getName());
 
    private static final Comparator<ObjectFactory<AbstractResourceDescriptor>> RESOURCE_COMPARATOR =
       new ResourceComparator();
@@ -112,46 +112,6 @@
    }
    
    /**
-    * @param containerContext eXo container context
-    * @throws Exception if can't set instance of {@link RuntimeDelegate}
-    */
-   /*
-   @SuppressWarnings("unchecked")
-   public ResourceBinder(ExoContainerContext containerContext) throws Exception
-   {
-      // Initialize RuntimeDelegate instance
-      // This is first component in life cycle what needs.
-      // TODO better solution to initialize RuntimeDelegate
-      rd = new RuntimeDelegateImpl();
-      RuntimeDelegate.setInstance(rd);
-
-      ExoContainer container = containerContext.getContainer();
-
-      // Lookup Applications
-      List<Application> al = container.getComponentInstancesOfType(Application.class);
-      for (Application a : al)
-      {
-         try
-         {
-            addApplication(a);
-         }
-         catch (Exception e)
-         {
-            LOG.error("Failed add JAX-RS application " + a.getClass().getName(), e);
-         }
-      }
-
-      // Lookup all object which implements ResourceContainer interface and
-      // process them to be add as root resources.
-      for (Object resource : container.getComponentInstancesOfType(ResourceContainer.class))
-      {
-         bind(resource);
-      }
-
-   }
-   */
-
-   /**
     * @param application Application
     * @see Application
     */

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-14 15:18:48 UTC (rev 278)
+++ ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ConstructorDescriptorImpl.java	2009-10-14 15:58:06 UTC (rev 279)
@@ -239,6 +239,8 @@
          }
          else
          {
+            // XXX need to use @Inject annotation here ??? 
+            
             // If parameter not has not annotation then get constructor parameter
             // from DependencyInjector, this is out of scope JAX-RS specification.
             

Added: 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	                        (rev 0)
+++ ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/InjectableProvider.java	2009-10-14 15:58:06 UTC (rev 279)
@@ -0,0 +1,48 @@
+/*
+ * 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.Inject;
+import org.exoplatform.services.rest.Parameter;
+
+/**
+ * @author <a href="mailto:andrey.parfonov at exoplatform.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public class InjectableProvider extends ParameterResolver<Inject>
+{
+
+   InjectableProvider(Inject inject)
+   {
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Object resolve(Parameter parameter, ApplicationContext context) throws Exception
+   {
+      if (context.getDependencyInjector() != null)
+         return context.getDependencyInjector().getInjectableParameter(parameter.getParameterClass(), null);
+
+      return null;
+   }
+
+}


Property changes on: ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/InjectableProvider.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/main/java/org/exoplatform/services/rest/impl/method/ParameterHelper.java
===================================================================
--- ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterHelper.java	2009-10-14 15:18:48 UTC (rev 278)
+++ ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterHelper.java	2009-10-14 15:58:06 UTC (rev 279)
@@ -18,6 +18,7 @@
  */
 package org.exoplatform.services.rest.impl.method;
 
+import org.exoplatform.services.rest.Inject;
 import org.exoplatform.services.rest.Property;
 import org.exoplatform.services.rest.method.TypeProducer;
 
@@ -88,11 +89,12 @@
    static
    {
       PROVIDER_FIELDS_ANNOTATIONS =
-         Collections.unmodifiableList(Arrays.asList(Context.class.getName(), Property.class.getName()));
-      
+         Collections.unmodifiableList(Arrays.asList(Context.class.getName(), Property.class.getName(), Inject.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());
@@ -101,6 +103,7 @@
       tmp1.add(PathParam.class.getName());
       tmp1.add(QueryParam.class.getName());
       tmp1.add(Property.class.getName());
+      tmp1.add(Inject.class.getName());
       RESOURCE_FIELDS_ANNOTATIONS = Collections.unmodifiableList(tmp1);
       RESOURCE_CONSTRUCTOR_PARAMETER_ANNOTATIONS = Collections.unmodifiableList(tmp1);
 

Modified: ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterResolverFactory.java
===================================================================
--- ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterResolverFactory.java	2009-10-14 15:18:48 UTC (rev 278)
+++ ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/ParameterResolverFactory.java	2009-10-14 15:58:06 UTC (rev 279)
@@ -28,6 +28,7 @@
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Context;
 
+import org.exoplatform.services.rest.Inject;
 import org.exoplatform.services.rest.Property;
 
 /**
@@ -70,6 +71,8 @@
          return new QueryParameterResolver((QueryParam)annotation);
       if (clazz == Property.class)
          return new PropertyResolver((Property)annotation);
+      if (clazz == Inject.class)
+         return new InjectableProvider((Inject)annotation);
       return null;
    }
 

Modified: ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/PropertyResolver.java
===================================================================
--- ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/PropertyResolver.java	2009-10-14 15:18:48 UTC (rev 278)
+++ ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/PropertyResolver.java	2009-10-14 15:58:06 UTC (rev 279)
@@ -19,13 +19,15 @@
 package org.exoplatform.services.rest.impl.method;
 
 import org.exoplatform.services.rest.ApplicationContext;
+import org.exoplatform.services.rest.InitialProperties;
 import org.exoplatform.services.rest.Property;
-import org.exoplatform.services.rest.impl.ApplicationContextImpl;
 
 /**
+ * Obtain value of property (see {@link InitialProperties}) with name 
+ * supplied in {@link Property#value()} .
+ * 
  * @author <a href="mailto:andrew00x at gmail.com">Andrey Parfonov</a>
  * @version $Id$
- *
  */
 public class PropertyResolver extends ParameterResolver<Property>
 {
@@ -44,9 +46,8 @@
    }
 
    /**
-    * @see org.exoplatform.services.rest.impl.method.ParameterResolver#resolve(org.exoplatform.services.rest.Parameter, org.exoplatform.services.rest.ApplicationContext)
+    * {@inheritDoc}
     */
-   @Override
    public Object resolve(org.exoplatform.services.rest.Parameter parameter, ApplicationContext context)
       throws Exception
    {

Modified: 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-14 15:18:48 UTC (rev 278)
+++ ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/BaseRestServlet.java	2009-10-14 15:58:06 UTC (rev 279)
@@ -20,16 +20,10 @@
 
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
-import org.exoplatform.services.rest.ContainerResponseWriter;
-import org.exoplatform.services.rest.GenericContainerResponse;
 import org.exoplatform.services.rest.RequestHandler;
 import org.exoplatform.services.rest.impl.ContainerResponse;
 import org.exoplatform.services.rest.impl.EnvironmentContext;
-import org.exoplatform.services.rest.impl.header.HeaderHelper;
 import java.io.IOException;
-import java.io.OutputStream;
-import java.util.List;
-import java.util.Map;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
@@ -37,7 +31,6 @@
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.ext.MessageBodyWriter;
 
 /**
  * @author <a href="mailto:andrew00x at gmail.com">Andrey Parfonov</a>
@@ -48,70 +41,8 @@
 
    private static final long serialVersionUID = -8234561611241680339L;
 
-   /**
-    * See {@link ContainerResponseWriter}.
-    */
-   class ServletContainerResponseWriter implements ContainerResponseWriter
-   {
+   private static final Log LOG = ExoLogger.getLogger(BaseRestServlet.class.getName());
 
-      /**
-       * See {@link HttpServletResponse}.
-       */
-      private HttpServletResponse servletResponse;
-
-      /**
-       * @param response HttpServletResponse
-       */
-      ServletContainerResponseWriter(HttpServletResponse response)
-      {
-         this.servletResponse = response;
-      }
-
-      /**
-       * {@inheritDoc}
-       */
-      @SuppressWarnings("unchecked")
-      public void writeBody(GenericContainerResponse response, MessageBodyWriter entityWriter) throws IOException
-      {
-         Object entity = response.getEntity();
-         if (entity != null)
-         {
-            OutputStream out = servletResponse.getOutputStream();
-            entityWriter.writeTo(entity, entity.getClass(), response.getEntityType(), null, response.getContentType(),
-               response.getHttpHeaders(), out);
-            out.flush();
-         }
-      }
-
-      /**
-       * {@inheritDoc}
-       */
-      public void writeHeaders(GenericContainerResponse response) throws IOException
-      {
-         if (servletResponse.isCommitted())
-            return;
-
-         servletResponse.setStatus(response.getStatus());
-
-         if (response.getHttpHeaders() != null)
-         {
-            // content-type and content-length should be preset in headers
-            for (Map.Entry<String, List<Object>> e : response.getHttpHeaders().entrySet())
-            {
-               String name = e.getKey();
-               for (Object o : e.getValue())
-               {
-                  String value = null;
-                  if (o != null && (value = HeaderHelper.getHeaderAsString(o)) != null)
-                     servletResponse.addHeader(name, value);
-               }
-            }
-         }
-      }
-   }
-
-   private static final Log LOG = ExoLogger.getLogger(RestServlet.class.getName());
-
    private RequestHandler requestHandler;
 
    private ServletConfig servletConfig;

Deleted: ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/RestServlet.java
===================================================================
--- ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/RestServlet.java	2009-10-14 15:18:48 UTC (rev 278)
+++ ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/RestServlet.java	2009-10-14 15:58:06 UTC (rev 279)
@@ -1,156 +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.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.ContainerResponseWriter;
-import org.exoplatform.services.rest.GenericContainerResponse;
-import org.exoplatform.services.rest.RequestHandler;
-import org.exoplatform.services.rest.impl.ContainerResponse;
-import org.exoplatform.services.rest.impl.EnvironmentContext;
-import org.exoplatform.services.rest.impl.header.HeaderHelper;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.ext.MessageBodyWriter;
-
-/**
- * This servlet is front-end for the REST engine.
- * 
- * @author <a href="mailto:andrew00x at 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);
-      }
-   }
-
-   /**
-    * See {@link ContainerResponseWriter}.
-    */
-   class ServletContainerResponseWriter implements ContainerResponseWriter
-   {
-
-      /**
-       * See {@link HttpServletResponse}.
-       */
-      private HttpServletResponse servletResponse;
-
-      /**
-       * @param response HttpServletResponse
-       */
-      ServletContainerResponseWriter(HttpServletResponse response)
-      {
-         this.servletResponse = response;
-      }
-
-      /**
-       * {@inheritDoc}
-       */
-      @SuppressWarnings("unchecked")
-      public void writeBody(GenericContainerResponse response, MessageBodyWriter entityWriter) throws IOException
-      {
-         Object entity = response.getEntity();
-         if (entity != null)
-         {
-            OutputStream out = servletResponse.getOutputStream();
-            entityWriter.writeTo(entity, entity.getClass(), response.getEntityType(), null, response.getContentType(),
-               response.getHttpHeaders(), out);
-            out.flush();
-         }
-      }
-
-      /**
-       * {@inheritDoc}
-       */
-      public void writeHeaders(GenericContainerResponse response) throws IOException
-      {
-         if (servletResponse.isCommitted())
-            return;
-
-         servletResponse.setStatus(response.getStatus());
-
-         if (response.getHttpHeaders() != null)
-         {
-            // content-type and content-length should be preset in headers
-            for (Map.Entry<String, List<Object>> e : response.getHttpHeaders().entrySet())
-            {
-               String name = e.getKey();
-               for (Object o : e.getValue())
-               {
-                  String value = null;
-                  if (o != null && (value = HeaderHelper.getHeaderAsString(o)) != null)
-                     servletResponse.addHeader(name, value);
-               }
-            }
-         }
-      }
-   }
-}

Added: ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/ServletContainerResponseWriter.java
===================================================================
--- ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/ServletContainerResponseWriter.java	                        (rev 0)
+++ ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/ServletContainerResponseWriter.java	2009-10-14 15:58:06 UTC (rev 279)
@@ -0,0 +1,96 @@
+/*
+ * 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 java.io.OutputStream;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.ext.MessageBodyWriter;
+
+import org.exoplatform.services.rest.ContainerResponseWriter;
+import org.exoplatform.services.rest.GenericContainerResponse;
+import org.exoplatform.services.rest.impl.header.HeaderHelper;
+
+/**
+ * See {@link ContainerResponseWriter}.
+ * 
+ * @author <a href="mailto:andrey.parfonov at exoplatform.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public class ServletContainerResponseWriter implements ContainerResponseWriter
+{
+
+   /**
+    * See {@link HttpServletResponse}.
+    */
+   private HttpServletResponse servletResponse;
+
+   /**
+    * @param response HttpServletResponse
+    */
+   ServletContainerResponseWriter(HttpServletResponse response)
+   {
+      this.servletResponse = response;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @SuppressWarnings("unchecked")
+   public void writeBody(GenericContainerResponse response, MessageBodyWriter entityWriter) throws IOException
+   {
+      Object entity = response.getEntity();
+      if (entity != null)
+      {
+         OutputStream out = servletResponse.getOutputStream();
+         entityWriter.writeTo(entity, entity.getClass(), response.getEntityType(), null, response.getContentType(),
+            response.getHttpHeaders(), out);
+         out.flush();
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void writeHeaders(GenericContainerResponse response) throws IOException
+   {
+      if (servletResponse.isCommitted())
+         return;
+
+      servletResponse.setStatus(response.getStatus());
+
+      if (response.getHttpHeaders() != null)
+      {
+         // content-type and content-length should be preset in headers
+         for (Map.Entry<String, List<Object>> e : response.getHttpHeaders().entrySet())
+         {
+            String name = e.getKey();
+            for (Object o : e.getValue())
+            {
+               String value = null;
+               if (o != null && (value = HeaderHelper.getHeaderAsString(o)) != null)
+                  servletResponse.addHeader(name, value);
+            }
+         }
+      }
+   }
+}
\ No newline at end of file


Property changes on: ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/ServletContainerResponseWriter.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/BaseTest.java
===================================================================
--- ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/BaseTest.java	2009-10-14 15:18:48 UTC (rev 278)
+++ ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/BaseTest.java	2009-10-14 15:58:06 UTC (rev 279)
@@ -46,7 +46,7 @@
 //      StandaloneContainer.setConfigurationPath("src/test/java/conf/standalone/test-configuration.xml");
 //      container = StandaloneContainer.getInstance();
       binder = new BaseResourceBinder();
-      requestHandler = new RequestHandlerImpl(binder, null/*new SimpleDependencyInjector()*/);
+      requestHandler = new RequestHandlerImpl(binder, new SimpleDependencyInjector());
       requestHandler.init();
       
       // reset providers to be sure it is clean
@@ -55,9 +55,14 @@
 
       // Set-up context for tests that are not used full request cycle.
       // Usually context is set-up in RequestHandler
+//      ApplicationContextImpl.setCurrent(new ApplicationContextImpl(null, null, providers));
+   }
+
+   protected void setContext()
+   {
       ApplicationContextImpl.setCurrent(new ApplicationContextImpl(null, null, providers));
    }
-
+   
    public void tearDown() throws Exception
    {
    }

Modified: ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java
===================================================================
--- ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java	2009-10-14 15:18:48 UTC (rev 278)
+++ ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java	2009-10-14 15:58:06 UTC (rev 279)
@@ -18,9 +18,6 @@
  */
 package org.exoplatform.services.rest.impl;
 
-import org.exoplatform.services.rest.GenericContainerResponse;
-import org.exoplatform.services.rest.Property;
-
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.Encoded;
 import javax.ws.rs.GET;
@@ -34,6 +31,10 @@
 import javax.ws.rs.core.SecurityContext;
 import javax.ws.rs.core.UriInfo;
 
+import org.exoplatform.services.rest.GenericContainerResponse;
+import org.exoplatform.services.rest.Inject;
+import org.exoplatform.services.rest.Property;
+
 /**
  * @author <a href="mailto:andrew00x at gmail.com">Andrey Parfonov</a>
  * @version $Id: $
@@ -41,6 +42,21 @@
 public class RequestDispatcherTest extends AbstractResourceTest
 {
 
+   public void setUp() throws Exception
+   {
+      binder = new BaseResourceBinder();
+      SimpleDependencyInjector depInjector = new SimpleDependencyInjector();
+      depInjector.put(InjectableComponent1.class, new InjectableComponent1());
+      depInjector.put(InjectableComponent2.class, new InjectableComponent2());
+
+      requestHandler = new RequestHandlerImpl(binder, depInjector);
+      requestHandler.init();
+      
+      // reset providers to be sure it is clean
+      ProviderBinder.setInstance(new ProviderBinder());
+      providers = ProviderBinder.getInstance();
+   }
+   
    @Path("/a")
    public static class Resource1
    {
@@ -102,7 +118,7 @@
       }
    }
 
-   public void testResource1() throws Exception
+   public void testSingletonResource() throws Exception
    {
       Resource1 r1 = new Resource1();
       registry(r1);
@@ -148,7 +164,7 @@
 
    }
 
-   public void testResource2() throws Exception
+   public void testSingletonResourceEncodedPath() throws Exception
    {
       Resource2 r2 = new Resource2();
       registry(r2);
@@ -214,10 +230,14 @@
    }
 
    //--------------------------------------
-   public static class TestContainerComponent
+   public static class InjectableComponent1
    {
    }
 
+   public static class InjectableComponent2
+   {
+   }
+
    @Path("{a}")
    public static class Resource4
    {
@@ -228,7 +248,10 @@
       @Context
       private HttpServletRequest request;
 
-      private TestContainerComponent tc;
+      private InjectableComponent1 ic1;
+      
+      @Inject
+      private InjectableComponent2 ic2;
 
       public Resource4(@PathParam("a") String test)
       {
@@ -237,34 +260,34 @@
          fail("Must not be used.");
       }
 
-      public Resource4(TestContainerComponent tc, @PathParam("a") String test)
+      public Resource4(InjectableComponent1 ic, @PathParam("a") String test)
       {
-         this.tc = tc;
+         this.ic1 = ic;
       }
 
       @GET
       @Path("{b}")
       public void m0()
       {
-         assertNotNull(tc);
+         assertNotNull(ic1);
+         assertNotNull(ic2);
          assertNotNull(uriInfo);
          assertNotNull(request);
       }
 
    }
 
-   public void testResourceConstructorsContainer() throws Exception
+   public void testResourceConstructorsDependencyInjection() throws Exception
    {
-//      container.registerComponentInstance(TestContainerComponent.class.getName(), new TestContainerComponent());
       registry(Resource4.class);
-      service("GET", "/aaa/bbb", "", null, null);
+      assertEquals(204, service("GET", "/aaa/bbb", "", null, null).getStatus());
       unregistry(Resource4.class);
    }
 
    // --------------------------------------
    public static class Failure
    {
-      // not member of exo-container
+      // may not be provided by DependencyInjector 
    }
 
    @Path("/_a/b/{c}/{d}")
@@ -283,7 +306,7 @@
       }
    }
 
-   public void testResourceConstructorFail() throws Exception
+   public void testResourceConstructorDependencyInjectionFail() throws Exception
    {
       registry(ResourceFail.class);
       GenericContainerResponse resp = service("GET", "/_a/b/c/d/m0", "", null, null);
@@ -292,6 +315,7 @@
       assertEquals(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), resp.getStatus());
       unregistry(ResourceFail.class);
    }
+
    //--------------------------------------
 
    @Path("a/{b}/{c}")
@@ -324,7 +348,7 @@
 
    }
 
-   public void testResource5() throws Exception
+   public void testQuery() throws Exception
    {
       registry(Resource5.class);
       service("GET", "/a/b/c/d?q1=q1&q2=q2", "", null, null);
@@ -332,7 +356,7 @@
    }
 
    //--------------------------------------
-   
+
    public void testFieldSuperClass() throws Exception
    {
       registry(EndResource.class);
@@ -347,7 +371,7 @@
 
       @Context
       public Request request;
-      
+
       @Context
       protected UriInfo something;
    }
@@ -364,7 +388,7 @@
    {
       @Context
       private HttpHeaders header;
-      
+
       @Context
       private SecurityContext something;
 
@@ -381,9 +405,9 @@
          assertNotNull(header);
       }
    }
-   
+
    // -----------------------------------------------
-   
+
    public void testPropertyInjection() throws Exception
    {
       registry(Resource6.class);
@@ -391,30 +415,30 @@
       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);
       }
-      
+
    }
-   
+
 }

Modified: ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/provider/JAXBEntityProviderTest.java
===================================================================
--- ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/provider/JAXBEntityProviderTest.java	2009-10-14 15:18:48 UTC (rev 278)
+++ ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/provider/JAXBEntityProviderTest.java	2009-10-14 15:58:06 UTC (rev 279)
@@ -18,12 +18,6 @@
  */
 package org.exoplatform.services.rest.impl.provider;
 
-import org.exoplatform.services.rest.generated.Book;
-import org.exoplatform.services.rest.generated.MemberPrice;
-import org.exoplatform.services.rest.generated.Price;
-import org.exoplatform.services.rest.impl.BaseTest;
-import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
-
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
@@ -42,6 +36,12 @@
 import javax.xml.transform.Source;
 import javax.xml.transform.stream.StreamSource;
 
+import org.exoplatform.services.rest.generated.Book;
+import org.exoplatform.services.rest.generated.MemberPrice;
+import org.exoplatform.services.rest.generated.Price;
+import org.exoplatform.services.rest.impl.BaseTest;
+import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
+
 /**
  * @author <a href="mailto:andrew00x at gmail.com">Andrey Parfonov</a>
  * @version $Id: $
@@ -57,6 +57,7 @@
    public void setUp() throws Exception
    {
       super.setUp();
+      setContext();
       mediaType = new MediaType("application", "xml");
       data =
          ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<book send-by-post=\"true\">"

Copied: ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/ContainerObjectFactory.java (from rev 277, ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ContainerObjectFactory.java)
===================================================================
--- ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/ContainerObjectFactory.java	                        (rev 0)
+++ ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/ContainerObjectFactory.java	2009-10-14 15:58:06 UTC (rev 279)
@@ -0,0 +1,65 @@
+/*
+ * 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 org.exoplatform.container.ExoContainerContext;
+
+/**
+ * Factory provides object that is created and is manageable by
+ * inversion-of-control container.
+ * 
+ * @param <T> any extension of {@link ObjectModel}
+ * @author <a href="mailto:andrew00x at gmail.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public class ContainerObjectFactory<T extends ObjectModel> implements ObjectFactory<T>
+{
+
+   /**
+    * Object model.
+    */
+   protected final T model;
+
+   /**
+    * @param model object model
+    * @see ObjectModel
+    */
+   public ContainerObjectFactory(T model)
+   {
+      this.model = model;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Object getInstance(ApplicationContext context)
+   {
+      Class<?> clazz = model.getObjectClass();
+      return ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(clazz);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public T getObjectModel()
+   {
+      return model;
+   }
+
+}


Property changes on: ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/ContainerObjectFactory.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/impl/ExoContainerResourceBinder.java
===================================================================
--- ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/impl/ExoContainerResourceBinder.java	                        (rev 0)
+++ ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/impl/ExoContainerResourceBinder.java	2009-10-14 15:58:06 UTC (rev 279)
@@ -0,0 +1,100 @@
+/*
+ * 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.List;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.ext.RuntimeDelegate;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.exoplatform.services.rest.impl.resource.ResourceDescriptorValidator;
+import org.exoplatform.services.rest.resource.ResourceContainer;
+import org.exoplatform.services.rest.resource.ResourceDescriptorVisitor;
+
+/**
+ * @author <a href="mailto:andrew00x at gmail.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public class ExoContainerResourceBinder extends BaseResourceBinder
+{
+
+   /**
+    * Logger.
+    */
+   private static final Log LOG = ExoLogger.getLogger(ExoContainerResourceBinder.class.getName());
+
+   /**
+    * Validator.
+    */
+   private final ResourceDescriptorVisitor rdv = ResourceDescriptorValidator.getInstance();
+
+   /**
+    * @see RuntimeDelegate
+    */
+   private final RuntimeDelegate rd;
+
+   public ExoContainerResourceBinder()
+   {
+      rd = new RuntimeDelegateImpl();
+      RuntimeDelegate.setInstance(rd);
+   }
+   
+   /**
+    * @param containerContext eXo container context
+    * @throws Exception if can't set instance of {@link RuntimeDelegate}
+    */
+   @SuppressWarnings("unchecked")
+   public ExoContainerResourceBinder(ExoContainerContext containerContext) throws Exception
+   {
+      // Initialize RuntimeDelegate instance
+      // This is first component in life cycle what needs.
+      // TODO better solution to initialize RuntimeDelegate
+      rd = new RuntimeDelegateImpl();
+      RuntimeDelegate.setInstance(rd);
+
+      ExoContainer container = containerContext.getContainer();
+
+      // Lookup Applications
+      List<Application> al = container.getComponentInstancesOfType(Application.class);
+      for (Application a : al)
+      {
+         try
+         {
+            addApplication(a);
+         }
+         catch (Exception e)
+         {
+            LOG.error("Failed add JAX-RS application " + a.getClass().getName(), e);
+         }
+      }
+
+      // Lookup all object which implements ResourceContainer interface and
+      // process them to be add as root resources.
+      for (Object resource : container.getComponentInstancesOfType(ResourceContainer.class))
+      {
+         bind(resource);
+      }
+
+   }
+
+}


Property changes on: ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/impl/ExoContainerResourceBinder.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Copied: ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/servlet/RestServlet.java (from rev 277, ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/RestServlet.java)
===================================================================
--- ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/servlet/RestServlet.java	                        (rev 0)
+++ ws/branches/2.2.x/rest/ext/src/main/java/org/exoplatform/services/rest/servlet/RestServlet.java	2009-10-14 15:58:06 UTC (rev 279)
@@ -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 at 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);
+      }
+   }
+}



More information about the exo-jcr-commits mailing list