Subversion Repositories SmartDukaan

Rev

Rev 6989 | Rev 6993 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6989 Rev 6991
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
3
 
3
 
-
 
4
import in.shop2020.model.v1.order.TransactionService;
4
import in.shop2020.model.v1.order.TransactionServiceException;
5
import in.shop2020.model.v1.order.TransactionServiceException;
5
import in.shop2020.thrift.clients.TransactionClient;
6
import in.shop2020.thrift.clients.TransactionClient;
6
 
7
 
7
import java.io.ByteArrayOutputStream;
8
import java.io.ByteArrayOutputStream;
8
import java.io.File;
9
import java.io.File;
Line 63... Line 64...
63
	public String show(){
64
	public String show(){
64
		orderId = id;
65
		orderId = id;
65
		response.setContentType("application/pdf");
66
		response.setContentType("application/pdf");
66
        response.setHeader("Content-disposition", "inline; filename=invoice-"+orderId+".pdf" );
67
        response.setHeader("Content-disposition", "inline; filename=invoice-"+orderId+".pdf" );
67
        
68
        
-
 
69
        ByteBuffer buffer = null;
-
 
70
        try {
-
 
71
            if (orderId == null || orderId.isEmpty()) {
-
 
72
                logger.error("Order Id is null or empty");
-
 
73
                return "show";
-
 
74
            }
-
 
75
            TransactionClient tc = new TransactionClient("support_transaction_service_server_host", "transaction_service_server_port");
-
 
76
            TransactionService.Client orderClient = transactionServiceClient.getClient();
-
 
77
            buffer = orderClient.retrieveInvoice(Long.parseLong(orderId));
-
 
78
            if(!buffer.hasArray()) {
-
 
79
                logger.error("The invoice does not found");
-
 
80
            }
-
 
81
        } catch (Exception e) {
-
 
82
            System.out.println(e.getMessage());
-
 
83
        }
-
 
84
 
68
        ServletOutputStream sos;
85
        ServletOutputStream sos;
69
        try {
86
        try {
70
        	TransactionClient tc = new TransactionClient("support_transaction_service_server_host", "transaction_service_server_port");
-
 
71
        	ByteBuffer bb = tc.getClient().retrieveInvoice(Long.parseLong(orderId));
-
 
72
        	ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
 
73
			WritableByteChannel channel = Channels.newChannel(baos);
-
 
74
			channel.write(bb);
-
 
75
        	sos = response.getOutputStream();
87
            sos = response.getOutputStream();
76
            baos.writeTo(sos);
88
            sos.write(buffer.array());
77
            sos.flush();
89
            sos.flush();
78
        } catch (Exception e) {
90
        } catch (Exception e) {
79
        	errorMsg = "Invoice not found";
-
 
80
            logger.error("Encountered error while sending invoice response: ", e);
91
            System.out.println("Unable to stream the invoice file");
81
        }
92
        }
82
        return "show";
93
        return "show";
83
	}
94
    }
84
	
-
 
85
			
95
			
86
	@Override
96
	@Override
87
	public void setServletContext(ServletContext context) {
97
	public void setServletContext(ServletContext context) {
88
		this.context = context;
98
		this.context = context;
89
	}
99
	}