summaryrefslogtreecommitdiff
path: root/WEB-INF/classes/SciExec.java~
diff options
context:
space:
mode:
authorsarangsingh292016-07-18 22:09:19 +0530
committersarangsingh292016-07-18 22:09:19 +0530
commit623f4797aaf29222aab9d9a44d7c2f8d09622d1f (patch)
treebe3a9c1d2458b684c6135fa16484cb77e1373c68 /WEB-INF/classes/SciExec.java~
parent8c702e995aa4f252b2816b7e905c4c1236673172 (diff)
downloadxcos-on-web-623f4797aaf29222aab9d9a44d7c2f8d09622d1f.tar.gz
xcos-on-web-623f4797aaf29222aab9d9a44d7c2f8d09622d1f.tar.bz2
xcos-on-web-623f4797aaf29222aab9d9a44d7c2f8d09622d1f.zip
Added the servlet code and directions to run.
Diffstat (limited to 'WEB-INF/classes/SciExec.java~')
-rwxr-xr-xWEB-INF/classes/SciExec.java~91
1 files changed, 91 insertions, 0 deletions
diff --git a/WEB-INF/classes/SciExec.java~ b/WEB-INF/classes/SciExec.java~
new file mode 100755
index 0000000..c4287aa
--- /dev/null
+++ b/WEB-INF/classes/SciExec.java~
@@ -0,0 +1,91 @@
+import java.io.*;
+import javax.servlet.*;
+import java.util.*;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.FilenameUtils;
+
+
+public class SciExec extends GenericServlet {
+
+
+ public void service(ServletRequest request,ServletResponse response) throws ServletException, IOException
+ {
+ PrintWriter pw = response.getWriter();
+
+
+
+
+ InputStream is = null;
+ ByteArrayOutputStream baos = null;
+ List<String> commands = new ArrayList<String>();
+ commands.add("scilab-adv-cli");
+ commands.add("-noatomsautoload");
+ commands.add("-nogui");
+ commands.add("-nb");
+ commands.add("-e");
+
+ String imagePath="";
+ String fileNameWithoutExt="";
+ //commands.add("plot3d();xs2png(gcf(),'img2.png');exit();");
+ /*String data=request.getParameter("name");
+ pw.println(data);
+ commands.add("echo "+data+" > /home/saarang/Softwares/apache-tomcat-8.0.36/webapps/sci/servlet/file.xcos");*/
+ //commands.add("driver('PNG');xinit('/home/saarang/apache-tomcat-8.0.36/webapps/worknogui/servlet/ans"+k+".png');loadXcosLibs();importXcosDiagram('/home/saarang/apache-tomcat-8.0.36/file.xcos');xcos_simulate(scs_m,4);mode(2);xend();quit();");
+ ProcessBuilder pb = new ProcessBuilder(commands);
+ try
+ {
+ InputStream inputStream = request.getInputStream();
+
+ File xcosFile = File.createTempFile("usr-", ".xcos");
+ OutputStream outputStream = new FileOutputStream(xcosFile);
+ IOUtils.copy(inputStream, outputStream);
+ outputStream.close();
+
+ String tempPath = xcosFile.getAbsolutePath();
+
+ String parentPath = xcosFile.getParent();
+ fileNameWithoutExt = FilenameUtils.removeExtension(xcosFile.getName());
+
+ imagePath = "/home/saarang/apache-tomcat-8.0.36/webapps/xcos-on-web/servlet"+File.separator + fileNameWithoutExt + ".png";
+
+ commands.add("driver('PNG');xinit('"+imagePath+"');loadXcosLibs();importXcosDiagram('"+tempPath+"');xcos_simulate(scs_m,4);mode(2);xend();quit();");
+
+ Process prs = pb.start();
+ is = prs.getInputStream();
+ byte[] b = new byte[1024];
+ int size = 0;
+ baos = new ByteArrayOutputStream();
+ while((size = is.read(b)) != -1){
+ baos.write(b, 0, size);
+ }
+ System.out.println(new String(baos.toByteArray()));
+
+
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ catch(Exception e)
+ {
+ /*System.out.println(e.toString()+"Some Exception");*/
+ pw.println("Exception");
+ }
+ finally
+ {
+ try {
+ if(is != null) is.close();
+ if(baos != null) baos.close();
+ } catch (Exception ex){}
+ }
+ pw.println("servlet/"+fileNameWithoutExt+".png");
+ //pw.println(request.getParameter("name"));
+ pw.close();
+ }
+
+}