package soln; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.*; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Properties; import com.elixirtech.ers2.client.ERSClient; import com.elixirtech.net.NetException; import com.elixirtech.report2.runtime.IFileSystem; import com.elixirtech.report2.runtime.IJobInfo; import com.elixirtech.report2.runtime.IFileSystem; public class APIDemo { /** * @param args */ public static String m_Host = "192.168.170.128"; public static int m_Port = 7000; public static String m_User = "admin"; public static String m_Password = "sa"; /** * Generate a Report * @throws IOException */ public void rendersReport(String reportName, Properties prop) throws IOException { ERSClient ersClient = new ERSClient(m_Host, m_Port, m_User, m_Password); ersClient.setSecure(new File("keystore"), "katevo", new File("keystore"), "katevo"); try { //FileOutputStream fos = new FileOutputStream( //new File("test.pdf")); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] bytes = bos.toByteArray(); IJobInfo ji = ersClient.renderReport(reportName, "application/pdf", bos, prop); System.out.println( "Job Received: " + ji.getLong(IJobInfo.JOB_RECEIVED) + ", " + "Job Started: " + ji.getLong(IJobInfo.JOB_STARTED) + ", " + "Job Ended: " + ji.getLong(IJobInfo.JOB_ENDED) + ", " + "Mime Type: " + ji.getString(IJobInfo.MIME_TYPE) + ", " + "Page Count: " + ji.getString(IJobInfo.PAGE_COUNT) + ", " + "Record Count: " + ji.getString(IJobInfo.RECORD_COUNT) + ", " + "Byte Size: " + ji.getLong(IJobInfo.BYTE_SIZE) + ", " + "Name: " + ji.getString(IJobInfo.NAME) + ", " + "Status Code: " + ji.getString(IJobInfo.STATUS_CODE) ); //} catch (FileNotFoundException e) { //e.printStackTrace(); } catch (NetException e) { e.printStackTrace(); } finally { ersClient.close(); } } /** * Generate a Report to a file target */ public void rendersReportToTarget(String reportName, Properties prop, String target, Properties target_prop) { ERSClient ersClient = new ERSClient(m_Host, m_Port, m_User, m_Password); try { IJobInfo ji = ersClient.renderReport(reportName, "application/pdf",prop,target,target_prop ); System.out.println( "Job Received: " + ji.getLong(com.elixirtech.job.IJobInfo.JOB_RECEIVED) + ", " + "Job Started: " + ji.getLong(com.elixirtech.job.IJobInfo.JOB_STARTED) + ", " + "Job Ended: " + ji.getLong(com.elixirtech.job.IJobInfo.JOB_ENDED) + ", " + "Mime Type: " + ji.getString(com.elixirtech.job.IJobInfo.MIME_TYPE) + ", " + "Page Count: " + ji.getString(com.elixirtech.job.IJobInfo.PAGE_COUNT) + ", " + "Record Count: " + ji.getString(com.elixirtech.job.IJobInfo.RECORD_COUNT) + ", " + "Byte Size: " + ji.getLong(com.elixirtech.job.IJobInfo.BYTE_SIZE) + ", " + "Name: " + ji.getString(com.elixirtech.job.IJobInfo.NAME) + ", " + "Status Code: " + ji.getString(com.elixirtech.job.IJobInfo.STATUS_CODE) ); } catch (NetException e) { e.printStackTrace(); } finally { ersClient.close(); } } /** * Call a Job on the server */ public void callJob(String reportName, Properties prop){ ERSClient ersClient = new ERSClient(m_Host, m_Port, m_User, m_Password); try{ IJobInfo ji = ersClient.triggerJob(reportName, prop); System.out.println( "Job Received: " + ji.getString(com.elixirtech.job.IJobInfo.JOB_RECEIVED) + ", " + "Job Started: " + ji.getString(com.elixirtech.job.IJobInfo.JOB_STARTED) + ", " + "Job Ended: " + ji.getString(com.elixirtech.job.IJobInfo.JOB_ENDED) + ", " + "Mime Type: " + ji.getString(com.elixirtech.job.IJobInfo.MIME_TYPE) + ", " + "Page Count: " + ji.getString(com.elixirtech.job.IJobInfo.PAGE_COUNT) + ", " + "Record Count: " + ji.getString(com.elixirtech.job.IJobInfo.RECORD_COUNT) + ", " + "Byte Size: " + ji.getLong(com.elixirtech.job.IJobInfo.BYTE_SIZE) + ", " + "Name: " + ji.getString(com.elixirtech.job.IJobInfo.NAME) + ", " + "Status Code: " + ji.getString(com.elixirtech.job.IJobInfo.STATUS_CODE) ); }catch (NetException e) { e.printStackTrace(); } finally { ersClient.close(); } } public void listReports( ) { ERSClient ersClient = new ERSClient(m_Host, m_Port, m_User, m_Password); try { String[] reports = ersClient.getReports("ElixirSamples"); for(int i=0; i<(reports.length); i++) { System.out.println(reports[i]); } } catch (NetException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ ersClient.close(); } } public void listFs( ) { ERSClient ersClient = new ERSClient(m_Host, m_Port, m_User, m_Password); try { String[] filesystem = ersClient.getFileSystems(); for(int i=0; i<(filesystem.length); i++ ) { System.out.println(filesystem[i]); } } catch (NetException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ ersClient.close(); } } public void getFilesystem( ) { ERSClient ersClient = new ERSClient(m_Host, m_Port, m_User, m_Password); try { IFileSystem fs = ersClient.getFileSystem("ElixirSamples"); System.out.println(fs); } catch (NetException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ ersClient.close(); } } public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Running Test Client"); APIDemo testClient = new APIDemo(); APIDemo testClient1 = new APIDemo(); //Parameter declaration Properties params = new Properties(); params.put("Order_ID","1002"); // 1 Generate Report System.out.println(">>>1 Generate Report using File Output Stream"); try { testClient.rendersReport("/ElixirSamples/Report/PetStore/OrderList.rml",params); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }