📄 jembossauthserver.java
字号:
/** * This program is free software; you can redistribute it and/or* modify it under the terms of the GNU General Public License* as published by the Free Software Foundation; either version 2* of the License, or (at your option) any later version.* * This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the* GNU General Public License for more details.* * You should have received a copy of the GNU General Public License* along with this program; if not, write to the Free Software* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.** @author: Copyright (C) Tim Carver* ***************************************************************/package org.emboss.jemboss.server;import org.emboss.jemboss.JembossParams;import org.emboss.jemboss.programs.RunEmbossApplication2;import org.emboss.jemboss.parser.Ajax;import java.io.*;import java.util.*;/**** Jemboss Authenticated Server for Apache Axis (SOAP)* web services**/public class JembossAuthServer{ /** SOAP results directory */ private String tmproot = new String("/tmp/SOAP/emboss/"); /** Jemboss log file */ private final String logFile = new String(tmproot+"/jemboss.log"); /** Jemboss error log file */ private final String errorLog = new String(tmproot+"/jemboss_error.log"); /** file separator */ private final String fs = new String(System.getProperty("file.separator")); /** path separator */ private final String ps = new String(System.getProperty("path.separator")); /** line seperator */ private final String ls = System.getProperty("line.separator");//get paths to EMBOSS /** jemboss properties */ final JembossParams jp = new JembossParams(); /** plplot path */ final String plplot = jp.getPlplot(); /** emboss data path */ final String embossData = jp.getEmbossData(); /** emboss binary path */ final String embossBin = jp.getEmbossBin(); /** path environment variable */ final String embossPath = embossBin + ps + jp.getEmbossPath(); /** emboss run environment */ final private String[] env = { "PATH=" + embossPath, "PLPLOT_LIB=" + plplot, "EMBOSS_DATA=" + embossData// ,"LD_LIBRARY_PATH=/usr/local/lib"// FIX FOR SOME SUNOS }; /** emboss run environment as a string */ private final String environ = "PATH=" + embossPath+ " "+ "PLPLOT_LIB=" + plplot +" "+ "EMBOSS_DATA=" + embossData +" "+ jp.getEmbossEnvironment();// "LD_LIBRARY_PATH=/usr/local/lib"+" ";// FIX FOR SOME SUNOS /** * * Retrieves the ACD file of an application. * @param appName application name * @return Vector of containing the ACD string * */ public Vector show_acd(String appName) { Vector acd = new Vector(4); StringBuffer acdText = new StringBuffer(); final String acdToParse = new String(jp.getAcdDirToParse() + appName + ".acd"); try { String line; BufferedReader in = new BufferedReader(new FileReader(acdToParse)); while((line = in.readLine()) != null ) { if(!line.startsWith("#") && !line.equals("")) { line = line.trim(); line = line.replace('}',')'); acdText.append(line + "\n"); } } } catch (IOException e) { appendToLogFile("Cannot open EMBOSS acd file "+acdToParse,errorLog); } acd.add("status"); acd.add("0"); acd.add("acd"); acd.add(acdText.toString()); return acd; } /** * * Returns the output of the EMBOSS utility wossname * @return wossname output * */ public Vector getWossname() { final String[] envp = jp.getEmbossEnvironmentArray(env); Vector wossOut = new Vector(4); final String embossCommand = new String(embossBin + "wossname -colon -gui -auto"); RunEmbossApplication2 rea = new RunEmbossApplication2(embossCommand, envp,null); rea.waitFor(); wossOut.add("status"); wossOut.add(rea.getStatus()); wossOut.add("wossname"); wossOut.add(rea.getProcessStdout()); return wossOut; } /** * * Returns the help for an application as given by 'tfm' * @param applName application name * @return help * */ public Vector show_help(String applName) { final String[] envp = jp.getEmbossEnvironmentArray(env); final String command = embossBin.concat("tfm " + applName + " -html -nomore"); RunEmbossApplication2 rea = new RunEmbossApplication2(command, envp,null); rea.waitFor(); String helptext = rea.getProcessStdout(); if(helptext.equals("")) helptext = "No help available for this application."; Vector vans = new Vector(2); vans.add("helptext"); vans.add(helptext); return vans; } /** * * Uses JNI to calculate sequence attributes using EMBOSS library call. * @param fileContent sequence filename or database entry * @param seqtype sequence type (seqset/sequence) * @param userName username * @param passwd passwd * @return sequence length, weight & type (protein/nucleotide) * */ public Vector call_ajax(String fileContent, String seqtype, String userName, byte[] passwd) { Vector vans = new Vector(8); Ajax aj = new Ajax(); if(!verifyUser(aj,userName,passwd,vans)) { vans.trimToSize(); return vans; } boolean afile = false; boolean fexists = false; // local file exists? if(fileContent.startsWith(fs)) { int ind = fileContent.lastIndexOf(fs); String fdir = fileContent.substring(0,ind); String ffile = fileContent.substring(ind+1).trim(); boolean ok = aj.listFiles(userName,passwd,environ,fdir); if(!ok) return returnError(aj,"listFiles error in call_ajax",userName); if(aj.getOutStd().indexOf(fs+ffile+"\n") > -1) fexists = true; else return returnError(aj,"listFiles error in call_ajax",userName); } // create temporary file String fn = null; if( ((fileContent.indexOf(":") < 0) || (fileContent.indexOf("\n") > 0) ) && (!fexists) ) { try { fn = tmproot+fs+userName+fs+".jembosstmp"; boolean ok = aj.putFile(userName,passwd,environ, fn,fileContent.getBytes()); if(!ok) return returnError(aj,"putFile error in call_ajax",userName); afile = true; } catch (Exception ioe) { String dat = new Date().toString(); dat = dat.replace(':','_'); appendToLogFile(userName+":: "+dat+ " Exception: call_ajax creating "+fn, errorLog); vans.add("status"); vans.add("1"); vans.trimToSize(); return vans; } } else { fn = fileContent; //looks like db entry or local file name } if( fexists || afile || //call ajax if sequence file fn.indexOf(":") > 0 ) //or db { boolean ok = false; try { if(seqtype.startsWith("seqset")) ok = aj.seqsetAttrib(userName,passwd,environ,fn); else ok = aj.seqAttrib(userName,passwd,environ,fn); if(!ok) return returnError(aj,"seqAttrib or seqsetAttrib error",userName); } catch (Exception e) { String dat = new Date().toString(); dat = dat.replace(':','_'); appendToLogFile(userName+":: "+dat+ " Exception: call_ajax status not ok", errorLog); vans.add("status"); vans.add("1"); vans.trimToSize(); return vans; } } if(afile) aj.delFile(userName,passwd,environ,fn); for(int i=0;i<passwd.length;i++) passwd[i] = '\0'; vans.add("length"); vans.add(new Integer(aj.length_soap)); vans.add("protein"); vans.add(new Boolean(aj.protein_soap)); vans.add("weight"); vans.add(new Float(aj.weight_soap)); vans.add("status"); vans.add("0"); return vans; } /** * * Uses JNI to calculate sequence attributes using EMBOSS library call. * @param fileContent sequence filename or database entry * @param seqtype sequence type (seqset/sequence) * @return sequence length, weight & type (protein/nucleotide) * */ public Vector call_ajax(String fileContent, String seqtype) { boolean afile = false; String fn = null; File tf = null; Vector vans = new Vector(8); // create temporary file if( ((fileContent.indexOf(":") < 0) || (fileContent.indexOf("\n") > 0) ) && !((new File(fileContent)).exists()) ) { afile = true; try { File tmprootDir = new File(tmproot); tf = File.createTempFile("tmp",".jembosstmp", tmprootDir); PrintWriter out = new PrintWriter(new FileWriter(tf)); out.println(fileContent); out.close(); fn = new String(tf.getCanonicalPath()); } catch (IOException ioe) { appendToLogFile("IOException: call_ajax creating tmp.jembosstmp", errorLog); vans.add("status"); vans.add("1"); vans.trimToSize(); return vans; } } else { fn = fileContent; //looks like db entry or local file name } boolean ok = false; Ajax aj = null; if( ((new File(fn)).exists()) || //call ajax if sequence file (fn.indexOf(":") > 0) ) //or db { try { aj = new Ajax(); if(seqtype.startsWith("seqset")) ok = aj.seqsetType(fn); else ok = aj.seqType(fn); } catch (Exception e) { appendToLogFile("Exception: call_ajax status not ok", errorLog); vans.add("status"); vans.add("1"); vans.trimToSize(); return vans; } } if(ok) {// System.out.println("STATUS OK"); vans.add("length"); vans.add(new Integer(aj.length)); vans.add("protein"); vans.add(new Boolean(aj.protein)); vans.add("weight"); vans.add(new Float(aj.weight)); vans.add("status"); vans.add("0"); } else { appendToLogFile("Error: call_ajax status not ok", errorLog); vans.add("status"); vans.add("1"); vans.trimToSize(); } if(afile) tf.delete(); return vans; } /** * * Returns the databases held on the server * @return output from 'showdb' * */ public Vector show_db() { final String[] envp = jp.getEmbossEnvironmentArray(env); Vector showdbOut = new Vector(8); final String embossCommand = new String(embossBin + "showdb -auto"); RunEmbossApplication2 rea = new RunEmbossApplication2(embossCommand, envp,null); rea.waitFor(); showdbOut.add("status"); showdbOut.add(rea.getStatus()); if(!rea.getStatus().equals("0")) { showdbOut.trimToSize(); return showdbOut; } showdbOut.add("showdb"); showdbOut.add(rea.getProcessStdout()); // find available matrices String dataFile[] = (new File(embossData)).list(new FilenameFilter() { public boolean accept(File dir, String name) { File fileName = new File(dir, name); return !fileName.isDirectory(); }; }); StringBuffer matrices = new StringBuffer(); for(int i=0;i<dataFile.length;i++) matrices.append(dataFile[i]+"\n"); showdbOut.add("matrices"); showdbOut.add(matrices.toString()); // find available codon usage tables dataFile = (new File(embossData+fs+"CODONS")).list(new FilenameFilter() { public boolean accept(File dir, String name) { File fileName = new File(dir, name); return !fileName.isDirectory(); }; }); matrices = new StringBuffer(); for(int i=0;i<dataFile.length;i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -