view src/de/mpiwg/itgroup/eSciDoc/Tools/SendFileToeSciDoc.java @ 15:e0efd3a9d2f0

changes for escidoc1.4
author dwinter
date Mon, 17 Sep 2012 10:21:04 +0200
parents b6cf6462d709
children
line wrap: on
line source

package de.mpiwg.itgroup.eSciDoc.Tools;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.log4j.BasicConfigurator;


public class SendFileToeSciDoc {

	
	//private static final String ESCIDOC_SERVER = "xserve07.mpiwg-berlin.mpg.de";
	//private static final String ESCIDOC_SERVER = "escidoc.mpiwg-berlin.mpg.de";
	private static final String ESCIDOC_SERVER = "escidoc-mpiwg.rz-berlin.mpg.de";
	//private static final String ESCIDOC_SERVER = "escidoc-test.mpiwg-berlin.mpg.de";

	/**
	 * @param args
	 * @throws IOException 
	 * @throws IllegalStateException 
	 */
	
	public static void main(String[] args) throws IllegalStateException, IOException {
		if (args.length<4){
			System.out.println("Usage: sendfile command urlOfFile user password");
			return;
		}
		
		BasicConfigurator.configure();
		EScidocBasicHandler handler = new EScidocBasicHandler(ESCIDOC_SERVER,8080,args[2],args[3]);
		URL url;
		HttpResponse ret;
		try {
			url = new URL(args[1]);
		} catch (MalformedURLException e) {
			
			e.printStackTrace();
			return;
		}
		try {
			//ret = handler.eScidocDelete(args[0]);
			ret = handler.eScidocPut(args[0], url);
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return;
		}
		
		System.out.println(ret.getStatusLine());
		String outTXT = EScidocBasicHandler.convertStreamToString(ret.getEntity().getContent());
		System.out.println(outTXT);
		
//		File nf = new File("/tmp/out.log");
//		FileWriter fw = new FileWriter(nf);
//		fw.append(outTXT);
//		fw.close();
		
		

	}

}