Axis调用webservice读取pdf文件

<%@ 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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值