svn commit: r552772 - in /ofbiz/trunk/specialpurpose/oagis: config/oagis.properties servicedef/secas.xml servicedef/services.xml src/org/ofbiz/oagis/OagisShipmentServices.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r552772 - in /ofbiz/trunk/specialpurpose/oagis: config/oagis.properties servicedef/secas.xml servicedef/services.xml src/org/ofbiz/oagis/OagisShipmentServices.java

jonesde
Author: jonesde
Date: Tue Jul  3 03:17:05 2007
New Revision: 552772

URL: http://svn.apache.org/viewvc?view=rev&rev=552772
Log:
Some changes to the processShipment service (which is now oagisProcessShipment to separate it further) so it can do various things with the export output

Modified:
    ofbiz/trunk/specialpurpose/oagis/config/oagis.properties
    ofbiz/trunk/specialpurpose/oagis/servicedef/secas.xml
    ofbiz/trunk/specialpurpose/oagis/servicedef/services.xml
    ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java

Modified: ofbiz/trunk/specialpurpose/oagis/config/oagis.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/config/oagis.properties?view=diff&rev=552772&r1=552771&r2=552772
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/config/oagis.properties (original)
+++ ofbiz/trunk/specialpurpose/oagis/config/oagis.properties Tue Jul  3 03:17:05 2007
@@ -27,7 +27,10 @@
 Oagis.Template.ReceiveDelivery=component://oagis/widget/MessageInfoScreens.xml#ReceiveDelivery
 Oagis.Template.ProcessShipment=component://oagis/widget/MessageInfoScreens.xml#ProcessShipment
 
+# Client Cert, etc settings
+auth.client.certificate.alias=testrpckey
+
 # URLs for outgoing messages
-url.send.processShipment=https://foo.bar.baz/oagis/control/processShipment
-url.send.confirmBod=https://foo.bar.baz/oagis/control/confirmBod
-url.send.receiveDelivery=https://foo.bar.baz/oagis/control/receiveDelivery
+#url.send.processShipment=https://foo.bar.baz/oagis/control/processShipment
+#url.send.confirmBod=https://foo.bar.baz/oagis/control/confirmBod
+#url.send.receiveDelivery=https://foo.bar.baz/oagis/control/receiveDelivery

Modified: ofbiz/trunk/specialpurpose/oagis/servicedef/secas.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/servicedef/secas.xml?view=diff&rev=552772&r1=552771&r2=552772
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/servicedef/secas.xml (original)
+++ ofbiz/trunk/specialpurpose/oagis/servicedef/secas.xml Tue Jul  3 03:17:05 2007
@@ -26,7 +26,7 @@
         <condition field-name="statusId" operator="equals" value="ORDER_APPROVED"/>
         <condition field-name="orderTypeId" operator="equals" value="SALES_ORDER"/>
         <condition-field field-name="statusId" operator="not-equals" to-field-name="oldStatusId"/>
-        <action service="processShipment" mode="sync"/>
+        <action service="oagisProcessShipment" mode="sync"/>
     </eca-->
     <eca service="processShipment" event="commit" run-on-error="false">
         <action service="createOagisMessageInfo" mode="sync"/>

Modified: ofbiz/trunk/specialpurpose/oagis/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/servicedef/services.xml?view=diff&rev=552772&r1=552771&r2=552772
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/servicedef/services.xml (original)
+++ ofbiz/trunk/specialpurpose/oagis/servicedef/services.xml Tue Jul  3 03:17:05 2007
@@ -104,11 +104,16 @@
         <attribute name="bodyParameters" type="Map" mode="IN" optional="true"/>
         <attribute name="body" type="String" mode="OUT" optional="true"/>
     </service>
-    <service name="processShipment" max-retry="0" engine="java"
-        location="org.ofbiz.oagis.OagisShipmentServices" invoke="processShipment">
-        <description>Process Shipment</description>
+    <service name="oagisProcessShipment" max-retry="0" engine="java"
+        location="org.ofbiz.oagis.OagisShipmentServices" invoke="oagisProcessShipment">
+        <description>Prepare and Optionally Send OAGIS Process Shipment Message.
+            Note on usage: you can pass in either sendToUrl, saveToFilename, or outputStream.
+            If none are passed in the URL in oagis.properties will be used at the target for the message.</description>
         <implements service="oagisMessageInfoInterface"/>
-        <attribute name="outputStream" type="java.io.OutputStream" mode="IN"/>
+        <attribute name="sendToUrl" type="String" mode="IN" optional="true"/>
+        <attribute name="saveToFilename" type="String" mode="IN" optional="true"/>
+        <attribute name="saveToDirectory" type="String" mode="IN" optional="true"/>
+        <attribute name="outputStream" type="java.io.OutputStream" mode="IN" optional="true"/>
         <override name="orderId" mode="INOUT" type="String" optional="false"/>
     </service>
     <service name="sendProcessShipmentMsg" max-retry="0" engine="simple"

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=552772&r1=552771&r2=552772
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java (original)
+++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java Tue Jul  3 03:17:05 2007
@@ -18,9 +18,14 @@
 specific language governing permissions and limitations
 under the License.
 **/
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
 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;
@@ -37,9 +42,12 @@
 import javolution.util.FastList;
 
 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;
+import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.base.util.collections.MapStack;
 import org.ofbiz.entity.GenericDelegator;
@@ -71,6 +79,8 @@
     protected static final FoFormRenderer foFormRenderer = new FoFormRenderer();
     
     public static final String resource = "OagisUiLabels";
+
+    public static final String certAlias = UtilProperties.getPropertyValue("oagis.properties", "auth.client.certificate.alias");
     
     public static Map showShipment(DispatchContext ctx, Map context) {
         InputStream in = (InputStream) context.get("inputStream");
@@ -177,12 +187,18 @@
         return result;
     }
 
-    public static Map processShipment(DispatchContext ctx, Map context) {
+    public static Map oagisProcessShipment(DispatchContext ctx, Map context) {
         LocalDispatcher dispatcher = ctx.getDispatcher();
         GenericDelegator delegator = ctx.getDelegator();
         String orderId = (String) context.get("orderId");
         String shipmentId = (String) context.get("shipmentId");
         GenericValue userLogin = (GenericValue) context.get("userLogin");
+        
+        String sendToUrl = (String) context.get("sendToUrl");
+        String saveToFilename = (String) context.get("saveToFilename");
+        String saveToDirectory = (String) context.get("saveToDirectory");
+        OutputStream out = (OutputStream) context.get("outputStream");
+        
         Map result = ServiceUtil.returnSuccess();
         MapStack bodyParameters =  MapStack.create();
         if (userLogin == null) {
@@ -241,8 +257,10 @@
                     while (oiIter.hasNext()) {
                         GenericValue orderItem = (GenericValue) oiIter.next();
                         String correspondingPoId = orderItem.getString("correspondingPoId");
-                        correspondingPoIdSet.add(correspondingPoId);
-                        bodyParameters.put("correspondingPoIdSet", correspondingPoIdSet);
+                        if (correspondingPoId != null) {
+                        correspondingPoIdSet.add(correspondingPoId);
+                        bodyParameters.put("correspondingPoIdSet", correspondingPoIdSet);
+                        }
                     }
                 } catch (GenericEntityException e) {
                     Debug.logError(e, module);
@@ -315,14 +333,60 @@
                 bodyParameters.put("orderId", orderId);
                 bodyParameters.put("userLogin", userLogin);
                 String bodyScreenUri = UtilProperties.getPropertyValue("oagis.properties", "Oagis.Template.ProcessShipment");
-                OutputStream out = (OutputStream) context.get("outputStream");
-                Writer writer = new OutputStreamWriter(out);
+
+                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();
+                }
+
                 ScreenRenderer screens = new ScreenRenderer(writer, bodyParameters, new HtmlScreenRenderer());
                 try {
                     screens.render(bodyScreenUri);
+                    writer.close();
                 } catch (Exception e) {
-                      Debug.logError(e, "Error rendering [text/xml]: ", module);
+                 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)
+
+                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
+                    http.setClientCertificateAlias(certAlias);
+                    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);
+                    }
+                }
+
                 // prepare map to Create Oagis Message Info
                 result.put("component", "INVENTORY");
                 result.put("task", "SHIPREQUES"); // Actual value of task is "SHIPREQUEST" which is more than 10 char