/* * Jalview - A Sequence Alignment Editor and Viewer * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ package jalview.io; import org.apache.axis.AxisFault; import org.apache.axis.client.*; import org.apache.axis.encoding.XMLType; import org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory; import org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory; import java.io.*; import javax.activation.DataHandler; import javax.xml.namespace.QName; import javax.xml.rpc.ParameterMode; 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"; } }