annotate src/de/mpiwg/itgroup/eSciDoc/Tools/SendFileToeSciDoc.java @ 0:c6929e63b0b8

first import
author dwinter
date Wed, 24 Nov 2010 16:52:07 +0100
parents
children a844f6948dd8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c6929e63b0b8 first import
dwinter
parents:
diff changeset
1 package de.mpiwg.itgroup.eSciDoc.Tools;
c6929e63b0b8 first import
dwinter
parents:
diff changeset
2 import java.io.File;
c6929e63b0b8 first import
dwinter
parents:
diff changeset
3 import java.io.FileWriter;
c6929e63b0b8 first import
dwinter
parents:
diff changeset
4 import java.io.IOException;
c6929e63b0b8 first import
dwinter
parents:
diff changeset
5 import java.net.MalformedURLException;
c6929e63b0b8 first import
dwinter
parents:
diff changeset
6 import java.net.URL;
c6929e63b0b8 first import
dwinter
parents:
diff changeset
7
c6929e63b0b8 first import
dwinter
parents:
diff changeset
8 import org.apache.http.HttpResponse;
c6929e63b0b8 first import
dwinter
parents:
diff changeset
9 import org.apache.http.client.ClientProtocolException;
c6929e63b0b8 first import
dwinter
parents:
diff changeset
10
c6929e63b0b8 first import
dwinter
parents:
diff changeset
11
c6929e63b0b8 first import
dwinter
parents:
diff changeset
12 public class SendFileToeSciDoc {
c6929e63b0b8 first import
dwinter
parents:
diff changeset
13
c6929e63b0b8 first import
dwinter
parents:
diff changeset
14
c6929e63b0b8 first import
dwinter
parents:
diff changeset
15 //private static final String ESCIDOC_SERVER = "xserve07.mpiwg-berlin.mpg.de";
c6929e63b0b8 first import
dwinter
parents:
diff changeset
16 private static final String ESCIDOC_SERVER = "escidoc-test.mpiwg-berlin.mpg.de";
c6929e63b0b8 first import
dwinter
parents:
diff changeset
17
c6929e63b0b8 first import
dwinter
parents:
diff changeset
18 /**
c6929e63b0b8 first import
dwinter
parents:
diff changeset
19 * @param args
c6929e63b0b8 first import
dwinter
parents:
diff changeset
20 * @throws IOException
c6929e63b0b8 first import
dwinter
parents:
diff changeset
21 * @throws IllegalStateException
c6929e63b0b8 first import
dwinter
parents:
diff changeset
22 */
c6929e63b0b8 first import
dwinter
parents:
diff changeset
23
c6929e63b0b8 first import
dwinter
parents:
diff changeset
24 public static void main(String[] args) throws IllegalStateException, IOException {
c6929e63b0b8 first import
dwinter
parents:
diff changeset
25 if (args.length<4){
c6929e63b0b8 first import
dwinter
parents:
diff changeset
26 System.out.println("Usage: sendfile command urlOfFile user password");
c6929e63b0b8 first import
dwinter
parents:
diff changeset
27 return;
c6929e63b0b8 first import
dwinter
parents:
diff changeset
28 }
c6929e63b0b8 first import
dwinter
parents:
diff changeset
29
c6929e63b0b8 first import
dwinter
parents:
diff changeset
30 EScidocBasicHandler handler = new EScidocBasicHandler(ESCIDOC_SERVER,8080,args[2],args[3]);
c6929e63b0b8 first import
dwinter
parents:
diff changeset
31 URL url;
c6929e63b0b8 first import
dwinter
parents:
diff changeset
32 HttpResponse ret;
c6929e63b0b8 first import
dwinter
parents:
diff changeset
33 try {
c6929e63b0b8 first import
dwinter
parents:
diff changeset
34 url = new URL(args[1]);
c6929e63b0b8 first import
dwinter
parents:
diff changeset
35 } catch (MalformedURLException e) {
c6929e63b0b8 first import
dwinter
parents:
diff changeset
36
c6929e63b0b8 first import
dwinter
parents:
diff changeset
37 e.printStackTrace();
c6929e63b0b8 first import
dwinter
parents:
diff changeset
38 return;
c6929e63b0b8 first import
dwinter
parents:
diff changeset
39 }
c6929e63b0b8 first import
dwinter
parents:
diff changeset
40 try {
c6929e63b0b8 first import
dwinter
parents:
diff changeset
41 ret = handler.eScidocPut(args[0], url);
c6929e63b0b8 first import
dwinter
parents:
diff changeset
42 } catch (ClientProtocolException e) {
c6929e63b0b8 first import
dwinter
parents:
diff changeset
43 // TODO Auto-generated catch block
c6929e63b0b8 first import
dwinter
parents:
diff changeset
44 e.printStackTrace();
c6929e63b0b8 first import
dwinter
parents:
diff changeset
45 return;
c6929e63b0b8 first import
dwinter
parents:
diff changeset
46 } catch (IOException e) {
c6929e63b0b8 first import
dwinter
parents:
diff changeset
47 // TODO Auto-generated catch block
c6929e63b0b8 first import
dwinter
parents:
diff changeset
48 e.printStackTrace();
c6929e63b0b8 first import
dwinter
parents:
diff changeset
49 return;
c6929e63b0b8 first import
dwinter
parents:
diff changeset
50 }
c6929e63b0b8 first import
dwinter
parents:
diff changeset
51
c6929e63b0b8 first import
dwinter
parents:
diff changeset
52 System.out.println(ret.getStatusLine());
c6929e63b0b8 first import
dwinter
parents:
diff changeset
53 String outTXT = EScidocBasicHandler.convertStreamToString(ret.getEntity().getContent());
c6929e63b0b8 first import
dwinter
parents:
diff changeset
54 System.out.println(outTXT);
c6929e63b0b8 first import
dwinter
parents:
diff changeset
55
c6929e63b0b8 first import
dwinter
parents:
diff changeset
56 // File nf = new File("/tmp/out.log");
c6929e63b0b8 first import
dwinter
parents:
diff changeset
57 // FileWriter fw = new FileWriter(nf);
c6929e63b0b8 first import
dwinter
parents:
diff changeset
58 // fw.append(outTXT);
c6929e63b0b8 first import
dwinter
parents:
diff changeset
59 // fw.close();
c6929e63b0b8 first import
dwinter
parents:
diff changeset
60
c6929e63b0b8 first import
dwinter
parents:
diff changeset
61
c6929e63b0b8 first import
dwinter
parents:
diff changeset
62
c6929e63b0b8 first import
dwinter
parents:
diff changeset
63 }
c6929e63b0b8 first import
dwinter
parents:
diff changeset
64
c6929e63b0b8 first import
dwinter
parents:
diff changeset
65 }