Return-Path: Delivered-To: apmail-incubator-cxf-commits-archive@locus.apache.org Received: (qmail 78336 invoked from network); 10 Dec 2007 14:16:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 10 Dec 2007 14:16:45 -0000 Received: (qmail 77328 invoked by uid 500); 10 Dec 2007 14:16:34 -0000 Delivered-To: apmail-incubator-cxf-commits-archive@incubator.apache.org Received: (qmail 77281 invoked by uid 500); 10 Dec 2007 14:16:33 -0000 Mailing-List: contact cxf-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cxf-dev@incubator.apache.org Delivered-To: mailing list cxf-commits@incubator.apache.org Received: (qmail 77272 invoked by uid 99); 10 Dec 2007 14:16:33 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Dec 2007 06:16:33 -0800 X-ASF-Spam-Status: No, hits=-96.5 required=10.0 tests=ALL_TRUSTED,URIBL_BLACK,WEIRD_PORT X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Dec 2007 14:16:39 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id F21B81A9832; Mon, 10 Dec 2007 06:16:16 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r602905 - in /incubator/cxf/trunk/rt/javascript/src: main/java/org/apache/cxf/javascript/ main/java/org/apache/cxf/javascript/service/ main/java/org/apache/cxf/javascript/types/ test/java/org/apache/cxf/javascript/ test/java/org/apache/cxf/... Date: Mon, 10 Dec 2007 14:16:15 -0000 To: cxf-commits@incubator.apache.org From: bimargulies@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071210141616.F21B81A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bimargulies Date: Mon Dec 10 06:16:13 2007 New Revision: 602905 URL: http://svn.apache.org/viewvc?rev=602905&view=rev Log: Turn on RPC style, at least for single outputs and simple types. Added: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/RPCClientTest.java (with props) incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/RPCTests.js (with props) Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ElementInfo.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/NamespacePrefixAccumulator.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/Messages.properties incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleRPC.java incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleRPCImpl.java incubator/cxf/trunk/rt/javascript/src/test/resources/RPCClientTestBeans.xml Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ElementInfo.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ElementInfo.java?rev=602905&r1=602904&r2=602905&view=diff ============================================================================== --- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ElementInfo.java (original) +++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ElementInfo.java Mon Dec 10 06:16:13 2007 @@ -34,7 +34,22 @@ private SchemaCollection xmlSchemaCollection; private String referencingURI; private XmlSchemaType containingType; + // in the RPC case, we can have a type and no element. + private XmlSchemaType type; + private boolean empty; + public ElementInfo(XmlSchemaElement element, XmlSchemaType type, String partJavascriptVar, + String elementXmlRef, boolean empty) { + this.element = element; + this.type = type; + this.elementJavascriptName = partJavascriptVar; + this.elementXmlName = elementXmlRef; + this.empty = empty; + } + + public ElementInfo() { + } + public String getUtilsVarName() { return utilsVarName; } @@ -76,5 +91,17 @@ } public void setContainingType(XmlSchemaType containingType) { this.containingType = containingType; + } + public XmlSchemaType getType() { + return type; + } + public void setType(XmlSchemaType type) { + this.type = type; + } + public boolean isEmpty() { + return empty; + } + public void setEmpty(boolean empty) { + this.empty = empty; } } 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=602905&r1=602904&r2=602905&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 Mon Dec 10 06:16:13 2007 @@ -29,6 +29,7 @@ import org.apache.cxf.wsdl.WSDLConstants; import org.apache.ws.commons.schema.XmlSchemaComplexType; +import org.apache.ws.commons.schema.XmlSchemaElement; import org.apache.ws.commons.schema.XmlSchemaSimpleType; import org.apache.ws.commons.schema.XmlSchemaType; @@ -191,28 +192,38 @@ } public void generateCodeToSerializeElement(ElementInfo elementInfo) { - boolean nillable = elementInfo.getElement().isNillable(); - boolean optional = XmlSchemaUtils.isParticleOptional(elementInfo.getElement()); - - XmlSchemaType elType = + XmlSchemaElement element = elementInfo.getElement(); + XmlSchemaType type = elementInfo.getType(); + boolean nillable = element == null || elementInfo.getElement().isNillable(); + boolean optional = element == null || XmlSchemaUtils.isParticleOptional(elementInfo.getElement()); + boolean array = element != null && XmlSchemaUtils.isParticleArray(elementInfo.getElement()); + + XmlSchemaType elType = type; + // perhaps push this up into the callers. + if (elType == null) { XmlSchemaUtils.getElementType(elementInfo.getXmlSchemaCollection(), elementInfo.getReferencingURI(), elementInfo.getElement(), elementInfo.getContainingType()); + if (elType == null) { + throw new UnsupportedConstruct("Null type"); + } + } + // first question: optional? if (optional) { startIf(elementInfo.getElementJavascriptName() + " != null"); - } + } // nillable and optional would be very strange together. // and nillable in the array case applies to the elements. - if (nillable && !XmlSchemaUtils.isParticleArray(elementInfo.getElement())) { + if (nillable && !array) { startIf(elementInfo.getElementJavascriptName() + " == null"); appendString("<" + elementInfo.getElementXmlName() + " " + XmlSchemaUtils.NIL_ATTRIBUTES + "/>"); appendElse(); } - if (XmlSchemaUtils.isParticleArray(elementInfo.getElement())) { + if (array) { // protected against null in arrays. startIf(elementInfo.getElementJavascriptName() + " != null"); startFor("var ax = 0", "ax < " + elementInfo.getElementJavascriptName() + ".length", "ax ++"); @@ -250,17 +261,17 @@ appendString(""); } - if (XmlSchemaUtils.isParticleArray(elementInfo.getElement())) { + if (array) { endBlock(); // for the extra level of nil checking, which might be wrong. endBlock(); // for the for loop. endBlock(); // the null protection. } - if (nillable && !XmlSchemaUtils.isParticleArray(elementInfo.getElement())) { + if (nillable && !array) { endBlock(); } - if (XmlSchemaUtils.isParticleOptional(elementInfo.getElement())) { + if (optional) { endBlock(); } Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/NamespacePrefixAccumulator.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/NamespacePrefixAccumulator.java?rev=602905&r1=602904&r2=602905&view=diff ============================================================================== --- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/NamespacePrefixAccumulator.java (original) +++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/NamespacePrefixAccumulator.java Mon Dec 10 06:16:13 2007 @@ -46,7 +46,7 @@ } public void collect(String prefix, String uri) { - if (!prefixes.contains(prefix)) { + if (!("".equals(uri)) && !prefixes.contains(prefix)) { attributes.append("xmlns:" + prefix + "='" + uri + "' "); prefixes.add(prefix); } @@ -57,6 +57,9 @@ } private String getPrefix(String namespaceURI) { + if ("".equals(namespaceURI)) { + throw new RuntimeException("Prefix requested for default namespace."); + } String schemaPrefix = schemaCollection.getNamespaceContext().getPrefix(namespaceURI); // there could also be a namespace context on an individual schema info. // perhaps SchemaCollection should be enforcing some discipline there. @@ -94,6 +97,10 @@ } public String xmlElementString(QName name) { // used with part concrete names + if ("".equals(name.getNamespaceURI())) { + return name.getLocalPart(); + } + String prefix = getPrefix(name.getNamespaceURI()); collect(prefix, name.getNamespaceURI()); return prefix + ":" + name.getLocalPart(); 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=602905&r1=602904&r2=602905&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 Mon Dec 10 06:16:13 2007 @@ -64,7 +64,6 @@ public class ServiceJavascriptBuilder extends ServiceModelVisitor { private static final Logger LOG = LogUtils.getL7dLogger(ServiceJavascriptBuilder.class); - private boolean isRPC; private SoapBindingInfo soapBindingInfo; private JavascriptUtils utils; private NameManager nameManager; @@ -92,7 +91,7 @@ // derived from the parts. private List inputParameterNames = new ArrayList(); // when not wrapped, we use this to keep track of the bits. - private List unwrappedElementsAndNames; + private List unwrappedElementsAndNames; private NamespacePrefixAccumulator prefixAccumulator; private BindingInfo xmlBindingInfo; @@ -107,6 +106,8 @@ private boolean nonVoidOutput; + private boolean isRPC; + public ServiceJavascriptBuilder(ServiceInfo serviceInfo, NamespacePrefixAccumulator prefixAccumulator, NameManager nameManager) { super(serviceInfo); @@ -152,39 +153,6 @@ serviceTargetNamespace = serviceInfo.getTargetNamespace(); } - private static class ElementAndNames { - private XmlSchemaElement element; - private String javascriptName; - private String xmlName; - private boolean empty; - - public ElementAndNames(XmlSchemaElement element, - String javascriptName, - String xmlName, - boolean empty) { - this.element = element; - this.javascriptName = javascriptName; - this.xmlName = xmlName; - this.empty = empty; - } - - public XmlSchemaElement getElement() { - return element; - } - - public String getXmlName() { - return xmlName; - } - - public String getJavascriptName() { - return javascriptName; - } - - public boolean isEmpty() { - return empty; - } - } - private String getFunctionGlobalName(QName itemName, String itemType) { return nameManager.getJavascriptName(itemName) + "_" + itemType; } @@ -211,10 +179,6 @@ return; } - if (isRPC) { - unsupportedConstruct("RPC", op.getInterface().getName().toString()); - } - isWrapped = op.isUnwrappedCapable(); StringBuilder parameterList = new StringBuilder(); @@ -250,13 +214,13 @@ * visit the input message parts and collect relevant data. */ private void collectUnwrappedInputInfo() { - unwrappedElementsAndNames = new ArrayList(); + unwrappedElementsAndNames = new ArrayList(); if (currentOperation.getInput() != null) { getElementsForParts(currentOperation.getInput(), unwrappedElementsAndNames); } - for (ElementAndNames ean : unwrappedElementsAndNames) { - inputParameterNames.add(ean.getJavascriptName()); + for (ElementInfo ean : unwrappedElementsAndNames) { + inputParameterNames.add(ean.getElementJavascriptName()); } } @@ -417,12 +381,26 @@ if (parts.size() != 1) { unsupportedConstruct("MULTIPLE_OUTPUTS", outputMessage.getName().toString()); } - List elements = new ArrayList(); + List elements = new ArrayList(); String functionName = outputDeserializerFunctionName(outputMessage); code.append("function " + functionName + "(cxfjsutils, partElement) {\n"); getElementsForParts(outputMessage, elements); - ElementAndNames element = elements.get(0); - XmlSchemaType type = element.getElement().getSchemaType(); + ElementInfo element = elements.get(0); + XmlSchemaType type; + + if (isRPC) { + // in the RPC case, there is an extra level of element for the output message. + utils.appendLine("cxfjsutils.trace('rpc element: ' + cxfjsutils.traceElementName(partElement));"); + utils.appendLine("partElement = cxfjsutils.getFirstElementChild(partElement);"); + utils.appendLine("cxfjsutils.trace('rpc element: ' + cxfjsutils.traceElementName(partElement));"); + } + + if (element.getType() != null) { + type = element.getType(); + } else { + type = element.getElement().getSchemaType(); + } + if (!element.isEmpty()) { if (type instanceof XmlSchemaComplexType) { // if there are no response items, the type is likely to have no name and no particle. @@ -490,6 +468,7 @@ ElementInfo elementInfo = new ElementInfo(); elementInfo.setContainingType(null); elementInfo.setElement(inputWrapperElement); + elementInfo.setType(inputWrapperElement.getSchemaType()); elementInfo.setElementJavascriptName("wrapperObj"); elementInfo.setElementXmlName(wrapperXmlElementName); elementInfo.setReferencingURI(serviceTargetNamespace); @@ -498,26 +477,41 @@ utils.generateCodeToSerializeElement(elementInfo); } else { + String operationXmlElement = null; + if (isRPC) { + operationXmlElement = + prefixAccumulator.xmlElementString(currentOperation.getName()); + + // RPC has a level of element for the entire operation. + // we might have some schema to model this, but the following seems + // sufficient. + utils.appendString("<" + operationXmlElement + ">"); + } int px = 0; - // Multiple parts violates WS-I, but we can still do them. + // Multiple parts for doc/lit violates WS-I, but we can still do them. + // They are normal for RPC. // Parts are top-level elements. As such, they cannot, directly, be arrays. // If a part is declared as an array type, the schema has a non-array element // with a complex type consisting of an element with array bounds. We don't // want the JavasSript programmer to have to concoct an extra level of object // (though if the same sort of thing happens elsewhere due to an XmlRootElement, // the JavaScript programmer is stuck with the situation). - for (ElementAndNames ean : unwrappedElementsAndNames) { + for (ElementInfo ean : unwrappedElementsAndNames) { ElementInfo elementInfo = new ElementInfo(); elementInfo.setContainingType(null); elementInfo.setElement(ean.getElement()); + elementInfo.setType(ean.getType()); elementInfo.setElementJavascriptName("args[" + px + "]"); - elementInfo.setElementXmlName(ean.getXmlName()); + elementInfo.setElementXmlName(ean.getElementXmlName()); elementInfo.setReferencingURI(serviceTargetNamespace); elementInfo.setUtilsVarName("cxfutils"); elementInfo.setXmlSchemaCollection(xmlSchemaCollection); utils.generateCodeToSerializeElement(elementInfo); px++; } + if (isRPC) { + utils.appendString(""); + } } utils.appendLine("xml = xml + cxfutils.endSoap11Message();"); @@ -530,23 +524,23 @@ } private XmlSchemaSequence getTypeSequence(XmlSchemaComplexType type, - XmlSchemaElement parentElement) { + QName parentName) { if (!(type.getParticle() instanceof XmlSchemaSequence)) { unsupportedConstruct("NON_SEQUENCE_PARTICLE", type.getQName() != null ? type.getQName() : - parentElement.getQName()); + parentName); } return (XmlSchemaSequence)type.getParticle(); } - private boolean isEmptyType(XmlSchemaType type, XmlSchemaElement parentElement) { + private boolean isEmptyType(XmlSchemaType type, QName parentName) { if (type instanceof XmlSchemaComplexType) { XmlSchemaComplexType complexType = (XmlSchemaComplexType)type; if (complexType.getParticle() == null) { return true; } - XmlSchemaSequence sequence = getTypeSequence(complexType, parentElement); + XmlSchemaSequence sequence = getTypeSequence(complexType, parentName); if (sequence.getItems().getCount() == 0) { return true; } @@ -555,8 +549,8 @@ } private XmlSchemaElement getBuriedElement(XmlSchemaComplexType type, - XmlSchemaElement parentElement) { - XmlSchemaSequence sequence = getTypeSequence(type, parentElement); + QName parentName) { + XmlSchemaSequence sequence = getTypeSequence(type, parentName); XmlSchemaObjectCollection insides = sequence.getItems(); if (insides.getCount() == 1) { XmlSchemaObject item = insides.getItem(0); @@ -572,39 +566,39 @@ * @param parts * @param elements */ - private void getElementsForParts(MessageInfo message, List elements) { + private void getElementsForParts(MessageInfo message, List elements) { for (MessagePartInfo mpi : message.getMessageParts()) { XmlSchemaElement element = null; + XmlSchemaType type = null; + QName diagnosticName = mpi.getName(); if (mpi.isElement()) { element = (XmlSchemaElement)mpi.getXmlSchema(); if (element == null) { element = XmlSchemaUtils.findElementByRefName(xmlSchemaCollection, mpi.getElementQName(), serviceInfo.getTargetNamespace()); } + diagnosticName = element.getQName(); + type = element.getSchemaType(); + if (type == null) { + type = XmlSchemaUtils.getElementType(xmlSchemaCollection, + null, + element, + null); + } } else { - // dkulp may have fixed the problem that caused me to write this - // code. - // aside from the fact that in the !isElement case (rpc) we have - // other work to do. - LOG.severe("Missing element " + mpi.getElementQName().toString() + " in " - + mpi.getName().toString()); - unsupportedConstruct("MISSING_PART_ELEMENT", mpi.getName().toString()); + // RPC (!isElement) + type = (XmlSchemaType)mpi.getXmlSchema(); + if (type == null) { + type = xmlSchemaCollection.getTypeByQName(mpi.getTypeQName()); + diagnosticName = type.getQName(); + } } - assert element != null; - assert element.getQName() != null; - XmlSchemaType type = element.getSchemaType(); - if (type == null) { - type = XmlSchemaUtils.getElementType(xmlSchemaCollection, - null, - element, - null); - } - boolean empty = isEmptyType(type, element); + boolean empty = isEmptyType(type, diagnosticName); if (!empty && type instanceof XmlSchemaComplexType && type.getName() == null) { XmlSchemaElement betterElement = getBuriedElement((XmlSchemaComplexType) type, - element); + diagnosticName); if (betterElement != null) { element = betterElement; if (element.getSchemaType() == null) { @@ -612,17 +606,17 @@ .getTypeByQName(element.getSchemaTypeName())); } } - } - String partJavascriptVar = JavascriptUtils.javaScriptNameToken(element.getQName().getLocalPart()); + String partJavascriptVar = + JavascriptUtils.javaScriptNameToken(mpi.getConcreteName().getLocalPart()); String elementXmlRef = prefixAccumulator.xmlElementString(mpi.getConcreteName()); - elements.add(new ElementAndNames(element, partJavascriptVar, elementXmlRef, empty)); + elements.add(new ElementInfo(element, type, partJavascriptVar, elementXmlRef, empty)); } } - // This function generated Javascript names for the parameters. + // This function finds all the information for the wrapper. private void collectWrapperElementInfo() { if (currentOperation.getInput() != null) { Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/Messages.properties URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/Messages.properties?rev=602905&r1=602904&r2=602905&view=diff ============================================================================== --- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/Messages.properties (original) +++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/Messages.properties Mon Dec 10 06:16:13 2007 @@ -19,4 +19,5 @@ # # ELEMENT_MISSING_TYPE= Root element {0} refers to undefined type {1} in {2}. -UNSUPPORTED_TYPE_CONSTRUCT= Unsupported schema construct {0}. \ No newline at end of file +UNSUPPORTED_TYPE_CONSTRUCT= Unsupported schema construct {0}. +ELEMENT_DANGLING_REFERENCE= Element {0} refers to undefined element {1}. \ No newline at end of file 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=602905&r1=602904&r2=602905&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 Mon Dec 10 06:16:13 2007 @@ -280,6 +280,16 @@ // assume that no lunatic has created multiple elements that differ only by namespace. // or, perhaps, detect that when generating the parser? + if (elChild.getRefName() != null) { + XmlSchemaElement refElement = xmlSchemaCollection.getElementByQName(elChild.getRefName()); + if (refElement == null) { + Message message = new Message("ELEMENT_DANGLING_REFERENCE", LOG, + elChild.getQName(), + elChild.getRefName()); + throw new UnsupportedConstruct(message.toString()); + } + elChild = refElement; + } String elementName = elementPrefix + elChild.getName(); String elementXmlRef = prefixAccumulator.xmlElementString(schemaInfo, elChild); @@ -291,6 +301,7 @@ elementInfo.setReferencingURI(null); elementInfo.setUtilsVarName("cxfjsutils"); elementInfo.setXmlSchemaCollection(xmlSchemaCollection); + elementInfo.setType(elChild.getSchemaType()); utils.generateCodeToSerializeElement(elementInfo); } } Added: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/RPCClientTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/RPCClientTest.java?rev=602905&view=auto ============================================================================== --- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/RPCClientTest.java (added) +++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/RPCClientTest.java Mon Dec 10 06:16:13 2007 @@ -0,0 +1,224 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.javascript; + +import java.util.List; +import java.util.logging.Logger; + +import org.apache.cxf.Bus; +import org.apache.cxf.common.logging.LogUtils; +import org.apache.cxf.endpoint.Client; +import org.apache.cxf.javascript.JavascriptTestUtilities.JSRunnable; +import org.apache.cxf.javascript.JavascriptTestUtilities.Notifier; +import org.apache.cxf.javascript.fortest.SimpleRPCImpl; +import org.apache.cxf.javascript.fortest.TestBean1; +import org.apache.cxf.javascript.fortest.TestBean2; +import org.apache.cxf.jaxws.EndpointImpl; +import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; +import org.apache.cxf.service.model.ServiceInfo; +import org.apache.cxf.test.AbstractCXFSpringTest; +import org.junit.Before; +import org.junit.Test; +import org.mozilla.javascript.Context; +import org.mozilla.javascript.Scriptable; +import org.springframework.context.support.GenericApplicationContext; + +/* + * We end up here with a part with isElement == true, a non-array element, + * but a complex type for an array of the element. + */ + +public class RPCClientTest extends AbstractCXFSpringTest { + + private static final Logger LOG = LogUtils.getL7dLogger(RPCClientTest.class); + + // shadow declaration from base class. + private JavascriptTestUtilities testUtilities; + private JaxWsProxyFactoryBean clientProxyFactory; + private EndpointImpl endpoint; + private SimpleRPCImpl implementor; + + private Client client; + private ServiceInfo serviceInfo; + + public RPCClientTest() throws Exception { + testUtilities = new JavascriptTestUtilities(getClass()); + testUtilities.addDefaultNamespaces(); + } + + @Before + public void setupRhino() throws Exception { + testUtilities.setBus(getBean(Bus.class, "cxf")); + testUtilities.initializeRhino(); + testUtilities.readResourceIntoRhino("/org/apache/cxf/javascript/cxf-utils.js"); + clientProxyFactory = getBean(JaxWsProxyFactoryBean.class, "rpc-proxy-factory"); + client = clientProxyFactory.getClientFactoryBean().create(); + List serviceInfos = client.getEndpoint().getService().getServiceInfos(); + // there can only be one. + assertEquals(1, serviceInfos.size()); + serviceInfo = serviceInfos.get(0); + testUtilities.loadJavascriptForService(serviceInfo); + testUtilities.readResourceIntoRhino("/org/apache/cxf/javascript/RPCTests.js"); + endpoint = getBean(EndpointImpl.class, "rpc-service-endpoint"); + // schema validation doesn't work in RPC. CXF-1277. + //endpoint.getService().put(org.apache.cxf.message.Message.Message.SCHEMA_VALIDATION_ENABLED, + // Boolean.TRUE); + implementor = (SimpleRPCImpl)endpoint.getImplementor(); + implementor.resetLastValues(); + } + + @Override + protected void additionalSpringConfiguration(GenericApplicationContext context) throws Exception { + } + + @Override + protected String[] getConfigLocations() { + return new String[] {"classpath:RPCClientTestBeans.xml"}; + } + + private Void simpleCaller(Context context) { + + LOG.info("About to call simpleTest " + endpoint.getAddress()); + Notifier notifier = + testUtilities.rhinoCallConvert("simpleTest", Notifier.class, + testUtilities.javaToJS(endpoint.getAddress()), + "String Parameter", + testUtilities.javaToJS(new Integer(1776))); + + boolean notified = notifier.waitForJavascript(1000 * 10); + assertTrue(notified); + Integer errorStatus = testUtilities.rhinoEvaluateConvert("globalErrorStatus", Integer.class); + assertNull(errorStatus); + String errorText = testUtilities.rhinoEvaluateConvert("globalErrorStatusText", String.class); + assertNull(errorText); + + // this method returns a String. + String responseObject = testUtilities.rhinoEvaluateConvert("globalResponseObject", String.class); + // there is no response, this thing returns 'void' + assertEquals("String Parameter", responseObject); + SimpleRPCImpl impl = getBean(SimpleRPCImpl.class, "rpc-service"); + assertEquals("String Parameter", impl.getLastString()); + assertEquals(1776, impl.getLastInt()); + return null; + } + + private Void beanFunctionCaller(Context context) { + + TestBean1 b1 = new TestBean1(); + b1.stringItem = "strung"; + TestBean1[] beans = new TestBean1[3]; + beans[0] = new TestBean1(); + beans[0].stringItem = "zerobean"; + beans[0].beanTwoNotRequiredItem = new TestBean2("bean2"); + beans[1] = null; + beans[2] = new TestBean1(); + beans[2].stringItem = "twobean"; + beans[2].optionalIntArrayItem = new int[2]; + beans[2].optionalIntArrayItem[0] = 4; + beans[2].optionalIntArrayItem[1] = 6; + + Object[] jsBeans = new Object[3]; + jsBeans[0] = testBean1ToJS(testUtilities, context, beans[0]); + jsBeans[1] = null; + jsBeans[2] = testBean1ToJS(testUtilities, context, beans[2]); + + Scriptable jsBean1 = testBean1ToJS(testUtilities, context, b1); + Scriptable jsBeanArray = context.newArray(testUtilities.getRhinoScope(), jsBeans); + + LOG.info("About to call beanFunctionTest " + endpoint.getAddress()); + Notifier notifier = + testUtilities.rhinoCallConvert("beanFunctionTest", Notifier.class, + testUtilities.javaToJS(endpoint.getAddress()), + jsBean1, + jsBeanArray); + boolean notified = notifier.waitForJavascript(1000 * 10); + assertTrue(notified); + Integer errorStatus = testUtilities.rhinoEvaluateConvert("globalErrorStatus", Integer.class); + assertNull(errorStatus); + String errorText = testUtilities.rhinoEvaluateConvert("globalErrorStatusText", String.class); + assertNull(errorText); + + // this method returns void. + Scriptable responseObject = (Scriptable)testUtilities.rhinoEvaluate("globalResponseObject"); + // there is no response, this thing returns 'void' + assertNull(responseObject); + SimpleRPCImpl impl = getBean(SimpleRPCImpl.class, "rpc-service"); + TestBean1 b1returned = impl.getLastBean(); + assertEquals(b1, b1returned); + return null; + } + + @Test + public void callSimple() { + LOG.info("about to call simpleTest"); + testUtilities.runInsideContext(Void.class, new JSRunnable() { + + public Void run(Context context) { + return simpleCaller(context); + } + + }); + } + + @org.junit.Ignore + @Test + public void callFunctionWithBeans() { + LOG.info("about to call beanFunctionTest"); + testUtilities.runInsideContext(Void.class, new JSRunnable() { + public Void run(Context context) { + return beanFunctionCaller(context); + } + }); + } + + public static Scriptable testBean1ToJS(JavascriptTestUtilities testUtilities, + Context context, + TestBean1 b1) { + if (b1 == null) { + return null; // black is always in fashion. (Really, we can be called with a null). + } + Scriptable rv = context.newObject(testUtilities.getRhinoScope(), + "org_apache_cxf_javascript_testns_testBean1"); + testUtilities.rhinoCallMethod(rv, "setStringItem", testUtilities.javaToJS(b1.stringItem)); + testUtilities.rhinoCallMethod(rv, "setIntItem", testUtilities.javaToJS(b1.intItem)); + testUtilities.rhinoCallMethod(rv, "setLongItem", testUtilities.javaToJS(b1.longItem)); + testUtilities.rhinoCallMethod(rv, "setBase64Item", testUtilities.javaToJS(b1.base64Item)); + testUtilities.rhinoCallMethod(rv, "setOptionalIntItem", testUtilities.javaToJS(b1.optionalIntItem)); + testUtilities.rhinoCallMethod(rv, "setOptionalIntArrayItem", + testUtilities.javaToJS(b1.optionalIntArrayItem)); + testUtilities.rhinoCallMethod(rv, "setDoubleItem", testUtilities.javaToJS(b1.doubleItem)); + testUtilities.rhinoCallMethod(rv, "setBeanTwoItem", testBean2ToJS(testUtilities, + context, b1.beanTwoItem)); + testUtilities.rhinoCallMethod(rv, "setBeanTwoNotRequiredItem", + testBean2ToJS(testUtilities, context, b1.beanTwoNotRequiredItem)); + return rv; + } + + public static Object testBean2ToJS(JavascriptTestUtilities testUtilities, + Context context, TestBean2 beanTwoItem) { + if (beanTwoItem == null) { + return null; + } + Scriptable rv = context.newObject(testUtilities.getRhinoScope(), + "org_apache_cxf_javascript_testns3_testBean2"); + testUtilities.rhinoCallMethod(rv, "setStringItem", beanTwoItem.stringItem); + return rv; + } +} Propchange: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/RPCClientTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/RPCClientTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleRPC.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleRPC.java?rev=602905&r1=602904&r2=602905&view=diff ============================================================================== --- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleRPC.java (original) +++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleRPC.java Mon Dec 10 06:16:13 2007 @@ -34,5 +34,7 @@ String simpleType(@WebParam(name = "P1") String p1, @WebParam(name = "P2") int p2); @WebMethod void returnVoid(@WebParam(name = "P1") String p1, @WebParam(name = "P2") int p2); + @WebMethod + void beanType(@WebParam(name = "param1") TestBean1 p1); } Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleRPCImpl.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleRPCImpl.java?rev=602905&r1=602904&r2=602905&view=diff ============================================================================== --- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleRPCImpl.java (original) +++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleRPCImpl.java Mon Dec 10 06:16:13 2007 @@ -23,14 +23,17 @@ @WebService(targetNamespace = "uri:cxf.apache.org.javascript.rpc", endpointInterface = "org.apache.cxf.javascript.fortest.SimpleRPC") +@org.apache.cxf.feature.Features(features = "org.apache.cxf.feature.LoggingFeature") public class SimpleRPCImpl implements SimpleRPC { private String lastString; private int lastInt; + private TestBean1 lastBean; public void resetLastValues() { lastString = null; lastInt = -1; + lastBean = null; } public void returnVoid(String p1, int p2) { @@ -44,6 +47,10 @@ return lastString; } + public void beanType(TestBean1 p1) { + lastBean = p1; + } + public String getLastString() { return lastString; } @@ -58,6 +65,14 @@ public void setLastInt(int lastInt) { this.lastInt = lastInt; + } + + public TestBean1 getLastBean() { + return lastBean; + } + + public void setLastBean(TestBean1 lastBean) { + this.lastBean = lastBean; } } Modified: incubator/cxf/trunk/rt/javascript/src/test/resources/RPCClientTestBeans.xml URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/resources/RPCClientTestBeans.xml?rev=602905&r1=602904&r2=602905&view=diff ============================================================================== --- incubator/cxf/trunk/rt/javascript/src/test/resources/RPCClientTestBeans.xml (original) +++ incubator/cxf/trunk/rt/javascript/src/test/resources/RPCClientTestBeans.xml Mon Dec 10 06:16:13 2007 @@ -34,8 +34,8 @@ - Added: incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/RPCTests.js URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/RPCTests.js?rev=602905&view=auto ============================================================================== --- incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/RPCTests.js (added) +++ incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/RPCTests.js Mon Dec 10 06:16:13 2007 @@ -0,0 +1,69 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +function assertionFailed(explanation) +{ + var assert = new Assert(explanation); // this will throw out in Java. +} + +var globalNotifier = null; +var globalErrorStatus = null; +var globalErrorStatusText = null; +var globalResponseObject = null; + +function resetGlobals() { + globalNotifier = null; + globalErrorStatus = null; + globalErrorStatusText = null; + globalResponseObject = null; +} + +function testErrorCallback(httpStatus, httpStatusText) +{ + org_apache_cxf_trace.trace("test error"); + globalErrorStatus = httpStatus; + globalStatusText = httpStatusText; + globalNotifier.notify(); +} + +// Because there is an explicit response wrapper declared, we have a JavaScript +// object here that wraps up the simple 'string'. It is easier to validate it +// from Java, I think. +function testSuccessCallback(responseObject) +{ + org_apache_cxf_trace.trace("test success"); + globalResponseObject = responseObject; + globalNotifier.notify(); +} + +function simpleTest(url, p1, p2) +{ + org_apache_cxf_trace.trace("Enter simpleTest."); + resetGlobals(); + globalNotifier = new org_apache_cxf_notifier(); + + var intf; + intf = new cxf_apache_org_javascript_rpc_SimpleRPC(); + + intf.url = url; + intf.simpleType(testSuccessCallback, testErrorCallback, p1, p2); + // Return the notifier as a convenience to the Java code. + return globalNotifier; +} + Propchange: incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/RPCTests.js ------------------------------------------------------------------------------ svn:eol-style = native