[axmlrpc] 01/08: Imported Upstream version 1.9.0

Guillaume Turri gturri-guest at moszumanska.debian.org
Tue Apr 12 20:08:48 UTC 2016


This is an automated email from the git hooks/post-receive script.

gturri-guest pushed a commit to annotated tag debian/1.9.0-1
in repository axmlrpc.

commit 4be2b9c68c2b8a5eb283baec6678fe9ea68c1c52
Author: Guillaume Turri <guillaume.turri at gmail.com>
Date:   Tue Apr 12 21:42:16 2016 +0200

    Imported Upstream version 1.9.0
---
 .gitignore                                         |   3 +
 .travis.yml                                        |   1 +
 Changelog                                          |   9 +
 README.md                                          |  89 ++------
 build.gradle                                       |  50 -----
 pom.xml                                            | 248 +++++++++++++++++++++
 settings.gradle                                    |   1 -
 src/main/java/de/timroes/axmlrpc/Call.java         |  10 +-
 .../java/de/timroes/axmlrpc/ResponseParser.java    |  33 ++-
 src/main/java/de/timroes/axmlrpc/XMLRPCClient.java |  14 +-
 .../axmlrpc/serializer/DateTimeSerializer.java     |  24 +-
 .../de/timeroes/axmlrpc/TestResponseParser.java    |  68 ++++++
 src/test/java/de/timeroes/base64/TestBase64.java   |  24 ++
 .../axmlrpc/serializer/TestDateTimeSerializer.java | 129 +++++++++--
 .../axmlrpc/serializer/TestSerializers.java        |  62 ++++++
 15 files changed, 592 insertions(+), 173 deletions(-)

diff --git a/.gitignore b/.gitignore
index 5e36154..2938b43 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,6 @@ build/
 dist/
 .gradle/
 /.nb-gradle/private/
+target
+.classpath
+.project
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..dff5f3a
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1 @@
+language: java
diff --git a/Changelog b/Changelog
new file mode 100644
index 0000000..2c43402
--- /dev/null
+++ b/Changelog
@@ -0,0 +1,9 @@
+Add FLAGS_DEBUG to display the xml returned by the server
+
+1.8.3
+Fix compatibility with Android
+
+1.8.2
+
+Forking from timroes project. The only purpose of this version is to have
+the fix from 1.8.1 in maven central
diff --git a/README.md b/README.md
index 34e7a2f..2e0b96f 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ How to include it?
 ==================
 
 How to include the aXMLRPC client into your project?
-There are four different ways to do that:
+There are several ways to do that:
 
 ### Include the source code
 
@@ -26,9 +26,9 @@ as a module to yours. So you will always stay up to date with the library.
 
 ### Compile it as library
 
-aXMLRPC uses gradle, so you can build it using
+aXMLRPC uses maven, so you can build it using
 
-    ./gradlew jar
+    mvn install
 
 ### Use Maven
 
@@ -36,7 +36,7 @@ To use it on your Maven project, add it as a dependency on your pom.xml file:
 
 ```xml
 <dependency>
-    <groupId>de.timroes</groupId>
+    <groupId>fr.turri</groupId>
     <artifactId>aXMLRPC</artifactId>
     <version>X.Y.Z</version>
 </dependency>
@@ -44,77 +44,6 @@ To use it on your Maven project, add it as a dependency on your pom.xml file:
 
 where X.Y.Z is the current aXMLRPC version
 
-### Download the JAR library
-
-You can download a compiled jar file from the below list and use it as a library
-for your project.
-
-[aXMLRPC v1.7.2](https://dl.dropbox.com/u/56970236/aXMLRPC/aXMLRPC_v1.7.2.jar)
-
-  * Bugfix in double representation
-  * Allow usage of any Iterable for array parameters
-  * Allow usage of BigDecimal as double parameters
-
-[aXMLRPC v1.7.1](https://dl.dropbox.com/u/56970236/aXMLRPC/aXMLRPC_v1.7.1.jar)
-
-  * Bugfix in String escaping (New default behavior: Escape Strings according to spec)
-  * Bugfix in Float encoding
-
-[aXMLRPC v1.7.0](https://dl.dropbox.com/u/56970236/aXMLRPC/aXMLRPC_v1.7.0.jar)
-  
-  * Added funtionality for custom TrustManagers
-
-[aXMLRPC v1.6.0](https://dl.dropbox.com/u/56970236/aXMLRPC/aXMLRPC_v1.6.0.jar)
-
-  * Added support for timeout
-  * Minor code improvements
-
-[aXMLRPC v1.5.0](https://dl.dropbox.com/u/56970236/aXMLRPC/aXMLRPC_v1.5.0.jar)
-  
-  * Added Proxy Support
-  * Fixed #13, Support for cookie reading
-
-[aXMLRPC v1.4.0](https://dl.dropbox.com/u/56970236/aXMLRPC/aXMLRPC_v1.4.0.jar)
-
-  * Added FLAGS_IGNORE_NAMESPACE, FLAGS_DEFAULT_TYPE_STRING
-
-[aXMLRPC v1.3.5](https://dl.dropbox.com/u/56970236/aXMLRPC/aXMLRPC_v1.3.5.jar)
-
-  * Fixed bug in canceling async calls
-
-[aXMLRPC v1.3.4](https://dl.dropbox.com/u/56970236/aXMLRPC/aXMLRPC_v1.3.4.jar)
-
-  * Added getURL-method
-  * Added FLAGS_IGNORE_SSL_ERRORS
-  * Removed debugging information from JAR
-
-[aXMLRPC v1.3.3](https://dl.dropbox.com/u/56970236/aXMLRPC/aXMLRPC_v1.3.3.jar)
-
-  * Improved handling of 40X http errors
-
-[aXMLRPC v1.3.2](https://dl.dropbox.com/u/56970236/aXMLRPC/aXMLRPC_v1.3.2.jar)
-
-  * Fixed handling of 40x http errors
-
-[aXMLRPC v1.3.1](https://dl.dropbox.com/u/56970236/aXMLRPC/aXMLRPC_v1.3.1.jar)
-
-  * Fixed bug in XML struct creation
-  * Method to clear HTTP basic auth login data
-
-[aXMLRPC v1.3.0](https://dl.dropbox.com/u/56970236/aXMLRPC/aXMLRPC_v1.3.0.jar)
-
-  * Flags to ignore SSL warnings
-  * HTTP forwarding
-  * Improved code quality
-
-**Real old versions:**
-
-  * [aXMLRPC v1.2.0](https://dl.dropbox.com/u/56970236/aXMLRPC/aXMLRPC_v1.2.0.jar)
-  * [aXMLRPC v1.1.0](https://dl.dropbox.com/u/56970236/aXMLRPC/aXMLRPC_v1.1.0.jar)
-  * [aXMLRPC v1.0.3](https://dl.dropbox.com/u/56970236/aXMLRPC/aXMLRPC_v1.0.3.jar)
-  * [aXMLRPC v1.0.2](https://dl.dropbox.com/u/56970236/aXMLRPC/aXMLRPC_v1.0.2.jar)
-  * [aXMLRPC v1.0.1](https://dl.dropbox.com/u/56970236/aXMLRPC/aXMLRPC_v1.0.1.jar)
-
 
 How to use the library?
 =======================
@@ -314,6 +243,10 @@ This prevents the decoding of incoming strings, meaning `&` and `<`
 won't be decoded to the & sign and the "less then" sign. See
 `FLAGS_NO_STRING_ENCODE` for the counterpart.
 
+#### FLAGS_DEBUG
+Will display additional information on the console.
+Do not use it in production.
+
 Meta Flags
 ----------
 
@@ -355,4 +288,8 @@ Bugs?
 =====
 
 If you find a bug or wish some enhancements for the library, please
-fill an issue here on github or contact me otherwise (www.timroes.de).
+fill an issue here on github.
+
+Build status
+============
+Status: ![Status](https://travis-ci.org/gturri/aXMLRPC.svg?branch=master)
diff --git a/build.gradle b/build.gradle
deleted file mode 100644
index 92c0363..0000000
--- a/build.gradle
+++ /dev/null
@@ -1,50 +0,0 @@
-plugins {
-	id "com.jfrog.bintray" version "1.3.1"
-}
-
-apply plugin: 'java'
-apply plugin: 'maven'
-apply plugin: 'signing'
-
-version = '1.8.1'
-group = 'de.timroes'
-
-task sourcesJar(type: Jar, dependsOn: classes) {
-	classifier = 'sources'
-	from sourceSets.main.allSource
-}
-
-task javadocJar(type: Jar, dependsOn: javadoc) {
-	classifier = 'javadoc'
-	from javadoc.destinationDir
-}
-
-artifacts {
-	archives sourcesJar
-	archives javadocJar
-}
-
-repositories {
-	mavenLocal()
-	mavenCentral()
-}
-
-dependencies {
-	testCompile "junit:junit:4.12"
-}
-
-bintray {
-	user = project.properties['bintray.user']
-	key = project.properties['bintray.key']
-	configurations = ['archives']
-	pkg {
-		repo = 'maven'
-		name = 'aXMLRPC'
-		userOrg = project.properties['bintray.user']
-		licenses = ['MIT']
-		vcsUrl = 'https://github.com/timroes/aXMLRPC.git'
-		version {
-			name = project.version
-		}
-	}
-}
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..798b3d4
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,248 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>fr.turri</groupId>
+	<artifactId>aXMLRPC</artifactId>
+	<version>1.9.0</version>
+	<packaging>jar</packaging>
+	<name>aXMLRPC</name>
+	<description>Lightweight Java XML-RPC working also on Android.</description>
+	<url>https://github.com/gturri/aXMLRPC</url>
+    <properties>
+      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+      <maven.compiler.source>1.7</maven.compiler.source>
+      <maven.compiler.target>1.7</maven.compiler.target>
+    </properties>
+	<licenses>
+		<license>
+			<name>The MIT License (MIT)</name>
+		</license>
+	</licenses>
+	<developers>
+		<developer>
+			<id>timroes</id>
+			<name>Tim Roes</name>
+			<email>mail at timroes.de</email>
+		</developer>
+		<developer>
+			<id>gturri</id>
+			<name>Guillaume Turri</name>
+			<email>guillaume.turri at gmail.com</email>
+		</developer>
+	</developers>
+	<dependencies>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.12</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>fr.turri</groupId>
+			<artifactId>jISO8601</artifactId>
+			<version>0.2</version>
+		</dependency>
+        <dependency>
+          <groupId>com.github.tomakehurst</groupId>
+          <artifactId>wiremock</artifactId>
+          <version>1.58</version>
+          <scope>test</scope>
+          <classifier>standalone</classifier>
+          <exclusions>
+            <exclusion>
+              <groupId>org.mortbay.jetty</groupId>
+              <artifactId>jetty</artifactId>
+            </exclusion>
+            <exclusion>
+              <groupId>com.google.guava</groupId>
+              <artifactId>guava</artifactId>
+            </exclusion>
+            <exclusion>
+              <groupId>com.fasterxml.jackson.core</groupId>
+              <artifactId>jackson-core</artifactId>
+            </exclusion>
+            <exclusion>
+              <groupId>com.fasterxml.jackson.core</groupId>
+              <artifactId>jackson-annotations</artifactId>
+            </exclusion>
+            <exclusion>
+              <groupId>com.fasterxml.jackson.core</groupId>
+              <artifactId>jackson-databind</artifactId>
+            </exclusion>
+            <exclusion>
+              <groupId>org.apache.httpcomponents</groupId>
+              <artifactId>httpclient</artifactId>
+            </exclusion>
+            <exclusion>
+              <groupId>org.skyscreamer</groupId>
+              <artifactId>jsonassert</artifactId>
+            </exclusion>
+            <exclusion>
+              <groupId>xmlunit</groupId>
+              <artifactId>xmlunit</artifactId>
+            </exclusion>
+            <exclusion>
+              <groupId>com.jayway.jsonpath</groupId>
+              <artifactId>json-path</artifactId>
+            </exclusion>
+            <exclusion>
+              <groupId>net.sf.jopt-simple</groupId>
+              <artifactId>jopt-simple</artifactId>
+            </exclusion>
+          </exclusions>
+        </dependency>
+	</dependencies>
+	<scm>
+        <connection>scm:git:https://github.com/gturri/aXMLRPC.git</connection>
+        <developerConnection>scm:git:git at github.com:gturri/aXMLRPC.git</developerConnection>
+        <url>https://github.com/gturri/aXMLRPC</url>
+        <tag>aXMLRPC-1.9.0</tag>
+	</scm>
+    <build>
+      <pluginManagement>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-release-plugin</artifactId>
+            <version>2.5.3</version>
+            <configuration>
+              <useReleaseProfile>false</useReleaseProfile>
+              <releaseProfiles>release</releaseProfiles>
+              <goals>deploy</goals>
+            </configuration>
+          </plugin>
+        </plugins>
+      </pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-jar-plugin</artifactId>
+          <version>2.6</version>
+          <configuration>
+            <archive>
+              <manifest>
+                <addClasspath>true</addClasspath>
+              </manifest>
+            </archive>
+          </configuration>
+        </plugin>
+        <plugin>
+          <groupId>org.sonatype.plugins</groupId>
+          <artifactId>nexus-staging-maven-plugin</artifactId>
+          <version>1.6.7</version>
+          <extensions>true</extensions>
+          <configuration>
+            <serverId>ossrh</serverId>
+            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
+            <autoReleaseAfterClose>true</autoReleaseAfterClose>
+          </configuration>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-javadoc-plugin</artifactId>
+          <version>2.10.3</version>
+          <executions>
+            <execution>
+              <id>attach-javadocs</id>
+              <goals>
+                <goal>jar</goal>
+              </goals>
+            </execution>
+          </executions>
+        </plugin>
+    </plugins>
+    </build>
+    <reporting>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-surefire-report-plugin</artifactId>
+          <version>2.19.1</version>
+        </plugin>
+        <plugin>
+          <groupId>org.codehaus.mojo</groupId>
+          <artifactId>cobertura-maven-plugin</artifactId>
+          <version>2.7</version>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-javadoc-plugin</artifactId>
+          <version>2.10.3</version>
+          <reportSets>
+            <reportSet>
+              <reports>
+                <report>javadoc</report>
+              </reports>
+              <configuration>
+                <destDir>doc-${project.version}</destDir>
+              </configuration>
+            </reportSet>
+          </reportSets>
+        </plugin>
+        <plugin>
+          <groupId>org.codehaus.mojo</groupId>
+          <artifactId>findbugs-maven-plugin</artifactId>
+          <version>3.0.3</version>
+        </plugin>
+      </plugins>
+    </reporting>
+    <profiles>
+      <profile>
+        <id>release</id>
+        <build>
+          <plugins>
+            <plugin>
+              <groupId>org.apache.maven.plugins</groupId>
+              <artifactId>maven-source-plugin</artifactId>
+              <version>3.0.0</version>
+              <executions>
+                <execution>
+                  <id>attach-sources</id>
+                  <goals>
+                    <goal>jar-no-fork</goal>
+                  </goals>
+                </execution>
+              </executions>
+            </plugin>
+            <plugin>
+              <groupId>org.apache.maven.plugins</groupId>
+              <artifactId>maven-javadoc-plugin</artifactId>
+              <version>2.10.3</version>
+              <executions>
+                <execution>
+                  <id>attach-javadocs</id>
+                  <goals>
+                    <goal>jar</goal>
+                  </goals>
+                </execution>
+              </executions>
+            </plugin>
+            <plugin>
+              <groupId>org.apache.maven.plugins</groupId>
+              <artifactId>maven-gpg-plugin</artifactId>
+              <version>1.6</version>
+              <executions>
+                <execution>
+                  <id>sign-artifacts</id>
+                  <phase>verify</phase>
+                  <goals>
+                    <goal>sign</goal>
+                  </goals>
+                </execution>
+              </executions>
+            </plugin>
+          </plugins>
+        </build>
+      </profile>
+    </profiles>
+    <distributionManagement>
+      <snapshotRepository>
+        <id>ossrh</id>
+        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+      </snapshotRepository>
+      <repository>
+        <id>ossrh</id>
+        <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
+      </repository>
+    </distributionManagement>
+</project>
diff --git a/settings.gradle b/settings.gradle
deleted file mode 100644
index 5d76855..0000000
--- a/settings.gradle
+++ /dev/null
@@ -1 +0,0 @@
-rootProject.name = 'aXMLRPC'
diff --git a/src/main/java/de/timroes/axmlrpc/Call.java b/src/main/java/de/timroes/axmlrpc/Call.java
index de393ec..ff8ec2b 100644
--- a/src/main/java/de/timroes/axmlrpc/Call.java
+++ b/src/main/java/de/timroes/axmlrpc/Call.java
@@ -45,7 +45,7 @@ public class Call {
 	 * 		be build without errors.
 	 * @see XMLRPCClient
 	 */
-	public String getXML() throws XMLRPCException {
+	public String getXML(boolean debugMode) throws XMLRPCException {
 
 		SimpleXMLCreator creator = new SimpleXMLCreator();
 
@@ -65,7 +65,13 @@ public class Call {
 			}
 		}
 
-		return creator.toString();
+		String result = creator.toString();
+
+		if ( debugMode){
+			System.out.println(result);
+		}
+
+		return result;
 	}
 
 	/**
diff --git a/src/main/java/de/timroes/axmlrpc/ResponseParser.java b/src/main/java/de/timroes/axmlrpc/ResponseParser.java
index b096896..f9e3bd0 100644
--- a/src/main/java/de/timroes/axmlrpc/ResponseParser.java
+++ b/src/main/java/de/timroes/axmlrpc/ResponseParser.java
@@ -1,10 +1,22 @@
 package de.timroes.axmlrpc;
 
 import de.timroes.axmlrpc.serializer.SerializerHandler;
+
+import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
 import java.util.Map;
+
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -27,7 +39,7 @@ class ResponseParser {
 	 * @throws XMLRPCException Will be thrown whenever something fails.
 	 * @throws XMLRPCServerException Will be thrown, if the server returns an error.
 	 */
-	public Object parse(InputStream response) throws XMLRPCException {
+	public Object parse(InputStream response, boolean debugMode) throws XMLRPCException {
 
 		try {
 
@@ -35,8 +47,12 @@ class ResponseParser {
 			factory.setNamespaceAware(true);
 			DocumentBuilder builder = factory.newDocumentBuilder();
 			Document dom = builder.parse(response);
+			if (debugMode ){
+				printDocument(dom, System.out);
+			}
 			Element e = dom.getDocumentElement();
 
+
 			// Check for root tag
 			if(!e.getNodeName().equals(XMLRPCClient.METHOD_RESPONSE)) {
 				throw new XMLRPCException("MethodResponse root tag is missing.");
@@ -76,10 +92,23 @@ class ResponseParser {
 
 	}
 
+	public static void printDocument(Document doc, OutputStream out) throws IOException, TransformerException {
+		TransformerFactory tf = TransformerFactory.newInstance();
+		Transformer transformer = tf.newTransformer();
+		transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
+		transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+		transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+		transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+		transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
+
+		transformer.transform(new DOMSource(doc),
+				new StreamResult(new OutputStreamWriter(out, "UTF-8")));
+	}
+
 	/**
 	 * This method takes an element (must be a param or fault element) and
 	 * returns the deserialized object of this param tag.
-	 * 
+	 *
 	 * @param element An param element.
 	 * @return The deserialized object within the given param element.
 	 * @throws XMLRPCException Will be thrown when the structure of the document
diff --git a/src/main/java/de/timroes/axmlrpc/XMLRPCClient.java b/src/main/java/de/timroes/axmlrpc/XMLRPCClient.java
index d07332a..cc7dc00 100644
--- a/src/main/java/de/timroes/axmlrpc/XMLRPCClient.java
+++ b/src/main/java/de/timroes/axmlrpc/XMLRPCClient.java
@@ -152,6 +152,12 @@ public class XMLRPCClient {
 	public static final int FLAGS_NO_STRING_ENCODE = 0x1000;
 
 	/**
+	 * Activate debug mode.
+	 * Do NOT use if you don't need it.
+	 */
+	public static final int FLAGS_DEBUG = 0x2000;
+
+	/**
 	 * This flag disables all SSL warnings. It is an alternative to use
 	 * FLAGS_SSL_IGNORE_INVALID_CERT | FLAGS_SSL_IGNORE_INVALID_HOST. There
 	 * is no functional difference.
@@ -286,7 +292,7 @@ public class XMLRPCClient {
 	/**
 	 * Sets the time in seconds after which a call should timeout.
 	 * If {@code timeout} will be zero or less the connection will never timeout.
-	 * In case the connection times out and {@link XMLRPCTimeoutException} will
+	 * In case the connection times out an {@link XMLRPCTimeoutException} will
 	 * be thrown for calls made by {@link #call(java.lang.String, java.lang.Object[])}.
 	 * For calls made by {@link #callAsync(de.timroes.axmlrpc.XMLRPCCallback, java.lang.String, java.lang.Object[])}
 	 * the {@link XMLRPCCallback#onError(long, de.timroes.axmlrpc.XMLRPCException)} method
@@ -311,7 +317,7 @@ public class XMLRPCClient {
 
 	/**
 	 * Sets a proxy to use for this client. If you want to use the system proxy,
-	 * use {@link #FLAGS_adbUSE_SYSTEM_PROXY} instead. If combined with
+	 * use {@link #FLAGS_USE_SYSTEM_PROXY} instead. If combined with
 	 * {@code FLAGS_USE_SYSTEM_PROXY}, this proxy will be used instead of the
 	 * system proxy.
 	 *
@@ -650,7 +656,7 @@ public class XMLRPCClient {
 				cookieManager.setCookies(http);
 
 				OutputStreamWriter stream = new OutputStreamWriter(http.getOutputStream());
-				stream.write(c.getXML());
+				stream.write(c.getXML(isFlagSet(FLAGS_DEBUG)));
 				stream.flush();
 				stream.close();
 
@@ -735,7 +741,7 @@ public class XMLRPCClient {
 
 				cookieManager.readCookies(http);
 
-				return responseParser.parse(istream);
+				return responseParser.parse(istream, isFlagSet(FLAGS_DEBUG));
 
 			} catch(SocketTimeoutException ex) {
 				throw new XMLRPCTimeoutException("The XMLRPC call timed out.");
diff --git a/src/main/java/de/timroes/axmlrpc/serializer/DateTimeSerializer.java b/src/main/java/de/timroes/axmlrpc/serializer/DateTimeSerializer.java
index b1410c0..009251a 100644
--- a/src/main/java/de/timroes/axmlrpc/serializer/DateTimeSerializer.java
+++ b/src/main/java/de/timroes/axmlrpc/serializer/DateTimeSerializer.java
@@ -1,14 +1,13 @@
 package de.timroes.axmlrpc.serializer;
 
 import java.text.SimpleDateFormat;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
 import org.w3c.dom.Element;
 
 import de.timroes.axmlrpc.XMLRPCException;
 import de.timroes.axmlrpc.XMLUtil;
 import de.timroes.axmlrpc.xmlcreator.XmlElement;
+import fr.turri.jiso8601.Iso8601Deserializer;
 
 /**
  *
@@ -16,10 +15,8 @@ import de.timroes.axmlrpc.xmlcreator.XmlElement;
  */
 public class DateTimeSerializer implements Serializer {
 
-	private static final String DATETIME_FORMAT = "yyyyMMdd'T'HH:mm:ss";
+	private static final String DATETIME_FORMAT = "yyyyMMdd'T'HHmmss";
 	private static final SimpleDateFormat DATE_FORMATER = new SimpleDateFormat(DATETIME_FORMAT);
-	private static final Pattern PATTERN_WITHOUT_COLON = Pattern.compile("(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\+\\d{2})(\\d{2})");
-	private static final Pattern PATTERN_LEGACY = Pattern.compile("(\\d{4})(\\d{2})(\\d{2}T\\d{2}:\\d{2}:\\d{2})");
 
 	@Override
 	public Object deserialize(Element content) throws XMLRPCException {
@@ -28,27 +25,12 @@ public class DateTimeSerializer implements Serializer {
 
 	public Object deserialize(String dateStr) throws XMLRPCException {
 		try {
-			String value = formatStringIfNeeded(dateStr);
-			return javax.xml.bind.DatatypeConverter.parseDateTime(value).getTime();
+			return Iso8601Deserializer.toDate(dateStr);
 		} catch (Exception ex) {
 			throw new XMLRPCException("Unable to parse given date.", ex);
 		}
 	}
 
-	private static String formatStringIfNeeded(String dateStr){
-		Matcher matcherWithoutColon = PATTERN_WITHOUT_COLON.matcher(dateStr);
-		if ( matcherWithoutColon.matches() ){
-			return matcherWithoutColon.group(1) + ":" + matcherWithoutColon.group(2);
-		}
-
-		Matcher matcherLegacy = PATTERN_LEGACY.matcher(dateStr);
-		if ( matcherLegacy.matches() ){
-			return matcherLegacy.group(1) + "-" + matcherLegacy.group(2) + "-" + matcherLegacy.group(3);
-		}
-
-		return dateStr;
-	}
-
 	@Override
 	public XmlElement serialize(Object object) {
 		return XMLUtil.makeXmlTag(SerializerHandler.TYPE_DATETIME,
diff --git a/src/test/java/de/timeroes/axmlrpc/TestResponseParser.java b/src/test/java/de/timeroes/axmlrpc/TestResponseParser.java
new file mode 100644
index 0000000..a0292d4
--- /dev/null
+++ b/src/test/java/de/timeroes/axmlrpc/TestResponseParser.java
@@ -0,0 +1,68 @@
+package de.timeroes.axmlrpc;
+
+import java.net.URL;
+
+import org.junit.Test;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.*;
+import static org.junit.Assert.*;
+
+import org.junit.Rule;
+
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+
+import de.timroes.axmlrpc.XMLRPCClient;
+
+public class TestResponseParser {
+	private final int port = 8080;
+	private final String endPoint = "/dummyEndPoint";
+
+	@Rule
+	public WireMockRule wireMockRule = new WireMockRule(port);
+
+	@Test
+	public void canParseString() throws Exception {
+		setMockWithXmlRpcContent("<value><string>toto</string></value>");
+		assertEquals("toto", makeDummyCall());
+	}
+
+	@Test
+	public void canParseAsStringWhenTypeIsntExplicitelyProvided() throws Exception {
+		setMockWithXmlRpcContent("<value>toto</value>");
+		assertEquals("toto", makeDummyCall(XMLRPCClient.FLAGS_DEFAULT_TYPE_STRING));
+	}
+
+	@Test
+	public void canParseInt() throws Exception {
+		setMockWithXmlRpcContent("<value><i4>32</i4></value>");
+		assertEquals(32, makeDummyCall());
+
+		setMockWithXmlRpcContent("<value><int>33</int></value>");
+		assertEquals(33, makeDummyCall());
+	}
+
+	@Test
+	public void canParseBoolean() throws Exception {
+		setMockWithXmlRpcContent("<value><boolean>1</boolean></value>");
+		assertEquals(true, makeDummyCall());
+
+		setMockWithXmlRpcContent("<value><boolean>0</boolean></value>");
+		assertEquals(false, makeDummyCall());
+	}
+
+	private void setMockWithXmlRpcContent(String content){
+		stubFor(post(urlEqualTo(endPoint))
+				.willReturn(aResponse()
+						.withStatus(200)
+						.withBody("<methodResponse><params><param>" + content + "</param></params></methodResponse>")
+						));
+	}
+
+	private Object makeDummyCall() throws Exception {
+		return makeDummyCall(XMLRPCClient.FLAGS_NONE);
+	}
+
+	private Object makeDummyCall(int flags) throws Exception {
+		return new XMLRPCClient(new URL("http://localhost:" + port + endPoint), flags).call("dummy_method");
+	}
+}
diff --git a/src/test/java/de/timeroes/base64/TestBase64.java b/src/test/java/de/timeroes/base64/TestBase64.java
new file mode 100644
index 0000000..02dafeb
--- /dev/null
+++ b/src/test/java/de/timeroes/base64/TestBase64.java
@@ -0,0 +1,24 @@
+package de.timeroes.base64;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+import de.timroes.base64.Base64;
+
+public class TestBase64 {
+
+	@Test
+	public void canEncode(){
+		assertEquals("TWFu", Base64.encode("Man"));
+		assertEquals("TWE=", Base64.encode("Ma"));
+		assertEquals("TQ==", Base64.encode("M"));
+	}
+
+	@Test
+	public void canDecode(){
+		assertEquals("Man", Base64.decodeAsString("TWFu"));
+		assertEquals("Ma", Base64.decodeAsString("TWE="));
+		assertEquals("M", Base64.decodeAsString("TQ=="));
+	}
+}
diff --git a/src/test/java/de/timroes/axmlrpc/serializer/TestDateTimeSerializer.java b/src/test/java/de/timroes/axmlrpc/serializer/TestDateTimeSerializer.java
index fce8b13..67dff3f 100644
--- a/src/test/java/de/timroes/axmlrpc/serializer/TestDateTimeSerializer.java
+++ b/src/test/java/de/timroes/axmlrpc/serializer/TestDateTimeSerializer.java
@@ -1,33 +1,128 @@
 package de.timroes.axmlrpc.serializer;
 
 import static org.junit.Assert.*;
+import org.junit.*;
 
 import java.util.Date;
+import java.util.TimeZone;
 
 public class TestDateTimeSerializer {
-	private static final Date EXPECTED_DATE = new Date(85, 2, 4, 12, 13, 14);
+	private TimeZone _previousTZ;
 
-	@org.junit.Test
-	public void canParseLegacyDates() throws Exception {
-		Date date = (Date) new DateTimeSerializer().deserialize("19850304T12:13:14");
-		assertDatesCloseEnough(EXPECTED_DATE, date);
+	@Before
+	public void setUp(){
+		_previousTZ = TimeZone.getDefault();
+		TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
 	}
 
-	@org.junit.Test
-	public void canParseDateWithoutSemiColon() throws Exception {
-		Date date = (Date) new DateTimeSerializer().deserialize("1985-03-04T12:13:14+0100");
-		assertDatesCloseEnough(EXPECTED_DATE, date);
+	@After
+	public void tearDown(){
+		TimeZone.setDefault(_previousTZ);
 	}
 
-	@org.junit.Test
-	public void canParseDateWithSemiColon() throws Exception {
-		Date date = (Date) new DateTimeSerializer().deserialize("1985-03-04T12:13:14+01:00");
-		assertDatesCloseEnough(EXPECTED_DATE, date);
+	@Test
+	public void canParseBasicFormatDate() throws Exception {
+		assertDeserializeEquals(new Date(85, 2, 4), "19850304");
 	}
 
-	//Because I don't want the tests to fail if the user isn't in my timezone
-	private void assertDatesCloseEnough(Date expected, Date actual){
-		long differenceInMs = Math.abs(expected.getTime() - actual.getTime());
-		assertTrue(differenceInMs < 24 * 60 * 60 * 1000);
+	@Test
+	public void canParseExtendedFormatDate() throws Exception {
+		assertDeserializeEquals(new Date(85, 2, 4), "1985-03-04");
+	}
+
+	@Test
+	public void canParseDateWithoutDay() throws Exception {
+		assertDeserializeEquals(new Date(85, 2, 1), "1985-03");
+	}
+
+	@Test
+	public void canParseDateWithoutMonth() throws Exception {
+		assertDeserializeEquals(new Date(85, 0, 1), "1985");
+	}
+
+	@Test
+	public void canParseBasicFormatHour() throws Exception {
+		assertDeserializeEquals(new Date(85, 2, 4, 12, 21, 36), "19850304T122136");
+	}
+
+	@Test
+	public void canParseExtendedFormatHour() throws Exception {
+		assertDeserializeEquals(new Date(85, 2, 4, 12, 21, 36), "1985-03-04T12:21:36");
+	}
+
+	@Test
+	public void canParseHourWithoutMinute() throws Exception {
+		assertDeserializeEquals(new Date(85, 2, 4, 12, 0), "1985-03-04T12");
+	}
+
+	@Test
+	public void canParseHourWithoutSecond() throws Exception {
+		assertDeserializeEquals(new Date(85, 2, 4, 12, 10), "1985-03-04T12:10");
+	}
+
+	@Test
+	public void canParseDecimalPartOfAMinute() throws Exception {
+		assertDeserializeEquals(new Date(85, 2, 4, 12, 21, 15), "1985-03-04T12:21.25");
+		assertDeserializeEquals(new Date(85, 2, 4, 12, 21, 30), "1985-03-04T12:21.5");
+	}
+
+	@Test
+	public void canParseDecimalPartOfAnHour() throws Exception {
+		assertDeserializeEquals(new Date(85, 2, 4, 12, 15), "1985-03-04T12.25");
+		assertDeserializeEquals(new Date(85, 2, 4, 12, 0, 36), "1985-03-04T12.01");
+	}
+
+	@Test
+	public void canParseMilliseconds() throws Exception {
+		Date ms500 = (Date) new DateTimeSerializer().deserialize("1985-03-04T12:21:36.5");
+		assertEquals(500, ms500.getTime() - new Date(85, 2, 4, 12, 21, 36).getTime());
+	}
+
+	@Test
+	public void canParseUTCHour() throws Exception {
+		Date expected = new Date(85, 2, 4, 12, 21, 36);
+		assertDeserializeEquals(expected, "1985-03-04T12:21:36Z");
+
+		// When timezone is explicit, we should get the exact same date regardless of this computer default timezone
+		TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
+		assertDeserializeEquals(expected, "1985-03-04T12:21:36Z");
+	}
+
+	@Test
+	public void canParseBasicFormatTimeOffset() throws Exception {
+		Date expected = new Date(85, 2, 4, 1, 40, 31);
+		assertDeserializeEquals(expected, "19850304T131031+1130");
+
+		// When timezone is explicit, we should get the exact same date regardless of this computer default timezone
+		TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
+		assertDeserializeEquals(expected, "19850304T131031+1130");
+	}
+
+	@Test
+	public void canParseExtendedFormatTimeOffset() throws Exception {
+		assertDeserializeEquals(new Date(85, 2, 4, 1, 40, 31), "1985-03-04T13:10:31+11:30");
+	}
+
+	@Test
+	public void canParseTimeOffsetWithoutMinute() throws Exception {
+		assertDeserializeEquals(new Date(85, 2, 4, 2, 10, 31), "1985-03-04T13:10:31+11");
+	}
+
+	@Test
+	public void canParseNegativeTimeOffset() throws Exception {
+		assertDeserializeEquals(new Date(85, 2, 4, 22, 30, 31), "1985-03-04T13:10:31-09:20");
+	}
+
+	@Test
+	public void canHandleLimitCases() throws Exception {
+		assertDeserializeEquals(new Date(80, 0, 1), "1980-01-01T00:00:00.0Z");
+		assertDeserializeEquals(new Date(80, 0, 1), "1980-01-01T00Z");
+		assertDeserializeEquals(new Date(81, 11, 31, 23, 59, 59), "1981-12-31T23:59:59Z");
+	}
+
+	private void assertDeserializeEquals(Date expected, String toDeserialize) throws Exception {
+		Date date = (Date) new DateTimeSerializer().deserialize(toDeserialize);
+		long diffMs = date.getTime() - expected.getTime();
+		assertEquals(expected, date);
 	}
 }
diff --git a/src/test/java/de/timroes/axmlrpc/serializer/TestSerializers.java b/src/test/java/de/timroes/axmlrpc/serializer/TestSerializers.java
new file mode 100644
index 0000000..0288d87
--- /dev/null
+++ b/src/test/java/de/timroes/axmlrpc/serializer/TestSerializers.java
@@ -0,0 +1,62 @@
+package de.timroes.axmlrpc.serializer;
+
+import static org.junit.Assert.*;
+
+import java.util.Date;
+
+import org.junit.Test;
+
+import de.timroes.axmlrpc.xmlcreator.XmlElement;
+
+public class TestSerializers {
+
+	@Test
+	public void canSerializeBase64(){
+		assertExpectedSerialized("<base64>AQIDBA==</base64>", new Base64Serializer().serialize(new Byte[]{1, 2, 3, 4}));
+	}
+
+	@Test
+	public void canSerializeBoolean(){
+		assertExpectedSerialized("<boolean>1</boolean>", new BooleanSerializer().serialize(true));
+		assertExpectedSerialized("<boolean>0</boolean>", new BooleanSerializer().serialize(false));
+	}
+
+	@Test
+	public void canSerializeDouble(){
+		assertExpectedSerialized("<double>3.2</double>", new DoubleSerializer().serialize(3.2));
+	}
+
+	@Test
+	public void canSerializeDate(){
+		assertExpectedSerialized("<dateTime.iso8601>19850503T122334</dateTime.iso8601>",
+				new DateTimeSerializer().serialize(new Date(85, 4, 3, 12, 23, 34)));
+	}
+
+	@Test
+	public void canSerializeInt(){
+		assertExpectedSerialized("<int>4</int>", new IntSerializer().serialize(4));
+	}
+
+	@Test
+	public void canSerializeLong(){
+		assertExpectedSerialized("<i8>1234</i8>", new LongSerializer().serialize(1234L));
+	}
+
+	@Test
+	public void canSerializeNullElement(){
+		assertExpectedSerialized("<nil/>", new NullSerializer().serialize(null));
+	}
+
+	@Test
+	public void canSerializeString(){
+		boolean encodeString = true;
+		assertExpectedSerialized("<string>te<&>st</string>", new StringSerializer(encodeString, true).serialize("te<&>st"));
+
+		encodeString = false;
+		assertExpectedSerialized("<string>te<&>st</string>", new StringSerializer(encodeString, true).serialize("te<&>st"));
+	}
+
+	private static void assertExpectedSerialized(String expected, XmlElement actual){
+		assertEquals(expected, actual.toString().trim());
+	}
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/axmlrpc.git



More information about the pkg-java-commits mailing list