Skip to content

Package: SOAPExceptionImpl

SOAPExceptionImpl

nameinstructionbranchcomplexitylinemethod
SOAPExceptionImpl()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
SOAPExceptionImpl(String)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
SOAPExceptionImpl(String, Throwable)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
SOAPExceptionImpl(Throwable)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getCause()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getMessage()
M: 7 C: 7
50%
M: 3 C: 1
25%
M: 2 C: 1
33%
M: 1 C: 3
75%
M: 0 C: 1
100%
initCause(Throwable)
M: 10 C: 11
52%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 2 C: 4
67%
M: 0 C: 1
100%
printStackTrace()
M: 12 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
printStackTrace(PrintStream)
M: 14 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
printStackTrace(PrintWriter)
M: 14 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Distribution License v. 1.0, which is available at
6: * http://www.eclipse.org/org/documents/edl-v10.php.
7: *
8: * SPDX-License-Identifier: BSD-3-Clause
9: */
10:
11: package com.sun.xml.messaging.saaj;
12:
13: import java.io.PrintStream;
14: import java.io.PrintWriter;
15:
16: import jakarta.xml.soap.SOAPException;
17:
18: /**
19: * An exception that signals that a SOAP exception has occurred. A
20: * <code>SOAPExceptionImpl</code> object may contain a <code>String</code>
21: * that gives the reason for the exception, an embedded
22: * <code>Throwable</code> object, or both. This class provides methods
23: * for retrieving reason messages and for retrieving the embedded
24: * <code>Throwable</code> object.
25: *
26: * <P> Typical reasons for throwing a <code>SOAPExceptionImpl</code>
27: * object are problems such as difficulty setting a header, not being
28: * able to send a message, and not being able to get a connection with
29: * the provider. Reasons for embedding a <code>Throwable</code>
30: * object include problems such as input/output errors or a parsing
31: * problem, such as an error in parsing a header.
32: */
33: public class SOAPExceptionImpl extends SOAPException {
34:
35: private static final long serialVersionUID = 449323096527796613L;
36:
37: private Throwable cause;
38:
39: /**
40: * Constructs a <code>SOAPExceptionImpl</code> object with no
41: * reason or embedded <code>Throwable</code> object.
42: */
43: public SOAPExceptionImpl() {
44: super();
45:         this.cause = null;
46: }
47:
48: /**
49: * Constructs a <code>SOAPExceptionImpl</code> object with the given
50: * <code>String</code> as the reason for the exception being thrown.
51: *
52: * @param reason a description of what caused the exception
53: */
54: public SOAPExceptionImpl(String reason) {
55: super(reason);
56:         this.cause = null;
57: }
58:
59: /**
60: * Constructs a <code>SOAPExceptionImpl</code> object with the given
61: * <code>String</code> as the reason for the exception being thrown
62: * and the given <code>Throwable</code> object as an embedded
63: * exception.
64: *
65: * @param reason a description of what caused the exception
66: * @param cause a <code>Throwable</code> object that is to
67: * be embedded in this <code>SOAPExceptionImpl</code> object
68: */
69: public SOAPExceptionImpl(String reason, Throwable cause) {
70: super (reason);
71: initCause(cause);
72: }
73:
74: /**
75: * Constructs a <code>SOAPExceptionImpl</code> object initialized
76: * with the given <code>Throwable</code> object.
77: * @param cause cause
78: */
79: public SOAPExceptionImpl(Throwable cause) {
80:         super (cause.toString());
81:         initCause(cause);
82: }
83:
84: /**
85: * Returns the detail message for this <code>SOAPExceptionImpl</code>
86: * object.
87: * <P>
88: * If there is an embedded <code>Throwable</code> object, and if the
89: * <code>SOAPExceptionImpl</code> object has no detail message of its
90: * own, this method will return the detail message from the embedded
91: * <code>Throwable</code> object.
92: *
93: * @return the error or warning message for this
94: * <code>SOAPExceptionImpl</code> or, if it has none, the
95: * message of the embedded <code>Throwable</code> object,
96: * if there is one
97: */
98: @Override
99: public String getMessage() {
100:         String message = super.getMessage ();
101:•        if (message == null && cause != null) {
102:          return cause.getMessage();        
103:         } else {
104:          return message;
105:         }
106: }
107:
108: /**
109: * Returns the <code>Throwable</code> object embedded in this
110: * <code>SOAPExceptionImpl</code> if there is one. Otherwise, this method
111: * returns <code>null</code>.
112: *
113: * @return the embedded <code>Throwable</code> object or <code>null</code>
114: * if there is none
115: */
116:
117: @Override
118: public Throwable getCause() {
119:         return cause;
120: }
121:
122: /**
123: * Initializes the <code>cause</code> field of this <code>SOAPExceptionImpl</code>
124: * object with the given <code>Throwable</code> object.
125: * <P>
126: * This method can be called at most once. It is generally called from
127: * within the constructor or immediately after the constructor has
128: * returned a new <code>SOAPExceptionImpl</code> object.
129: * If this <code>SOAPExceptionImpl</code> object was created with the
130: * constructor {@link #SOAPExceptionImpl(Throwable)} or
131: * {@link #SOAPExceptionImpl(String,Throwable)}, meaning that its
132: * <code>cause</code> field already has a value, this method cannot be
133: * called even once.
134: *
135: * @param cause the <code>Throwable</code> object that caused this
136: * <code>SOAPExceptionImpl</code> object to be thrown. The value of this
137: * parameter is saved for later retrieval by the
138: * {@link #getCause()} method. A {@code null} value is
139: * permitted and indicates that the cause is nonexistent or
140: * unknown.
141: * @return a reference to this <code>SOAPExceptionImpl</code> instance
142: * @throws IllegalArgumentException if <code>cause</code> is this
143: * <code>Throwable</code> object. (A <code>Throwable</code> object
144: * cannot be its own cause.)
145: * @throws IllegalStateException if this <code>SOAPExceptionImpl</code> object
146: * was created with {@link #SOAPExceptionImpl(Throwable)} or
147: * {@link #SOAPExceptionImpl(String,Throwable)}, or this
148: * method has already been called on this <code>SOAPExceptionImpl</code>
149: * object
150: */
151: @Override
152: public synchronized Throwable initCause(Throwable cause)
153: {
154:•         if(this.cause != null) {
155:          throw new IllegalStateException("Can't override cause");
156:         }
157:•        if(cause == this) {
158:          throw new IllegalArgumentException("Self-causation not permitted");        
159:         }
160:         this.cause = cause;
161:
162:         return this;
163: }
164:
165: @Override
166: public void printStackTrace() {
167: super.printStackTrace();
168:• if (cause != null) {
169: System.err.println("\nCAUSE:\n");
170: cause.printStackTrace();
171: }
172: }
173:
174: @Override
175: public void printStackTrace(PrintStream s) {
176: super.printStackTrace(s);
177:• if (cause != null) {
178: s.println("\nCAUSE:\n");
179: cause.printStackTrace(s);
180: }
181: }
182:
183: @Override
184: public void printStackTrace(PrintWriter s) {
185: super.printStackTrace(s);
186:• if (cause != null) {
187: s.println("\nCAUSE:\n");
188: cause.printStackTrace(s);
189: }
190: }
191: }