openrat-java-client

Unnamed repository; edit this file 'description' to name the repository.
git clone http://git.code.weiherhei.de/openrat-java-client.git
Log | Files | Refs

commit 19bb5a2c37cbfe2738f0377fba75800f859f08f7
parent cce661bd2c21b2ac6b1c55e5bae4e5e88f020773
Author: Jan Dankert <devnull@localhost>
Date:   Wed, 12 Dec 2018 18:22:33 +0100

Finer Exception-Hierarchie.

Diffstat:
src/de/openrat/client/CMSClient.java | 2+-
src/de/openrat/client/util/CMSConnectionException.java | 37+++++++++++++++++++++++++++++++++++++
src/de/openrat/client/util/CMSRequest.java | 12++++++------
src/de/openrat/client/util/CMSServerErrorException.java | 43+++++++++++++++++++++++++++++++++++++++++++
src/de/openrat/client/util/HttpClient.java | 5++---
test/de/openrat/client/test/TestLowLevelAPI.java | 2--
6 files changed, 89 insertions(+), 12 deletions(-)

diff --git a/src/de/openrat/client/CMSClient.java b/src/de/openrat/client/CMSClient.java @@ -264,7 +264,7 @@ public class CMSClient Constructor<T> c = actionClass.getConstructor(CMSConnection.class); return c.newInstance( this.connection ); } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { - throw new RuntimeException("The action '" + actionClass.getSimpleName() + " could not be created: " + e.getMessage(), e); + throw new IllegalArgumentException("The action '" + actionClass.getSimpleName() + " could not be created: " + e.getMessage(), e); } } } diff --git a/src/de/openrat/client/util/CMSConnectionException.java b/src/de/openrat/client/util/CMSConnectionException.java @@ -0,0 +1,37 @@ +package de.openrat.client.util; + +public class CMSConnectionException extends CMSException +{ + + private static final long serialVersionUID = 3734310284809339317L; + + private String message; + private String status; + private String description; + private String reason; + + public CMSConnectionException(String message, Throwable cause) + { + super(message, cause); + } + + public CMSConnectionException(String message, String status, String description, String reason, Throwable cause) + { + super(message, cause); + + this.message = message; + this.status = status; + this.description = description; + this.reason = reason; + } + + public CMSConnectionException(String message, String status, String description, String reason) + { + super(message); + + this.message = message; + this.status = status; + this.description = description; + this.reason = reason; + } +} diff --git a/src/de/openrat/client/util/CMSRequest.java b/src/de/openrat/client/util/CMSRequest.java @@ -154,7 +154,7 @@ public class CMSRequest } catch (SAXException e) { - throw new CMSException("Server did not return a valid XML-document: " + httpResponse.getPayload(), "" + throw new CMSServerErrorException("Server did not return a valid XML-document: " + httpResponse.getPayload(), "" + httpResponse.getHttpStatus().getStatusCode(), httpResponse.getHttpStatus().getServerMessage(), e.getMessage(), e); } @@ -191,12 +191,12 @@ public class CMSRequest String description = rootNode.getChild("description").getValue(); String reason = rootNode.getChild("reason").getValue(); - throw new CMSException(error, status, description, reason); + throw new CMSServerErrorException(error, status, description, reason); } else { - throw new CMSException(httpStatus.getServerMessage(), "" + httpStatus.getStatusCode(), "", ""); + throw new CMSServerErrorException(httpStatus.getServerMessage(), "" + httpStatus.getStatusCode(), "", ""); } } @@ -214,13 +214,13 @@ public class CMSRequest else { // HTTP-Status 200 OK, but no XML-Element "server" found. - throw new CMSException(httpStatus.getServerMessage(), "" + httpStatus.getStatusCode(), "", "no SERVER element found"); + throw new CMSServerErrorException(httpStatus.getServerMessage(), "" + httpStatus.getStatusCode(), "", "no SERVER element found"); } } else { // Unknown HTTP Status - throw new CMSException(httpStatus.getServerMessage(), "" + httpStatus.getStatusCode(), "", "Unsupported HTTP Status"); + throw new CMSServerErrorException(httpStatus.getServerMessage(), "" + httpStatus.getStatusCode(), "", "Unsupported HTTP Status"); } } @@ -236,7 +236,7 @@ public class CMSRequest { // oh no, the server api is older or newer than our client api. // there is nothing we can do. - throw new CMSException("Only API Version " + CMSClient.SUPPORTED_API_VERSION + + throw new CMSServerErrorException("Only API Version " + CMSClient.SUPPORTED_API_VERSION + " is supported. The server is using API Version " + apiVersion); } diff --git a/src/de/openrat/client/util/CMSServerErrorException.java b/src/de/openrat/client/util/CMSServerErrorException.java @@ -0,0 +1,43 @@ +package de.openrat.client.util; + +public class CMSServerErrorException extends CMSException +{ + + private static final long serialVersionUID = 3734310284809339317L; + + private String message; + private String status; + private String description; + private String reason; + + public CMSServerErrorException(String message, Throwable cause) + { + super(message, cause); + } + + public CMSServerErrorException(String message, String status, String description, String reason, Throwable cause) + { + super(message, cause); + + this.message = message; + this.status = status; + this.description = description; + this.reason = reason; + } + + public CMSServerErrorException(String message) + { + super(message); + this.message = message; + } + + public CMSServerErrorException(String message, String status, String description, String reason) + { + super(message); + + this.message = message; + this.status = status; + this.description = description; + this.reason = reason; + } +} diff --git a/src/de/openrat/client/util/HttpClient.java b/src/de/openrat/client/util/HttpClient.java @@ -165,7 +165,7 @@ public class HttpClient if (readLine == null) { - throw new CMSException("Server response is empty"); + throw new CMSServerErrorException("Server response is empty"); } final String httpServerResponse = readLine.trim(); @@ -174,7 +174,6 @@ public class HttpClient if (this.logWriter != null) { - logWriter.println("--- HTTP-Response ---"); logWriter.println(httpServerResponse); } @@ -197,7 +196,7 @@ public class HttpClient } else { - throw new CMSException("Unknown HTTP response header:" + responseHeaderString); + throw new CMSServerErrorException("Unknown HTTP response header:" + responseHeaderString); } } diff --git a/test/de/openrat/client/test/TestLowLevelAPI.java b/test/de/openrat/client/test/TestLowLevelAPI.java @@ -6,9 +6,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import java.io.PrintWriter; import java.util.HashMap; -import java.util.Locale; import java.util.Map; import static de.openrat.client.test.TestConfiguration.*;