Subversion Repositories SmartDukaan

Rev

Rev 1884 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1884 Rev 2784
Line 9... Line 9...
9
import in.shop2020.support.services.InvoiceGenerationService;
9
import in.shop2020.support.services.InvoiceGenerationService;
10
 
10
 
11
import org.apache.struts2.interceptor.ServletResponseAware;
11
import org.apache.struts2.interceptor.ServletResponseAware;
12
import org.apache.struts2.rest.DefaultHttpHeaders;
12
import org.apache.struts2.rest.DefaultHttpHeaders;
13
import org.apache.struts2.rest.HttpHeaders;
13
import org.apache.struts2.rest.HttpHeaders;
-
 
14
import org.slf4j.Logger;
-
 
15
import org.slf4j.LoggerFactory;
14
 
16
 
15
public class InvoiceController implements ServletResponseAware{
17
public class InvoiceController implements ServletResponseAware{
16
 
18
 
-
 
19
	private static Logger logger = LoggerFactory.getLogger(InvoiceController.class);
-
 
20
	
17
	private int errorCode = 0;
21
	private int errorCode = 0;
18
	private String errorMessage;
22
	private String errorMessage;
19
	
23
	
20
	private String id;
24
	private String id;
21
	private long orderId;
25
	private long orderId;
Line 24... Line 28...
24
	public InvoiceController(){
28
	public InvoiceController(){
25
		
29
		
26
	}
30
	}
27
	
31
	
28
	public HttpHeaders show(){
32
	public HttpHeaders show(){
29
		System.out.println("Order Id is:  " + getId());
33
		logger.info("Printing invoice for order id: " + getId());
30
		this.orderId = Long.parseLong(getId());
34
		this.orderId = Long.parseLong(getId());
31
		
35
		
32
		InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
36
		InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
33
		ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId);
37
		ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId);
34
		response.setContentType("application/pdf");
38
		response.setContentType("application/pdf");
Line 38... Line 42...
38
		try {
42
		try {
39
			sos = response.getOutputStream();
43
			sos = response.getOutputStream();
40
			baos.writeTo(sos);
44
			baos.writeTo(sos);
41
			sos.flush();
45
			sos.flush();
42
		} catch (IOException e) {
46
		} catch (IOException e) {
43
			// TODO Auto-generated catch block
47
			logger.error("Encountered error while sending invoice response: ", e);
44
			e.printStackTrace();
-
 
45
		}
48
		}
46
 
-
 
47
		
49
		
48
		return new DefaultHttpHeaders("lsuccess");
50
		return new DefaultHttpHeaders("lsuccess");
49
	}
51
	}
50
	
52
	
51
	
-
 
52
	
-
 
53
	public int getErrorCode() {
53
	public int getErrorCode() {
54
		return errorCode;
54
		return errorCode;
55
	}
55
	}
56
 
56
 
57
	public String getErrorMessage() {
57
	public String getErrorMessage() {
Line 67... Line 67...
67
	}
67
	}
68
 
68
 
69
	@Override
69
	@Override
70
	public void setServletResponse(HttpServletResponse response) {
70
	public void setServletResponse(HttpServletResponse response) {
71
		this.response  = response;
71
		this.response  = response;
72
		
-
 
73
	}
72
	}
74
 
73
 
75
}
74
}