|
Author: hansbak
Date: Mon Dec 21 07:31:58 2009 New Revision: 892712 URL: http://svn.apache.org/viewvc?rev=892712&view=rev Log: Upgrade Axis1 to Axis2. Ofbiz now supports complex parameters in webservices including WSDL generation. see OFBIZ-3363 for more info. A contribution of Antwebsystems employee Chatree Added: ofbiz/trunk/framework/service/lib/XmlSchema-1.4.3.jar (with props) ofbiz/trunk/framework/service/lib/axiom-api-1.2.8.jar (with props) ofbiz/trunk/framework/service/lib/axiom-impl-1.2.8.jar (with props) ofbiz/trunk/framework/service/lib/axis2-kernel-1.5.1.jar (with props) ofbiz/trunk/framework/service/lib/axis2-transport-http-1.5.1.jar (with props) ofbiz/trunk/framework/service/lib/axis2-transport-local-1.5.1.jar (with props) ofbiz/trunk/framework/service/lib/commons-httpclient-3.1.jar (with props) ofbiz/trunk/framework/service/lib/neethi-2.0.4.jar (with props) ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceSOAPTests.java (with props) Modified: ofbiz/trunk/LICENSE ofbiz/trunk/framework/common/servicedef/services_test.xml ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelParam.java ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/SOAPClientEngine.java ofbiz/trunk/framework/service/testdef/servicetests.xml ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/SOAPEventHandler.java Modified: ofbiz/trunk/LICENSE URL: http://svn.apache.org/viewvc/ofbiz/trunk/LICENSE?rev=892712&r1=892711&r2=892712&view=diff ============================================================================== --- ofbiz/trunk/LICENSE (original) +++ ofbiz/trunk/LICENSE Mon Dec 21 07:31:58 2009 @@ -87,6 +87,14 @@ ofbiz/trunk/framework/jetty/lib/xmlParserAPIs-2.6.2.jar ofbiz/trunk/framework/service/lib/axis-ant.jar ofbiz/trunk/framework/service/lib/axis.jar +ofbiz/trunk/framework/service/lib/axiom-api-1.2.8.jar +ofbiz/trunk/framework/service/lib/axiom-impl-1.2.8.jar +ofbiz/trunk/framework/service/lib/axis2-kernel-1.5.1.jar +ofbiz/trunk/framework/service/lib/axis2-transport-http-1.5.1.jar +ofbiz/trunk/framework/service/lib/axis2-transport-local-1.5.1.jar +ofbiz/trunk/framework/service/lib/commons-httpclient-3.1.jar +ofbiz/trunk/framework/service/lib/neethi-2.0.4.jar +ofbiz/trunk/framework/service/lib/XmlSchema-1.4.3.jar ofbiz/trunk/framework/webapp/lib/fop-0.95.jar ofbiz/trunk/framework/webapp/lib/velocity-1.6.1.jar ofbiz/trunk/framework/webapp/lib/xmlgraphics-commons-1.3.1.jar Modified: ofbiz/trunk/framework/common/servicedef/services_test.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/servicedef/services_test.xml?rev=892712&r1=892711&r2=892712&view=diff ============================================================================== --- ofbiz/trunk/framework/common/servicedef/services_test.xml (original) +++ ofbiz/trunk/framework/common/servicedef/services_test.xml Mon Dec 21 07:31:58 2009 @@ -31,6 +31,12 @@ <attribute name="message" type="String" mode="IN" optional="true"/> <attribute name="resp" type="String" mode="OUT"/> </service> + <service name="testSOAPScv" engine="java" export="true" validate="false" require-new-transaction="true" + location="org.ofbiz.common.CommonServices" invoke="testSOAPService"> + <description>Test SOAP service</description> + <attribute name="productCategory" type="org.ofbiz.entity.GenericValue" mode="IN" optional="false"/> + <attribute name="products" type="List" mode="OUT" optional="true"/> + </service> <service name="blockingTestScv" engine="java" export="true" validate="false" require-new-transaction="true" transaction-timeout="20" location="org.ofbiz.common.CommonServices" invoke="blockingTestService"> <description>Blocking Test service</description> @@ -84,10 +90,15 @@ </service> <service name="testSoap" engine="soap" export="true" + location="http://localhost:8080/webtools/control/SOAPService" invoke="testSOAPScv"> + <description>SOAP service; calls the OFBiz test SOAP service</description> + <implements service="testSOAPScv"/> + </service> + + <service name="testSoapSimple" engine="soap" export="true" location="http://localhost:8080/webtools/control/SOAPService" invoke="testScv"> - <description>Test SOAP service; calls the OFBiz test service</description> - <attribute name="message" type="String" mode="IN" optional="true"/> - <attribute name="resp" type="String" mode="OUT"/> + <description>simple SOAP service; calls the OFBiz test service</description> + <implements service="testScv"/> </service> <service name="testRemoteSoap" engine="soap" export="true" Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java?rev=892712&r1=892711&r2=892712&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java Mon Dec 21 07:31:58 2009 @@ -26,6 +26,7 @@ import javax.mail.internet.MimeMessage; import javax.transaction.xa.XAException; +import javolution.util.FastList; import javolution.util.FastMap; import org.apache.log4j.Level; @@ -84,6 +85,32 @@ System.out.println("----- SVC: " + dctx.getName() + " -----"); return response; } + + /** + * Generic Test SOAP Service + *@param dctx The DispatchContext that this service is operating in + *@param context Map containing the input parameters + *@return Map with the result of the service, the output parameters + */ + public static Map<String, Object> testSOAPService(DispatchContext dctx, Map<String, ?> context) { + Delegator delegator = dctx.getDelegator(); + Map<String, Object> response = ServiceUtil.returnSuccess(); + + GenericValue productCategory = (GenericValue) context.get("productCategory"); + List<GenericValue> products = FastList.newInstance(); + for (int i = 0; i < 3; i ++) { + GenericValue product = delegator.makeValue("Product"); + product.put("productId", "PROD_TEST" + i); + product.put("productTypeId", "FINISHED_GOOD"); + product.put("primaryProductCategoryId", "202"); + product.put("internalName", "Product Test " + i); + product.put("productName", "Product Test " + i); + product.put("createdStamp", UtilDateTime.nowTimestamp()); + products.add(product); + } + response.put("products", products); + return response; + } public static Map<String, Object> blockingTestService(DispatchContext dctx, Map<String, ?> context) { Long duration = (Long) context.get("duration"); Added: ofbiz/trunk/framework/service/lib/XmlSchema-1.4.3.jar URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/lib/XmlSchema-1.4.3.jar?rev=892712&view=auto ============================================================================== Binary file - no diff available. Propchange: ofbiz/trunk/framework/service/lib/XmlSchema-1.4.3.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: ofbiz/trunk/framework/service/lib/axiom-api-1.2.8.jar URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/lib/axiom-api-1.2.8.jar?rev=892712&view=auto ============================================================================== Binary file - no diff available. Propchange: ofbiz/trunk/framework/service/lib/axiom-api-1.2.8.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: ofbiz/trunk/framework/service/lib/axiom-impl-1.2.8.jar URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/lib/axiom-impl-1.2.8.jar?rev=892712&view=auto ============================================================================== Binary file - no diff available. Propchange: ofbiz/trunk/framework/service/lib/axiom-impl-1.2.8.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: ofbiz/trunk/framework/service/lib/axis2-kernel-1.5.1.jar URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/lib/axis2-kernel-1.5.1.jar?rev=892712&view=auto ============================================================================== Binary file - no diff available. Propchange: ofbiz/trunk/framework/service/lib/axis2-kernel-1.5.1.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: ofbiz/trunk/framework/service/lib/axis2-transport-http-1.5.1.jar URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/lib/axis2-transport-http-1.5.1.jar?rev=892712&view=auto ============================================================================== Binary file - no diff available. Propchange: ofbiz/trunk/framework/service/lib/axis2-transport-http-1.5.1.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: ofbiz/trunk/framework/service/lib/axis2-transport-local-1.5.1.jar URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/lib/axis2-transport-local-1.5.1.jar?rev=892712&view=auto ============================================================================== Binary file - no diff available. Propchange: ofbiz/trunk/framework/service/lib/axis2-transport-local-1.5.1.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: ofbiz/trunk/framework/service/lib/commons-httpclient-3.1.jar URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/lib/commons-httpclient-3.1.jar?rev=892712&view=auto ============================================================================== Binary file - no diff available. Propchange: ofbiz/trunk/framework/service/lib/commons-httpclient-3.1.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: ofbiz/trunk/framework/service/lib/neethi-2.0.4.jar URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/lib/neethi-2.0.4.jar?rev=892712&view=auto ============================================================================== Binary file - no diff available. Propchange: ofbiz/trunk/framework/service/lib/neethi-2.0.4.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelParam.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelParam.java?rev=892712&r1=892711&r2=892712&view=diff ============================================================================== --- ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelParam.java (original) +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelParam.java Mon Dec 21 07:31:58 2009 @@ -207,47 +207,56 @@ public Part getWSDLPart(Definition def) throws WSDLException { Part part = def.createPart(); part.setName(this.name); - part.setTypeName(new QName(ModelService.XSD, this.java2wsdlType())); + part.setTypeName(new QName(ModelService.TNS, this.java2wsdlType())); return part; } protected String java2wsdlType() throws WSDLException { if (ObjectType.instanceOf(java.lang.Character.class, this.type)) { - return "string"; + return "std-String"; } else if (ObjectType.instanceOf(java.lang.String.class, this.type)) { - return "string"; + return "std-String"; } else if (ObjectType.instanceOf(java.lang.Byte.class, this.type)) { - return "byte"; + return "std-String"; } else if (ObjectType.instanceOf(java.lang.Boolean.class, this.type)) { - return "boolean"; + return "std-Boolean"; } else if (ObjectType.instanceOf(java.lang.Integer.class, this.type)) { - return "int"; + return "std-Integer"; } else if (ObjectType.instanceOf(java.lang.Double.class, this.type)) { - return "double"; + return "std-Double"; } else if (ObjectType.instanceOf(java.lang.Float.class, this.type)) { - return "float"; + return "std-Float"; } else if (ObjectType.instanceOf(java.lang.Short.class, this.type)) { - return "short"; + return "std-Integer"; } else if (ObjectType.instanceOf(java.math.BigDecimal.class, this.type)) { - return "decimal"; + return "std-Long"; } else if (ObjectType.instanceOf(java.math.BigInteger.class, this.type)) { - return "integer"; + return "std-Integer"; } else if (ObjectType.instanceOf(java.util.Calendar.class, this.type)) { - return "dateTime"; + return "sql-Timestamp"; } else if (ObjectType.instanceOf(com.ibm.icu.util.Calendar.class, this.type)) { - return "dateTime"; + return "sql-Timestamp"; } else if (ObjectType.instanceOf(java.sql.Date.class, this.type)) { - return "date"; + return "sql-Date"; } else if (ObjectType.instanceOf(java.util.Date.class, this.type)) { - return "dateTime"; + return "sql-Timestamp"; } else if (ObjectType.instanceOf(java.lang.Long.class, this.type)) { - return "unsignedInt"; + return "std-Long"; } else if (ObjectType.instanceOf(java.sql.Timestamp.class, this.type)) { - return "string"; + return "sql-Timestamp"; + } else if (ObjectType.instanceOf(org.ofbiz.entity.GenericValue.class, this.type)) { + return "eeval-"; + } else if (ObjectType.instanceOf(org.ofbiz.entity.GenericPK.class, this.type)) { + return "eepk-"; + } else if (ObjectType.instanceOf(java.util.Map.class, this.type)) { + return "map-Map"; + } else if (ObjectType.instanceOf(java.util.List.class, this.type)) { + return "col-LinkedList"; + } else { + return "cus-obj"; } - // TODO add array support (maybe even convert List objects); add GenericValue/Map support - throw new WSDLException(WSDLException.OTHER_ERROR, "Service cannot be described with WSDL (" + this.name + " / " + this.type + ")"); + //throw new WSDLException(WSDLException.OTHER_ERROR, "Service cannot be described with WSDL (" + this.name + " / " + this.type + ")"); } static class ModelParamValidator implements Serializable { Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java?rev=892712&r1=892711&r2=892712&view=diff ============================================================================== --- ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java (original) +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java Mon Dec 21 07:31:58 2009 @@ -41,9 +41,11 @@ import javax.wsdl.Message; import javax.wsdl.Operation; import javax.wsdl.Output; +import javax.wsdl.Part; import javax.wsdl.Port; import javax.wsdl.PortType; import javax.wsdl.Service; +import javax.wsdl.Types; import javax.wsdl.WSDLException; import javax.wsdl.extensions.soap.SOAPAddress; import javax.wsdl.extensions.soap.SOAPBinding; @@ -51,6 +53,8 @@ import javax.wsdl.extensions.soap.SOAPOperation; import javax.wsdl.factory.WSDLFactory; import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; import javolution.util.FastList; import javolution.util.FastMap; @@ -66,6 +70,7 @@ import org.ofbiz.service.group.GroupServiceModel; import org.ofbiz.service.group.ServiceGroupReader; import org.w3c.dom.Document; +import org.w3c.dom.Element; import com.ibm.wsdl.extensions.soap.SOAPAddressImpl; import com.ibm.wsdl.extensions.soap.SOAPBindingImpl; @@ -1189,6 +1194,18 @@ } public void getWSDL(Definition def, String locationURI) throws WSDLException { + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = null; + Document document = null; + try { + builder = factory.newDocumentBuilder(); + document = builder.newDocument(); + } catch (Exception e) { + throw new WSDLException("can not create WSDL", module); + } + def.setTypes(this.getTypes(document, def)); + // set the IN parameters Input input = def.createInput(); Set<String> inParam = this.getInParamNames(); @@ -1196,12 +1213,25 @@ Message inMessage = def.createMessage(); inMessage.setQName(new QName(TNS, this.name + "Request")); inMessage.setUndefined(false); + Part parametersPart = def.createPart(); + parametersPart.setName("map-Map"); + parametersPart.setTypeName(new QName(TNS, "map-Map")); + inMessage.addPart(parametersPart); + Element documentation = document.createElement("wsdl:documentation"); for (String paramName: inParam) { ModelParam param = this.getParam(paramName); if (!param.internal) { - inMessage.addPart(param.getWSDLPart(def)); + Part part = param.getWSDLPart(def); + Element attribute = document.createElement("attribute"); + attribute.setAttribute("name", paramName); + attribute.setAttribute("type", part.getTypeName().getLocalPart()); + attribute.setAttribute("namespace", part.getTypeName().getNamespaceURI()); + attribute.setAttribute("java-class", param.type); + attribute.setAttribute("optional", Boolean.toString(param.optional)); + documentation.appendChild(attribute); } } + parametersPart.setDocumentationElement(documentation); def.addMessage(inMessage); input.setMessage(inMessage); } @@ -1213,12 +1243,25 @@ Message outMessage = def.createMessage(); outMessage.setQName(new QName(TNS, this.name + "Response")); outMessage.setUndefined(false); + Part resultsPart = def.createPart(); + resultsPart.setName("map-Map"); + resultsPart.setTypeName(new QName(TNS, "map-Map")); + outMessage.addPart(resultsPart); + Element documentation = document.createElement("wsdl:documentation"); for (String paramName: outParam) { ModelParam param = this.getParam(paramName); if (!param.internal) { - outMessage.addPart(param.getWSDLPart(def)); + Part part = param.getWSDLPart(def); + Element attribute = document.createElement("attribute"); + attribute.setAttribute("name", paramName); + attribute.setAttribute("type", part.getTypeName().getLocalPart()); + attribute.setAttribute("namespace", part.getTypeName().getNamespaceURI()); + attribute.setAttribute("java-class", param.type); + attribute.setAttribute("optional", Boolean.toString(param.optional)); + documentation.appendChild(attribute); } } + resultsPart.setDocumentationElement(documentation); def.addMessage(outMessage); output.setMessage(outMessage); } @@ -1291,4 +1334,410 @@ service.addPort(port); def.addService(service); } + + public Types getTypes(Document document, Definition def) { + Types types = def.createTypes(); + /* Schema */ + Element schema = document.createElement("xsd:schema"); + schema.setAttribute("targetNamespace", TNS); + + /*-----------------------------------*/ + /*--------- Standard Objects --------*/ + /*-----------------------------------*/ + + /* std-String Element */ + Element stdStringElement = document.createElement("xsd:element"); + stdStringElement.setAttribute("name", "std-String"); + Element stdStringElement0 = document.createElement("xsd:complexType"); + stdStringElement.appendChild(stdStringElement0); + Element stdStringElement1 = document.createElement("xsd:attribute"); + stdStringElement0.appendChild(stdStringElement1); + stdStringElement1.setAttribute("name", "value"); + stdStringElement1.setAttribute("type", "xsd:string"); + stdStringElement1.setAttribute("use", "required"); + schema.appendChild(stdStringElement); + /* std-Integer Element */ + Element stdIntegerElement = document.createElement("xsd:element"); + stdIntegerElement.setAttribute("name", "std-Integer"); + Element stdIntegerElement0 = document.createElement("xsd:complexType"); + stdIntegerElement.appendChild(stdIntegerElement0); + Element stdIntegerElement1 = document.createElement("xsd:attribute"); + stdIntegerElement0.appendChild(stdIntegerElement1); + stdIntegerElement1.setAttribute("name", "value"); + stdIntegerElement1.setAttribute("type", "xsd:integer"); + stdIntegerElement1.setAttribute("use", "required"); + schema.appendChild(stdIntegerElement); + /* std-Long Element */ + Element stdLongElement = document.createElement("xsd:element"); + stdLongElement.setAttribute("name", "std-Long"); + Element stdLongElement0 = document.createElement("xsd:complexType"); + stdLongElement.appendChild(stdLongElement0); + Element stdLongElement1 = document.createElement("xsd:attribute"); + stdLongElement0.appendChild(stdLongElement1); + stdLongElement1.setAttribute("name", "value"); + stdLongElement1.setAttribute("type", "xsd:long"); + stdLongElement1.setAttribute("use", "required"); + schema.appendChild(stdLongElement); + /* std-Float Element */ + Element stdFloatElement = document.createElement("xsd:element"); + stdFloatElement.setAttribute("name", "std-Float"); + Element stdFloatElement0 = document.createElement("xsd:complexType"); + stdFloatElement.appendChild(stdFloatElement0); + Element stdFloatElement1 = document.createElement("xsd:attribute"); + stdFloatElement0.appendChild(stdFloatElement1); + stdFloatElement1.setAttribute("name", "value"); + stdFloatElement1.setAttribute("type", "xsd:float"); + stdFloatElement1.setAttribute("use", "required"); + schema.appendChild(stdFloatElement); + /* std-Double Element */ + Element stdDoubleElement = document.createElement("xsd:element"); + stdDoubleElement.setAttribute("name", "std-Double"); + Element stdDoubleElement0 = document.createElement("xsd:complexType"); + stdDoubleElement.appendChild(stdDoubleElement0); + Element stdDoubleElement1 = document.createElement("xsd:attribute"); + stdDoubleElement0.appendChild(stdDoubleElement1); + stdDoubleElement1.setAttribute("name", "value"); + stdDoubleElement1.setAttribute("type", "xsd:double"); + stdDoubleElement1.setAttribute("use", "required"); + schema.appendChild(stdDoubleElement); + /* std-Boolean Element */ + Element stdBooleanElement = document.createElement("xsd:element"); + stdBooleanElement.setAttribute("name", "std-Boolean"); + Element stdBooleanElement0 = document.createElement("xsd:complexType"); + stdBooleanElement.appendChild(stdBooleanElement0); + Element stdBooleanElement1 = document.createElement("xsd:attribute"); + stdBooleanElement0.appendChild(stdBooleanElement1); + stdBooleanElement1.setAttribute("name", "value"); + stdBooleanElement1.setAttribute("type", "xsd:boolean"); + stdBooleanElement1.setAttribute("use", "required"); + schema.appendChild(stdBooleanElement); + /* std-Locale Element */ + Element stdLocaleElement = document.createElement("xsd:element"); + stdLocaleElement.setAttribute("name", "std-Locale"); + Element stdLocaleElement0 = document.createElement("xsd:complexType"); + stdLocaleElement.appendChild(stdLocaleElement0); + Element stdLocaleElement1 = document.createElement("xsd:attribute"); + stdLocaleElement0.appendChild(stdLocaleElement1); + stdLocaleElement1.setAttribute("name", "value"); + stdLocaleElement1.setAttribute("type", "xsd:string"); + stdLocaleElement1.setAttribute("use", "required"); + schema.appendChild(stdLocaleElement); + + /*-----------------------------------*/ + /*----------- SQL Objects -----------*/ + /*-----------------------------------*/ + + /* sql-Timestamp Element */ + Element sqlTimestampElement = document.createElement("xsd:element"); + sqlTimestampElement.setAttribute("name", "sql-Timestamp"); + Element sqlTimestampElement0 = document.createElement("xsd:complexType"); + sqlTimestampElement.appendChild(sqlTimestampElement0); + Element sqlTimestampElement1 = document.createElement("xsd:attribute"); + sqlTimestampElement0.appendChild(sqlTimestampElement1); + sqlTimestampElement1.setAttribute("name", "value"); + sqlTimestampElement1.setAttribute("type", "xsd:dateTime"); + sqlTimestampElement1.setAttribute("use", "required"); + schema.appendChild(sqlTimestampElement); + /* sql-Date Element */ + Element sqlDateElement = document.createElement("xsd:element"); + sqlDateElement.setAttribute("name", "sql-Date"); + Element sqlDateElement0 = document.createElement("xsd:complexType"); + sqlDateElement.appendChild(sqlDateElement0); + Element sqlDateElement1 = document.createElement("xsd:attribute"); + sqlDateElement0.appendChild(sqlDateElement1); + sqlDateElement1.setAttribute("name", "value"); + sqlDateElement1.setAttribute("type", "xsd:date"); + sqlDateElement1.setAttribute("use", "required"); + schema.appendChild(sqlDateElement); + /* sql-Time Element */ + Element sqlTimeElement = document.createElement("xsd:element"); + sqlTimeElement.setAttribute("name", "sql-Time"); + Element sqlTimeElement0 = document.createElement("xsd:complexType"); + sqlTimeElement.appendChild(sqlTimeElement0); + Element sqlTimeElement1 = document.createElement("xsd:attribute"); + sqlTimeElement0.appendChild(sqlTimeElement1); + sqlTimeElement1.setAttribute("name", "value"); + sqlTimeElement1.setAttribute("type", "xsd:time"); + sqlTimeElement1.setAttribute("use", "required"); + schema.appendChild(sqlTimeElement); + + /*-----------------------------------*/ + /*----------- List Objects -----------*/ + /*-----------------------------------*/ + + /* col-ArrayList Element */ + Element colArrayListElement = document.createElement("xsd:element"); + colArrayListElement.setAttribute("name", "col-ArrayList"); + schema.appendChild(colArrayListElement); + /* col-LinkedList Element */ + Element colLinkedListElement = document.createElement("xsd:element"); + colLinkedListElement.setAttribute("name", "col-LinkedList"); + schema.appendChild(colLinkedListElement); + /* col-Stack Element */ + Element colStackElement = document.createElement("xsd:element"); + colStackElement.setAttribute("name", "col-Stack"); + schema.appendChild(colStackElement); + /* col-Vector Element */ + Element colVectorElement = document.createElement("xsd:element"); + colVectorElement.setAttribute("name", "col-Vector"); + schema.appendChild(colVectorElement); + /* col-TreeSet Element */ + Element colTreeSetElement = document.createElement("xsd:element"); + colTreeSetElement.setAttribute("name", "col-TreeSet"); + schema.appendChild(colTreeSetElement); + /* col-HashSet Element */ + Element colHashSetElement = document.createElement("xsd:element"); + colHashSetElement.setAttribute("name", "col-HashSet"); + schema.appendChild(colHashSetElement); + /* col-Collection Element */ + Element colCollectionElement = document.createElement("xsd:element"); + colCollectionElement.setAttribute("name", "col-Collection"); + schema.appendChild(colCollectionElement); + + /*-----------------------------------*/ + /*----------- Map Objects -----------*/ + /*-----------------------------------*/ + + /* map-TreeMap Element */ + Element mapTreeMapElement = document.createElement("xsd:element"); + mapTreeMapElement.setAttribute("name", "map-TreeMap"); + mapTreeMapElement.setAttribute("type", "tns:map-Map"); + schema.appendChild(mapTreeMapElement); + /* map-WeakHashMap Element */ + Element mapWeakHashMapElement = document.createElement("xsd:element"); + mapWeakHashMapElement.setAttribute("name", "map-WeakHashMap"); + mapWeakHashMapElement.setAttribute("type", "tns:map-Map"); + schema.appendChild(mapWeakHashMapElement); + /* map-Hashtable Element */ + Element mapHashtableElement = document.createElement("xsd:element"); + mapHashtableElement.setAttribute("name", "map-Hashtable"); + mapHashtableElement.setAttribute("type", "tns:map-Map"); + schema.appendChild(mapHashtableElement); + /* map-Properties Element */ + Element mapPropertiesElement = document.createElement("xsd:element"); + mapPropertiesElement.setAttribute("name", "map-Properties"); + mapPropertiesElement.setAttribute("type", "tns:map-Map"); + schema.appendChild(mapPropertiesElement); + /* map-HashMap Element */ + Element mapHashMapElement = document.createElement("xsd:element"); + mapHashMapElement.setAttribute("name", "map-HashMap"); + mapHashMapElement.setAttribute("type", "tns:map-Map"); + schema.appendChild(mapHashMapElement); + /* map-Map Element */ + Element mapMapElement = document.createElement("xsd:element"); + mapMapElement.setAttribute("name", "map-Map"); + mapMapElement.setAttribute("type", "tns:map-Map"); + schema.appendChild(mapMapElement); + /* map-Entry Element */ + Element mapEntryElement = document.createElement("xsd:element"); + mapEntryElement.setAttribute("name", "map-Entry"); + mapEntryElement.setAttribute("type", "tns:map-Entry"); + schema.appendChild(mapEntryElement); + /* map-Key Element */ + Element mapKeyElement = document.createElement("xsd:element"); + mapKeyElement.setAttribute("name", "map-Key"); + mapKeyElement.setAttribute("type", "tns:map-Key"); + schema.appendChild(mapKeyElement); + /* map-Value Element */ + Element mapValueElement = document.createElement("xsd:element"); + mapValueElement.setAttribute("name", "map-Value"); + mapValueElement.setAttribute("type", "tns:map-Value"); + schema.appendChild(mapValueElement); + /* eepk- Element */ + Element eepkElement = document.createElement("xsd:element"); + eepkElement.setAttribute("name", "eepk-"); + eepkElement.setAttribute("type", "tns:map-Value"); + schema.appendChild(eepkElement); + /* eeval- Element */ + Element eevalElement = document.createElement("xsd:element"); + eevalElement.setAttribute("name", "eeval-"); + eevalElement.setAttribute("type", "tns:map-Value"); + schema.appendChild(eevalElement); + + /*-----------------------------------*/ + /*----------- Custom Objects -----------*/ + /*-----------------------------------*/ + + /* cus-obj Element */ + Element cusObjElement = document.createElement("xsd:element"); + cusObjElement.setAttribute("name", "cus-obj"); + schema.appendChild(cusObjElement); + + /*-----------------------------------*/ + /*---------- Complex Types ----------*/ + /*-----------------------------------*/ + + /* map-Map Complex Type */ + Element mapMapComplexType = document.createElement("xsd:complexType"); + mapMapComplexType.setAttribute("name", "map-Map"); + Element mapMapComplexType0 = document.createElement("xsd:sequence"); + mapMapComplexType.appendChild(mapMapComplexType0); + Element mapMapComplexType1 = document.createElement("xsd:element"); + mapMapComplexType1.setAttribute("ref", "tns:map-Entry"); + mapMapComplexType1.setAttribute("minOccurs", "0"); + mapMapComplexType1.setAttribute("maxOccurs", "unbounded"); + mapMapComplexType0.appendChild(mapMapComplexType1); + schema.appendChild(mapMapComplexType); + /* map-Entry Complex Type */ + Element mapEntryComplexType = document.createElement("xsd:complexType"); + mapEntryComplexType.setAttribute("name", "map-Entry"); + Element mapEntryComplexType0 = document.createElement("xsd:sequence"); + mapEntryComplexType.appendChild(mapEntryComplexType0); + Element mapEntryComplexType1 = document.createElement("xsd:element"); + mapEntryComplexType1.setAttribute("ref", "tns:map-Key"); + mapEntryComplexType1.setAttribute("minOccurs", "1"); + mapEntryComplexType1.setAttribute("maxOccurs", "1"); + mapEntryComplexType0.appendChild(mapEntryComplexType1); + Element mapEntryComplexType2 = document.createElement("xsd:element"); + mapEntryComplexType2.setAttribute("ref", "tns:map-Value"); + mapEntryComplexType2.setAttribute("minOccurs", "1"); + mapEntryComplexType2.setAttribute("maxOccurs", "1"); + mapEntryComplexType0.appendChild(mapEntryComplexType2); + schema.appendChild(mapEntryComplexType); + /* map-Key Complex Type */ + Element mapKeyComplexType = document.createElement("xsd:complexType"); + mapKeyComplexType.setAttribute("name", "map-Key"); + Element mapKeyComplexType0 = document.createElement("xsd:all"); + mapKeyComplexType.appendChild(mapKeyComplexType0); + Element mapKeyComplexType1 = document.createElement("xsd:element"); + mapKeyComplexType1.setAttribute("ref", "tns:std-String"); + mapKeyComplexType1.setAttribute("minOccurs", "1"); + mapKeyComplexType1.setAttribute("maxOccurs", "1"); + mapKeyComplexType0.appendChild(mapKeyComplexType1); + schema.appendChild(mapKeyComplexType); + /* map-Value Complex Type */ + Element mapValueComplexType = document.createElement("xsd:complexType"); + mapValueComplexType.setAttribute("name", "map-Value"); + Element mapValueComplexType0 = document.createElement("xsd:choice"); + mapValueComplexType.appendChild(mapValueComplexType0); + Element mapValueComplexType1 = document.createElement("xsd:element"); + mapValueComplexType1.setAttribute("ref", "tns:std-String"); + mapValueComplexType1.setAttribute("minOccurs", "1"); + mapValueComplexType1.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType1); + Element mapValueComplexType2 = document.createElement("xsd:element"); + mapValueComplexType2.setAttribute("ref", "tns:std-Integer"); + mapValueComplexType2.setAttribute("minOccurs", "1"); + mapValueComplexType2.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType2); + Element mapValueComplexType3 = document.createElement("xsd:element"); + mapValueComplexType3.setAttribute("ref", "tns:std-Long"); + mapValueComplexType3.setAttribute("minOccurs", "1"); + mapValueComplexType3.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType3); + Element mapValueComplexType4 = document.createElement("xsd:element"); + mapValueComplexType4.setAttribute("ref", "tns:std-Float"); + mapValueComplexType4.setAttribute("minOccurs", "1"); + mapValueComplexType4.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType4); + Element mapValueComplexType5 = document.createElement("xsd:element"); + mapValueComplexType5.setAttribute("ref", "tns:std-Double"); + mapValueComplexType5.setAttribute("minOccurs", "1"); + mapValueComplexType5.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType5); + Element mapValueComplexType6 = document.createElement("xsd:element"); + mapValueComplexType6.setAttribute("ref", "tns:std-Boolean"); + mapValueComplexType6.setAttribute("minOccurs", "1"); + mapValueComplexType6.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType6); + Element mapValueComplexType7 = document.createElement("xsd:element"); + mapValueComplexType7.setAttribute("ref", "tns:std-Locale"); + mapValueComplexType7.setAttribute("minOccurs", "1"); + mapValueComplexType7.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType7); + Element mapValueComplexType8 = document.createElement("xsd:element"); + mapValueComplexType8.setAttribute("ref", "tns:sql-Timestamp"); + mapValueComplexType8.setAttribute("minOccurs", "1"); + mapValueComplexType8.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType8); + Element mapValueComplexType9 = document.createElement("xsd:element"); + mapValueComplexType9.setAttribute("ref", "tns:sql-Date"); + mapValueComplexType9.setAttribute("minOccurs", "1"); + mapValueComplexType9.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType9); + Element mapValueComplexType10 = document.createElement("xsd:element"); + mapValueComplexType10.setAttribute("ref", "tns:sql-Time"); + mapValueComplexType10.setAttribute("minOccurs", "1"); + mapValueComplexType10.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType10); + Element mapValueComplexType11 = document.createElement("xsd:element"); + mapValueComplexType11.setAttribute("ref", "tns:col-ArrayList"); + mapValueComplexType11.setAttribute("minOccurs", "1"); + mapValueComplexType11.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType11); + Element mapValueComplexType12 = document.createElement("xsd:element"); + mapValueComplexType12.setAttribute("ref", "tns:col-LinkedList"); + mapValueComplexType12.setAttribute("minOccurs", "1"); + mapValueComplexType12.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType12); + Element mapValueComplexType13 = document.createElement("xsd:element"); + mapValueComplexType13.setAttribute("ref", "tns:col-Stack"); + mapValueComplexType13.setAttribute("minOccurs", "1"); + mapValueComplexType13.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType13); + Element mapValueComplexType14 = document.createElement("xsd:element"); + mapValueComplexType14.setAttribute("ref", "tns:col-Vector"); + mapValueComplexType14.setAttribute("minOccurs", "1"); + mapValueComplexType14.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType14); + Element mapValueComplexType15 = document.createElement("xsd:element"); + mapValueComplexType15.setAttribute("ref", "tns:col-TreeSet"); + mapValueComplexType15.setAttribute("minOccurs", "1"); + mapValueComplexType15.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType15); + Element mapValueComplexType16 = document.createElement("xsd:element"); + mapValueComplexType16.setAttribute("ref", "tns:col-HashSet"); + mapValueComplexType16.setAttribute("minOccurs", "1"); + mapValueComplexType16.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType16); + Element mapValueComplexType17 = document.createElement("xsd:element"); + mapValueComplexType17.setAttribute("ref", "tns:col-Collection"); + mapValueComplexType17.setAttribute("minOccurs", "1"); + mapValueComplexType17.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType17); + Element mapValueComplexType18 = document.createElement("xsd:element"); + mapValueComplexType18.setAttribute("ref", "tns:map-HashMap"); + mapValueComplexType18.setAttribute("minOccurs", "1"); + mapValueComplexType18.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType18); + Element mapValueComplexType19 = document.createElement("xsd:element"); + mapValueComplexType19.setAttribute("ref", "tns:map-Properties"); + mapValueComplexType19.setAttribute("minOccurs", "1"); + mapValueComplexType19.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType19); + Element mapValueComplexType20 = document.createElement("xsd:element"); + mapValueComplexType20.setAttribute("ref", "tns:map-Hashtable"); + mapValueComplexType20.setAttribute("minOccurs", "1"); + mapValueComplexType20.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType20); + Element mapValueComplexType21 = document.createElement("xsd:element"); + mapValueComplexType21.setAttribute("ref", "tns:map-WeakHashMap"); + mapValueComplexType21.setAttribute("minOccurs", "1"); + mapValueComplexType21.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType21); + Element mapValueComplexType22 = document.createElement("xsd:element"); + mapValueComplexType22.setAttribute("ref", "tns:map-TreeMap"); + mapValueComplexType22.setAttribute("minOccurs", "1"); + mapValueComplexType22.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType22); + Element mapValueComplexType23 = document.createElement("xsd:element"); + mapValueComplexType23.setAttribute("ref", "tns:map-Map"); + mapValueComplexType23.setAttribute("minOccurs", "1"); + mapValueComplexType23.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType23); + Element mapValueComplexType24 = document.createElement("xsd:element"); + mapValueComplexType24.setAttribute("ref", "tns:eepk-"); + mapValueComplexType24.setAttribute("minOccurs", "1"); + mapValueComplexType24.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType24); + Element mapValueComplexType25 = document.createElement("xsd:element"); + mapValueComplexType25.setAttribute("ref", "tns:eeval-"); + mapValueComplexType25.setAttribute("minOccurs", "1"); + mapValueComplexType25.setAttribute("maxOccurs", "1"); + mapValueComplexType0.appendChild(mapValueComplexType25); + schema.appendChild(mapValueComplexType); + + types.setDocumentationElement(schema); + return types; + } } 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=892712&r1=892711&r2=892712&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 Mon Dec 21 07:31:58 2009 @@ -18,32 +18,32 @@ *******************************************************************************/ package org.ofbiz.service.engine; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Iterator; +import java.io.StringReader; import java.util.List; import java.util.Map; import javax.xml.namespace.QName; -import javax.xml.rpc.ParameterMode; -import javax.xml.rpc.ServiceException; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; import javolution.util.FastMap; -import org.apache.axis.Message; -import org.apache.axis.client.Call; -import org.apache.axis.client.Service; -import org.apache.axis.encoding.XMLType; -import org.apache.axis.message.RPCElement; -import org.apache.axis.message.RPCParam; -import org.apache.axis.message.SOAPEnvelope; +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.axis2.AxisFault; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.client.Options; +import org.apache.axis2.client.ServiceClient; +import org.ofbiz.base.util.Debug; +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; import org.ofbiz.service.ServiceDispatcher; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilValidate; /** * Generic Service SOAP Interface @@ -78,113 +78,67 @@ // Invoke the remote SOAP service private Map<String, Object> serviceInvoker(ModelService modelService, Map<String, Object> context) throws GenericServiceException { + Delegator delegator = dispatcher.getDelegator(); if (modelService.location == null || modelService.invoke == null) throw new GenericServiceException("Cannot locate service to invoke"); - - Service service = null; - Call call = null; - + + ServiceClient client = null; + QName serviceName = null; + try { - service = new Service(); - call = (Call) service.createCall(); - } catch (javax.xml.rpc.JAXRPCException e) { - throw new GenericServiceException("RPC service error", e); - } catch (ServiceException e) {//Add by Andy.Chen 2003.01.15 + client = new ServiceClient(); + Options options = new Options(); + EndpointReference endPoint = new EndpointReference(this.getLocation(modelService)); + options.setTo(endPoint); + client.setOptions(options); + } catch (AxisFault e) { throw new GenericServiceException("RPC service error", e); } - - URL endPoint = null; - - try { - endPoint = new URL(this.getLocation(modelService)); - } catch (MalformedURLException e) { - throw new GenericServiceException("Location not a valid URL", e); - } - + List<ModelParam> inModelParamList = modelService.getInModelParamList(); - + if (Debug.infoOn()) Debug.logInfo("[SOAPClientEngine.invoke] : Parameter length - " + inModelParamList.size(), module); - - call.setTargetEndpointAddress(endPoint); - + if (UtilValidate.isNotEmpty(modelService.nameSpace)) { - call.setOperationName(new QName(modelService.nameSpace, modelService.invoke)); + serviceName = new QName(modelService.nameSpace, modelService.invoke); } else { - call.setOperationName(modelService.invoke); + serviceName = new QName(modelService.invoke); } - + int i = 0; - - call.setOperation(call.getOperationName().getLocalPart()); - List<Object> vParams = new ArrayList<Object>(); + + Map<String, Object> parameterMap = FastMap.newInstance(); for (ModelParam p: inModelParamList) { if (Debug.infoOn()) Debug.logInfo("[SOAPClientEngine.invoke} : Parameter: " + p.name + " (" + p.mode + ") - " + i, module); // exclude params that ModelServiceReader insert into (internal params) if (!p.internal) { - QName qName = call.getParameterTypeByName(p.name); //.getTypeMapping().getTypeQName((Class) ObjectType.classNameClassMap.get(p.type)); - call.addParameter(p.name, qName, getMode(p.mode)); - vParams.add(context.get(p.name)); + parameterMap.put(p.name, context.get(p.name)); } i++; } - call.setReturnType(XMLType.XSD_ANYTYPE); - Object[] params=vParams.toArray(new Object[vParams.size()]); - - Object result = null; - + OMElement parameterSer = null; + try { - Debug.logInfo("[SOAPClientEngine.invoke] : Sending Call To SOAP Server", module); - result = call.invoke(params); - } catch (java.rmi.RemoteException e) { - throw new GenericServiceException("RPC error", e); - } - if (Debug.verboseOn()) { - Debug.log("SOAP Service Result - " + result, module); + String xmlParameters = XmlSerializer.serialize(parameterMap); + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xmlParameters)); + StAXOMBuilder builder = new StAXOMBuilder(reader); + parameterSer = builder.getDocumentElement(); + } catch (Exception e) { + Debug.logError(e, module); } - - return getResponseParams(call.getMessageContext().getResponseMessage()); - } - - private Map<String, Object> getResponseParams(Message respMessage) { - Map<String, Object> mRet = FastMap.newInstance(); + + Map<String, Object> results = null; try { - SOAPEnvelope resEnv = respMessage.getSOAPEnvelope(); - Iterator<?> i = resEnv.getBodyElements().iterator(); - while (i.hasNext()) { - Object o = i.next(); - - if (o instanceof RPCElement) { - RPCElement body = (RPCElement) o; - - Iterator<?> p = body.getParams().iterator(); - while (p.hasNext()) { - RPCParam param = (RPCParam) p.next(); - mRet.put(param.getName(), param.getValue()); - if (Debug.verboseOn()) { - Debug.log("SOAP Client Param - " + param.getName() + "=" + param.getValue(), module); - } - } - } - } - } catch (org.apache.axis.AxisFault e) { - Debug.logError(e, "AxisFault", module); - } catch (org.xml.sax.SAXException e) { - Debug.logError(e, "SAXException", module); - } - return mRet; - } - - private ParameterMode getMode(String sMode) { - if (sMode.equals("IN")) { - return ParameterMode.IN; - } else if (sMode.equals("OUT")) { - return ParameterMode.OUT; - } else if (sMode.equals("INOUT")) { - return ParameterMode.INOUT; - } else { - return null; + OMFactory factory = OMAbstractFactory.getOMFactory(); + OMElement payload = factory.createOMElement(serviceName); + payload.addChild(parameterSer.getFirstElement()); + OMElement respOMElement = client.sendReceive(payload); + results = (Map<String, Object>) XmlSerializer.deserialize(respOMElement.toString(), delegator); + } catch (Exception e) { + Debug.logError(e, module); } + return results; } } Added: ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceSOAPTests.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceSOAPTests.java?rev=892712&view=auto ============================================================================== --- ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceSOAPTests.java (added) +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceSOAPTests.java Mon Dec 21 07:31:58 2009 @@ -0,0 +1,43 @@ +package org.ofbiz.service.test; + +import java.util.List; +import java.util.Map; + +import javolution.util.FastMap; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilDateTime; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.service.testtools.OFBizTestCase; + +public class ServiceSOAPTests extends OFBizTestCase { + + public final static String module = ServiceSOAPTests.class.getName(); + + public ServiceSOAPTests(String name) { + // TODO Auto-generated constructor stub + super(name); + } + + public void testSOAPSimpleService() throws Exception { + Map<String, Object> serviceContext = FastMap.newInstance(); + serviceContext.put("defaultValue", new Double("123.4567")); + serviceContext.put("message", "Test Message !!!"); + Map<String, Object> results = dispatcher.runSync("testSoapSimple", serviceContext); + String resp = (String) results.get("resp"); + } + + public void testSOAPService() throws Exception { + Map<String, Object> serviceContext = FastMap.newInstance(); + GenericValue productCategory = delegator.makeValue("ProductCategory"); + productCategory.put("productCategoryId", "PRODCAT_TEST"); + productCategory.put("productCategoryTypeId", "CATALOG_CATEGORY"); + productCategory.put("categoryName", "Test ProductCategory"); + productCategory.put("createdStamp", UtilDateTime.nowTimestamp()); + serviceContext.put("productCategory", productCategory); + Map<String, Object> results = dispatcher.runSync("testSoap", serviceContext); + List<GenericValue> products = (List<GenericValue>) results.get("products"); + assertNotNull(products); + } +} Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceSOAPTests.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceSOAPTests.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceSOAPTests.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: ofbiz/trunk/framework/service/testdef/servicetests.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/testdef/servicetests.xml?rev=892712&r1=892711&r2=892712&view=diff ============================================================================== --- ofbiz/trunk/framework/service/testdef/servicetests.xml (original) +++ ofbiz/trunk/framework/service/testdef/servicetests.xml Mon Dec 21 07:31:58 2009 @@ -22,6 +22,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/test-suite.xsd"> <test-case case-name="service-tests"><junit-test-suite class-name="org.ofbiz.service.test.ServiceEngineTests"/></test-case> + <test-case case-name="service-soap-tests"><junit-test-suite class-name="org.ofbiz.service.test.ServiceSOAPTests"/></test-case> <test-case case-name="load-service-test-data"> <entity-xml action="load" entity-xml-url="component://service/testdef/data/ServiceTestData.xml"/> 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=892712&r1=892711&r2=892712&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 Mon Dec 21 07:31:58 2009 @@ -18,33 +18,35 @@ *******************************************************************************/ package org.ofbiz.webapp.event; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.io.StringReader; import java.io.Writer; -import java.util.List; +import java.util.Iterator; import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.wsdl.WSDLException; -import javax.xml.soap.SOAPException; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; import javolution.util.FastMap; -import org.apache.axis.AxisFault; -import org.apache.axis.Constants; -import org.apache.axis.Message; -import org.apache.axis.MessageContext; -import org.apache.axis.message.RPCElement; -import org.apache.axis.message.RPCParam; -import org.apache.axis.message.SOAPEnvelope; -import org.apache.axis.server.AxisServer; +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.axiom.om.util.StAXUtils; +import org.apache.axiom.soap.SOAPBody; +import org.apache.axiom.soap.SOAPEnvelope; +import org.apache.axiom.soap.SOAPFactory; +import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder; import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilXml; +import org.ofbiz.entity.GenericDelegator; +import org.ofbiz.entity.serialize.XmlSerializer; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; @@ -72,7 +74,7 @@ */ public String invoke(Event event, RequestMap requestMap, HttpServletRequest request, HttpServletResponse response) throws EventHandlerException { LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); - AxisServer axisServer; + GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); // first check for WSDL request String wsdlReq = request.getParameter("wsdl"); @@ -138,163 +140,119 @@ } // not a wsdl request; invoke the service - try { - axisServer = AxisServer.getServer(UtilMisc.toMap("name", "OFBiz/Axis Server", "provider", null)); - } catch (AxisFault e) { - sendError(response, e); - throw new EventHandlerException("Problems with the AXIS server", e); - } - MessageContext mctx = new MessageContext(axisServer); - mctx.setEncodingStyle(Constants.URI_LITERAL_ENC); // sets the response encoding - - // get the SOAP message - Message msg = null; - - try { - msg = new Message(request.getInputStream(), false, - request.getHeader("Content-Type"), request.getHeader("Content-Location")); - } catch (IOException ioe) { - sendError(response, "Problem processing the service"); - throw new EventHandlerException("Cannot read the input stream", ioe); - } - - if (msg == null) { - sendError(response, "No message"); - throw new EventHandlerException("SOAP Message is null"); - } - - // log the request message - if (Debug.verboseOn()) { - try { - Debug.logInfo("Request Message:\n" + messageToString(msg) + "\n", module); - } catch (Throwable t) { - } - } - - mctx.setRequestMessage(msg); - - // new envelopes - SOAPEnvelope resEnv = new SOAPEnvelope(); + + // request envelope SOAPEnvelope reqEnv = null; - + // get the service name and parameters try { - reqEnv = (SOAPEnvelope) msg.getSOAPPart().getEnvelope(); - } catch (SOAPException e) { + XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(request.getInputStream()); + StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(xmlReader); + reqEnv = (SOAPEnvelope) builder.getDocumentElement(); + + // log the request message + if (Debug.verboseOn()) { + try { + Debug.logInfo("Request Message:\n" + reqEnv + "\n", module); + } catch (Throwable t) { + } + } + } catch (Exception e) { sendError(response, "Problem processing the service"); throw new EventHandlerException("Cannot get the envelope", e); } - - List<Object> bodies = null; - - try { - bodies = UtilGenerics.checkList(reqEnv.getBodyElements()); - } catch (AxisFault e) { - sendError(response, e); - throw new EventHandlerException(e.getMessage(), e); - } - + Debug.logVerbose("[Processing]: SOAP Event", module); + + try { + // each is a different service call + SOAPBody reqBody = reqEnv.getBody(); + Iterator serviceIter = reqBody.getChildElements(); + while (serviceIter.hasNext()) { + Object serviceObj = serviceIter.next(); + if (serviceObj instanceof OMElement) { + OMElement serviceElement = (OMElement) serviceObj; + String serviceName = serviceElement.getLocalName(); + Map<String, Object> parameters = (Map<String, Object>) XmlSerializer.deserialize(serviceElement.toString(), delegator); + try { + // verify the service is exported for remote execution and invoke it + ModelService model = dispatcher.getDispatchContext().getModelService(serviceName); - // each is a different service call - for (Object o: bodies) { - - if (o instanceof RPCElement) { - RPCElement body = (RPCElement) o; - String serviceName = body.getMethodName(); - List<RPCParam> params = null; - try { - params = UtilGenerics.checkList(body.getParams()); - } catch (Exception e) { - sendError(response, e); - throw new EventHandlerException(e.getMessage(), e); - } - Map<String, Object> serviceContext = FastMap.newInstance(); - for (RPCParam param: params) { - if (Debug.verboseOn()) Debug.logVerbose("[Reading Param]: " + param.getName(), module); - serviceContext.put(param.getName(), param.getObjectValue()); - } - try { - // verify the service is exported for remote execution and invoke it - ModelService model = dispatcher.getDispatchContext().getModelService(serviceName); - - if (model != null && model.export) { - Map<String, Object> result = dispatcher.runSync(serviceName, serviceContext); - - Debug.logVerbose("[EventHandler] : Service invoked", module); - RPCElement resBody = new RPCElement(serviceName + "Response"); - - resBody.setPrefix(body.getPrefix()); - resBody.setNamespaceURI(body.getNamespaceURI()); - - for (Map.Entry<String, Object> entry: result.entrySet()) { - RPCParam par = new RPCParam(entry.getKey(), entry.getValue()); + if (model != null && model.export) { + Map<String, Object> results = dispatcher.runSync(serviceName, parameters); + Debug.logVerbose("[EventHandler] : Service invoked", module); + + // setup the response + Debug.logVerbose("[EventHandler] : Setting up response message", module); + String xmlResults = XmlSerializer.serialize(results); + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xmlResults)); + StAXOMBuilder resultsBuilder = new StAXOMBuilder(reader); + OMElement resultSer = resultsBuilder.getDocumentElement(); + + // create the response soap + SOAPFactory factory = OMAbstractFactory.getSOAP11Factory(); + SOAPEnvelope resEnv = factory.createSOAPEnvelope(); + SOAPBody resBody = factory.createSOAPBody(); + OMElement resService = factory.createOMElement(new QName(serviceName + "Response")); + resService.addChild(resultSer.getFirstElement()); + resBody.addChild(resService); + resEnv.addChild(resBody); + + // log the response message + if (Debug.verboseOn()) { + try { + Debug.log("Response Message:\n" + resEnv + "\n", module); + } catch (Throwable t) { + } + } - resBody.addParam(par); + resEnv.serialize(response.getOutputStream()); + response.getOutputStream().flush(); } - resEnv.addBodyElement(resBody); - resEnv.setEncodingStyle(Constants.URI_LITERAL_ENC); - } else { - sendError(response, "Requested service not available"); - throw new EventHandlerException("Service is not exported"); + + } catch (GenericServiceException e) { + sendError(response, "Problem processing the service"); + throw new EventHandlerException(e.getMessage(), e); } - } catch (GenericServiceException e) { - sendError(response, "Problem processing the service"); - throw new EventHandlerException(e.getMessage(), e); - } catch (javax.xml.soap.SOAPException e) { - sendError(response, "Problem processing the service"); - throw new EventHandlerException(e.getMessage(), e); } } - } - - // setup the response - Debug.logVerbose("[EventHandler] : Setting up response message", module); - msg = new Message(resEnv); - mctx.setResponseMessage(msg); - if (msg == null) { - sendError(response, "No response message available"); - throw new EventHandlerException("No response message available"); - } - - // log the response message - if (Debug.verboseOn()) { - try { - Debug.log("Response Message:\n" + messageToString(msg) + "\n", module); - } catch (Throwable t) { - } - } - - try { - response.setContentType(msg.getContentType(Constants.DEFAULT_SOAP_VERSION)); - response.setContentLength(Integer.parseInt(Long.toString(msg.getContentLength()))); - } catch (AxisFault e) { - sendError(response, e); + } catch (Exception e) { + sendError(response, e.getMessage()); throw new EventHandlerException(e.getMessage(), e); } - - try { - msg.writeTo(response.getOutputStream()); - response.flushBuffer(); - } catch (IOException e) { - throw new EventHandlerException("Cannot write to the output stream"); - } catch (SOAPException e) { - throw new EventHandlerException("Cannot write message to the output stream"); - } - - Debug.logVerbose("[EventHandler] : Message sent to requester", module); - + return null; } - private void sendError(HttpServletResponse res, Object obj) throws EventHandlerException { - Message msg = new Message(obj); - + private void sendError(HttpServletResponse res, String errorMessage) throws EventHandlerException { try { - res.setContentType(msg.getContentType(Constants.DEFAULT_SOAP_VERSION)); - res.setContentLength(Integer.parseInt(Long.toString(msg.getContentLength()))); - msg.writeTo(res.getOutputStream()); - res.flushBuffer(); + // setup the response + Map<String, Object> results = FastMap.newInstance(); + results.put("errorMessage", errorMessage); + String xmlResults= XmlSerializer.serialize(results); + XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xmlResults)); + StAXOMBuilder resultsBuilder = new StAXOMBuilder(xmlReader); + OMElement resultSer = resultsBuilder.getDocumentElement(); + + // create the response soap + SOAPFactory factory = OMAbstractFactory.getSOAP11Factory(); + SOAPEnvelope resEnv = factory.createSOAPEnvelope(); + SOAPBody resBody = factory.createSOAPBody(); + OMElement errMsg = factory.createOMElement(new QName("Response")); + errMsg.addChild(resultSer.getFirstElement()); + resBody.addChild(errMsg); + resEnv.addChild(resBody); + + // log the response message + if (Debug.verboseOn()) { + try { + Debug.log("Response Message:\n" + resEnv + "\n", module); + } catch (Throwable t) { + } + } + + resEnv.serialize(res.getOutputStream()); + res.getOutputStream().flush(); } catch (Exception e) { throw new EventHandlerException(e.getMessage(), e); } @@ -320,10 +278,4 @@ uri.append(reqInfo); return uri.toString(); } - - public static String messageToString(Message msg) throws SOAPException, IOException { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - msg.writeTo(out); - return out.toString(); - } } |
| Free forum by Nabble | Edit this page |
