Changeset 402
- Timestamp:
- 03/08/12 17:20:11 (12 years ago)
- Location:
- tapas
- Files:
-
- 1 deleted
- 11 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
tapas/common/interface/com/ether/FormattedException.java
r376 r402 5 5 6 6 @SuppressWarnings("serial") 7 public class FormattedException extends Exception 7 public class FormattedException 8 extends Exception 8 9 { 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 ); 11 13 } 12 14 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 ); 15 18 } 16 19 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 ); 19 23 } 20 24 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 ); 23 28 } 24 29 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 ); 27 33 } 28 34 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 ); 31 39 } 32 40 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(); 35 47 } 36 48 37 p rivate 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 ) 38 50 { 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 ); 43 55 } 44 56 … … 46 58 * Prefixes the message with code if not null. 47 59 */ 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 ) 49 61 { 50 62 final StringBuffer stringBuffer = new StringBuffer(); 51 63 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 } 56 69 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; 59 77 } 60 78 61 79 /** 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. 64 82 * If the subclass is not an enum it won't be recognized by the constructor. 65 83 */ … … 70 88 public static String DEFAULT_MESSAGE = "no message"; 71 89 public static String DEFAULT_THROWABLE = null; 90 private static final Throwable EXCEPTION_THROWABLE = new Throwable( "EXCEPTION_THROWABLE" ); 72 91 } -
tapas/service/implementation/com/ether/TapasServiceImpl.java
r389 r402 3 3 import com.ether.dao.ParameterDAO; 4 4 import com.ether.dao.PlateformDAO; 5 import com.ether.tapas.Tapas; 5 6 import org.apache.commons.logging.Log; 6 7 import org.apache.commons.logging.LogFactory; 7 import org.jdom.*; 8 import org.jdom.Attribute; 9 import org.jdom.Document; 10 import org.jdom.Element; 8 11 import org.jdom.output.Format; 9 12 import org.jdom.output.XMLOutputter; … … 15 18 import java.io.FileOutputStream; 16 19 import java.util.List; 17 import java.util.prefs.Preferences;18 20 19 21 /** … … 25 27 { 26 28 27 public void createXMLRequest() 28 29 public void createXMLRequest( @NotNull final Tapas tapas ) 29 30 { 30 31 String idF = "Ether_TAPAS_0000001"; … … 66 67 } 67 68 68 69 69 public void createXMLFile( final String fichier, final Document document ) 70 70 { … … 83 83 84 84 85 // TODO : supprimer cette méthode --> EXEMPLE 85 86 @Nullable 86 87 @Transactional(readOnly = true) … … 98 99 } 99 100 101 // TODO : supprimer cette méthode --> EXEMPLE 100 102 @Nullable 101 103 @Transactional(readOnly = true) … … 115 117 } 116 118 119 // TODO : supprimer cette méthode --> EXEMPLE 117 120 @Nullable 118 121 @Transactional(readOnly = true) … … 130 133 } 131 134 135 // TODO : supprimer cette méthode --> EXEMPLE 132 136 @Required 133 137 public void setPlateformDAO( final PlateformDAO plateformDAO ) … … 136 140 } 137 141 142 // TODO : supprimer cette méthode --> EXEMPLE 138 143 @Required 139 144 public void setParameterDAO( final ParameterDAO parameterDAO ) … … 144 149 private static final Log LOGGER = LogFactory.getLog( TapasServiceImpl.class ); 145 150 146 151 // TODO : supprimer ces DAO --> EXEMPLES 147 152 private PlateformDAO _plateformDAO; 148 153 private ParameterDAO _parameterDAO; -
tapas/service/interface/com/ether/TapasService.java
r389 r402 1 1 package com.ether; 2 2 3 import com.ether.tapas.Tapas; 3 4 import org.jdom.Document; 4 5 import org.jetbrains.annotations.NotNull; … … 8 9 9 10 /** 10 * @author vmipsl11 * @date 0 7 mar 201111 * @author rboipsl 12 * @date 02 march 2012 12 13 */ 13 14 public interface TapasService 14 15 extends Service 15 16 { 16 17 public void createXMLRequest(); 17 public void createXMLRequest( @NotNull final Tapas tapas ); 18 18 19 19 public void createXMLFile( final String fichier, final Document document ); 20 21 @Nullable22 List<Plateform> getAllPlateforms() throws ServiceException;23 24 @Nullable25 Plateform getPlateformById( @Nullable final Integer plateformId ) throws ServiceException;26 27 @Nullable28 List<Parameter> getAllParametersByPlateformId( @NotNull final Integer plateformId ) throws ServiceException;29 20 } -
tapas/service/test/com/ether/EtherTest.java
r389 r402 2 2 3 3 import org.jetbrains.annotations.NotNull; 4 import org.junit.Assert;5 4 import org.junit.Test; 6 5 … … 11 10 import java.io.File; 12 11 import java.io.Serializable; 13 import java.text.DateFormat;14 12 import java.text.ParseException; 15 import java.text.SimpleDateFormat;16 import java.util.Calendar;17 import java.util.Date;18 13 19 14 /** … … 29 24 { 30 25 31 getService().createXMLRequest( );26 getService().createXMLRequest( null ); 32 27 33 28 } -
tapas/web/project/formTapas.jsp
r400 r402 1 1 <%@ page import="com.ether.Context" %> 2 <%@ page import="com.ether.WebException" %> 2 3 <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 4 <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> … … 26 27 </div> 27 28 29 <div id="errors"></div> 28 30 29 31 <BR/> … … 40 42 41 43 <script type="text/javascript"> 42 var initTexts = $A( "" );44 var tapasTexts = $A( "" ); 43 45 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"/>"; 45 48 46 49 -
tapas/web/project/formTapas_script.jsp
r401 r402 6 6 /** *********** CONTAINERS *********** **/ 7 7 this.containerForm = $( "#formulaire" ); 8 this.containerErrors = $( "#errors" ); 8 9 10 this.containerErrors.hide(); 9 11 this.createForm(); 10 11 12 }, 12 13 … … 24 25 this.containerForm.append( input2 ); 25 26 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 )} ); 27 28 28 29 }, … … 37 38 $.ajax( { 38 39 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 ) 40 42 } ); 41 43 }, … … 45 47 { 46 48 var bob = jQuery.parseJSON( result ).result; 47 //alert( bob );49 alert( bob ); 48 50 }, 49 51 … … 52 54 onClickSubmit: function() 53 55 { 56 this.containerErrors.hide(); 54 57 this.requestCreateXML(); 55 58 }, 56 59 57 60 // OTHERS ******************************************************** 61 showErrors: function( result ) 62 { 63 this.containerErrors.show(); 64 this.containerErrors.html( tapasTexts[result.responseText] ); 65 }, 66 58 67 createTapasForm: function() 59 68 { -
tapas/web/src/com/ether/Controller.java
r400 r402 17 17 /** 18 18 * @author vmipsl 19 * @date 0 5march 201219 * @date 02 march 2012 20 20 */ 21 21 public class Controller … … 45 45 @ControllerMethod(jsonResult = true) 46 46 public JSONObject createUserRequest( @ParamName("jsonTapas") @Mandatory @UseJSON final Tapas jsonTapas ) 47 throws ServiceException47 throws WebException 48 48 { 49 if( null == jsonTapas ) 50 throw new WebException( WebException.WebCode.ERROR_JSON_TAPAS_IS_NULL, "Serialization error : jsonTapas is null", WebException.getExceptionThrowable() ); 51 49 52 //appel a createxml 50 _tapasService.createXMLRequest( );53 _tapasService.createXMLRequest( jsonTapas ); 51 54 52 55 final JSONObject result = new JSONObject(); -
tapas/web/src/com/ether/ControllerEther.java
r376 r402 1 1 package com.ether; 2 2 3 import com.ether.annotation.ControllerMethod; 4 import com.ether.annotation.Mandatory; 5 import com.ether.annotation.ParamName; 6 import com.ether.annotation.UseJSON; 7 import net.sf.json.JSON; 8 import net.sf.json.JSONArray; 9 import net.sf.json.JSONNull; 10 import net.sf.json.JSONObject; 11 import net.sf.json.util.JSONUtils; 12 import org.apache.commons.logging.Log; 13 import org.apache.commons.logging.LogFactory; 14 import org.jetbrains.annotations.NotNull; 15 import org.jetbrains.annotations.Nullable; 16 import org.springframework.beans.factory.annotation.Required; 17 import org.springframework.web.servlet.ModelAndView; 18 import org.springframework.web.servlet.mvc.AbstractController; 19 import org.springframework.web.servlet.mvc.multiaction.MethodNameResolver; 20 import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException; 21 22 import javax.servlet.http.HttpServletRequest; 23 import javax.servlet.http.HttpServletResponse; 24 import java.io.IOException; 3 25 import java.io.UnsupportedEncodingException; 4 26 import java.lang.annotation.Annotation; … … 12 34 import java.util.Map; 13 35 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 36 public class ControllerEther 37 extends AbstractController 39 38 { 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 ) 109 139 return JSONNull.getInstance().toString(); 110 140 if( object instanceof JSON ) … … 119 149 } 120 150 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 ) 141 173 { 142 174 if( null == paramValue ) … … 148 180 if( JSONArray.class.equals( paramType ) ) 149 181 return _jsonHelper.toJSON( paramValue ); 150 if( String.class 182 if( String.class.equals( paramType ) ) 151 183 return paramValue; 152 184 if( Boolean.TYPE.equals( paramType ) || Boolean.class.equals( paramType ) ) … … 170 202 } 171 203 172 private void initialize() 173 204 private void initialize() 205 throws WebException 174 206 { 175 207 for( final Method method : getClass().getMethods() ) … … 178 210 if( null != annotation ) 179 211 { 180 181 182 212 final MethodDescription methodDescription = new MethodDescription( method, annotation ); 213 fillMethodDescription( method, methodDescription ); 214 _methods.put( method.getName(), methodDescription ); 183 215 } 184 216 } … … 187 219 } 188 220 189 private void fillMethodDescription( @NotNull final Method method, @NotNull final MethodDescription methodDescription ) 190 221 private void fillMethodDescription( @NotNull final Method method, @NotNull final MethodDescription methodDescription ) 222 throws WebException 191 223 { 192 224 final Class<?>[] paramTypes = method.getParameterTypes(); 193 225 final Annotation[][] paramAnnotations = method.getParameterAnnotations(); 194 226 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 198 230 for( int i = 0; i < paramTypes.length; ++i ) 199 231 { … … 219 251 } 220 252 } 221 } 222 223 253 } 254 224 255 @Required 225 256 public void setMethodNameResolver( final MethodNameResolver methodNameResolver ) … … 236 267 public void setJsonHelper( final JSONHelper jsonHelper ) 237 268 { 238 269 _jsonHelper = jsonHelper; 239 270 } 240 271 … … 245 276 246 277 private static final Log LOGGER = LogFactory.getLog( ControllerEther.class ); 247 278 248 279 private JSONHelper _jsonHelper; 249 280 private MethodNameResolver _methodNameResolver; -
tapas/web/src/com/ether/WebException.java
r382 r402 3 3 /** 4 4 * @author vmipsl 5 * @date 02 feb 2011 5 * @date 02 feb 2011 6 6 */ 7 public class WebException 8 7 public class WebException 8 extends FormattedException 9 9 { 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 ); 16 13 } 17 14 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 ); 20 18 } 21 19 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 } 25 24 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 } 29 29 30 public static enum WebCode implements Code 30 protected WebException( final Enum<? extends Code> code, final String message, final Throwable throwable, final Object... parameters ) 31 31 { 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 ); 42 33 } 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; 43 49 } -
tapas/web/src/com/ether/WebHelper.java
r389 r402 1 1 package com.ether; 2 2 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 3 import com.ether.WebException.WebCode; 11 4 import org.apache.commons.logging.Log; 12 5 import org.apache.commons.logging.LogFactory; … … 14 7 import org.jetbrains.annotations.Nullable; 15 8 16 import com.ether.WebException.WebCode; 9 import javax.servlet.ServletOutputStream; 10 import javax.servlet.http.HttpServletRequest; 11 import javax.servlet.http.HttpServletResponse; 12 import java.io.IOException; 13 import java.io.PrintWriter; 14 import java.security.InvalidParameterException; 17 15 18 16 public final class WebHelper … … 23 21 24 22 @NotNull 25 public static String getRequestParameter( @NotNull final HttpServletRequest httpServletRequest, @Nullable final String parameterName, @Nullable final String defaultParameterValue, final boolean canBeNull )26 23 public static String getRequestParameter( @NotNull final HttpServletRequest httpServletRequest, @Nullable final String parameterName, @Nullable final String defaultParameterValue, final boolean canBeNull ) 24 throws InvalidParameterException 27 25 { 28 29 if(null == parameterName)30 31 26 String parameterValue; 27 if( null == parameterName ) 28 parameterValue = defaultParameterValue; 29 32 30 parameterValue = httpServletRequest.getParameter( parameterName ); 33 31 … … 48 46 49 47 final PrintWriter writer = httpServletResponse.getWriter(); 50 51 writer.write( JSON_TAG_BEGIN );52 48 writer.write( data ); 53 writer.write( JSON_TAG_END );54 49 } 55 50 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 } 70 68 } 71 69 72 70 private static final Log LOGGER = LogFactory.getLog( WebHelper.class ); 73 71 72 public static final int STATUS_CODE_SERVICE_EXCEPTION = 500; 74 73 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 = ' '; // ')';77 74 } -
tapas/web/src/messages_en.properties
r396 r402 13 13 label.map=Map 14 14 label.mail=Email 15 16 error.ERROR_JSON_TAPAS_IS_NULL=Error to create the form 15 17 16 18 label.atmosphere.chemistry=Atmosphere chemistry -
tapas/web/src/messages_fr.properties
r396 r402 13 13 label.map=Plan 14 14 label.mail=Email 15 16 error.ERROR_JSON_TAPAS_IS_NULL=Erreur de création du formulaire Tapas 15 17 16 18 label.atmosphere.chemistry=Chimie de l'atmosphÚre
Note: See TracChangeset
for help on using the changeset viewer.