Author: jonesde
Date: Fri Aug 3 06:05:18 2007 New Revision: 562455 URL: http://svn.apache.org/viewvc?view=rev&rev=562455 Log: Some code updates to handle errors better and save interim information, and clean up how certain things flow and are done for more consistent operation Modified: ofbiz/trunk/specialpurpose/oagis/script/org/ofbiz/oagis/OagisMessageServices.xml ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java Modified: ofbiz/trunk/specialpurpose/oagis/script/org/ofbiz/oagis/OagisMessageServices.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/script/org/ofbiz/oagis/OagisMessageServices.xml?view=diff&rev=562455&r1=562454&r2=562455 ============================================================================== --- ofbiz/trunk/specialpurpose/oagis/script/org/ofbiz/oagis/OagisMessageServices.xml (original) +++ ofbiz/trunk/specialpurpose/oagis/script/org/ofbiz/oagis/OagisMessageServices.xml Fri Aug 3 06:05:18 2007 @@ -49,9 +49,7 @@ <simple-method method-name="createOagisMessageErrorInfo" short-description="Create MessageErrorInfo"> <make-value entity-name="OagisMessageErrorInfo" value-name="newEntity"/> <set-pk-fields map-name="parameters" value-name="newEntity" /> - <if-empty field-name="parameters.errorSeqId"> - <sequenced-id-to-env sequence-name="OagisMessageErrorInfo" env-name="newEntity.errorSeqId"/> - </if-empty> + <make-next-seq-id value-name="newEntity" seq-field-name="errorSeqId"/> <set-nonpk-fields map-name="parameters" value-name="newEntity"/> <create-value value-name="newEntity"/> </simple-method> @@ -78,17 +76,4 @@ </else> </if-not-empty> </simple-method> - - <simple-method method-name="sendProcessShipmentMsg" - short-description="Send Process Shipment Message"> - <set field="serviceContext.bodyParameters.shipmentId" from-field="parameters.shipmentId"/> - <set field="serviceContext.bodyParameters.logicalId" from-field="parameters.logicalId"/> - <set field="serviceContext.bodyParameters.authId" from-field="parameters.authId"/> - <set field="serviceContext.bodyParameters.referenceId" from-field="parameters.referenceId"/> - <set field="serviceContext.bodyParameters.sentDate" from-field="parameters.sentDate" type="Timestamp"/> - <set field="serviceContext.bodyScreenUri" value="component://oagis/widget/MessageInfoScreens.xml#ProcessShipment"/> - <call-service service-name="exportMsgFromScreen" in-map-name="serviceContext"/> - <!-- Todo: Get partner server url to post the message --> - </simple-method> - </simple-methods> Modified: ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java?view=diff&rev=562455&r1=562454&r2=562455 ============================================================================== --- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java (original) +++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java Fri Aug 3 06:05:18 2007 @@ -315,7 +315,7 @@ } } try { - dispatcher.runAsync("createOagisMessageInfo", comiCtx, true); + dispatcher.runSync("createOagisMessageInfo", comiCtx, 60, true); /* now calling async for better error handling if (ServiceUtil.isError(comiResult)) { String errMsg = ServiceUtil.getErrorMessage(comiResult); @@ -324,7 +324,7 @@ */ } catch (GenericServiceException e) { String errMsg = "Error creating OagisMessageInfo for the Incoming Message: " + e.toString(); - errorMapList.add(UtilMisc.toMap("reasonCode", "CreateOagisMessageInfoError", "description", errMsg)); + //errorMapList.add(UtilMisc.toMap("reasonCode", "CreateOagisMessageInfoError", "description", errMsg)); Debug.logError(e, errMsg, module); } @@ -524,7 +524,7 @@ } } try { - dispatcher.runAsync("createOagisMessageInfo", comiCtx, true); + dispatcher.runSync("createOagisMessageInfo", comiCtx, 60, true); /* running async for better error handling if (ServiceUtil.isError(comiResult)) { String errMsg = ServiceUtil.getErrorMessage(comiResult); @@ -533,8 +533,8 @@ */ } catch (GenericServiceException e) { String errMsg = "Error creating OagisMessageInfo for the Incoming Message: " + e.toString(); - // TODO: reconsider sending this error back to other server, not much they can do about it, and it may not be a critical error causing the message to be rejected... - errorMapList.add(UtilMisc.toMap("reasonCode", "CreateOagisMessageInfoError", "description", errMsg)); + // reconsider sending this error back to other server, not much they can do about it, and it may not be a critical error causing the message to be rejected... + //errorMapList.add(UtilMisc.toMap("reasonCode", "CreateOagisMessageInfoError", "description", errMsg)); Debug.logError(e, errMsg, module); } Map result = FastMap.newInstance(); @@ -766,7 +766,7 @@ } } try { - dispatcher.runAsync("createOagisMessageInfo", comiCtx); + dispatcher.runSync("createOagisMessageInfo", comiCtx, 60, true); /* running async for better error handling if (ServiceUtil.isError(comiResult)) { String errMsg = ServiceUtil.getErrorMessage(comiResult); @@ -775,8 +775,8 @@ */ } catch (GenericServiceException e) { String errMsg = "Error creating OagisMessageInfo for the Incoming Message: " + e.toString(); - // TODO: reconsider sending this error back to other server, not much they can do about it, and it may not be a critical error causing the message to be rejected... - errorMapList.add(UtilMisc.toMap("reasonCode", "CreateOagisMessageInfoError", "description", errMsg)); + // reconsider sending this error back to other server, not much they can do about it, and it may not be a critical error causing the message to be rejected... + //errorMapList.add(UtilMisc.toMap("reasonCode", "CreateOagisMessageInfoError", "description", errMsg)); Debug.logError(e, errMsg, module); } Modified: ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java?view=diff&rev=562455&r1=562454&r2=562455 ============================================================================== --- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java (original) +++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java Fri Aug 3 06:05:18 2007 @@ -1,6 +1,4 @@ -package org.ofbiz.oagis; - -/** +/* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information @@ -17,7 +15,9 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -**/ +*/ +package org.ofbiz.oagis; + import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.ByteArrayInputStream; @@ -127,31 +127,13 @@ bodyParameters.put("origRef", context.get("origRefId")); String bodyScreenUri = UtilProperties.getPropertyValue("oagis.properties", "Oagis.Template.ConfirmBod"); - Writer writer = null; - if (out != null) { - writer = new OutputStreamWriter(out); - } else if (UtilValidate.isNotEmpty(saveToFilename)) { - try { - File outdir = new File(saveToDirectory); - if (!outdir.exists()) { - outdir.mkdir(); - } - writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(outdir, saveToFilename)), "UTF-8"))); - } catch (Exception e) { - String errMsg = "Error opening file to save message to [" + saveToFilename + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(errMsg); - } - } else if (UtilValidate.isNotEmpty(sendToUrl)) { - writer = new StringWriter(); - } else { - return ServiceUtil.returnError("No send to information pass (url, file, or out stream)"); - } - - ScreenRenderer screens = new ScreenRenderer(writer, bodyParameters, new HtmlScreenRenderer()); + String outText = null; try { + Writer writer = new StringWriter(); + ScreenRenderer screens = new ScreenRenderer(writer, bodyParameters, new HtmlScreenRenderer()); screens.render(bodyScreenUri); writer.close(); + outText = writer.toString(); } catch (Exception e) { String errMsg = "Error rendering message: " + e.toString(); Debug.logError(e, errMsg, module); @@ -171,8 +153,11 @@ oagisMsgInfoContext.put("bsrNoun", "BOD"); oagisMsgInfoContext.put("bsrRevision", "004"); oagisMsgInfoContext.put("userLogin", userLogin); + if (OagisServices.debugSaveXmlOut) { + oagisMsgInfoContext.put("fullMessageXml", outText); + } try { - dispatcher.runAsync("createOagisMessageInfo", oagisMsgInfoContext, true); + dispatcher.runSync("createOagisMessageInfo", oagisMsgInfoContext, 60, true); /* running async for better error handling if (ServiceUtil.isError(oagisMsgInfoResult)) return ServiceUtil.returnError("Error creating OagisMessageInfo"); */ @@ -181,31 +166,9 @@ Debug.logError(e, "Saving message to database failed", module); } - if (UtilValidate.isNotEmpty(sendToUrl)) { - HttpClient http = new HttpClient(sendToUrl); - - // test parameters - http.setHostVerificationLevel(SSLUtil.HOSTCERT_NO_CHECK); - http.setAllowUntrusted(true); - http.setDebug(true); - - // needed XML post parameters - if (UtilValidate.isNotEmpty(certAlias)) { - http.setClientCertificateAlias(certAlias); - } - if (UtilValidate.isNotEmpty(basicAuthUsername)) { - http.setBasicAuthInfo(basicAuthUsername, basicAuthPassword); - } - http.setContentType("text/xml"); - http.setKeepAlive(true); - - try { - String resp = http.post(writer.toString()); - } catch (Exception e) { - String errMsg = "Error posting message to server with UTL [" + sendToUrl + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(errMsg); - } + Map sendMessageReturn = OagisServices.sendMessageText(outText, out, sendToUrl, saveToDirectory, saveToFilename); + if (sendMessageReturn != null) { + return sendMessageReturn; } return ServiceUtil.returnSuccess("Service Completed Successfully"); @@ -272,7 +235,7 @@ oagisMsgInfoCtx.put("outgoingMessage", "N"); oagisMsgInfoCtx.put("userLogin", userLogin); try { - dispatcher.runAsync("createOagisMessageInfo", oagisMsgInfoCtx, true); + dispatcher.runSync("createOagisMessageInfo", oagisMsgInfoCtx, 60, true); /* running async for better error handling if (ServiceUtil.isError(oagisMsgInfoResult)){ String errMsg = "Error creating OagisMessageInfo for the Incoming Message: "+ServiceUtil.getErrorMessage(oagisMsgInfoResult); @@ -371,7 +334,7 @@ ByteArrayInputStream bis = new ByteArrayInputStream(xmlText.getBytes("UTF-8")); doc = UtilXml.readXmlDocument(bis, true, "OagisMessage"); } catch (SAXException e) { - String errMsg = "XML Error parsing the Received Message [" + e.toString() + "]; The text received we could not parse is: " + xmlText; + String errMsg = "XML Error parsing the Received Message [" + e.toString() + "]; The text received we could not parse is: [" + xmlText + "]"; errorList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "SAXException")); Debug.logError(e, errMsg, module); } catch (ParserConfigurationException e) { @@ -468,5 +431,63 @@ } return result; + } + + public static Map sendMessageText(String outText, OutputStream out, String sendToUrl, String saveToDirectory, String saveToFilename) { + if (out != null) { + Writer outWriter = new OutputStreamWriter(out); + try { + outWriter.write(outText); + outWriter.close(); + } catch (IOException e) { + String errMsg = "Error writing message to output stream: " + e.toString(); + Debug.logError(e, errMsg, module); + return ServiceUtil.returnError(errMsg); + } + } else if (UtilValidate.isNotEmpty(saveToFilename)) { + try { + File outdir = new File(saveToDirectory); + if (!outdir.exists()) { + outdir.mkdir(); + } + Writer outWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(outdir, saveToFilename)), "UTF-8"))); + outWriter.write(outText); + outWriter.close(); + } catch (Exception e) { + String errMsg = "Error saving message to file [" + saveToFilename + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + return ServiceUtil.returnError(errMsg); + } + } else if (UtilValidate.isNotEmpty(sendToUrl)) { + HttpClient http = new HttpClient(sendToUrl); + + // test parameters + http.setHostVerificationLevel(SSLUtil.HOSTCERT_NO_CHECK); + http.setAllowUntrusted(true); + http.setDebug(true); + + // needed XML post parameters + if (UtilValidate.isNotEmpty(certAlias)) { + http.setClientCertificateAlias(certAlias); + } + if (UtilValidate.isNotEmpty(basicAuthUsername)) { + http.setBasicAuthInfo(basicAuthUsername, basicAuthPassword); + } + http.setContentType("text/xml"); + http.setKeepAlive(true); + + try { + http.post(outText); + } catch (Exception e) { + String errMsg = "Error posting message to server with URL [" + sendToUrl + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + return ServiceUtil.returnError(errMsg); + } + } else { + if (Debug.infoOn()) Debug.logInfo("No send to information, so here is the message: " + outText, module); + return ServiceUtil.returnError("No send to information pass (url, file, or out stream)"); + } + + return null; } } Modified: ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java?view=diff&rev=562455&r1=562454&r2=562455 ============================================================================== --- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java (original) +++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java Fri Aug 3 06:05:18 2007 @@ -1,6 +1,4 @@ -package org.ofbiz.oagis; - -/** +/* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information @@ -17,39 +15,29 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -**/ -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileOutputStream; +*/ + +package org.ofbiz.oagis; + import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.io.StringWriter; import java.io.Writer; import java.sql.Timestamp; import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; -import java.util.TreeSet; - -import javax.xml.parsers.ParserConfigurationException; import javolution.util.FastList; import javolution.util.FastMap; import javolution.util.FastSet; import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.HttpClient; -import org.ofbiz.base.util.SSLUtil; import org.ofbiz.base.util.UtilDateTime; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilProperties; @@ -65,18 +53,16 @@ import org.ofbiz.entity.condition.EntityOperator; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.order.order.OrderReadHelper; +import org.ofbiz.party.party.PartyWorker; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; -import org.ofbiz.service.ModelService; import org.ofbiz.service.ServiceUtil; import org.ofbiz.widget.fo.FoFormRenderer; import org.ofbiz.widget.html.HtmlScreenRenderer; import org.ofbiz.widget.screen.ScreenRenderer; import org.w3c.dom.Document; import org.w3c.dom.Element; -import org.xml.sax.SAXException; -import org.ofbiz.party.party.PartyWorker; public class OagisShipmentServices { @@ -298,7 +284,6 @@ LocalDispatcher dispatcher = ctx.getDispatcher(); GenericDelegator delegator = ctx.getDelegator(); String orderId = (String) context.get("orderId"); - String shipmentId = (String) context.get("shipmentId"); String sendToUrl = (String) context.get("sendToUrl"); if (UtilValidate.isEmpty(sendToUrl)) { @@ -306,9 +291,19 @@ } String saveToFilename = (String) context.get("saveToFilename"); + if (UtilValidate.isEmpty(saveToFilename)) { + String saveToFilenameBase = UtilProperties.getPropertyValue("oagis.properties", "test.save.outgoing.filename.base", ""); + saveToFilename = saveToFilenameBase + "ProcessShipment" + orderId + ".xml"; + } String saveToDirectory = (String) context.get("saveToDirectory"); + if (UtilValidate.isEmpty(saveToDirectory)) { + saveToDirectory = UtilProperties.getPropertyValue("oagis.properties", "test.save.outgoing.directory"); + } + OutputStream out = (OutputStream) context.get("outputStream"); + if (Debug.infoOn()) Debug.logInfo("Call to oagisProcessShipment for orderId [" + orderId + "], sendToUrl=[" + sendToUrl + "], saveToDirectory=[" + saveToDirectory + "], saveToFilename=[" + saveToFilename + "]", module); + Map result = ServiceUtil.returnSuccess(); MapStack bodyParameters = MapStack.create(); @@ -347,8 +342,45 @@ if (orderHeader != null) { String orderStatusId = orderHeader.getString("statusId"); if (orderStatusId.equals("ORDER_APPROVED")) { - try { + String logicalId = UtilProperties.getPropertyValue("oagis.properties", "CNTROLAREA.SENDER.LOGICALID"); + bodyParameters.put("logicalId", logicalId); + Map comiCtx = UtilMisc.toMap("logicalId", logicalId); + + String authId = UtilProperties.getPropertyValue("oagis.properties", "CNTROLAREA.SENDER.AUTHID"); + bodyParameters.put("authId", authId); + comiCtx.put("authId", authId); + + String referenceId = delegator.getNextSeqId("OagisMessageInfo"); + bodyParameters.put("referenceId", referenceId); + comiCtx.put("referenceId", referenceId); + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSS'Z'Z"); + Timestamp timestamp = UtilDateTime.nowTimestamp(); + String sentDate = dateFormat.format(timestamp); + bodyParameters.put("sentDate", sentDate); + comiCtx.put("sentDate", timestamp); + // prepare map to Create Oagis Message Info + comiCtx.put("processingStatusId", "OAGMP_TRIGGERED"); + comiCtx.put("component", "INVENTORY"); + comiCtx.put("task", "SHIPREQUES"); // Actual value of task is "SHIPREQUEST" which is more than 10 char + comiCtx.put("outgoingMessage", "Y"); + comiCtx.put("confirmation", "1"); + comiCtx.put("bsrVerb", "PROCESS"); + comiCtx.put("bsrNoun", "SHIPMENT"); + comiCtx.put("bsrRevision", "001"); + comiCtx.put("processingStatusId", orderStatusId); + comiCtx.put("orderId", orderId); + comiCtx.put("userLogin", userLogin); + try { + dispatcher.runSync("createOagisMessageInfo", comiCtx, 60, true); + } catch (GenericServiceException e){ + String errMsg = UtilProperties.getMessage(ServiceUtil.resource, "OagisErrorInCreatingDataForOagisMessageInfoEntity", (Locale) context.get("locale")); + Debug.logError(e, errMsg, module); + } + if (Debug.infoOn()) Debug.logInfo("Saved OagisMessageInfo for oagisProcessShipment message for orderId [" + orderId + "]", module); + + String shipmentId = null; + try { // check to see if there is already a Shipment for this order EntityCondition findShipmentCondition = new EntityConditionList(UtilMisc.toList( new EntityExpr("primaryOrderId", EntityOperator.EQUALS, orderId), @@ -437,110 +469,51 @@ return ServiceUtil.returnError(errMsg); } - String logicalId = UtilProperties.getPropertyValue("oagis.properties", "CNTROLAREA.SENDER.LOGICALID"); - bodyParameters.put("logicalId", logicalId); - Map comiCtx = UtilMisc.toMap("logicalId", logicalId); - - String authId = UtilProperties.getPropertyValue("oagis.properties", "CNTROLAREA.SENDER.AUTHID"); - bodyParameters.put("authId", authId); - comiCtx.put("authId", authId); - - String referenceId = delegator.getNextSeqId("OagisMessageInfo"); - bodyParameters.put("referenceId", referenceId); - comiCtx.put("referenceId", referenceId); - - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSS'Z'Z"); - Timestamp timestamp = UtilDateTime.nowTimestamp(); - String sentDate = dateFormat.format(timestamp); - bodyParameters.put("sentDate", sentDate); - comiCtx.put("sentDate", timestamp); - bodyParameters.put("shipmentId", shipmentId); bodyParameters.put("orderId", orderId); bodyParameters.put("userLogin", userLogin); - String bodyScreenUri = UtilProperties.getPropertyValue("oagis.properties", "Oagis.Template.ProcessShipment"); - Writer writer = null; - if (out != null) { - writer = new OutputStreamWriter(out); - } else if (UtilValidate.isNotEmpty(saveToFilename)) { - try { - File outdir = new File(saveToDirectory); - if (!outdir.exists()) { - outdir.mkdir(); - } - writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(outdir, saveToFilename)), "UTF-8"))); - } catch (Exception e) { - String errMsg = "Error opening file to save message to [" + saveToFilename + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(errMsg); - } - } else if (UtilValidate.isNotEmpty(sendToUrl)) { - writer = new StringWriter(); - } else { - return ServiceUtil.returnError("No send to information pass (url, file, or out stream)"); - } + + String bodyScreenUri = UtilProperties.getPropertyValue("oagis.properties", "Oagis.Template.ProcessShipment"); - ScreenRenderer screens = new ScreenRenderer(writer, bodyParameters, new HtmlScreenRenderer()); + String outText = null; try { + Writer writer = new StringWriter(); + ScreenRenderer screens = new ScreenRenderer(writer, bodyParameters, htmlScreenRenderer); screens.render(bodyScreenUri); writer.close(); + outText = writer.toString(); } catch (Exception e) { String errMsg = "Error rendering message: " + e.toString(); Debug.logError(e, errMsg, module); return ServiceUtil.returnError(errMsg); } - - // TODO: should we make sure this is saved in error conditions - // prepare map to Create Oagis Message Info - comiCtx.put("component", "INVENTORY"); - comiCtx.put("task", "SHIPREQUES"); // Actual value of task is "SHIPREQUEST" which is more than 10 char - comiCtx.put("outgoingMessage", "Y"); - comiCtx.put("confirmation", "1"); - comiCtx.put("bsrVerb", "PROCESS"); - comiCtx.put("bsrNoun", "SHIPMENT"); - comiCtx.put("bsrRevision", "001"); - comiCtx.put("processingStatusId", orderStatusId); - comiCtx.put("orderId", orderId); + if (Debug.infoOn()) Debug.logInfo("Finished rendering oagisProcessShipment message for orderId [" + orderId + "]", module); + + comiCtx.put("processingStatusId", "OAGMP_OGEN_SUCCESS"); comiCtx.put("shipmentId", shipmentId); - comiCtx.put("userLogin", userLogin); if (OagisServices.debugSaveXmlOut) { - comiCtx.put("fullMessageXml", writer.toString()); + comiCtx.put("fullMessageXml", outText); } - try { - dispatcher.runAsync("createOagisMessageInfo", comiCtx, true); + dispatcher.runSync("updateOagisMessageInfo", comiCtx, 60, true); } catch (GenericServiceException e){ String errMsg = UtilProperties.getMessage(ServiceUtil.resource, "OagisErrorInCreatingDataForOagisMessageInfoEntity", (Locale) context.get("locale")); Debug.logError(e, errMsg, module); } - - if (UtilValidate.isNotEmpty(sendToUrl)) { - HttpClient http = new HttpClient(sendToUrl); - - // test parameters - http.setHostVerificationLevel(SSLUtil.HOSTCERT_NO_CHECK); - http.setAllowUntrusted(true); - http.setDebug(true); - - // needed XML post parameters - if (UtilValidate.isNotEmpty(certAlias)) { - http.setClientCertificateAlias(certAlias); - } - if (UtilValidate.isNotEmpty(basicAuthUsername)) { - http.setBasicAuthInfo(basicAuthUsername, basicAuthPassword); - } - http.setContentType("text/xml"); - http.setKeepAlive(true); + Map sendMessageReturn = OagisServices.sendMessageText(outText, out, sendToUrl, saveToDirectory, saveToFilename); + if (sendMessageReturn != null) { + return sendMessageReturn; + } + if (Debug.infoOn()) Debug.logInfo("Message send done for oagisProcessShipment for orderId [" + orderId + "], sendToUrl=[" + sendToUrl + "], saveToDirectory=[" + saveToDirectory + "], saveToFilename=[" + saveToFilename + "]", module); - try { - http.post(writer.toString()); - } catch (Exception e) { - String errMsg = "Error posting message to server with UTL [" + sendToUrl + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(errMsg); - } + comiCtx.put("processingStatusId", "OAGMP_SENT"); + try { + dispatcher.runSync("updateOagisMessageInfo", comiCtx, 60, true); + } catch (GenericServiceException e){ + String errMsg = UtilProperties.getMessage(ServiceUtil.resource, "OagisErrorInCreatingDataForOagisMessageInfoEntity", (Locale) context.get("locale")); + Debug.logError(e, errMsg, module); } } } @@ -559,7 +532,14 @@ } String saveToFilename = (String) context.get("saveToFilename"); + if (UtilValidate.isEmpty(saveToFilename)) { + String saveToFilenameBase = UtilProperties.getPropertyValue("oagis.properties", "test.save.outgoing.filename.base", ""); + saveToFilename = saveToFilenameBase + "ProcessShipment" + returnId + ".xml"; + } String saveToDirectory = (String) context.get("saveToDirectory"); + if (UtilValidate.isEmpty(saveToDirectory)) { + saveToDirectory = UtilProperties.getPropertyValue("oagis.properties", "test.save.outgoing.directory"); + } OutputStream out = (OutputStream) context.get("outputStream"); Map result = ServiceUtil.returnSuccess(); @@ -651,37 +631,19 @@ bodyParameters.put("returnId", returnId); String bodyScreenUri = UtilProperties.getPropertyValue("oagis.properties", "Oagis.Template.ReceiveDelivery"); - Writer writer = null; - if (out != null) { - writer = new OutputStreamWriter(out); - } else if (UtilValidate.isNotEmpty(saveToFilename)) { - try { - File outdir = new File(saveToDirectory); - if (!outdir.exists()) { - outdir.mkdir(); - } - writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(outdir, saveToFilename)), "UTF-8"))); - } catch (Exception e) { - String errMsg = "Error opening file to save message to [" + saveToFilename + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(errMsg); - } - } else if (UtilValidate.isNotEmpty(sendToUrl)) { - writer = new StringWriter(); - } else { - return ServiceUtil.returnError("No send to information pass (url, file, or out stream)"); - } - - ScreenRenderer screens = new ScreenRenderer(writer, bodyParameters, new HtmlScreenRenderer()); + String outText = null; try { + Writer writer = new StringWriter(); + ScreenRenderer screens = new ScreenRenderer(writer, bodyParameters, htmlScreenRenderer); screens.render(bodyScreenUri); writer.close(); + outText = writer.toString(); } catch (Exception e) { String errMsg = "Error rendering message: " + e.toString(); Debug.logError(e, errMsg, module); return ServiceUtil.returnError(errMsg); } - + // TODO: call service with require-new-transaction=true to save the OagisMessageInfo data (to make sure it saves before) // prepare map to Create Oagis Message Info comiCtx.put("component", "INVENTORY"); @@ -695,41 +657,19 @@ comiCtx.put("returnId", returnId); comiCtx.put("userLogin", userLogin); if (OagisServices.debugSaveXmlOut) { - comiCtx.put("fullMessageXml", writer.toString()); + comiCtx.put("fullMessageXml", outText); } try { - dispatcher.runAsync("createOagisMessageInfo", comiCtx, true); + dispatcher.runSync("createOagisMessageInfo", comiCtx, 60, true); } catch (GenericServiceException e) { String errMsg = UtilProperties.getMessage(ServiceUtil.resource, "OagisErrorInCreatingDataForOagisMessageInfoEntity", (Locale) context.get("locale")); Debug.logError(e, errMsg, module); } - if (UtilValidate.isNotEmpty(sendToUrl)) { - HttpClient http = new HttpClient(sendToUrl); - - // test parameters - http.setHostVerificationLevel(SSLUtil.HOSTCERT_NO_CHECK); - http.setAllowUntrusted(true); - http.setDebug(true); - - // needed XML post parameters - if (UtilValidate.isNotEmpty(certAlias)) { - http.setClientCertificateAlias(certAlias); - } - if (UtilValidate.isNotEmpty(basicAuthUsername)) { - http.setBasicAuthInfo(basicAuthUsername, basicAuthPassword); - } - http.setContentType("text/xml"); - http.setKeepAlive(true); - - try { - http.post(writer.toString()); - } catch (Exception e) { - String errMsg = "Error posting message to server with UTL [" + sendToUrl + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(errMsg); - } + Map sendMessageReturn = OagisServices.sendMessageText(outText, out, sendToUrl, saveToDirectory, saveToFilename); + if (sendMessageReturn != null) { + return sendMessageReturn; } } } |
Free forum by Nabble | Edit this page |