mirror of
https://github.com/fergalmoran/chrometophone.git
synced 2026-01-06 00:44:08 +00:00
Log send type
This commit is contained in:
@@ -41,12 +41,12 @@ public class SendServlet extends HttpServlet {
|
|||||||
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||||
resp.setContentType("text/plain");
|
resp.setContentType("text/plain");
|
||||||
|
|
||||||
RequestInfo reqInfo = RequestInfo.processRequest(req, resp,
|
RequestInfo reqInfo = RequestInfo.processRequest(req, resp,
|
||||||
getServletContext());
|
getServletContext());
|
||||||
if (reqInfo == null) {
|
if (reqInfo == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String sel = reqInfo.getParameter("sel");
|
String sel = reqInfo.getParameter("sel");
|
||||||
if (sel == null) sel = ""; // optional
|
if (sel == null) sel = ""; // optional
|
||||||
|
|
||||||
@@ -59,23 +59,24 @@ public class SendServlet extends HttpServlet {
|
|||||||
resp.getWriter().println(ERROR_STATUS + " (Must specify url parameter)");
|
resp.getWriter().println(ERROR_STATUS + " (Must specify url parameter)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
logUrlType(url, sel);
|
||||||
|
|
||||||
String deviceName = reqInfo.getParameter("deviceName");
|
String deviceName = reqInfo.getParameter("deviceName");
|
||||||
String[] deviceNames = deviceName != null ?
|
String[] deviceNames = deviceName != null ?
|
||||||
deviceName.split(",") : null;
|
deviceName.split(",") : null;
|
||||||
|
|
||||||
String deviceType = reqInfo.getParameter("deviceType");
|
String deviceType = reqInfo.getParameter("deviceType");
|
||||||
|
|
||||||
String id = doSendToDevice(url, title, sel, reqInfo,
|
String id = doSendToDevice(url, title, sel, reqInfo,
|
||||||
deviceNames, deviceType);
|
deviceNames, deviceType);
|
||||||
|
|
||||||
if (id.startsWith(ERROR_STATUS)) {
|
if (id.startsWith(ERROR_STATUS)) {
|
||||||
resp.setStatus(500);
|
resp.setStatus(500);
|
||||||
}
|
}
|
||||||
resp.getWriter().println(id);
|
resp.getWriter().println(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String doSendToDevice(String url, String title,
|
protected String doSendToDevice(String url, String title,
|
||||||
String sel, RequestInfo reqInfo,
|
String sel, RequestInfo reqInfo,
|
||||||
String deviceNames[], String deviceType) throws IOException {
|
String deviceNames[], String deviceType) throws IOException {
|
||||||
|
|
||||||
@@ -87,11 +88,11 @@ public class SendServlet extends HttpServlet {
|
|||||||
boolean res = false;
|
boolean res = false;
|
||||||
|
|
||||||
String collapseKey = "" + url.hashCode();
|
String collapseKey = "" + url.hashCode();
|
||||||
|
|
||||||
boolean reqDebug = "1".equals(reqInfo.getParameter("debug"));
|
boolean reqDebug = "1".equals(reqInfo.getParameter("debug"));
|
||||||
|
|
||||||
int ac2dmCnt = 0;
|
int ac2dmCnt = 0;
|
||||||
|
|
||||||
for (DeviceInfo deviceInfo : reqInfo.devices) {
|
for (DeviceInfo deviceInfo : reqInfo.devices) {
|
||||||
if ("ac2dm".equals(deviceInfo.getType())) {
|
if ("ac2dm".equals(deviceInfo.getType())) {
|
||||||
ac2dmCnt++;
|
ac2dmCnt++;
|
||||||
@@ -123,7 +124,7 @@ public class SendServlet extends HttpServlet {
|
|||||||
log.info("Link sent to phone! collapse_key:" + collapseKey);
|
log.info("Link sent to phone! collapse_key:" + collapseKey);
|
||||||
ok = true;
|
ok = true;
|
||||||
} else {
|
} else {
|
||||||
log.warning("Error: Unable to send link to device: " +
|
log.warning("Error: Unable to send link to device: " +
|
||||||
deviceInfo.getDeviceRegistrationID());
|
deviceInfo.getDeviceRegistrationID());
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
@@ -144,7 +145,7 @@ public class SendServlet extends HttpServlet {
|
|||||||
return OK_STATUS;
|
return OK_STATUS;
|
||||||
} else {
|
} else {
|
||||||
// Show the 'no devices' if only the browser is registered.
|
// Show the 'no devices' if only the browser is registered.
|
||||||
// We should also clarify that 'error status' mean no matching
|
// We should also clarify that 'error status' mean no matching
|
||||||
// device found ( when the extension allow specifying the destination )
|
// device found ( when the extension allow specifying the destination )
|
||||||
if (ac2dmCnt == 0 && "ac2dm".equals(deviceType)) {
|
if (ac2dmCnt == 0 && "ac2dm".equals(deviceType)) {
|
||||||
log.warning("No device registered for " + reqInfo.userName);
|
log.warning("No device registered for " + reqInfo.userName);
|
||||||
@@ -190,4 +191,17 @@ public class SendServlet extends HttpServlet {
|
|||||||
new ChannelMessage(channelToken, url));
|
new ChannelMessage(channelToken, url));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void logUrlType(String url, String sel) {
|
||||||
|
String type = "link"; // default
|
||||||
|
if (sel != null && sel.matches("([Tt]el[:]?)?\\s?[+]?(\\(?[0-9|\\s|\\-|\\.]\\)?)+")) {
|
||||||
|
type = "phone number";
|
||||||
|
} else if (url.matches("http://maps\\.google\\.[a-z]{2,3}(\\.[a-z]{2})?[/?].*") ||
|
||||||
|
url.matches("http://www\\.google\\.[a-z]{2,3}(\\.[a-z]{2})?/maps.*")) {
|
||||||
|
type = "Maps";
|
||||||
|
} else if (url.matches("http://www\\.youtube\\.[a-z]{2,3}(\\.[a-z]{2})?/.*")) {
|
||||||
|
type = "YouTube";
|
||||||
|
}
|
||||||
|
log.info("URL type: " + type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user