1717
1818import org .apache .hc .client5 .http .classic .methods .HttpPost ;
1919import org .apache .hc .client5 .http .entity .mime .FileBody ;
20+ import org .apache .hc .client5 .http .entity .mime .InputStreamBody ;
2021import org .apache .hc .client5 .http .entity .mime .MultipartEntityBuilder ;
2122import org .apache .hc .client5 .http .impl .classic .CloseableHttpClient ;
2223import org .apache .hc .client5 .http .impl .classic .CloseableHttpResponse ;
2324import org .apache .hc .client5 .http .impl .classic .HttpClientBuilder ;
25+ import org .apache .hc .core5 .http .ContentType ;
2426import org .apache .hc .core5 .http .HttpEntity ;
2527import org .apache .hc .core5 .http .ParseException ;
2628import org .apache .hc .core5 .http .io .entity .EntityUtils ;
2729import org .apache .logging .log4j .Logger ;
2830import org .jetbrains .annotations .NotNull ;
2931import org .labkey .api .util .PageFlowUtil ;
3032import org .labkey .api .util .logging .LogHelper ;
33+ import org .labkey .vfs .FileLike ;
3134
3235import java .io .File ;
3336import java .io .IOException ;
@@ -49,17 +52,17 @@ private enum METHOD {submitDataset, validateXML, requestID}
4952
5053 private static final Logger LOG = LogHelper .getLogger (ProteomeXchangeService .class , "Handles requests to the ProteomeXchange server" );
5154
52- public static String validatePxXml (File pxxmlFile , boolean testDatabase , String user , String pass ) throws ProteomeXchangeServiceException
55+ public static String validatePxXml (FileLike pxxmlFile , boolean testDatabase , String user , String pass ) throws ProteomeXchangeServiceException
5356 {
5457 return postPxXml (pxxmlFile , testDatabase , user , pass , METHOD .validateXML );
5558 }
5659
57- public static String submitPxXml (File pxxmlFile , boolean testDatabase , String user , String pass ) throws ProteomeXchangeServiceException
60+ public static String submitPxXml (FileLike pxxmlFile , boolean testDatabase , String user , String pass ) throws ProteomeXchangeServiceException
5861 {
5962 return postPxXml (pxxmlFile , testDatabase , user , pass , METHOD .submitDataset );
6063 }
6164
62- private static String postPxXml (File pxxmlFile , boolean testDatabase , String user , String pass , METHOD method ) throws ProteomeXchangeServiceException
65+ private static String postPxXml (FileLike pxxmlFile , boolean testDatabase , String user , String pass , METHOD method ) throws ProteomeXchangeServiceException
6366 {
6467 String responseMessage ;
6568 try {
@@ -118,12 +121,12 @@ public static String getPxId(boolean testDatabase, String user, String pass) thr
118121 }
119122
120123 @ NotNull
121- private static MultipartEntityBuilder getMultipartEntityBuilder (File pxxmlFile , boolean testDatabase , METHOD method , String user , String pass )
124+ private static MultipartEntityBuilder getMultipartEntityBuilder (FileLike pxxmlFile , boolean testDatabase , METHOD method , String user , String pass ) throws IOException
122125 {
123126 MultipartEntityBuilder builder = MultipartEntityBuilder .create ();
124127 if (pxxmlFile != null )
125128 {
126- builder .addPart ("ProteomeXchangeXML" , new FileBody (pxxmlFile ));
129+ builder .addPart ("ProteomeXchangeXML" , new InputStreamBody (pxxmlFile . openInputStream (), ContentType . TEXT_XML , pxxmlFile . getName () ));
127130 }
128131 builder .addTextBody ("PXPartner" , user );
129132 builder .addTextBody ("authentication" , pass );
@@ -140,7 +143,7 @@ private static MultipartEntityBuilder getMultipartEntityBuilder(File pxxmlFile,
140143 return builder ;
141144 }
142145
143- private static MultipartEntityBuilder getMultipartEntityBuilder (boolean testDatabase , METHOD method , String user , String pass )
146+ private static MultipartEntityBuilder getMultipartEntityBuilder (boolean testDatabase , METHOD method , String user , String pass ) throws IOException
144147 {
145148 return getMultipartEntityBuilder (null , testDatabase , method , user , pass );
146149 }
0 commit comments