qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kw...@apache.org
Subject svn commit: r1685703 - in /qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet: ./ rest/
Date Tue, 16 Jun 2015 05:36:56 GMT
Author: kwall
Date: Tue Jun 16 05:36:55 2015
New Revision: 1685703

URL: http://svn.apache.org/r1685703
Log:
QPID-6588: [Java Broker] Refactor servlets to centralise the setting of headers and set content-endoding
consistently across all application/json responses

Modified:
    qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/LogFileServlet.java
    qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java
    qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogFileListingServlet.java
    qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsServlet.java
    qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java
    qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
    qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java
    qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java
    qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/TimeZoneServlet.java

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/LogFileServlet.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/LogFileServlet.java?rev=1685703&r1=1685702&r2=1685703&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/LogFileServlet.java
(original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/LogFileServlet.java
Tue Jun 16 05:36:55 2015
@@ -44,9 +44,7 @@ public class LogFileServlet extends Abst
     protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse
response) throws IOException,
             ServletException
     {
-        response.setHeader("Cache-Control", "no-cache");
-        response.setHeader("Pragma", "no-cache");
-        response.setDateHeader("Expires", 0);
+        sendCachingHeadersOnResponse(response);
 
         if (!getBroker().getSecurityManager().authoriseLogsAccess())
         {
@@ -86,7 +84,7 @@ public class LogFileServlet extends Abst
 
         String fileName = String.format(LOGS_FILE_NAME, new SimpleDateFormat(DATE_FORMAT).format(new
Date()));
         response.setStatus(HttpServletResponse.SC_OK);
-        response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+        response.setHeader(CONTENT_DISPOSITION, "attachment;filename=" + fileName);
         response.setContentType(LogFileHelper.ZIP_MIME_TYPE);
 
         OutputStream os = response.getOutputStream();

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java?rev=1685703&r1=1685702&r2=1685703&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java
(original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java
Tue Jun 16 05:36:55 2015
@@ -23,10 +23,11 @@ package org.apache.qpid.server.managemen
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
-import java.io.Writer;
 import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
+import java.util.Collections;
 
 import javax.security.auth.Subject;
 import javax.servlet.ServletConfig;
@@ -50,6 +51,7 @@ import org.apache.qpid.server.util.Conne
 public abstract class AbstractServlet extends HttpServlet
 {
     private static final Logger LOGGER = LoggerFactory.getLogger(AbstractServlet.class);
+    public static final String CONTENT_DISPOSITION = "Content-disposition";
 
     private Broker<?> _broker;
     private HttpManagementConfiguration _managementConfiguration;
@@ -246,30 +248,50 @@ public abstract class AbstractServlet ex
         return _managementConfiguration;
     }
 
-    protected void sendError(final HttpServletResponse resp, int errorCode)
+    protected void sendJsonResponse(Object object, HttpServletRequest request, HttpServletResponse
response) throws IOException
     {
-        try
-        {
-            resp.sendError(errorCode);
-        }
-        catch (IOException e)
+        sendJsonResponse(object, request, response, HttpServletResponse.SC_OK, true);
+    }
+
+    protected void sendJsonResponse(Object object, HttpServletRequest request, HttpServletResponse
response, int responseCode, boolean sendCachingHeaders) throws IOException
+    {
+        response.setStatus(responseCode);
+        response.setContentType("application/json");
+        response.setCharacterEncoding(StandardCharsets.UTF_8.name());
+
+        if (sendCachingHeaders)
         {
-            throw new ConnectionScopedRuntimeException("Failed to send error response code
" + errorCode, e);
+            sendCachingHeadersOnResponse(response);
         }
+
+        writeObjectToResponse(object, request, response);
     }
 
-    protected void sendJsonResponse(Object object, HttpServletRequest request, HttpServletResponse
response) throws IOException
+    protected void sendJsonErrorResponse(HttpServletRequest request,
+                                         HttpServletResponse response,
+                                         int responseCode,
+                                         String message) throws IOException
     {
-        response.setStatus(HttpServletResponse.SC_OK);
-        response.setHeader("Cache-Control","no-cache");
-        response.setHeader("Pragma","no-cache");
-        response.setDateHeader ("Expires", 0);
+        response.setStatus(responseCode);
         response.setContentType("application/json");
+        response.setCharacterEncoding(StandardCharsets.UTF_8.name());
 
-        writeObjectToResponse(object, request, response);
+        writeObjectToResponse(Collections.singletonMap("errorMessage", message), request,
response);
     }
 
-    protected void writeObjectToResponse(Object object, HttpServletRequest request,  HttpServletResponse
response) throws IOException
+    protected void sendError(final HttpServletResponse resp, int responseCode)
+    {
+        try
+        {
+            resp.sendError(responseCode);
+        }
+        catch (IOException e)
+        {
+            throw new ConnectionScopedRuntimeException("Failed to send error response code
" + responseCode, e);
+        }
+    }
+
+    private void writeObjectToResponse(Object object, HttpServletRequest request,  HttpServletResponse
response) throws IOException
     {
         OutputStream stream = getOutputStream(request, response);
         ObjectMapper mapper = ConfiguredObjectJacksonModule.newObjectMapper();
@@ -277,6 +299,13 @@ public abstract class AbstractServlet ex
         mapper.writeValue(stream, object);
     }
 
+    protected void sendCachingHeadersOnResponse(HttpServletResponse response)
+    {
+        response.setHeader("Cache-Control", "no-cache");
+        response.setHeader("Pragma", "no-cache");
+        response.setDateHeader("Expires", 0);
+    }
+
     protected String[] getPathInfoElements(HttpServletRequest request)
     {
         String pathInfo = request.getPathInfo();

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogFileListingServlet.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogFileListingServlet.java?rev=1685703&r1=1685702&r2=1685703&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogFileListingServlet.java
(original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogFileListingServlet.java
Tue Jun 16 05:36:55 2015
@@ -18,18 +18,12 @@
 package org.apache.qpid.server.management.plugin.servlet.rest;
 
 import java.io.IOException;
-import java.io.OutputStream;
-import java.io.Writer;
-import java.util.Collections;
 import java.util.List;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.SerializationConfig;
-
 import org.apache.qpid.server.management.plugin.log.LogFileDetails;
 import org.apache.qpid.server.management.plugin.log.LogFileHelper;
 
@@ -41,10 +35,6 @@ public class LogFileListingServlet exten
     protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse
response) throws IOException,
             ServletException
     {
-        response.setHeader("Cache-Control", "no-cache");
-        response.setHeader("Pragma", "no-cache");
-        response.setDateHeader("Expires", 0);
-
         if (!getBroker().getSecurityManager().authoriseLogsAccess())
         {
             response.sendError(HttpServletResponse.SC_FORBIDDEN, "Log files access is denied");
@@ -55,15 +45,8 @@ public class LogFileListingServlet exten
         // QPID-6516 : TODO
         LogFileHelper helper = null; // new LogFileHelper(Collections.list(LogManager.getRootLogger().getAllAppenders()));
         List<LogFileDetails> logFiles = helper.getLogFileDetails(false);
-        response.setContentType("application/json");
-        response.setStatus(HttpServletResponse.SC_OK);
-
-        final OutputStream stream = getOutputStream(request, response);
-        ObjectMapper mapper = new ObjectMapper();
-        mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
-        mapper.writeValue(stream, logFiles);
 
-        response.setStatus(HttpServletResponse.SC_OK);
+        sendJsonResponse(logFiles, request, response);
     }
 
 }

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsServlet.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsServlet.java?rev=1685703&r1=1685702&r2=1685703&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsServlet.java
(original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsServlet.java
Tue Jun 16 05:36:55 2015
@@ -48,13 +48,6 @@ public class LogRecordsServlet extends A
     @Override
     protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse
response) throws IOException, ServletException
     {
-        response.setContentType("application/json");
-        response.setStatus(HttpServletResponse.SC_OK);
-
-        response.setHeader("Cache-Control","no-cache");
-        response.setHeader("Pragma","no-cache");
-        response.setDateHeader ("Expires", 0);
-
         if (!getBroker().getSecurityManager().authoriseLogsAccess())
         {
             response.sendError(HttpServletResponse.SC_FORBIDDEN, "Broker logs access is denied");
@@ -82,13 +75,7 @@ public class LogRecordsServlet extends A
             }
         }
 
-        final OutputStream stream = getOutputStream(request, response);
-        ObjectMapper mapper = new ObjectMapper();
-        mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
-        mapper.writeValue(stream, logRecords);
-
-        response.setStatus(HttpServletResponse.SC_OK);
-
+        sendJsonResponse(logRecords, request, response);
     }
 
     private Map<String, Object> logRecordToObject(LogRecord record)

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java?rev=1685703&r1=1685702&r2=1685703&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java
(original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java
Tue Jun 16 05:36:55 2015
@@ -80,14 +80,7 @@ public class MessageServlet extends Abst
         MessageFinder messageFinder = new MessageFinder(Long.parseLong(path[2]));
         queue.visit(messageFinder);
 
-        response.setStatus(HttpServletResponse.SC_OK);
-
-        response.setHeader("Cache-Control","no-cache");
-        response.setHeader("Pragma","no-cache");
-        response.setDateHeader ("Expires", 0);
-        response.setContentType("application/json");
-
-        writeObjectToResponse(messageFinder.getMessageObject(), request, response);
+        sendJsonResponse(messageFinder.getMessageObject(), request, response);
     }
 
     private void getMessageList(HttpServletRequest request, HttpServletResponse response)
throws IOException
@@ -106,19 +99,13 @@ public class MessageServlet extends Abst
         final MessageCollector messageCollector = new MessageCollector(first, last);
         queue.visit(messageCollector);
 
-        response.setContentType("application/json");
         final List<Map<String, Object>> messages = messageCollector.getMessages();
         int queueSize = (int) queue.getQueueDepthMessages();
         String min = messages.isEmpty() ? "0" : messages.get(0).get("position").toString();
         String max = messages.isEmpty() ? "0" : messages.get(messages.size()-1).get("position").toString();
         response.setHeader("Content-Range", (min + "-" + max + "/" + queueSize));
-        response.setStatus(HttpServletResponse.SC_OK);
-
-        response.setHeader("Cache-Control","no-cache");
-        response.setHeader("Pragma","no-cache");
-        response.setDateHeader ("Expires", 0);
 
-        writeObjectToResponse(messages, request, response);
+        sendJsonResponse(messages, request, response);
     }
 
     private Queue<?> getQueueFromRequest(HttpServletRequest request)

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java?rev=1685703&r1=1685702&r2=1685703&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
(original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
Tue Jun 16 05:36:55 2015
@@ -38,7 +38,6 @@ import javax.servlet.http.HttpServletRes
 import javax.servlet.http.Part;
 
 import org.apache.qpid.server.model.AbstractConfiguredObject;
-import org.apache.qpid.server.model.ConfiguredObjectJacksonModule;
 import org.apache.qpid.server.model.ConfiguredObjectOperation;
 import org.apache.qpid.server.model.IllegalStateTransitionException;
 import org.apache.qpid.server.model.IntegrityViolationException;
@@ -46,7 +45,6 @@ import org.apache.qpid.server.model.Type
 import org.apache.qpid.server.virtualhost.ExchangeExistsException;
 import org.apache.qpid.server.virtualhost.QueueExistsException;
 import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.SerializationConfig;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -339,14 +337,7 @@ public class RestServlet extends Abstrac
         String attachmentFilename = request.getParameter(CONTENT_DISPOSITION_ATTACHMENT_FILENAME_PARAM);
         boolean extractInitialConfig = getBooleanParameterFromRequest(request, EXTRACT_INITIAL_CONFIG_PARAM);
 
-        response.setContentType("application/json");
-        response.setStatus(HttpServletResponse.SC_OK);
-
-        if (attachmentFilename == null)
-        {
-            setCachingHeadersOnResponse(response);
-        }
-        else
+        if (attachmentFilename != null)
         {
             setContentDispositionHeaderIfNecessary(response, attachmentFilename);
         }
@@ -355,7 +346,7 @@ public class RestServlet extends Abstrac
 
         if (allObjects.isEmpty() && isSingleObjectRequest(request) )
         {
-            sendErrorResponse(request, response, HttpServletResponse.SC_NOT_FOUND, "Not Found");
+            sendJsonErrorResponse(request, response, HttpServletResponse.SC_NOT_FOUND, "Not
Found");
             return;
         }
 
@@ -391,7 +382,12 @@ public class RestServlet extends Abstrac
         }
 
 
-        writeObjectToResponse(extractInitialConfig && output.size() == 1 ? output.get(0)
: output, request, response);
+        boolean sendCachingHeaders = attachmentFilename == null;
+        sendJsonResponse(extractInitialConfig && output.size() == 1 ? output.get(0)
: output,
+                         request,
+                         response,
+                         HttpServletResponse.SC_OK,
+                         sendCachingHeaders);
     }
 
     private boolean isSingleObjectRequest(HttpServletRequest request)
@@ -413,11 +409,11 @@ public class RestServlet extends Abstrac
             String filenameRfc2183 = ensureFilenameIsRfc2183(attachmentFilename);
             if (filenameRfc2183.length() > 0)
             {
-                response.setHeader("Content-disposition", String.format("attachment; filename=\"%s\"",
filenameRfc2183));
+                response.setHeader(CONTENT_DISPOSITION, String.format("attachment; filename=\"%s\"",
filenameRfc2183));
             }
             else
             {
-                response.setHeader("Content-disposition", String.format("attachment")); 
// Agent will allow user to choose a name
+                response.setHeader(CONTENT_DISPOSITION, String.format("attachment"));  //
Agent will allow user to choose a name
             }
         }
     }
@@ -479,10 +475,10 @@ public class RestServlet extends Abstrac
                     }
                     else if (isPostToFullURL)
                     {
-                        sendErrorResponse(request, response, HttpServletResponse.SC_NOT_FOUND,
"Object with "
-                                                                                        
      + (providedObject.containsKey(
+                        sendJsonErrorResponse(request, response, HttpServletResponse.SC_NOT_FOUND,
"Object with "
+                                                                                        
          + (providedObject.containsKey(
                                 "id") ? " id '" + providedObject.get("id") : " name '" +
providedObject.get("name"))
-                                                                                        
      + "' does not exist!");
+                                                                                        
          + "' does not exist!");
                         return;
                     }
                 }
@@ -535,7 +531,13 @@ public class RestServlet extends Abstrac
             subject = findObjectToUpdateInParent(objClass, objectName, theParent, otherParents);
             if(subject == null)
             {
-                sendErrorResponse(request, response, HttpServletResponse.SC_NOT_FOUND, getConfiguredClass().getSimpleName()
+ " '" + pathInfoElements[pathInfoElements.length-2] + "' not found.");
+                sendJsonErrorResponse(request,
+                                      response,
+                                      HttpServletResponse.SC_NOT_FOUND,
+                                      getConfiguredClass().getSimpleName()
+                                      + " '"
+                                      + pathInfoElements[pathInfoElements.length - 2]
+                                      + "' not found.");
                 return;
             }
         }
@@ -545,25 +547,24 @@ public class RestServlet extends Abstrac
         ConfiguredObjectOperation operation = availableOperations.get(operationName);
         if (operation == null)
         {
-            sendErrorResponse(request, response, HttpServletResponse.SC_NOT_FOUND, "No such
operation: " + operationName);
+            sendJsonErrorResponse(request,
+                                  response,
+                                  HttpServletResponse.SC_NOT_FOUND,
+                                  "No such operation: " + operationName);
             return;
         }
         Object returnVal = operation.perform(subject, providedObject);
-        response.setStatus(HttpServletResponse.SC_OK);
         if(returnVal instanceof TypedContent)
         {
             TypedContent typedContent = (TypedContent)returnVal;
+            response.setStatus(HttpServletResponse.SC_OK);
             response.setContentType(typedContent.getContentType());
             response.setContentLength(typedContent.getData().length);
             getOutputStream(request, response).write(typedContent.getData());
         }
         else
         {
-            response.setContentType("application/json");
-            OutputStream stream = getOutputStream(request, response);
-            ObjectMapper mapper = ConfiguredObjectJacksonModule.newObjectMapper();
-            mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
-            mapper.writeValue(stream, returnVal);
+            sendJsonResponse(returnVal, request, response);
         }
 
     }
@@ -789,31 +790,14 @@ public class RestServlet extends Abstrac
             }
 
 
-            sendErrorResponse(request, response, responseCode, message);
+            sendJsonErrorResponse(request, response, responseCode, message);
 
         }
     }
 
-    private void sendErrorResponse(HttpServletRequest request, HttpServletResponse response,
int responseCode, String message) throws IOException
-    {
-        response.setStatus(responseCode);
-
-        response.setContentType("application/json");
-        response.setCharacterEncoding("UTF-8");
-
-        OutputStream out = getOutputStream(request, response);
-        ObjectMapper mapper = new ObjectMapper();
-        mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
-        mapper.writeValue(out, Collections.singletonMap("errorMessage", message));
-    }
-
     @Override
     protected void doDeleteWithSubjectAndActor(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
     {
-        response.setContentType("application/json");
-        response.setStatus(HttpServletResponse.SC_OK);
-
-        setCachingHeadersOnResponse(response);
         try
         {
             Collection<ConfiguredObject<?>> allObjects = getObjects(request);
@@ -822,6 +806,7 @@ public class RestServlet extends Abstrac
                 o.delete();
             }
 
+            sendCachingHeadersOnResponse(response);
             response.setStatus(HttpServletResponse.SC_OK);
         }
         catch(RuntimeException e)
@@ -836,12 +821,6 @@ public class RestServlet extends Abstrac
         performCreateOrUpdate(request, response);
     }
 
-    private void setCachingHeadersOnResponse(HttpServletResponse response)
-    {
-        response.setHeader("Cache-Control","no-cache");
-        response.setHeader("Pragma","no-cache");
-        response.setDateHeader ("Expires", 0);
-    }
 
     private int getIntParameterFromRequest(final HttpServletRequest request,
                                            final String paramName,

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java?rev=1685703&r1=1685702&r2=1685703&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java
(original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java
Tue Jun 16 05:36:55 2015
@@ -21,7 +21,6 @@
 package org.apache.qpid.server.management.plugin.servlet.rest;
 
 import java.io.IOException;
-import java.io.OutputStream;
 import java.security.Principal;
 import java.security.SecureRandom;
 import java.util.LinkedHashMap;
@@ -38,8 +37,6 @@ import javax.servlet.http.HttpServletRes
 import javax.servlet.http.HttpSession;
 import javax.xml.bind.DatatypeConverter;
 
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.SerializationConfig;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -72,13 +69,6 @@ public class SaslServlet extends Abstrac
                                                                                    ServletException,
                                                                                    IOException
     {
-        response.setContentType("application/json");
-        response.setStatus(HttpServletResponse.SC_OK);
-
-        response.setHeader("Cache-Control","no-cache");
-        response.setHeader("Pragma","no-cache");
-        response.setDateHeader ("Expires", 0);
-
         HttpSession session = request.getSession();
         getRandom(session);
 
@@ -100,10 +90,7 @@ public class SaslServlet extends Abstrac
 
         outputObject.put("mechanisms", (Object) mechanisms);
 
-        final OutputStream stream = getOutputStream(request, response);
-        ObjectMapper mapper = new ObjectMapper();
-        mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
-        mapper.writeValue(stream, outputObject);
+        sendJsonResponse(outputObject, request, response);
 
     }
 
@@ -129,11 +116,6 @@ public class SaslServlet extends Abstrac
 
         try
         {
-            response.setContentType("application/json");
-            response.setHeader("Cache-Control","no-cache");
-            response.setHeader("Pragma","no-cache");
-            response.setDateHeader("Expires", 0);
-
             HttpSession session = request.getSession();
 
             String mechanism = request.getParameter("mechanism");
@@ -269,8 +251,9 @@ public class SaslServlet extends Abstrac
                 Map<String, Object> outputObject = new LinkedHashMap<String, Object>();
                 outputObject.put("challenge", DatatypeConverter.printBase64Binary(challenge));
 
-                writeObjectToResponse(outputObject, request, response);
+                sendJsonResponse(outputObject, request, response);
             }
+
             response.setStatus(HttpServletResponse.SC_OK);
         }
         else
@@ -287,7 +270,7 @@ public class SaslServlet extends Abstrac
             outputObject.put("id", id);
             outputObject.put("challenge", DatatypeConverter.printBase64Binary(challenge));
 
-            writeObjectToResponse(outputObject, request, response);
+            sendJsonResponse(outputObject, request, response);
         }
     }
 

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java?rev=1685703&r1=1685702&r2=1685703&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java
(original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java
Tue Jun 16 05:36:55 2015
@@ -40,20 +40,12 @@ public class StructureServlet extends Ab
     @Override
     protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse
response) throws IOException, ServletException
     {
-        response.setContentType("application/json");
-        response.setStatus(HttpServletResponse.SC_OK);
-
-        response.setHeader("Cache-Control","no-cache");
-        response.setHeader("Pragma","no-cache");
-        response.setDateHeader ("Expires", 0);
 
         // TODO filtering??? request.getParameter("filter"); // filter=1,2,3   /groups/*/*
 
         Map<String,Object> structure = generateStructure(getBroker(), Broker.class);
 
-        writeObjectToResponse(structure, request, response);
-
-        response.setStatus(HttpServletResponse.SC_OK);
+        sendJsonResponse(structure, request, response);
 
     }
 

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/TimeZoneServlet.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/TimeZoneServlet.java?rev=1685703&r1=1685702&r2=1685703&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/TimeZoneServlet.java
(original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/TimeZoneServlet.java
Tue Jun 16 05:36:55 2015
@@ -1,6 +1,25 @@
-package org.apache.qpid.server.management.plugin.servlet.rest;
-
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
 
+package org.apache.qpid.server.management.plugin.servlet.rest;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Date;
@@ -11,33 +30,22 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.SerializationConfig;
-
 public class TimeZoneServlet extends AbstractServlet
 {
 
     private static final String[] TIMEZONE_REGIONS = { "Africa", "America", "Antarctica",
"Arctic", "Asia", "Atlantic", "Australia",
             "Europe", "Indian", "Pacific" };
 
-    private final ObjectMapper _mapper;
-
     public TimeZoneServlet()
     {
         super();
-        _mapper = new ObjectMapper();
-        _mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
     }
 
     @Override
     protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse
response) throws ServletException,
             IOException
     {
-        response.setContentType("application/json");
-        writeObjectToResponse(getTimeZones(), request, response);
-
-        response.setStatus(HttpServletResponse.SC_OK);
+        sendJsonResponse(getTimeZones(), request, response);
     }
 
     public List<TimeZoneDetails> getTimeZones()



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message