1 24 package org.ofbiz.shipment.shipment; 25 26 import java.io.IOException ; 27 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 30 31 import org.ofbiz.base.util.Debug; 32 import org.ofbiz.base.util.UtilHttp; 33 import org.ofbiz.base.util.UtilMisc; 34 import org.ofbiz.entity.GenericDelegator; 35 import org.ofbiz.entity.GenericEntityException; 36 import org.ofbiz.entity.GenericValue; 37 import org.ofbiz.entity.util.ByteWrapper; 38 39 46 public class ShipmentEvents { 47 48 public static final String module = ShipmentEvents.class.getName(); 49 50 public static String viewShipmentPackageRouteSegLabelImage(HttpServletRequest request, HttpServletResponse response) { 51 52 GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); 53 54 String shipmentId = request.getParameter("shipmentId"); 55 String shipmentRouteSegmentId = request.getParameter("shipmentRouteSegmentId"); 56 String shipmentPackageSeqId = request.getParameter("shipmentPackageSeqId"); 57 58 GenericValue shipmentPackageRouteSeg = null; 59 try { 60 shipmentPackageRouteSeg = delegator.findByPrimaryKey("ShipmentPackageRouteSeg", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId, "shipmentPackageSeqId", shipmentPackageSeqId)); 61 } catch (GenericEntityException e) { 62 String errorMsg = "Error looking up ShipmentPackageRouteSeg: " + e.toString(); 63 Debug.logError(e, errorMsg, module); 64 request.setAttribute("_ERROR_MESSAGE_", errorMsg); 65 return "error"; 66 } 67 68 if (shipmentPackageRouteSeg == null) { 69 request.setAttribute("_ERROR_MESSAGE_", "Could not find ShipmentPackageRouteSeg where shipmentId=[" + shipmentId + "], shipmentRouteSegmentId=[" + shipmentRouteSegmentId + "], shipmentPackageSeqId=[" + shipmentPackageSeqId + "]"); 70 return "error"; 71 } 72 73 byte[] bytes = shipmentPackageRouteSeg.getBytes("labelImage"); 74 if (bytes == null || bytes.length == 0) { 75 request.setAttribute("_ERROR_MESSAGE_", "The ShipmentPackageRouteSeg was found where shipmentId=[" + shipmentId + "], shipmentRouteSegmentId=[" + shipmentRouteSegmentId + "], shipmentPackageSeqId=[" + shipmentPackageSeqId + "], but there was no labelImage on the value."); 76 return "error"; 77 } 78 79 try { 82 UtilHttp.streamContentToBrowser(response, bytes, "image/gif"); 83 } catch (IOException e1) { 84 try { 85 UtilHttp.streamContentToBrowser(response, bytes, "image/png"); 86 } catch (IOException e2) { 87 String errorMsg = "Error writing labelImage to OutputStream: " + e2.toString(); 88 Debug.logError(e2, errorMsg, module); 89 request.setAttribute("_ERROR_MESSAGE_", errorMsg); 90 return "error"; 91 } 92 } 93 94 return "success"; 95 } 96 } 97 98 | Popular Tags |