]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - main/java/org/argeo/server/ServerAnswer.java
1 package org
.argeo
.server
;
3 import java
.io
.PrintWriter
;
4 import java
.io
.StringWriter
;
6 import org
.apache
.commons
.io
.IOUtils
;
8 /** Answer to an execution of a remote service which performed changes. */
9 public class ServerAnswer
{
10 public final static String OK
= "OK";
11 public final static String ERROR
= "ERROR";
13 private String status
= OK
;
14 private String message
= "";
16 /** Canonical constructor */
17 public ServerAnswer(String status
, String message
) {
20 throw new ArgeoServerException("Message cannot be null");
21 this.message
= message
;
24 /** Empty constructor */
25 public ServerAnswer() {
28 public String
getStatus() {
32 public void setStatus(String status
) {
33 if (status
== null || (!status
.equals(OK
) && !status
.equals(ERROR
)))
34 throw new ArgeoServerException("Bad status format: " + status
);
38 public String
getMessage() {
42 public void setMessage(String message
) {
43 this.message
= message
;
46 public Boolean
isOk() {
47 return status
.equals(OK
);
50 public Boolean
isError() {
51 return status
.equals(ERROR
);
54 public static ServerAnswer
error(String message
) {
55 return new ServerAnswer(ERROR
, message
);
58 public static ServerAnswer
error(Throwable e
) {
59 StringWriter writer
= new StringWriter();
61 e
.printStackTrace(new PrintWriter(writer
));
62 return new ServerAnswer(ERROR
, writer
.toString());
64 IOUtils
.closeQuietly(writer
);
68 public static ServerAnswer
ok(String message
) {
69 return new ServerAnswer(OK
, message
);
73 public String
toString() {
74 return "ServerAnswer{status:"+status
+", message:"+message
+"}";