comparison src/HumanEchoServlet.java @ 51:ebfb3b91fb06

Various invocation fixes, plus updated isvr.jar
author Chris Cannam
date Fri, 28 Feb 2014 16:13:29 +0000
parents 398a53b30079
children b27106b380d8
comparison
equal deleted inserted replaced
50:85667ba3d75e 51:ebfb3b91fb06
35 private String wavdir = ""; 35 private String wavdir = "";
36 36
37 public void init(ServletConfig config) throws ServletException { 37 public void init(ServletConfig config) throws ServletException {
38 super.init(config); 38 super.init(config);
39 39
40 System.err.println("In init"); 40 logger.info("In init");
41 41
42 logger.error("java.library.path is " + 42 logger.info("java.library.path is " +
43 System.getProperty("java.library.path")); 43 System.getProperty("java.library.path"));
44 44
45 try { 45 try {
46 // Read directory properties 46 // Read directory properties
47 Properties properties = new Properties(); 47 Properties properties = new Properties();
48 properties.load 48 properties.load
49 (Thread.currentThread().getContextClassLoader(). 49 (Thread.currentThread().getContextClassLoader().
50 getResourceAsStream("myapp.properties")); 50 getResourceAsStream("HumanEcho.properties"));
51 51
52 wavdir = properties.getProperty("outdir"); 52 wavdir = properties.getProperty("outdir");
53 53
54 System.err.println("WAV file directory is " + wavdir); 54 logger.info("WAV file directory is " + wavdir);
55 55
56 } catch (IOException e) { 56 } catch (Exception e) {
57 logger.error("Failed to load app properties: " + e.getMessage());
57 e.printStackTrace(); 58 e.printStackTrace();
58 } 59 }
59 60
60 try { 61 try {
61 // Test that we can construct one of the MATLAB objects 62 // Test that we can construct one of the MATLAB objects
62 63
63 long before = System.currentTimeMillis(); 64 long before = System.currentTimeMillis();
64 echo = new HumanEcho(); 65 echo = new HumanEcho();
65 long after = System.currentTimeMillis(); 66 long after = System.currentTimeMillis();
66 System.err.println("Created a HumanEcho object: it took " + (after - before) + " ms"); 67 logger.info("Created a HumanEcho object: it took " + (after - before) + " ms");
67 } catch (MWException e) { 68 } catch (MWException e) {
69 logger.error("Failed to construct HumanEcho object: " + e.getMessage());
68 e.printStackTrace(); 70 e.printStackTrace();
69 } 71 }
72
73 logger.info("Init completed");
70 } 74 }
71 75
72 public void destroy() { 76 public void destroy() {
73 super.destroy(); 77 super.destroy();
74 78
77 } 81 }
78 } 82 }
79 83
80 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 84 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
81 85
82 System.err.println("In doGet"); 86 logger.info("In doGet");
83 87
84 // todo: validate/normalise distance 88 // todo: validate/normalise distance
85 int dist = Integer.parseInt(request.getParameter("dist")); 89 int dist = Integer.parseInt(request.getParameter("dist"));
86 90
87 logger.info("String azim is: " + request.getParameter("azim")); 91 logger.info("String azim is: " + request.getParameter("azim"));
90 MWStructArray Input = null; 94 MWStructArray Input = null;
91 HumanEcho echo; 95 HumanEcho echo;
92 96
93 String outputfname = new String(); 97 String outputfname = new String();
94 98
95 System.err.println("Got dist and azim"); 99 logger.info("Got dist and azim");
96 100
97 try { 101 try {
98 //!!! erch, shouldn't be creating a new one on each request as well as a global one 102 //!!! erch, shouldn't be creating a new one on each request as well as a global one
99 echo = new HumanEcho(); 103 echo = new HumanEcho();
100 104
101 logger.error("We are logging!"); 105 logger.info("Property catalina.base is " + System.getProperty("catalina.base"));
102 logger.warn(System.getProperty("catalina.base"));
103
104 System.err.println("Done some logging");
105 System.err.println(System.getProperty("catalina.base"));
106 106
107 // Matlab structure: 107 // Matlab structure:
108 // Input = struct('dist', 0.9, 'azim', 0, 'orient', 'horz', 'dirweight', 0.2, 'outdir', '/tmp/wav', 'outname', 'foo.wav') 108 // Input = struct('dist', 0.9, 'azim', 0, 'orient', 'horz', 'dirweight', 0.2, 'outdir', '/tmp/wav', 'outname', 'foo.wav')
109 109
110 String[] InputStructFields = {"dist", "azim", "orient", "dirweight", "outdir", "outname"}; 110 String[] InputStructFields = {"dist", "azim", "orient", "dirweight", "outdir", "outname"};
128 128
129 // todo: before calling should test if wav already exists.. 129 // todo: before calling should test if wav already exists..
130 Object[] result = echo.simulateBinauralSignals(Input); 130 Object[] result = echo.simulateBinauralSignals(Input);
131 } 131 }
132 catch(MWException e) { 132 catch(MWException e) {
133 logger.error("Failed to calculate simulateBinauralSignals: " + e.getMessage());
133 e.printStackTrace(); 134 e.printStackTrace();
134 } 135 }
135 136
136 // Creating the stream 137 // Creating the stream
137 ServletOutputStream stream = null; 138 ServletOutputStream stream = null;
153 //read from the file; write to the ServletOutputStream 154 //read from the file; write to the ServletOutputStream
154 while((readBytes = buf.read( )) != -1) 155 while((readBytes = buf.read( )) != -1)
155 stream.write(readBytes); 156 stream.write(readBytes);
156 157
157 } catch (IOException ioe){ 158 } catch (IOException ioe){
159 logger.error("Failed to read wav data: " + ioe.getMessage());
158 throw new ServletException(ioe.getMessage( )); 160 throw new ServletException(ioe.getMessage( ));
159 } finally { 161 } finally {
160 //close the input/output streams 162 //close the input/output streams
161 if(stream != null) 163 if(stream != null)
162 stream.close( ); 164 stream.close( );
163 165
164 if(buf != null) 166 if(buf != null)
165 buf.close( ); 167 buf.close( );
166 } 168 }
167 169
168 logger.info("Wrote file:" + outputfname); 170 logger.info("Wrote file: " + outputfname);
169 } 171 }
170 } 172 }