← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10519: [mobile] replace AnnotationMethodHandlerAdapter with RequestMappingHandlerAdapter

 

------------------------------------------------------------
revno: 10519
committer: Long <Long@Long-Laptop>
branch nick: dhis2
timestamp: Thu 2013-04-11 14:19:40 +0700
message:
  [mobile] replace AnnotationMethodHandlerAdapter with RequestMappingHandlerAdapter
modified:
  dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/MessageConverterAddingPostProcessor.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/MessageConverterAddingPostProcessor.java'
--- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/MessageConverterAddingPostProcessor.java	2013-03-13 10:11:52 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/MessageConverterAddingPostProcessor.java	2013-04-11 07:19:40 +0000
@@ -1,7 +1,7 @@
 package org.hisp.dhis.api.mobile.support;
 
 /*
- * Copyright (c) 2004-2012, University of Oslo
+ * Copyright (c) 2004-2013, University of Oslo
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,17 +27,14 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.config.BeanPostProcessor;
 import org.springframework.http.converter.HttpMessageConverter;
 import org.springframework.stereotype.Component;
-import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter;
+import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
 
 @Component
 public class MessageConverterAddingPostProcessor
@@ -57,39 +54,27 @@
     public Object postProcessAfterInitialization( Object bean, String beanName )
         throws BeansException
     {
-
-        if ( !(bean instanceof AnnotationMethodHandlerAdapter) )
+        if ( !(bean instanceof RequestMappingHandlerAdapter) )
         {
             return bean;
         }
 
-        AnnotationMethodHandlerAdapter handlerAdapter = (AnnotationMethodHandlerAdapter) bean;
-
-        HttpMessageConverter<?>[] converterArray = handlerAdapter.getMessageConverters();
-        
-        List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>(
-            Arrays.asList( converterArray ) );
-
+        RequestMappingHandlerAdapter handlerAdapter = (RequestMappingHandlerAdapter) bean;
+        List<HttpMessageConverter<?>> converters = handlerAdapter.getMessageConverters();
         converters.add( 0, messageConverter );
-
-        converterArray = converters.toArray( new HttpMessageConverter<?>[converters.size()] );
-
-        handlerAdapter.setMessageConverters( converterArray );
-
-        log( converterArray );
-        
+        handlerAdapter.setMessageConverters( converters );
         return handlerAdapter;
     }
 
     private void log( HttpMessageConverter<?>[] array )
     {
-        StringBuilder sb = new StringBuilder("Converters after adding custom one: ");
+        StringBuilder sb = new StringBuilder( "Converters after adding custom one: " );
 
         for ( HttpMessageConverter<?> httpMessageConverter : array )
         {
             sb.append( httpMessageConverter.getClass().getName() ).append( ", " );
         }
-        
+
         String string = sb.toString();
         logger.info( string.substring( 0, string.length() - 2 ) );
     }