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

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Oct 13 23:44:20 EDT 2009


Author: aparfonov
Date: 2009-10-13 23:44:20 -0400 (Tue, 13 Oct 2009)
New Revision: 277

Modified:
   ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ResourceBinder.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/RequestHandlerImpl.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/main/java/org/exoplatform/services/rest/servlet/RestInitializedListener.java
   ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/BaseTest.java
Log:
EXOJCR-185 : 

Modified: ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ResourceBinder.java
===================================================================
--- ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ResourceBinder.java	2009-10-13 18:38:38 UTC (rev 276)
+++ ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/ResourceBinder.java	2009-10-14 03:44:20 UTC (rev 277)
@@ -22,6 +22,8 @@
 
 import java.util.List;
 
+import javax.ws.rs.core.Application;
+
 /**
  * Manages root resources.
  * 
@@ -31,6 +33,12 @@
 public interface ResourceBinder
 {
    /**
+    * @param application Application
+    * @see Application
+    */
+   void addApplication(Application application);
+
+   /**
     * @param resourceClass class of candidate to be root resource
     * @return true if resource was bound and false if resource was not bound
     *         cause it is not root resource

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-13 18:38:38 UTC (rev 276)
+++ ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/BaseResourceBinder.java	2009-10-14 03:44:20 UTC (rev 277)
@@ -156,7 +156,6 @@
     * @see Application
     */
    @SuppressWarnings("unchecked")
-   @Deprecated
    public void addApplication(Application application)
    {
       ProviderBinder providers = ProviderBinder.getInstance();

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-13 18:38:38 UTC (rev 276)
+++ ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/ConstructorDescriptorImpl.java	2009-10-14 03:44:20 UTC (rev 277)
@@ -18,8 +18,6 @@
  */
 package org.exoplatform.services.rest.impl;
 
-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.ApplicationContext;
@@ -218,7 +216,6 @@
     */
    public Object createInstance(ApplicationContext context)
    {
-      ExoContainer container = ExoContainerContext.getCurrentContainer();
       Object[] p = new Object[parameters.size()];
       int i = 0;
       for (ConstructorParameter cp : parameters)
@@ -243,9 +240,19 @@
          else
          {
             // If parameter not has not annotation then get constructor parameter
-            // from container, this is out of scope JAX-RS specification.
-            Object tmp = container.getComponentInstanceOfType(cp.getParameterClass());
+            // from DependencyInjector, this is out of scope JAX-RS specification.
+            
+            if (context.getDependencyInjector() == null)
+            {
+               String msg =
+                  "Can't instantiate resource " + resourceClass
+                     + ". DependencyInjector not found, not able get required parameter " + cp;
+               LOG.error(msg);
+               throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg)
+                  .type(MediaType.TEXT_PLAIN).build());
+            }
 
+            Object tmp = context.getDependencyInjector().getInjectableParameter(cp.getParameterClass(), null);
             if (tmp == null)
             {
                String msg =

Modified: ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java
===================================================================
--- ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java	2009-10-13 18:38:38 UTC (rev 276)
+++ ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java	2009-10-14 03:44:20 UTC (rev 277)
@@ -116,12 +116,12 @@
    
    private final DependencyInjector depInjector;
    
-   public RequestHandlerImpl(DependencyInjector depInjector)
-   {
-      this.binder = new BaseResourceBinder();
-      this.dispatcher = new RequestDispatcher(binder);
-      this.depInjector = depInjector;
-   }
+//   public RequestHandlerImpl(DependencyInjector depInjector)
+//   {
+//      this.binder = new BaseResourceBinder();
+//      this.dispatcher = new RequestDispatcher(binder);
+//      this.depInjector = depInjector;
+//   }
    
    public RequestHandlerImpl(ResourceBinder binder, DependencyInjector depInjector)
    {

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-13 18:38:38 UTC (rev 276)
+++ ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/BaseRestServlet.java	2009-10-14 03:44:20 UTC (rev 277)
@@ -142,7 +142,7 @@
          EnvironmentContext.setCurrent(env);
          ServletContainerRequest request = new ServletContainerRequest(httpRequest);
          ContainerResponse response = new ContainerResponse(new ServletContainerResponseWriter(httpResponse));
-         requestHandler.handleRequest(request, response);
+         getRequestHandler().handleRequest(request, response);
       }
       catch (Exception e)
       {

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-13 18:38:38 UTC (rev 276)
+++ ws/branches/2.2.x/rest/core/src/main/java/org/exoplatform/services/rest/servlet/RestInitializedListener.java	2009-10-14 03:44:20 UTC (rev 277)
@@ -20,10 +20,13 @@
 
 import org.exoplatform.services.rest.DependencyInjector;
 import org.exoplatform.services.rest.RequestHandler;
+import org.exoplatform.services.rest.ResourceBinder;
+import org.exoplatform.services.rest.impl.BaseResourceBinder;
 import org.exoplatform.services.rest.impl.RequestHandlerImpl;
 
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
+import javax.ws.rs.core.Application;
 
 /**
  * @author <a href="mailto:andrew00x at gmail.com">Andrey Parfonov</a>
@@ -61,9 +64,32 @@
          }
       }
 
-      RequestHandler handler = new RequestHandlerImpl(dependencyInjector);
+      ResourceBinder binder = new BaseResourceBinder();
+      String applicationFQN = event.getServletContext().getInitParameter("javax.ws.rs.Application");
+      if (applicationFQN != null)
+      {
+         try
+         {
+            Class<?> cl = Thread.currentThread().getContextClassLoader().loadClass(applicationFQN.trim());
+            Application application = (Application)cl.newInstance();
+            binder.addApplication(application);
+         }
+         catch (ClassNotFoundException cnfe)
+         {
+            throw new RuntimeException(cnfe);
+         }
+         catch (InstantiationException ie)
+         {
+            throw new RuntimeException(ie);
+         }
+         catch (IllegalAccessException iae)
+         {
+            throw new RuntimeException(iae);
+         }
+      }
+
+      RequestHandler handler = new RequestHandlerImpl(binder, dependencyInjector);
       event.getServletContext().setAttribute(RequestHandler.class.getName(), handler);
-      // TODO process for javax.ws.rs.Application
    }
 
 }

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-13 18:38:38 UTC (rev 276)
+++ ws/branches/2.2.x/rest/core/src/test/java/org/exoplatform/services/rest/impl/BaseTest.java	2009-10-14 03:44:20 UTC (rev 277)
@@ -45,14 +45,14 @@
    {
 //      StandaloneContainer.setConfigurationPath("src/test/java/conf/standalone/test-configuration.xml");
 //      container = StandaloneContainer.getInstance();
-
-      requestHandler = new RequestHandlerImpl(new SimpleDependencyInjector());
+      binder = new BaseResourceBinder();
+      requestHandler = new RequestHandlerImpl(binder, null/*new SimpleDependencyInjector()*/);
       requestHandler.init();
-      binder = (BaseResourceBinder)requestHandler.getBinder();
       
       // reset providers to be sure it is clean
       ProviderBinder.setInstance(new ProviderBinder());
       providers = ProviderBinder.getInstance();
+
       // 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));



More information about the exo-jcr-commits mailing list