Skip to content

Commit d4c1ce4

Browse files
AbhinabKanrarmaibin
authored andcommitted
PR for spring-mobile (eugenp#1062)
* rest with spark java * 4
1 parent 1e74f9d commit d4c1ce4

8 files changed

Lines changed: 153 additions & 0 deletions

File tree

‎pom.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
<module>xstream</module>
186186

187187
<module>struts2</module>
188+
188189
</modules>
189190

190191
</project>

‎spring-mobile/pom.xml‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.baeldung</groupId>
7+
<artifactId>spring-mobile</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
<name>spring-mobile</name>
10+
<packaging>war</packaging>
11+
<url>http://maven.apache.org</url>
12+
13+
<properties>
14+
<java.version>1.8</java.version>
15+
</properties>
16+
17+
<parent>
18+
<groupId>org.springframework.boot</groupId>
19+
<artifactId>spring-boot-starter-parent</artifactId>
20+
<version>1.4.3.RELEASE</version>
21+
</parent>
22+
23+
<dependencies>
24+
<dependency>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-starter-web</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.springframework.mobile</groupId>
30+
<artifactId>spring-mobile-device</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-freemarker</artifactId>
35+
</dependency>
36+
</dependencies>
37+
38+
<build>
39+
<resources>
40+
<resource>
41+
<directory>src/main/resources</directory>
42+
</resource>
43+
</resources>
44+
<plugins>
45+
<plugin>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-maven-plugin</artifactId>
48+
</plugin>
49+
</plugins>
50+
</build>
51+
52+
<repositories>
53+
<repository>
54+
<id>spring-releases</id>
55+
<name>Spring Milestone Repository</name>
56+
<url>https://repo.spring.io/libs-release</url>
57+
</repository>
58+
</repositories>
59+
60+
<pluginRepositories>
61+
<pluginRepository>
62+
<id>spring-releases</id>
63+
<name>Spring Milestone Repository</name>
64+
<url>https://repo.spring.io/libs-release</url>
65+
</pluginRepository>
66+
</pluginRepositories>
67+
68+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(Application.class, args);
11+
}
12+
13+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.baeldung.controller;
2+
3+
import java.util.logging.Logger;
4+
5+
import org.springframework.mobile.device.Device;
6+
import org.springframework.stereotype.Controller;
7+
import org.springframework.web.bind.annotation.GetMapping;
8+
9+
@Controller
10+
public class IndexController {
11+
12+
private final static Logger LOGGER = Logger.getLogger(IndexController.class.getName());
13+
14+
@GetMapping("/")
15+
public String greeting(Device device) {
16+
17+
String deviceType = "browser";
18+
String platform = "browser";
19+
20+
if (device.isNormal()) {
21+
deviceType = "browser";
22+
} else if (device.isMobile()) {
23+
deviceType = "mobile";
24+
} else if (device.isTablet()) {
25+
deviceType = "tablet";
26+
}
27+
28+
platform = device.getDevicePlatform().name();
29+
30+
if (platform.equalsIgnoreCase("UNKNOWN")) {
31+
platform = "browser";
32+
}
33+
34+
LOGGER.info("Client Device Type: " + deviceType +", Platform: " + platform);
35+
36+
37+
return "index";
38+
}
39+
40+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spring.mobile.devicedelegatingviewresolver.enabled: true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>spring-web</title>
6+
</head>
7+
<body>
8+
<h1>You are into browser version</h1>
9+
</body>
10+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>spring-web</title>
6+
</head>
7+
<body>
8+
<h1>You are into mobile version</h1>
9+
</body>
10+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>spring-web</title>
6+
</head>
7+
<body>
8+
<h1>You are into tablet version</h1>
9+
</body>
10+
</html>

0 commit comments

Comments
 (0)