* * 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
* @version $Id: BaseLogRecord.java,v 1.10 2013/10/29 16:57:57 eby Exp $\r
*/\r
public class BaseLogRecord implements LOGJSONable, Loadable {\r
- protected static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");\r
+ protected static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");\r
\r
- private long eventTime;\r
- private String publishId;\r
- private int feedid;\r
- private String requestUri;\r
- private String method;\r
- private String contentType;\r
- private long contentLength;\r
+ private long eventTime;\r
+ private String publishId;\r
+ private int feedid;\r
+ private String requestUri;\r
+ private String method;\r
+ private String contentType;\r
+ private long contentLength;\r
\r
- protected BaseLogRecord(String[] pp) throws ParseException {\r
-// This throws exceptions occasionally - don't know why.\r
-// Date d = null;\r
-// synchronized (sdf) {\r
-// d = sdf.parse(pp[0]);\r
-// }\r
- Date d = parseDate(pp[0]);\r
- this.eventTime = d.getTime();\r
- this.publishId = pp[2];\r
- this.feedid = Integer.parseInt(pp[3]);\r
- if (pp[1].equals("DLX")) {\r
- this.requestUri = "";\r
- this.method = "GET"; // Note: we need a valid value in this field, even though unused\r
- this.contentType = "";\r
- this.contentLength = Long.parseLong(pp[5]);\r
- } else if (pp[1].equals("PUB") || pp[1].equals("LOG") || pp[1].equals("PBF")) {\r
- this.requestUri = pp[4];\r
- this.method = pp[5];\r
- this.contentType = pp[6];\r
- this.contentLength = Long.parseLong(pp[7]);\r
- } else {\r
- this.requestUri = pp[5];\r
- this.method = pp[6];\r
- this.contentType = pp[7];\r
- this.contentLength = Long.parseLong(pp[8]);\r
- }\r
- }\r
- protected BaseLogRecord(ResultSet rs) throws SQLException {\r
- this.eventTime = rs.getLong("EVENT_TIME");\r
- this.publishId = rs.getString("PUBLISH_ID");\r
- this.feedid = rs.getInt("FEEDID");\r
- this.requestUri = rs.getString("REQURI");\r
- this.method = rs.getString("METHOD");\r
- this.contentType = rs.getString("CONTENT_TYPE");\r
- this.contentLength = rs.getLong("CONTENT_LENGTH");\r
- }\r
- protected Date parseDate(final String s) throws ParseException {\r
- int[] n = new int[7];\r
- int p = 0;\r
- for (int i = 0; i < s.length(); i++) {\r
- char c = s.charAt(i);\r
- if (c < '0' || c > '9') {\r
- p++;\r
- } else {\r
- if (p > n.length)\r
- throw new ParseException("parseDate()", 0);\r
- n[p] = (n[p] * 10) + (c - '0');\r
- }\r
- }\r
- if (p != 7)\r
- throw new ParseException("parseDate()", 1);\r
- Calendar cal = new GregorianCalendar();\r
- cal.set(Calendar.YEAR, n[0]);\r
- cal.set(Calendar.MONTH, n[1]-1);\r
- cal.set(Calendar.DAY_OF_MONTH, n[2]);\r
- cal.set(Calendar.HOUR_OF_DAY, n[3]);\r
- cal.set(Calendar.MINUTE, n[4]);\r
- cal.set(Calendar.SECOND, n[5]);\r
- cal.set(Calendar.MILLISECOND, n[6]);\r
- return cal.getTime();\r
- }\r
- public long getEventTime() {\r
- return eventTime;\r
- }\r
- public void setEventTime(long eventTime) {\r
- this.eventTime = eventTime;\r
- }\r
- public String getPublishId() {\r
- return publishId;\r
- }\r
- public void setPublishId(String publishId) {\r
- this.publishId = publishId;\r
- }\r
- public int getFeedid() {\r
- return feedid;\r
- }\r
- public void setFeedid(int feedid) {\r
- this.feedid = feedid;\r
- }\r
- public String getRequestUri() {\r
- return requestUri;\r
- }\r
- public void setRequestUri(String requestUri) {\r
- this.requestUri = requestUri;\r
- }\r
- public String getMethod() {\r
- return method;\r
- }\r
- public void setMethod(String method) {\r
- this.method = method;\r
- }\r
- public String getContentType() {\r
- return contentType;\r
- }\r
- public void setContentType(String contentType) {\r
- this.contentType = contentType;\r
- }\r
- public long getContentLength() {\r
- return contentLength;\r
- }\r
- public void setContentLength(long contentLength) {\r
- this.contentLength = contentLength;\r
- }\r
- @Override\r
- public LOGJSONObject asJSONObject() {\r
- LOGJSONObject jo = new LOGJSONObject();\r
- String t = "";\r
- synchronized (sdf) {\r
- t = sdf.format(eventTime);\r
- }\r
- jo.put("date", t);\r
- jo.put("publishId", publishId);\r
- jo.put("requestURI", requestUri);\r
- jo.put("method", method);\r
- if (method.equals("PUT")) {\r
- jo.put("contentType", contentType);\r
- jo.put("contentLength", contentLength);\r
- }\r
- return jo;\r
- }\r
- @Override\r
- public void load(PreparedStatement ps) throws SQLException {\r
- ps.setLong (2, getEventTime());\r
- ps.setString(3, getPublishId());\r
- ps.setInt (4, getFeedid());\r
- ps.setString(5, getRequestUri());\r
- ps.setString(6, getMethod());\r
- ps.setString(7, getContentType());\r
- ps.setLong (8, getContentLength());\r
- }\r
+ protected BaseLogRecord(String[] pp) throws ParseException {\r
+// This throws exceptions occasionally - don't know why.\r
+// Date d = null;\r
+// synchronized (sdf) {\r
+// d = sdf.parse(pp[0]);\r
+// }\r
+ Date d = parseDate(pp[0]);\r
+ this.eventTime = d.getTime();\r
+ this.publishId = pp[2];\r
+ this.feedid = Integer.parseInt(pp[3]);\r
+ if (pp[1].equals("DLX")) {\r
+ this.requestUri = "";\r
+ this.method = "GET"; // Note: we need a valid value in this field, even though unused\r
+ this.contentType = "";\r
+ this.contentLength = Long.parseLong(pp[5]);\r
+ } else if (pp[1].equals("PUB") || pp[1].equals("LOG") || pp[1].equals("PBF")) {\r
+ this.requestUri = pp[4];\r
+ this.method = pp[5];\r
+ this.contentType = pp[6];\r
+ this.contentLength = Long.parseLong(pp[7]);\r
+ } else {\r
+ this.requestUri = pp[5];\r
+ this.method = pp[6];\r
+ this.contentType = pp[7];\r
+ this.contentLength = Long.parseLong(pp[8]);\r
+ }\r
+ }\r
+ protected BaseLogRecord(ResultSet rs) throws SQLException {\r
+ this.eventTime = rs.getLong("EVENT_TIME");\r
+ this.publishId = rs.getString("PUBLISH_ID");\r
+ this.feedid = rs.getInt("FEEDID");\r
+ this.requestUri = rs.getString("REQURI");\r
+ this.method = rs.getString("METHOD");\r
+ this.contentType = rs.getString("CONTENT_TYPE");\r
+ this.contentLength = rs.getLong("CONTENT_LENGTH");\r
+ }\r
+ protected Date parseDate(final String s) throws ParseException {\r
+ int[] n = new int[7];\r
+ int p = 0;\r
+ for (int i = 0; i < s.length(); i++) {\r
+ char c = s.charAt(i);\r
+ if (c < '0' || c > '9') {\r
+ p++;\r
+ } else {\r
+ if (p > n.length)\r
+ throw new ParseException("parseDate()", 0);\r
+ n[p] = (n[p] * 10) + (c - '0');\r
+ }\r
+ }\r
+ if (p != 7)\r
+ throw new ParseException("parseDate()", 1);\r
+ Calendar cal = new GregorianCalendar();\r
+ cal.set(Calendar.YEAR, n[0]);\r
+ cal.set(Calendar.MONTH, n[1]-1);\r
+ cal.set(Calendar.DAY_OF_MONTH, n[2]);\r
+ cal.set(Calendar.HOUR_OF_DAY, n[3]);\r
+ cal.set(Calendar.MINUTE, n[4]);\r
+ cal.set(Calendar.SECOND, n[5]);\r
+ cal.set(Calendar.MILLISECOND, n[6]);\r
+ return cal.getTime();\r
+ }\r
+ public long getEventTime() {\r
+ return eventTime;\r
+ }\r
+ public void setEventTime(long eventTime) {\r
+ this.eventTime = eventTime;\r
+ }\r
+ public String getPublishId() {\r
+ return publishId;\r
+ }\r
+ public void setPublishId(String publishId) {\r
+ this.publishId = publishId;\r
+ }\r
+ public int getFeedid() {\r
+ return feedid;\r
+ }\r
+ public void setFeedid(int feedid) {\r
+ this.feedid = feedid;\r
+ }\r
+ public String getRequestUri() {\r
+ return requestUri;\r
+ }\r
+ public void setRequestUri(String requestUri) {\r
+ this.requestUri = requestUri;\r
+ }\r
+ public String getMethod() {\r
+ return method;\r
+ }\r
+ public void setMethod(String method) {\r
+ this.method = method;\r
+ }\r
+ public String getContentType() {\r
+ return contentType;\r
+ }\r
+ public void setContentType(String contentType) {\r
+ this.contentType = contentType;\r
+ }\r
+ public long getContentLength() {\r
+ return contentLength;\r
+ }\r
+ public void setContentLength(long contentLength) {\r
+ this.contentLength = contentLength;\r
+ }\r
+ @Override\r
+ public LOGJSONObject asJSONObject() {\r
+ LOGJSONObject jo = new LOGJSONObject();\r
+ String t = "";\r
+ synchronized (sdf) {\r
+ t = sdf.format(eventTime);\r
+ }\r
+ jo.put("date", t);\r
+ jo.put("publishId", publishId);\r
+ jo.put("requestURI", requestUri);\r
+ jo.put("method", method);\r
+ if (method.equals("PUT")) {\r
+ jo.put("contentType", contentType);\r
+ jo.put("contentLength", contentLength);\r
+ }\r
+ return jo;\r
+ }\r
+ @Override\r
+ public void load(PreparedStatement ps) throws SQLException {\r
+ ps.setLong (2, getEventTime());\r
+ ps.setString(3, getPublishId());\r
+ ps.setInt (4, getFeedid());\r
+ ps.setString(5, getRequestUri());\r
+ ps.setString(6, getMethod());\r
+ ps.setString(7, getContentType());\r
+ ps.setLong (8, getContentLength());\r
+ }\r
}\r