Subject: Re: FileReplace activity does not work with input stream
- Next message: Steven Lynden: "RE: [Ogsa-dai-ug] WebRowSetToResultSet error in OGSA-DQP"
- Previous message: Stephan Rudlof: "FileReplace activity does not work with input stream"
- In reply to: Stephan Rudlof: "FileReplace activity does not work with input stream"
- Next in thread: Stephan Rudlof: "Re: FileReplace activity does not work with input stream"
- Reply: Stephan Rudlof: "Re: FileReplace activity does not work with input stream"
From: Amy Krause (amrey@epcc.ed.ac.uk)
Date: Apr 04, 2006 12:43
Hi Stephan,
The DeliverFromURL activity produces blocks of byte arrays whereas the
ReplaceFile activity expects blocks of Strings - you can't pipe output
from the delivery activity to ReplaceFile.
Unfortunately there is no activity which transforms byte array output into
Strings so there is no workaround for your problem with the current
release.
You could write an activity which turns byte arrays into Strings. See:
http://www.ogsadai.org.uk/documentation/ogsadai-wsi-2.1/doc/tutorials/activitywrite/index.html
Or you can add a line in the server-side FileWritingActivity (method
obtainInput) so that it accepts byte arrays as well as Strings:
if (obj instanceof byte[]) {
byte[] bytes = (byte[])obj;
String input = new String(bytes);
// ... continue to process the input string
}
Hope this helps.
Amy
On Tue, 4 Apr 2006, Stephan Rudlof wrote:
> Hello All,
>
> I have a problem with FileReplace: in the following there is my code using client toolkit activities.
>
> The problem is case 2.: Though 1. and 3. both are working, case 2. does *not* work. Any ideas?
>
> ========
> public void testPlayground_2() throws Exception {
> String sourceHandle = "http://localhost:8080/wsrf/services/ogsadai/DataService";
> String sourceResource = "FilesResource";
>
> DataService sourceService = GenericServiceFetcher.getInstance().getDataService(sourceHandle, sourceResource);
>
> DeliverFromFile deliverFrom = new DeliverFromFile("c:/tmp/in.txt");
>
> /* In the following there are three alternatives. */
>
> // 1. This works, but is unsafe (arbitrary dirs possible)
> //DeliverToFile target = new DeliverToFile( "c:/tmp/out_f.txt" );
>
> // 2. This could be more safe (root dir can be given), but it does *not* work!
> // The result is, that the file will be made empty (size zero) instead of filling it with the input.
> FileReplace target = new FileReplace("out_f.txt", FileWriting.BOF, FileWriting.TO_EOF, false);
>
> // 3. This works, but is not what is wanted...
> //FileReplace target = new FileReplace("out_f.txt", FileWriting.BOF, FileWriting.TO_EOF, false, "from input string");
>
> target.setInput(deliverFrom.getOutput());
>
> ActivityRequest request = new ActivityRequest();
> request.add(deliverFrom);
> request.add(target);
>
> printRequestAsXML(request);
> Response response = sourceService.perform(request);
>
> System.out.println("Response:\n" + response.getAsString());
> System.out.println(response.toString());
> }
> ========
>
> My goal is to transfer a file to another host (without installing an FTP server): therefore it would be good to have a client toolkit activity
> - creating a new file, if given filename does not exist, or
> - overwriting the old one, if given filename exists (with an argument saying if it should overwrite or give an error);
> but I haven't found one.
> So I've tried with the existing ones: using FileReplace is a sufficient workaround, if it's OK to limit yourself to a pool of predefined filenames (denoting existing files (may be empty at the beginning)).
>
> Alternative 1. above using DeliverToFile would work, but
> - is too unsecure (able to reach whole filesystem, always overwrites existing files), and
> - needs knowledge about the structure of the external file system, if one wants to avoid the home dir of the GT installation (probably similar using Tomcat/WSI).
>
> Besides the problem above pointers to better alternatives for file transfer are appreciated.
>
>
> Best regards,
> Stephan
> --
> Stephan Rudlof (rudlof@ontoprise.de)
> Professional Services
> ontoprise GmbH - know how to use Know-how
> ---
> Amalienbadstraße 36 (Raumfabrik 29); 76227 Karlsruhe
> Phone: +49 (0) 721 509 809 46; FAX: +49 (0) 509 809 11
> http://www.ontoprise.de
>
-- ------------------------------------------------------------ | Dr Amy Krause Applications Consultant | | |epcc|, The University of Edinburgh | | King's Buildings, Mayfield Road, Edinburgh EH9 3JZ, UK | | Tel: +44 (0)131 650 6718 --- email: a.krause@epcc.ed.ac.uk | ------------------------------------------------------------
- Next message: Steven Lynden: "RE: [Ogsa-dai-ug] WebRowSetToResultSet error in OGSA-DQP"
- Previous message: Stephan Rudlof: "FileReplace activity does not work with input stream"
- In reply to: Stephan Rudlof: "FileReplace activity does not work with input stream"
- Next in thread: Stephan Rudlof: "Re: FileReplace activity does not work with input stream"
- Reply: Stephan Rudlof: "Re: FileReplace activity does not work with input stream"