Skip to content

Commit

Permalink
fixed #65 Export Packing List > IllegalStateException: getOutputStrea…
Browse files Browse the repository at this point in the history
…m() has already been called for this response
  • Loading branch information
jmiranda committed May 11, 2015
1 parent ee18ecf commit 4141f5e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,44 @@ class ShipmentController {

redirect(controller: "inventory", action: "browse")
}



def exportPackingList = {
log.info "Export packing list for shipment " + params
Shipment shipment = Shipment.get(params.id)
if (!shipment) {
throw new Exception("Could not locate shipment with ID " + params.id)
}

OutputStream outputStream = null
try {
// Write the file to the response
ByteArrayOutputStream baos = new ByteArrayOutputStream()
response.contentType = "application/vnd.ms-excel"
response.setHeader 'Content-disposition', "attachment; filename=\"Shipment ${shipment?.shipmentNumber} - Packing List.xls\""
shipmentService.exportPackingList(params.id, baos)
response.outputStream << baos.toByteArray()
response.outputStream.flush();
return;

} catch (IOException e) {
flash.message = "Failed to export packing list due to the following error: " + e.message
} catch (Exception e) {
log.warn("Failed to export packing list due to the following error: " + e.message, e)
flash.message = "Failed to export packing list due to the following error: " + e.message
} finally {
if (outputStream != null){
try {
outputStream.close()
} catch (IOException e) {
log.error('IOException occurred while closing output stream', e)
}
}
}
redirect(controller: "shipment", action: "showDetails", id: params.id)
}

}

class ReceiveShipmentCommand implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<button id="btnAddContents" class="button icon log">
<warehouse:message code="shipping.importPackingList.label" default="Import packing list"/></button>

<g:link controller="createShipmentWorkflow" action="createShipment" event="exportPackingList" id="${shipmentInstance.id}" class="button icon arrowdown">
<g:link controller="shipment" action="exportPackingList" id="${shipmentInstance.id}" class="button icon arrowdown">
<warehouse:message code="shipping.exportPackingList.label" default="Export packing list"/>
</g:link>

Expand Down

0 comments on commit 4141f5e

Please sign in to comment.