From e300752d9b5189eda26084b62a5d455ee609dace Mon Sep 17 00:00:00 2001 From: himanshuatgit Date: Fri, 26 May 2023 07:42:44 +0000 Subject: [PATCH 1/8] BUG 35047999: Show Server Error in faultString instead of error details. Signed-off-by: Himanshu Ranjan --- .../sun/xml/ws/fault/SOAPFaultBuilder.java | 36 ++++-- .../xml/ws/fault/SOAPFaultBuilderTest.java | 117 ++++++++++++++++-- 2 files changed, 131 insertions(+), 22 deletions(-) diff --git a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java index 754707532..b33fcf36d 100644 --- a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java +++ b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023 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 @@ -37,9 +37,11 @@ import jakarta.xml.soap.Detail; import jakarta.xml.soap.DetailEntry; import javax.xml.transform.dom.DOMResult; +import jakarta.xml.soap.SOAPException; import jakarta.xml.ws.ProtocolException; import jakarta.xml.ws.WebServiceException; import jakarta.xml.ws.soap.SOAPFaultException; + import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -56,6 +58,8 @@ */ public abstract class SOAPFaultBuilder { + public static final String SERVER_ERROR = "Server Error"; + /** * Default constructor. */ @@ -214,7 +218,10 @@ public static Message createSOAPFaultMessage(SOAPVersion soapVersion, String fau return createSOAPFaultMessage(soapVersion, faultString, faultCode, null); } - public static Message createSOAPFaultMessage(SOAPVersion soapVersion, SOAPFault fault) { + public static Message createSOAPFaultMessage(SOAPVersion soapVersion, SOAPFault fault) throws SOAPException { + if (!isCaptureExceptionMessage()) { + fault.setFaultString(SERVER_ERROR); + } switch (soapVersion) { case SOAP_11: return JAXBMessage.create(JAXB_CONTEXT, new SOAP11Fault(fault), soapVersion); @@ -226,6 +233,9 @@ public static Message createSOAPFaultMessage(SOAPVersion soapVersion, SOAPFault } private static Message createSOAPFaultMessage(SOAPVersion soapVersion, String faultString, QName faultCode, Element detail) { + if (!isCaptureExceptionMessage()) { + faultString = SERVER_ERROR; + } switch (soapVersion) { case SOAP_11: return JAXBMessage.create(JAXB_CONTEXT, new SOAP11Fault(faultCode, faultString, null, detail), soapVersion); @@ -379,14 +389,9 @@ private static Message createSOAP11Fault(SOAPVersion soapVersion, Throwable e, O } if (faultString == null) { - if (!isCaptureExceptionMessage()) { - faultString = "Server Error"; - } - else { - faultString = e.getMessage(); - if (faultString == null) { - faultString = e.toString(); - } + faultString = e.getMessage(); + if (faultString == null) { + faultString = e.toString(); } } Element detailNode = null; @@ -406,6 +411,11 @@ private static Message createSOAP11Fault(SOAPVersion soapVersion, Throwable e, O faultCode = getDefaultFaultCode(soapVersion); } } + + if (!isCaptureExceptionMessage()) { + faultString = SERVER_ERROR; + } + SOAP11Fault soap11Fault = new SOAP11Fault(faultCode, faultString, faultActor, detailNode); //Don't fill the stacktrace for Service specific exceptions. @@ -483,7 +493,6 @@ private static Message createSOAP12Fault(SOAPVersion soapVersion, Throwable e, O } } - ReasonType reason = new ReasonType(faultString); Element detailNode = null; QName firstEntry = null; if (detail == null && soapFaultException != null) { @@ -501,6 +510,11 @@ private static Message createSOAP12Fault(SOAPVersion soapVersion, Throwable e, O } } + if (!isCaptureExceptionMessage()) { + faultString = SERVER_ERROR; + } + ReasonType reason = new ReasonType(faultString); + SOAP12Fault soap12Fault = new SOAP12Fault(code, reason, faultNode, faultRole, detailNode); //Don't fill the stacktrace for Service specific exceptions. diff --git a/jaxws-ri/runtime/rt/src/test/java/com/sun/xml/ws/fault/SOAPFaultBuilderTest.java b/jaxws-ri/runtime/rt/src/test/java/com/sun/xml/ws/fault/SOAPFaultBuilderTest.java index e1b606c72..6c3b431fe 100644 --- a/jaxws-ri/runtime/rt/src/test/java/com/sun/xml/ws/fault/SOAPFaultBuilderTest.java +++ b/jaxws-ri/runtime/rt/src/test/java/com/sun/xml/ws/fault/SOAPFaultBuilderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023 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 @@ -21,10 +21,12 @@ import javax.xml.namespace.QName; import jakarta.xml.soap.Detail; import jakarta.xml.soap.MessageFactory; +import jakarta.xml.soap.SOAPConstants; import jakarta.xml.soap.SOAPElement; import jakarta.xml.soap.SOAPFactory; import jakarta.xml.soap.SOAPFault; import jakarta.xml.soap.SOAPMessage; + import javax.xml.stream.XMLStreamReader; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; @@ -125,16 +127,7 @@ public void testCreate11FaultFromRE() { 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()); - } - } - } + verifyFaultStringForSoap11(faultMsg); } catch(Exception ex) { ex.printStackTrace(); fail(ex.getMessage()); @@ -143,6 +136,82 @@ public void testCreate11FaultFromRE() { } } + public void testCreate12FaultFromRE() { + 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_12, null, re); + verifyFaultStringForSoap12(faultMsg); + } catch (Exception ex) { + ex.printStackTrace(); + fail(ex.getMessage()); + } finally { + SOAPFaultBuilder.setCaptureExceptionMessage(true); + } + } + + public void testCreateSOAPFaultMessageWithSOAPFaultArgumentForSOAP11() { + try { + SOAPFaultBuilder.setCaptureExceptionMessage(false); + Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(SOAPVersion.SOAP_11, FAULT_11); + verifyFaultStringForSoap11(faultMsg); + } catch (Exception ex) { + ex.printStackTrace(); + fail(ex.getMessage()); + } finally { + SOAPFaultBuilder.setCaptureExceptionMessage(true); + } + } + + public void testCreateSOAPFaultMessageWithFaultStringArgumentForSOAP11() { + + String faultString = "Couldn't create SOAP message due to exception: XML reader error: " + + "com.ctc.wstx.exc.WstxParsingException: Unexpected '<' character in element " + + "(missing closing '>'?)"; + try { + SOAPFaultBuilder.setCaptureExceptionMessage(false); + Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(SOAPVersion.SOAP_11, faultString, DETAIL1_QNAME); + verifyFaultStringForSoap11(faultMsg); + } catch (Exception ex) { + ex.printStackTrace(); + fail(ex.getMessage()); + } finally { + SOAPFaultBuilder.setCaptureExceptionMessage(true); + } + } + + public void testCreateSOAPFaultMessageWithSOAPFaultArgumentForSOAP12() { + try { + SOAPFaultBuilder.setCaptureExceptionMessage(false); + Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(SOAPVersion.SOAP_12, FAULT_12); + verifyFaultStringForSoap12(faultMsg); + } catch (Exception ex) { + ex.printStackTrace(); + fail(ex.getMessage()); + } finally { + SOAPFaultBuilder.setCaptureExceptionMessage(true); + } + } + + public void testCreateSOAPFaultMessageWithFaultStringArgumentForSOAP12() { + + String faultString = "Couldn't create SOAP message due to exception: XML reader error: " + + "com.ctc.wstx.exc.WstxParsingException: Unexpected '<' character in element " + + "(missing closing '>'?)"; + try { + SOAPFaultBuilder.setCaptureExceptionMessage(false); + Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(SOAPVersion.SOAP_12, faultString, + SOAPConstants.SOAP_RECEIVER_FAULT); + verifyFaultStringForSoap12(faultMsg); + } 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())); @@ -177,4 +246,30 @@ private void verifyDetail(Message message) throws Exception { } } + private void verifyFaultStringForSoap11(Message faultMsg) throws Exception { + boolean isfaultStringPresent = false; + XMLStreamReader rdr = faultMsg.readPayload(); + while (rdr.hasNext()) { + int event = rdr.next(); + if (event == XMLStreamReader.START_ELEMENT) { + if (rdr.getName().getLocalPart().equals("faultstring")) { + isfaultStringPresent = true; + event = rdr.next(); + assertEquals(SOAPFaultBuilder.SERVER_ERROR, rdr.getText()); + } + } + } + if(!isfaultStringPresent) { + fail("There is no faultstring in the response"); + } + } + + private void verifyFaultStringForSoap12(Message faultMsg) throws Exception { + SOAPFaultBuilder sfb = SOAPFaultBuilder.create(faultMsg); + Throwable ex = sfb.createException(null); + assertTrue(ex instanceof SOAPFaultException); + SOAPFaultException sfe = (SOAPFaultException) ex; + SOAPFault sf = sfe.getFault(); + assertTrue(sf.getFaultString().equals(SOAPFaultBuilder.SERVER_ERROR)); + } } From 8bdac5f9e5c6bb1bc0c535d052e6b20948458aef Mon Sep 17 00:00:00 2001 From: himanshuatgit Date: Thu, 1 Jun 2023 10:32:46 +0000 Subject: [PATCH 2/8] BUG 35047999: Show Server Error in faultString instead of error details. Signed-off-by: Himanshu Ranjan --- .../test/java/com/sun/xml/ws/fault/SOAPFaultBuilderTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jaxws-ri/runtime/rt/src/test/java/com/sun/xml/ws/fault/SOAPFaultBuilderTest.java b/jaxws-ri/runtime/rt/src/test/java/com/sun/xml/ws/fault/SOAPFaultBuilderTest.java index 6c3b431fe..f6af0c618 100644 --- a/jaxws-ri/runtime/rt/src/test/java/com/sun/xml/ws/fault/SOAPFaultBuilderTest.java +++ b/jaxws-ri/runtime/rt/src/test/java/com/sun/xml/ws/fault/SOAPFaultBuilderTest.java @@ -270,6 +270,6 @@ private void verifyFaultStringForSoap12(Message faultMsg) throws Exception { assertTrue(ex instanceof SOAPFaultException); SOAPFaultException sfe = (SOAPFaultException) ex; SOAPFault sf = sfe.getFault(); - assertTrue(sf.getFaultString().equals(SOAPFaultBuilder.SERVER_ERROR)); + assertEquals(sf.getFaultString(),SOAPFaultBuilder.SERVER_ERROR); } } From d69cc498c60120075e4145b5aa9bcc70fe31d0ba Mon Sep 17 00:00:00 2001 From: himanshuatgit Date: Mon, 12 Jun 2023 08:31:04 +0000 Subject: [PATCH 3/8] BUG 35047999: Show Server Error in faultString instead of error details. Signed-off-by: Himanshu Ranjan --- .../sun/xml/ws/fault/SOAPFaultBuilder.java | 19 ++++++------- .../xml/ws/fault/SOAPFaultBuilderTest.java | 28 +++++++++++++------ 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java index b33fcf36d..91cbd7fd9 100644 --- a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java +++ b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java @@ -58,7 +58,7 @@ */ public abstract class SOAPFaultBuilder { - public static final String SERVER_ERROR = "Server Error"; + private static final String SERVER_ERROR = "Server Error"; /** * Default constructor. @@ -233,9 +233,7 @@ public static Message createSOAPFaultMessage(SOAPVersion soapVersion, SOAPFault } private static Message createSOAPFaultMessage(SOAPVersion soapVersion, String faultString, QName faultCode, Element detail) { - if (!isCaptureExceptionMessage()) { - faultString = SERVER_ERROR; - } + faultString = setFaultStringToServerError(faultString); switch (soapVersion) { case SOAP_11: return JAXBMessage.create(JAXB_CONTEXT, new SOAP11Fault(faultCode, faultString, null, detail), soapVersion); @@ -412,9 +410,7 @@ private static Message createSOAP11Fault(SOAPVersion soapVersion, Throwable e, O } } - if (!isCaptureExceptionMessage()) { - faultString = SERVER_ERROR; - } + faultString = setFaultStringToServerError(faultString); SOAP11Fault soap11Fault = new SOAP11Fault(faultCode, faultString, faultActor, detailNode); @@ -510,9 +506,7 @@ private static Message createSOAP12Fault(SOAPVersion soapVersion, Throwable e, O } } - if (!isCaptureExceptionMessage()) { - faultString = SERVER_ERROR; - } + faultString = setFaultStringToServerError(faultString); ReasonType reason = new ReasonType(faultString); SOAP12Fault soap12Fault = new SOAP12Fault(code, reason, faultNode, faultRole, detailNode); @@ -593,4 +587,9 @@ private static JAXBContext createJAXBContext() { public static boolean isCaptureExceptionMessage() { return captureExceptionMessage; } + + + private static String setFaultStringToServerError(String faultString) { + return isCaptureExceptionMessage() ? faultString : SERVER_ERROR; + } } diff --git a/jaxws-ri/runtime/rt/src/test/java/com/sun/xml/ws/fault/SOAPFaultBuilderTest.java b/jaxws-ri/runtime/rt/src/test/java/com/sun/xml/ws/fault/SOAPFaultBuilderTest.java index f6af0c618..7520889e4 100644 --- a/jaxws-ri/runtime/rt/src/test/java/com/sun/xml/ws/fault/SOAPFaultBuilderTest.java +++ b/jaxws-ri/runtime/rt/src/test/java/com/sun/xml/ws/fault/SOAPFaultBuilderTest.java @@ -64,6 +64,7 @@ public class SOAPFaultBuilderTest extends TestCase { static { SOAPFault fault11 = null; SOAPFault fault12 = null; + SOAPFaultBuilder.setCaptureExceptionMessage(true); try { fault11 = createFault(SOAPVersion.SOAP_11); fault12 = createFault(SOAPVersion.SOAP_12); @@ -124,6 +125,7 @@ public void testCreate12FaultFromFault() throws Exception { public void testCreate11FaultFromRE() { RuntimeException re = new RuntimeException("XML reader error: com.ctc.wstx.exc.WstxParsingException: Unexpected < character in element"); + boolean captureExceptionMessageOldValue = SOAPFaultBuilder.isCaptureExceptionMessage(); try { SOAPFaultBuilder.setCaptureExceptionMessage(false); Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(SOAPVersion.SOAP_11, null, re); @@ -132,13 +134,15 @@ public void testCreate11FaultFromRE() { ex.printStackTrace(); fail(ex.getMessage()); } finally{ - SOAPFaultBuilder.setCaptureExceptionMessage(true); + SOAPFaultBuilder.setCaptureExceptionMessage(captureExceptionMessageOldValue); } } public void testCreate12FaultFromRE() { RuntimeException re = new RuntimeException( "XML reader error: com.ctc.wstx.exc.WstxParsingException: Unexpected < character in element"); + + boolean captureExceptionMessageOldValue = SOAPFaultBuilder.isCaptureExceptionMessage(); try { SOAPFaultBuilder.setCaptureExceptionMessage(false); Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(SOAPVersion.SOAP_12, null, re); @@ -147,11 +151,13 @@ public void testCreate12FaultFromRE() { ex.printStackTrace(); fail(ex.getMessage()); } finally { - SOAPFaultBuilder.setCaptureExceptionMessage(true); + SOAPFaultBuilder.setCaptureExceptionMessage(captureExceptionMessageOldValue); } } public void testCreateSOAPFaultMessageWithSOAPFaultArgumentForSOAP11() { + + boolean captureExceptionMessageOldValue = SOAPFaultBuilder.isCaptureExceptionMessage(); try { SOAPFaultBuilder.setCaptureExceptionMessage(false); Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(SOAPVersion.SOAP_11, FAULT_11); @@ -160,7 +166,7 @@ public void testCreateSOAPFaultMessageWithSOAPFaultArgumentForSOAP11() { ex.printStackTrace(); fail(ex.getMessage()); } finally { - SOAPFaultBuilder.setCaptureExceptionMessage(true); + SOAPFaultBuilder.setCaptureExceptionMessage(captureExceptionMessageOldValue); } } @@ -169,6 +175,8 @@ public void testCreateSOAPFaultMessageWithFaultStringArgumentForSOAP11() { String faultString = "Couldn't create SOAP message due to exception: XML reader error: " + "com.ctc.wstx.exc.WstxParsingException: Unexpected '<' character in element " + "(missing closing '>'?)"; + + boolean captureExceptionMessageOldValue = SOAPFaultBuilder.isCaptureExceptionMessage(); try { SOAPFaultBuilder.setCaptureExceptionMessage(false); Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(SOAPVersion.SOAP_11, faultString, DETAIL1_QNAME); @@ -177,11 +185,13 @@ public void testCreateSOAPFaultMessageWithFaultStringArgumentForSOAP11() { ex.printStackTrace(); fail(ex.getMessage()); } finally { - SOAPFaultBuilder.setCaptureExceptionMessage(true); + SOAPFaultBuilder.setCaptureExceptionMessage(captureExceptionMessageOldValue); } } public void testCreateSOAPFaultMessageWithSOAPFaultArgumentForSOAP12() { + + boolean captureExceptionMessageOldValue = SOAPFaultBuilder.isCaptureExceptionMessage(); try { SOAPFaultBuilder.setCaptureExceptionMessage(false); Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(SOAPVersion.SOAP_12, FAULT_12); @@ -190,7 +200,7 @@ public void testCreateSOAPFaultMessageWithSOAPFaultArgumentForSOAP12() { ex.printStackTrace(); fail(ex.getMessage()); } finally { - SOAPFaultBuilder.setCaptureExceptionMessage(true); + SOAPFaultBuilder.setCaptureExceptionMessage(captureExceptionMessageOldValue); } } @@ -199,6 +209,8 @@ public void testCreateSOAPFaultMessageWithFaultStringArgumentForSOAP12() { String faultString = "Couldn't create SOAP message due to exception: XML reader error: " + "com.ctc.wstx.exc.WstxParsingException: Unexpected '<' character in element " + "(missing closing '>'?)"; + + boolean captureExceptionMessageOldValue = SOAPFaultBuilder.isCaptureExceptionMessage(); try { SOAPFaultBuilder.setCaptureExceptionMessage(false); Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(SOAPVersion.SOAP_12, faultString, @@ -208,7 +220,7 @@ public void testCreateSOAPFaultMessageWithFaultStringArgumentForSOAP12() { ex.printStackTrace(); fail(ex.getMessage()); } finally { - SOAPFaultBuilder.setCaptureExceptionMessage(true); + SOAPFaultBuilder.setCaptureExceptionMessage(captureExceptionMessageOldValue); } } @@ -255,7 +267,7 @@ private void verifyFaultStringForSoap11(Message faultMsg) throws Exception { if (rdr.getName().getLocalPart().equals("faultstring")) { isfaultStringPresent = true; event = rdr.next(); - assertEquals(SOAPFaultBuilder.SERVER_ERROR, rdr.getText()); + assertEquals("Server Error", rdr.getText()); } } } @@ -270,6 +282,6 @@ private void verifyFaultStringForSoap12(Message faultMsg) throws Exception { assertTrue(ex instanceof SOAPFaultException); SOAPFaultException sfe = (SOAPFaultException) ex; SOAPFault sf = sfe.getFault(); - assertEquals(sf.getFaultString(),SOAPFaultBuilder.SERVER_ERROR); + assertEquals(sf.getFaultString(),"Server Error"); } } From 74fbc89d94323c394f076838c0dcd6bbf33c8517 Mon Sep 17 00:00:00 2001 From: himanshuatgit Date: Thu, 15 Jun 2023 06:31:30 +0000 Subject: [PATCH 4/8] BUG 35047999: Show Server Error in faultString instead of error details. Signed-off-by: Himanshu Ranjan --- .../main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java | 8 ++++---- .../java/com/sun/xml/ws/fault/SOAPFaultBuilderTest.java | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java index 91cbd7fd9..5c8136f6e 100644 --- a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java +++ b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java @@ -233,7 +233,7 @@ public static Message createSOAPFaultMessage(SOAPVersion soapVersion, SOAPFault } private static Message createSOAPFaultMessage(SOAPVersion soapVersion, String faultString, QName faultCode, Element detail) { - faultString = setFaultStringToServerError(faultString); + faultString = changeFaultStringToServerError(faultString); switch (soapVersion) { case SOAP_11: return JAXBMessage.create(JAXB_CONTEXT, new SOAP11Fault(faultCode, faultString, null, detail), soapVersion); @@ -410,7 +410,7 @@ private static Message createSOAP11Fault(SOAPVersion soapVersion, Throwable e, O } } - faultString = setFaultStringToServerError(faultString); + faultString = changeFaultStringToServerError(faultString); SOAP11Fault soap11Fault = new SOAP11Fault(faultCode, faultString, faultActor, detailNode); @@ -506,7 +506,7 @@ private static Message createSOAP12Fault(SOAPVersion soapVersion, Throwable e, O } } - faultString = setFaultStringToServerError(faultString); + faultString = changeFaultStringToServerError(faultString); ReasonType reason = new ReasonType(faultString); SOAP12Fault soap12Fault = new SOAP12Fault(code, reason, faultNode, faultRole, detailNode); @@ -589,7 +589,7 @@ public static boolean isCaptureExceptionMessage() { } - private static String setFaultStringToServerError(String faultString) { + private static String changeFaultStringToServerError(String faultString) { return isCaptureExceptionMessage() ? faultString : SERVER_ERROR; } } diff --git a/jaxws-ri/runtime/rt/src/test/java/com/sun/xml/ws/fault/SOAPFaultBuilderTest.java b/jaxws-ri/runtime/rt/src/test/java/com/sun/xml/ws/fault/SOAPFaultBuilderTest.java index 7520889e4..ddf9eb1a7 100644 --- a/jaxws-ri/runtime/rt/src/test/java/com/sun/xml/ws/fault/SOAPFaultBuilderTest.java +++ b/jaxws-ri/runtime/rt/src/test/java/com/sun/xml/ws/fault/SOAPFaultBuilderTest.java @@ -64,7 +64,6 @@ public class SOAPFaultBuilderTest extends TestCase { static { SOAPFault fault11 = null; SOAPFault fault12 = null; - SOAPFaultBuilder.setCaptureExceptionMessage(true); try { fault11 = createFault(SOAPVersion.SOAP_11); fault12 = createFault(SOAPVersion.SOAP_12); From 2360075f8d8e26dbf0a25c3ff040129b69dca89b Mon Sep 17 00:00:00 2001 From: himanshuatgit Date: Wed, 21 Jun 2023 08:57:46 +0000 Subject: [PATCH 5/8] BUG 35047999: Show Server Error in faultString instead of error details. Signed-off-by: Himanshu Ranjan --- .../java/com/sun/xml/ws/fault/SOAP11Fault.java | 6 +++--- .../java/com/sun/xml/ws/fault/SOAP12Fault.java | 6 +++--- .../com/sun/xml/ws/fault/SOAPFaultBuilder.java | 14 +++----------- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP11Fault.java b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP11Fault.java index 829abbb25..5f736810f 100644 --- a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP11Fault.java +++ b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP11Fault.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023 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 @@ -76,7 +76,7 @@ class SOAP11Fault extends SOAPFaultBuilder { */ SOAP11Fault(QName code, String reason, String actor, Element detailObject) { this.faultcode = code; - this.faultstring = reason; + this.faultstring = changeFaultStringToServerError(reason); this.faultactor = actor; if (detailObject != null) { if ((detailObject.getNamespaceURI() == null || @@ -93,7 +93,7 @@ class SOAP11Fault extends SOAPFaultBuilder { SOAP11Fault(SOAPFault fault) { this.faultcode = fault.getFaultCodeAsQName(); - this.faultstring = fault.getFaultString(); + this.faultstring = changeFaultStringToServerError(fault.getFaultString()); this.faultactor = fault.getFaultActor(); if (fault.getDetail() != null) { detail = new DetailType(); diff --git a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP12Fault.java b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP12Fault.java index ecc7a8b1c..1ce771155 100644 --- a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP12Fault.java +++ b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP12Fault.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023 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 @@ -99,7 +99,7 @@ class SOAP12Fault extends SOAPFaultBuilder { SOAP12Fault(CodeType code, ReasonType reason, String node, String role, Element detailObject) { this.code = code; - this.reason = reason; + this.reason = isCaptureExceptionMessage() ? reason : new ReasonType(SERVER_ERROR); this.node = node; this.role = role; if (detailObject != null) { @@ -122,7 +122,7 @@ class SOAP12Fault extends SOAPFaultBuilder { throw new WebServiceException(e); } - reason = new ReasonType(fault.getFaultString()); + reason = new ReasonType(changeFaultStringToServerError(fault.getFaultString())); role = fault.getFaultRole(); node = fault.getFaultNode(); if (fault.getDetail() != null) { diff --git a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java index 5c8136f6e..41c73df16 100644 --- a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java +++ b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java @@ -58,7 +58,7 @@ */ public abstract class SOAPFaultBuilder { - private static final String SERVER_ERROR = "Server Error"; + protected static final String SERVER_ERROR = "Server Error"; /** * Default constructor. @@ -218,10 +218,7 @@ public static Message createSOAPFaultMessage(SOAPVersion soapVersion, String fau return createSOAPFaultMessage(soapVersion, faultString, faultCode, null); } - public static Message createSOAPFaultMessage(SOAPVersion soapVersion, SOAPFault fault) throws SOAPException { - if (!isCaptureExceptionMessage()) { - fault.setFaultString(SERVER_ERROR); - } + public static Message createSOAPFaultMessage(SOAPVersion soapVersion, SOAPFault fault) { switch (soapVersion) { case SOAP_11: return JAXBMessage.create(JAXB_CONTEXT, new SOAP11Fault(fault), soapVersion); @@ -233,7 +230,6 @@ public static Message createSOAPFaultMessage(SOAPVersion soapVersion, SOAPFault } private static Message createSOAPFaultMessage(SOAPVersion soapVersion, String faultString, QName faultCode, Element detail) { - faultString = changeFaultStringToServerError(faultString); switch (soapVersion) { case SOAP_11: return JAXBMessage.create(JAXB_CONTEXT, new SOAP11Fault(faultCode, faultString, null, detail), soapVersion); @@ -409,9 +405,6 @@ private static Message createSOAP11Fault(SOAPVersion soapVersion, Throwable e, O faultCode = getDefaultFaultCode(soapVersion); } } - - faultString = changeFaultStringToServerError(faultString); - SOAP11Fault soap11Fault = new SOAP11Fault(faultCode, faultString, faultActor, detailNode); //Don't fill the stacktrace for Service specific exceptions. @@ -506,7 +499,6 @@ private static Message createSOAP12Fault(SOAPVersion soapVersion, Throwable e, O } } - faultString = changeFaultStringToServerError(faultString); ReasonType reason = new ReasonType(faultString); SOAP12Fault soap12Fault = new SOAP12Fault(code, reason, faultNode, faultRole, detailNode); @@ -589,7 +581,7 @@ public static boolean isCaptureExceptionMessage() { } - private static String changeFaultStringToServerError(String faultString) { + protected static String changeFaultStringToServerError(String faultString) { return isCaptureExceptionMessage() ? faultString : SERVER_ERROR; } } From 245278959955ba0ad40a15968c387b75dcb4f209 Mon Sep 17 00:00:00 2001 From: himanshuatgit Date: Fri, 23 Jun 2023 08:48:05 +0000 Subject: [PATCH 6/8] BUG 35047999: Show Server Error in faultString instead of error details. Signed-off-by: Himanshu Ranjan --- .../rt/src/main/java/com/sun/xml/ws/fault/SOAP11Fault.java | 4 ++-- .../rt/src/main/java/com/sun/xml/ws/fault/SOAP12Fault.java | 2 +- .../src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP11Fault.java b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP11Fault.java index 5f736810f..5c1746a0f 100644 --- a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP11Fault.java +++ b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP11Fault.java @@ -76,7 +76,7 @@ class SOAP11Fault extends SOAPFaultBuilder { */ SOAP11Fault(QName code, String reason, String actor, Element detailObject) { this.faultcode = code; - this.faultstring = changeFaultStringToServerError(reason); + this.faultstring = createFaultString(reason); this.faultactor = actor; if (detailObject != null) { if ((detailObject.getNamespaceURI() == null || @@ -93,7 +93,7 @@ class SOAP11Fault extends SOAPFaultBuilder { SOAP11Fault(SOAPFault fault) { this.faultcode = fault.getFaultCodeAsQName(); - this.faultstring = changeFaultStringToServerError(fault.getFaultString()); + this.faultstring = createFaultString(fault.getFaultString()); this.faultactor = fault.getFaultActor(); if (fault.getDetail() != null) { detail = new DetailType(); diff --git a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP12Fault.java b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP12Fault.java index 1ce771155..45e2e965a 100644 --- a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP12Fault.java +++ b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP12Fault.java @@ -122,7 +122,7 @@ class SOAP12Fault extends SOAPFaultBuilder { throw new WebServiceException(e); } - reason = new ReasonType(changeFaultStringToServerError(fault.getFaultString())); + reason = new ReasonType(createFaultString(fault.getFaultString())); role = fault.getFaultRole(); node = fault.getFaultNode(); if (fault.getDetail() != null) { diff --git a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java index 41c73df16..6ae3f2b6a 100644 --- a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java +++ b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java @@ -581,7 +581,7 @@ public static boolean isCaptureExceptionMessage() { } - protected static String changeFaultStringToServerError(String faultString) { + protected static String createFaultString(String faultString) { return isCaptureExceptionMessage() ? faultString : SERVER_ERROR; } } From 651978f270dc404cb9d791a7d5afd85acde2c953 Mon Sep 17 00:00:00 2001 From: himanshuatgit Date: Fri, 23 Jun 2023 09:18:32 +0000 Subject: [PATCH 7/8] BUG 35047999: Show Server Error in faultString instead of error details. Signed-off-by: Himanshu Ranjan --- .../rt/src/main/java/com/sun/xml/ws/fault/SOAP12Fault.java | 2 +- .../main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP12Fault.java b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP12Fault.java index 45e2e965a..fefb6711a 100644 --- a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP12Fault.java +++ b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP12Fault.java @@ -99,7 +99,7 @@ class SOAP12Fault extends SOAPFaultBuilder { SOAP12Fault(CodeType code, ReasonType reason, String node, String role, Element detailObject) { this.code = code; - this.reason = isCaptureExceptionMessage() ? reason : new ReasonType(SERVER_ERROR); + this.reason = isCaptureExceptionMessage() ? reason : new ReasonType(getConstantServerError()); this.node = node; this.role = role; if (detailObject != null) { diff --git a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java index 6ae3f2b6a..4772f6fcc 100644 --- a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java +++ b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java @@ -58,7 +58,7 @@ */ public abstract class SOAPFaultBuilder { - protected static final String SERVER_ERROR = "Server Error"; + private static final String SERVER_ERROR = "Server Error"; /** * Default constructor. @@ -584,4 +584,8 @@ public static boolean isCaptureExceptionMessage() { protected static String createFaultString(String faultString) { return isCaptureExceptionMessage() ? faultString : SERVER_ERROR; } + + protected static String getConstantServerError(){ + return SERVER_ERROR; + } } From c064368ea294c6032b258baec3b87f42d1208e4d Mon Sep 17 00:00:00 2001 From: himanshuatgit Date: Fri, 23 Jun 2023 10:19:19 +0000 Subject: [PATCH 8/8] BUG 35047999: Show Server Error in faultString instead of error details. Signed-off-by: Himanshu Ranjan --- .../rt/src/main/java/com/sun/xml/ws/fault/SOAP12Fault.java | 2 +- .../rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP12Fault.java b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP12Fault.java index fefb6711a..fd67e96ce 100644 --- a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP12Fault.java +++ b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAP12Fault.java @@ -99,7 +99,7 @@ class SOAP12Fault extends SOAPFaultBuilder { SOAP12Fault(CodeType code, ReasonType reason, String node, String role, Element detailObject) { this.code = code; - this.reason = isCaptureExceptionMessage() ? reason : new ReasonType(getConstantServerError()); + this.reason = isCaptureExceptionMessage() ? reason : new ReasonType(createFaultString()); this.node = node; this.role = role; if (detailObject != null) { diff --git a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java index 4772f6fcc..3ff096fc8 100644 --- a/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java +++ b/jaxws-ri/runtime/rt/src/main/java/com/sun/xml/ws/fault/SOAPFaultBuilder.java @@ -585,7 +585,7 @@ protected static String createFaultString(String faultString) { return isCaptureExceptionMessage() ? faultString : SERVER_ERROR; } - protected static String getConstantServerError(){ + protected static String createFaultString(){ return SERVER_ERROR; } }