changeset 281:fdd31cc5e164

Make Auth implementation more generic and improve structure of code Reviewed-by: jkang Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-October/025347.html
author Miloslav Zezulka <mzezulka@redhat.com>
date Tue, 17 Oct 2017 11:11:23 +0200
parents 262f254b0ac0
children ca400f9fdbde
files common/core/src/main/java/com/redhat/thermostat/gateway/common/db/Pair.java common/core/src/main/java/com/redhat/thermostat/gateway/common/db/servlet/AbstractHttpHandlerHelper.java common/core/src/main/java/com/redhat/thermostat/gateway/common/db/servlet/HttpHandlerHelper.java common/mongodb/src/main/java/com/redhat/thermostat/gateway/common/mongodb/servlet/MongoHttpHandlerHelper.java services/jcmd/src/main/java/com/redhat/thermostat/gateway/service/jvm/jcmd/JcmdHttpHandler.java services/jvm-byteman/src/main/java/com/redhat/thermostat/gateway/service/jvm/byteman/JvmBytemanMetricsHttpHandler.java services/jvm-byteman/src/main/java/com/redhat/thermostat/gateway/service/jvm/byteman/JvmBytemanStatusHttpHandler.java services/jvm-compiler/src/main/java/com/redhat/thermostat/gateway/service/jvm/compiler/JvmCompilerHttpHandler.java services/jvm-cpu/src/main/java/com/redhat/thermostat/gateway/service/jvm/cpu/JvmCpuHttpHandler.java services/jvm-gc/src/main/java/com/redhat/thermostat/gateway/service/jvm/gc/http/JvmGcHttpHandler.java services/jvm-io/src/main/java/com/redhat/thermostat/gateway/service/jvm/io/JvmIoHttpHandler.java services/jvm-memory/src/main/java/com/redhat/thermostat/gateway/service/jvm/memory/JvmMemoryHttpHandler.java services/jvms/src/main/java/com/redhat/thermostat/gateway/service/jvms/http/JvmsHttpHandler.java services/system-cpu/src/main/java/com/redhat/thermostat/gateway/service/system/cpu/http/SystemInfoCPUHttpHandler.java services/system-memory/src/main/java/com/redhat/thermostat/gateway/service/system/memory/http/SystemMemoryHttpHandler.java services/system-network/src/main/java/com/redhat/thermostat/gateway/service/system/network/http/SystemNetworkHttpHandler.java services/systems/src/main/java/com/redhat/thermostat/gateway/service/systems/http/SystemsHttpHandler.java
diffstat 17 files changed, 516 insertions(+), 182 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/core/src/main/java/com/redhat/thermostat/gateway/common/db/Pair.java	Tue Oct 17 11:11:23 2017 +0200
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2012-2017 Red Hat, Inc.
+ *
+ * This file is part of Thermostat.
+ *
+ * Thermostat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Thermostat is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Thermostat; see the file COPYING.  If not see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Linking this code with other modules is making a combined work
+ * based on this code.  Thus, the terms and conditions of the GNU
+ * General Public License cover the whole combination.
+ *
+ * As a special exception, the copyright holders of this code give
+ * you permission to link this code with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also
+ * meet, for each linked independent module, the terms and conditions
+ * of the license of that module.  An independent module is a module
+ * which is not derived from or based on this code.  If you modify
+ * this code, you may extend this exception to your version of the
+ * library, but you are not obligated to do so.  If you do not wish
+ * to do so, delete this exception statement from your version.
+ */
+
+package com.redhat.thermostat.gateway.common.db;
+
+import java.util.Objects;
+
+/**
+ * A container that hold two values.
+ * <p>
+ * The values may be related or unrelated.
+ * <p>
+ * For most predictable results, the params should be immutable. If the value of
+ * {@link #hashCode()} is relevant, the two values must provide sane
+ * implementations of hashCode too.
+ *
+ * @param <F> the type of the first value
+ * @param <S> the type of the second value
+ */
+public class Pair<F, S> {
+
+    private final F first;
+    private final S second;
+
+    public Pair(F first, S second) {
+        this.first = first;
+        this.second = second;
+    }
+
+    public F getFirst() {
+        return first;
+    }
+
+    public S getSecond() {
+        return second;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof Pair)) {
+            return false;
+        }
+        Pair<?,?> other = (Pair<?,?>) obj;
+        return Objects.equals(first, other.first) && Objects.equals(second, other.second);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(first, second);
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/core/src/main/java/com/redhat/thermostat/gateway/common/db/servlet/AbstractHttpHandlerHelper.java	Tue Oct 17 11:11:23 2017 +0200
@@ -0,0 +1,216 @@
+/*
+ * Copyright 2012-2017 Red Hat, Inc.
+ *
+ * This file is part of Thermostat.
+ *
+ * Thermostat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Thermostat is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Thermostat; see the file COPYING.  If not see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Linking this code with other modules is making a combined work
+ * based on this code.  Thus, the terms and conditions of the GNU
+ * General Public License cover the whole combination.
+ *
+ * As a special exception, the copyright holders of this code give
+ * you permission to link this code with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also
+ * meet, for each linked independent module, the terms and conditions
+ * of the license of that module.  An independent module is a module
+ * which is not derived from or based on this code.  If you modify
+ * this code, you may extend this exception to your version of the
+ * library, but you are not obligated to do so.  If you do not wish
+ * to do so, delete this exception statement from your version.
+ */
+
+package com.redhat.thermostat.gateway.common.db.servlet;
+
+import com.redhat.thermostat.gateway.common.core.auth.RealmAuthorizer;
+import com.redhat.thermostat.gateway.common.core.servlet.CommonQueryParams;
+import com.redhat.thermostat.gateway.common.db.Pair;
+import com.redhat.thermostat.gateway.common.util.HttpResponseExceptionHandler;
+import com.redhat.thermostat.gateway.common.util.ServiceException;
+import java.io.IOException;
+import java.util.List;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Response;
+
+public abstract class AbstractHttpHandlerHelper implements HttpHandlerHelper {
+
+    private final String collectionName;
+    private final HttpResponseExceptionHandler exceptionHandler = new HttpResponseExceptionHandler();
+
+    public AbstractHttpHandlerHelper(String collectionName) {
+        this.collectionName = collectionName;
+        exceptionHandler
+                .add(UnsupportedOperationException.class, ServiceException.MALFORMED_CLIENT_REQUEST)
+                .add(ClassCastException.class, ServiceException.EXPECTED_JSON_ARRAY)
+                .add(IOException.class, ServiceException.CANNOT_QUERY_REALMS_PROPERTY)
+                .add(NullPointerException.class, ServiceException.UNEXPECTED_ERROR);
+        addAllImplSpecificHandlers();
+    }
+
+    protected abstract List<Pair<Class<? extends Exception>, ServiceException>> getImplSpecificHandlers();
+
+    private void addAllImplSpecificHandlers() {
+        for (Pair<Class<? extends Exception>, ServiceException> pair : getImplSpecificHandlers()) {
+            exceptionHandler.add(pair.getFirst(), pair.getSecond());
+        }
+    }
+
+    protected String getCollectionName() {
+        return collectionName;
+    }
+
+    @Override
+    public final Response handleGetWithSystemID(HttpServletRequest httpServletRequest,
+            ServletContext context, String systemId, CommonQueryParams params) {
+        return handleGet(httpServletRequest, context, andSystemIdQuery(params.getQueries(), systemId), params);
+    }
+
+    @Override
+    public final Response handleGetWithJvmID(HttpServletRequest httpServletRequest,
+            ServletContext context, String systemId, String jvmId, CommonQueryParams params) {
+        return handleGet(httpServletRequest, context, andSystemIdJvmIdQuery(params.getQueries(), systemId, jvmId), params);
+    }
+
+    @Override
+    public final Response handleGet(HttpServletRequest httpServletRequest,
+            ServletContext context, CommonQueryParams params) {
+        return handleGet(httpServletRequest, context, params.getQueries(), params);
+    }
+
+    @Override
+    public final Response handleGet(HttpServletRequest httpServletRequest,
+            ServletContext context, String queries, CommonQueryParams params) {
+
+        try {
+            return handleGetImpl(getRealmAuthorizer(httpServletRequest), httpServletRequest, context, queries, params);
+        } catch (Exception e) {
+            return exceptionHandler.generateResponseForException(e);
+        }
+    }
+
+    protected abstract Response handleGetImpl(RealmAuthorizer realmAuthorizer, 
+            HttpServletRequest httpServletRequest, ServletContext context, 
+            String queries, CommonQueryParams params) throws Exception;
+
+    /*
+     *  HTTP POST handling
+     */
+    @Override
+    public final Response handlePostWithSystemID(HttpServletRequest httpServletRequest,
+            ServletContext context, String systemId, boolean returnMetadata, String body) {
+        return handlePost(httpServletRequest, context, systemId, null, returnMetadata, body);
+    }
+
+    @Override
+    public final Response handlePostWithJvmID(HttpServletRequest httpServletRequest,
+            ServletContext context, String systemId, String jvmId, boolean returnMetadata, String body) {
+        return handlePost(httpServletRequest, context, systemId, jvmId, returnMetadata, body);
+    }
+
+    /*
+     *  HTTP PUT handling
+     */
+    @Override
+    public final Response handlePutWithSystemId(HttpServletRequest httpServletRequest,
+            ServletContext context, String systemId, String queries, boolean metadata, String body) {
+        return handlePut(httpServletRequest, context, systemId, null, queries, metadata, body);
+    }
+
+    @Override
+    public final Response handlePutWithJvmId(HttpServletRequest httpServletRequest,
+            ServletContext context, String systemId, String jvmId, String queries, boolean metadata, String body) {
+        return handlePut(httpServletRequest, context, systemId, jvmId, queries, metadata, body);
+    }
+
+    @Override
+    public final Response handlePut(HttpServletRequest httpServletRequest, ServletContext context,
+            String systemId, String jvmId, String queries, boolean returnMetadata, String body) {
+
+        try {
+            return handlePutImpl(getRealmAuthorizer(httpServletRequest), context, systemId, jvmId,
+                    queries, returnMetadata, body);
+        } catch (Exception e) {
+            return exceptionHandler.generateResponseForException(e);
+        }
+    }
+
+    protected abstract Response handlePutImpl(RealmAuthorizer realmAuthorizer,
+            ServletContext context, String systemId, String jvmId, String queries,
+            boolean returnMetadata, String body) throws Exception;
+
+    @Override
+    public final Response handlePost(HttpServletRequest httpServletRequest,
+            ServletContext context, String systemId, String jvmId,
+            boolean returnMetadata, String body) {
+
+        try {
+            return handlePostImpl(getRealmAuthorizer(httpServletRequest),
+                    context, systemId, jvmId, returnMetadata, body);
+        } catch (Exception e) {
+            return exceptionHandler.generateResponseForException(e);
+        }
+    }
+
+    /*
+     *  HTTP DELETE handling
+     */
+    @Override
+    public final Response handleDeleteWithSystemID(HttpServletRequest httpServletRequest,
+            ServletContext context, String systemId, String queries, boolean returnMetadata) {
+        return handleDelete(httpServletRequest, context, andSystemIdQuery(queries, systemId), returnMetadata);
+    }
+
+    @Override
+    public final Response handleDeleteWithJvmID(HttpServletRequest httpServletRequest,
+            ServletContext context, String systemId, String jvmId, String queries, boolean returnMetadata) {
+        return handleDelete(httpServletRequest, context,
+                andSystemIdJvmIdQuery(queries, systemId, jvmId), returnMetadata);
+    }
+
+    protected abstract Response handlePostImpl(RealmAuthorizer realmAuthorizer,
+            ServletContext context, String systemId, String jvmId,
+            boolean returnMetadata, String body) throws Exception;
+
+    @Override
+    public final Response handleDelete(HttpServletRequest httpServletRequest,
+            ServletContext context, String queries, boolean returnMetadata) {
+        try {
+            return handleDeleteImpl(getRealmAuthorizer(httpServletRequest), context, queries, returnMetadata);
+        } catch (Exception e) {
+            return exceptionHandler.generateResponseForException(e);
+        }
+    }
+
+    protected abstract Response handleDeleteImpl(RealmAuthorizer realmAuthorizer,
+            ServletContext context, String queries, boolean returnMetadata) throws Exception;
+
+    /* Utility methods we do not want to expose to public API */
+    protected abstract String andSystemIdQuery(final String originalQuery,
+            final String systemId);
+
+    protected abstract String andSystemIdJvmIdQuery(final String originalQuery,
+            final String systemId, final String jvmId);
+
+    protected final boolean isNullOrEmpty(final String s) {
+        return s == null || s.isEmpty();
+    }
+
+    private RealmAuthorizer getRealmAuthorizer(HttpServletRequest httpServletRequest) {
+        return (RealmAuthorizer) httpServletRequest.getAttribute(RealmAuthorizer.class.getName());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/core/src/main/java/com/redhat/thermostat/gateway/common/db/servlet/HttpHandlerHelper.java	Tue Oct 17 11:11:23 2017 +0200
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2012-2017 Red Hat, Inc.
+ *
+ * This file is part of Thermostat.
+ *
+ * Thermostat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Thermostat is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Thermostat; see the file COPYING.  If not see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Linking this code with other modules is making a combined work
+ * based on this code.  Thus, the terms and conditions of the GNU
+ * General Public License cover the whole combination.
+ *
+ * As a special exception, the copyright holders of this code give
+ * you permission to link this code with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also
+ * meet, for each linked independent module, the terms and conditions
+ * of the license of that module.  An independent module is a module
+ * which is not derived from or based on this code.  If you modify
+ * this code, you may extend this exception to your version of the
+ * library, but you are not obligated to do so.  If you do not wish
+ * to do so, delete this exception statement from your version.
+ */
+
+package com.redhat.thermostat.gateway.common.db.servlet;
+
+import com.redhat.thermostat.gateway.common.core.servlet.CommonQueryParams;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Response;
+
+public interface HttpHandlerHelper {
+
+    /*
+     *  HTTP DELETE handling
+     */
+    Response handleDelete(HttpServletRequest httpServletRequest,
+            ServletContext context, String queries, boolean returnMetadata);
+
+    Response handleDeleteWithJvmID(HttpServletRequest httpServletRequest,
+            ServletContext context, String systemId, String jvmId, String queries, boolean returnMetadata);
+
+    Response handleDeleteWithSystemID(HttpServletRequest httpServletRequest,
+            ServletContext context, String systemId, String queries, boolean returnMetadata);
+
+    /*
+     *  HTTP GET handling
+     */
+    Response handleGetWithSystemID(HttpServletRequest httpServletRequest,
+            ServletContext context, String systemId, CommonQueryParams params);
+
+    Response handleGetWithJvmID(HttpServletRequest httpServletRequest,
+            ServletContext context, String systemId, String jvmId, CommonQueryParams params);
+
+    Response handleGet(HttpServletRequest httpServletRequest,
+            ServletContext context, CommonQueryParams params);
+
+    Response handleGet(HttpServletRequest httpServletRequest,
+            ServletContext context, String queries, CommonQueryParams params);
+
+    /*
+     *  HTTP POST handling
+     */
+    Response handlePost(HttpServletRequest httpServletRequest,
+            ServletContext context, String systemId, String jvmId, boolean returnMetadata, String body);
+
+    Response handlePostWithJvmID(HttpServletRequest httpServletRequest,
+            ServletContext context, String systemId, String jvmId, boolean returnMetadata, String body);
+
+    Response handlePostWithSystemID(HttpServletRequest httpServletRequest,
+            ServletContext context, String systemId, boolean returnMetadata, String body);
+
+    /*
+     *  HTTP PUT handling
+     */
+    Response handlePut(HttpServletRequest httpServletRequest,
+            ServletContext context, String systemId, String jvmId, String queries, boolean returnMetadata, String body);
+
+    Response handlePutWithJvmId(HttpServletRequest httpServletRequest,
+            ServletContext context, String systemId, String jvmId, String queries, boolean metadata, String body);
+
+    Response handlePutWithSystemId(HttpServletRequest httpServletRequest,
+            ServletContext context, String systemId, String queries, boolean metadata, String body);
+}
--- a/common/mongodb/src/main/java/com/redhat/thermostat/gateway/common/mongodb/servlet/MongoHttpHandlerHelper.java	Tue Oct 17 08:49:58 2017 -0400
+++ b/common/mongodb/src/main/java/com/redhat/thermostat/gateway/common/mongodb/servlet/MongoHttpHandlerHelper.java	Tue Oct 17 11:11:23 2017 +0200
@@ -36,13 +36,8 @@
 
 package com.redhat.thermostat.gateway.common.mongodb.servlet;
 
-import static com.redhat.thermostat.gateway.common.util.ServiceException.CANNOT_QUERY_REALMS_PROPERTY;
 import static com.redhat.thermostat.gateway.common.util.ServiceException.DATABASE_UNAVAILABLE;
-import static com.redhat.thermostat.gateway.common.util.ServiceException.EXPECTED_JSON_ARRAY;
 import static com.redhat.thermostat.gateway.common.util.ServiceException.MALFORMED_CLIENT_REQUEST;
-import static com.redhat.thermostat.gateway.common.util.ServiceException.UNEXPECTED_ERROR;
-
-import java.io.IOException;
 
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
@@ -55,6 +50,8 @@
 import com.mongodb.MongoWriteException;
 import com.redhat.thermostat.gateway.common.core.auth.RealmAuthorizer;
 import com.redhat.thermostat.gateway.common.core.servlet.CommonQueryParams;
+import com.redhat.thermostat.gateway.common.db.Pair;
+import com.redhat.thermostat.gateway.common.db.servlet.AbstractHttpHandlerHelper;
 import com.redhat.thermostat.gateway.common.mongodb.ThermostatFields;
 import com.redhat.thermostat.gateway.common.mongodb.ThermostatMongoStorage;
 import com.redhat.thermostat.gateway.common.mongodb.executor.MongoDataResultContainer;
@@ -62,222 +59,152 @@
 import com.redhat.thermostat.gateway.common.mongodb.response.MongoMetaDataGenerator;
 import com.redhat.thermostat.gateway.common.mongodb.response.MongoMetaDataResponseBuilder;
 import com.redhat.thermostat.gateway.common.mongodb.response.MongoResponseBuilder;
-import com.redhat.thermostat.gateway.common.util.HttpResponseExceptionHandler;
-
+import com.redhat.thermostat.gateway.common.util.ServiceException;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
-public class MongoHttpHandlerHelper {
+public class MongoHttpHandlerHelper extends AbstractHttpHandlerHelper {
 
-    private final String collectionName;
     private final MongoExecutor mongoExecutor = new MongoExecutor();
-    private final HttpResponseExceptionHandler exceptionHandler = new HttpResponseExceptionHandler();
 
     public MongoHttpHandlerHelper(String collectionName) {
-        this.collectionName = collectionName;
-        exceptionHandler.add(MongoWriteException.class, MALFORMED_CLIENT_REQUEST)
-                .add(JsonParseException.class, MALFORMED_CLIENT_REQUEST)
-                .add(UnsupportedOperationException.class, MALFORMED_CLIENT_REQUEST)
-                .add(ClassCastException.class, EXPECTED_JSON_ARRAY)
-                .add(MongoTimeoutException.class, DATABASE_UNAVAILABLE)
-                .add(IOException.class, CANNOT_QUERY_REALMS_PROPERTY)
-                .add(NullPointerException.class, UNEXPECTED_ERROR);
+        super(collectionName);
     }
 
-    /*
-     *  HTTP GET handling
-     */
+    @Override
+    protected List<Pair<Class<? extends Exception>, ServiceException>> getImplSpecificHandlers() {
+        List<Pair<Class<? extends Exception>, ServiceException>> result = new ArrayList<>();
 
-    public Response handleGetWithSystemID(HttpServletRequest httpServletRequest, ServletContext context, String systemId, CommonQueryParams params) {
-        return handleGet(httpServletRequest, context, andSystemIdQuery(params.getQueries(), systemId), params);
-    }
-
-    public Response handleGetWithJvmID(HttpServletRequest httpServletRequest, ServletContext context, String systemId, String jvmId, CommonQueryParams params) {
-        return handleGet(httpServletRequest, context, andSystemIdJvmIdQuery(params.getQueries(), systemId, jvmId), params);
-    }
-
-    public Response handleGet(HttpServletRequest httpServletRequest, ServletContext context, CommonQueryParams params) {
-        return handleGet(httpServletRequest, context, params.getQueries(), params);
+        result.add(new Pair<Class<? extends Exception>, ServiceException>(MongoWriteException.class, MALFORMED_CLIENT_REQUEST));
+        result.add(new Pair<Class<? extends Exception>, ServiceException>(JsonParseException.class, MALFORMED_CLIENT_REQUEST));
+        result.add(new Pair<Class<? extends Exception>, ServiceException>(MongoTimeoutException.class, DATABASE_UNAVAILABLE));
+        return result;
     }
 
     /*
      * originalQueries contains only query info from the client's original request argument. queries contains this info,
      * as well as added JVM/SYS ids built by andSystemIdJvmIdQuery(...).
      */
-    public Response handleGet(HttpServletRequest httpServletRequest, ServletContext context, String queries, CommonQueryParams params) {
-        try {
-            RealmAuthorizer realmAuthorizer = (RealmAuthorizer) httpServletRequest.getAttribute(RealmAuthorizer.class.getName());
-
-            if (realmAuthorizer.readable()) {
-                ThermostatMongoStorage storage = (ThermostatMongoStorage) context.getAttribute(ServletContextConstants.MONGODB_CLIENT_ATTRIBUTE);
-
-                MongoDataResultContainer execResult = mongoExecutor.execGetRequest(
-                        storage.getDatabase().getCollection(collectionName), queries, params, realmAuthorizer.getReadableRealms());
-
-                MongoResponseBuilder.Builder response = new MongoResponseBuilder.Builder();
-                response.addQueryDocuments(execResult.getQueryDataResult());
-
-                if (params.isReturnMetadata()) {
-
-                    Map<String, String> paramArgs = params.buildParams();
+    @Override
+    public Response handleGetImpl(RealmAuthorizer realmAuthorizer, HttpServletRequest httpServletRequest,
+            ServletContext context, String queries, CommonQueryParams params) throws Exception {
+        if (realmAuthorizer.readable()) {
+            ThermostatMongoStorage storage = (ThermostatMongoStorage) context.getAttribute(ServletContextConstants.MONGODB_CLIENT_ATTRIBUTE);
 
-                    String baseUrl = httpServletRequest.getRequestURL().toString();
-                    MongoMetaDataResponseBuilder.MetaBuilder metaDataResponse = new MongoMetaDataResponseBuilder.MetaBuilder();
-                    MongoMetaDataGenerator metaDataGenerator = new MongoMetaDataGenerator(params, paramArgs, execResult, baseUrl);
-
-                    metaDataGenerator.setDocAndPayloadCount(metaDataResponse);
-                    metaDataGenerator.setPrev(metaDataResponse);
-                    metaDataGenerator.setNext(metaDataResponse);
+            MongoDataResultContainer execResult = mongoExecutor.execGetRequest(
+                    storage.getDatabase().getCollection(getCollectionName()), queries, params, realmAuthorizer.getReadableRealms());
 
-                    response.addMetaData(metaDataResponse.build());
-                }
-                return Response.status(Response.Status.OK).entity(response.build()).build();
-            } else {
-                return Response.status(Response.Status.FORBIDDEN).build();
-            }
-        } catch (Exception e) {
-            return exceptionHandler.generateResponseForException(e);
-        }
-    }
+            MongoResponseBuilder.Builder responseBuilder = new MongoResponseBuilder.Builder();
+            responseBuilder.addQueryDocuments(execResult.getQueryDataResult());
+
+            if (params.isReturnMetadata()) {
 
-    /*
-     *  HTTP PUT handling
-     */
-
-    public Response handlePutWithSystemId(HttpServletRequest httpServletRequest, ServletContext context, String systemId, String queries, boolean metadata, String body) {
-        return handlePut(httpServletRequest, context, systemId, null, queries, metadata, body);
-    }
+                Map<String, String> paramArgs = params.buildParams();
 
-    public Response handlePutWithJvmId(HttpServletRequest httpServletRequest, ServletContext context, String systemId, String jvmId, String queries, boolean metadata, String body) {
-        return handlePut(httpServletRequest, context, systemId, jvmId, queries, metadata, body);
-    }
-
-    public Response handlePut(HttpServletRequest httpServletRequest, ServletContext context, String queries, boolean metadata, String body) {
-        return handlePut(httpServletRequest, context, null, null, queries, metadata, body);
-    }
-
-    public Response handlePut(HttpServletRequest httpServletRequest, ServletContext context, String systemId, String jvmId, String queries, boolean returnMetadata, String body) {
-        try {
-            RealmAuthorizer realmAuthorizer = (RealmAuthorizer) httpServletRequest.getAttribute(RealmAuthorizer.class.getName());
+                String baseUrl = httpServletRequest.getRequestURL().toString();
+                MongoMetaDataResponseBuilder.MetaBuilder metaDataResponse = new MongoMetaDataResponseBuilder.MetaBuilder();
+                MongoMetaDataGenerator metaDataGenerator = new MongoMetaDataGenerator(params, paramArgs, execResult, baseUrl);
 
-            if (realmAuthorizer.updatable()) {
-                ThermostatMongoStorage storage = (ThermostatMongoStorage) context.getAttribute(ServletContextConstants.MONGODB_CLIENT_ATTRIBUTE);
-
-                MongoDataResultContainer execResult = mongoExecutor.execPutRequest(storage.getDatabase().getCollection(collectionName), body, queries, realmAuthorizer.getUpdatableRealms(), systemId, jvmId);
-
-                MongoResponseBuilder.Builder response = new MongoResponseBuilder.Builder();
-                if (returnMetadata) {
-                    MongoMetaDataResponseBuilder.MetaBuilder metadataResponse = new MongoMetaDataResponseBuilder.MetaBuilder();
-                    metadataResponse.matchCount(execResult.getPutReqMatches());
+                metaDataGenerator.setDocAndPayloadCount(metaDataResponse);
+                metaDataGenerator.setPrev(metaDataResponse);
+                metaDataGenerator.setNext(metaDataResponse);
 
-                    response.addMetaData(metadataResponse.build());
-                }
-
-                return Response.status(Response.Status.OK).entity(response.build()).build();
-            } else {
-                return Response.status(Response.Status.FORBIDDEN).build();
+                responseBuilder.addMetaData(metaDataResponse.build());
             }
-        } catch (Exception e) {
-            return exceptionHandler.generateResponseForException(e);
+            return okResponse(responseBuilder);
+        } else {
+            return errorResponse();
         }
     }
 
-    /*
-     *  HTTP POST handling
-     */
-
-    public Response handlePostWithSystemID(HttpServletRequest httpServletRequest, ServletContext context, String systemId, boolean returnMetadata, String body) {
-        return handlePost(httpServletRequest, context, systemId, null, returnMetadata, body);
-    }
+    @Override
+    public Response handlePutImpl(RealmAuthorizer realmAuthorizer, ServletContext context,
+            String systemId, String jvmId, String queries, boolean returnMetadata, String body) throws Exception {
+        if (realmAuthorizer.updatable()) {
+            ThermostatMongoStorage storage = (ThermostatMongoStorage) context.getAttribute(ServletContextConstants.MONGODB_CLIENT_ATTRIBUTE);
 
-    public Response handlePostWithJvmID(HttpServletRequest httpServletRequest, ServletContext context, String systemId, String jvmId, boolean returnMetadata, String body) {
-        return handlePost(httpServletRequest, context, systemId, jvmId, returnMetadata, body);
-    }
-
-    public Response handlePost(HttpServletRequest httpServletRequest, ServletContext context, boolean returnMetadata, String body) {
-        return handlePost(httpServletRequest, context, null, null, returnMetadata, body);
-    }
-
-    public Response handlePost(HttpServletRequest httpServletRequest, ServletContext context, String systemId, String jvmId, boolean returnMetadata, String body) {
-        try {
-            RealmAuthorizer realmAuthorizer = (RealmAuthorizer) httpServletRequest.getAttribute(RealmAuthorizer.class.getName());
+            MongoDataResultContainer execResult = mongoExecutor.execPutRequest(storage.getDatabase().getCollection(getCollectionName()), body, queries, realmAuthorizer.getUpdatableRealms(), systemId, jvmId);
 
-            if (realmAuthorizer.writable()) {
-                ThermostatMongoStorage storage = (ThermostatMongoStorage) context.getAttribute(ServletContextConstants.MONGODB_CLIENT_ATTRIBUTE);
-
-                MongoDataResultContainer execResult = mongoExecutor.execPostRequest(storage.getDatabase().getCollection(collectionName, DBObject.class), body, realmAuthorizer.getWritableRealms(), systemId, jvmId);
-                MongoResponseBuilder.Builder response = new MongoResponseBuilder.Builder();
-
-                if (returnMetadata) {
-                    MongoMetaDataResponseBuilder.MetaBuilder metadataResponse = new MongoMetaDataResponseBuilder.MetaBuilder();
-                    metadataResponse.insertCount(execResult.getPostReqInsertions());
+            MongoResponseBuilder.Builder responseBuilder = new MongoResponseBuilder.Builder();
+            if (returnMetadata) {
+                MongoMetaDataResponseBuilder.MetaBuilder metadataResponse = new MongoMetaDataResponseBuilder.MetaBuilder();
+                metadataResponse.matchCount(execResult.getPutReqMatches());
 
-                    response.addMetaData(metadataResponse.build());
-                }
+                responseBuilder.addMetaData(metadataResponse.build());
+            }
 
-                return Response.status(Response.Status.OK).entity(response.build()).build();
-            } else {
-                return Response.status(Response.Status.FORBIDDEN).build();
-            }
-        } catch (Exception e) {
-            return exceptionHandler.generateResponseForException(e);
+            return okResponse(responseBuilder);
+        } else {
+            return errorResponse();
         }
     }
 
-    /*
-     *  HTTP DELETE handling
-     */
+    @Override
+    public Response handlePostImpl(RealmAuthorizer realmAuthorizer, ServletContext context,
+            String systemId, String jvmId, boolean returnMetadata, String body) throws Exception {
+        if (realmAuthorizer.writable()) {
+            ThermostatMongoStorage storage = (ThermostatMongoStorage) context.getAttribute(ServletContextConstants.MONGODB_CLIENT_ATTRIBUTE);
+
+            MongoDataResultContainer execResult = mongoExecutor.execPostRequest(storage.getDatabase().getCollection(getCollectionName(), DBObject.class), body, realmAuthorizer.getWritableRealms(), systemId, jvmId);
+            MongoResponseBuilder.Builder responseBuilder = new MongoResponseBuilder.Builder();
 
-    public Response handleDeleteWithSystemID(HttpServletRequest httpServletRequest, ServletContext context, String systemId, String queries, boolean returnMetadata) {
-        return handleDelete(httpServletRequest, context, andSystemIdQuery(queries, systemId), returnMetadata);
-    }
+            if (returnMetadata) {
+                MongoMetaDataResponseBuilder.MetaBuilder metadataResponse = new MongoMetaDataResponseBuilder.MetaBuilder();
+                metadataResponse.insertCount(execResult.getPostReqInsertions());
 
-    public Response handleDeleteWithJvmID(HttpServletRequest httpServletRequest, ServletContext context, String systemId, String jvmId, String queries, boolean returnMetadata) {
-        return handleDelete(httpServletRequest, context, andSystemIdJvmIdQuery(queries, systemId, jvmId), returnMetadata);
+                responseBuilder.addMetaData(metadataResponse.build());
+            }
+
+            return okResponse(responseBuilder);
+        } else {
+            return errorResponse();
+        }
     }
 
-    public Response handleDelete(HttpServletRequest httpServletRequest, ServletContext context, String queries, boolean returnMetadata) {
-        try {
-            RealmAuthorizer realmAuthorizer = (RealmAuthorizer) httpServletRequest.getAttribute(RealmAuthorizer.class.getName());
+    @Override
+    public Response handleDeleteImpl(RealmAuthorizer realmAuthorizer, ServletContext context,
+            String queries, boolean returnMetadata) throws Exception {
+        if (realmAuthorizer.deletable()) {
+            ThermostatMongoStorage storage = (ThermostatMongoStorage) context.getAttribute(ServletContextConstants.MONGODB_CLIENT_ATTRIBUTE);
 
-            if (realmAuthorizer.deletable()) {
-                ThermostatMongoStorage storage = (ThermostatMongoStorage) context.getAttribute(ServletContextConstants.MONGODB_CLIENT_ATTRIBUTE);
-
-                MongoDataResultContainer execResult = mongoExecutor.execDeleteRequest(storage.getDatabase().getCollection(collectionName), queries, realmAuthorizer.getDeletableRealms());
+            MongoDataResultContainer execResult = mongoExecutor.execDeleteRequest(storage.getDatabase().getCollection(getCollectionName()), queries, realmAuthorizer.getDeletableRealms());
 
-                MongoResponseBuilder.Builder response = new MongoResponseBuilder.Builder();
-                if (returnMetadata) {
-                    MongoMetaDataResponseBuilder.MetaBuilder metadataResponse = new MongoMetaDataResponseBuilder.MetaBuilder();
-                    metadataResponse.matchCount(execResult.getDeleteReqMatches());
+            MongoResponseBuilder.Builder responseBuilder = new MongoResponseBuilder.Builder();
+            if (returnMetadata) {
+                MongoMetaDataResponseBuilder.MetaBuilder metadataResponse = new MongoMetaDataResponseBuilder.MetaBuilder();
+                metadataResponse.matchCount(execResult.getDeleteReqMatches());
 
-                    response.addMetaData(metadataResponse.build());
-                }
+                responseBuilder.addMetaData(metadataResponse.build());
+            }
 
-                return Response.status(Response.Status.OK).entity(response.build()).build();
-            } else {
-                return Response.status(Response.Status.FORBIDDEN).build();
-            }
-        } catch (Exception e) {
-            return exceptionHandler.generateResponseForException(e);
+            return okResponse(responseBuilder);
+        } else {
+            return errorResponse();
         }
     }
 
     /*
      * Utility code
      */
-
-    private String andSystemIdQuery(final String originalQuery, final String systemId) {
+    @Override
+    protected String andSystemIdQuery(final String originalQuery, final String systemId) {
         final String sysQuery = ThermostatFields.SYSTEM_ID + "==\"" + systemId + '"';
         return isNullOrEmpty(originalQuery) ? sysQuery : sysQuery + ',' + originalQuery;
     }
 
-    private String andSystemIdJvmIdQuery(final String originalQuery, final String systemId, final String jvmId) {
+    @Override
+    protected String andSystemIdJvmIdQuery(final String originalQuery, final String systemId, final String jvmId) {
         final String jvmQuery = ThermostatFields.JVM_ID + "==\"" + jvmId + '"';
         final String sysJvmQuery = jvmQuery + (isNullOrEmpty(systemId) ? "" : ',' + ThermostatFields.SYSTEM_ID + "==\"" + systemId + '"');
         return isNullOrEmpty(originalQuery) ? sysJvmQuery : sysJvmQuery + ',' + originalQuery;
     }
 
-    private final boolean isNullOrEmpty(final String s) {
-        return s == null || s.isEmpty();
+    private Response errorResponse() {
+        return Response.status(Response.Status.FORBIDDEN).build();
     }
 
+    private Response okResponse(MongoResponseBuilder.Builder responseBuilder) {
+        return Response.status(Response.Status.OK).entity(responseBuilder.build()).build();
+    }
 }
--- a/services/jcmd/src/main/java/com/redhat/thermostat/gateway/service/jvm/jcmd/JcmdHttpHandler.java	Tue Oct 17 08:49:58 2017 -0400
+++ b/services/jcmd/src/main/java/com/redhat/thermostat/gateway/service/jvm/jcmd/JcmdHttpHandler.java	Tue Oct 17 11:11:23 2017 +0200
@@ -38,6 +38,7 @@
 
 import com.redhat.thermostat.gateway.common.core.servlet.CommonQueryParams;
 import com.redhat.thermostat.gateway.common.core.servlet.RequestParameters;
+import com.redhat.thermostat.gateway.common.db.servlet.HttpHandlerHelper;
 import com.redhat.thermostat.gateway.common.mongodb.servlet.MongoHttpHandlerHelper;
 
 import javax.servlet.ServletContext;
@@ -56,7 +57,7 @@
 @Path("/")
 public class JcmdHttpHandler {
     private static final String COLLECTION_NAME = "jcmd";
-    private final MongoHttpHandlerHelper metricsServiceHelper = new MongoHttpHandlerHelper(COLLECTION_NAME);
+    private final HttpHandlerHelper metricsServiceHelper = new MongoHttpHandlerHelper(COLLECTION_NAME);
 
     @POST
     @Path("/systems/{" + RequestParameters.SYSTEM_ID +"}/jvms/{" + RequestParameters.JVM_ID +"}")
--- a/services/jvm-byteman/src/main/java/com/redhat/thermostat/gateway/service/jvm/byteman/JvmBytemanMetricsHttpHandler.java	Tue Oct 17 08:49:58 2017 -0400
+++ b/services/jvm-byteman/src/main/java/com/redhat/thermostat/gateway/service/jvm/byteman/JvmBytemanMetricsHttpHandler.java	Tue Oct 17 11:11:23 2017 +0200
@@ -52,6 +52,7 @@
 import com.redhat.thermostat.gateway.common.core.model.OffsetParameter;
 import com.redhat.thermostat.gateway.common.core.servlet.CommonQueryParams;
 import com.redhat.thermostat.gateway.common.core.servlet.RequestParameters;
+import com.redhat.thermostat.gateway.common.db.servlet.HttpHandlerHelper;
 import com.redhat.thermostat.gateway.common.mongodb.servlet.MongoHttpHandlerHelper;
 
 @Path("/metrics")
@@ -59,7 +60,7 @@
 
     private static final String NO_SYSTEM_ID = null;
     private static final String BYTEMAN_METRICS_COLLECTION_NAME = "jvm-byteman-metrics";
-    private final MongoHttpHandlerHelper metricsServiceHelper = new MongoHttpHandlerHelper( BYTEMAN_METRICS_COLLECTION_NAME );
+    private final HttpHandlerHelper metricsServiceHelper = new MongoHttpHandlerHelper( BYTEMAN_METRICS_COLLECTION_NAME );
 
     @GET
     @Path("/jvms/{" + RequestParameters.JVM_ID +"}")
--- a/services/jvm-byteman/src/main/java/com/redhat/thermostat/gateway/service/jvm/byteman/JvmBytemanStatusHttpHandler.java	Tue Oct 17 08:49:58 2017 -0400
+++ b/services/jvm-byteman/src/main/java/com/redhat/thermostat/gateway/service/jvm/byteman/JvmBytemanStatusHttpHandler.java	Tue Oct 17 11:11:23 2017 +0200
@@ -39,11 +39,9 @@
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
 import javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
@@ -53,6 +51,7 @@
 
 import com.redhat.thermostat.gateway.common.core.servlet.CommonQueryParams;
 import com.redhat.thermostat.gateway.common.core.servlet.RequestParameters;
+import com.redhat.thermostat.gateway.common.db.servlet.HttpHandlerHelper;
 import com.redhat.thermostat.gateway.common.mongodb.servlet.MongoHttpHandlerHelper;
 
 @Path("/status")
@@ -63,7 +62,7 @@
     private static final String DESCENDING_TIMESTAMP_SORT = "-timeStamp";
     private static final String NO_QUERIES = null;
     private static final String NO_SYSTEM_ID = null;
-    private final MongoHttpHandlerHelper statusServiceHelper = new MongoHttpHandlerHelper( BYTEMAN_STATUS_COLLECTION_NAME );
+    private final HttpHandlerHelper statusServiceHelper = new MongoHttpHandlerHelper( BYTEMAN_STATUS_COLLECTION_NAME );
 
     @GET
     @Path("/jvms/{" + RequestParameters.JVM_ID +"}")
--- a/services/jvm-compiler/src/main/java/com/redhat/thermostat/gateway/service/jvm/compiler/JvmCompilerHttpHandler.java	Tue Oct 17 08:49:58 2017 -0400
+++ b/services/jvm-compiler/src/main/java/com/redhat/thermostat/gateway/service/jvm/compiler/JvmCompilerHttpHandler.java	Tue Oct 17 11:11:23 2017 +0200
@@ -54,13 +54,14 @@
 import com.redhat.thermostat.gateway.common.core.model.OffsetParameter;
 import com.redhat.thermostat.gateway.common.core.servlet.CommonQueryParams;
 import com.redhat.thermostat.gateway.common.core.servlet.RequestParameters;
+import com.redhat.thermostat.gateway.common.db.servlet.HttpHandlerHelper;
 import com.redhat.thermostat.gateway.common.mongodb.servlet.MongoHttpHandlerHelper;
 
 @Path("/")
 public class JvmCompilerHttpHandler {
     private static final String collectionName = "jvm-compiler";
 
-    private final MongoHttpHandlerHelper serviceHelper = new MongoHttpHandlerHelper(collectionName);
+    private final HttpHandlerHelper serviceHelper = new MongoHttpHandlerHelper(collectionName);
 
     @GET
     @Path("/jvms/{" + RequestParameters.JVM_ID + "}")
--- a/services/jvm-cpu/src/main/java/com/redhat/thermostat/gateway/service/jvm/cpu/JvmCpuHttpHandler.java	Tue Oct 17 08:49:58 2017 -0400
+++ b/services/jvm-cpu/src/main/java/com/redhat/thermostat/gateway/service/jvm/cpu/JvmCpuHttpHandler.java	Tue Oct 17 11:11:23 2017 +0200
@@ -55,12 +55,13 @@
 import com.redhat.thermostat.gateway.common.core.servlet.CommonQueryParams;
 import com.redhat.thermostat.gateway.common.mongodb.servlet.MongoHttpHandlerHelper;
 import com.redhat.thermostat.gateway.common.core.servlet.RequestParameters;
+import com.redhat.thermostat.gateway.common.db.servlet.HttpHandlerHelper;
 
 @Path("/")
 public class JvmCpuHttpHandler {
 
     private static final String collectionName = "jvm-cpu";
-    private final MongoHttpHandlerHelper serviceHelper = new MongoHttpHandlerHelper(collectionName);
+    private final HttpHandlerHelper serviceHelper = new MongoHttpHandlerHelper(collectionName);
 
     @GET
     @Path("/jvms/{" + RequestParameters.JVM_ID + "}")
--- a/services/jvm-gc/src/main/java/com/redhat/thermostat/gateway/service/jvm/gc/http/JvmGcHttpHandler.java	Tue Oct 17 08:49:58 2017 -0400
+++ b/services/jvm-gc/src/main/java/com/redhat/thermostat/gateway/service/jvm/gc/http/JvmGcHttpHandler.java	Tue Oct 17 11:11:23 2017 +0200
@@ -57,6 +57,7 @@
 import com.redhat.thermostat.gateway.common.core.servlet.CommonQueryParams;
 import com.redhat.thermostat.gateway.common.mongodb.ThermostatMongoStorage;
 import com.redhat.thermostat.gateway.common.core.servlet.RequestParameters;
+import com.redhat.thermostat.gateway.common.db.servlet.HttpHandlerHelper;
 import com.redhat.thermostat.gateway.common.mongodb.servlet.MongoHttpHandlerHelper;
 import com.redhat.thermostat.gateway.common.mongodb.servlet.ServletContextConstants;
 import com.redhat.thermostat.gateway.service.jvm.gc.mongo.JvmGcMongoStorageHandler;
@@ -67,7 +68,7 @@
 
     private static final String collectionName = "jvm-gc";
     private final JvmGcMongoStorageHandler mongoStorageHandler = new JvmGcMongoStorageHandler();
-    private final MongoHttpHandlerHelper serviceHelper = new MongoHttpHandlerHelper( collectionName );
+    private final HttpHandlerHelper serviceHelper = new MongoHttpHandlerHelper( collectionName );
 
     @GET
     @Path("/jvms/{" + RequestParameters.JVM_ID +"}")
--- a/services/jvm-io/src/main/java/com/redhat/thermostat/gateway/service/jvm/io/JvmIoHttpHandler.java	Tue Oct 17 08:49:58 2017 -0400
+++ b/services/jvm-io/src/main/java/com/redhat/thermostat/gateway/service/jvm/io/JvmIoHttpHandler.java	Tue Oct 17 11:11:23 2017 +0200
@@ -55,12 +55,13 @@
 import com.redhat.thermostat.gateway.common.core.model.OffsetParameter;
 import com.redhat.thermostat.gateway.common.core.servlet.CommonQueryParams;
 import com.redhat.thermostat.gateway.common.core.servlet.RequestParameters;
+import com.redhat.thermostat.gateway.common.db.servlet.HttpHandlerHelper;
 import com.redhat.thermostat.gateway.common.mongodb.servlet.MongoHttpHandlerHelper;
 
 @Path("/")
 public class JvmIoHttpHandler {
     private static final String collectionName = "jvm-io";
-    private final MongoHttpHandlerHelper serviceHelper = new MongoHttpHandlerHelper( collectionName );
+    private final HttpHandlerHelper serviceHelper = new MongoHttpHandlerHelper( collectionName );
 
     @GET
     @Path("/jvms/{" + RequestParameters.JVM_ID +"}")
--- a/services/jvm-memory/src/main/java/com/redhat/thermostat/gateway/service/jvm/memory/JvmMemoryHttpHandler.java	Tue Oct 17 08:49:58 2017 -0400
+++ b/services/jvm-memory/src/main/java/com/redhat/thermostat/gateway/service/jvm/memory/JvmMemoryHttpHandler.java	Tue Oct 17 11:11:23 2017 +0200
@@ -55,12 +55,13 @@
 import com.redhat.thermostat.gateway.common.core.model.OffsetParameter;
 import com.redhat.thermostat.gateway.common.core.servlet.CommonQueryParams;
 import com.redhat.thermostat.gateway.common.core.servlet.RequestParameters;
+import com.redhat.thermostat.gateway.common.db.servlet.HttpHandlerHelper;
 import com.redhat.thermostat.gateway.common.mongodb.servlet.MongoHttpHandlerHelper;
 
 @Path("/")
 public class JvmMemoryHttpHandler {
     private static final String collectionName = "jvm-memory";
-    private final MongoHttpHandlerHelper serviceHelper = new MongoHttpHandlerHelper( collectionName );
+    private final HttpHandlerHelper serviceHelper = new MongoHttpHandlerHelper( collectionName );
 
     @GET
     @Path("/jvms/{" + RequestParameters.JVM_ID +"}")
--- a/services/jvms/src/main/java/com/redhat/thermostat/gateway/service/jvms/http/JvmsHttpHandler.java	Tue Oct 17 08:49:58 2017 -0400
+++ b/services/jvms/src/main/java/com/redhat/thermostat/gateway/service/jvms/http/JvmsHttpHandler.java	Tue Oct 17 11:11:23 2017 +0200
@@ -65,6 +65,7 @@
 import com.redhat.thermostat.gateway.common.core.model.LimitParameter;
 import com.redhat.thermostat.gateway.common.core.model.OffsetParameter;
 import com.redhat.thermostat.gateway.common.core.servlet.RequestParameters;
+import com.redhat.thermostat.gateway.common.db.servlet.HttpHandlerHelper;
 import com.redhat.thermostat.gateway.common.mongodb.ThermostatMongoStorage;
 import com.redhat.thermostat.gateway.common.mongodb.servlet.ServletContextConstants;
 import com.redhat.thermostat.gateway.common.mongodb.servlet.MongoHttpHandlerHelper;
@@ -76,7 +77,7 @@
 public class JvmsHttpHandler {
     private static final String collectionName = "jvm-info";
     private final JvmInfoMongoStorageHandler mongoStorageHandler = new JvmInfoMongoStorageHandler();
-    private final MongoHttpHandlerHelper serviceHelper = new MongoHttpHandlerHelper( collectionName );
+    private final HttpHandlerHelper serviceHelper = new MongoHttpHandlerHelper( collectionName );
     private final HttpResponseExceptionHandler exceptionHandler = new HttpResponseExceptionHandler();
 
     public JvmsHttpHandler() {
--- a/services/system-cpu/src/main/java/com/redhat/thermostat/gateway/service/system/cpu/http/SystemInfoCPUHttpHandler.java	Tue Oct 17 08:49:58 2017 -0400
+++ b/services/system-cpu/src/main/java/com/redhat/thermostat/gateway/service/system/cpu/http/SystemInfoCPUHttpHandler.java	Tue Oct 17 11:11:23 2017 +0200
@@ -55,12 +55,13 @@
 import com.redhat.thermostat.gateway.common.core.model.OffsetParameter;
 import com.redhat.thermostat.gateway.common.core.servlet.CommonQueryParams;
 import com.redhat.thermostat.gateway.common.core.servlet.RequestParameters;
+import com.redhat.thermostat.gateway.common.db.servlet.HttpHandlerHelper;
 import com.redhat.thermostat.gateway.common.mongodb.servlet.MongoHttpHandlerHelper;
 
 @Path("/")
 public class SystemInfoCPUHttpHandler {
     private final String collectionName = "cpu-info";
-    private final MongoHttpHandlerHelper serviceHelper = new MongoHttpHandlerHelper( collectionName );
+    private final HttpHandlerHelper serviceHelper = new MongoHttpHandlerHelper( collectionName );
 
     @GET
     @Path("/systems/{" + RequestParameters.SYSTEM_ID +"}")
--- a/services/system-memory/src/main/java/com/redhat/thermostat/gateway/service/system/memory/http/SystemMemoryHttpHandler.java	Tue Oct 17 08:49:58 2017 -0400
+++ b/services/system-memory/src/main/java/com/redhat/thermostat/gateway/service/system/memory/http/SystemMemoryHttpHandler.java	Tue Oct 17 11:11:23 2017 +0200
@@ -49,19 +49,19 @@
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
 import com.redhat.thermostat.gateway.common.core.model.LimitParameter;
 import com.redhat.thermostat.gateway.common.core.model.OffsetParameter;
 import com.redhat.thermostat.gateway.common.core.servlet.CommonQueryParams;
 import com.redhat.thermostat.gateway.common.core.servlet.RequestParameters;
+import com.redhat.thermostat.gateway.common.db.servlet.HttpHandlerHelper;
 import com.redhat.thermostat.gateway.common.mongodb.servlet.MongoHttpHandlerHelper;
 
 @Path("/")
 public class SystemMemoryHttpHandler {
     private final String collectionName = "memory-info";
-    private final MongoHttpHandlerHelper serviceHelper = new MongoHttpHandlerHelper( collectionName );
+    private final HttpHandlerHelper serviceHelper = new MongoHttpHandlerHelper( collectionName );
 
     @GET
     @Path("/systems/{" + RequestParameters.SYSTEM_ID +"}")
--- a/services/system-network/src/main/java/com/redhat/thermostat/gateway/service/system/network/http/SystemNetworkHttpHandler.java	Tue Oct 17 08:49:58 2017 -0400
+++ b/services/system-network/src/main/java/com/redhat/thermostat/gateway/service/system/network/http/SystemNetworkHttpHandler.java	Tue Oct 17 11:11:23 2017 +0200
@@ -40,6 +40,7 @@
 import com.redhat.thermostat.gateway.common.core.model.OffsetParameter;
 import com.redhat.thermostat.gateway.common.core.servlet.CommonQueryParams;
 import com.redhat.thermostat.gateway.common.core.servlet.RequestParameters;
+import com.redhat.thermostat.gateway.common.db.servlet.HttpHandlerHelper;
 import com.redhat.thermostat.gateway.common.mongodb.servlet.MongoHttpHandlerHelper;
 
 import javax.servlet.ServletContext;
@@ -60,7 +61,7 @@
 @Path("/")
 public class SystemNetworkHttpHandler {
     private static final String collectionName = "network-info";
-    private final MongoHttpHandlerHelper serviceHelper = new MongoHttpHandlerHelper( collectionName );
+    private final HttpHandlerHelper serviceHelper = new MongoHttpHandlerHelper( collectionName );
 
     @GET
     @Path("/systems/{" + RequestParameters.SYSTEM_ID +"}")
--- a/services/systems/src/main/java/com/redhat/thermostat/gateway/service/systems/http/SystemsHttpHandler.java	Tue Oct 17 08:49:58 2017 -0400
+++ b/services/systems/src/main/java/com/redhat/thermostat/gateway/service/systems/http/SystemsHttpHandler.java	Tue Oct 17 11:11:23 2017 +0200
@@ -55,12 +55,13 @@
 import com.redhat.thermostat.gateway.common.core.model.OffsetParameter;
 import com.redhat.thermostat.gateway.common.core.servlet.CommonQueryParams;
 import com.redhat.thermostat.gateway.common.core.servlet.RequestParameters;
+import com.redhat.thermostat.gateway.common.db.servlet.HttpHandlerHelper;
 import com.redhat.thermostat.gateway.common.mongodb.servlet.MongoHttpHandlerHelper;
 
 @Path("/")
 public class SystemsHttpHandler {
     private final String collectionName = "system-info";
-    private final MongoHttpHandlerHelper serviceHelper = new MongoHttpHandlerHelper( collectionName );
+    private final HttpHandlerHelper serviceHelper = new MongoHttpHandlerHelper( collectionName );
 
     @GET
     @Consumes({ "application/json" })