[
https://issues.apache.org/jira/browse/SYNAPSE-1041?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15319165#comment-15319165
]
Andreas Veithen commented on SYNAPSE-1041:
------------------------------------------
{noformat}
+ /**
+ * if string is xml, this method will convert it as a OMElement and return
back.
+ * @param text
+ * @return OMElemen
+ */
+ public static OMElement getOMFromXML(String text) {
+ int escape = StringUtils.countMatches(text, "<!") +
+ StringUtils.countMatches(text, "<?");
+ int numOfLTWithS = StringUtils.countMatches(text, "</");
+ int numOfGTWithS = StringUtils.countMatches(text, "/>");
+ int numOfLT = StringUtils.countMatches(text, "<") - escape;
+ //Should satisfy the conditions if an XML
+ if (numOfLT == 0 || ((numOfLTWithS * 2 + numOfGTWithS) != numOfLT)) {
+ return null;
+ }
+ try {
+ OMElement om = AXIOMUtil.stringToOM(text);
+ return om;
+ } catch (XMLStreamException ignore) {
+ return null;
+ } catch (OMException ignore) {
+ return null;
+ }
+ }
{noformat}
That code looks very fragile to me, especially because it has zero test
coverage. SOAP fault details can only contain elements, not text. Why do we
even allow the code to produce SOAP faults that don't conform to the specs?
> xml string set in the Script mediator is not honored as OM in Fault mediator
> -----------------------------------------------------------------------------
>
> Key: SYNAPSE-1041
> URL: https://issues.apache.org/jira/browse/SYNAPSE-1041
> Project: Synapse
> Issue Type: Bug
> Reporter: Vanjikumaran Sivajothy
> Assignee: Hiranya Jayathilaka
> Attachments: SYNAPSE-1041.diff, detailTransform.js,
> synapse_sample_2000.xml
>
>
> Sample 5 with with custom error message generated via Script mediator does
> not produce the proper xml as the fault response in fault mediator.
> *Synapse Configuration*
> {code}
> <definitions xmlns="http://ws.apache.org/ns/synapse">
> <localEntry key="FaultMessageScript"
>
> src="file:repository/conf/sample/resources/script/CustomErrorMessageScript.js"/>
> <sequence name="myFaultHandler">
> <property name="customErrorCode" value="2016" scope="default"
> type="STRING"/>
> <property name="customErrorText" value="This is Bug" scope="default"
> type="STRING"/>
> <property name="customTime" expression="get-property('SYSTEM_DATE')"
> scope="default" type="STRING"/>
> <script language="js" key="FaultMessageScript"
> function="transformFault"/>
> <log level="custom">
> <property name="**************Custom Detail*****************"
> expression="get-property('customErrorDetail')" />
> </log>
> <makefault version="soap11">
> <code xmlns:tns="http://schemas.xmlsoap.org/soap/envelope/"
> value="tns:Receiver" />
> <reason expression="get-property('ERROR_MESSAGE')"/>
> <detail expression="get-property('customErrorDetail')" type="OM"/>
> </makefault>
> <send/>
> </sequence>
> <sequence name="fault">
> <log level="full">
> <property name="MESSAGE" value="Executing default fault
> sequence"/>
> <property name="ERROR_CODE"
> expression="get-property('ERROR_CODE')"/>
> <property name="ERROR_MESSAGE"
> expression="get-property('ERROR_MESSAGE')"/>
> </log>
> <drop/>
> </sequence>
> <sequence name="main" onError="myFaultHandler">
> <in>
> <log level="full"/>
> <switch xmlns:m0="http://services.samples"
> source="//m0:getQuote/m0:request/m0:symbol">
> <case regex="MSFT">
> <send>
> <endpoint name="testEndpoint1">
> <address
> uri="http://bogus:9000/services/NonExistentStockQuoteService"/>
> </endpoint>
> </send>
> </case>
> <case regex="SUN">
> <send>
> <endpoint name="testEndpoint2">
> <address
> uri="http://localhost:9009/services/NonExistentStockQuoteService"/>
> </endpoint>
> </send>
> </case>
> </switch>
> <drop/>
> </in>
> <out>
> <send/>
> </out>
> </sequence>
> </definitions>
> {code}
> *Script*
> {code}
> function transformFault(mc) {
> var symbol = mc.getPayloadXML()..*::Code.toString();
> var errorCode = mc.getProperty("customErrorCode");
> var errorText = mc.getProperty("customErrorText");
> var time = mc.getProperty('customTime');
> mc.setProperty("customErrorDetail",
> "<CustomErrorDetails><TimeStamp>"+time+"</TimeStamp><ErrorCode>"+errorCode+"</ErrorCode><ErrorText>"+errorText+"</ErrorText></CustomErrorDetails>");
> }
> {code}
> *Client Request*
> Same request as in sample 5
> {{ant stockquote
> -Daddurl=http://localhost:9000/services/SimpleStockQuoteService
> -Dtrpurl=http://localhost:8281/ -Dsymbol=SUN}}
> *Response resiveed and monitored via tcpmon*
> {code}
> <soapenv:Fault>
> <faultcode
> xmlns:tns="http://schemas.xmlsoap.org/soap/envelope/">tns:Receiver</faultcode>
> <faultstring>Error while connecting to the endpoint (Connection
> Failed)</faultstring>
> <detail><CustomErrorDetails><TimeStamp>6/7/16 12:36
> AM</TimeStamp><ErrorCode>2016</ErrorCode><ErrorText>This
> is Bug </ErrorText></CustomErrorDetails></detail>
> </soapenv:Fault>
> {code}
> However,expected results is
> {code}
> <soapenv:Fault>
> <faultcode
> xmlns:tns="http://schemas.xmlsoap.org/soap/envelope/">tns:Receiver</faultcode>
> <faultstring>Error while connecting to the endpoint (Connection
> Failed)</faultstring>
> <detail>
> <CustomErrorDetails>
> <TimeStamp>6/7/16 12:09 AM</TimeStamp>
> <ErrorCode>2016</ErrorCode>
> <ErrorText>This is Bug</ErrorText>
> </CustomErrorDetails>
> </detail>
> </soapenv:Fault>
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]