Skip to content

Commit

Permalink
Bugno34600318 (#630)
Browse files Browse the repository at this point in the history
Signed-off-by: Vaibhav Vishal <[email protected]>
  • Loading branch information
vavishal authored Oct 18, 2022
1 parent 27cba0f commit 5d35361
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
<listitem>
<para>Switches protocol for W3C schemas to https, see <link xlink:href="https://www.w3.org/blog/2022/07/redirecting-to-https-on-www-w3-org/">the announcement</link> for details</para>
</listitem>
<para>Added a new system property named com.sun.xml.ws.fault.SOAPFaultBuilder.captureExceptionMessage, which when set to false will not add exception messages in the faultstring</para>
<listitem>
</listitem>
</itemizedlist>
</listitem>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2010, 2022 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -129,4 +129,27 @@ bp.setOutboundHeaders(
</section>
</section>

<section xml:id="capture-of-exception-message-in-faultstring">
<title>Capture of exception message in faultstring</title>

<para>The soap fault messages has a faultstring which contains
the exception message if any received from the server side.
If the customer does not want to display any exception messages
from the server side then this system property can be used to
disable that.</para>

<section xml:id="disabling-capture-of-exception-message-in-faultstring">
<title>Disabling capture of exception message in faultstring</title>

<para>The capture of exception message in faultstring is enabled
by default. For your Web Service Application to disable the capture
of exception message in faultstring, set the system property to
false</para>

<informalexample>
<programlisting><![CDATA[com.sun.xml.ws.fault.SOAPFaultBuilder.captureExceptionMessage=false]]></programlisting>
</informalexample>
</section>
</section>

</chapter>
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,14 @@ private static Message createSOAP11Fault(SOAPVersion soapVersion, Throwable e, O
}

if (faultString == null) {
faultString = e.getMessage();
if (faultString == null) {
faultString = e.toString();
if (!isCaptureExceptionMessage()) {
faultString = "Server Error";
}
else {
faultString = e.getMessage();
if (faultString == null) {
faultString = e.toString();
}
}
}
Element detailNode = null;
Expand Down Expand Up @@ -533,13 +538,18 @@ public static SOAPFaultBuilder create(Message msg) throws JAXBException {

private static final Logger logger = Logger.getLogger(SOAPFaultBuilder.class.getName());

private static boolean captureExceptionMessage = true;
/**
* Set to false if you don't want the generated faults to have stack trace in it.
*/
public static final boolean captureStackTrace;

/*package*/ static final String CAPTURE_STACK_TRACE_PROPERTY = SOAPFaultBuilder.class.getName()+".captureStackTrace";

public static void setCaptureExceptionMessage(boolean capture) {
captureExceptionMessage = capture;
}

static {
boolean tmpVal = false;
try {
Expand All @@ -549,6 +559,13 @@ public static SOAPFaultBuilder create(Message msg) throws JAXBException {
}
captureStackTrace = tmpVal;
JAXB_CONTEXT = createJAXBContext();
try {
if (System.getProperty("com.sun.xml.ws.fault.SOAPFaultBuilder.captureExceptionMessage") != null) {
setCaptureExceptionMessage(Boolean.getBoolean("com.sun.xml.ws.fault.SOAPFaultBuilder.captureExceptionMessage"));
}
} catch (SecurityException e) {
// ignore
}
}

private static JAXBContext createJAXBContext() {
Expand All @@ -558,4 +575,8 @@ private static JAXBContext createJAXBContext() {
throw new Error(e);
}
}

public static boolean isCaptureExceptionMessage() {
return captureExceptionMessage;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -34,7 +34,6 @@
import jakarta.xml.ws.soap.SOAPFaultException;
import java.io.StringWriter;


/**
* @author Jitendra Kotamraju
*/
Expand Down Expand Up @@ -121,6 +120,29 @@ public void testCreate12FaultFromFault() throws Exception {
verifyDetail(msg);
}

public void testCreate11FaultFromRE() {
RuntimeException re = new RuntimeException("XML reader error: com.ctc.wstx.exc.WstxParsingException: Unexpected < character in element");
try {
SOAPFaultBuilder.setCaptureExceptionMessage(false);
Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(SOAPVersion.SOAP_11, null, re);
XMLStreamReader rdr = faultMsg.readPayload();
while(rdr.hasNext()) {
int event = rdr.next();
if (event == XMLStreamReader.START_ELEMENT) {
if (rdr.getName().getLocalPart().equals("faultstring")) {
event = rdr.next();
assertEquals("Server Error", rdr.getText());
}
}
}
} catch(Exception ex) {
ex.printStackTrace();
fail(ex.getMessage());
} finally{
SOAPFaultBuilder.setCaptureExceptionMessage(true);
}
}

public void testCreateException_14504957() throws Exception {
MessageFactory f = MessageFactory.newInstance();
SOAPMessage soapMsg = f.createMessage(null, new ByteArrayInputStream(NPE_FAULT.getBytes()));
Expand Down

0 comments on commit 5d35361

Please sign in to comment.