/* Rajarshi Guha * 14/12/2004 * * Updated 07/03/2006 to work with the latest version of the QSAR package * Updated 01/03/2006 to be in sync with the latest CVS * * Based on code written by Marty Hall */ import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.encoding.XMLType; import org.apache.axis.AxisFault; import javax.xml.namespace.QName; import javax.xml.rpc.ParameterMode; import java.io.*; import java.util.Vector; import java.util.Iterator; public class CDKdescClient { private Call call; private QName qn; private boolean requestError; private String requestErrorMessage; // Initialize the Axis setup public CDKdescClient(String host) { String endpoint = "http://localhost:8080/axis/services/CDKdesc"; if (host != null) { endpoint = host; } try { Service service = new Service(); call = (Call) service.createCall(); call.setTargetEndpointAddress( new java.net.URL(endpoint) ); } catch (Throwable t) { handleError("CDKClient (constructor) had an Exception.",t); } } // Return true in an error was found public boolean error() { return requestError; } // Return the error message public String getErrorText() { String msg; if (requestError) { msg = requestErrorMessage; } else { msg = ""; } return msg; } public String getDescriptors(String[] args) { try { call.removeAllParameters(); call.setOperationName( "getDescriptors" ); call.addParameter( "moleculeString", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter( "classes", XMLType.XSD_STRING, ParameterMode.IN); call.setReturnType( XMLType.XSD_STRING ); String ret = (String)call.invoke( new Object[] { args[0],args[1] }); System.out.println("CDKdescClient got result : "); System.out.println(ret); return ret; } catch (Throwable t) { handleError("CDKdescClient (getDescriptors) had an Exception.",t); return null; } } public static String readFile(String inFileName) throws IOException { FileReader r = null; try { r = new FileReader(new File(inFileName)); StringBuffer sb = new StringBuffer(); char[] b = new char[8192]; int n; while ((n = r.read(b)) > 0) { sb.append(b, 0, n); } return sb.toString(); } finally { try { r.close(); } catch (IOException e1) { e1.printStackTrace(); } } } // Set error flags, print stack trace public void handleError(String text, Throwable t) { requestError = true; requestErrorMessage = t.toString(); System.out.println(text); System.out.println(t); t.printStackTrace(); return; } // Test program public static void main(String [] args) { if (args.length < 1) { System.out.println("Usage: java CDKdescClient SDFile [class1,class2,...] [host]\n"); System.out.println("SDFile is a molecular structure.\n"); System.out.println("class1,class2 etc are possible descriptor classes. The available"); System.out.println("values are: geometrical, topological, constitutional, electronic"); System.out.println(" hybrid\n"+ "If no value is specifed that all available descriptors will be\n"+ "calculated"); System.out.println("host can be a valid AXIS server. By default the host is set to"); System.out.println("http://localhost:8080/axis/services/CDKdesc\n"); System.exit(0); } try { String testcml = readFile(args[0]); String types = "all"; String host = null; if (args.length >= 2) { types = args[1]; } if (args.length == 3) { host = args[2]; } CDKdescClient sr = new CDKdescClient(host); String[] wsargs = {testcml,types}; sr.getDescriptors(wsargs); } catch (Exception e) { System.out.println(e.toString()); } } }