# HG changeset patch # User luisf # Date 1385550643 0 # Node ID b6acfffd25cdf5fd8802257eccf58cf45e214550 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. diff -r 000000000000 -r b6acfffd25cd INSTALL.txt --- /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 + + diff -r 000000000000 -r b6acfffd25cd webapp/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" %> + + + Calculation Services + + <% + String sizeStr = request.getParameter("size"); + int size = 5; + boolean sizeSet = false; + if(sizeStr!=null && sizeStr.length()>0) + { + size = Integer.parseInt(sizeStr); + sizeSet = true; + } + %> + + + + + + +
+
+ + + + +
Header Image Not Found
+
+ +

Calculation Services

+ + Calculate Magic Square +
+ Size: + +
+ +
+
+ +
+
+
+ + + diff -r 000000000000 -r b6acfffd25cd webapp/StyleSheet.css --- /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; +} diff -r 000000000000 -r b6acfffd25cd webapp/WEB-INF/README.txt --- /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 + + + diff -r 000000000000 -r b6acfffd25cd webapp/WEB-INF/mcode/README.txt --- /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. diff -r 000000000000 -r b6acfffd25cd webapp/WEB-INF/src/HumanEchoServlet.java --- /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("
"); + buffer.append("
"); + + buffer.append(""); + for (double[] row : square) + { + buffer.append(""); + for (double value : row) + { + buffer.append("
"); + buffer.append(new Double(value).intValue()); + } + } + buffer.append("
"); + buffer.append("
"); + response.getOutputStream().print(buffer.toString()); + } +} diff -r 000000000000 -r b6acfffd25cd webapp/WEB-INF/src/TestEchoClass.java --- /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(); + } + + } + +} diff -r 000000000000 -r b6acfffd25cd webapp/WEB-INF/web.xml --- /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 @@ + + + + + MagicSquareServlet + MagicSquareServlet + + + MagicSquareServlet + /MagicSquare + + + + WebFigures + + com.mathworks.toolbox.javabuilder.webfigures.WebFiguresServlet + + + + WebFigures + /WebFigures/* + +