Mercurial > hg > human-echolocation-java-webapp
comparison src/HumanEchoServlet.java @ 23:73a60617e1a7
Moved the src and classes folders to the root of the workspace; renamed the classes folder to build
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Fri, 06 Dec 2013 12:51:59 +0000 |
parents | webapp/WEB-INF/src/HumanEchoServlet.java@533821b15f83 |
children | 1d1122584af9 |
comparison
equal
deleted
inserted
replaced
22:41bc856ceaea | 23:73a60617e1a7 |
---|---|
1 /* | |
2 * Classname | |
3 * | |
4 * Version information | |
5 * | |
6 * 3 December 2013 | |
7 * | |
8 * Copyright notice | |
9 */ | |
10 | |
11 import java.util.Properties; | |
12 import java.io.IOException; | |
13 | |
14 import org.apache.log4j.Logger; | |
15 | |
16 import javax.servlet.http.HttpServlet; | |
17 import javax.servlet.http.HttpServletRequest; | |
18 import javax.servlet.http.HttpServletResponse; | |
19 import javax.servlet.ServletException; | |
20 import javax.servlet.ServletConfig; | |
21 import javax.servlet.RequestDispatcher; | |
22 | |
23 import com.mathworks.toolbox.javabuilder.MWJavaObjectRef; | |
24 import com.mathworks.toolbox.javabuilder.MWNumericArray; | |
25 import com.mathworks.toolbox.javabuilder.MWStructArray; | |
26 import com.mathworks.toolbox.javabuilder.MWException; | |
27 import com.mathworks.toolbox.javabuilder.internal.MCRConfiguration; | |
28 | |
29 import uk.ac.soton.isvr.*; | |
30 | |
31 public class HumanEchoServlet extends HttpServlet { | |
32 private HumanEcho echo; | |
33 | |
34 private static Logger logger = Logger.getLogger(HumanEchoServlet.class); | |
35 | |
36 public void init(ServletConfig config) throws ServletException { | |
37 super.init(config); | |
38 | |
39 // reading properties file | |
40 try { | |
41 Properties properties = new Properties(); | |
42 properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("myapp.properties")); | |
43 | |
44 //get the property value and print it out | |
45 System.out.println(properties.getProperty("tmpdir")); | |
46 System.out.println(properties.getProperty("outdir")); | |
47 | |
48 } catch (IOException e) { | |
49 e.printStackTrace(); | |
50 } | |
51 | |
52 try { | |
53 echo = new HumanEcho(); | |
54 } | |
55 catch(MWException e) { | |
56 e.printStackTrace(); | |
57 } | |
58 } | |
59 | |
60 public void destroy() { | |
61 super.destroy(); | |
62 | |
63 if(echo!=null) { | |
64 echo.dispose(); | |
65 } | |
66 } | |
67 | |
68 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
69 | |
70 // todo: validate/normalise distance | |
71 int dist = Integer.parseInt(request.getParameter("dist")); | |
72 MWStructArray Input = null; | |
73 HumanEcho echo; | |
74 | |
75 try { | |
76 echo = new HumanEcho(); | |
77 | |
78 logger.error("We are logging!"); | |
79 | |
80 // Matlab structure: | |
81 // Input = struct('dist', 0.9, 'azim', 0, 'orient', 'horz', 'dirweight', 0.2, 'outputfname', 'foo.wav') | |
82 | |
83 String[] InputStructFields = {"dist", "azim", "orient", "dirweight", "outputfname"}; | |
84 Input = new MWStructArray(1, 1, InputStructFields); | |
85 Input.set("dist", 1, Double.valueOf(dist)); | |
86 Input.set("azim", 1, Double.valueOf(0)); | |
87 Input.set("orient", 1, "horz"); | |
88 Input.set("dirweight", 1, Double.valueOf(0.2)); | |
89 | |
90 // the ofname should depend on the parameters | |
91 StringBuilder sb = new StringBuilder(); | |
92 sb.append("e_d"); | |
93 sb.append(dist); | |
94 sb.append(".wav"); | |
95 String outputfname = sb.toString(); | |
96 | |
97 Input.set("outputfname", 1, outputfname); | |
98 | |
99 // todo: before calling should test if wav already exists.. | |
100 Object[] result = echo.simulateBinauralSignals(Input); | |
101 } | |
102 catch(MWException e) { | |
103 e.printStackTrace(); | |
104 } | |
105 | |
106 System.out.println("MCRROOT: " + System.getenv("MCRROOT")); | |
107 System.out.println("PATH: " + System.getenv("PATH")); | |
108 System.out.println(MCRConfiguration.isInstalledMCR()); | |
109 | |
110 | |
111 StringBuffer buffer = new StringBuffer(); | |
112 | |
113 buffer.append("<BR>"); | |
114 buffer.append("<BR>"); | |
115 | |
116 buffer.append("worked, ?"); | |
117 | |
118 buffer.append("<BR>"); | |
119 buffer.append("<BR>"); | |
120 | |
121 /* | |
122 buffer.append("<TABLE >"); | |
123 for (double[] row : square) | |
124 { | |
125 buffer.append("<TR>"); | |
126 for (double value : row) | |
127 { | |
128 buffer.append("<TH>"); | |
129 buffer.append(new Double(value).intValue()); | |
130 } | |
131 } | |
132 buffer.append("</TABLE>"); | |
133 buffer.append("<BR>"); | |
134 response.getOutputStream().print(buffer.toString()); | |
135 */ | |
136 } | |
137 } |