Modified code to be slightly more logic.
authorMarco Zanon <info@marcozanon.com>
Wed, 1 Feb 2012 18:31:42 +0000 (18:31 +0000)
committerMarco Zanon <info@marcozanon.com>
Wed, 1 Feb 2012 18:31:42 +0000 (18:31 +0000)
src/java/com/marcozanon/macaco/web/ui/MWebApplicationServlet.java

index c04a63ca6d59f68d7c729a67b804b2d469a02dbb..8a08959627ffb09f88863e9709b59ebcadad8b44 100644 (file)
@@ -201,17 +201,17 @@ public abstract class MWebApplicationServlet extends MHttpServlet {
         // prepare response content
         byte[] responseContent = null;
         if (ajaxMode) {
-            MJsonObject returnValue = null;
             try {
+                MJsonObject returnValue = null;
                 returnValue = new MJsonObject();
                 returnValue.setValue("errorMode", new MJsonNumber("" + MWebApplicationServlet.ErrorMode.CLEAN.ordinal()));
                 MJsonString jsonParameter = new MJsonString();
                 jsonParameter.setValue(new String(content, MInformation.TEXT_ENCODING));
                 returnValue.setValue("parameter", jsonParameter);
+                responseContent = returnValue.getJsonValue().getBytes(MInformation.TEXT_ENCODING);
             }
             catch (MInvalidValueJsonException exception) { // cannot happen
             }
-            responseContent = returnValue.getJsonValue().getBytes(MInformation.TEXT_ENCODING);
         }
         else {
             responseContent = content;
@@ -241,8 +241,8 @@ public abstract class MWebApplicationServlet extends MHttpServlet {
         try {
             if (MWebApplicationServlet.ErrorMode.DEBUG == errorMode) {
                 if (ajaxMode) {
-                    MJsonObject returnValue = null;
                     try {
+                        MJsonObject returnValue = null;
                         returnValue = new MJsonObject();
                         returnValue.setValue("errorMode", new MJsonNumber("" + errorMode.ordinal()));
                         MJsonString jsonParameter = new MJsonString();
@@ -253,10 +253,10 @@ public abstract class MWebApplicationServlet extends MHttpServlet {
                             jsonParameter.setValue(content.getClass().getName());
                         }
                         returnValue.setValue("parameter", jsonParameter);
+                        responseContent = returnValue.getJsonValue().getBytes(MInformation.TEXT_ENCODING);
                     }
                     catch (MInvalidValueJsonException exception) { // should not happen
                     }
-                    responseContent = returnValue.getJsonValue().getBytes(MInformation.TEXT_ENCODING);
                 }
                 else {
                     if (null != content.getMessage()) {