User Tools

Site Tools


tech:psoft:get_file_from_ps_report_repo_externally

Get a File out of the PeopleSoft Report Repository from Java

I used the Apache Jakarta HttpClient libraries to accomplish this. HttpClient is available from http://jakarta.apache.org/commons/httpclient/

Make sure that you have the following jar files in you CLASSPATH:

  • commons-codec-1.3.jar
  • commons-httpclient-3.0.1.jar
  • commons-logging-1.1.jar
  • commons-logging-adapters-1.1.jar
  • commons-logging-api-1.1.jar
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodParams;
import java.io.*;


public class getFile1 {
	
  public static void main(String[] args) {
  	
  	//Parameters
  	String getUrl    = "http://localhost:8000/psreports/ps/356/DDDAUDIT_500.PDF"; 
  	String loginUrl  = "http://localhost:8000/psp/ps/?cmd=login";    
  	String userId    = "VP1";
  	String passWord  = "VP1";    
  	String outFile   = "C:/temp/report_output.pdf";
  	
  	//Logging
  	System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
  	System.setProperty("org.apache.commons.logging.simplelog.showdatetime","true");
  	System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire.header","debug");
  	System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient","debug");
  	
  	//Create objects
		HttpClient      client    = new HttpClient();
		GetMethod       get       = new GetMethod(getUrl);
		PostMethod      post      = new PostMethod(loginUrl);
		NameValuePair[] logindata = {new NameValuePair("userid", userId),new NameValuePair("pwd", passWord)};
		
		try {
			
			//Login to PeopleSoft with userid and password above
			post.setRequestBody(logindata);
			client.executeMethod(post);
			post.releaseConnection();
			
			//Get the file from the PeopleSoft report repository
			client.executeMethod(get);
			InputStream  in  = get.getResponseBodyAsStream();
			OutputStream out = new FileOutputStream(outFile);
			
			//Write out InputStream to file
			byte[] b = new byte[1024];
                        int len;
                        while ((len = in.read(b)) != -1) {
                             out.write(b, 0, len);
			}
			
			//Clean up
			get.releaseConnection();
			in.close();
			
	  } catch (Exception ex) {
	  	System.out.println(ex);
	  } 
	}
}
tech/psoft/get_file_from_ps_report_repo_externally.txt · Last modified: 2024/06/21 12:04 by 127.0.0.1