package jalview.io; import org.apache.axis.client.*; import java.io.*; import javax.activation.DataHandler; import org.apache.axis.AxisFault; import org.apache.axis.encoding.XMLType; import javax.xml.rpc.ParameterMode; import javax.xml.namespace.QName; import org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory; import org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory; public class EBIFetchClient { Call call; String format = "default"; String style = "raw"; public EBIFetchClient() { try{ call = (Call)new Service().createCall(); call.setTargetEndpointAddress(new java.net.URL( "http://www.ebi.ac.uk/ws/services/Dbfetch")); }catch(Exception ex){} } public String [] getSupportedDBs() { try{ call.setOperationName(new QName("urn:Dbfetch", "getSupportedDBs")); call.setReturnType(XMLType.SOAP_ARRAY); return (String[]) call.invoke(new Object[]{}); }catch(Exception ex){return null;} } public String [] getSupportedFormats() { try{ call.setOperationName(new QName("urn:Dbfetch", "getSupportedFormats")); call.setReturnType(XMLType.SOAP_ARRAY); return (String[]) call.invoke(new Object[] {}); }catch(Exception ex){ return null; } } public String [] getSupportedStyles() { try{ call.setOperationName(new QName("urn:Dbfetch", "getSupportedStyles")); call.setReturnType(XMLType.SOAP_ARRAY); return (String[]) call.invoke(new Object[] {}); }catch(Exception ex){return null;} } public String [] fetchData(String ids, String f, String s) { // ids should be of the form uniprot:25KD_SARPE;ADHR_DROPS; // max 50 ids can be added at one time try{ call.setOperationName(new QName("urn:Dbfetch", "fetchData")); call.addParameter("query", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("format", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("style", XMLType.XSD_STRING, ParameterMode.IN); call.setReturnType(XMLType.SOAP_ARRAY); if (f != null) format = f; if (s != null) style = s; return (String[]) call.invoke(new Object[] {ids, format, style}); }catch(Exception ex){return null;} } public String fetchDataFile(String arg, String f, String s) { if (f != null) format = f; if (s != null) style = s; call.setOperationName(new QName("urn:Dbfetch", "fetchDataFile")); call.addParameter("query", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("format", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("style", XMLType.XSD_STRING, ParameterMode.IN); QName qnameAttachment = new QName("urn:Dbfetch", "DataHandler"); call.registerTypeMapping(javax.activation.DataSource.class, qnameAttachment, JAFDataHandlerSerializerFactory.class, JAFDataHandlerDeserializerFactory.class); call.setReturnType(qnameAttachment); try{ Object ret = call.invoke(new Object[] {arg, format, style}); if (null == ret) { System.err.println("Received null "); throw new AxisFault("", "Received null", null, null); } if (ret instanceof String) { System.err.println("Received problem response from server: " + ret); throw new AxisFault("", (String) ret, null, null); } if (! (ret instanceof DataHandler)) { //The wrong type of object that what was expected. System.err.println("Received problem response from server:" + ret.getClass().getName()); throw new AxisFault("", "Received problem response from server:" + ret.getClass().getName(), null, null); } //Still here, so far so good. DataHandler rdh = (DataHandler) ret; //From here we'll just treat the data resource as file. String receivedfileName = rdh.getName(); //Get the filename. if (receivedfileName == null) { System.err.println("Could not get the file name."); throw new AxisFault("", "Could not get the file name.", null, null); } if (arg.equalsIgnoreCase("medline")) { return receivedfileName; } else if (arg.equalsIgnoreCase("interpro")) { return receivedfileName; } else System.err.println(receivedfileName); }catch(Exception ex) { ex.printStackTrace(); } return "ERROR"; } }