You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devicemap.apache.org by re...@apache.org on 2014/07/28 00:27:24 UTC

svn commit: r1613856 - in /incubator/devicemap/trunk/examples/spring: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/devicemap/ src/main/java/org/apache/devicemap/spring/ src/main/resources/ src/m...

Author: rezan
Date: Sun Jul 27 22:27:24 2014
New Revision: 1613856

URL: http://svn.apache.org/r1613856
Log:
spring example

Added:
    incubator/devicemap/trunk/examples/spring/
    incubator/devicemap/trunk/examples/spring/pom.xml   (with props)
    incubator/devicemap/trunk/examples/spring/src/
    incubator/devicemap/trunk/examples/spring/src/main/
    incubator/devicemap/trunk/examples/spring/src/main/java/
    incubator/devicemap/trunk/examples/spring/src/main/java/org/
    incubator/devicemap/trunk/examples/spring/src/main/java/org/apache/
    incubator/devicemap/trunk/examples/spring/src/main/java/org/apache/devicemap/
    incubator/devicemap/trunk/examples/spring/src/main/java/org/apache/devicemap/spring/
    incubator/devicemap/trunk/examples/spring/src/main/java/org/apache/devicemap/spring/Classifier.java   (with props)
    incubator/devicemap/trunk/examples/spring/src/main/java/org/apache/devicemap/spring/ClassifyAPI.java   (with props)
    incubator/devicemap/trunk/examples/spring/src/main/resources/
    incubator/devicemap/trunk/examples/spring/src/main/resources/log4j.properties
    incubator/devicemap/trunk/examples/spring/src/main/webapp/
    incubator/devicemap/trunk/examples/spring/src/main/webapp/WEB-INF/
    incubator/devicemap/trunk/examples/spring/src/main/webapp/WEB-INF/applicationContext.xml   (with props)
    incubator/devicemap/trunk/examples/spring/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml   (with props)
    incubator/devicemap/trunk/examples/spring/src/main/webapp/WEB-INF/views/
    incubator/devicemap/trunk/examples/spring/src/main/webapp/WEB-INF/views/device.jsp
    incubator/devicemap/trunk/examples/spring/src/main/webapp/WEB-INF/web.xml   (with props)
    incubator/devicemap/trunk/examples/spring/src/main/webapp/index.jsp
    incubator/devicemap/trunk/examples/spring/src/main/webapp/version.jsp
    incubator/devicemap/trunk/examples/spring/src/test/
    incubator/devicemap/trunk/examples/spring/src/test/java/

Added: incubator/devicemap/trunk/examples/spring/pom.xml
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/examples/spring/pom.xml?rev=1613856&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/devicemap/trunk/examples/spring/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Added: incubator/devicemap/trunk/examples/spring/src/main/java/org/apache/devicemap/spring/Classifier.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/examples/spring/src/main/java/org/apache/devicemap/spring/Classifier.java?rev=1613856&view=auto
==============================================================================
--- incubator/devicemap/trunk/examples/spring/src/main/java/org/apache/devicemap/spring/Classifier.java (added)
+++ incubator/devicemap/trunk/examples/spring/src/main/java/org/apache/devicemap/spring/Classifier.java Sun Jul 27 22:27:24 2014
@@ -0,0 +1,37 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.devicemap.spring;
+
+import org.apache.devicemap.DeviceMapClient;
+import org.apache.devicemap.data.Device;
+import org.apache.devicemap.loader.LoaderOption;
+
+public class Classifier {
+    
+    private DeviceMapClient client;
+    
+    public synchronized void init() throws Exception {
+        client = new DeviceMapClient();
+        client.initDeviceData(LoaderOption.URL);
+    }
+    
+    public Device classify(String text) {
+        return client.classifyDevice(text);
+    }
+}

Propchange: incubator/devicemap/trunk/examples/spring/src/main/java/org/apache/devicemap/spring/Classifier.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/devicemap/trunk/examples/spring/src/main/java/org/apache/devicemap/spring/ClassifyAPI.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/examples/spring/src/main/java/org/apache/devicemap/spring/ClassifyAPI.java?rev=1613856&view=auto
==============================================================================
--- incubator/devicemap/trunk/examples/spring/src/main/java/org/apache/devicemap/spring/ClassifyAPI.java (added)
+++ incubator/devicemap/trunk/examples/spring/src/main/java/org/apache/devicemap/spring/ClassifyAPI.java Sun Jul 27 22:27:24 2014
@@ -0,0 +1,63 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.devicemap.spring;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.devicemap.data.Device;
+import org.apache.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+
+@Controller
+@RequestMapping("/")
+public class ClassifyAPI {
+
+    private static final Logger log = Logger.getLogger(ClassifyAPI.class);
+
+    @Autowired
+    private Classifier classifier;
+
+    @RequestMapping(value = "/classify", method = RequestMethod.GET)
+    public String classify(HttpServletRequest request, HttpServletResponse response, ModelMap model,
+            @RequestParam(value = "ua", required = false) String ua) throws Exception {
+
+        log.info("classify() ua: '" + ua + "'");
+
+        if (ua == null || ua.isEmpty()) {
+            ua = request.getHeader("User-Agent");
+        }
+
+        long start = System.nanoTime();
+
+        Device device = classifier.classify(ua);
+
+        Long diff = (System.nanoTime() - start) / 1000;
+
+        model.addAttribute("ua", ua);
+        model.addAttribute("device", device);
+        model.addAttribute("time", diff);
+
+        return "device";
+    }
+}

Propchange: incubator/devicemap/trunk/examples/spring/src/main/java/org/apache/devicemap/spring/ClassifyAPI.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/devicemap/trunk/examples/spring/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/examples/spring/src/main/resources/log4j.properties?rev=1613856&view=auto
==============================================================================
--- incubator/devicemap/trunk/examples/spring/src/main/resources/log4j.properties (added)
+++ incubator/devicemap/trunk/examples/spring/src/main/resources/log4j.properties Sun Jul 27 22:27:24 2014
@@ -0,0 +1,8 @@
+log4j.rootLogger=INFO,file
+
+log4j.appender.file=org.apache.log4j.RollingFileAppender
+log4j.appender.file.MaxFileSize=10MB
+log4j.appender.file.MaxBackupIndex=25
+log4j.appender.file.File=${catalina.home}/logs/devicemap.log
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %t (%F:%L): %m%n

Added: incubator/devicemap/trunk/examples/spring/src/main/webapp/WEB-INF/applicationContext.xml
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/examples/spring/src/main/webapp/WEB-INF/applicationContext.xml?rev=1613856&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/devicemap/trunk/examples/spring/src/main/webapp/WEB-INF/applicationContext.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Added: incubator/devicemap/trunk/examples/spring/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/examples/spring/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml?rev=1613856&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/devicemap/trunk/examples/spring/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Added: incubator/devicemap/trunk/examples/spring/src/main/webapp/WEB-INF/views/device.jsp
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/examples/spring/src/main/webapp/WEB-INF/views/device.jsp?rev=1613856&view=auto
==============================================================================
--- incubator/devicemap/trunk/examples/spring/src/main/webapp/WEB-INF/views/device.jsp (added)
+++ incubator/devicemap/trunk/examples/spring/src/main/webapp/WEB-INF/views/device.jsp Sun Jul 27 22:27:24 2014
@@ -0,0 +1,9 @@
+<%@ page session="false" %>
+<%@ page trimDirectiveWhitespaces="true" %>
+<%@ page contentType="application/json; charset=UTF-8" %>
+{
+"success":true,
+"ua":"${ua}",
+"time_microseconds":${time},
+"result":${device}
+}

Added: incubator/devicemap/trunk/examples/spring/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/examples/spring/src/main/webapp/WEB-INF/web.xml?rev=1613856&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/devicemap/trunk/examples/spring/src/main/webapp/WEB-INF/web.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Added: incubator/devicemap/trunk/examples/spring/src/main/webapp/index.jsp
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/examples/spring/src/main/webapp/index.jsp?rev=1613856&view=auto
==============================================================================
--- incubator/devicemap/trunk/examples/spring/src/main/webapp/index.jsp (added)
+++ incubator/devicemap/trunk/examples/spring/src/main/webapp/index.jsp Sun Jul 27 22:27:24 2014
@@ -0,0 +1,42 @@
+<%@ page session="false" %>
+<%--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License.
+--%>
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<title>DeviceMap Spring Example</title>
+</head>
+<body>
+<pre>
+<h1>DeviceMap Spring Example</h1>
+<a href="version.jsp">version</a>
+
+<b>classify</b>
+GET /classify
+Classify a device using a user-agent header or param
+-params: ua [optional]
+<form action="classify" method="GET">
+ua <input type="text" name="ua">
+<input type="submit" value="Submit">
+</form>
+
+</pre>
+</body>
+</html>

Added: incubator/devicemap/trunk/examples/spring/src/main/webapp/version.jsp
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/examples/spring/src/main/webapp/version.jsp?rev=1613856&view=auto
==============================================================================
--- incubator/devicemap/trunk/examples/spring/src/main/webapp/version.jsp (added)
+++ incubator/devicemap/trunk/examples/spring/src/main/webapp/version.jsp Sun Jul 27 22:27:24 2014
@@ -0,0 +1,30 @@
+<%@ page session="false" %>
+<%--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License.
+--%>
+<html>
+<head>
+<title>DeviceMap</title>
+</head>
+<body>
+<h1>DeviceMap</h1>
+Project name: ${project.name}<br>
+Project version: ${project.version}<br>
+Build date: ${build.date}<br>
+</body>
+</html>