Changeset 402


Ignore:
Timestamp:
03/08/12 17:20:11 (12 years ago)
Author:
vmipsl
Message:

clean
mise en place message d'erreurs javascript

Location:
tapas
Files:
1 deleted
11 edited
1 moved

Legend:

Unmodified
Added
Removed
  • tapas/common/interface/com/ether/FormattedException.java

    r376 r402  
    55 
    66@SuppressWarnings("serial") 
    7 public class FormattedException extends Exception 
     7public class FormattedException 
     8        extends Exception 
    89{ 
    9     public FormattedException(final Object... parameters) { 
    10         this(Locale.getDefault(), DEFAULT_MESSAGE, DEFAULT_THROWABLE, parameters); 
     10    public FormattedException( final Object... parameters ) 
     11    { 
     12        this( Locale.getDefault(), DEFAULT_MESSAGE, DEFAULT_THROWABLE, parameters ); 
    1113    } 
    1214 
    13     public FormattedException(final Locale locale, final Object... parameters) { 
    14         this(locale, DEFAULT_MESSAGE, DEFAULT_THROWABLE, parameters); 
     15    public FormattedException( final Throwable throwable, final Object... parameters ) 
     16    { 
     17        this( Locale.getDefault(), throwable.getMessage(), throwable, parameters ); 
    1518    } 
    1619 
    17     public FormattedException(final String message, final Object... parameters) { 
    18         this(Locale.getDefault(), message, DEFAULT_THROWABLE, parameters); 
     20    public FormattedException( final Locale locale, final String message, final Object... parameters ) 
     21    { 
     22        this( locale, message, null, parameters ); 
    1923    } 
    2024 
    21     public FormattedException(final Locale locale, final String message, final Object... parameters) { 
    22         this(locale, message, null, parameters); 
     25    public FormattedException( final String message, final Throwable throwable, final Object... parameters ) 
     26    { 
     27        this( Locale.getDefault(), message, throwable, parameters ); 
    2328    } 
    2429 
    25     public FormattedException(final Throwable throwable, final Object... parameters) { 
    26         this(Locale.getDefault(), throwable.getMessage(), throwable, parameters); 
     30    public FormattedException( final Locale locale, final String message, final Throwable throwable, final Object... parameters ) 
     31    { 
     32        super( format( locale, message, parameters ), throwable ); 
    2733    } 
    2834 
    29     public FormattedException(final String message, final Throwable throwable, final Object... parameters) { 
    30         this(Locale.getDefault(), message, throwable, parameters); 
     35    public FormattedException( final Enum<? extends Code> code, final String message, final Throwable throwable, 
     36                               final Object... parameters ) 
     37    { 
     38        this( prefix( code, message ), throwable, parameters ); 
    3139    } 
    3240 
    33     public FormattedException(final Locale locale, final String message, final Throwable throwable, final Object... parameters) { 
    34         super(format(locale, message, parameters), throwable); 
     41    private static String format( final Locale locale, final String message, final Object[] parameters ) 
     42    { 
     43        final StringBuilder stringBuilder = new StringBuilder(); 
     44        final Formatter formatter = new Formatter( stringBuilder ); 
     45        formatter.format( locale, message, parameters ); 
     46        return stringBuilder.toString(); 
    3547    } 
    3648 
    37     private static String format(final Locale locale, final String message, final Object[] parameters) 
     49    public static String formatThrowable( final Enum<? extends Code> code, final String message, final Throwable throwable ) 
    3850    { 
    39         final StringBuilder stringBuilder = new StringBuilder(); 
    40         final Formatter formatter = new Formatter(stringBuilder); 
    41         formatter.format(locale, message, parameters); 
    42         return stringBuilder.toString(); 
     51        if( throwable.equals( EXCEPTION_THROWABLE ) ) 
     52            return code.name(); 
     53        else 
     54            return prefix( code, message ); 
    4355    } 
    4456 
     
    4658     * Prefixes the message with code if not null. 
    4759     */ 
    48     public static String prefix(final Enum<? extends Code> code, final String message) 
     60    public static String prefix( final Enum<? extends Code> code, final String message ) 
    4961    { 
    50                 final StringBuffer stringBuffer = new StringBuffer(); 
     62        final StringBuffer stringBuffer = new StringBuffer(); 
    5163 
    52                 if (code != null) { 
    53                         stringBuffer.append(code.toString()); 
    54                         stringBuffer.append(" - "); 
    55                 } 
     64        if( code != null ) 
     65        { 
     66            stringBuffer.append( code.toString() ); 
     67            stringBuffer.append( " - " ); 
     68        } 
    5669 
    57                 stringBuffer.append(message); 
    58                 return stringBuffer.toString(); 
     70        stringBuffer.append( message ); 
     71        return stringBuffer.toString(); 
     72    } 
     73 
     74    public static Throwable getExceptionThrowable() 
     75    { 
     76        return EXCEPTION_THROWABLE; 
    5977    } 
    6078 
    6179    /** 
    62      * The error code, it identifies the type of error.  
    63      * The derived classes must creates their own code as enum and implements this interface.  
     80     * The error code, it identifies the type of error. 
     81     * The derived classes must creates their own code as enum and implements this interface. 
    6482     * If the subclass is not an enum it won't be recognized by the constructor. 
    6583     */ 
     
    7088    public static String DEFAULT_MESSAGE = "no message"; 
    7189    public static String DEFAULT_THROWABLE = null; 
     90    private static final Throwable EXCEPTION_THROWABLE = new Throwable( "EXCEPTION_THROWABLE" ); 
    7291} 
  • tapas/service/implementation/com/ether/TapasServiceImpl.java

    r389 r402  
    33import com.ether.dao.ParameterDAO; 
    44import com.ether.dao.PlateformDAO; 
     5import com.ether.tapas.Tapas; 
    56import org.apache.commons.logging.Log; 
    67import org.apache.commons.logging.LogFactory; 
    7 import org.jdom.*; 
     8import org.jdom.Attribute; 
     9import org.jdom.Document; 
     10import org.jdom.Element; 
    811import org.jdom.output.Format; 
    912import org.jdom.output.XMLOutputter; 
     
    1518import java.io.FileOutputStream; 
    1619import java.util.List; 
    17 import java.util.prefs.Preferences; 
    1820 
    1921/** 
     
    2527{ 
    2628 
    27     public void createXMLRequest() 
    28  
     29    public void createXMLRequest( @NotNull final Tapas tapas ) 
    2930    { 
    3031        String idF = "Ether_TAPAS_0000001"; 
     
    6667    } 
    6768 
    68  
    6969    public void createXMLFile( final String fichier, final Document document ) 
    7070    { 
     
    8383 
    8484 
     85    // TODO : supprimer cette méthode --> EXEMPLE 
    8586    @Nullable 
    8687    @Transactional(readOnly = true) 
     
    9899    } 
    99100 
     101    // TODO : supprimer cette méthode --> EXEMPLE 
    100102    @Nullable 
    101103    @Transactional(readOnly = true) 
     
    115117    } 
    116118 
     119    // TODO : supprimer cette méthode --> EXEMPLE 
    117120    @Nullable 
    118121    @Transactional(readOnly = true) 
     
    130133    } 
    131134 
     135    // TODO : supprimer cette méthode --> EXEMPLE 
    132136    @Required 
    133137    public void setPlateformDAO( final PlateformDAO plateformDAO ) 
     
    136140    } 
    137141 
     142    // TODO : supprimer cette méthode --> EXEMPLE 
    138143    @Required 
    139144    public void setParameterDAO( final ParameterDAO parameterDAO ) 
     
    144149    private static final Log LOGGER = LogFactory.getLog( TapasServiceImpl.class ); 
    145150 
    146  
     151    // TODO : supprimer ces DAO --> EXEMPLES 
    147152    private PlateformDAO _plateformDAO; 
    148153    private ParameterDAO _parameterDAO; 
  • tapas/service/interface/com/ether/TapasService.java

    r389 r402  
    11package com.ether; 
    22 
     3import com.ether.tapas.Tapas; 
    34import org.jdom.Document; 
    45import org.jetbrains.annotations.NotNull; 
     
    89 
    910/** 
    10  * @author vmipsl 
    11  * @date 07 mar 2011 
     11 * @author rboipsl 
     12 * @date 02 march 2012 
    1213 */ 
    1314public interface TapasService 
    1415        extends Service 
    1516{ 
    16  
    17     public void createXMLRequest(); 
     17    public void createXMLRequest( @NotNull final Tapas tapas ); 
    1818 
    1919    public void createXMLFile( final String fichier, final Document document ); 
    20  
    21         @Nullable 
    22         List<Plateform> getAllPlateforms() throws ServiceException; 
    23  
    24     @Nullable 
    25     Plateform getPlateformById( @Nullable final Integer plateformId ) throws ServiceException; 
    26  
    27     @Nullable 
    28     List<Parameter> getAllParametersByPlateformId( @NotNull final Integer plateformId ) throws ServiceException; 
    2920} 
  • tapas/service/test/com/ether/EtherTest.java

    r389 r402  
    22 
    33import org.jetbrains.annotations.NotNull; 
    4 import org.junit.Assert; 
    54import org.junit.Test; 
    65 
     
    1110import java.io.File; 
    1211import java.io.Serializable; 
    13 import java.text.DateFormat; 
    1412import java.text.ParseException; 
    15 import java.text.SimpleDateFormat; 
    16 import java.util.Calendar; 
    17 import java.util.Date; 
    1813 
    1914/** 
     
    2924    { 
    3025 
    31         getService().createXMLRequest(); 
     26        getService().createXMLRequest( null ); 
    3227 
    3328    } 
  • tapas/web/project/formTapas.jsp

    r400 r402  
    11<%@ page import="com.ether.Context" %> 
     2<%@ page import="com.ether.WebException" %> 
    23<%@ page contentType="text/html;charset=UTF-8" language="java" %> 
    34<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 
     
    2627        </div> 
    2728 
     29        <div id="errors"></div> 
    2830 
    2931        <BR/> 
     
    4042 
    4143        <script type="text/javascript"> 
    42             var initTexts = $A( "" ); 
     44            var tapasTexts = $A( "" ); 
    4345 
    44             initTexts["label.submitButton"] = '<spring:message code="label.submitButton"/>'; 
     46            tapasTexts["label.submitButton"] = '<spring:message code="label.submitButton"/>'; 
     47            tapasTexts["<%=WebException.WebCode.ERROR_JSON_TAPAS_IS_NULL%>"] = "<spring:message code="error.ERROR_JSON_TAPAS_IS_NULL"/>"; 
    4548 
    4649 
  • tapas/web/project/formTapas_script.jsp

    r401 r402  
    66            /** *********** CONTAINERS *********** **/ 
    77            this.containerForm = $( "#formulaire" ); 
     8            this.containerErrors = $( "#errors" ); 
    89 
     10            this.containerErrors.hide(); 
    911            this.createForm(); 
    10  
    1112        }, 
    1213 
     
    2425            this.containerForm.append( input2 ); 
    2526 
    26             var submitButton = new Button( {value:initTexts["label.submitButton"], parent:this.containerForm, id:"button_submit", className: "red_button", classNameText:"red_button_text", onClick:jQuery.proxy( this.onClickSubmit, this )} ); 
     27            var submitButton = new Button( {value:tapasTexts["label.submitButton"], parent:this.containerForm, id:"button_submit", className: "red_button", classNameText:"red_button_text", onClick:jQuery.proxy( this.onClickSubmit, this )} ); 
    2728 
    2829        }, 
     
    3738                $.ajax( { 
    3839                    url: "project?methodName=createUserRequest&jsonTapas=" + jsonTapasForm, 
    39                     success:jQuery.proxy( this.handleCreateXML, this ) 
     40                    success:jQuery.proxy( this.handleCreateXML, this ), 
     41                    error: jQuery.proxy( this.showErrors, this ) 
    4042                } ); 
    4143        }, 
     
    4547        { 
    4648            var bob = jQuery.parseJSON( result ).result; 
    47 //            alert( bob ); 
     49            alert( bob ); 
    4850        }, 
    4951 
     
    5254        onClickSubmit: function() 
    5355        { 
     56            this.containerErrors.hide(); 
    5457            this.requestCreateXML(); 
    5558        }, 
    5659 
    5760        // OTHERS ******************************************************** 
     61        showErrors: function( result ) 
     62        { 
     63            this.containerErrors.show(); 
     64            this.containerErrors.html( tapasTexts[result.responseText] ); 
     65        }, 
     66 
    5867        createTapasForm: function() 
    5968        { 
  • tapas/web/src/com/ether/Controller.java

    r400 r402  
    1717/** 
    1818 * @author vmipsl 
    19  * @date 05 march 2012 
     19 * @date 02 march 2012 
    2020 */ 
    2121public class Controller 
     
    4545    @ControllerMethod(jsonResult = true) 
    4646    public JSONObject createUserRequest( @ParamName("jsonTapas") @Mandatory @UseJSON final Tapas jsonTapas ) 
    47             throws ServiceException 
     47            throws WebException 
    4848    { 
     49        if( null == jsonTapas ) 
     50            throw new WebException( WebException.WebCode.ERROR_JSON_TAPAS_IS_NULL, "Serialization error : jsonTapas is null", WebException.getExceptionThrowable() ); 
     51 
    4952        //appel a createxml 
    50         _tapasService.createXMLRequest(); 
     53        _tapasService.createXMLRequest( jsonTapas ); 
    5154 
    5255        final JSONObject result = new JSONObject(); 
  • tapas/web/src/com/ether/ControllerEther.java

    r376 r402  
    11package com.ether; 
    22 
     3import com.ether.annotation.ControllerMethod; 
     4import com.ether.annotation.Mandatory; 
     5import com.ether.annotation.ParamName; 
     6import com.ether.annotation.UseJSON; 
     7import net.sf.json.JSON; 
     8import net.sf.json.JSONArray; 
     9import net.sf.json.JSONNull; 
     10import net.sf.json.JSONObject; 
     11import net.sf.json.util.JSONUtils; 
     12import org.apache.commons.logging.Log; 
     13import org.apache.commons.logging.LogFactory; 
     14import org.jetbrains.annotations.NotNull; 
     15import org.jetbrains.annotations.Nullable; 
     16import org.springframework.beans.factory.annotation.Required; 
     17import org.springframework.web.servlet.ModelAndView; 
     18import org.springframework.web.servlet.mvc.AbstractController; 
     19import org.springframework.web.servlet.mvc.multiaction.MethodNameResolver; 
     20import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException; 
     21 
     22import javax.servlet.http.HttpServletRequest; 
     23import javax.servlet.http.HttpServletResponse; 
     24import java.io.IOException; 
    325import java.io.UnsupportedEncodingException; 
    426import java.lang.annotation.Annotation; 
     
    1234import java.util.Map; 
    1335 
    14 import javax.servlet.http.HttpServletRequest; 
    15 import javax.servlet.http.HttpServletResponse; 
    16  
    17 import net.sf.json.JSON; 
    18 import net.sf.json.JSONArray; 
    19 import net.sf.json.JSONNull; 
    20 import net.sf.json.JSONObject; 
    21 import net.sf.json.util.JSONUtils; 
    22  
    23 import org.apache.commons.logging.Log; 
    24 import org.apache.commons.logging.LogFactory; 
    25 import org.jetbrains.annotations.NotNull; 
    26 import org.jetbrains.annotations.Nullable; 
    27 import org.springframework.beans.factory.annotation.Required; 
    28 import org.springframework.web.servlet.ModelAndView; 
    29 import org.springframework.web.servlet.mvc.AbstractController; 
    30 import org.springframework.web.servlet.mvc.multiaction.MethodNameResolver; 
    31 import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException; 
    32  
    33 import com.ether.annotation.ControllerMethod; 
    34 import com.ether.annotation.Mandatory; 
    35 import com.ether.annotation.ParamName; 
    36 import com.ether.annotation.UseJSON; 
    37  
    38 public class ControllerEther extends AbstractController 
     36public class ControllerEther 
     37        extends AbstractController 
    3938{ 
    40         @Override 
    41         @Nullable 
    42         protected ModelAndView handleRequestInternal(@NotNull final HttpServletRequest request, @NotNull final HttpServletResponse response) 
    43                 throws WebException 
    44         { 
    45                 try { 
    46                         if (!_initialized) 
    47                                 initialize(); 
    48  
    49                         request.setCharacterEncoding(UTF8Charset.getEncoding()); 
    50                          
    51                         // Get method to call 
    52                         final String methodName = _methodNameResolver.getHandlerMethodName(request); 
    53  
    54                         final MethodDescription methodDescription = _methods.get(methodName); 
    55                         if (null == methodDescription) { 
    56                                 WebHelper.displayAjaxError(response, methodName); 
    57                                 if (LOGGER.isWarnEnabled()) 
    58                                         LOGGER.warn(String.format("Controller=%1$s Method=%2$s METHOD NOT FOUND", getClass().getSimpleName(), methodName)); 
    59                                 return null; 
    60                         } 
    61  
    62                         return invokeMethod(methodDescription, request, response); 
    63  
    64                 } catch (UnsupportedEncodingException e) { 
    65                         throw new WebException(WebException.WebCode.ERROR_UNSUPPORTED_UTF8_ENCODING, e); 
    66                 } catch (NoSuchRequestHandlingMethodException e) { 
    67                         throw new WebException(WebException.WebCode.ERROR_NO_REQUEST_HANDLING_METHOD, e); 
    68                 } 
    69         } 
    70  
    71         @Nullable 
    72         private ModelAndView invokeMethod( @NotNull final MethodDescription methodDescription, @NotNull final HttpServletRequest request, @NotNull final HttpServletResponse response) 
    73                 throws WebException  
    74         { 
    75                 try { 
    76                         // Parse parameters 
    77                         final Object[] params = buildParams(methodDescription, request); 
    78  
    79                         // Invoke method (go to controller) 
    80                         final Object result = methodDescription.getMethod().invoke(this, params); 
    81                          
    82                         // Return result 
    83                         if (!methodDescription.getView().isEmpty()) { 
    84                                 response.setStatus(HttpServletResponse.SC_OK); 
    85                                 if (result instanceof Map) 
    86                                         return new ModelAndView(methodDescription.getView(), (Map) result); 
    87                                 else 
    88                                         return new ModelAndView(methodDescription.getView(), "result", result); 
    89                                  
    90                         } else if (methodDescription.isJsonResult()) { 
    91                                 response.setStatus(HttpServletResponse.SC_OK); 
    92                                 final String jsonResult = convertToJson(result); 
    93                                 WebHelper.writeJsonToResponse(response, jsonResult);                             
    94                                 return null; 
    95                         } else { 
    96                                 response.setStatus(HttpServletResponse.SC_NO_CONTENT); 
    97                                 return null; 
    98                         } 
    99                          
    100                 } catch (Throwable e) { 
    101                         throw new WebException(e); 
    102                 } 
    103         }        
    104          
    105         @NotNull 
    106         private String convertToJson( @Nullable final Object object ) 
    107     { 
    108         if( null == object) 
     39    @Override 
     40    @Nullable 
     41    protected ModelAndView handleRequestInternal( @NotNull final HttpServletRequest request, @NotNull final HttpServletResponse response ) 
     42            throws WebException 
     43    { 
     44        try 
     45        { 
     46            if( !_initialized ) 
     47                initialize(); 
     48 
     49            request.setCharacterEncoding( UTF8Charset.getEncoding() ); 
     50 
     51            // Get method to call 
     52            final String methodName = _methodNameResolver.getHandlerMethodName( request ); 
     53 
     54            final MethodDescription methodDescription = _methods.get( methodName ); 
     55            if( null == methodDescription ) 
     56            { 
     57                WebHelper.displayAjaxError( response, methodName ); 
     58                if( LOGGER.isWarnEnabled() ) 
     59                    LOGGER.warn( String.format( "Controller=%1$s Method=%2$s METHOD NOT FOUND", getClass().getSimpleName(), methodName ) ); 
     60                return null; 
     61            } 
     62 
     63            return invokeMethod( methodDescription, request, response ); 
     64        } 
     65        catch( UnsupportedEncodingException e ) 
     66        { 
     67            throw new WebException( WebException.WebCode.ERROR_UNSUPPORTED_UTF8_ENCODING, e ); 
     68        } 
     69        catch( NoSuchRequestHandlingMethodException e ) 
     70        { 
     71            throw new WebException( WebException.WebCode.ERROR_NO_REQUEST_HANDLING_METHOD, e ); 
     72        } 
     73    } 
     74 
     75    @Nullable 
     76    private ModelAndView invokeMethod( @NotNull final MethodDescription methodDescription, @NotNull final HttpServletRequest request, @NotNull final HttpServletResponse response ) 
     77            throws WebException 
     78    { 
     79        try 
     80        { 
     81            // Parse parameters 
     82            final Object[] params = buildParams( methodDescription, request ); 
     83 
     84            final Object result; 
     85            try 
     86            { 
     87                // Invoke method (go to controller) 
     88                result = methodDescription.getMethod().invoke( this, params ); 
     89            } 
     90            catch( Throwable e ) 
     91            { 
     92                sendSerializedException( response, e.getCause() ); 
     93                return null; 
     94            } 
     95 
     96            // Return result 
     97            if( !methodDescription.getView().isEmpty() ) 
     98            { 
     99                response.setStatus( HttpServletResponse.SC_OK ); 
     100                if( result instanceof Map ) 
     101                    return new ModelAndView( methodDescription.getView(), (Map) result ); 
     102                else 
     103                    return new ModelAndView( methodDescription.getView(), "result", result ); 
     104            } 
     105            else if( methodDescription.isJsonResult() ) 
     106            { 
     107                response.setStatus( HttpServletResponse.SC_OK ); 
     108                final String jsonResult = convertToJson( result ); 
     109                WebHelper.writeJsonToResponse( response, jsonResult ); 
     110                return null; 
     111            } 
     112            else 
     113            { 
     114                response.setStatus( HttpServletResponse.SC_NO_CONTENT ); 
     115                return null; 
     116            } 
     117        } 
     118        catch( Throwable e ) 
     119        { 
     120            throw new WebException( e ); 
     121        } 
     122    } 
     123 
     124    private void sendSerializedException( @NotNull final HttpServletResponse response, @NotNull final Throwable exception ) 
     125            throws IOException 
     126    { 
     127        response.setStatus( WebHelper.STATUS_CODE_SERVICE_EXCEPTION ); 
     128 
     129        if( exception.getCause().equals( WebException.getExceptionThrowable() ) ) 
     130            WebHelper.writeJsonToResponse( response, exception.getLocalizedMessage() ); 
     131        else 
     132            WebHelper.writeJsonToResponse( response, _jsonHelper.toJSONObject( exception ).toString() ); 
     133    } 
     134 
     135    @NotNull 
     136    private String convertToJson( @Nullable final Object object ) 
     137    { 
     138        if( null == object ) 
    109139            return JSONNull.getInstance().toString(); 
    110140        if( object instanceof JSON ) 
     
    119149    } 
    120150 
    121         @NotNull 
    122         private Object[] buildParams(@NotNull final MethodDescription methodDescription, @NotNull final HttpServletRequest request)  
    123                 throws InvalidParameterException  
    124         { 
    125                 final List<Object> params = new ArrayList<Object>(); 
    126                 for (final ParamDescription paramDescription : methodDescription.getParams()) { 
    127                         if (null == paramDescription) { 
    128                                 params.add(null); 
    129                                 continue; 
    130                         } 
    131                         final boolean canBeNull = !paramDescription.isPrimitive() && !paramDescription.isMandatory(); 
    132                         final String paramValue = WebHelper.getRequestParameter(request, paramDescription.getName(), null, canBeNull); 
    133                         final boolean useJSON = paramDescription.isUsingJSON(); 
    134                         params.add(convertParameter(paramDescription.getType(), paramValue, useJSON)); 
    135                 } 
    136                 return params.toArray(new Object[params.size()]); 
    137         } 
    138          
    139         @Nullable 
    140         private Object convertParameter( @NotNull final Class paramType, @Nullable final String paramValue, final boolean useJSON ) 
     151    @NotNull 
     152    private Object[] buildParams( @NotNull final MethodDescription methodDescription, @NotNull final HttpServletRequest request ) 
     153            throws InvalidParameterException 
     154    { 
     155        final List<Object> params = new ArrayList<Object>(); 
     156        for( final ParamDescription paramDescription : methodDescription.getParams() ) 
     157        { 
     158            if( null == paramDescription ) 
     159            { 
     160                params.add( null ); 
     161                continue; 
     162            } 
     163            final boolean canBeNull = !paramDescription.isPrimitive() && !paramDescription.isMandatory(); 
     164            final String paramValue = WebHelper.getRequestParameter( request, paramDescription.getName(), null, canBeNull ); 
     165            final boolean useJSON = paramDescription.isUsingJSON(); 
     166            params.add( convertParameter( paramDescription.getType(), paramValue, useJSON ) ); 
     167        } 
     168        return params.toArray( new Object[params.size()] ); 
     169    } 
     170 
     171    @Nullable 
     172    private Object convertParameter( @NotNull final Class paramType, @Nullable final String paramValue, final boolean useJSON ) 
    141173    { 
    142174        if( null == paramValue ) 
     
    148180        if( JSONArray.class.equals( paramType ) ) 
    149181            return _jsonHelper.toJSON( paramValue ); 
    150         if( String.class .equals( paramType ) ) 
     182        if( String.class.equals( paramType ) ) 
    151183            return paramValue; 
    152184        if( Boolean.TYPE.equals( paramType ) || Boolean.class.equals( paramType ) ) 
     
    170202    } 
    171203 
    172     private void initialize()  
    173         throws WebException 
     204    private void initialize() 
     205            throws WebException 
    174206    { 
    175207        for( final Method method : getClass().getMethods() ) 
     
    178210            if( null != annotation ) 
    179211            { 
    180                 final MethodDescription methodDescription = new MethodDescription( method, annotation ); 
    181                 fillMethodDescription( method, methodDescription ); 
    182                 _methods.put( method.getName(), methodDescription ); 
     212                final MethodDescription methodDescription = new MethodDescription( method, annotation ); 
     213                fillMethodDescription( method, methodDescription ); 
     214                _methods.put( method.getName(), methodDescription ); 
    183215            } 
    184216        } 
     
    187219    } 
    188220 
    189     private void fillMethodDescription( @NotNull final Method method, @NotNull final MethodDescription methodDescription )  
    190         throws WebException 
     221    private void fillMethodDescription( @NotNull final Method method, @NotNull final MethodDescription methodDescription ) 
     222            throws WebException 
    191223    { 
    192224        final Class<?>[] paramTypes = method.getParameterTypes(); 
    193225        final Annotation[][] paramAnnotations = method.getParameterAnnotations(); 
    194226 
    195         if(paramTypes.length != paramAnnotations.length) 
    196                 throw new WebException(WebException.WebCode.ERROR_NUMBER_OF_PARAM_TYPES_NOT_EQUAL_TO_PARAM_ANNOTATIONS, paramTypes.length+" "+paramAnnotations.length); 
    197           
     227        if( paramTypes.length != paramAnnotations.length ) 
     228            throw new WebException( WebException.WebCode.ERROR_NUMBER_OF_PARAM_TYPES_NOT_EQUAL_TO_PARAM_ANNOTATIONS, paramTypes.length + " " + paramAnnotations.length ); 
     229 
    198230        for( int i = 0; i < paramTypes.length; ++i ) 
    199231        { 
     
    219251            } 
    220252        } 
    221     }     
    222  
    223      
     253    } 
     254 
    224255    @Required 
    225256    public void setMethodNameResolver( final MethodNameResolver methodNameResolver ) 
     
    236267    public void setJsonHelper( final JSONHelper jsonHelper ) 
    237268    { 
    238         _jsonHelper = jsonHelper; 
     269        _jsonHelper = jsonHelper; 
    239270    } 
    240271 
     
    245276 
    246277    private static final Log LOGGER = LogFactory.getLog( ControllerEther.class ); 
    247     
     278 
    248279    private JSONHelper _jsonHelper; 
    249280    private MethodNameResolver _methodNameResolver; 
  • tapas/web/src/com/ether/WebException.java

    r382 r402  
    33/** 
    44 * @author vmipsl 
    5  * @date 02 feb 2011  
     5 * @date 02 feb 2011 
    66 */ 
    7 public class WebException  
    8         extends FormattedException 
     7public class WebException 
     8        extends FormattedException 
    99{ 
    10     public WebException(final Enum<? extends Code> code) { 
    11         super(code); 
    12         } 
    13  
    14         public WebException(final Enum<? extends Code> code, final Throwable cause, final Object... parameters) { 
    15         this(code, cause.getMessage(), cause, parameters); 
     10    public WebException( final Enum<? extends Code> code ) 
     11    { 
     12        super( code ); 
    1613    } 
    1714 
    18     protected WebException(final Enum<? extends Code> code, final String message, final Throwable cause, final Object... parameters) { 
    19         super(prefix(code, message), cause, parameters); 
     15    public WebException( final Throwable throwable ) 
     16    { 
     17        super( throwable ); 
    2018    } 
    2119 
    22         public WebException(final Throwable cause) { 
    23                 super(cause); 
    24         } 
     20    public WebException( final Enum<? extends Code> code, final Throwable throwable, final Object... parameters ) 
     21    { 
     22        this( code, throwable.getMessage(), throwable, parameters ); 
     23    } 
    2524 
    26         public WebException( final Enum<? extends Code> code, final String string) { 
    27                 super(code, string); 
    28         } 
     25    public WebException( final Enum<? extends Code> code, final String message, final Object... parameters ) 
     26    { 
     27        super( code, message, DEFAULT_THROWABLE, parameters ); 
     28    } 
    2929 
    30         public static enum WebCode implements Code  
     30    protected WebException( final Enum<? extends Code> code, final String message, final Throwable throwable, final Object... parameters ) 
    3131    { 
    32                 UNKNOWN,  
    33                 PERSISTENCE,  
    34                 SERVICE_PROBLEM, 
    35                 PLATEFORME_ID_NOT_FOUND, 
    36                 IO_EXCEPTION_ERROR_TO_GET_OUTPUTSTREAM, 
    37                 ERROR_UNSUPPORTED_UTF8_ENCODING, 
    38                 ERROR_NO_REQUEST_HANDLING_METHOD, 
    39                 ERROR_NUMBER_OF_PARAM_TYPES_NOT_EQUAL_TO_PARAM_ANNOTATIONS, 
    40         PLATEFORM_NOT_FOUND, 
    41         PARAMETER_NOT_FOUND 
     32        super( formatThrowable( code, message, throwable ), throwable, parameters ); 
    4233    } 
     34 
     35    public static enum WebCode 
     36            implements Code 
     37    { 
     38        UNKNOWN, 
     39        PERSISTENCE, 
     40        SERVICE_PROBLEM, 
     41        IO_EXCEPTION_ERROR_TO_GET_OUTPUTSTREAM, 
     42        ERROR_UNSUPPORTED_UTF8_ENCODING, 
     43        ERROR_NO_REQUEST_HANDLING_METHOD, 
     44        ERROR_NUMBER_OF_PARAM_TYPES_NOT_EQUAL_TO_PARAM_ANNOTATIONS, 
     45        ERROR_JSON_TAPAS_IS_NULL, 
     46    } 
     47 
     48    private static final Throwable DEFAULT_THROWABLE = null; 
    4349} 
  • tapas/web/src/com/ether/WebHelper.java

    r389 r402  
    11package com.ether; 
    22 
    3 import java.io.IOException; 
    4 import java.io.PrintWriter; 
    5 import java.security.InvalidParameterException; 
    6  
    7 import javax.servlet.ServletOutputStream; 
    8 import javax.servlet.http.HttpServletRequest; 
    9 import javax.servlet.http.HttpServletResponse; 
    10  
     3import com.ether.WebException.WebCode; 
    114import org.apache.commons.logging.Log; 
    125import org.apache.commons.logging.LogFactory; 
     
    147import org.jetbrains.annotations.Nullable; 
    158 
    16 import com.ether.WebException.WebCode; 
     9import javax.servlet.ServletOutputStream; 
     10import javax.servlet.http.HttpServletRequest; 
     11import javax.servlet.http.HttpServletResponse; 
     12import java.io.IOException; 
     13import java.io.PrintWriter; 
     14import java.security.InvalidParameterException; 
    1715 
    1816public final class WebHelper 
     
    2321 
    2422    @NotNull 
    25     public static String getRequestParameter(@NotNull final HttpServletRequest httpServletRequest, @Nullable final String parameterName, @Nullable final String defaultParameterValue, final boolean canBeNull ) 
    26         throws InvalidParameterException 
     23    public static String getRequestParameter( @NotNull final HttpServletRequest httpServletRequest, @Nullable final String parameterName, @Nullable final String defaultParameterValue, final boolean canBeNull ) 
     24            throws InvalidParameterException 
    2725    { 
    28         String parameterValue; 
    29         if(null == parameterName) 
    30                 parameterValue = defaultParameterValue; 
    31          
     26        String parameterValue; 
     27        if( null == parameterName ) 
     28            parameterValue = defaultParameterValue; 
     29 
    3230        parameterValue = httpServletRequest.getParameter( parameterName ); 
    3331 
     
    4846 
    4947        final PrintWriter writer = httpServletResponse.getWriter(); 
    50  
    51         writer.write( JSON_TAG_BEGIN ); 
    5248        writer.write( data ); 
    53         writer.write( JSON_TAG_END ); 
    5449    } 
    5550 
    56     public static void displayAjaxError(@NotNull final HttpServletResponse response, @Nullable final String methodName)  
    57         throws WebException 
    58     {            
    59         try { 
    60                 response.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED); 
    61                 response.setCharacterEncoding(UTF8Charset.getEncoding()); 
    62                 response.setContentType("text/plain;charset="+ UTF8Charset.getEncoding()); 
    63                 final ServletOutputStream outputStream = response.getOutputStream(); 
    64                 outputStream.print("error.method_not_implemented : " + methodName+ " is not implemented."); 
    65                 outputStream.flush(); 
    66                 outputStream.close(); 
    67         } catch (IOException e) { 
    68                 throw new WebException(WebCode.IO_EXCEPTION_ERROR_TO_GET_OUTPUTSTREAM, e); 
    69         } 
     51    public static void displayAjaxError( @NotNull final HttpServletResponse response, @Nullable final String methodName ) 
     52            throws WebException 
     53    { 
     54        try 
     55        { 
     56            response.setStatus( HttpServletResponse.SC_NOT_IMPLEMENTED ); 
     57            response.setCharacterEncoding( UTF8Charset.getEncoding() ); 
     58            response.setContentType( "text/plain;charset=" + UTF8Charset.getEncoding() ); 
     59            final ServletOutputStream outputStream = response.getOutputStream(); 
     60            outputStream.print( "error.method_not_implemented : " + methodName + " is not implemented." ); 
     61            outputStream.flush(); 
     62            outputStream.close(); 
     63        } 
     64        catch( IOException e ) 
     65        { 
     66            throw new WebException( WebCode.IO_EXCEPTION_ERROR_TO_GET_OUTPUTSTREAM, e ); 
     67        } 
    7068    } 
    7169 
    7270    private static final Log LOGGER = LogFactory.getLog( WebHelper.class ); 
    73      
     71 
     72    public static final int STATUS_CODE_SERVICE_EXCEPTION = 500; 
    7473    private static final String CONTENT_TYPE_TEXT_JSON = "text/javascript;charset=" + UTF8Charset.getEncoding(); 
    75     private static final char JSON_TAG_BEGIN = ' ' ;  // '('; 
    76     private static final char JSON_TAG_END = ' ';     // ')'; 
    7774} 
  • tapas/web/src/messages_en.properties

    r396 r402  
    1313label.map=Map 
    1414label.mail=Email 
     15 
     16error.ERROR_JSON_TAPAS_IS_NULL=Error to create the form 
    1517 
    1618label.atmosphere.chemistry=Atmosphere chemistry 
  • tapas/web/src/messages_fr.properties

    r396 r402  
    1313label.map=Plan 
    1414label.mail=Email 
     15 
     16error.ERROR_JSON_TAPAS_IS_NULL=Erreur de création du formulaire Tapas 
    1517 
    1618label.atmosphere.chemistry=Chimie de l&apos;atmosphÚre 
Note: See TracChangeset for help on using the changeset viewer.