import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.rmi.RemoteException; import java.util.Hashtable; import java.util.Iterator; import java.util.Set; import javax.xml.namespace.QName; import javax.xml.rpc.ServiceException; import org.apache.axis.AxisFault; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.w3c.dom.Element; public class ClustalWCOrig { public static void main(String[] args) { try { final String server = "http://bibiwsserv.techfak.uni-bielefeld.de"; final URL wsdl = new URL("http://bibiserv.techfak.uni-bielefeld.de/wsdl/ClustalW.wsdl"); //final String server = "http://bibiwstest.techfak.uni-bielefeld.de"; //final URL wsdl = new URL("http://bibiwstest.techfak.uni-bielefeld.de/ClustalW/axis/ClustalWPort?wsdl"); // parameter to hashtable Hashtable paramshash = parseParameter(args); if (!paramshash.containsKey("F")) { System.err.println("java "+ClustalWCOrig.class.getSimpleName()+" -F \n\t[-MATRIX (BLOSUM|PAM|GONNET|ID|WUERZBURG)]\n\t[-GAPOPEN ]\n\t[-GAPEXT "); System.exit(0); } // read sequence from file File infile = new File((String) paramshash.get("F")); BufferedReader reader = new BufferedReader(new FileReader(infile)); String line; StringBuffer sequence = new StringBuffer(); while ((line = reader.readLine()) != null) { sequence.append(line + "\n"); } reader.close(); // remove File parameter paramshash.remove("F"); // prepare the call (the same for all called methods) Service ser = new Service(wsdl, new QName( server+"/ClustalW/axis/ClustalWPort", "ClustalWImplementationService")); Call call = (Call) ser.createCall(new QName("ClustalWPort"), "request_orig"); // call and get id String id = (String) call.invoke(new Object[] {hashtable2array(paramshash), sequence.toString() }); // print id on STDOUT System.err.println("get id - '" + id + "'"); int statuscode = 601; while ((statuscode > 600) && (statuscode < 700)) { try { Thread.sleep(2500); call = (Call) ser.createCall(new QName("ClustalWPort"), "response_orig"); // call and get result as DOM Tree(if finished) String result = (String) call.invoke(new Object[] { id }); // and print it to STDOUT System.out.println(result); // finished statuscode = 600; } catch (InterruptedException e) { System.err.println("process can't sleep!"); } catch (RemoteException e) { // on error WS will throw a soapfault as hobitstatuscode Element root = ((AxisFault) e).lookupFaultDetail(new QName( "http://hobit.sourceforge.net/xsds/hobitStatuscode.xsd", "hobitStatuscode")); if (root == null) { System.err.println("ws remote error (no Hobitstatuscode): " + e.toString()); System.exit(1); } String description = root.getLastChild().getFirstChild().getNodeValue(); statuscode = Integer.parseInt(root.getFirstChild().getFirstChild().getNodeValue()); // print Statusinformation to STDERR System.err.println("(" + statuscode + " - " + description + ")"); } } // error handling with proper information for the user } catch (RemoteException e) { // on error WS will throw a soapfault as hobitstatuscode Element root = ((AxisFault) e).lookupFaultDetail(new QName( "http://hobit.sourceforge.net/xsds/hobitStatuscode.xsd", "hobitStatuscode")); if (root == null) { System.err.println("ws remote error (no Hobitstatuscode): " + e.toString()); System.exit(1); } String description = root.getLastChild().getFirstChild().getNodeValue(); String code = root.getFirstChild().getFirstChild().getNodeValue(); System.out.println("Statuscode: " + code); System.out.println("Description: " + description); /* * Using this kind of Webservice there is only one one field for * giving back a error message. When an axception occours, the * client side of Axis will throw an RemoteException which includes * the class name of the thrown exception. There is no way to get * more information like the original stacktrace !!! */ System.exit(1); } catch (MalformedURLException e) { System.err.println("failed (" + e.toString() + ")"); System.exit(1); } catch (ServiceException e) { System.err.println("Service unavailable (" + e.toString() + ")"); System.exit(1); } catch (IOException e) { System.err.println("can't read sequence file " + args[0]); System.exit(1); } } /* * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ following * function(s) used by class * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /** static method parse Inputparameter into a Hashtable */ private static Hashtable parseParameter(String args[]) { Hashtable prop = new Hashtable(); prop.put("MATRIX", new String()); prop.put("GAPOPEN", new Integer(0)); prop.put("GAPEXT", new Integer(0)); prop.put("F", new String()); Hashtable ret = new Hashtable(); String key = ""; for (int i = 0; i < args.length; ++i) { String current = args[i]; /* found key */ if (current.startsWith("-")) { /* check - maybe boolean */ if ((key != null) && (prop.get(key) != null)) { Class c = (prop.get(key)).getClass(); if ((c.getName()).equals("java.lang.Boolean")) { ret.put(key, new Boolean(true)); } } /* remove -- */ key = current.replaceAll("-", ""); } else { /* found value, check if current key exists in prop */ if (prop.get(key) != null) { /* get Class of value */ Class c = (prop.get(key)).getClass(); if ((c.getName()).equals("java.lang.Integer")) { ret.put(key, new Integer(Integer.parseInt(current))); } else if ((c.getName()).equals("java.lang.String")) { ret.put(key, current); } else if ((c.getName()).equals("java.lang.Double")) { ret.put(key, new Double(Double.parseDouble(current))); } } key = null; } } return ret; } /** convert a Hashtable to an ObjectArray */ private static Object[] hashtable2array(Hashtable ht) { Set keys = ht.keySet(); Object ret[] = new Object[keys.size() * 2]; int counter = 0; for (Iterator i = keys.iterator(); i.hasNext();) { Object key = i.next(); ret[counter] = key; counter++; ret[counter] = ht.get(key); counter++; } return ret; } }