Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package au.org.alfred.icu.pdf.services.dischargesummary; import au.org.alfred.icu.pdf.services.factories.ICUDischargeSummaryFactory; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.jws.WebParam; import jcifs.smb.NtlmPasswordAuthentication; import jcifs.smb.SmbFile; import jcifs.smb.SmbFileOutputStream; import org.apache.pdfbox.exceptions.COSVisitorException; import org.apache.pdfbox.pdmodel.PDDocument; import org.json.*; public class pdfservice { public pdfservice() { } public String discharge(@WebParam(name = "parameters") String parameters) { PDDocument pdf = null; String encodedPdf = "Error"; //ByteArrayOutputStream output = new ByteArrayOutputStream(); String pdfName = "Error Could Not Create File"; try { pdf = new PDDocument(); JSONObject jsonParams = new JSONObject(parameters); String title = jsonParams.getString("pmiid"); String subject = jsonParams.getString("admid"); String keywords = jsonParams.getString("admid"); String creator = jsonParams.getString("user"); String author = jsonParams.getString("user"); ICUDischargeSummaryFactory.addDocumentInformation(pdf, title, subject, keywords, creator, author); pdfName = ICUDischargeSummaryFactory.createContent(pdf, jsonParams.getString("icuid"), jsonParams.getString("admid"), jsonParams.getString("pmiid"), jsonParams.getString("user"), jsonParams.getString("userid")); ICUDischargeSummaryFactory.saveDocument( "/opt/glassfish3/glassfish/domains/domain1/applications/ICUDischargeSummaryWeb/pdf_tmp/" + pdfName, pdf); pdf.close(); } catch (IOException ex) { ex.printStackTrace(System.out); Logger.getLogger(pdfservice.class.getName()).log(Level.SEVERE, null, ex); } catch (COSVisitorException ex) { Logger.getLogger(pdfservice.class.getName()).log(Level.SEVERE, null, ex); } return pdfName; } public String dischargeToCerner(@WebParam(name = "parameters") String parameters) { PDDocument pdf; String encodedPdf = "Error"; ByteArrayOutputStream output = new ByteArrayOutputStream(); String pdfName = "Error Could Not Create File"; try { pdf = new PDDocument(); JSONObject jsonParams = new JSONObject(parameters); String title = jsonParams.getString("pmiid"); String subject = jsonParams.getString("admid"); String keywords = jsonParams.getString("admid"); String creator = jsonParams.getString("user"); String author = jsonParams.getString("user"); ICUDischargeSummaryFactory.addDocumentInformation(pdf, title, subject, keywords, creator, author); pdfName = ICUDischargeSummaryFactory.createContent(pdf, jsonParams.getString("icuid"), jsonParams.getString("admid"), jsonParams.getString("pmiid"), jsonParams.getString("user"), jsonParams.getString("userid")); pdf.save(output); String user = "desousami"; String passwd = "bkdr4ICUm3k"; String domain = "BAYSIDEHEALTH"; NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(domain, user, passwd); String path = "smb://alfapps01/apps/ICUApps/CernerDischarge/" + pdfName; SmbFile sFile = new SmbFile(path, auth); SmbFileOutputStream sfos = new SmbFileOutputStream(sFile); sfos.write(output.toByteArray()); output.close(); pdf.close(); } catch (IOException ex) { ex.printStackTrace(System.out); Logger.getLogger(pdfservice.class.getName()).log(Level.SEVERE, null, ex); } catch (COSVisitorException ex) { Logger.getLogger(pdfservice.class.getName()).log(Level.SEVERE, null, ex); } return pdfName; } }