You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bi...@apache.org on 2007/11/18 22:11:21 UTC
svn commit: r596136 - in /incubator/cxf/trunk/rt/javascript/src/test:
java/org/apache/cxf/javascript/ resources/
resources/org/apache/cxf/javascript/
Author: bimargulies
Date: Sun Nov 18 13:11:20 2007
New Revision: 596136
URL: http://svn.apache.org/viewvc?rev=596136&view=rev
Log:
Test (and debug) using the XMLHttpRequest to talk to an actual service.
Added:
incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/XML_GreetMeDocLiteralReq.xml
Modified:
incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JsHttpRequestTest.java
incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JsXMLHttpRequest.java
incubator/cxf/trunk/rt/javascript/src/test/resources/XMLHttpRequestTestBeans.xml
incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/XMLHttpRequestTests.js
Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JsHttpRequestTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JsHttpRequestTest.java?rev=596136&r1=596135&r2=596136&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JsHttpRequestTest.java (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JsHttpRequestTest.java Sun Nov 18 13:11:20 2007
@@ -20,12 +20,19 @@
package org.apache.cxf.javascript;
import java.io.File;
+import java.io.Reader;
+import java.io.StringWriter;
import java.net.URL;
import java.util.Properties;
+import org.w3c.dom.Document;
+
import org.apache.cxf.Bus;
import org.apache.cxf.javascript.JavascriptTestUtilities.Notifier;
+import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.test.AbstractCXFSpringTest;
+import org.jaxen.XPath;
+import org.jaxen.dom.DOMXPath;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
@@ -103,7 +110,7 @@
assertTrue("headers", testUtilities.rhinoEvaluateConvert("asyncResponseHeaders", String.class)
.contains("Content-Type: text/html"));
}
-
+
@Test
public void testSyncHttpFetch() throws Exception {
setupRhino();
@@ -113,6 +120,30 @@
String httpResponse = (String) httpObj;
// check for 'Shalom' in Hebrew as a charset check.
assertTrue(httpResponse.contains("\u05e9\u05dc\u05d5\u05dd"));
+ }
+
+ @Test
+ public void testSyncWebServiceInteraction() throws Exception {
+ Reader r = getResourceAsReader("/org/apache/cxf/javascript/XML_GreetMeDocLiteralReq.xml");
+ StringWriter writer = new StringWriter();
+ char[] buffer = new char[1024];
+ int readCount;
+ while ((readCount = r.read(buffer, 0, 1024)) > 0) {
+ writer.write(buffer, 0, readCount);
+ }
+ String xml = writer.toString();
+ EndpointImpl endpoint = this.getBean(EndpointImpl.class, "greeter-service-endpoint");
+ JsSimpleDomNode xmlResponse =
+ testUtilities.rhinoCallConvert("testSyncXml",
+ JsSimpleDomNode.class,
+ testUtilities.javaToJS(endpoint.getAddress()),
+ testUtilities.javaToJS(xml));
+ assertNotNull(xmlResponse);
+ Document doc = (Document)xmlResponse.getWrappedNode();
+ XPath echoStringPath = new DOMXPath("//t:responseType/text()");
+ echoStringPath.addNamespace("t", "http://apache.org/hello_world_xml_http/wrapped/types");
+ String nodeText = echoStringPath.stringValueOf(echoStringPath.selectSingleNode(doc));
+ assertEquals(nodeText, "Hello \u05e9\u05dc\u05d5\u05dd");
}
public String getStaticResourceURL() throws Exception {
Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JsXMLHttpRequest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JsXMLHttpRequest.java?rev=596136&r1=596135&r2=596136&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JsXMLHttpRequest.java (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JsXMLHttpRequest.java Sun Nov 18 13:11:20 2007
@@ -374,7 +374,9 @@
|| contentType.endsWith("+xml")) {
try {
- DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
ByteArrayInputStream bais = new ByteArrayInputStream(contentBytes);
InputSource inputSource = new InputSource(bais);
inputSource.setEncoding(contentEncoding);
@@ -413,7 +415,7 @@
private byte[] utf8Bytes(String data) {
ByteBuffer bb = utf8.encode(data);
- byte[] val = new byte[bb.capacity()];
+ byte[] val = new byte[bb.limit()];
bb.get(val);
return val;
}
Modified: incubator/cxf/trunk/rt/javascript/src/test/resources/XMLHttpRequestTestBeans.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/resources/XMLHttpRequestTestBeans.xml?rev=596136&r1=596135&r2=596136&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/resources/XMLHttpRequestTestBeans.xml (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/resources/XMLHttpRequestTestBeans.xml Sun Nov 18 13:11:20 2007
@@ -37,6 +37,7 @@
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
+ <import resource="classpath:META-INF/cxf/cxf-extension-xml.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml" />
@@ -61,7 +62,7 @@
</httpj:engine-factory>
<jaxws:endpoint id="greeter-service-endpoint"
- implementor="org.apache.hello_world_doc_lit.GreeterImplDoc"
+ implementor="org.apache.hello_world_xml_http.wrapped.GreeterImpl"
address="http://localhost:8808/Greeter">
</jaxws:endpoint>
Modified: incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/XMLHttpRequestTests.js
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/XMLHttpRequestTests.js?rev=596136&r1=596135&r2=596136&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/XMLHttpRequestTests.js (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/XMLHttpRequestTests.js Sun Nov 18 13:11:20 2007
@@ -149,4 +149,19 @@
function testAsyncHttpFetch2() {
globalAsyncRequest.send();
-}
\ No newline at end of file
+}
+// this tests XML in both directions.
+function testSyncXml(address, request) {
+
+ var r = new XMLHttpRequest();
+ r.open("POST", address, false);
+ if (r.readyState != r.OPENED) {
+ assertionFailed("state not OPENED after OPEN");
+ }
+ // just send it as text (or, really, whatever the Java code set up for us).
+ r.send(request);
+ if (r.readyState != r.DONE) {
+ assertionFailed("state not DONE after sync send.")
+ }
+ return r.responseXML;
+}
Added: incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/XML_GreetMeDocLiteralReq.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/XML_GreetMeDocLiteralReq.xml?rev=596136&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/XML_GreetMeDocLiteralReq.xml (added)
+++ incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/XML_GreetMeDocLiteralReq.xml Sun Nov 18 13:11:20 2007
@@ -0,0 +1,22 @@
+<!--
+ 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.
+--><!-- this message goes to org.apache.hello_world_xml_http.wrapped.GreeterImpl -->
+<ns2:greetMe xmlns="http://www.w3.org/2005/02/addressing/wsdl"
+ xmlns:ns2="http://apache.org/hello_world_xml_http/wrapped/types">
+ <ns2:requestType>ש×××</ns2:requestType>
+</ns2:greetMe>