1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.ws.security.conversation;
21
22 import java.text.MessageFormat;
23 import java.util.MissingResourceException;
24 import java.util.ResourceBundle;
25
26 public class ConversationException extends Exception {
27
28 private static final long serialVersionUID = 970894530660804319L;
29
30 public static final String BAD_CONTEXT_TOKEN = "BadContextToken";
31 public static final String UNSUPPORTED_CONTEXT_TOKEN = "UnsupportedContextToken";
32 public static final String UNKNOWN_DERIVATION_SOURCE = "UnknownDerivationSource";
33 public static final String RENEW_NEEDED = "RenewNeeded";
34 public static final String UNABLE_TO_REVIEW = "UnableToRenew";
35
36 private static ResourceBundle resources;
37
38 private String faultCode;
39 private String faultString;
40
41 static {
42 try {
43 resources = ResourceBundle.getBundle("org.apache.ws.security.conversation.errors");
44 } catch (MissingResourceException e) {
45 throw new RuntimeException(e.getMessage(), e);
46 }
47 }
48
49 public ConversationException(String faultCode, Object[] args) {
50 super(getMessage(faultCode, args));
51 this.faultCode = getFaultCode(faultCode);
52 this.faultString = getMessage(faultCode, args);
53 }
54
55
56
57
58
59
60 private String getFaultCode(String code) {
61 if(BAD_CONTEXT_TOKEN.equals(code) ||
62 UNABLE_TO_REVIEW.equals(code) ||
63 UNKNOWN_DERIVATION_SOURCE.equals(code) ||
64 UNSUPPORTED_CONTEXT_TOKEN.equals(code) ||
65 RENEW_NEEDED.equals(code)) {
66 return ConversationConstants.WSC_PREFIX+ ":" + code;
67 } else {
68 return code;
69 }
70 }
71
72 public ConversationException(String faultCode) {
73 this(faultCode, (Object[])null);
74 }
75
76 public ConversationException(String faultCode, Object[] args, Throwable e) {
77 super(getMessage(faultCode, args),e);
78 this.faultCode = faultCode;
79 this.faultString = getMessage(faultCode, args);
80 }
81
82 public ConversationException(String faultCode, Throwable e) {
83 this(faultCode, null, e);
84 }
85
86
87
88
89
90
91
92 protected static String getMessage(String faultCode, Object[] args) {
93 String msg = null;
94 try {
95 msg = MessageFormat.format(resources.getString(faultCode), args);
96 } catch (MissingResourceException e) {
97 throw new RuntimeException("Undefined '" + faultCode + "' resource property", e);
98 }
99 if (msg != null) {
100 return msg;
101 } else {
102 return faultCode;
103 }
104 }
105
106
107
108
109 protected String getFaultCode() {
110 return faultCode;
111 }
112
113
114
115
116 protected String getFaultString() {
117 return faultString;
118 }
119
120
121 }