cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r593928 - in /incubator/cxf/trunk: api/src/main/java/org/apache/cxf/message/ rt/javascript/src/main/java/org/apache/cxf/javascript/ rt/javascript/src/main/java/org/apache/cxf/javascript/service/ rt/javascript/src/main/java/org/apache/cxf/ja...
Date Sun, 11 Nov 2007 16:52:24 GMT
Author: bimargulies
Date: Sun Nov 11 08:52:23 2007
New Revision: 593928

URL: http://svn.apache.org/viewvc?rev=593928&view=rev
Log:
Attempt to test Javascript message serialization. Sadly, apparently this 
is blocked on CXF-1197, or I'm just confused.


Modified:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/StringMapImpl.java
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptUtils.java
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java
    incubator/cxf/trunk/rt/javascript/src/main/resources/org/apache/cxf/javascript/cxf-utils.js
    incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java
    incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/service/DocLitWrappedTest.java
    incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/StringMapImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/StringMapImpl.java?rev=593928&r1=593927&r2=593928&view=diff
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/StringMapImpl.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/StringMapImpl.java Sun Nov
11 08:52:23 2007
@@ -21,13 +21,16 @@
 
 import java.util.HashMap;
 
+/**
+ * A variation on HashMap which allows lookup by Class, via the string
+ * returned by {@link Class#getName()}.
+ */
 public class StringMapImpl 
     extends HashMap<String, Object> 
     implements StringMap {
     
-    @SuppressWarnings("unchecked")
     public <T> T get(Class<T> key) {
-        return (T)get(key.getName());
+        return key.cast(get(key.getName()));
     }
 
     public <T> void put(Class<T> key, T value) {

Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptUtils.java?rev=593928&r1=593927&r2=593928&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptUtils.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptUtils.java
Sun Nov 11 08:52:23 2007
@@ -192,7 +192,8 @@
         return token;
     }
     
-    public void generateCodeToSerializeElement(XmlSchemaElement element, 
+    public void generateCodeToSerializeElement(String utilsVarName,
+                                               XmlSchemaElement element, 
                                                String elementJavascriptName,
                                                String elementXmlName,
                                                XmlSchemaCollection xmlSchemaCollection,
@@ -234,7 +235,9 @@
                 startIf(elementJavascriptName + " == null");
                 appendString("<" + elementXmlName + " " + XmlSchemaUtils.NIL_ATTRIBUTES
+ "/>");
                 appendElse();
-                appendExpression(elementJavascriptName + ".serialize(cxfjsutils, '" + elementXmlName
+ "')");
+                appendExpression(elementJavascriptName + ".serialize(" 
+                                 + utilsVarName + ", '" 
+                                 + elementXmlName + "')");
                 endBlock();
             } else {
                 startIf(elementJavascriptName + " != null");
@@ -248,7 +251,7 @@
             // warning: this assumes that ordinary Javascript serialization is all we need.
             // except for &gt; ad all of that.
             if (isStringSimpleType(typeName)) {
-                appendExpression("cxfjsutils.escapeXmlEntities(" + elementJavascriptName
+ ")");
+                appendExpression(utilsVarName + ".escapeXmlEntities(" + elementJavascriptName
+ ")");
             } else {
                 appendExpression(elementJavascriptName);
             }

Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java?rev=593928&r1=593927&r2=593928&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java
Sun Nov 11 08:52:23 2007
@@ -76,7 +76,7 @@
         this.nameManager = nameManager;
         xmlSchemaCollection = serviceInfo.getXmlSchemaCollection();
     }
-    
+
     public String getCode() {
         return code.toString();
     }
@@ -87,10 +87,12 @@
 
     @Override
     public void begin(InterfaceInfo intf) {
+        code.append("\n// Javascript for " + intf.getName() + "\n\n");
+        
         currentInterfaceClassName = nameManager.getJavascriptName(intf.getName());
         operationsWithNameConflicts = new HashSet<OperationInfo>();
         code.append("function " + currentInterfaceClassName + " () {\n");
-        code.append("}\n");
+        code.append("}\n\n");
         Map<String, OperationInfo> localNameMap = new HashMap<String, OperationInfo>();
         for (OperationInfo operation : intf.getOperations()) {
             OperationInfo conflict = localNameMap.get(operation.getName().getLocalPart());
@@ -110,12 +112,12 @@
     @Override
     public void begin(MessagePartInfo part) {
     }
-    
+
     private static class ElementAndNames {
         private XmlSchemaElement element;
         private String javascriptName;
         private String xmlName;
-        
+
         public ElementAndNames(XmlSchemaElement element, String javascriptName, String xmlName)
{
             this.element = element;
             this.javascriptName = javascriptName;
@@ -134,7 +136,7 @@
             return javascriptName;
         }
     }
-    
+
     @Override
     public void begin(OperationInfo op) {
         assert !isRPC;
@@ -143,12 +145,10 @@
         if (op.isUnwrapped()) {
             return;
         }
-        // to make best use of the visitor scheme, we wait until end to
-        // create the function, since the message function can participate in
-        // building the argument list.
+
         boolean needsLongName = operationsWithNameConflicts.contains(op);
         String opFunctionName;
-        String opGlobalFunctionName = nameManager.getJavascriptName(op.getName());
+        String opGlobalFunctionName = nameManager.getJavascriptName(op.getName()) + "_op";
         if (needsLongName) {
             opFunctionName = opGlobalFunctionName;
         } else {
@@ -158,12 +158,13 @@
         MessageInfo inputMessage = op.getInput();
         String wrapperClassName = null;
         StringBuilder parameterList = new StringBuilder();
-        
-        // the message content is a set of elements. Perhaps they come from the parts,
+
+        // the message content is a set of elements. Perhaps they come from the
+        // parts,
         // or perhaps we invent them.
         List<ElementAndNames> elements = new ArrayList<ElementAndNames>();
-        List<MessagePartInfo> parts  = null;
-        
+        List<MessagePartInfo> parts = null;
+
         if (inputMessage != null) {
             parts = inputMessage.getMessageParts();
             if (isWrapped) {
@@ -177,75 +178,99 @@
         }
 
         code.append("function " + opGlobalFunctionName + "(" + parameterList
-                         + "responseCallback, errorCallback) {\n");
+                    + "responseCallback, errorCallback) {\n");
+        if (inputMessage != null) {
+            utils.appendLine("var args = new Array(" + inputParameterNames.size() + ");");
+            int px = 0;
+            for (String param : inputParameterNames) {
+                utils.appendLine("args[" + px + "] = " + param + ";");
+                px++;
+            }
+            utils.appendLine("var xml = this.serializeInputMessage(args);");
+            // more to come ...
+        }
+        code.append("}\n\n");
+        code.append(currentInterfaceClassName + ".prototype." + opFunctionName + " = " +
opGlobalFunctionName
+                    + ";\n\n");
+
+        createInputSerializer(op, isWrapped, inputParameterNames, wrapperClassName, elements,
+                              parts);
+    }
+
+    private void createInputSerializer(OperationInfo op, boolean isWrapped,
+                                       List<String> inputParameterNames, String wrapperClassName,
+                                       List<ElementAndNames> elements, List<MessagePartInfo>
parts) {
+        String serializerFunctionName = nameManager.getJavascriptName(op.getName()) + "_serializeInput";
         
+        code.append("function " + serializerFunctionName + "(args) {\n");
         NamespacePrefixAccumulator prefixAccumulator = new NamespacePrefixAccumulator(serviceSchemaInfo);
-
-        if (parts != null) {
-            for (MessagePartInfo mpi : parts) {
-                XmlSchemaElement element;
-                if (mpi.isElement()) {
-                    element = (XmlSchemaElement) mpi.getXmlSchema();
-                    if (element == null) {
-                        element = XmlSchemaUtils.findElementByRefName(xmlSchemaCollection,

-                                                                      mpi.getElementQName(),
-                                                                      serviceInfo.getTargetNamespace());
-                    }
-                } else {
-                    // there is still an element in there, but it's not a very interesting
element
-                    element = new XmlSchemaElement();
-                    XmlSchemaElement dummyElement = (XmlSchemaElement)mpi.getXmlSchema();
-                    element.setMaxOccurs(dummyElement.getMaxOccurs());
-                    element.setMinOccurs(dummyElement.getMinOccurs());
-                    element.setNillable(dummyElement.isNillable());
-                    element.setSchemaType(xmlSchemaCollection.getTypeByQName(mpi.getTypeQName()));
-                    element.setQName(mpi.getName());
+        for (MessagePartInfo mpi : parts) {
+            XmlSchemaElement element;
+            if (mpi.isElement()) {
+                element = (XmlSchemaElement)mpi.getXmlSchema();
+                if (element == null) {
+                    element = XmlSchemaUtils.findElementByRefName(xmlSchemaCollection, mpi.getElementQName(),
+                                                                  serviceInfo.getTargetNamespace());
                 }
-                assert element != null;
-                assert element.getQName() != null;
-                String partJavascriptVar = 
-                    JavascriptUtils.javaScriptNameToken(element.getQName().getLocalPart());
-                String elementXmlRef = prefixAccumulator.xmlElementString(element);
-
-                elements.add(new ElementAndNames(element, partJavascriptVar, elementXmlRef));
+            } else {
+                // there is still an element in there, but it's not a very
+                // interesting element
+                element = new XmlSchemaElement();
+                XmlSchemaElement dummyElement = (XmlSchemaElement)mpi.getXmlSchema();
+                element.setMaxOccurs(dummyElement.getMaxOccurs());
+                element.setMinOccurs(dummyElement.getMinOccurs());
+                element.setNillable(dummyElement.isNillable());
+                element.setSchemaType(xmlSchemaCollection.getTypeByQName(mpi.getTypeQName()));
+                element.setQName(mpi.getName());
             }
+            assert element != null;
+            assert element.getQName() != null;
+            String partJavascriptVar = JavascriptUtils.javaScriptNameToken(element.getQName().getLocalPart());
+            String elementXmlRef = prefixAccumulator.xmlElementString(element);
+
+            elements.add(new ElementAndNames(element, partJavascriptVar, elementXmlRef));
         }
-        
-        // if not wrapped, we already have parameter vars for each of the parts.
+
+        // if not wrapped, the param array matches up with the parts. If wrapped, the members
+        // of it have to be packed into an object.
 
         if (isWrapped) {
             String partJavascriptVar = elements.get(0).getJavascriptName();
             utils.appendLine("var " + partJavascriptVar + " = new " + wrapperClassName +
"();");
+            int px = 0;
             for (String param : inputParameterNames) {
-                utils.appendLine(partJavascriptVar + ".set" 
-                                 + StringUtils.capitalize(param) + "(" + param + ");");
+                utils.appendLine(partJavascriptVar + ".set" + StringUtils.capitalize(param)
+ "(args[" + px
+                                 + "]);");
+                px++;
             }
+            // stick this into the array in slot 0.
+            utils.appendLine("args[0] = " + partJavascriptVar + ";");
         }
-        
+
         utils.appendLine("var cxfutils = new CxfApacheOrgUtil();");
-        
+
         SoapVersion soapVersion = soapBindingInfo.getSoapVersion();
         assert soapVersion.getVersion() == 1.1;
         utils.appendLine("var xml;");
-        utils.appendLine("xml = cxfutils.beginSoap11Message(\""
-                         + prefixAccumulator.getAttributes()
-                         + "\");");
+        utils.appendLine("xml = cxfutils.beginSoap11Message(\"" + prefixAccumulator.getAttributes()
+ "\");");
 
         utils.setXmlStringAccumulator("xml");
-        
+
+        int px = 0;
         for (ElementAndNames partElement : elements) {
-            utils.generateCodeToSerializeElement(partElement.getElement(),
-                                                 partElement.getJavascriptName(),
-                                                 partElement.getXmlName(), 
-                                                 xmlSchemaCollection, serviceSchemaInfo.getNamespaceURI(),

-                                                 null);
+            utils.generateCodeToSerializeElement("cxfutils",
+                                                 partElement.getElement(), "args[" + px +
"]",
+                                                 partElement.getXmlName(), xmlSchemaCollection,
+                                                 serviceSchemaInfo.getNamespaceURI(), null);
+            px++;
         }
-  
-        utils.appendLine("xml = xml + cxfutils.endSoap11Message();");
 
+        utils.appendLine("xml = xml + cxfutils.endSoap11Message();");
+        utils.appendLine("return xml;");
         code.append("}\n\n");
-        code.append(currentInterfaceClassName + ".prototype." + opFunctionName + " = " 
-                    + opGlobalFunctionName + "\n\n");
+        code.append(currentInterfaceClassName + ".prototype.serializeInputMessage = " 
+                    + serializerFunctionName
+                    + ";\n\n");
     }
 
     private String setupWrapperElement(OperationInfo op, List<String> inputParameterNames,
@@ -257,18 +282,15 @@
         // we expect a type
         assert wrapperPart.isElement();
         wrapperElement = (XmlSchemaElement)wrapperPart.getXmlSchema();
-        XmlSchemaComplexType wrapperType = 
-            (XmlSchemaComplexType)XmlSchemaUtils.getElementType(xmlSchemaCollection, 
-                                                                op.getName().getNamespaceURI(),

-                                                                wrapperElement,
-                                                                null);
+        XmlSchemaComplexType wrapperType = (XmlSchemaComplexType)XmlSchemaUtils
+            .getElementType(xmlSchemaCollection, op.getName().getNamespaceURI(), wrapperElement,
null);
         wrapperClassName = nameManager.getJavascriptName(wrapperType);
         XmlSchemaSequence wrapperTypeSequence = XmlSchemaUtils.getSequence(wrapperType);
         for (int i = 0; i < wrapperTypeSequence.getItems().getCount(); i++) {
             XmlSchemaObject thing = wrapperTypeSequence.getItems().getItem(i);
             if (!(thing instanceof XmlSchemaElement)) {
-                XmlSchemaUtils.unsupportedConstruct("NON_ELEMENT_CHILD", thing.getClass()
-                    .getSimpleName(), wrapperType);
+                XmlSchemaUtils.unsupportedConstruct("NON_ELEMENT_CHILD", thing.getClass().getSimpleName(),
+                                                    wrapperType);
             }
 
             XmlSchemaElement elChild = (XmlSchemaElement)thing;

Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java?rev=593928&r1=593927&r2=593928&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java
Sun Nov 11 08:52:23 2007
@@ -20,9 +20,11 @@
 package org.apache.cxf.javascript.types;
 
 import java.util.Iterator;
+import java.util.logging.Logger;
 
 import javax.xml.namespace.QName;
 
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.javascript.JavascriptUtils;
 import org.apache.cxf.javascript.NameManager;
@@ -47,8 +49,7 @@
  */
 public class SchemaJavascriptBuilder {
     
-    //private static final Logger LOG = LogUtils.getL7dLogger(SchemaJavascriptBuilder.class);
-    
+    private static final Logger LOG = LogUtils.getL7dLogger(SchemaJavascriptBuilder.class);
     
     private XmlSchemaCollection xmlSchemaCollection;
     private NameManager nameManager;
@@ -85,7 +86,9 @@
             }
         }
         
-        return code.toString();
+        String returnValue = code.toString();
+        LOG.finer(returnValue);
+        return returnValue;
     }
     
     
@@ -232,7 +235,7 @@
             String elementName = elementPrefix + elChild.getName();
             String elementXmlRef = prefixAccumulator.xmlElementString(elChild);
             
-            utils.generateCodeToSerializeElement(elChild, elementName, 
+            utils.generateCodeToSerializeElement("cxfjsutils", elChild, elementName, 
                                                  elementXmlRef, xmlSchemaCollection, null,
type);
         }
     }

Modified: incubator/cxf/trunk/rt/javascript/src/main/resources/org/apache/cxf/javascript/cxf-utils.js
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/resources/org/apache/cxf/javascript/cxf-utils.js?rev=593928&r1=593927&r2=593928&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/resources/org/apache/cxf/javascript/cxf-utils.js
(original)
+++ incubator/cxf/trunk/rt/javascript/src/main/resources/org/apache/cxf/javascript/cxf-utils.js
Sun Nov 11 08:52:23 2007
@@ -150,13 +150,16 @@
 
 function org_apache_cxf_begin_soap11_message(namespaceAttributes)
 {
-	return
-		'<?xml version="1.0" encoding="UTF-8"?><soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"'
+	var value = 
+	    '<?xml version="1.0" encoding="UTF-8"?>' 
+	    + '<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"'
 		+ ' xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"'
 	    + '><soap-env:Body '
-	    + namespaceAtttributes 
+	    + namespaceAttributes 
 	    + '>';
+		return value;
 }
+
 CxfApacheOrgUtil.prototype.beginSoap11Message = org_apache_cxf_begin_soap11_message; 
 
 function org_apache_cxf_end_soap11_message()
@@ -164,5 +167,5 @@
 	return '</soap-env:Body>';
 }
 	
-CxfApacheOrgUtil.prototype.envSoap11Message = org_apache_cxf_end_soap11_message; 
+CxfApacheOrgUtil.prototype.endSoap11Message = org_apache_cxf_end_soap11_message; 
 	

Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java?rev=593928&r1=593927&r2=593928&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java
Sun Nov 11 08:52:23 2007
@@ -26,8 +26,10 @@
 
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.test.TestUtilities;
+import org.junit.Assert;
 import org.mozilla.javascript.Context;
 import org.mozilla.javascript.Function;
+import org.mozilla.javascript.RhinoException;
 import org.mozilla.javascript.ScriptableObject;
 
 /**
@@ -47,9 +49,9 @@
         }
     }
     
-    public static class Assert extends ScriptableObject {
+    public static class JsAssert extends ScriptableObject {
 
-        public Assert() { }
+        public JsAssert() { }
         public void jsConstructor(String exp) {
             LOG.severe("Assertion failed: " + exp);
             throw new JavaScriptAssertionFailed(exp);
@@ -86,7 +88,7 @@
         rhinoContext = Context.enter();
         rhinoScope = rhinoContext.initStandardObjects();
         try {
-            ScriptableObject.defineClass(rhinoScope, Assert.class);
+            ScriptableObject.defineClass(rhinoScope, JsAssert.class);
             ScriptableObject.defineClass(rhinoScope, Trace.class);
         } catch (IllegalAccessException e) {
             throw new RuntimeException(e);
@@ -127,7 +129,15 @@
             throw new RuntimeException("Missing test function " + functionName);
         }
         Function function = (Function)fObj;
-        return function.call(rhinoContext, rhinoScope, rhinoScope, args);
+        try {
+            return function.call(rhinoContext, rhinoScope, rhinoScope, args);
+        } catch (RhinoException angryRhino) {
+            String trace = angryRhino.getScriptStackTrace();
+            Assert.fail("JavaScript error: " + angryRhino.toString() + " " + trace);
+        } catch (JavaScriptAssertionFailed assertion) {
+            Assert.fail(assertion.getMessage());
+        }
+        // we never reach here, but Eclipse doesn't know about Assert.fail.
+        return null;
     }
-
 }

Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/service/DocLitWrappedTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/service/DocLitWrappedTest.java?rev=593928&r1=593927&r2=593928&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/service/DocLitWrappedTest.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/service/DocLitWrappedTest.java
Sun Nov 11 08:52:23 2007
@@ -20,33 +20,52 @@
 package org.apache.cxf.javascript.service;
 
 import java.io.IOException;
+import java.io.StringReader;
 import java.util.Collection;
 import java.util.List;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.databinding.DataBinding;
+import org.apache.cxf.databinding.DataReader;
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.javascript.BasicNameManager;
 import org.apache.cxf.javascript.JavascriptTestUtilities;
 import org.apache.cxf.javascript.NameManager;
 import org.apache.cxf.javascript.types.SchemaJavascriptBuilder;
 import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import org.apache.cxf.service.model.MessageInfo;
+import org.apache.cxf.service.model.MessagePartInfo;
 import org.apache.cxf.service.model.SchemaInfo;
 import org.apache.cxf.service.model.ServiceInfo;
+import org.junit.Ignore;
 import org.junit.Test;
+import org.mozilla.javascript.Scriptable;
 import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
 
+@Ignore
 public class DocLitWrappedTest extends AbstractDependencyInjectionSpringContextTests {
+    private static final Logger LOG = LogUtils.getL7dLogger(DocLitWrappedTest.class);
+    private static final String BASIC_TYPE_FUNCTION_RETURN_STRING_SERIALIZER_NAME 
+        = "org_apache_cxf_javascript_fortest_basicTypeFunctionReturnString_serializeInput";
+    
     private JavascriptTestUtilities testUtilities;
     private Client client;
     private List<ServiceInfo> serviceInfos;
     private Collection<SchemaInfo> schemata;
     private NameManager nameManager;
     private JaxWsProxyFactoryBean clientProxyFactory;
+    private XMLInputFactory xmlInputFactory;
 
     public DocLitWrappedTest() {
         testUtilities = new JavascriptTestUtilities(getClass());
         testUtilities.addDefaultNamespaces();
+        xmlInputFactory = XMLInputFactory.newInstance();
     }
 
     @Override
@@ -55,10 +74,47 @@
     }
 
     @Test 
-    public void testDeserialization() throws Exception {
+    public void testMessageSerialization() throws Exception {
         setupClientAndRhino("simple-dlwu-proxy-factory");
         DataBinding dataBinding = clientProxyFactory.getServiceFactory().getDataBinding();
         assertNotNull(dataBinding);
+        // the serialize function takes an array of the five parameters.
+        Object[] params = new Object[5];
+        params[0] = new String("Hello<Dolly&sheep");
+        params[1] = new Integer(42);
+        params[2] = new Long(420000);
+        params[3] = new Float("3.14159");
+        params[4] = new Double("7.90834");
+        Scriptable jsParamArray = 
+            testUtilities.getRhinoContext().newArray(testUtilities.getRhinoScope(), params);
+        Object xmlString = null;
+        xmlString = testUtilities.rhinoCall(BASIC_TYPE_FUNCTION_RETURN_STRING_SERIALIZER_NAME,
+                                                    jsParamArray);
+        assertTrue(xmlString instanceof String);
+        DataReader<XMLStreamReader> reader = dataBinding.createReader(XMLStreamReader.class);
+        ServiceInfo serviceInfo = serviceInfos.get(0); // assume we only have one.
+        QName messageName = 
+            new QName("uri:org.apache.cxf.javascript.fortest", "basicTypeFunctionReturnString");
+        MessageInfo inputMessage = serviceInfo.getMessage(messageName);
+        assertNotNull(inputMessage);
+        MessagePartInfo part = inputMessage.getMessagePartByIndex(0); // has only one part.
+        // we have the entire SOAP message in the string. Readng the entire message is
+        // really organized by the full endpoint. If we want to focus for the moment at the
message
+        // or part part level, either need to invoke Javascript that builds less, or we need
to fish out the 
+        // part from the DOM or the reader.
+        // we can use the DOM to local
+        StringReader stringReader = new StringReader((String)xmlString);
+        XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(stringReader);
+        boolean gotToPart = false;
+        do {
+            xmlStreamReader.nextTag();
+            if (xmlStreamReader.getName().equals(part.getElementQName())) {
+                gotToPart = true;
+            }
+        } while (!gotToPart && xmlStreamReader.hasNext());
+        assertTrue(gotToPart);
+        Object messageObject = reader.read(part, xmlStreamReader);
+        assertNotNull(messageObject);
     }
 
     private void setupClientAndRhino(String clientProxyFactoryBeanId) throws IOException
{
@@ -80,6 +136,8 @@
                 new SchemaJavascriptBuilder(serviceInfo.getXmlSchemaCollection(), nameManager,
schema);
             String allThatJavascript = builder.generateCodeForSchema(schema);
             assertNotNull(allThatJavascript);
+            LOG.info(schema.toString());
+            LOG.info(allThatJavascript);
             testUtilities.readStringIntoRhino(allThatJavascript, schema.toString() + ".js");
         }
         
@@ -87,6 +145,8 @@
             new ServiceJavascriptBuilder(serviceInfo, nameManager);
         serviceBuilder.walk();
         String serviceJavascript = serviceBuilder.getCode();
-        testUtilities.readStringIntoRhino(serviceJavascript, serviceInfo.toString() + ".js");
+        LOG.info(serviceInfo.toString());
+        LOG.info(serviceJavascript);
+        testUtilities.readStringIntoRhino(serviceJavascript, serviceInfo.getName() + ".js");
     }
 }

Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java?rev=593928&r1=593927&r2=593928&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java
Sun Nov 11 08:52:23 2007
@@ -39,16 +39,13 @@
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.javascript.BasicNameManager;
 import org.apache.cxf.javascript.JavascriptTestUtilities;
-import org.apache.cxf.javascript.JavascriptTestUtilities.JavaScriptAssertionFailed;
 import org.apache.cxf.javascript.NameManager;
 import org.apache.cxf.javascript.fortest.TestBean1;
 import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
 import org.apache.cxf.service.model.SchemaInfo;
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.wsdl.EndpointReferenceUtils;
-import org.junit.Assert;
 import org.junit.Test;
-import org.mozilla.javascript.RhinoException;
 import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
 
 public class SerializationTest extends AbstractDependencyInjectionSpringContextTests {
@@ -72,48 +69,39 @@
     protected String[] getConfigLocations() {
         return new String[] {"classpath:serializationTestBeans.xml"};
     }
-    
-    @Test 
+
+    @Test
     public void testEndpointGetSchema() throws IOException {
         setupClientAndRhino("simple-dlwu-proxy-factory");
         ServiceInfo serviceInfo = serviceInfos.get(0);
         EndpointReferenceUtils.getSchema(serviceInfo);
     }
-    
-    @Test 
+
+    @Test
     public void testDeserialization() throws Exception {
         setupClientAndRhino("simple-dlwu-proxy-factory");
         testUtilities.readResourceIntoRhino("/deserializationTests.js");
         DataBinding dataBinding = clientProxyFactory.getServiceFactory().getDataBinding();
         assertNotNull(dataBinding);
-        try {
-            TestBean1 bean = new TestBean1();
-            bean.stringItem = "bean1>stringItem";
-            bean.doubleItem = -1.0;
-            String serialized = serializeObject(dataBinding, bean);
-            testUtilities.rhinoCall("deserializeTestBean1_1", serialized);
-            
-            bean = new TestBean1();
-            bean.stringItem = null;
-            bean.intItem = 21;
-            bean.longItem = 200000001;
-            bean.optionalIntItem = 456123;
-            bean.optionalIntArrayItem = new int[4];
-            bean.optionalIntArrayItem[0] = 3;
-            bean.optionalIntArrayItem[1] = 1;
-            bean.optionalIntArrayItem[2] = 4;
-            bean.optionalIntArrayItem[3] = 1;
-            bean.doubleItem = -1.0;
-            serialized = serializeObject(dataBinding, bean);
-            testUtilities.rhinoCall("deserializeTestBean1_2", serialized);
-
-        } catch (JavaScriptAssertionFailed assertion) {
-            fail(assertion.getMessage());
-        } catch (RhinoException angryRhino) {
-            String trace = angryRhino.getScriptStackTrace();
-            Assert.fail("Javascript error: " + angryRhino.toString() + " " + trace);
-        }
-
+        TestBean1 bean = new TestBean1();
+        bean.stringItem = "bean1>stringItem";
+        bean.doubleItem = -1.0;
+        String serialized = serializeObject(dataBinding, bean);
+        testUtilities.rhinoCall("deserializeTestBean1_1", serialized);
+
+        bean = new TestBean1();
+        bean.stringItem = null;
+        bean.intItem = 21;
+        bean.longItem = 200000001;
+        bean.optionalIntItem = 456123;
+        bean.optionalIntArrayItem = new int[4];
+        bean.optionalIntArrayItem[0] = 3;
+        bean.optionalIntArrayItem[1] = 1;
+        bean.optionalIntArrayItem[2] = 4;
+        bean.optionalIntArrayItem[3] = 1;
+        bean.doubleItem = -1.0;
+        serialized = serializeObject(dataBinding, bean);
+        testUtilities.rhinoCall("deserializeTestBean1_2", serialized);
     }
 
     private String serializeObject(DataBinding dataBinding, TestBean1 bean) throws XMLStreamException
{
@@ -125,80 +113,74 @@
         xmlStreamWriter.close();
         return stringWriter.toString();
     }
-    
+
     @Test
     public void testSerialization() throws Exception {
         setupClientAndRhino("simple-dlwu-proxy-factory");
-        
+
         testUtilities.readResourceIntoRhino("/serializationTests.js");
         DataBinding dataBinding = clientProxyFactory.getServiceFactory().getDataBinding();
         assertNotNull(dataBinding);
-        
-        try {
-            Object serialized = testUtilities.rhinoCall("serializeTestBean1_1");
-            assertTrue(serialized instanceof String);
-            String xml = (String)serialized;
-            DataReader<XMLStreamReader> reader = dataBinding.createReader(XMLStreamReader.class);
-            StringReader stringReader = new StringReader(xml);
-            XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(stringReader);
-            QName testBeanQName = new QName("uri:org.apache.cxf.javascript.testns", "TestBean1");
-            Object bean = reader.read(testBeanQName, xmlStreamReader, TestBean1.class);
-            assertNotNull(bean);
-            assertTrue(bean instanceof TestBean1);
-            TestBean1 testBean = (TestBean1)bean;
-            assertEquals("bean1<stringItem", testBean.stringItem);
-            assertEquals(64, testBean.intItem);
-            assertEquals(64000000, testBean.longItem);
-            assertEquals(101, testBean.optionalIntItem);
-            assertNotNull(testBean.optionalIntArrayItem);
-            assertEquals(1, testBean.optionalIntArrayItem.length);
-            assertEquals(543, testBean.optionalIntArrayItem[0]);
-            
-            serialized = testUtilities.rhinoCall("serializeTestBean1_2");
-            assertTrue(serialized instanceof String);
-            xml = (String)serialized;
-            reader = dataBinding.createReader(XMLStreamReader.class);
-            stringReader = new StringReader(xml);
-            xmlStreamReader = xmlInputFactory.createXMLStreamReader(stringReader);
-            bean = reader.read(testBeanQName, xmlStreamReader, TestBean1.class);
-            assertNotNull(bean);
-            assertTrue(bean instanceof TestBean1);
-            testBean = (TestBean1)bean;
-            assertEquals("bean1<stringItem", testBean.stringItem);
-            assertEquals(64, testBean.intItem);
-            assertEquals(64000000, testBean.longItem);
-            assertEquals(0, testBean.optionalIntItem);
-            assertNotNull(testBean.optionalIntArrayItem);
-            assertEquals(3, testBean.optionalIntArrayItem.length);
-            assertEquals(543, testBean.optionalIntArrayItem[0]);
-            assertEquals(0, testBean.optionalIntArrayItem[1]);
-            assertEquals(345, testBean.optionalIntArrayItem[2]);
-            
-            serialized = testUtilities.rhinoCall("serializeTestBean1_3");
-            assertTrue(serialized instanceof String);
-            xml = (String)serialized;
-            reader = dataBinding.createReader(XMLStreamReader.class);
-            stringReader = new StringReader(xml);
-            xmlStreamReader = xmlInputFactory.createXMLStreamReader(stringReader);
-            bean = reader.read(testBeanQName, xmlStreamReader, TestBean1.class);
-            assertNotNull(bean);
-            assertTrue(bean instanceof TestBean1);
-            testBean = (TestBean1)bean;
-            assertEquals("bean1<stringItem", testBean.stringItem);
-            assertEquals(64, testBean.intItem);
-            assertEquals(43, testBean.longItem);
-            assertEquals(33, testBean.optionalIntItem);
-            assertNull(testBean.optionalIntArrayItem);
-        } catch (RhinoException angryRhino) {
-            String trace = angryRhino.getScriptStackTrace();
-            Assert.fail("Javascript error: " + angryRhino.toString() + " " + trace);
-        }
-        
+
+        Object serialized = testUtilities.rhinoCall("serializeTestBean1_1");
+        assertTrue(serialized instanceof String);
+        String xml = (String)serialized;
+        DataReader<XMLStreamReader> reader = dataBinding.createReader(XMLStreamReader.class);
+        StringReader stringReader = new StringReader(xml);
+        XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(stringReader);
+        QName testBeanQName = new QName("uri:org.apache.cxf.javascript.testns", "TestBean1");
+        Object bean = reader.read(testBeanQName, xmlStreamReader, TestBean1.class);
+        assertNotNull(bean);
+        assertTrue(bean instanceof TestBean1);
+        TestBean1 testBean = (TestBean1)bean;
+        assertEquals("bean1<stringItem", testBean.stringItem);
+        assertEquals(64, testBean.intItem);
+        assertEquals(64000000, testBean.longItem);
+        assertEquals(101, testBean.optionalIntItem);
+        assertNotNull(testBean.optionalIntArrayItem);
+        assertEquals(1, testBean.optionalIntArrayItem.length);
+        assertEquals(543, testBean.optionalIntArrayItem[0]);
+
+        serialized = testUtilities.rhinoCall("serializeTestBean1_2");
+        assertTrue(serialized instanceof String);
+        xml = (String)serialized;
+        reader = dataBinding.createReader(XMLStreamReader.class);
+        stringReader = new StringReader(xml);
+        xmlStreamReader = xmlInputFactory.createXMLStreamReader(stringReader);
+        bean = reader.read(testBeanQName, xmlStreamReader, TestBean1.class);
+        assertNotNull(bean);
+        assertTrue(bean instanceof TestBean1);
+        testBean = (TestBean1)bean;
+        assertEquals("bean1<stringItem", testBean.stringItem);
+        assertEquals(64, testBean.intItem);
+        assertEquals(64000000, testBean.longItem);
+        assertEquals(0, testBean.optionalIntItem);
+        assertNotNull(testBean.optionalIntArrayItem);
+        assertEquals(3, testBean.optionalIntArrayItem.length);
+        assertEquals(543, testBean.optionalIntArrayItem[0]);
+        assertEquals(0, testBean.optionalIntArrayItem[1]);
+        assertEquals(345, testBean.optionalIntArrayItem[2]);
+
+        serialized = testUtilities.rhinoCall("serializeTestBean1_3");
+        assertTrue(serialized instanceof String);
+        xml = (String)serialized;
+        reader = dataBinding.createReader(XMLStreamReader.class);
+        stringReader = new StringReader(xml);
+        xmlStreamReader = xmlInputFactory.createXMLStreamReader(stringReader);
+        bean = reader.read(testBeanQName, xmlStreamReader, TestBean1.class);
+        assertNotNull(bean);
+        assertTrue(bean instanceof TestBean1);
+        testBean = (TestBean1)bean;
+        assertEquals("bean1<stringItem", testBean.stringItem);
+        assertEquals(64, testBean.intItem);
+        assertEquals(43, testBean.longItem);
+        assertEquals(33, testBean.optionalIntItem);
+        assertNull(testBean.optionalIntArrayItem);
     }
 
     private void setupClientAndRhino(String clientProxyFactoryBeanId) throws IOException
{
         testUtilities.setBus((Bus)applicationContext.getBean("cxf"));
-        
+
         testUtilities.initializeRhino();
         testUtilities.readResourceIntoRhino("/org/apache/cxf/javascript/cxf-utils.js");
 
@@ -211,8 +193,8 @@
         schemata = serviceInfo.getSchemas();
         nameManager = new BasicNameManager(serviceInfo);
         for (SchemaInfo schema : schemata) {
-            SchemaJavascriptBuilder builder = 
-                new SchemaJavascriptBuilder(serviceInfo.getXmlSchemaCollection(), nameManager,
schema);
+            SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo
+                .getXmlSchemaCollection(), nameManager, schema);
             String allThatJavascript = builder.generateCodeForSchema(schema);
             assertNotNull(allThatJavascript);
             testUtilities.readStringIntoRhino(allThatJavascript, schema.toString() + ".js");



Mime
View raw message