Skip to content
Snippets Groups Projects
Commit 0155146d authored by ammar's avatar ammar
Browse files

Send PDF file for payment history PDF request

parent f77505ab
Branches master
No related merge requests found
......@@ -36,6 +36,7 @@ services:
dockerfile: Dockerfile
environment:
REST_API_KEY: "REST_API_KEY"
PDF_FILE_LOCATION: "/opt/saved_history"
MONOLITH_API_KEY: "MONOLITH_API_KEY"
sender_email: kms.bizzzzzz@gmail.com
sender_password:
......
......@@ -4,7 +4,6 @@ import com.j256.ormlite.dao.Dao;
import com.kms.crosscut.SoapFaultHelper;
import com.kms.dto.EmailReq;
import com.kms.dto.payment.PaymentHistoryResp;
import com.kms.model.Payment;
import com.kms.service.helper.PaymentHistoryCacheHelper;
import com.kms.util.PdfUtil;
......@@ -15,6 +14,7 @@ import freemarker.template.TemplateExceptionHandler;
import lombok.RequiredArgsConstructor;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.annotation.Resource;
import javax.jws.HandlerChain;
import javax.jws.WebMethod;
......@@ -23,9 +23,7 @@ import javax.jws.WebService;
import javax.xml.bind.annotation.XmlMimeType;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import javax.xml.ws.soap.MTOM;
import java.io.IOException;
import java.io.StringWriter;
import java.sql.SQLException;
......@@ -39,6 +37,7 @@ import java.util.stream.Collectors;
@WebService
@RequiredArgsConstructor
@HandlerChain(file = "handlers.xml")
@MTOM(threshold = 512)
public class PaymentHistoryService {
@Resource
......@@ -153,8 +152,8 @@ public class PaymentHistoryService {
SoapFaultHelper.throwFault("UnexpectedError", "Unexpected error has happened.");
}
return getPdfDataHandler(filePath);
} catch (SQLException | TemplateException | IOException ignored) {
System.out.println(ignored);
} catch (SQLException | TemplateException | IOException e) {
System.out.println(e.getMessage());
SoapFaultHelper.throwFault("UnexpectedError", "Unexpected error has happened.");
}
......@@ -162,15 +161,7 @@ public class PaymentHistoryService {
}
private DataHandler getPdfDataHandler(String filePath) {
File file = new File(filePath);
byte[] byteArr = new byte[(int) file.length()];
try (FileInputStream fileInputStream = new FileInputStream(file)) {
fileInputStream.read(byteArr);
} catch (IOException e) {
SoapFaultHelper.throwFault("UnexpectedError", "Unexpected error has happened.");
}
return new DataHandler(byteArr, "application/pdf");
return new DataHandler(new FileDataSource(filePath));
}
private String formPdfFilename(String initiatorId) {
......
......@@ -12,7 +12,17 @@ import java.nio.file.Files;
public class PdfUtil {
private static final String PDF_FILE_LOCATION = System.getenv("PDF_FILE_LOCATION");
private static final String PDF_FILE_LOCATION;
static {
String pdfFileLocation = System.getenv("PDF_FILE_LOCATION");
if (!pdfFileLocation.endsWith("/")) {
pdfFileLocation += "/";
}
PDF_FILE_LOCATION = pdfFileLocation;
}
public static void writePdfToFile(String html, String filename) {
final File file = new File(PDF_FILE_LOCATION+filename);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment