view webapp/WEB-INF/src/HumanEchoServlet.java @ 8:76f809129f98

build file now correctly compiling the TestEchoClass; the TestEchoClass now calls the matlab function with the output filename arg.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Fri, 29 Nov 2013 13:04:29 +0000
parents b6acfffd25cd
children 2129d2bac6cb
line wrap: on
line source
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());
*/
    }
}