| 490 |
rajveer |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
|
|
3 |
import java.io.ByteArrayOutputStream;
|
|
|
4 |
import java.io.IOException;
|
|
|
5 |
|
|
|
6 |
import javax.servlet.ServletOutputStream;
|
|
|
7 |
import javax.servlet.http.HttpServletResponse;
|
|
|
8 |
|
|
|
9 |
import in.shop2020.support.services.InvoiceGenerationService;
|
|
|
10 |
|
|
|
11 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
|
|
12 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
|
|
13 |
import org.apache.struts2.rest.HttpHeaders;
|
|
|
14 |
|
|
|
15 |
public class InvoiceController implements ServletResponseAware{
|
|
|
16 |
|
|
|
17 |
private int errorCode = 0;
|
|
|
18 |
private String errorMessage;
|
|
|
19 |
|
|
|
20 |
private String id;
|
|
|
21 |
private long orderId;
|
|
|
22 |
private HttpServletResponse response;
|
|
|
23 |
|
|
|
24 |
public InvoiceController(){
|
|
|
25 |
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
public HttpHeaders show(){
|
|
|
29 |
System.out.println("Order Id is: " + getId());
|
|
|
30 |
this.orderId = Long.parseLong(getId());
|
|
|
31 |
|
| 734 |
chandransh |
32 |
InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
|
|
|
33 |
ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId);
|
| 490 |
rajveer |
34 |
response.setContentType("application/pdf");
|
|
|
35 |
response.setHeader("Content-disposition", "inline; filename=invoice-"+orderId+".pdf" );
|
|
|
36 |
|
|
|
37 |
ServletOutputStream sos;
|
|
|
38 |
try {
|
|
|
39 |
sos = response.getOutputStream();
|
|
|
40 |
baos.writeTo(sos);
|
|
|
41 |
sos.flush();
|
|
|
42 |
} catch (IOException e) {
|
|
|
43 |
// TODO Auto-generated catch block
|
|
|
44 |
e.printStackTrace();
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
return new DefaultHttpHeaders("lsuccess");
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
public int getErrorCode() {
|
|
|
54 |
return errorCode;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
public String getErrorMessage() {
|
|
|
58 |
return errorMessage;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
public String getId(){
|
|
|
62 |
return id;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
public void setId(String id){
|
|
|
66 |
this.id = id;
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
@Override
|
|
|
70 |
public void setServletResponse(HttpServletResponse response) {
|
|
|
71 |
this.response = response;
|
|
|
72 |
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
}
|