* * Licensed under the Apache License, Version 2.0 (the "License");\r
* * you may not use this file except in compliance with the License.\r
* * You may obtain a copy of the License at\r
- * * \r
+ * *\r
* * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
+ * *\r
* * Unless required by applicable law or agreed to in writing, software\r
* * distributed under the License is distributed on an "AS IS" BASIS,\r
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
import javax.servlet.http.HttpServletRequest;\r
import javax.servlet.http.HttpServletResponse;\r
\r
-import org.json.LOGJSONObject;\r
+import org.apache.log4j.Logger;\r
import org.onap.dmaap.datarouter.provisioning.beans.DeliveryRecord;\r
import org.onap.dmaap.datarouter.provisioning.beans.EventLogRecord;\r
import org.onap.dmaap.datarouter.provisioning.beans.ExpiryRecord;\r
import org.onap.dmaap.datarouter.provisioning.beans.Subscription;\r
import org.onap.dmaap.datarouter.provisioning.eelf.EelfMsgs;\r
import org.onap.dmaap.datarouter.provisioning.utils.DB;\r
+import org.onap.dmaap.datarouter.provisioning.utils.LOGJSONObject;\r
\r
import com.att.eelf.configuration.EELFLogger;\r
import com.att.eelf.configuration.EELFManager;\r
*/\r
@SuppressWarnings("serial")\r
public class LogServlet extends BaseServlet {\r
- //Adding EELF Logger Rally:US664892 \r
+ //Adding EELF Logger Rally:US664892\r
private static EELFLogger eelflogger = EELFManager.getInstance().getLogger("org.onap.dmaap.datarouter.provisioning.LogServlet");\r
+ private static final long TWENTYFOUR_HOURS = (24 * 60 * 60 * 1000L);\r
+ private static final String fmt1 = "yyyy-MM-dd'T'HH:mm:ss'Z'";\r
+ private static final String fmt2 = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";\r
\r
- private static final long TWENTYFOUR_HOURS = (24 * 60 * 60 * 1000L);\r
- private static final String fmt1 = "yyyy-MM-dd'T'HH:mm:ss'Z'";\r
- private static final String fmt2 = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";\r
-\r
- private boolean isfeedlog;\r
+ private static boolean isfeedlog;\r
\r
- public abstract class RowHandler {\r
- private final ServletOutputStream out;\r
- private final String[] fields;\r
- public boolean firstrow;\r
+ public abstract class RowHandler {\r
+ private final ServletOutputStream out;\r
+ private final String[] fields;\r
+ private boolean firstrow;\r
\r
- public RowHandler(ServletOutputStream out, String fieldparam, boolean b) {\r
- this.out = out;\r
- this.firstrow = b;\r
- this.fields = (fieldparam != null) ? fieldparam.split(":") : null;\r
- }\r
- public void handleRow(ResultSet rs) {\r
- try {\r
- LOGJSONable js = buildJSONable(rs);\r
- LOGJSONObject jo = js.asJSONObject();\r
- if (fields != null) {\r
- // filter out unwanted fields\r
- LOGJSONObject j2 = new LOGJSONObject();\r
- for (String key : fields) {\r
- Object v = jo.opt(key);\r
- if (v != null)\r
- j2.put(key, v);\r
- }\r
- jo = j2;\r
- }\r
- String t = firstrow ? "\n" : ",\n";\r
- t += jo.toString();\r
- out.print(t);\r
- firstrow = false;\r
- } catch (Exception e) {\r
- // ignore\r
- }\r
- }\r
- public abstract LOGJSONable buildJSONable(ResultSet rs) throws SQLException;\r
- }\r
- public class PublishRecordRowHandler extends RowHandler {\r
- public PublishRecordRowHandler(ServletOutputStream out, String fields, boolean b) {\r
- super(out, fields, b);\r
- }\r
- @Override\r
- public LOGJSONable buildJSONable(ResultSet rs) throws SQLException {\r
- return new PublishRecord(rs);\r
- }\r
- }\r
- public class DeliveryRecordRowHandler extends RowHandler {\r
- public DeliveryRecordRowHandler(ServletOutputStream out, String fields, boolean b) {\r
- super(out, fields, b);\r
- }\r
- @Override\r
- public LOGJSONable buildJSONable(ResultSet rs) throws SQLException {\r
- return new DeliveryRecord(rs);\r
- }\r
- }\r
- public class ExpiryRecordRowHandler extends RowHandler {\r
- public ExpiryRecordRowHandler(ServletOutputStream out, String fields, boolean b) {\r
- super(out, fields, b);\r
- }\r
- @Override\r
- public LOGJSONable buildJSONable(ResultSet rs) throws SQLException {\r
- return new ExpiryRecord(rs);\r
- }\r
- }\r
+ public RowHandler(ServletOutputStream out, String fieldparam, boolean b) {\r
+ this.out = out;\r
+ this.firstrow = b;\r
+ this.fields = (fieldparam != null) ? fieldparam.split(":") : null;\r
+ }\r
+ public void handleRow(ResultSet rs) {\r
+ try {\r
+ LOGJSONable js = buildJSONable(rs);\r
+ LOGJSONObject jo = js.asJSONObject();\r
+ if (fields != null) {\r
+ // filter out unwanted fields\r
+ LOGJSONObject j2 = new LOGJSONObject();\r
+ for (String key : fields) {\r
+ Object v = jo.opt(key);\r
+ if (v != null)\r
+ j2.put(key, v);\r
+ }\r
+ jo = j2;\r
+ }\r
+ String t = firstrow ? "\n" : ",\n";\r
+ t += jo.toString();\r
+ out.print(t);\r
+ firstrow = false;\r
+ } catch (Exception exception) {\r
+ intlogger.info("Failed to handle row. Exception = " + exception.getMessage(),exception);\r
+ }\r
+ }\r
+ public abstract LOGJSONable buildJSONable(ResultSet rs) throws SQLException;\r
+ }\r
+ public class PublishRecordRowHandler extends RowHandler {\r
+ public PublishRecordRowHandler(ServletOutputStream out, String fields, boolean b) {\r
+ super(out, fields, b);\r
+ }\r
+ @Override\r
+ public LOGJSONable buildJSONable(ResultSet rs) throws SQLException {\r
+ return new PublishRecord(rs);\r
+ }\r
+ }\r
+ public class DeliveryRecordRowHandler extends RowHandler {\r
+ public DeliveryRecordRowHandler(ServletOutputStream out, String fields, boolean b) {\r
+ super(out, fields, b);\r
+ }\r
+ @Override\r
+ public LOGJSONable buildJSONable(ResultSet rs) throws SQLException {\r
+ return new DeliveryRecord(rs);\r
+ }\r
+ }\r
+ public class ExpiryRecordRowHandler extends RowHandler {\r
+ public ExpiryRecordRowHandler(ServletOutputStream out, String fields, boolean b) {\r
+ super(out, fields, b);\r
+ }\r
+ @Override\r
+ public LOGJSONable buildJSONable(ResultSet rs) throws SQLException {\r
+ return new ExpiryRecord(rs);\r
+ }\r
+ }\r
\r
- /**\r
- * This class must be created from either a {@link FeedLogServlet} or a {@link SubLogServlet}.\r
- * @param isFeedLog boolean to handle those places where a feedlog request is different from\r
- * a sublog request\r
- */\r
- protected LogServlet(boolean isFeedLog) {\r
- this.isfeedlog = isFeedLog;\r
- }\r
+ /**\r
+ * This class must be created from either a {@link FeedLogServlet} or a {@link SubLogServlet}.\r
+ * @param isFeedLog boolean to handle those places where a feedlog request is different from\r
+ * a sublog request\r
+ */\r
+ protected LogServlet(boolean isFeedLog) {\r
+ this.isfeedlog = isFeedLog;\r
+ }\r
\r
- /**\r
- * DELETE a logging URL -- not supported.\r
- */\r
- @Override\r
- public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException {\r
- setIpAndFqdnForEelf("doDelete");\r
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");\r
- String message = "DELETE not allowed for the logURL.";\r
- EventLogRecord elr = new EventLogRecord(req);\r
- elr.setMessage(message);\r
- elr.setResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED);\r
- eventlogger.info(elr);\r
- resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, message);\r
- }\r
- /**\r
- * GET a logging URL -- retrieve logging data for a feed or subscription.\r
- * See the <b>Logging API</b> document for details on how this method should be invoked.\r
- */\r
- @Override\r
- public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {\r
- setIpAndFqdnForEelf("doGet");\r
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");\r
- int id = getIdFromPath(req);\r
- if (id < 0) {\r
- resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing or bad feed/subscription number.");\r
- return;\r
- }\r
- Map<String, String> map = buildMapFromRequest(req);\r
- if (map.get("err") != null) {\r
- resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid arguments: "+map.get("err"));\r
- return;\r
- }\r
- // check Accept: header??\r
+ /**\r
+ * DELETE a logging URL -- not supported.\r
+ */\r
+ @Override\r
+ public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException {\r
+ setIpAndFqdnForEelf("doDelete");\r
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");\r
+ String message = "DELETE not allowed for the logURL.";\r
+ EventLogRecord elr = new EventLogRecord(req);\r
+ elr.setMessage(message);\r
+ elr.setResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED);\r
+ eventlogger.info(elr);\r
+ resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, message);\r
+ }\r
+ /**\r
+ * GET a logging URL -- retrieve logging data for a feed or subscription.\r
+ * See the <b>Logging API</b> document for details on how this method should be invoked.\r
+ */\r
+ @Override\r
+ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {\r
+ setIpAndFqdnForEelf("doGet");\r
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");\r
+ int id = getIdFromPath(req);\r
+ if (id < 0) {\r
+ resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing or bad feed/subscription number.");\r
+ return;\r
+ }\r
+ Map<String, String> map = buildMapFromRequest(req);\r
+ if (map.get("err") != null) {\r
+ resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid arguments: "+map.get("err"));\r
+ return;\r
+ }\r
+ // check Accept: header??\r
\r
- resp.setStatus(HttpServletResponse.SC_OK);\r
- resp.setContentType(LOGLIST_CONTENT_TYPE);\r
- @SuppressWarnings("resource")\r
- ServletOutputStream out = resp.getOutputStream();\r
- final String fields = req.getParameter("fields");\r
+ resp.setStatus(HttpServletResponse.SC_OK);\r
+ resp.setContentType(LOGLIST_CONTENT_TYPE);\r
+ @SuppressWarnings("resource")\r
+ ServletOutputStream out = resp.getOutputStream();\r
+ final String fields = req.getParameter("fields");\r
\r
- out.print("[");\r
- if (isfeedlog) {\r
- // Handle /feedlog/feedid request\r
- boolean firstrow = true;\r
+ out.print("[");\r
+ if (isfeedlog) {\r
+ // Handle /feedlog/feedid request\r
+ boolean firstrow = true;\r
\r
- // 1. Collect publish records for this feed\r
- RowHandler rh = new PublishRecordRowHandler(out, fields, firstrow);\r
- getPublishRecordsForFeed(id, rh, map);\r
- firstrow = rh.firstrow;\r
+ // 1. Collect publish records for this feed\r
+ RowHandler rh = new PublishRecordRowHandler(out, fields, firstrow);\r
+ getPublishRecordsForFeed(id, rh, map);\r
+ firstrow = rh.firstrow;\r
\r
- // 2. Collect delivery records for subscriptions to this feed\r
- rh = new DeliveryRecordRowHandler(out, fields, firstrow);\r
- getDeliveryRecordsForFeed(id, rh, map);\r
- firstrow = rh.firstrow;\r
+ // 2. Collect delivery records for subscriptions to this feed\r
+ rh = new DeliveryRecordRowHandler(out, fields, firstrow);\r
+ getDeliveryRecordsForFeed(id, rh, map);\r
+ firstrow = rh.firstrow;\r
\r
- // 3. Collect expiry records for subscriptions to this feed\r
- rh = new ExpiryRecordRowHandler(out, fields, firstrow);\r
- getExpiryRecordsForFeed(id, rh, map);\r
- } else {\r
- // Handle /sublog/subid request\r
- Subscription sub = Subscription.getSubscriptionById(id);\r
- if (sub != null) {\r
- // 1. Collect publish records for the feed this subscription feeds\r
- RowHandler rh = new PublishRecordRowHandler(out, fields, true);\r
- getPublishRecordsForFeed(sub.getFeedid(), rh, map);\r
+ // 3. Collect expiry records for subscriptions to this feed\r
+ rh = new ExpiryRecordRowHandler(out, fields, firstrow);\r
+ getExpiryRecordsForFeed(id, rh, map);\r
+ } else {\r
+ // Handle /sublog/subid request\r
+ Subscription sub = Subscription.getSubscriptionById(id);\r
+ if (sub != null) {\r
+ // 1. Collect publish records for the feed this subscription feeds\r
+ RowHandler rh = new PublishRecordRowHandler(out, fields, true);\r
+ getPublishRecordsForFeed(sub.getFeedid(), rh, map);\r
\r
- // 2. Collect delivery records for this subscription\r
- rh = new DeliveryRecordRowHandler(out, fields, rh.firstrow);\r
- getDeliveryRecordsForSubscription(id, rh, map);\r
+ // 2. Collect delivery records for this subscription\r
+ rh = new DeliveryRecordRowHandler(out, fields, rh.firstrow);\r
+ getDeliveryRecordsForSubscription(id, rh, map);\r
\r
- // 3. Collect expiry records for this subscription\r
- rh = new ExpiryRecordRowHandler(out, fields, rh.firstrow);\r
- getExpiryRecordsForSubscription(id, rh, map);\r
- }\r
- }\r
- out.print("\n]");\r
- }\r
- /**\r
- * PUT a logging URL -- not supported.\r
- */\r
- @Override\r
- public void doPut(HttpServletRequest req, HttpServletResponse resp) throws IOException {\r
- setIpAndFqdnForEelf("doPut");\r
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");\r
- String message = "PUT not allowed for the logURL.";\r
- EventLogRecord elr = new EventLogRecord(req);\r
- elr.setMessage(message);\r
- elr.setResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED);\r
- eventlogger.info(elr);\r
- resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, message);\r
- }\r
- /**\r
- * POST a logging URL -- not supported.\r
- */\r
- @Override\r
- public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {\r
- setIpAndFqdnForEelf("doPost");\r
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF, req.getHeader(BEHALF_HEADER));\r
- String message = "POST not allowed for the logURL.";\r
- EventLogRecord elr = new EventLogRecord(req);\r
- elr.setMessage(message);\r
- elr.setResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED);\r
- eventlogger.info(elr);\r
- resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, message);\r
- }\r
+ // 3. Collect expiry records for this subscription\r
+ rh = new ExpiryRecordRowHandler(out, fields, rh.firstrow);\r
+ getExpiryRecordsForSubscription(id, rh, map);\r
+ }\r
+ }\r
+ out.print("\n]");\r
+ }\r
+ /**\r
+ * PUT a logging URL -- not supported.\r
+ */\r
+ @Override\r
+ public void doPut(HttpServletRequest req, HttpServletResponse resp) throws IOException {\r
+ setIpAndFqdnForEelf("doPut");\r
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");\r
+ String message = "PUT not allowed for the logURL.";\r
+ EventLogRecord elr = new EventLogRecord(req);\r
+ elr.setMessage(message);\r
+ elr.setResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED);\r
+ eventlogger.info(elr);\r
+ resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, message);\r
+ }\r
+ /**\r
+ * POST a logging URL -- not supported.\r
+ */\r
+ @Override\r
+ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {\r
+ setIpAndFqdnForEelf("doPost");\r
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF, req.getHeader(BEHALF_HEADER));\r
+ String message = "POST not allowed for the logURL.";\r
+ EventLogRecord elr = new EventLogRecord(req);\r
+ elr.setMessage(message);\r
+ elr.setResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED);\r
+ eventlogger.info(elr);\r
+ resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, message);\r
+ }\r
\r
- private Map<String, String> buildMapFromRequest(HttpServletRequest req) {\r
- Map<String, String> map = new HashMap<String, String>();\r
- String s = req.getParameter("type");\r
- if (s != null) {\r
- if (s.equals("pub") || s.equals("del") || s.equals("exp")) {\r
- map.put("type", s);\r
- } else {\r
- map.put("err", "bad type");\r
- return map;\r
- }\r
- } else\r
- map.put("type", "all");\r
- map.put("publishSQL", "");\r
- map.put("statusSQL", "");\r
- map.put("resultSQL", "");\r
- map.put("reasonSQL", "");\r
+ private Map<String, String> buildMapFromRequest(HttpServletRequest req) {\r
+ Map<String, String> map = new HashMap<String, String>();\r
+ String s = req.getParameter("type");\r
+ if (s != null) {\r
+ if (s.equals("pub") || s.equals("del") || s.equals("exp")) {\r
+ map.put("type", s);\r
+ } else {\r
+ map.put("err", "bad type");\r
+ return map;\r
+ }\r
+ } else\r
+ map.put("type", "all");\r
+ map.put("publishSQL", "");\r
+ map.put("statusSQL", "");\r
+ map.put("resultSQL", "");\r
+ map.put("reasonSQL", "");\r
\r
- s = req.getParameter("publishId");\r
- if (s != null) {\r
- if (s.indexOf("'") >= 0) {\r
- map.put("err", "bad publishId");\r
- return map;\r
- }\r
- map.put("publishSQL", " AND PUBLISH_ID = '"+s+"'");\r
- }\r
+ s = req.getParameter("publishId");\r
+ if (s != null) {\r
+ if (s.indexOf("'") >= 0) {\r
+ map.put("err", "bad publishId");\r
+ return map;\r
+ }\r
+ map.put("publishSQL", " AND PUBLISH_ID = '"+s+"'");\r
+ }\r
\r
- s = req.getParameter("statusCode");\r
- if (s != null) {\r
- String sql = null;\r
- if (s.equals("success")) {\r
- sql = " AND STATUS >= 200 AND STATUS < 300";\r
- } else if (s.equals("redirect")) {\r
- sql = " AND STATUS >= 300 AND STATUS < 400";\r
- } else if (s.equals("failure")) {\r
- sql = " AND STATUS >= 400";\r
- } else {\r
- try {\r
- Integer n = Integer.parseInt(s);\r
- if ((n >= 100 && n < 600) || (n == -1))\r
- sql = " AND STATUS = " + n;\r
- } catch (NumberFormatException e) {\r
- }\r
- }\r
- if (sql == null) {\r
- map.put("err", "bad statusCode");\r
- return map;\r
- }\r
- map.put("statusSQL", sql);\r
- map.put("resultSQL", sql.replaceAll("STATUS", "RESULT"));\r
- }\r
+ s = req.getParameter("statusCode");\r
+ if (s != null) {\r
+ String sql = null;\r
+ if (s.equals("success")) {\r
+ sql = " AND STATUS >= 200 AND STATUS < 300";\r
+ } else if (s.equals("redirect")) {\r
+ sql = " AND STATUS >= 300 AND STATUS < 400";\r
+ } else if (s.equals("failure")) {\r
+ sql = " AND STATUS >= 400";\r
+ } else {\r
+ try {\r
+ Integer n = Integer.parseInt(s);\r
+ if ((n >= 100 && n < 600) || (n == -1))\r
+ sql = " AND STATUS = " + n;\r
+ } catch (NumberFormatException e) {\r
+ }\r
+ }\r
+ if (sql == null) {\r
+ map.put("err", "bad statusCode");\r
+ return map;\r
+ }\r
+ map.put("statusSQL", sql);\r
+ map.put("resultSQL", sql.replaceAll("STATUS", "RESULT"));\r
+ }\r
\r
- s = req.getParameter("expiryReason");\r
- if (s != null) {\r
- map.put("type", "exp");\r
- if (s.equals("notRetryable")) {\r
- map.put("reasonSQL", " AND REASON = 'notRetryable'");\r
- } else if (s.equals("retriesExhausted")) {\r
- map.put("reasonSQL", " AND REASON = 'retriesExhausted'");\r
- } else if (s.equals("diskFull")) {\r
- map.put("reasonSQL", " AND REASON = 'diskFull'");\r
- } else if (s.equals("other")) {\r
- map.put("reasonSQL", " AND REASON = 'other'");\r
- } else {\r
- map.put("err", "bad expiryReason");\r
- return map;\r
- }\r
- }\r
+ s = req.getParameter("expiryReason");\r
+ if (s != null) {\r
+ map.put("type", "exp");\r
+ if (s.equals("notRetryable")) {\r
+ map.put("reasonSQL", " AND REASON = 'notRetryable'");\r
+ } else if (s.equals("retriesExhausted")) {\r
+ map.put("reasonSQL", " AND REASON = 'retriesExhausted'");\r
+ } else if (s.equals("diskFull")) {\r
+ map.put("reasonSQL", " AND REASON = 'diskFull'");\r
+ } else if (s.equals("other")) {\r
+ map.put("reasonSQL", " AND REASON = 'other'");\r
+ } else {\r
+ map.put("err", "bad expiryReason");\r
+ return map;\r
+ }\r
+ }\r
\r
- long stime = getTimeFromParam(req.getParameter("start"));\r
- if (stime < 0) {\r
- map.put("err", "bad start");\r
- return map;\r
- }\r
- long etime = getTimeFromParam(req.getParameter("end"));\r
- if (etime < 0) {\r
- map.put("err", "bad end");\r
- return map;\r
- }\r
- if (stime == 0 && etime == 0) {\r
- etime = System.currentTimeMillis();\r
- stime = etime - TWENTYFOUR_HOURS;\r
- } else if (stime == 0) {\r
- stime = etime - TWENTYFOUR_HOURS;\r
- } else if (etime == 0) {\r
- etime = stime + TWENTYFOUR_HOURS;\r
- }\r
- map.put("timeSQL", String.format(" AND EVENT_TIME >= %d AND EVENT_TIME <= %d", stime, etime));\r
- return map;\r
- }\r
- private long getTimeFromParam(final String s) {\r
- if (s == null)\r
- return 0;\r
- try {\r
- // First, look for an RFC 3339 date\r
- String fmt = (s.indexOf('.') > 0) ? fmt2 : fmt1;\r
- SimpleDateFormat sdf = new SimpleDateFormat(fmt);\r
- Date d = sdf.parse(s);\r
- return d.getTime();\r
- } catch (ParseException e) {\r
- }\r
- try {\r
- // Also allow a long (in ms); useful for testing\r
- long n = Long.parseLong(s);\r
- return n;\r
- } catch (NumberFormatException e) {\r
- }\r
- intlogger.info("Error parsing time="+s);\r
- return -1;\r
- }\r
+ long stime = getTimeFromParam(req.getParameter("start"));\r
+ if (stime < 0) {\r
+ map.put("err", "bad start");\r
+ return map;\r
+ }\r
+ long etime = getTimeFromParam(req.getParameter("end"));\r
+ if (etime < 0) {\r
+ map.put("err", "bad end");\r
+ return map;\r
+ }\r
+ if (stime == 0 && etime == 0) {\r
+ etime = System.currentTimeMillis();\r
+ stime = etime - TWENTYFOUR_HOURS;\r
+ } else if (stime == 0) {\r
+ stime = etime - TWENTYFOUR_HOURS;\r
+ } else if (etime == 0) {\r
+ etime = stime + TWENTYFOUR_HOURS;\r
+ }\r
+ map.put("timeSQL", String.format(" AND EVENT_TIME >= %d AND EVENT_TIME <= %d", stime, etime));\r
+ return map;\r
+ }\r
+ private long getTimeFromParam(final String s) {\r
+ if (s == null)\r
+ return 0;\r
+ try {\r
+ // First, look for an RFC 3339 date\r
+ String fmt = (s.indexOf('.') > 0) ? fmt2 : fmt1;\r
+ SimpleDateFormat sdf = new SimpleDateFormat(fmt);\r
+ Date d = sdf.parse(s);\r
+ return d.getTime();\r
+ } catch (ParseException parseException) {\r
+ intlogger.error("Exception in getting Time :- "+parseException.getMessage(),parseException);\r
+ }\r
+ try {\r
+ // Also allow a long (in ms); useful for testing\r
+ long n = Long.parseLong(s);\r
+ return n;\r
+ } catch (NumberFormatException numberFormatException) {\r
+ intlogger.error("Exception in getting Time :- "+numberFormatException.getMessage(),numberFormatException);\r
+ }\r
+ intlogger.info("Error parsing time="+s);\r
+ return -1;\r
+ }\r
\r
- private void getPublishRecordsForFeed(int feedid, RowHandler rh, Map<String, String> map) {\r
- String type = map.get("type");\r
- if (type.equals("all") || type.equals("pub")) {\r
- String sql = "select * from LOG_RECORDS where FEEDID = "+feedid\r
- + " AND TYPE = 'pub'"\r
- + map.get("timeSQL") + map.get("publishSQL") + map.get("statusSQL");\r
- getRecordsForSQL(sql, rh);\r
- }\r
- }\r
- private void getDeliveryRecordsForFeed(int feedid, RowHandler rh, Map<String, String> map) {\r
- String type = map.get("type");\r
- if (type.equals("all") || type.equals("del")) {\r
- String sql = "select * from LOG_RECORDS where FEEDID = "+feedid\r
- + " AND TYPE = 'del'"\r
- + map.get("timeSQL") + map.get("publishSQL") + map.get("resultSQL");\r
- getRecordsForSQL(sql, rh);\r
- }\r
- }\r
- private void getDeliveryRecordsForSubscription(int subid, RowHandler rh, Map<String, String> map) {\r
- String type = map.get("type");\r
- if (type.equals("all") || type.equals("del")) {\r
- String sql = "select * from LOG_RECORDS where DELIVERY_SUBID = "+subid\r
- + " AND TYPE = 'del'"\r
- + map.get("timeSQL") + map.get("publishSQL") + map.get("resultSQL");\r
- getRecordsForSQL(sql, rh);\r
- }\r
- }\r
- private void getExpiryRecordsForFeed(int feedid, RowHandler rh, Map<String, String> map) {\r
- String type = map.get("type");\r
- if (type.equals("all") || type.equals("exp")) {\r
- String st = map.get("statusSQL");\r
- if (st == null || st.length() == 0) {\r
- String sql = "select * from LOG_RECORDS where FEEDID = "+feedid\r
- + " AND TYPE = 'exp'"\r
- + map.get("timeSQL") + map.get("publishSQL") + map.get("reasonSQL");\r
- getRecordsForSQL(sql, rh);\r
- }\r
- }\r
- }\r
- private void getExpiryRecordsForSubscription(int subid, RowHandler rh, Map<String, String> map) {\r
- String type = map.get("type");\r
- if (type.equals("all") || type.equals("exp")) {\r
- String st = map.get("statusSQL");\r
- if (st == null || st.length() == 0) {\r
- String sql = "select * from LOG_RECORDS where DELIVERY_SUBID = "+subid\r
- + " AND TYPE = 'exp'"\r
- + map.get("timeSQL") + map.get("publishSQL") + map.get("reasonSQL");\r
- getRecordsForSQL(sql, rh);\r
- }\r
- }\r
- }\r
- private void getRecordsForSQL(String sql, RowHandler rh) {\r
- intlogger.debug(sql);\r
- long start = System.currentTimeMillis();\r
- DB db = new DB();\r
- Connection conn = null;\r
- try {\r
- conn = db.getConnection();\r
- Statement stmt = conn.createStatement();\r
- ResultSet rs = stmt.executeQuery(sql);\r
- while (rs.next()) {\r
- rh.handleRow(rs);\r
- }\r
- rs.close();\r
- stmt.close();\r
- } catch (SQLException e) {\r
- e.printStackTrace();\r
- } finally {\r
- if (conn != null)\r
- db.release(conn);\r
- }\r
- intlogger.debug("Time: " + (System.currentTimeMillis()-start) + " ms");\r
- }\r
+ private void getPublishRecordsForFeed(int feedid, RowHandler rh, Map<String, String> map) {\r
+ String type = map.get("type");\r
+ if (type.equals("all") || type.equals("pub")) {\r
+ String sql = "select * from LOG_RECORDS where FEEDID = "+feedid\r
+ + " AND TYPE = 'pub'"\r
+ + map.get("timeSQL") + map.get("publishSQL") + map.get("statusSQL");\r
+ getRecordsForSQL(sql, rh);\r
+ }\r
+ }\r
+ private void getDeliveryRecordsForFeed(int feedid, RowHandler rh, Map<String, String> map) {\r
+ String type = map.get("type");\r
+ if (type.equals("all") || type.equals("del")) {\r
+ String sql = "select * from LOG_RECORDS where FEEDID = "+feedid\r
+ + " AND TYPE = 'del'"\r
+ + map.get("timeSQL") + map.get("publishSQL") + map.get("resultSQL");\r
+ getRecordsForSQL(sql, rh);\r
+ }\r
+ }\r
+ private void getDeliveryRecordsForSubscription(int subid, RowHandler rh, Map<String, String> map) {\r
+ String type = map.get("type");\r
+ if (type.equals("all") || type.equals("del")) {\r
+ String sql = "select * from LOG_RECORDS where DELIVERY_SUBID = "+subid\r
+ + " AND TYPE = 'del'"\r
+ + map.get("timeSQL") + map.get("publishSQL") + map.get("resultSQL");\r
+ getRecordsForSQL(sql, rh);\r
+ }\r
+ }\r
+ private void getExpiryRecordsForFeed(int feedid, RowHandler rh, Map<String, String> map) {\r
+ String type = map.get("type");\r
+ if (type.equals("all") || type.equals("exp")) {\r
+ String st = map.get("statusSQL");\r
+ if (st == null || st.length() == 0) {\r
+ String sql = "select * from LOG_RECORDS where FEEDID = "+feedid\r
+ + " AND TYPE = 'exp'"\r
+ + map.get("timeSQL") + map.get("publishSQL") + map.get("reasonSQL");\r
+ getRecordsForSQL(sql, rh);\r
+ }\r
+ }\r
+ }\r
+ private void getExpiryRecordsForSubscription(int subid, RowHandler rh, Map<String, String> map) {\r
+ String type = map.get("type");\r
+ if (type.equals("all") || type.equals("exp")) {\r
+ String st = map.get("statusSQL");\r
+ if (st == null || st.length() == 0) {\r
+ String sql = "select * from LOG_RECORDS where DELIVERY_SUBID = "+subid\r
+ + " AND TYPE = 'exp'"\r
+ + map.get("timeSQL") + map.get("publishSQL") + map.get("reasonSQL");\r
+ getRecordsForSQL(sql, rh);\r
+ }\r
+ }\r
+ }\r
+ private void getRecordsForSQL(String sql, RowHandler rh) {\r
+ intlogger.debug(sql);\r
+ long start = System.currentTimeMillis();\r
+ DB db = new DB();\r
+ Connection conn = null;\r
+ try {\r
+ conn = db.getConnection();\r
+ try( Statement stmt = conn.createStatement()){\r
+ try(ResultSet rs = stmt.executeQuery(sql)){\r
+ while (rs.next()) {\r
+ rh.handleRow(rs);\r
+ }\r
+ }\r
+ }\r
+ } catch (SQLException sqlException) {\r
+ intlogger.info("Failed to get Records. Exception = " +sqlException.getMessage(),sqlException);\r
+ } finally {\r
+ if (conn != null)\r
+ db.release(conn);\r
+ }\r
+ intlogger.debug("Time: " + (System.currentTimeMillis()-start) + " ms");\r
+ }\r
}\r