Changeset 3919


Ignore:
Timestamp:
Nov 6, 2007, 4:49:15 PM (14 years ago)
Author:
Martin Svensson
Message:

References #492 Modified the download methods to eliminate the problems with hardcoded filenames. WSDL files are now generated in misc/wsdl.

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/build.xml

    r3914 r3919  
    145145      <fileset dir="${dist}" defaultexcludes="no" />
    146146      <fileset dir="bin/jar" defaultexcludes="no" />
     147      <fileset dir="misc/wsdl" defaultexcludes="no" />
    147148      <fileset dir="www/WEB-INF/lib" defaultexcludes="no" />
    148149      <fileset dir="www/WEB-INF/classes" defaultexcludes="no" />
     
    848849    <property name="webservices.build" location="${build}/webservices"
    849850      description="Location of compiled files" />
     851    <property name="webservices.wsdlpath" location="misc/wsdl"
     852      description="Location of created wsdl-files" />
    850853    <path id="webservices.classpath" description="Class path for compiling webservices">
    851854      <path refid="core.classpath"/>
     
    904907        classpath="${webservices.build};${core.build}"
    905908        className="net.sf.basedb.ws.server.@{serviceClassName}"
    906         outputLocation="${webservices.build}/wsdl"     
     909        outputLocation="${webservices.wsdlpath}"     
    907910        serviceName="@{serviceClassName}"
    908911        outputFileName="@{serviceClassName}.wsdl"
  • trunk/src/webservices/server/net/sf/basedb/ws/server/AbstractRPCService.java

    r3908 r3919  
    2727import net.sf.basedb.core.SessionControl;
    2828
    29 import java.io.File;
    30 
    3129import javax.activation.DataHandler;
    32 import javax.activation.FileDataSource;
     30import javax.activation.DataSource;
    3331
    3432import org.apache.axiom.om.OMAbstractFactory;
     
    8482      InputStream in = dataHandler.getInputStream();<br>
    8583     </code>
    86       @param file File to be attached.
     84      @param dataSource A DataSource to be attached to an OMElement.
    8785      @param elementName The name to call the element by.
    8886      @return OMElement where the file is attached to.
    8987   */
    90   protected OMElement attachFile(File file, String elementName)
     88  protected OMElement attachFile(DataSource dataSource, String elementName)
    9189  {
    9290    OMFactory messageFactory = OMAbstractFactory.getOMFactory();
     
    9492    OMElement fileElement = messageFactory.createOMElement(elementName, nameSpace);
    9593   
    96     FileDataSource fileDataSource = new FileDataSource(file);
    97     DataHandler dataHandler = new DataHandler(fileDataSource);
     94    DataHandler dataHandler = new DataHandler(dataSource);
    9895    OMText node = messageFactory.createOMText(dataHandler, true);   
    9996    fileElement.addChild(node);
  • trunk/src/webservices/server/net/sf/basedb/ws/server/ArrayDesignService.java

    r3876 r3919  
    2727import net.sf.basedb.core.DataFileType;
    2828import net.sf.basedb.core.DbControl;
     29import net.sf.basedb.core.File;
    2930import net.sf.basedb.core.FileSet;
    3031import net.sf.basedb.core.FileSetMember;
    3132import net.sf.basedb.core.ItemQuery;
    3233import net.sf.basedb.core.SessionControl;
    33 import net.sf.basedb.util.FileUtil;
    3434import net.sf.basedb.ws.info.DataFileTypeInfo;
    3535import net.sf.basedb.ws.info.QueryOptions;
    3636
    37 import java.io.File;
    38 import java.io.FileOutputStream;
    3937import java.util.LinkedList;
    4038import java.util.List;
     
    5957 
    6058  /**
    61     Returns array design file of a certain type.
     59    Returns array design file of a certain type, attached to an OMElement.
    6260      @param ID Used to identify an active session with.
    6361      @param arrayDesignId Id of the array design the file is associated with.
     
    7068  {
    7169    if (ID == null || typeInfo == null) return null;
    72     File arrayDesignFile = null;
     70   
    7371    SessionControl sc = getSessionControl(ID);
    7472    DbControl dc = sc.newDbControl();
     
    8280        FileSet fileSet = design.getFileSet();
    8381        FileSetMember member = fileSet.getMember(type);
    84         FileOutputStream fos = null;
    85         try
    86         {
    87           arrayDesignFile = new File(member.getFile().getName());
    88           fos = new FileOutputStream(arrayDesignFile); 
    89           FileUtil.copy(member.getFile().getDownloadStream(0), fos);
    90           fos.close();
    91         }
    92         catch (Throwable th)
    93         {
    94           arrayDesignFile = null;
    95         }
     82        File file = member.getFile();
     83        BaseFileDataSource source = new BaseFileDataSource(member.getFile());
     84        return attachFile(source, file.getName());
    9685      }
     86      else return null;
    9787    }
    9888    finally
    9989    {
    10090      if (dc != null) dc.close();
    101     }
    102     if (arrayDesignFile == null ) return null;
    103     return attachFile(arrayDesignFile, arrayDesignFile.getName());
     91    }   
    10492  }
    10593 
  • trunk/src/webservices/server/net/sf/basedb/ws/server/BioAssaySetService.java

    r3874 r3919  
    3636import java.util.Collections;
    3737import java.util.List;
     38
     39import javax.activation.FileDataSource;
    3840
    3941import org.apache.axiom.om.OMElement;
     
    99101   
    100102    String elementName = "exportFile";
     103    OMElement elementWithAttachment = null;
    101104   
    102105    SessionControl sc = getSessionControl(ID);
     
    113116      mergeReporters = mergeReporters == null ? false : mergeReporters;
    114117     
     118      exportFile =  File.createTempFile("BioAssaySetFile", null);
     119      fos = new FileOutputStream(exportFile);
     120     
    115121      BioAssaySetExporter exporter = new BioAssaySetExporter();
    116122      //Export to MeV-file format     
    117123      if (format.equals(MEV))
    118       {     
    119           exportFile = new File("mevfile");
    120           fos = new FileOutputStream(exportFile);
    121           exporter.exportMeV(bioassayset, fos, null);
    122           fos.close();
     124      {             
     125        exporter.exportMeV(bioassayset, fos, null);       
    123126      }           
    124127      //Export the data from the bioassayset as one big matrix in a BASEfile
    125128      else if(format.equals(MATRIX_BASEFILE))
    126129      {
    127         exportFile = new File("MatrixBaseFile");
    128         fos = new FileOutputStream(exportFile);
    129130        exporter.exportBaseFileMatrix(bioassayset, fos, Collections.EMPTY_MAP, reporterFields, spotFields, mergeReporters);
    130         fos.close();
    131131      }     
    132132      //Export the data from a bioassayset as a serial BASEfile.       
    133133      else if (format.equals(SERIAL_BASEFILE))
    134134      {
    135         exportFile = new File("SerialBaseFile");
    136         fos = new FileOutputStream(exportFile);
    137135        exporter.exportBaseFileSerial(bioassayset, fos, Collections.EMPTY_MAP, reporterFields, spotFields, mergeReporters);
    138         fos.close();
    139136      }     
    140137      else
     
    142139        throw new BaseException("BASE web services does not support this format: " + format);
    143140      }
     141      fos.close();
     142      FileDataSource source = new FileDataSource(exportFile);
     143      elementWithAttachment = attachFile(source, elementName);
    144144    }
    145145    catch(Throwable th)
     
    151151    {   
    152152      if (dc != null) dc.close();
     153      if (exportFile != null) exportFile.deleteOnExit();
    153154    }
    154     return attachFile(exportFile, elementName);   
     155   
     156    return elementWithAttachment;
    155157  }
    156158}
  • trunk/src/webservices/server/net/sf/basedb/ws/server/RawBioAssayService.java

    r3914 r3919  
    2727import net.sf.basedb.core.DataFileType;
    2828import net.sf.basedb.core.DbControl;
     29import net.sf.basedb.core.File;
    2930import net.sf.basedb.core.FileSet;
    3031import net.sf.basedb.core.FileSetMember;
     
    3233import net.sf.basedb.core.RawBioAssay;
    3334import net.sf.basedb.core.SessionControl;
    34 import net.sf.basedb.util.FileUtil;
    3535import net.sf.basedb.ws.info.ArrayDesignInfo;
    3636import net.sf.basedb.ws.info.DataFileTypeInfo;
    3737import net.sf.basedb.ws.info.QueryOptions;
    3838
    39 import java.io.File;
    40 import java.io.FileOutputStream;
    4139import java.util.LinkedList;
    4240import java.util.List;
     
    9492  {
    9593    if (ID == null || typeInfo == null) return null;
    96     File rawDataFile = null;
    9794    SessionControl sc = getSessionControl(ID);
    9895    DbControl dc = sc.newDbControl();
     
    10299      RawBioAssay rawBioAssay = RawBioAssay.getById(dc, rawBioAssayId);
    103100      DataFileType type = DataFileType.getByExternalId(dc, typeInfo.getExternalId());
    104       if (rawBioAssay.hasFileSet());
     101      if (rawBioAssay.hasFileSet())
    105102      {
    106103        FileSet fileSet = rawBioAssay.getFileSet();
    107104        FileSetMember member = fileSet.getMember(type);
    108         FileOutputStream fos = null;
    109         try
    110         {
    111           rawDataFile = new File(member.getFile().getName());
    112           fos = new FileOutputStream(rawDataFile); 
    113           FileUtil.copy(member.getFile().getDownloadStream(0), fos);
    114           fos.close();
    115         }
    116         catch (Throwable th)
    117         {
    118           rawDataFile = null;
    119         }
     105        File file = member.getFile();
     106        BaseFileDataSource source = new BaseFileDataSource(file);
     107        return attachFile(source, file.getName());
    120108      }
     109      else return null;
    121110    }
    122111    finally
     
    124113      if (dc != null) dc.close();
    125114    }
    126     if (rawDataFile == null) return null;
    127     return attachFile(rawDataFile, rawDataFile.getName());
    128115  }
    129116 
Note: See TracChangeset for help on using the changeset viewer.