devicemap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wk...@apache.org
Subject svn commit: r1648550 - in /devicemap/trunk/examples: ./ ddr-filter/ ddr-filter/src/main/java/org/apache/devicemap/example/webfilter/ ddr-filter/src/main/resources/ ddr-filter/src/main/webapp/WEB-INF/ ddr-filter/src/test/ ddr-service/ ddr-service/src/ma...
Date Tue, 30 Dec 2014 17:26:03 GMT
Author: wkeil
Date: Tue Dec 30 17:26:03 2014
New Revision: 1648550

URL: http://svn.apache.org/r1648550
Log:
DMAP-111: Improve Web Examples 
Updated examples, Log4J upgrade
Task-Url: https://issues.apache.org/jira/browse/DMAP-111

Added:
    devicemap/trunk/examples/ddr-filter/src/main/resources/log4j2.xml
    devicemap/trunk/examples/ddr-filter/src/test/test-uas.txt
    devicemap/trunk/examples/ddr-service/src/main/resources/log4j2.xml
Modified:
    devicemap/trunk/examples/ddr-filter/pom.xml
    devicemap/trunk/examples/ddr-filter/src/main/java/org/apache/devicemap/example/webfilter/IdentificationFilter.java
    devicemap/trunk/examples/ddr-filter/src/main/webapp/WEB-INF/oddr.properties
    devicemap/trunk/examples/ddr-service/pom.xml
    devicemap/trunk/examples/ddr-service/src/main/java/org/apache/devicemap/simpleddr/web/controller/Service.java
    devicemap/trunk/examples/ddr-service/src/main/java/org/apache/devicemap/simpleddr/web/filter/IdentificationFilter.java
    devicemap/trunk/examples/pom.xml

Modified: devicemap/trunk/examples/ddr-filter/pom.xml
URL: http://svn.apache.org/viewvc/devicemap/trunk/examples/ddr-filter/pom.xml?rev=1648550&r1=1648549&r2=1648550&view=diff
==============================================================================
--- devicemap/trunk/examples/ddr-filter/pom.xml (original)
+++ devicemap/trunk/examples/ddr-filter/pom.xml Tue Dec 30 17:26:03 2014
@@ -24,6 +24,15 @@
 		<!-- <dependency> <groupId>org.w3c</groupId> <artifactId>ddr-simple</artifactId>

 			<version>${w3cddr.version}</version> </dependency> -->
 		<dependency>
+			<groupId>org.apache.logging.log4j</groupId>
+			<artifactId>log4j-api</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.logging.log4j</groupId>
+			<artifactId>log4j-core</artifactId>
+		</dependency>
+		
+		<dependency>
 			<groupId>org.apache.devicemap</groupId>
 			<artifactId>devicemap-data</artifactId>
 			<scope>test</scope>
@@ -67,23 +76,11 @@
 					<debug>true</debug>
 				</configuration>
 			</plugin>
-<!-- 
-			<plugin>
-				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-war-plugin</artifactId>
-				<version>2.5</version>
-				<configuration>
-					<webResources>
-						<resource>
-							<!- this is relative to the pom.xml directory ->
-							<directory>../../data/device-data/src/main/resources</directory>
-							<!- override the destination directory for this resource ->
-							<targetPath>WEB-INF/classes</targetPath>
-						</resource>
-					</webResources>
-				</configuration>
-			</plugin>
- -->
+			<!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId>

+				<version>2.5</version> <configuration> <webResources> <resource>
<!- this 
+				is relative to the pom.xml directory -> <directory>../../data/device-data/src/main/resources</directory>

+				<!- override the destination directory for this resource -> <targetPath>WEB-INF/classes</targetPath>

+				</resource> </webResources> </configuration> </plugin> -->
 		</plugins>
 	</build>
 </project>

Modified: devicemap/trunk/examples/ddr-filter/src/main/java/org/apache/devicemap/example/webfilter/IdentificationFilter.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/examples/ddr-filter/src/main/java/org/apache/devicemap/example/webfilter/IdentificationFilter.java?rev=1648550&r1=1648549&r2=1648550&view=diff
==============================================================================
--- devicemap/trunk/examples/ddr-filter/src/main/java/org/apache/devicemap/example/webfilter/IdentificationFilter.java
(original)
+++ devicemap/trunk/examples/ddr-filter/src/main/java/org/apache/devicemap/example/webfilter/IdentificationFilter.java
Tue Dec 30 17:26:03 2014
@@ -39,11 +39,15 @@ import org.w3c.ddr.simple.ServiceFactory
 import org.w3c.ddr.simple.exception.NameException;
 import org.apache.devicemap.simpleddr.ODDRService;
 import org.apache.devicemap.simpleddr.model.ODDRHTTPEvidence;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 
 /**
  * Servlet Filter implementation class
  */
 public class IdentificationFilter implements Filter {
+	private static final Logger log = LogManager.getLogger(IdentificationFilter.class);
+	
 	private Service identificationService = null;
 	
     /**
@@ -56,30 +60,31 @@ public class IdentificationFilter implem
 	 * @see Filter#init(FilterConfig)
 	 */
 	public void init(FilterConfig filterConfig) throws ServletException {
-	     System.out.println("Initialize filter");
-	        Properties initializationProperties = new Properties();
-	        ServletContext context = filterConfig.getServletContext();                
-
-	        try {
-	            initializationProperties.load(context.getResourceAsStream("/WEB-INF/oddr.properties"));
-	            identificationService = ServiceFactory.newService("org.apache.devicemap.simpleddr.ODDRService",
initializationProperties.getProperty(ODDRService.ODDR_VOCABULARY_IRI), initializationProperties);
-	        } catch (Exception ex) {
-	            throw new RuntimeException(ex);
-	        }
+	    log.info("Initialize filter");
+	    Properties initializationProperties = new Properties();
+	    ServletContext context = filterConfig.getServletContext();                
+	
+	    try {
+	        initializationProperties.load(context.getResourceAsStream("/WEB-INF/oddr.properties"));
+	        identificationService = ServiceFactory.newService("org.apache.devicemap.simpleddr.ODDRService",
initializationProperties.getProperty(ODDRService.ODDR_VOCABULARY_IRI), initializationProperties);
+	    } catch (Exception ex) {
+	    	log.error(ex);
+	        throw new RuntimeException(ex);
+	    }
 	}
 	
 	/**
 	 * @see Filter#destroy()
 	 */
 	public void destroy() {
-		System.out.println("Destroy Filter");
+		log.info("Destroy Filter");
 	}
 
 	/**
 	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
 	 */
 	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
-		System.out.println("Do filter");
+		log.info("Do filter");
 		PropertyRef vendorRef;
         PropertyRef modelRef;
         PropertyRef displayWidthRef;
@@ -92,26 +97,21 @@ public class IdentificationFilter implem
             displayHeightRef = identificationService.newPropertyRef("displayHeight");
 
         } catch (NameException ex) {
-        	System.err.println(ex.getLocalizedMessage());
+        	log.error(ex);
             throw new RuntimeException(ex);
         }
 
         final PropertyRef[] propertyRefs = new PropertyRef[] {vendorRef, modelRef, displayWidthRef,
displayHeightRef};
         final Evidence e = new ODDRHTTPEvidence();
         
-        final String uaParam = ((HttpServletRequest)request).getParameter("ua");
-//        System.out.println("Param: " + uaParam);
-        
-//        String userAgent = ((HttpServletRequest)request).getHeader("User-Agent");
-//        String userAgent = "Mozilla/5.0 (Linux; Android 4.4.2; nl-nl; SAMSUNG SM-T530 Build/KOT49H)
AppleWebKit/537.36 (KHTML, like Gecko) Version/1.5 Chrome/28.0.1500.94 Safari/537.36";
-//        String userAgent = "Mozilla/5.0 (Linux; U; Android 2.2.1; en-us; SAMSUNG-SGH-I997
Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
-        final String userAgent = uaParam != null ? uaParam : ((HttpServletRequest)request).getHeader("User-Agent");
-        if (uaParam!= null) {
-        	System.out.println("User-Agent (*): " + userAgent);
+        String ua=((HttpServletRequest)request).getParameter("ua");
+        if(ua==null || ua.isEmpty()) {
+          ua=((HttpServletRequest)request).getHeader("User-Agent");
+          log.info("User-Agent: " + ua);
         } else {
-        	System.out.println("User-Agent: " + userAgent);
+        	log.info("User-Agent (*): " + ua);
         }
-        e.put("User-Agent", userAgent);
+        e.put("User-Agent", ua);
 
         try {
             PropertyValues propertyValues = identificationService.getPropertyValues(e, propertyRefs);
@@ -120,20 +120,19 @@ public class IdentificationFilter implem
             PropertyValue displayWidth = propertyValues.getValue(displayWidthRef);
             PropertyValue displayHeight = propertyValues.getValue(displayHeightRef);
 
-            System.out.print("Vendor: " + vendor + "(" + vendor.exists() + ")");
-            System.out.print(" ;");
-            System.out.println("Model: " + model + "(" + model.exists() + ")");
+            log.info("Vendor: " + vendor + "(" + vendor.exists() + ")");
+            log.info("Model: " + model + "(" + model.exists() + ")");
 
             if (vendor.exists())
                 ((HttpServletRequest)request).setAttribute("vendor", vendor.getString());
             if (model.exists())
                 ((HttpServletRequest)request).setAttribute("model", model.getString());
             if (displayWidth.exists()) {
-            	System.out.println("W: " + displayWidth + "(" + displayWidth.exists() + ")");
+            	log.info("W: " + displayWidth + "(" + displayWidth.exists() + ")");
                 request.setAttribute("displayWidth", displayWidth.getInteger());
             }
             if (displayHeight.exists()) {
-            	System.out.println("H: " + displayHeight + "(" + displayHeight.exists() + ")");
+            	log.info("H: " + displayHeight + "(" + displayHeight.exists() + ")");
             	request.setAttribute("displayHeight", displayHeight.getInteger());
             }
         } catch (Exception ex) {

Added: devicemap/trunk/examples/ddr-filter/src/main/resources/log4j2.xml
URL: http://svn.apache.org/viewvc/devicemap/trunk/examples/ddr-filter/src/main/resources/log4j2.xml?rev=1648550&view=auto
==============================================================================
--- devicemap/trunk/examples/ddr-filter/src/main/resources/log4j2.xml (added)
+++ devicemap/trunk/examples/ddr-filter/src/main/resources/log4j2.xml Tue Dec 30 17:26:03
2014
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="WARN">
+  <Appenders>
+    <Console name="Console" target="SYSTEM_OUT">
+      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
+    </Console>
+  </Appenders>
+  <Loggers>
+    <!-- Root level is "info", if you want to see more detailed output like data streams,
please change to "debug" -->
+    <Root level="info">
+      <AppenderRef ref="Console"/>
+    </Root>
+  </Loggers>
+</Configuration>
\ No newline at end of file

Modified: devicemap/trunk/examples/ddr-filter/src/main/webapp/WEB-INF/oddr.properties
URL: http://svn.apache.org/viewvc/devicemap/trunk/examples/ddr-filter/src/main/webapp/WEB-INF/oddr.properties?rev=1648550&r1=1648549&r2=1648550&view=diff
==============================================================================
--- devicemap/trunk/examples/ddr-filter/src/main/webapp/WEB-INF/oddr.properties (original)
+++ devicemap/trunk/examples/ddr-filter/src/main/webapp/WEB-INF/oddr.properties Tue Dec 30
17:26:03 2014
@@ -8,4 +8,4 @@ ddr.vocabulary.core.path=/temp/devicemap
 oddr.vocabulary.path=/temp/devicemap-data/devicedata/oddrVocabulary.xml
 oddr.limited.vocabulary.path=/temp/devicemap-data/devicedata/oddrLimitedVocabulary.xml
 oddr.vocabulary.device=http://www.openddr.org/oddr-vocabulary
-oddr.threshold=99
+oddr.threshold=30

Added: devicemap/trunk/examples/ddr-filter/src/test/test-uas.txt
URL: http://svn.apache.org/viewvc/devicemap/trunk/examples/ddr-filter/src/test/test-uas.txt?rev=1648550&view=auto
==============================================================================
--- devicemap/trunk/examples/ddr-filter/src/test/test-uas.txt (added)
+++ devicemap/trunk/examples/ddr-filter/src/test/test-uas.txt Tue Dec 30 17:26:03 2014
@@ -0,0 +1,3 @@
+Test UAs:
+Mozilla/5.0 (Linux; Android 4.4.2; nl-nl; SAMSUNG SM-T530 Build/KOT49H) AppleWebKit/537.36
(KHTML, like Gecko) Version/1.5 Chrome/28.0.1500.94 Safari/537.36
+Mozilla/5.0 (Linux; U; Android 2.2.1; en-us; SAMSUNG-SGH-I997 Build/FROYO) AppleWebKit/533.1
(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

Modified: devicemap/trunk/examples/ddr-service/pom.xml
URL: http://svn.apache.org/viewvc/devicemap/trunk/examples/ddr-service/pom.xml?rev=1648550&r1=1648549&r2=1648550&view=diff
==============================================================================
--- devicemap/trunk/examples/ddr-service/pom.xml (original)
+++ devicemap/trunk/examples/ddr-service/pom.xml Tue Dec 30 17:26:03 2014
@@ -35,11 +35,15 @@
 			<artifactId>jstl</artifactId>
 		</dependency>
 		<dependency>
-			<groupId>log4j</groupId>
-			<artifactId>log4j</artifactId>
-			<version>1.2.17</version>
+			<groupId>org.apache.logging.log4j</groupId>
+			<artifactId>log4j-api</artifactId>
 		</dependency>
 		<dependency>
+			<groupId>org.apache.logging.log4j</groupId>
+			<artifactId>log4j-core</artifactId>
+		</dependency>
+
+		<dependency>
 			<groupId>org.apache.devicemap</groupId>
 			<artifactId>devicemap-simpleddr</artifactId>
 		</dependency>

Modified: devicemap/trunk/examples/ddr-service/src/main/java/org/apache/devicemap/simpleddr/web/controller/Service.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/examples/ddr-service/src/main/java/org/apache/devicemap/simpleddr/web/controller/Service.java?rev=1648550&r1=1648549&r2=1648550&view=diff
==============================================================================
--- devicemap/trunk/examples/ddr-service/src/main/java/org/apache/devicemap/simpleddr/web/controller/Service.java
(original)
+++ devicemap/trunk/examples/ddr-service/src/main/java/org/apache/devicemap/simpleddr/web/controller/Service.java
Tue Dec 30 17:26:03 2014
@@ -19,7 +19,8 @@
 
 package org.apache.devicemap.simpleddr.web.controller;
  
-import org.apache.log4j.Logger;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.ModelMap;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -30,7 +31,7 @@ import org.springframework.web.bind.anno
 @RequestMapping("/service")
 public class Service
 {
-    private static final Logger log = Logger.getLogger(Service.class);
+    private static final Logger log = LogManager.getLogger(Service.class);
 
     @RequestMapping(method=RequestMethod.GET)
     public String root(ModelMap model)

Modified: devicemap/trunk/examples/ddr-service/src/main/java/org/apache/devicemap/simpleddr/web/filter/IdentificationFilter.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/examples/ddr-service/src/main/java/org/apache/devicemap/simpleddr/web/filter/IdentificationFilter.java?rev=1648550&r1=1648549&r2=1648550&view=diff
==============================================================================
--- devicemap/trunk/examples/ddr-service/src/main/java/org/apache/devicemap/simpleddr/web/filter/IdentificationFilter.java
(original)
+++ devicemap/trunk/examples/ddr-service/src/main/java/org/apache/devicemap/simpleddr/web/filter/IdentificationFilter.java
Tue Dec 30 17:26:03 2014
@@ -21,7 +21,7 @@ package org.apache.devicemap.simpleddr.w
 
 import java.io.IOException;
 import java.util.Properties;
-import org.apache.log4j.Logger;
+
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
 import javax.servlet.FilterConfig;
@@ -30,8 +30,11 @@ import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
+
 import org.apache.devicemap.simpleddr.ODDRService;
 import org.apache.devicemap.simpleddr.model.ODDRHTTPEvidence;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.w3c.ddr.simple.Evidence;
 import org.w3c.ddr.simple.PropertyRef;
 import org.w3c.ddr.simple.PropertyValue;
@@ -42,7 +45,7 @@ import org.w3c.ddr.simple.exception.Name
 
 public class IdentificationFilter implements Filter {
 
-    private static final Logger log = Logger.getLogger(IdentificationFilter.class);
+    private static final Logger log = LogManager.getLogger(IdentificationFilter.class);
 
     private Service identificationService = null;
 
@@ -51,13 +54,13 @@ public class IdentificationFilter implem
     Properties initializationProperties = new Properties();
     ServletContext context = filterConfig.getServletContext();                
 
-    try {
-        initializationProperties.load(context.getResourceAsStream("/WEB-INF/oddr.properties"));
-        identificationService = ServiceFactory.newService("org.apache.devicemap.simpleddr.ODDRService",
initializationProperties.getProperty(ODDRService.ODDR_VOCABULARY_IRI), initializationProperties);
-
-    } catch (Exception ex) {
-        throw new RuntimeException(ex);
-    }
+	    try {
+	        initializationProperties.load(context.getResourceAsStream("/WEB-INF/oddr.properties"));
+	        identificationService = ServiceFactory.newService("org.apache.devicemap.simpleddr.ODDRService",
initializationProperties.getProperty(ODDRService.ODDR_VOCABULARY_IRI), initializationProperties);
+	
+	    } catch (Exception ex) {
+	        throw new RuntimeException(ex);
+	    }
     }
 
     public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
@@ -131,7 +134,6 @@ public class IdentificationFilter implem
         }
         if (wireless!=null && wireless.exists()) {
             ((HttpServletRequest)request).setAttribute("dmapWireless", wireless.getString());
-
         }
 
     } catch (Exception ex) {

Added: devicemap/trunk/examples/ddr-service/src/main/resources/log4j2.xml
URL: http://svn.apache.org/viewvc/devicemap/trunk/examples/ddr-service/src/main/resources/log4j2.xml?rev=1648550&view=auto
==============================================================================
--- devicemap/trunk/examples/ddr-service/src/main/resources/log4j2.xml (added)
+++ devicemap/trunk/examples/ddr-service/src/main/resources/log4j2.xml Tue Dec 30 17:26:03
2014
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="WARN">
+  <Appenders>
+    <Console name="Console" target="SYSTEM_OUT">
+      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
+    </Console>
+  </Appenders>
+  <Loggers>
+    <!-- Root level is "info", if you want to see more detailed output like data streams,
please change to "debug" -->
+    <Root level="info">
+      <AppenderRef ref="Console"/>
+    </Root>
+  </Loggers>
+</Configuration>
\ No newline at end of file

Modified: devicemap/trunk/examples/pom.xml
URL: http://svn.apache.org/viewvc/devicemap/trunk/examples/pom.xml?rev=1648550&r1=1648549&r2=1648550&view=diff
==============================================================================
--- devicemap/trunk/examples/pom.xml (original)
+++ devicemap/trunk/examples/pom.xml Tue Dec 30 17:26:03 2014
@@ -16,7 +16,7 @@
 	<version>1.0.0-SNAPSHOT</version>
 	<packaging>pom</packaging>
 	<name>Apache DeviceMap Examples (Java)</name>
-	<inceptionYear>2014</inceptionYear>
+	<inceptionYear>2013</inceptionYear>
 	<modules>
 		<module>console</module>
 		<module>servlet</module>
@@ -79,6 +79,17 @@
 				<scope>provided</scope>
 			</dependency>
 			<dependency>
+				<groupId>org.apache.logging.log4j</groupId>
+				<artifactId>log4j-api</artifactId>
+				<version>2.1</version>
+			</dependency>
+			<dependency>
+				<groupId>org.apache.logging.log4j</groupId>
+				<artifactId>log4j-core</artifactId>
+				<version>2.1</version>
+			</dependency>
+
+			<dependency>
 				<groupId>junit</groupId>
 				<artifactId>junit</artifactId>
 				<version>4.11</version>
@@ -88,18 +99,9 @@
 	</dependencyManagement>
 
 	<build>
-		<!-- >pluginManagement>
-			<plugins>
-				<plugin>
-					<artifactId>maven-assembly-plugin</artifactId>
-					<configuration>
-						<descriptors>
-							<descriptor>src/assembly/bin.xml</descriptor>
-						</descriptors>
-					</configuration>
-				</plugin>
-			</plugins>
-		</pluginManagement -->
+		<!-- >pluginManagement> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId>

+			<configuration> <descriptors> <descriptor>src/assembly/bin.xml</descriptor>

+			</descriptors> </configuration> </plugin> </plugins> </pluginManagement
-->
 		<plugins>
 			<plugin>
 				<groupId>org.apache.maven.plugins</groupId>



Mime
View raw message