Author: jochen
Date: Thu Oct 26 14:26:38 2006
New Revision: 468143
URL: http://svn.apache.org/viewvc?view=rev&rev=468143
Log:
Fixed a serious performance problem, if the XML parser was sending large
content in small pieces. This could happen, for example, if the content
contained a large number of character entities.
PR: XMLRPC-119
Removed:
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/ShutdownTest.java
Modified:
webservices/xmlrpc/trunk/.classpath
webservices/xmlrpc/trunk/common/pom.xml
webservices/xmlrpc/trunk/common/src/main/java/org/apache/xmlrpc/parser/AtomicParser.java
webservices/xmlrpc/trunk/common/src/main/java/org/apache/xmlrpc/parser/RecursiveTypeParserImpl.java
webservices/xmlrpc/trunk/pom.xml
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/RequestProcessorFactoryFactory.java
webservices/xmlrpc/trunk/src/changes/changes.xml
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/JiraTest.java
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/ParserTest.java
webservices/xmlrpc/trunk/tests/src/test/resources/org/apache/xmlrpc/test/JiraTest.properties
Modified: webservices/xmlrpc/trunk/.classpath
URL:
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/.classpath?view=diff&rev=468143&r1=468142&r2=468143
==============================================================================
--- webservices/xmlrpc/trunk/.classpath (original)
+++ webservices/xmlrpc/trunk/.classpath Thu Oct 26 14:26:38 2006
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry path="common/src/main/java"
output="common/target/classes" kind="src"/>
- <classpathentry path="client/src/main/java"
output="client/target/classes" kind="src"/>
- <classpathentry path="server/src/main/java"
output="server/target/classes" kind="src"/>
- <classpathentry path="tests/src/test/java" kind="src"/>
- <classpathentry path="tests/src/test/resources" kind="src"/>
- <classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER"
kind="con"/>
- <classpathentry path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"
kind="con"/>
- <classpathentry path="tests/target/test-classes" kind="output"/>
+ <classpathentry kind="src" output="common/target/classes"
path="common/src/main/java"/>
+ <classpathentry kind="src" output="client/target/classes"
path="client/src/main/java"/>
+ <classpathentry kind="src" output="server/target/classes"
path="server/src/main/java"/>
+ <classpathentry kind="src" path="tests/src/test/java"/>
+ <classpathentry kind="src" path="tests/src/test/resources"/>
+ <classpathentry kind="con"
path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JDK-1.5.0"/>
+ <classpathentry kind="output" path="tests/target/test-classes"/>
</classpath>
Modified: webservices/xmlrpc/trunk/common/pom.xml
URL:
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/common/pom.xml?view=diff&rev=468143&r1=468142&r2=468143
==============================================================================
--- webservices/xmlrpc/trunk/common/pom.xml (original)
+++ webservices/xmlrpc/trunk/common/pom.xml Thu Oct 26 14:26:38 2006
@@ -36,9 +36,8 @@
</build>
<dependencies>
<dependency>
- <groupId>org.apache.ws.commons</groupId>
+ <groupId>org.apache.ws.commons.util</groupId>
<artifactId>ws-commons-util</artifactId>
- <version>1.0.1</version>
</dependency>
<dependency>
<groupId>jaxme</groupId>
Modified:
webservices/xmlrpc/trunk/common/src/main/java/org/apache/xmlrpc/parser/AtomicParser.java
URL:
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/common/src/main/java/org/apache/xmlrpc/parser/AtomicParser.java?view=diff&rev=468143&r1=468142&r2=468143
==============================================================================
---
webservices/xmlrpc/trunk/common/src/main/java/org/apache/xmlrpc/parser/AtomicParser.java
(original)
+++
webservices/xmlrpc/trunk/common/src/main/java/org/apache/xmlrpc/parser/AtomicParser.java
Thu Oct 26 14:26:38 2006
@@ -41,7 +41,7 @@
}
public void characters(char[] pChars, int pStart, int pLength) throws
SAXException {
- if (sb == null) {
+ if (sb == null) {
if (!isEmpty(pChars, pStart, pLength)) {
throw new SAXParseException("Unexpected
non-whitespace characters",
getDocumentLocator());
Modified:
webservices/xmlrpc/trunk/common/src/main/java/org/apache/xmlrpc/parser/RecursiveTypeParserImpl.java
URL:
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/common/src/main/java/org/apache/xmlrpc/parser/RecursiveTypeParserImpl.java?view=diff&rev=468143&r1=468142&r2=468143
==============================================================================
---
webservices/xmlrpc/trunk/common/src/main/java/org/apache/xmlrpc/parser/RecursiveTypeParserImpl.java
(original)
+++
webservices/xmlrpc/trunk/common/src/main/java/org/apache/xmlrpc/parser/RecursiveTypeParserImpl.java
Thu Oct 26 14:26:38 2006
@@ -37,7 +37,7 @@
private final TypeFactory factory;
private boolean inValueTag;
private TypeParser typeParser;
- private String text;
+ private StringBuffer text = new StringBuffer();
/** Creates a new instance.
* @param pContext The namespace context.
@@ -54,7 +54,7 @@
protected void startValueTag() throws SAXException {
inValueTag = true;
- text = null;
+ text.setLength(0);
typeParser = null;
}
@@ -63,8 +63,8 @@
protected void endValueTag() throws SAXException {
if (inValueTag) {
if (typeParser == null) {
- addResult(text == null ? "" : text);
- text = null;
+ addResult(text.toString());
+ text.setLength(0);
} else {
typeParser.endDocument();
try {
@@ -82,7 +82,7 @@
public void startDocument() throws SAXException {
inValueTag = false;
- text = null;
+ text.setLength(0);
typeParser = null;
}
@@ -118,9 +118,9 @@
}
typeParser.setDocumentLocator(getDocumentLocator());
typeParser.startDocument();
- if (text != null) {
-
typeParser.characters(text.toCharArray(), 0, text.length());
- text = null;
+ if (text.length() > 0) {
+
typeParser.characters(text.toString().toCharArray(), 0, text.length());
+ text.setLength(0);
}
}
typeParser.startElement(pURI, pLocalName, pQName,
pAttrs);
@@ -133,8 +133,7 @@
public void characters(char[] pChars, int pOffset, int pLength) throws
SAXException {
if (typeParser == null) {
if (inValueTag) {
- String s = new String(pChars, pOffset, pLength);
- text = text == null ? s : text + s;
+ text.append(pChars, pOffset, pLength);
} else {
super.characters(pChars, pOffset, pLength);
}
@@ -146,8 +145,7 @@
public void ignorableWhitespace(char[] pChars, int pOffset, int
pLength) throws SAXException {
if (typeParser == null) {
if (inValueTag) {
- String s = new String(pChars, pOffset, pLength);
- text = text == null ? s : text + s;
+ text.append(pChars, pOffset, pLength);
} else {
super.ignorableWhitespace(pChars, pOffset,
pLength);
}
Modified: webservices/xmlrpc/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/pom.xml?view=diff&rev=468143&r1=468142&r2=468143
==============================================================================
--- webservices/xmlrpc/trunk/pom.xml (original)
+++ webservices/xmlrpc/trunk/pom.xml Thu Oct 26 14:26:38 2006
@@ -262,7 +262,7 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.apache.ws.commons</groupId>
+ <groupId>org.apache.ws.commons.util</groupId>
<artifactId>ws-commons-util</artifactId>
<version>1.0.2-SNAPSHOT</version>
</dependency>
Modified:
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/RequestProcessorFactoryFactory.java
URL:
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/RequestProcessorFactoryFactory.java?view=diff&rev=468143&r1=468142&r2=468143
==============================================================================
---
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/RequestProcessorFactoryFactory.java
(original)
+++
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/RequestProcessorFactoryFactory.java
Thu Oct 26 14:26:38 2006
@@ -39,7 +39,7 @@
* implement them.</p>
* <p>The default [EMAIL PROTECTED] RequestProcessorFactoryFactory} is the
* [EMAIL PROTECTED] RequestSpecificProcessorFactoryFactory}. It creates a new
- * processor instance for any request. In other words, it allows to
+ * processor instance for any request. In other words, it allows the
* request processor to have some state. This is fine, if the request
* processor is a lightweight object or needs request specific
* initialization. In this case, the actual request processor is
Modified: webservices/xmlrpc/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/src/changes/changes.xml?view=diff&rev=468143&r1=468142&r2=468143
==============================================================================
--- webservices/xmlrpc/trunk/src/changes/changes.xml (original)
+++ webservices/xmlrpc/trunk/src/changes/changes.xml Thu Oct 26 14:26:38 2006
@@ -62,6 +62,11 @@
The method TimingOutCallback.waitForResponse is now checking, whether
a response has already arrived before waiting.
</action>
+ <action dev="jochen" type="fix" issue="XMLRPC-119">
+ Fixed a serious performance problem, if the XML parser was
sending large
+ content in small pieces. This could happen, for example, if the
content
+ contained a large number of character entities.
+ </action>
</release>
<release version="3.0" date="30-Aug-2006">
<action dev="jochen" type="fix" due-to="Matt Preston"
Modified:
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/JiraTest.java
URL:
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/JiraTest.java?view=diff&rev=468143&r1=468142&r2=468143
==============================================================================
---
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/JiraTest.java
(original)
+++
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/JiraTest.java
Thu Oct 26 14:26:38 2006
@@ -1,366 +1,399 @@
-/*
- * Copyright 1999,2005 The Apache Software Foundation.
- *
- * Licensed 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.xmlrpc.test;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.lang.reflect.UndeclaredThrowableException;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.Collections;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Vector;
-
-import org.apache.xmlrpc.XmlRpcException;
-import org.apache.xmlrpc.client.TimingOutCallback;
-import org.apache.xmlrpc.client.XmlRpcClient;
-import org.apache.xmlrpc.client.XmlRpcHttpClientConfig;
-import org.apache.xmlrpc.client.util.ClientFactory;
-import org.apache.xmlrpc.common.XmlRpcStreamRequestConfig;
-import org.apache.xmlrpc.parser.XmlRpcResponseParser;
-import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
-import org.apache.xmlrpc.util.SAXParsers;
-import org.xml.sax.InputSource;
-import org.xml.sax.XMLReader;
-
-
-/**
- * Test case for various jira issues.
- */
-public class JiraTest extends XmlRpcTestCase {
- /** Interface of the handler for [EMAIL PROTECTED] JiraTest#testXMLRPC89()}
- */
- public interface XMLRPC89Handler {
- /**
- * Returns the reversed vector.
- */
- Vector reverse(Vector pVector);
- /**
- * Returns the same hashtable, but doubles the
- * values.
- */
- Hashtable doubledValues(Hashtable pMap);
- /**
- * Returns the same properties, but doubles the
- * values.
- */
- Properties doubledPropertyValues(Properties pMap);
- }
-
- /**
- * Handler for [EMAIL PROTECTED] JiraTest#testXMLRPC89()}
- */
- public static class XMLRPC89HandlerImpl implements XMLRPC89Handler {
- public Vector reverse(Vector pVector) {
- Vector result = new Vector(pVector.size());
- result.addAll(pVector);
- Collections.reverse(result);
- return result;
- }
- public Hashtable doubledValues(Hashtable pMap) {
- final Hashtable result;
- if (pMap instanceof Properties) {
- result = new Properties();
- } else {
- result = new Hashtable();
- }
- result.putAll(pMap);
- for (Iterator iter = result.entrySet().iterator();
iter.hasNext(); ) {
- Map.Entry entry = (Map.Entry) iter.next();
- Object value = entry.getValue();
- final Integer i;
- if (pMap instanceof Properties) {
- i = Integer.valueOf((String) value);
- } else {
- i = (Integer) value;
- }
- Integer iDoubled = new Integer(i.intValue()*2);
- if (pMap instanceof Properties) {
- entry.setValue(iDoubled.toString());
- } else {
- entry.setValue(iDoubled);
- }
- }
- return result;
- }
- public Properties doubledPropertyValues(Properties pProperties) {
- return (Properties) doubledValues(pProperties);
- }
- }
-
- protected XmlRpcHandlerMapping getHandlerMapping() throws IOException,
- XmlRpcException {
- return getHandlerMapping("JiraTest.properties");
- }
-
- /**
- * Test case for <a href="http://issues.apache.org/jira/browse/XMLRPC-89">
- * XMLRPC-89</a>
- */
- public void testXMLRPC89() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testXMLRPC89Vector(providers[i]);
- testXMLRPC89Hashtable(providers[i]);
- testXMLRPC89Properties(providers[i]);
- }
- }
-
- private void testXMLRPC89Vector(ClientProvider pProvider) throws Exception
{
- Vector values = new Vector();
- for (int i = 0; i < 3; i++) {
- values.add(new Integer(i));
- }
- Vector params = new Vector();
- params.add(values);
- XmlRpcClient client = pProvider.getClient();
- client.setConfig(getConfig(pProvider));
- Object res = client.execute(XMLRPC89Handler.class.getName() +
".reverse", params);
- Object[] result = (Object[]) res;
- assertNotNull(result);
- assertEquals(3, result.length);
- for (int i = 0; i < 3; i++) {
- assertEquals(new Integer(2-i), result[i]);
- }
-
- ClientFactory factory = new ClientFactory(client);
- XMLRPC89Handler handler = (XMLRPC89Handler)
factory.newInstance(XMLRPC89Handler.class);
- Vector resultVector = handler.reverse(values);
- assertNotNull(resultVector);
- assertEquals(3, resultVector.size());
- for (int i = 0; i < 3; i++) {
- assertEquals(new Integer(2-i), resultVector.get(i));
- }
- }
-
- private void verifyXMLRPC89Hashtable(Map pMap) {
- assertNotNull(pMap);
- assertEquals(3, pMap.size());
- for (int i = 0; i < 3; i++) {
- Integer j = (Integer) pMap.get(String.valueOf(i));
- assertEquals(i*2, j.intValue());
- }
- }
-
- private void testXMLRPC89Hashtable(ClientProvider pProvider) throws
Exception {
- Hashtable values = new Hashtable();
- for (int i = 0; i < 3; i++) {
- values.put(String.valueOf(i), new Integer(i));
- }
- XmlRpcClient client = pProvider.getClient();
- client.setConfig(getConfig(pProvider));
- Object res = client.execute(XMLRPC89Handler.class.getName() +
".doubledValues", new Object[]{values});
- verifyXMLRPC89Hashtable((Map) res);
-
- ClientFactory factory = new ClientFactory(client);
- XMLRPC89Handler handler = (XMLRPC89Handler)
factory.newInstance(XMLRPC89Handler.class);
- Hashtable result = handler.doubledValues(values);
- verifyXMLRPC89Hashtable(result);
- }
-
- private void verifyXMLRPC89Properties(Map pMap) {
- assertNotNull(pMap);
- assertEquals(3, pMap.size());
- for (int i = 0; i < 3; i++) {
- String j = (String) pMap.get(String.valueOf(i));
- assertEquals(i*2, Integer.parseInt(j));
- }
- }
-
- private void testXMLRPC89Properties(ClientProvider pProvider) throws
Exception {
- Properties values = new Properties();
- for (int i = 0; i < 3; i++) {
- values.put(String.valueOf(i), String.valueOf(i));
- }
- XmlRpcClient client = pProvider.getClient();
- client.setConfig(getConfig(pProvider));
- Object res = client.execute(XMLRPC89Handler.class.getName() +
".doubledPropertyValues", new Object[]{values});
- verifyXMLRPC89Properties((Map) res);
-
- ClientFactory factory = new ClientFactory(client);
- XMLRPC89Handler handler = (XMLRPC89Handler)
factory.newInstance(XMLRPC89Handler.class);
- Properties result = handler.doubledPropertyValues(values);
- verifyXMLRPC89Properties(result);
- }
-
- /** Handler for XMLRPC-96
- */
- public static class XMLRPC96Handler {
- /** Returns the "Hello, world!" string.
- */
- public String getHelloWorld() {
- return "Hello, world!";
- }
- }
-
- /**
- * Test case for <a href="http://issues.apache.org/jira/browse/XMLRPC-96">
- * XMLRPC-96</a>
- */
- public void testXMLRPC96() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testXMLRPC96(providers[i]);
- }
- }
-
- private void testXMLRPC96(ClientProvider pProvider) throws Exception {
- XmlRpcClient client = pProvider.getClient();
- client.setConfig(getConfig(pProvider));
- String s = (String) client.execute(XMLRPC96Handler.class.getName() +
".getHelloWorld", new Object[0]);
- assertEquals("Hello, world!", s);
- s = (String) client.execute(XMLRPC96Handler.class.getName() +
".getHelloWorld", (Object[]) null);
- assertEquals("Hello, world!", s);
- }
-
- /**
- * Test case for <a href="http://issues.apache.org/jira/browse/XMLRPC-112">
- * XMLRPC-112</a>
- */
- public void testXMLRPC112() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testXMLRPC112(providers[i]);
- }
- }
-
- /**
- * Test case for <a href="http://issues.apache.org/jira/browse/XMLRPC-113">
- * XMLRPC-113</a>
- */
- public void testXMLRPC113() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testXMLRPC113(providers[i]);
- }
- }
-
-
- private void testXMLRPC112(ClientProvider pProvider) throws Exception {
- XmlRpcClient client = pProvider.getClient();
- client.setConfig(getConfig(pProvider));
- TimingOutCallback toc = new TimingOutCallback(5000);
- final String methodName = XMLRPC89Handler.class.getName() + ".reverse";
- client.executeAsync(methodName, new Object[]{new Object[]{"1", "2",
"3"}}, toc);
- Object o;
- try {
- o = toc.waitForResponse();
- } catch (Exception e) {
- throw e;
- } catch (Throwable t) {
- throw new UndeclaredThrowableException(t);
- }
- checkXMLRPC112Result(o);
- checkXMLRPC112Result(client.execute(methodName, new Object[]{new
Object[]{"1", "2", "3"}}));
- checkXMLRPC112Result(client.execute(methodName, new Object[]{new
Object[]{"1", "2", "3"}}));
- }
-
- private void checkXMLRPC112Result(Object pObject) {
- Object[] args = (Object[]) pObject;
- assertEquals(3, args.length);
- assertEquals("3", args[0]);
- assertEquals("2", args[1]);
- assertEquals("1", args[2]);
- }
-
- /**
- * Handler interface for [EMAIL PROTECTED] JiraTest#testXMLRPC113()}
- */
- public interface XMLRPC113Handler {
- /**
- * Throws an [EMAIL PROTECTED] XmlRpcException} with the given error
code.
- */
- Object throwCode(int pCode) throws XmlRpcException;
- }
-
- /**
- * Handler for [EMAIL PROTECTED] JiraTest#testXMLRPC113()}
- */
- public static class XMLRPC113HandlerImpl implements XMLRPC113Handler {
- public Object throwCode(int pCode) throws XmlRpcException {
- throw new XmlRpcException(pCode, "Message: " + pCode);
- }
- }
-
- private void testXMLRPC113(ClientProvider pProvider) throws Exception {
- XmlRpcClient client = pProvider.getClient();
- client.setConfig(getConfig(pProvider));
- XMLRPC113Handler handler = (XMLRPC113Handler) new
ClientFactory(client).newInstance(XMLRPC113Handler.class);
- for (int i = 0; i < 5; i++) {
- try {
- client.execute(XMLRPC113Handler.class.getName() +
".throwCode", new Object[]{new Integer(i)});
- fail("Excpected exception");
- } catch (XmlRpcException e) {
- assertEquals(i, e.code);
- }
- try {
- handler.throwCode(i);
- } catch (XmlRpcException e) {
- assertEquals(i, e.code);
- }
- }
- }
-
- /**
- * Handler for [EMAIL PROTECTED] JiraTest#testXMLRPC115()}
- */
- public static class XMLRPC115Handler {
- /**
- * Does nothing, just for checking, whether the server is alive.
- */
- public Object[] ping() {
- return new Object[0];
- }
- }
-
- /**
- * Test case for <a href="http://issues.apache.org/jira/browse/XMLRPC-115">
- * XMLRPC-115</a>
- */
- public void testXMLRPC115() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testXMLRPC115(providers[i]);
- }
- }
-
- private void testXMLRPC115(ClientProvider pProvider) throws Exception {
- if (pProvider instanceof SunHttpTransportProvider) {
- XmlRpcClient client = pProvider.getClient();
- client.setConfig(getConfig(pProvider));
- URL url = ((XmlRpcHttpClientConfig)
client.getConfig()).getServerURL();
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- conn.setDoInput(true);
- conn.setDoOutput(true);
- conn.setRequestMethod("POST");
- conn.setRequestProperty("content-type", "text/xml");
- OutputStream ostream = conn.getOutputStream();
- Writer w = new OutputStreamWriter(ostream, "UTF-8");
- w.write("<methodCall><methodName>" +
XMLRPC115Handler.class.getName() + ".ping"
- + "</methodName></methodCall>");
- w.close();
- InputStream istream = conn.getInputStream();
- XmlRpcResponseParser parser = new
XmlRpcResponseParser((XmlRpcStreamRequestConfig) client.getClientConfig(),
client.getTypeFactory());
- XMLReader xr = SAXParsers.newXMLReader();
- xr.setContentHandler(parser);
- xr.parse(new InputSource(istream));
- istream.close();
- assertTrue(parser.getResult() instanceof Object[]);
- assertEquals(0, ((Object[]) parser.getResult()).length);
- }
- }
-}
+/*
+ * Copyright 1999,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.xmlrpc.test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Vector;
+
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.client.TimingOutCallback;
+import org.apache.xmlrpc.client.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcHttpClientConfig;
+import org.apache.xmlrpc.client.util.ClientFactory;
+import org.apache.xmlrpc.common.XmlRpcStreamRequestConfig;
+import org.apache.xmlrpc.parser.XmlRpcResponseParser;
+import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
+import org.apache.xmlrpc.util.SAXParsers;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+
+
+/**
+ * Test case for various jira issues.
+ */
+public class JiraTest extends XmlRpcTestCase {
+ /** Interface of the handler for [EMAIL PROTECTED] JiraTest#testXMLRPC89()}
+ */
+ public interface XMLRPC89Handler {
+ /**
+ * Returns the reversed vector.
+ */
+ Vector reverse(Vector pVector);
+ /**
+ * Returns the same hashtable, but doubles the
+ * values.
+ */
+ Hashtable doubledValues(Hashtable pMap);
+ /**
+ * Returns the same properties, but doubles the
+ * values.
+ */
+ Properties doubledPropertyValues(Properties pMap);
+ }
+
+ /**
+ * Handler for [EMAIL PROTECTED] JiraTest#testXMLRPC89()}
+ */
+ public static class XMLRPC89HandlerImpl implements XMLRPC89Handler {
+ public Vector reverse(Vector pVector) {
+ Vector result = new Vector(pVector.size());
+ result.addAll(pVector);
+ Collections.reverse(result);
+ return result;
+ }
+ public Hashtable doubledValues(Hashtable pMap) {
+ final Hashtable result;
+ if (pMap instanceof Properties) {
+ result = new Properties();
+ } else {
+ result = new Hashtable();
+ }
+ result.putAll(pMap);
+ for (Iterator iter = result.entrySet().iterator();
iter.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ Object value = entry.getValue();
+ final Integer i;
+ if (pMap instanceof Properties) {
+ i = Integer.valueOf((String) value);
+ } else {
+ i = (Integer) value;
+ }
+ Integer iDoubled = new Integer(i.intValue()*2);
+ if (pMap instanceof Properties) {
+ entry.setValue(iDoubled.toString());
+ } else {
+ entry.setValue(iDoubled);
+ }
+ }
+ return result;
+ }
+ public Properties doubledPropertyValues(Properties pProperties) {
+ return (Properties) doubledValues(pProperties);
+ }
+ }
+
+ protected XmlRpcHandlerMapping getHandlerMapping() throws IOException,
+ XmlRpcException {
+ return getHandlerMapping("JiraTest.properties");
+ }
+
+ /**
+ * Test case for <a href="http://issues.apache.org/jira/browse/XMLRPC-89">
+ * XMLRPC-89</a>
+ */
+ public void testXMLRPC89() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testXMLRPC89Vector(providers[i]);
+ testXMLRPC89Hashtable(providers[i]);
+ testXMLRPC89Properties(providers[i]);
+ }
+ }
+
+ private void testXMLRPC89Vector(ClientProvider pProvider) throws Exception
{
+ Vector values = new Vector();
+ for (int i = 0; i < 3; i++) {
+ values.add(new Integer(i));
+ }
+ Vector params = new Vector();
+ params.add(values);
+ XmlRpcClient client = pProvider.getClient();
+ client.setConfig(getConfig(pProvider));
+ Object res = client.execute(XMLRPC89Handler.class.getName() +
".reverse", params);
+ Object[] result = (Object[]) res;
+ assertNotNull(result);
+ assertEquals(3, result.length);
+ for (int i = 0; i < 3; i++) {
+ assertEquals(new Integer(2-i), result[i]);
+ }
+
+ ClientFactory factory = new ClientFactory(client);
+ XMLRPC89Handler handler = (XMLRPC89Handler)
factory.newInstance(XMLRPC89Handler.class);
+ Vector resultVector = handler.reverse(values);
+ assertNotNull(resultVector);
+ assertEquals(3, resultVector.size());
+ for (int i = 0; i < 3; i++) {
+ assertEquals(new Integer(2-i), resultVector.get(i));
+ }
+ }
+
+ private void verifyXMLRPC89Hashtable(Map pMap) {
+ assertNotNull(pMap);
+ assertEquals(3, pMap.size());
+ for (int i = 0; i < 3; i++) {
+ Integer j = (Integer) pMap.get(String.valueOf(i));
+ assertEquals(i*2, j.intValue());
+ }
+ }
+
+ private void testXMLRPC89Hashtable(ClientProvider pProvider) throws
Exception {
+ Hashtable values = new Hashtable();
+ for (int i = 0; i < 3; i++) {
+ values.put(String.valueOf(i), new Integer(i));
+ }
+ XmlRpcClient client = pProvider.getClient();
+ client.setConfig(getConfig(pProvider));
+ Object res = client.execute(XMLRPC89Handler.class.getName() +
".doubledValues", new Object[]{values});
+ verifyXMLRPC89Hashtable((Map) res);
+
+ ClientFactory factory = new ClientFactory(client);
+ XMLRPC89Handler handler = (XMLRPC89Handler)
factory.newInstance(XMLRPC89Handler.class);
+ Hashtable result = handler.doubledValues(values);
+ verifyXMLRPC89Hashtable(result);
+ }
+
+ private void verifyXMLRPC89Properties(Map pMap) {
+ assertNotNull(pMap);
+ assertEquals(3, pMap.size());
+ for (int i = 0; i < 3; i++) {
+ String j = (String) pMap.get(String.valueOf(i));
+ assertEquals(i*2, Integer.parseInt(j));
+ }
+ }
+
+ private void testXMLRPC89Properties(ClientProvider pProvider) throws
Exception {
+ Properties values = new Properties();
+ for (int i = 0; i < 3; i++) {
+ values.put(String.valueOf(i), String.valueOf(i));
+ }
+ XmlRpcClient client = pProvider.getClient();
+ client.setConfig(getConfig(pProvider));
+ Object res = client.execute(XMLRPC89Handler.class.getName() +
".doubledPropertyValues", new Object[]{values});
+ verifyXMLRPC89Properties((Map) res);
+
+ ClientFactory factory = new ClientFactory(client);
+ XMLRPC89Handler handler = (XMLRPC89Handler)
factory.newInstance(XMLRPC89Handler.class);
+ Properties result = handler.doubledPropertyValues(values);
+ verifyXMLRPC89Properties(result);
+ }
+
+ /** Handler for XMLRPC-96
+ */
+ public static class XMLRPC96Handler {
+ /** Returns the "Hello, world!" string.
+ */
+ public String getHelloWorld() {
+ return "Hello, world!";
+ }
+ }
+
+ /**
+ * Test case for <a href="http://issues.apache.org/jira/browse/XMLRPC-96">
+ * XMLRPC-96</a>
+ */
+ public void testXMLRPC96() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testXMLRPC96(providers[i]);
+ }
+ }
+
+ private void testXMLRPC96(ClientProvider pProvider) throws Exception {
+ XmlRpcClient client = pProvider.getClient();
+ client.setConfig(getConfig(pProvider));
+ String s = (String) client.execute(XMLRPC96Handler.class.getName() +
".getHelloWorld", new Object[0]);
+ assertEquals("Hello, world!", s);
+ s = (String) client.execute(XMLRPC96Handler.class.getName() +
".getHelloWorld", (Object[]) null);
+ assertEquals("Hello, world!", s);
+ }
+
+ /**
+ * Test case for <a href="http://issues.apache.org/jira/browse/XMLRPC-112">
+ * XMLRPC-112</a>
+ */
+ public void testXMLRPC112() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testXMLRPC112(providers[i]);
+ }
+ }
+
+ /**
+ * Test case for <a href="http://issues.apache.org/jira/browse/XMLRPC-113">
+ * XMLRPC-113</a>
+ */
+ public void testXMLRPC113() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testXMLRPC113(providers[i]);
+ }
+ }
+
+
+ private void testXMLRPC112(ClientProvider pProvider) throws Exception {
+ XmlRpcClient client = pProvider.getClient();
+ client.setConfig(getConfig(pProvider));
+ TimingOutCallback toc = new TimingOutCallback(5000);
+ final String methodName = XMLRPC89Handler.class.getName() + ".reverse";
+ client.executeAsync(methodName, new Object[]{new Object[]{"1", "2",
"3"}}, toc);
+ Object o;
+ try {
+ o = toc.waitForResponse();
+ } catch (Exception e) {
+ throw e;
+ } catch (Throwable t) {
+ throw new UndeclaredThrowableException(t);
+ }
+ checkXMLRPC112Result(o);
+ checkXMLRPC112Result(client.execute(methodName, new Object[]{new
Object[]{"1", "2", "3"}}));
+ checkXMLRPC112Result(client.execute(methodName, new Object[]{new
Object[]{"1", "2", "3"}}));
+ }
+
+ private void checkXMLRPC112Result(Object pObject) {
+ Object[] args = (Object[]) pObject;
+ assertEquals(3, args.length);
+ assertEquals("3", args[0]);
+ assertEquals("2", args[1]);
+ assertEquals("1", args[2]);
+ }
+
+ /**
+ * Handler interface for [EMAIL PROTECTED] JiraTest#testXMLRPC113()}
+ */
+ public interface XMLRPC113Handler {
+ /**
+ * Throws an [EMAIL PROTECTED] XmlRpcException} with the given error
code.
+ */
+ Object throwCode(int pCode) throws XmlRpcException;
+ }
+
+ /**
+ * Handler for [EMAIL PROTECTED] JiraTest#testXMLRPC113()}
+ */
+ public static class XMLRPC113HandlerImpl implements XMLRPC113Handler {
+ public Object throwCode(int pCode) throws XmlRpcException {
+ throw new XmlRpcException(pCode, "Message: " + pCode);
+ }
+ }
+
+ private void testXMLRPC113(ClientProvider pProvider) throws Exception {
+ XmlRpcClient client = pProvider.getClient();
+ client.setConfig(getConfig(pProvider));
+ XMLRPC113Handler handler = (XMLRPC113Handler) new
ClientFactory(client).newInstance(XMLRPC113Handler.class);
+ for (int i = 0; i < 5; i++) {
+ try {
+ client.execute(XMLRPC113Handler.class.getName() +
".throwCode", new Object[]{new Integer(i)});
+ fail("Excpected exception");
+ } catch (XmlRpcException e) {
+ assertEquals(i, e.code);
+ }
+ try {
+ handler.throwCode(i);
+ } catch (XmlRpcException e) {
+ assertEquals(i, e.code);
+ }
+ }
+ }
+
+ /**
+ * Handler for [EMAIL PROTECTED] JiraTest#testXMLRPC115()}
+ */
+ public static class XMLRPC115Handler {
+ /**
+ * Does nothing, just for checking, whether the server is alive.
+ */
+ public Object[] ping() {
+ return new Object[0];
+ }
+ }
+
+ /**
+ * Test case for <a href="http://issues.apache.org/jira/browse/XMLRPC-115">
+ * XMLRPC-115</a>
+ */
+ public void testXMLRPC115() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testXMLRPC115(providers[i]);
+ }
+ }
+
+ private void testXMLRPC115(ClientProvider pProvider) throws Exception {
+ if (pProvider instanceof SunHttpTransportProvider) {
+ XmlRpcClient client = pProvider.getClient();
+ client.setConfig(getConfig(pProvider));
+ URL url = ((XmlRpcHttpClientConfig)
client.getConfig()).getServerURL();
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+ conn.setDoInput(true);
+ conn.setDoOutput(true);
+ conn.setRequestMethod("POST");
+ conn.setRequestProperty("content-type", "text/xml");
+ OutputStream ostream = conn.getOutputStream();
+ Writer w = new OutputStreamWriter(ostream, "UTF-8");
+ w.write("<methodCall><methodName>" +
XMLRPC115Handler.class.getName() + ".ping"
+ + "</methodName></methodCall>");
+ w.close();
+ InputStream istream = conn.getInputStream();
+ XmlRpcResponseParser parser = new
XmlRpcResponseParser((XmlRpcStreamRequestConfig) client.getClientConfig(),
client.getTypeFactory());
+ XMLReader xr = SAXParsers.newXMLReader();
+ xr.setContentHandler(parser);
+ xr.parse(new InputSource(istream));
+ istream.close();
+ assertTrue(parser.getResult() instanceof Object[]);
+ assertEquals(0, ((Object[]) parser.getResult()).length);
+ }
+ }
+
+ /**
+ * Test case for <a href="http://issues.apache.org/jira/browse/XMLRPC-119">
+ * XMLRPC-119</a>
+ */
+ public void testXMLRPC119() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testXMLRPC119(providers[i]);
+ }
+ }
+
+ /** Handler for XMLRPC-119
+ */
+ public static class XMLRPC119Handler {
+ /** Returns a string with a length of "num" Kilobytes.
+ */
+ public String getString(int pSize) {
+ StringBuffer sb = new StringBuffer(pSize*1024);
+ for (int i = 0; i < pSize*1024; i++) {
+ sb.append('&');
+ }
+ return sb.toString();
+ }
+ }
+
+ private void testXMLRPC119(ClientProvider pProvider) throws Exception {
+ XmlRpcClient client = pProvider.getClient();
+ client.setConfig(getConfig(pProvider));
+ for (int i = 0; i < 100; i+= 10) {
+ String s = (String)
client.execute(XMLRPC119Handler.class.getName() + ".getString", new
Object[]{new Integer(i)});
+ assertEquals(i*1024, s.length());
+ }
+ }
+}
Modified:
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/ParserTest.java
URL:
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/ParserTest.java?view=diff&rev=468143&r1=468142&r2=468143
==============================================================================
---
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/ParserTest.java
(original)
+++
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/ParserTest.java
Thu Oct 26 14:26:38 2006
@@ -1,9 +1,9 @@
package org.apache.xmlrpc.test;
-import java.io.File;
import java.io.IOException;
import java.io.StringReader;
-import java.util.Map;
+
+import javax.xml.parsers.SAXParserFactory;
import junit.framework.TestCase;
@@ -27,10 +27,6 @@
private Object parseResponse(final String s) throws XmlRpcException,
IOException, SAXException {
return parseResponse(new InputSource(new StringReader(s)));
}
-
- private Object parseResponse(final File f) throws XmlRpcException,
IOException, SAXException {
- return parseResponse(new
InputSource(f.toURI().toURL().toExternalForm()));
- }
private Object parseResponse(InputSource isource) throws XmlRpcException,
IOException, SAXException {
Modified:
webservices/xmlrpc/trunk/tests/src/test/resources/org/apache/xmlrpc/test/JiraTest.properties
URL:
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/tests/src/test/resources/org/apache/xmlrpc/test/JiraTest.properties?view=diff&rev=468143&r1=468142&r2=468143
==============================================================================
---
webservices/xmlrpc/trunk/tests/src/test/resources/org/apache/xmlrpc/test/JiraTest.properties
(original)
+++
webservices/xmlrpc/trunk/tests/src/test/resources/org/apache/xmlrpc/test/JiraTest.properties
Thu Oct 26 14:26:38 2006
@@ -1,4 +1,5 @@
-org.apache.xmlrpc.test.JiraTest$XMLRPC89Handler=org.apache.xmlrpc.test.JiraTest$XMLRPC89HandlerImpl
-org.apache.xmlrpc.test.JiraTest$XMLRPC96Handler=org.apache.xmlrpc.test.JiraTest$XMLRPC96Handler
-org.apache.xmlrpc.test.JiraTest$XMLRPC113Handler=org.apache.xmlrpc.test.JiraTest$XMLRPC113HandlerImpl
-org.apache.xmlrpc.test.JiraTest$XMLRPC115Handler=org.apache.xmlrpc.test.JiraTest$XMLRPC115Handler
+org.apache.xmlrpc.test.JiraTest$XMLRPC89Handler=org.apache.xmlrpc.test.JiraTest$XMLRPC89HandlerImpl
+org.apache.xmlrpc.test.JiraTest$XMLRPC96Handler=org.apache.xmlrpc.test.JiraTest$XMLRPC96Handler
+org.apache.xmlrpc.test.JiraTest$XMLRPC113Handler=org.apache.xmlrpc.test.JiraTest$XMLRPC113HandlerImpl
+org.apache.xmlrpc.test.JiraTest$XMLRPC115Handler=org.apache.xmlrpc.test.JiraTest$XMLRPC115Handler
+org.apache.xmlrpc.test.JiraTest$XMLRPC119Handler=org.apache.xmlrpc.test.JiraTest$XMLRPC119Handler