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 7475da41afaba2ae3f3bae921802e921d957e498
parent 5a414f9bcd631c538743ebccddb456b3e9eedb2f
Author: Jan Dankert <devnull@localhost>
Date:   Wed, 19 Dec 2018 15:57:00 +0100

better example for server message.

Diffstat:
src/de/openrat/client/util/CMSRequest.java | 28+++++++++++++++++-----------
src/de/openrat/client/util/ServerSideException.java | 20++++++++++++++++++++
2 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/src/de/openrat/client/util/CMSRequest.java b/src/de/openrat/client/util/CMSRequest.java @@ -54,7 +54,7 @@ import de.openrat.client.util.HttpRequest.HttpMethod; * calling the CMS a DOM-document is returned, which contains the server * response.<br> * Example <br> - * + * * <pre> * CMSRequest request = new CMSRequest(&quot;your.openrat.example.com&quot;); * // prints tracing information to stdout. @@ -72,7 +72,7 @@ import de.openrat.client.util.HttpRequest.HttpMethod; * // your error handling. * } * </pre> - * + * * @author Jan Dankert */ public class CMSRequest @@ -88,7 +88,7 @@ public class CMSRequest /** * Set the HTTP Method. Default is "GET". - * + * * @param method * HTTP-method */ @@ -100,7 +100,7 @@ public class CMSRequest /** * Constructs a CMS-Request to the specified server/path/port. - * + * * @param connection Connection to server */ public CMSRequest(CMSConnection connection) @@ -114,7 +114,7 @@ public class CMSRequest /** * Sends a request to the openrat-server and parses the response into a DOM * tree document. - * + * * @return server response as a DOM tree * @throws IOException * if server is unrechable or responds non-wellformed XML @@ -168,9 +168,9 @@ public class CMSRequest /** * Erzeugt aus - * + * * @param httpStatus - * + * * @param rootNode * @return */ @@ -194,16 +194,22 @@ public class CMSRequest ServerSideException cause = null; - // TODO only when trace available - cause = new ServerSideException(); + // TODO only if trace available + final List<StackTraceElement> trace = new ArrayList<>(); final String file = "modules/cms-core/Dispatcher.class.php"; final String filename = FileSystems.getDefault().getPath(file).getFileName().toString(); final String method = "cms\\Dispatcher->commitDatabaseTransaction()"; final int line = 110; - StackTraceElement[] trace = new StackTraceElement[] { new StackTraceElement(file,method,filename,line) } ; + trace.add( new StackTraceElement(file,method,filename,line) ); + + String name = "MyServerException"; + String message = "server error"; + + cause = new ServerSideException(message,name); + cause.setStackTrace( trace.toArray(new StackTraceElement[]{}) ); + // TODO recursive exceptions - cause.setStackTrace( trace ); throw new CMSServerErrorException(error, status, description, reason, cause); } diff --git a/src/de/openrat/client/util/ServerSideException.java b/src/de/openrat/client/util/ServerSideException.java @@ -2,7 +2,27 @@ package de.openrat.client.util; public class ServerSideException extends Exception { + private String name; + public ServerSideException() { } + + public ServerSideException(String message, String name) { + super(message); + this.name = name; + } + + + public ServerSideException(String message) { + super(message); + } + + + public String toString() { + String s = (name != null) ? name : getClass().getName(); + + String message = getLocalizedMessage(); + return (message != null) ? (s + ": " + message) : s; + } }