You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2010/02/14 19:38:35 UTC
svn commit: r910060 - in /ofbiz/trunk/framework:
entity/src/org/ofbiz/entity/serialize/
service/src/org/ofbiz/service/engine/ webapp/src/org/ofbiz/webapp/event/
Author: adrianc
Date: Sun Feb 14 18:38:34 2010
New Revision: 910060
URL: http://svn.apache.org/viewvc?rev=910060&view=rev
Log:
Created a SOAP serializer facade class to decouple SOAP code from XmlSerialize.
Added:
ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/SoapSerializer.java (with props)
Modified:
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/serialize/XmlSerializer.java
ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/SOAPClientEngine.java
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/SOAPEventHandler.java
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/serialize/XmlSerializer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/serialize/XmlSerializer.java?rev=910060&r1=910059&r2=910060&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/serialize/XmlSerializer.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/serialize/XmlSerializer.java Sun Feb 14 18:38:34 2010
@@ -58,8 +58,8 @@
import org.xml.sax.SAXException;
/**
- * <p><b>Title:</b> XmlSerializer
- * <p><b>Description:</b> Simple XML serialization/deserialization routines with embedded type information
+ * XmlSerializer class. This class is deprecated - new code should use the
+ * Java object marshalling/unmarshalling methods in <code>UtilXml.java</code>.
*
*/
public class XmlSerializer {
@@ -80,23 +80,26 @@
// readXmlDocument with false second parameter to disable validation
Document document = UtilXml.readXmlDocument(content, false);
if (document != null) {
- Element rootElement = document.getDocumentElement();
- // find the first element below the root element, that should be the object
- Node curChild = rootElement.getFirstChild();
-
- while (curChild != null && curChild.getNodeType() != Node.ELEMENT_NODE) {
- curChild = curChild.getNextSibling();
- }
- if (curChild == null) return null;
- Element element = (Element) curChild;
-
- return deserializeSingle(element, delegator);
+ return deserialize(document, delegator);
} else {
Debug.logWarning("Serialized document came back null", module);
return null;
}
}
+ public static Object deserialize(Document document, Delegator delegator) throws SerializeException {
+ Element rootElement = document.getDocumentElement();
+ // find the first element below the root element, that should be the object
+ Node curChild = rootElement.getFirstChild();
+ while (curChild != null && curChild.getNodeType() != Node.ELEMENT_NODE) {
+ curChild = curChild.getNextSibling();
+ }
+ if (curChild == null) {
+ return null;
+ }
+ return deserializeSingle((Element) curChild, delegator);
+ }
+
public static Element serializeSingle(Object object, Document document) throws SerializeException {
if (document == null) return null;
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/SOAPClientEngine.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/SOAPClientEngine.java?rev=910060&r1=910059&r2=910060&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/SOAPClientEngine.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/SOAPClientEngine.java Sun Feb 14 18:38:34 2010
@@ -40,7 +40,6 @@
import org.ofbiz.base.util.UtilGenerics;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.entity.Delegator;
-import org.ofbiz.entity.serialize.XmlSerializer;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.ModelParam;
import org.ofbiz.service.ModelService;
@@ -122,7 +121,7 @@
OMElement parameterSer = null;
try {
- String xmlParameters = XmlSerializer.serialize(parameterMap);
+ String xmlParameters = SoapSerializer.serialize(parameterMap);
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xmlParameters));
StAXOMBuilder builder = new StAXOMBuilder(reader);
parameterSer = builder.getDocumentElement();
@@ -136,7 +135,7 @@
OMElement payload = factory.createOMElement(serviceName);
payload.addChild(parameterSer.getFirstElement());
OMElement respOMElement = client.sendReceive(payload);
- results = UtilGenerics.cast(XmlSerializer.deserialize(respOMElement.toString(), delegator));
+ results = UtilGenerics.cast(SoapSerializer.deserialize(respOMElement.toString(), delegator));
} catch (Exception e) {
Debug.logError(e, module);
}
Added: ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/SoapSerializer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/SoapSerializer.java?rev=910060&view=auto
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/SoapSerializer.java (added)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/SoapSerializer.java Sun Feb 14 18:38:34 2010
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * 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
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+package org.ofbiz.service.engine;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilXml;
+import org.ofbiz.entity.Delegator;
+import org.ofbiz.entity.serialize.SerializeException;
+import org.ofbiz.entity.serialize.XmlSerializer;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+/**
+ * A facade class used to connect SOAP code to the legacy XML serialization code.
+ *
+ */
+public class SoapSerializer {
+ public static final String module = SoapSerializer.class.getName();
+
+ public static Object deserialize(String content, Delegator delegator) throws SerializeException, SAXException, ParserConfigurationException, IOException {
+ Document document = UtilXml.readXmlDocument(content, false);
+ if (document != null) {
+ return XmlSerializer.deserialize(document, delegator);
+ } else {
+ Debug.logWarning("Serialized document came back null", module);
+ return null;
+ }
+ }
+
+ public static String serialize(Object object) throws SerializeException, FileNotFoundException, IOException {
+ Document document = UtilXml.makeEmptyXmlDocument("ofbiz-ser");
+ Element rootElement = document.getDocumentElement();
+ rootElement.appendChild(XmlSerializer.serializeSingle(object, document));
+ return UtilXml.writeXmlDocument(document);
+ }
+}
Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/SoapSerializer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/SoapSerializer.java
------------------------------------------------------------------------------
svn:keywords = Date Rev Author URL Id
Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/SoapSerializer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/SOAPEventHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/SOAPEventHandler.java?rev=910060&r1=910059&r2=910060&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/SOAPEventHandler.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/SOAPEventHandler.java Sun Feb 14 18:38:34 2010
@@ -48,7 +48,7 @@
import org.ofbiz.base.util.UtilGenerics;
import org.ofbiz.base.util.UtilXml;
import org.ofbiz.entity.GenericDelegator;
-import org.ofbiz.entity.serialize.XmlSerializer;
+import org.ofbiz.service.engine.SoapSerializer;
import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.LocalDispatcher;
@@ -176,7 +176,7 @@
if (serviceObj instanceof OMElement) {
OMElement serviceElement = (OMElement) serviceObj;
String serviceName = serviceElement.getLocalName();
- Map<String, Object> parameters = UtilGenerics.cast(XmlSerializer.deserialize(serviceElement.toString(), delegator));
+ Map<String, Object> parameters = UtilGenerics.cast(SoapSerializer.deserialize(serviceElement.toString(), delegator));
try {
// verify the service is exported for remote execution and invoke it
ModelService model = dispatcher.getDispatchContext().getModelService(serviceName);
@@ -187,7 +187,7 @@
// setup the response
Debug.logVerbose("[EventHandler] : Setting up response message", module);
- String xmlResults = XmlSerializer.serialize(results);
+ String xmlResults = SoapSerializer.serialize(results);
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xmlResults));
StAXOMBuilder resultsBuilder = new StAXOMBuilder(reader);
OMElement resultSer = resultsBuilder.getDocumentElement();
@@ -240,7 +240,7 @@
res.setContentType("text/xml");
Map<String, Object> results = FastMap.newInstance();
results.put("errorMessage", errorMessage);
- String xmlResults= XmlSerializer.serialize(results);
+ String xmlResults= SoapSerializer.serialize(results);
XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xmlResults));
StAXOMBuilder resultsBuilder = new StAXOMBuilder(xmlReader);
OMElement resultSer = resultsBuilder.getDocumentElement();
Re: svn commit: r910060 - in /ofbiz/trunk/framework: entity/src/org/ofbiz/entity/serialize/
service/src/org/ofbiz/service/engine/ webapp/src/org/ofbiz/webapp/event/
Posted by Adam Heath <do...@brainfood.com>.
Adam Heath wrote:
> adrianc@apache.org wrote:
>> Author: adrianc
>> Date: Sun Feb 14 18:38:34 2010
>> New Revision: 910060
>>
>> URL: http://svn.apache.org/viewvc?rev=910060&view=rev
>> Log:
>> Created a SOAP serializer facade class to decouple SOAP code from XmlSerialize.
>>
>> Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/serialize/XmlSerializer.java
>> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/serialize/XmlSerializer.java?rev=910060&r1=910059&r2=910060&view=diff
>> ==============================================================================
>> --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/serialize/XmlSerializer.java (original)
>> +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/serialize/XmlSerializer.java Sun Feb 14 18:38:34 2010
>> @@ -58,8 +58,8 @@
>> import org.xml.sax.SAXException;
>>
>> /**
>> - * <p><b>Title:</b> XmlSerializer
>> - * <p><b>Description:</b> Simple XML serialization/deserialization routines with embedded type information
>> + * XmlSerializer class. This class is deprecated - new code should use the
>> + * Java object marshalling/unmarshalling methods in <code>UtilXml.java</code>.
>> *
>> */
>> public class XmlSerializer {
>> @@ -80,23 +80,26 @@
>> // readXmlDocument with false second parameter to disable validation
>> Document document = UtilXml.readXmlDocument(content, false);
>> if (document != null) {
>> - Element rootElement = document.getDocumentElement();
>> - // find the first element below the root element, that should be the object
>> - Node curChild = rootElement.getFirstChild();
>> -
>> - while (curChild != null && curChild.getNodeType() != Node.ELEMENT_NODE) {
>> - curChild = curChild.getNextSibling();
>> - }
>> - if (curChild == null) return null;
>> - Element element = (Element) curChild;
>> -
>> - return deserializeSingle(element, delegator);
>> + return deserialize(document, delegator);
>> } else {
>> Debug.logWarning("Serialized document came back null", module);
>> return null;
>> }
>> }
>>
>> + public static Object deserialize(Document document, Delegator delegator) throws SerializeException {
>> + Element rootElement = document.getDocumentElement();
>> + // find the first element below the root element, that should be the object
>> + Node curChild = rootElement.getFirstChild();
>> + while (curChild != null && curChild.getNodeType() != Node.ELEMENT_NODE) {
>> + curChild = curChild.getNextSibling();
>> + }
>> + if (curChild == null) {
>> + return null;
>> + }
>> + return deserializeSingle((Element) curChild, delegator);
>> + }
>> +
>
>
> This should have been a separate commit.
And in any event, this change wasn't describe in the changelog.
Re: svn commit: r910060 - in /ofbiz/trunk/framework: entity/src/org/ofbiz/entity/serialize/
service/src/org/ofbiz/service/engine/ webapp/src/org/ofbiz/webapp/event/
Posted by Adam Heath <do...@brainfood.com>.
adrianc@apache.org wrote:
> Author: adrianc
> Date: Sun Feb 14 18:38:34 2010
> New Revision: 910060
>
> URL: http://svn.apache.org/viewvc?rev=910060&view=rev
> Log:
> Created a SOAP serializer facade class to decouple SOAP code from XmlSerialize.
>
> Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/serialize/XmlSerializer.java
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/serialize/XmlSerializer.java?rev=910060&r1=910059&r2=910060&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/serialize/XmlSerializer.java (original)
> +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/serialize/XmlSerializer.java Sun Feb 14 18:38:34 2010
> @@ -58,8 +58,8 @@
> import org.xml.sax.SAXException;
>
> /**
> - * <p><b>Title:</b> XmlSerializer
> - * <p><b>Description:</b> Simple XML serialization/deserialization routines with embedded type information
> + * XmlSerializer class. This class is deprecated - new code should use the
> + * Java object marshalling/unmarshalling methods in <code>UtilXml.java</code>.
> *
> */
> public class XmlSerializer {
> @@ -80,23 +80,26 @@
> // readXmlDocument with false second parameter to disable validation
> Document document = UtilXml.readXmlDocument(content, false);
> if (document != null) {
> - Element rootElement = document.getDocumentElement();
> - // find the first element below the root element, that should be the object
> - Node curChild = rootElement.getFirstChild();
> -
> - while (curChild != null && curChild.getNodeType() != Node.ELEMENT_NODE) {
> - curChild = curChild.getNextSibling();
> - }
> - if (curChild == null) return null;
> - Element element = (Element) curChild;
> -
> - return deserializeSingle(element, delegator);
> + return deserialize(document, delegator);
> } else {
> Debug.logWarning("Serialized document came back null", module);
> return null;
> }
> }
>
> + public static Object deserialize(Document document, Delegator delegator) throws SerializeException {
> + Element rootElement = document.getDocumentElement();
> + // find the first element below the root element, that should be the object
> + Node curChild = rootElement.getFirstChild();
> + while (curChild != null && curChild.getNodeType() != Node.ELEMENT_NODE) {
> + curChild = curChild.getNextSibling();
> + }
> + if (curChild == null) {
> + return null;
> + }
> + return deserializeSingle((Element) curChild, delegator);
> + }
> +
This should have been a separate commit.