/* Rajarshi Guha * 02/03/2006 * * 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 CDKstruct3DClient { private Call call; private QName qn; private boolean requestError; private String requestErrorMessage; // Initialize the Axis setup public CDKstruct3DClient(String host) { String endpoint = "http://localhost:8080/axis/services/CDKstruct3D"; 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("CDKwsClient (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 getCoords(String[] args) { try { call.removeAllParameters(); call.setOperationName( "get3DCoordinates" ); call.addParameter( "smiles", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter( "forceField", 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("CDKstruct3DClient (getCoords) had an Exception.",t); return null; } } // 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 CDKstruct3DClient SMILES [forceField] [host]\n"); System.out.println("SMILES is a valid SMILES string. Note that strings\n"+ " representing rings may not work very well\n"+ "forceField is optional and currently the only possible\n"+ " values are mm2 or mmf94\n\n"); System.out.println("host can be a valid AXIS server. By default the host"); System.out.println(" is set to http://localhost:8080/axis/services/CDKdesc\n"); System.exit(0); } try { String molstr = args[0]; String ff = "mm2"; String host = null; if (args.length >= 2) { ff = args[1]; } if (args.length == 3) { host = args[2]; } CDKstruct3DClient sr = new CDKstruct3DClient(host); String[] wsargs = {molstr,ff}; sr.getCoords(wsargs); } catch (Exception e) { System.out.println(e.toString()); } } }