-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathRouter.java
More file actions
75 lines (66 loc) · 2.76 KB
/
Router.java
File metadata and controls
75 lines (66 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package org.ayfaar.app.controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.FileSystemResource;
import org.springframework.security.web.DefaultRedirectStrategy;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
@Controller
public class Router {
@Autowired ServletContext context;
private final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
@Value("${OPENSHIFT_HOMEDIR}")
private String jbossDir;
@RequestMapping("/")
@ResponseBody
public Object returnIndex(HttpServletRequest request) throws IOException {
String index = "index.html";
String path = request.getServletContext().getRealPath(index);
if (path == null) {
path = jbossDir+"app-deployments/current/repo/src/main/webapp/"+index;
}
return new FileSystemResource(path);
}
@RequestMapping("/new/**")
@ResponseBody
public Object returnNewIndex(HttpServletRequest request, HttpServletResponse response) throws IOException {
String index = "new/index.html";
if (request.getRequestURL().toString().matches("/new/.*/")) {
String url = "/new" +
request.getRequestURL()
.substring(request
.getRequestURL()
.lastIndexOf("/"));
redirectStrategy.sendRedirect(request,response, url);
}
String path = request.getServletContext().getRealPath(index);
if (path == null) {
path = jbossDir+"app-deployments/current/repo/src/main/webapp/"+index;
}
return new FileSystemResource(path);
}
private String find(File dir) {
for (File file : dir.listFiles()) {
if (file.isDirectory() && file.canRead()) {
String result = find(file);
if (!result.equals("not found")) {
return result;
}
} else if (file.getName().equals("google9ff4abadde5fb24d.html")) {
return file.getAbsolutePath();
}
}
return "not found";
}
/*@RequestMapping("/")
public void redirect(HttpServletRequest request, HttpServletResponse response) throws IOException {
redirectStrategy.setContextRelative(true);
redirectStrategy.sendRedirect(request, response, "index.html");
}*/
}