Mercurial > hg > human-echolocation-java-webapp
changeset 0:b6acfffd25cd
Initial commit of code. Not in a working state yet. This code is based on the JavaEndToEnd example described on Mathwork's MATLAB Application Deplyment (Web Example Guide for R2013b) - see this project's documentation for more details.
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Wed, 27 Nov 2013 11:10:43 +0000 |
parents | |
children | 5f60298bcc0b |
files | INSTALL.txt webapp/ExamplesPage.jsp webapp/StyleSheet.css webapp/WEB-INF/README.txt webapp/WEB-INF/mcode/README.txt webapp/WEB-INF/src/HumanEchoServlet.java webapp/WEB-INF/src/TestEchoClass.java webapp/WEB-INF/web.xml |
diffstat | 8 files changed, 282 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/INSTALL.txt Wed Nov 27 11:10:43 2013 +0000 @@ -0,0 +1,40 @@ +Build Instructions: + + + +On OSX you need to + + export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/Applications/MATLAB_R2013b.app/sys/os/maci64/:/Applications/MATLAB_R2013b.app/runtime/maci64/:/Applications/MATLAB_R2013b.app/bin/maci64/ + +1. Copy your web servers servlet-api.jar file into this directory. + +2. Copy the javabuilder.jar file from your MATLAB or MCR install root in the direcotry /toolbox/javabuilder/jar/javabuilder.jar to the web applications lib folder ./webapp/WEB-INF/lib + +3. Recompile the MATLAB component by running the following MCC command: + + /Applications/MATLAB_R2013b.app/bin/mcc -W "java:uk.ac.soton.isvr,HumanEcho" -d ./scratch -T "link:lib" -v "class{HumanEcho:./webapp/WEB-INF/mcode/gen_echo.m}" + +4. Copy the deployed component from the scratch folder to the web applications lib folder .\webapp\WEB-INF\lib + + cp ./scratch/isvr.jar ./webapp/WEB-INF/lib + +5. Compile the web application making sure to reference the servlet-api.jar, the deployed component jar, and the javabuilder.jar + + javac -cp servlet-api.jar:./webapp/WEB-INF/lib/javabuilder.jar:./webapp/WEB-INF/lib/examples.jar: -d ./webapp/WEB-INF/classes ./webapp/WEB-INF/src/MagicSquareServlet.java + +This will create the servlet: + + webapp/WEB-INF/classes/HumanEchoServlet.class + +6. Navigate to the web applications directory and create the war file. + + cd webapp + jar -cvf ..\JavaEndToEnd.war . + cd .. + +7. Copy this JavaEndToEnd.war file into your web servers webapps direcotry + +8. Start the web server and navigate in a browser to the following url: +http://localhost:8080/JavaEndToEnd/ExamplesPage.jsp + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/webapp/ExamplesPage.jsp Wed Nov 27 11:10:43 2013 +0000 @@ -0,0 +1,73 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<html> + <head> + <title>Calculation Services</title> + + <% + String sizeStr = request.getParameter("size"); + int size = 5; + boolean sizeSet = false; + if(sizeStr!=null && sizeStr.length()>0) + { + size = Integer.parseInt(sizeStr); + sizeSet = true; + } + %> + + <link rel="Stylesheet" type="text/css" media=all href="./StyleSheet.css" /> + <link href="StyleSheet.css" rel="stylesheet" type="text/css" /> + </head> + + <body> + <form method="get"> + <div style="text-align: center"> + <table width="760" cellpadding="0" cellspacing="0"> + <tr> + <td><img src="header_bg.jpg" alt="Header Image Not Found" width="779" height="72" /></td> + </tr> + </table> + <br /> + + <h1> Calculation Services</h1> + + Calculate Magic Square + <br> + Size: + <input type="text" name="size" size="8" value="<%=size%>" > + <br> + <input type="submit" value="Calculate"> + <br> + <br /> + <script type="text/javascript"> + try + { + var objXHR = new XMLHttpRequest(); + } + catch (e) + { + try + { + var objXHR = new ActiveXObject('Msxml2.XMLHTTP'); + } + catch (e) + { + try + { + var objXHR = new ActiveXObject('Microsoft.XMLHTTP'); + } + catch (e) + { + document.write('XMLHttpRequest not supported'); + } + } + } + objXHR.open('GET','MagicSquare?size=<%=size%>',false); + objXHR.send(null); + document.writeln(objXHR.responseText); + </script> + <br> + </div> + </form> + </body> +</html> +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/webapp/StyleSheet.css Wed Nov 27 11:10:43 2013 +0000 @@ -0,0 +1,18 @@ +body +{ + font-size: 11pt; + font-family: Arial; + background-color: whitesmoke; +} +LABEL +{ + font-size: 12pt; + font-family: Arial; +} +H1 +{ + font-family: Arial; + font-weight: bold; + font-size: 22pt; + color: black; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/webapp/WEB-INF/README.txt Wed Nov 27 11:10:43 2013 +0000 @@ -0,0 +1,14 @@ +You need to copy the following files to this folder: + +Copy the javabuilder.jar file from your MATLAB or MCR install root in +the directory /toolbox/javabuilder/jar/javabuilder.jar to the web +applications lib folder ./webapp/WEB-INF/lib + + + +You should copy the generated JAR file here: + +cp ./scratch/examples.jar ./webapp/WEB-INF/lib + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/webapp/WEB-INF/mcode/README.txt Wed Nov 27 11:10:43 2013 +0000 @@ -0,0 +1,1 @@ +You should put your MATLAB code in this folder.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/webapp/WEB-INF/src/HumanEchoServlet.java Wed Nov 27 11:10:43 2013 +0000 @@ -0,0 +1,76 @@ +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.ServletException; +import javax.servlet.ServletConfig; +import java.io.IOException; +import uk.ac.soton.isvr.*; + +import com.mathworks.toolbox.javabuilder.MWJavaObjectRef; +import com.mathworks.toolbox.javabuilder.MWNumericArray; +import com.mathworks.toolbox.javabuilder.MWException; + +public class HumanEchoServlet extends HttpServlet { + private HumanEcho echo; + + public void init(ServletConfig config) throws ServletException { + super.init(config); + + try { + echo = new HumanEcho(); + } + catch(MWException e) { + e.printStackTrace(); + } + } + + public void destroy() { + super.destroy(); + + if(echo!=null) { + echo.dispose(); + } + } + + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // Test parameter + MWNumericArray test = new MWNumericArray(Integer.parseInt(request.getParameter("test"))); + + double[][] square = new double[0][]; + + // double[][] square = new double[0][]; + // WebFigure figure = null; + + try { + // refers to the mcode function gen_echo.m + Object[] result = echo.gen_echo(1, test); + + MWNumericArray array = (MWNumericArray)result[0]; + square = (double[][])array.toArray(); + + } + catch(MWException e) { + e.printStackTrace(); + } + + StringBuffer buffer = new StringBuffer(); + + buffer.append("<BR>"); + buffer.append("<BR>"); + + buffer.append("<TABLE >"); + for (double[] row : square) + { + buffer.append("<TR>"); + for (double value : row) + { + buffer.append("<TH>"); + buffer.append(new Double(value).intValue()); + } + } + buffer.append("</TABLE>"); + buffer.append("<BR>"); + response.getOutputStream().print(buffer.toString()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/webapp/WEB-INF/src/TestEchoClass.java Wed Nov 27 11:10:43 2013 +0000 @@ -0,0 +1,33 @@ +import com.mathworks.toolbox.javabuilder.MWJavaObjectRef; +import com.mathworks.toolbox.javabuilder.MWNumericArray; +import com.mathworks.toolbox.javabuilder.MWException; + +import uk.ac.soton.isvr.*; + +public class TestEchoClass { + + int test = 4; + + double[][] square = new double[0][]; + + + public static void main(String[] args) { + System.out.println("YOOOOOO, Bs"); + + HumanEcho echo; + + try { + echo = new HumanEcho(); + Object[] result = echo.gen_echo(1); + + MWNumericArray array = (MWNumericArray)result[0]; + //square = (double[][])array.toArray(); + + } + catch(MWException e) { + e.printStackTrace(); + } + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/webapp/WEB-INF/web.xml Wed Nov 27 11:10:43 2013 +0000 @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<web-app xmlns="http://java.sun.com/xml/ns/javaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee + http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" + version="2.5"> + + <servlet> + <servlet-name>MagicSquareServlet</servlet-name> + <servlet-class>MagicSquareServlet</servlet-class> + </servlet> + <servlet-mapping> + <servlet-name>MagicSquareServlet</servlet-name> + <url-pattern>/MagicSquare</url-pattern> + </servlet-mapping> + + <servlet> + <servlet-name>WebFigures</servlet-name> + <servlet-class> + com.mathworks.toolbox.javabuilder.webfigures.WebFiguresServlet + </servlet-class> + </servlet> + <servlet-mapping> + <servlet-name>WebFigures</servlet-name> + <url-pattern>/WebFigures/*</url-pattern> + </servlet-mapping> +</web-app>