[exo-jcr-commits] exo-jcr SVN: r3559 - in ws/trunk: exo.ws.rest.core/src/test/resources/conf/standalone and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Nov 25 08:31:32 EST 2010


Author: aparfonov
Date: 2010-11-25 08:31:31 -0500 (Thu, 25 Nov 2010)
New Revision: 3559

Added:
   ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ExceptionMapperComponentPlugin.java
Modified:
   ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java
   ws/trunk/exo.ws.rest.core/src/test/resources/conf/standalone/test-configuration.xml
   ws/trunk/exo.ws.rest.ext/src/test/resources/conf/standalone/test-configuration.xml
Log:
EXOJCR-1079

Added: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ExceptionMapperComponentPlugin.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ExceptionMapperComponentPlugin.java	                        (rev 0)
+++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ExceptionMapperComponentPlugin.java	2010-11-25 13:31:31 UTC (rev 3559)
@@ -0,0 +1,80 @@
+/**
+ * Copyright (C) 2010 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.component.BaseComponentPlugin;
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.container.xml.ValueParam;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.exoplatform.services.rest.method.MethodInvokerFilter;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.ws.rs.ext.ExceptionMapper;
+
+/**
+ * @author <a href="mailto:andrew00x at gmail.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public class ExceptionMapperComponentPlugin extends BaseComponentPlugin
+{
+   /** Logger. */
+   private static final Log LOG = ExoLogger.getLogger("exo.ws.rest.core.ExceptionMapperComponentPlugin");
+
+   /** List of {@link MethodInvokerFilter}. */
+   private Set<Class<? extends ExceptionMapper<?>>> emaps = new HashSet<Class<? extends ExceptionMapper<?>>>();
+
+   /**
+    * @param params initialize parameters from configuration
+    * @see InitParams
+    */
+   @SuppressWarnings("unchecked")
+   public ExceptionMapperComponentPlugin(InitParams params)
+   {
+      if (params != null)
+      {
+         Iterator<ValueParam> i = params.getValueParamIterator();
+         while (i.hasNext())
+         {
+            ValueParam v = i.next();
+            try
+            {
+               emaps.add((Class<? extends ExceptionMapper<?>>)Class.forName(v.getValue()));
+            }
+            catch (ClassNotFoundException e)
+            {
+               LOG.error("Failed load class " + v.getValue(), e);
+            }
+         }
+      }
+   }
+
+   /**
+    * @return get collection of classes ExceptionMapper supplied from
+    *         configuration
+    */
+   public Set<Class<? extends ExceptionMapper<?>>> getExceptionMappers()
+   {
+      return emaps;
+   }
+}


Property changes on: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ExceptionMapperComponentPlugin.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java	2010-11-25 13:19:34 UTC (rev 3558)
+++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java	2010-11-25 13:31:31 UTC (rev 3559)
@@ -52,8 +52,8 @@
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.core.StreamingOutput;
 import javax.ws.rs.core.Response.ResponseBuilder;
-import javax.ws.rs.core.StreamingOutput;
 import javax.ws.rs.ext.ExceptionMapper;
 
 /**
@@ -424,6 +424,14 @@
          for (Class<? extends ResponseFilter> filter : filters)
             providers.addResponseFilter(filter);
       }
+      else if (ExceptionMapperComponentPlugin.class.isAssignableFrom(plugin.getClass()))
+      {
+         Set<Class<? extends ExceptionMapper<?>>> emaps = ((ExceptionMapperComponentPlugin)plugin).getExceptionMappers();
+         for (Class<? extends ExceptionMapper<?>> mapper : emaps){
+            providers.addExceptionMapper(mapper);
+System.out.println("\n>>>>>>>>>>>>>>>>> ADD <<<<<<<<<<<<<<<<<\n\n");
+         }
+      }
    }
 
 }

Modified: ws/trunk/exo.ws.rest.core/src/test/resources/conf/standalone/test-configuration.xml
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/resources/conf/standalone/test-configuration.xml	2010-11-25 13:19:34 UTC (rev 3558)
+++ ws/trunk/exo.ws.rest.core/src/test/resources/conf/standalone/test-configuration.xml	2010-11-25 13:31:31 UTC (rev 3559)
@@ -149,5 +149,18 @@
          </init-params>
          -->
       </component-plugin>
+      <component-plugin>
+         <name>ws.rs.exception.mapper</name>
+         <set-method>addPlugin</set-method>
+         <type>org.exoplatform.services.rest.impl.ExceptionMapperComponentPlugin</type>
+         <!--
+         <init-params>
+            <value-param>
+               <name>name</name>
+               <value>mapper name</value>
+            </value-param>
+         </init-params>
+         -->
+      </component-plugin>
    </external-component-plugins>
 </configuration>

Modified: ws/trunk/exo.ws.rest.ext/src/test/resources/conf/standalone/test-configuration.xml
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/resources/conf/standalone/test-configuration.xml	2010-11-25 13:19:34 UTC (rev 3558)
+++ ws/trunk/exo.ws.rest.ext/src/test/resources/conf/standalone/test-configuration.xml	2010-11-25 13:31:31 UTC (rev 3559)
@@ -72,13 +72,7 @@
 			<set-method>addPlugin</set-method>
 			<type>org.exoplatform.services.rest.impl.provider.JAXBContextComponentPlugin</type>
 			<init-params>
-				<!-- ======== example ======= -->
 				<value-param>
-					<name>book</name>
-					<value>org.exoplatform.services.rest.generated.Book</value>
-				</value-param>
-				<!-- ======================== -->
-				<value-param>
 					<name>wadl.application</name>
 					<value>org.exoplatform.services.rest.wadl.research.Application</value>
 				</value-param>



More information about the exo-jcr-commits mailing list