<%@ page
import="java.io.*,javax.activation.DataHandler,org.apache.axis.client.Call,org.apache.axis.attachments.AttachmentPart,
org.apache.axis.client.Service,java.net.URL,javax.xml.namespace.QName,javax.xml.rpc.ParameterMode" %>
<html>
<head>
<title>Display PDF</title>
</head>
<%
String objId = request.getParameter("OracleInvoiceNo");
String endpoint = request.getParameter("constorPath");
try {
// Check Whether OracleInvoiceNo is Null
// Displaying the pdf by calling the WebService
if(objId != null && !objId.equals(""))
{
String cs_invoice="cs_invoice";
StringBuffer strDetails=new StringBuffer();
strDetails.append("<getdocument>");
strDetails.append("<object type=/"cs_invoice/">");
strDetails.append("<attribute name=/"g_invoice_number/">"+objId+"</attribute>");
strDetails.append("</object>");
strDetails.append("</getdocument>");
String Details = new String(strDetails);
// String endpoint = "http://3.96.194.163:12000/webservices/services/DCTMWebService";
org.apache.axis.client.Service service = new org.apache.axis.client.Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName("viewDocument");
QName qnameAttachment = new QName("DCTMWebService", "String");
call.addParameter("strappname", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN );
call.addParameter("strattrxml", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN );
call.addParameter("resultsoption",org.apache.axis.Constants.XSD_STRING, ParameterMode.IN);
QName qname = new QName("DCTMWebService","Object[]");
call.setReturnType(qname);
Object ret = call.invoke(new Object[] {"abe",Details,"content"});
if(ret !=null && ret instanceof Object[]) {
Object[] result = (Object[])ret;
if(result[1] != null)
{
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "inline;attachment filename=" + objId + ".pdf");
javax.servlet.ServletOutputStream servletoutputstream = response.getOutputStream();
DataHandler dhSource = null;
if(result[1] instanceof AttachmentPart){
AttachmentPart attachmentPart = (AttachmentPart)result[1];
dhSource = attachmentPart.getDataHandler();
InputStream is = dhSource.getInputStream();
byte b[] = new byte[is.available()];
is.read(b);
response.setContentLength(b.length);
servletoutputstream.write(b);
servletoutputstream.flush();
servletoutputstream.close();
}
}else
{
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "inline;attachment filename=" + objId + ".pdf");
// String objId = request.getParameter("OracleInvoiceNo");
String filepath="/opt/app/7200/EmisInvoices/PdfFiles/"+objId+".pdf";
FileInputStream fis = new FileInputStream(filepath);
byte[] bytes = new byte[fis.available()];
response.setContentLength(bytes.length);
fis.read(bytes,0,bytes.length);
javax.servlet.ServletOutputStream Pout = response.getOutputStream();
//Pout.render(Pout);
Pout.write(bytes);
Pout.flush();
Pout.close();
}
}
}// End of OracleInvoiceChecking
// The following block displaying the pdf using URL
else
{
String pyID=request.getParameter("pyID");
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "inline;attachment filename=" + pyID+ ".pdf");
String filepath="/opt/app/7200/EmisInvoices/PdfFiles/"+pyID+".pdf";
FileInputStream fis = new FileInputStream(filepath);
byte[] bytes = new byte[fis.available()];
response.setContentLength(bytes.length);
fis.read(bytes,0,bytes.length);
javax.servlet.ServletOutputStream Pout = response.getOutputStream();
//Pout.render(Pout);
Pout.write(bytes);
Pout.flush();
Pout.close();
}
}
catch(Exception e) {
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "inline;attachment filename=" + objId + ".pdf");
// String objId = request.getParameter("OracleInvoiceNo");
String filepath="/opt/app/7200/EmisInvoices/PdfFiles/"+objId+".pdf";
FileInputStream fis = new FileInputStream(filepath);
byte[] bytes = new byte[fis.available()];
response.setContentLength(bytes.length);
fis.read(bytes,0,bytes.length);
javax.servlet.ServletOutputStream Pout = response.getOutputStream();
//Pout.render(Pout);
Pout.write(bytes);
Pout.flush();
Pout.close();
}
%>
</html>