[jboss-svn-commits] JBL Code SVN: r34637 - in labs/jbossesb/branches/JBESB_4_7_CP/product: services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Aug 11 09:32:32 EDT 2010
Author: kevin.conner at jboss.com
Date: 2010-08-11 09:32:31 -0400 (Wed, 11 Aug 2010)
New Revision: 34637
Modified:
labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/soap/OGNLUtils.java
labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java
labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/StandardTypes.xsd
labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/expected_02.xml
labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/expected_03.xml
Log:
Pulled across fix for SOAPClient action remappes objects with null strings to empty strings: JBESB-3451
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/soap/OGNLUtils.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/soap/OGNLUtils.java 2010-08-11 11:46:44 UTC (rev 34636)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/soap/OGNLUtils.java 2010-08-11 13:32:31 UTC (rev 34637)
@@ -60,7 +60,7 @@
}
}
- return (param != null?param:"");
+ return param;
}
public static String getOGNLExpression(Element element ) {
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java 2010-08-11 11:46:44 UTC (rev 34636)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java 2010-08-11 13:32:31 UTC (rev 34637)
@@ -31,6 +31,8 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -38,6 +40,7 @@
import java.util.Set;
import javax.wsdl.Part;
+import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
@@ -78,6 +81,7 @@
import com.eviware.soapui.impl.wsdl.WsdlProject;
import com.eviware.soapui.impl.wsdl.support.soap.SoapMessageBuilder;
import com.eviware.soapui.impl.wsdl.support.xsd.SampleXmlUtil;
+import com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils;
import com.eviware.soapui.model.iface.MessagePart;
import com.eviware.soapui.model.iface.Operation;
import com.eviware.soapui.settings.WsdlSettings;
@@ -93,10 +97,18 @@
private static final String IS_CLONE_ATTRIB = "is-clone";
private static Logger logger = Logger.getLogger(SoapUIClientService.class);
private Map<String, WsdlInterface[]> wsdls = new HashMap<String, WsdlInterface[]>();
+ private Map<String, Set<QName>> nillables = new HashMap<String, Set<QName>>();
private DocumentBuilderFactory docBuilderFactory ;
private SmooksCache smooksCache;
private ESBProperties properties;
private static final String CLONED_POSTFIX = " - cloned";
+ private static final String SOAPUI_OPTIONAL_COMMENT = "Optional:";
+ private static final String REMOVE_POSTFIX = " to be removed";
+ private static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/";
+ private static final String XMLSCHEMA_INSTANCE_URI = "http://www.w3.org/2001/XMLSchema-instance";
+ private static final String NILLABLE_TAG_NAME = "nillable";
+ private static final String XMLNS_XSI = "xmlns:xsi";
+ private static final String XSI_NIL = "xsi:nil";
/**
* The SoapUI property file.
*/
@@ -324,8 +336,9 @@
public String buildRequest(String wsdl, String operation, Map params, Properties httpClientProps, String smooksResource, String soapNs) throws IOException, UnsupportedOperationException, SAXException {
Operation operationInst = getOperation(wsdl, operation, httpClientProps);
String requestTemplate = operationInst.getRequestAt(0).getRequestContent();
+ Set<QName> nils = nillables.get(wsdl);
- return buildSOAPMessage(requestTemplate, params, smooksResource, soapNs);
+ return buildSOAPMessage(requestTemplate, params, smooksResource, soapNs, nils);
}
/**
@@ -348,7 +361,8 @@
Operation operationInst = getOperation(wsdl, operation, httpClientProps);
WsdlOperation wsdlOperation = (WsdlOperation)operationInst;
String responseTemplate = wsdlOperation.createResponse(true);
- return buildSOAPMessage(responseTemplate, params, smooksResource, soapNs);
+ Set<QName> nils = nillables.get(wsdl);
+ return buildSOAPMessage(responseTemplate, params, smooksResource, soapNs, nils);
}
@@ -383,7 +397,8 @@
}
faultTemplate = faultTemplate + detail.xmlText( new XmlOptions().setSaveAggressiveNamespaces().setSavePrettyPrint())
+ "</detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>";
- faultDetail = buildSOAPMessage(faultTemplate, params, smooksResource, soapNs);
+ Set<QName> nils = nillables.get(wsdl);
+ faultDetail = buildSOAPMessage(faultTemplate, params, smooksResource, soapNs, nils);
return faultDetail;
}
@@ -407,12 +422,24 @@
if (wsdlInterfaces == null) {
WsdlProject wsdlProject = new WsdlProject();
HttpClient httpClient = HttpClientFactory.createHttpClient(httpClientProps);
+ Set<QName> nils = new HashSet<QName>();
try {
- wsdlInterfaces = wsdlProject.importWsdl(wsdl, true, new EsbWsdlLoader(wsdl, httpClient));
+ EsbWsdlLoader loader = new EsbWsdlLoader(wsdl, httpClient);
+ wsdlInterfaces = wsdlProject.importWsdl(wsdl, true, loader);
+ Map<String, XmlObject> schemas = SchemaUtils.getSchemas(wsdl, loader);
+ Iterator keys = schemas.keySet().iterator();
+ while (keys.hasNext()) {
+ XmlObject schema = schemas.get(keys.next());
+ String namespace = SchemaUtils.getTargetNamespace(schema);
+ Document doc = getDocument(schema.toString());
+ Element docRoot = doc.getDocumentElement();
+ extractNillableElements(docRoot, nils, namespace);
+ }
} finally {
HttpClientFactory.shutdown(httpClient);
}
+ nillables.put(wsdl, nils);
wsdls.put(wsdl, wsdlInterfaces);
}
return wsdlInterfaces;
@@ -423,6 +450,26 @@
}
}
+ private void extractNillableElements(Element element, Set<QName> nils, String namespace) {
+ if (element != null
+ && element.getLocalName()!= null
+ && element.getLocalName().equals("element")
+ && element.hasAttribute(NILLABLE_TAG_NAME)
+ && element.getAttribute(NILLABLE_TAG_NAME).equals("true")) {
+ nils.add(new QName(namespace, element.getAttribute("name")));
+ }
+
+ NodeList children = element.getChildNodes();
+ int childCount = children.getLength();
+
+ for(int i = 0; i < childCount; i++) {
+ Node child = children.item(i);
+ if(child.getNodeType() == Node.ELEMENT_NODE) {
+ extractNillableElements((Element) child, nils, namespace);
+ }
+ }
+ }
+
private Operation getOperation(String wsdl, String operation, Properties httpClientProps) throws IOException, UnsupportedOperationException {
WsdlInterface[] wsdlInterfaces = getWsdlInterfaces(wsdl, httpClientProps);
@@ -436,6 +483,7 @@
// Try clearing WSDL cache, WSDL may have updated
wsdls.remove(wsdl);
+ nillables.remove(wsdl);
wsdlInterfaces = getWsdlInterfaces(wsdl, httpClientProps);
for (WsdlInterface wsdlInterface : wsdlInterfaces) {
@@ -449,7 +497,7 @@
throw new UnsupportedOperationException("Operation '" + operation + "' not supported by WSDL '" + wsdl + "'.");
}
- private String buildSOAPMessage(String soapMessageTemplate, Map params, String smooksResource, String soapNs) throws IOException, SAXException {
+ private String buildSOAPMessage(String soapMessageTemplate, Map params, String smooksResource, String soapNs, Set<QName> nils) throws IOException, SAXException {
Document messageDoc = getDocument(soapMessageTemplate) ;
Element docRoot = messageDoc.getDocumentElement();
@@ -468,7 +516,7 @@
dumpSOAP("SOAP Template (Expanded):", docRoot);
}
- injectParameters(docRoot, params, soapNs);
+ injectParameters(docRoot, params, soapNs, nils);
if(smooksResource != null) {
applySmooksTransform(smooksResource, messageDoc);
@@ -701,7 +749,7 @@
}
}
- private void injectParameters(Element element, Map params, String soapNs) {
+ private void injectParameters(Element element, Map params, String soapNs, Set<QName> nils) {
NodeList children = element.getChildNodes();
int childCount = children.getLength();
@@ -713,13 +761,54 @@
String ognl = OGNLUtils.getOGNLExpression(element, soapNs);
Object param = OGNLUtils.getParameter(ognl, params);
- element.removeChild(node);
- element.appendChild(element.getOwnerDocument().createTextNode(param.toString()));
+ if (param == null) {
+ Node parent = element.getParentNode();
+ String namespace = element.getNamespaceURI();
+ Node nsParent = parent;
+ while (nsParent != null && namespace == null) {
+ //Check the parents for the namespace
+ namespace = nsParent.getNamespaceURI();
+ nsParent = nsParent.getParentNode();
+ }
+ QName qname = new QName(namespace, element.getLocalName());
+
+ if (nils.contains(qname)) {
+ //If value is null and it is declared to be nillable set it as xsi:nil
+ element.getOwnerDocument().getDocumentElement().setAttributeNS(XMLNS_URI, XMLNS_XSI, XMLSCHEMA_INSTANCE_URI);
+ element.setAttributeNS(XMLSCHEMA_INSTANCE_URI, XSI_NIL, "true");
+ //Remove the soapUI's '?' text
+ element.removeChild(node);
+ } else {
+ Comment comment = YADOMUtil.getCommentBefore(element);
+ if(comment != null && comment.getTextContent().endsWith(SOAPUI_OPTIONAL_COMMENT)) {
+ //If it is optional do not generate the element
+ parent.removeChild(comment);
+ Comment clone = (Comment) comment.cloneNode(true);
+ clone.setTextContent(comment.getTextContent() + REMOVE_POSTFIX);
+ parent.insertBefore(clone, element);
+ } else {
+ //If it is required generate empty element
+ //Remove the soapUI's '?' text
+ element.removeChild(node);
+ }
+ }
+ } else {
+ element.removeChild(node);
+ element.appendChild(element.getOwnerDocument().createTextNode(param.toString()));
+ }
}
- } else if (node.getNodeType() == Node.ELEMENT_NODE) {
+ } else if (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
NamedNodeMap attributes = node.getAttributes();
injectAttributeParameters(params, soapNs, node, attributes);
- injectParameters((Element) node, params, soapNs);
+ injectParameters((Element) node, params, soapNs, nils);
+ Comment comment = YADOMUtil.getCommentBefore((Element) node);
+ if(comment != null && comment.getTextContent().endsWith(SOAPUI_OPTIONAL_COMMENT + REMOVE_POSTFIX)) {
+ Node parent = node.getParentNode();
+ parent.removeChild(node);
+ parent.removeChild(comment);
+ childCount -= 2;
+ i -= 2;
+ }
}
}
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/StandardTypes.xsd
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/StandardTypes.xsd 2010-08-11 11:46:44 UTC (rev 34636)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/StandardTypes.xsd 2010-08-11 13:32:31 UTC (rev 34637)
@@ -17,8 +17,8 @@
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="phone" type="xs:string" />
- <xs:element name="fax" type="xs:string" />
- <xs:element name="email" type="xs:string" />
+ <xs:element name="fax" type="xs:string" nillable="true"/>
+ <xs:element name="email" type="xs:string" nillable="true" minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/expected_02.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/expected_02.xml 2010-08-11 11:46:44 UTC (rev 34636)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/expected_02.xml 2010-08-11 13:32:31 UTC (rev 34637)
@@ -1,4 +1,4 @@
-<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cus="http://schemas.active-endpoints.com/sample/customerorder/2006/04/CustomerOrder.xsd" xmlns:stan="http://schemas.active-endpoints.com/sample/standardtypes/2006/04/StandardTypes.xsd">
+<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cus="http://schemas.active-endpoints.com/sample/customerorder/2006/04/CustomerOrder.xsd" xmlns:stan="http://schemas.active-endpoints.com/sample/standardtypes/2006/04/StandardTypes.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<cus:customerOrder>
@@ -12,13 +12,12 @@
<stan:contact>
<stan:name/>
<stan:phone/>
- <stan:fax/>
- <stan:email/>
+ <stan:fax xsi:nil="true"/>
+ <!--Optional:-->
+ <stan:email xsi:nil="true"/>
</stan:contact>
<stan:address>
<stan:street1/>
- <!--Optional:-->
- <stan:street2/>
<stan:city/>
<stan:state/>
<stan:zip/>
@@ -29,22 +28,17 @@
<stan:contact>
<stan:name/>
<stan:phone/>
- <stan:fax/>
- <stan:email/>
+ <stan:fax xsi:nil="true"/>
+ <!--Optional:-->
+ <stan:email xsi:nil="true"/>
</stan:contact>
<stan:address>
<stan:street1/>
- <!--Optional:-->
- <stan:street2/>
<stan:city/>
<stan:state/>
<stan:zip/>
</stan:address>
</cus:shipTo>
- <!--Optional:-->
- <cus:billTerms/>
- <!--Optional:-->
- <cus:shipTerms/>
</cus:header>
<cus:items>
<!--1 or more repetitions: - cloned-->
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/expected_03.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/expected_03.xml 2010-08-11 11:46:44 UTC (rev 34636)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/expected_03.xml 2010-08-11 13:32:31 UTC (rev 34637)
@@ -1,4 +1,4 @@
-<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cus="http://schemas.active-endpoints.com/sample/customerorder/2006/04/CustomerOrder.xsd" xmlns:stan="http://schemas.active-endpoints.com/sample/standardtypes/2006/04/StandardTypes.xsd">
+<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cus="http://schemas.active-endpoints.com/sample/customerorder/2006/04/CustomerOrder.xsd" xmlns:stan="http://schemas.active-endpoints.com/sample/standardtypes/2006/04/StandardTypes.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<cus:customerOrder>
@@ -12,13 +12,12 @@
<stan:contact>
<stan:name/>
<stan:phone/>
- <stan:fax/>
- <stan:email/>
+ <stan:fax xsi:nil="true"/>
+ <!--Optional:-->
+ <stan:email xsi:nil="true"/>
</stan:contact>
<stan:address>
<stan:street1/>
- <!--Optional:-->
- <stan:street2/>
<stan:city/>
<stan:state/>
<stan:zip/>
@@ -29,22 +28,17 @@
<stan:contact>
<stan:name/>
<stan:phone/>
- <stan:fax/>
- <stan:email/>
+ <stan:fax xsi:nil="true"/>
+ <!--Optional:-->
+ <stan:email xsi:nil="true"/>
</stan:contact>
<stan:address>
<stan:street1/>
- <!--Optional:-->
- <stan:street2/>
<stan:city/>
<stan:state/>
<stan:zip/>
</stan:address>
</cus:shipTo>
- <!--Optional:-->
- <cus:billTerms/>
- <!--Optional:-->
- <cus:shipTerms/>
</cus:header>
<cus:items>
<!--1 or more repetitions: - cloned-->
More information about the jboss-svn-commits
mailing list