perfsonar-dev - [pS-dev] [GEANT/SA2/ps-java-services] r6366 - trunk/perfsonar-base/base/src/test/java/net/geant/perfsonar/helpers
Subject: perfsonar development work
List archive
[pS-dev] [GEANT/SA2/ps-java-services] r6366 - trunk/perfsonar-base/base/src/test/java/net/geant/perfsonar/helpers
Chronological Thread
- From:
- To:
- Subject: [pS-dev] [GEANT/SA2/ps-java-services] r6366 - trunk/perfsonar-base/base/src/test/java/net/geant/perfsonar/helpers
- Date: Mon, 6 May 2013 19:07:02 +0100 (BST)
- Authentication-results: sfpop-ironport02.merit.edu; dkim=neutral (message not signed) header.i=none
Author: psnc.pietrzak
Date: 2013-05-06 19:07:02 +0100 (Mon, 06 May 2013)
New Revision: 6366
Modified:
trunk/perfsonar-base/base/src/test/java/net/geant/perfsonar/helpers/Response.java
Log:
changed internal representation to string to fix the parse bug problem.
Modified:
trunk/perfsonar-base/base/src/test/java/net/geant/perfsonar/helpers/Response.java
===================================================================
---
trunk/perfsonar-base/base/src/test/java/net/geant/perfsonar/helpers/Response.java
2013-05-06 17:27:04 UTC (rev 6365)
+++
trunk/perfsonar-base/base/src/test/java/net/geant/perfsonar/helpers/Response.java
2013-05-06 18:07:02 UTC (rev 6366)
@@ -4,6 +4,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import javax.xml.transform.stream.StreamSource;
@@ -11,16 +12,20 @@
import org.custommonkey.xmlunit.Diff;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.xml.sax.SAXParseException;
public class Response {
protected Logger logger = LoggerFactory.getLogger(getClass());
private final Reader input;
+ private String inputString;
+
public Response(InputStream input) {
if (input == null)
throw new NullPointerException("Response InputStream cannot
be null.");
try {
this.input = new InputStreamReader(input, "UTF-8");
+ toString(this.input);
} catch (UnsupportedEncodingException e) {
String msg = "UTF-8 charset is not supported on this platform.";
logger.error(msg);
@@ -28,7 +33,22 @@
}
}
- public Response(StreamSource source) {
+ private void toString(Reader input) {
+ final StringBuffer buffer = new StringBuffer();
+ try {
+ int ch = input.read();
+ for (; ch != -1; ) {
+ buffer.append((char) ch);
+ ch = input.read();
+ }
+ } catch (IOException e) {
+ logger.error("Error converting Response to string
(returning null!): {}", e.getMessage());
+ return;
+ }
+ inputString = buffer.toString();
+ }
+
+ public Response(StreamSource source) {
if (source.getInputStream() == null) {
if (source.getReader() == null) {
String msg = "Response StreamSource Reader cannot be
null.";
@@ -44,6 +64,8 @@
logger.error(msg);
throw new RuntimeException(msg, e);
}
+
+ toString(input);
}
public Response(Reader input) {
@@ -53,6 +75,7 @@
throw new NullPointerException();
}
this.input = input;
+ toString(input);
}
public boolean equals(Object obj) {
@@ -63,38 +86,51 @@
}
if (obj instanceof Response)
- return equals(((Response) obj).input);
+ //return equals(((Response) obj).input);
+ return equals(((Response) obj).inputString);
- if (!(obj instanceof Reader))
+ //if (!(obj instanceof Reader))
+ if (!(obj instanceof String))
return false;
try {
- logger.debug("Object to compare against: {}", obj);
- logger.debug("My own content: {}", input);
- Diff diff = new Diff((Reader) obj, input);
+// logger.debug("Object to compare against: {}", obj);
+// logger.debug("My own content: {}", input);
+ //Diff diff = new Diff((Reader) obj, input);
+ Diff diff = new Diff((String) obj, inputString);
return diff.identical();
+ } catch (SAXParseException ex) {
+ String msg = "Cannot compare XML responses at line: "
+ ex.getLineNumber() + "; column: " + ex.getColumnNumber() + "; " +
ex.getException();
+ //String msg = "Cannot compare XML responses (" +
ex.getClass() + "): " + ex.getMessage();
+ logger.error(msg);
+ throw new RuntimeException(msg, ex);
} catch (Exception ex) {
String msg = "Cannot compare XML responses (" +
ex.getClass() + "): " + ex.getMessage();
logger.error(msg);
throw new RuntimeException(msg, ex);
}
+
+
}
public Reader getReader() {
- return this.input;
+ //return this.input;
+ return new StringReader(inputString);
}
public String toString() {
- final StringBuffer buffer = new StringBuffer();
- try {
- for (int ch = 0; ch != -1; ) {
- ch = input.read();
- buffer.append((char) ch);
- }
- } catch (IOException e) {
- logger.error("Error converting Response to string
(returning null!): {}", e.getMessage());
- return null;
- }
- return buffer.toString();
+ return inputString;
+// final StringBuffer buffer = new StringBuffer();
+// try {
+// int ch = input.read();
+// for (; ch != -1; ) {
+// buffer.append((char) ch);
+// ch = input.read();
+// }
+// } catch (IOException e) {
+// logger.error("Error converting Response to string
(returning null!): {}", e.getMessage());
+// return null;
+// }
+// return buffer.toString();
}
}
- [pS-dev] [GEANT/SA2/ps-java-services] r6366 - trunk/perfsonar-base/base/src/test/java/net/geant/perfsonar/helpers, svn-noreply, 05/06/2013
Archive powered by MHonArc 2.6.16.