/* Rajarshi Guha * 14/12/2004 * * Updated 01/03/2006 - Synced with latest CDK. Added usage message * * 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.util.Vector; import java.util.Iterator; public class CDKsimClient { private Call call; private QName qn; private boolean requestError; private String requestErrorMessage; // Initialize the Axis setup public CDKsimClient(String host) { String endpoint = "http://localhost:8080/axis/services/CDKsim"; 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("CDKsimClient (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 double getSim(String target, String query, int l, int d) { try { call.removeAllParameters(); call.setOperationName( "getSim" ); call.addParameter( "target", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter( "query", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter( "length", XMLType.XSD_INTEGER, ParameterMode.IN); call.addParameter( "depth", XMLType.XSD_INTEGER, ParameterMode.IN); call.setReturnType( XMLType.XSD_DOUBLE ); Double ret = (Double)call.invoke( new Object[] { target, query, new Integer(l), new Integer(d) }); if (ret == null) { System.out.println("Error in SOAP call"); } double retval = ret.doubleValue(); System.out.println("CDKsimClient got result : "); System.out.println(retval); return retval; } catch (Throwable t) { handleError("CDKsimClient (getFPString) had an Exception.",t); return (-1.0); } } // 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 < 2) { System.out.println("Usage: java CDKsimClient target query [host]"); System.out.println("\ntarget and query should be valid SMILES strings"); System.out.println("If host is not specified then http://localhost:8080/axis/services/CDKws is used\n"); System.exit(0); } String host = null; if (args.length == 3) { host = args[2]; } CDKsimClient sr = new CDKsimClient(host); sr.getSim(args[0], args[1], 1024, 6); } }