1414package com .predic8 .membrane .core .interceptor .xslt ;
1515
1616import com .predic8 .membrane .annot .*;
17+ import com .predic8 .membrane .core .exceptions .*;
1718import com .predic8 .membrane .core .exchange .*;
1819import com .predic8 .membrane .core .http .*;
1920import com .predic8 .membrane .core .interceptor .*;
2425
2526import javax .xml .transform .*;
2627import javax .xml .transform .stream .*;
28+ import java .io .*;
2729import java .util .*;
2830
2931import static com .predic8 .membrane .core .exceptions .ProblemDetails .*;
32+ import static com .predic8 .membrane .core .exceptions .ProblemDetails .internal ;
3033import static com .predic8 .membrane .core .interceptor .Interceptor .Flow .*;
3134import static com .predic8 .membrane .core .interceptor .Outcome .*;
3235import static com .predic8 .membrane .core .interceptor .Outcome .ABORT ;
36+ import static com .predic8 .membrane .core .util .ExceptionUtil .getRootCause ;
3337import static com .predic8 .membrane .core .util .text .StringUtil .*;
3438import static com .predic8 .membrane .core .util .text .TextUtil .*;
3539
@@ -70,31 +74,42 @@ private Outcome handleInternal(Exchange exc, Flow flow) {
7074 transformMsg (msg , exc .getStringProperties ());
7175 } catch (TransformerException e ) {
7276 log .debug ("" , e );
73- if (e .getMessage () != null && e .getMessage ().contains ("not allowed in prolog" )) {
77+ var cause = getRootCause (e );
78+ if (cause .getMessage () != null && cause .getMessage ().contains ("not allowed in prolog" )) {
7479 user (router .getConfiguration ().isProduction (), getDisplayName ())
7580 .title ("Content not allowed in prolog of XML input." )
7681 .detail ("Check for extra characters before the XML declaration <?xml ... ?>" )
7782 .internal ("offendingInput" , truncateAfter (msg .getBodyAsStringDecoded () + "..." , 50 ))
83+ .stacktrace (false )
7884 .buildAndSetResponse (exc );
7985 return ABORT ;
8086 }
81- if (e .getMessage () != null && e .getMessage ().contains ("is not allowed in trailing section" )) {
87+ if (cause .getMessage () != null && cause .getMessage ().contains ("is not allowed in trailing section" )) {
8288 user (router .getConfiguration ().isProduction (), getDisplayName ())
8389 .title ("Content not allowed in trailing section of XML input." )
8490 .detail ("Check for extra characters after the XML root element (after the final closing tag like </root>)." )
8591 .internal ("offendingInput" , tail (msg .getBodyAsStringDecoded (), 50 ))
92+ .stacktrace (false )
8693 .buildAndSetResponse (exc );
8794 return ABORT ;
8895 }
89- return createErrorResponse (exc ,e ,flow );
96+ if (cause .getMessage () != null && cause .getMessage ().contains ("No such file" )) {
97+ internal (router .getConfiguration ().isProduction (), getDisplayName ())
98+ .title ("XSLT transformation failed" )
99+ .detail (cause .getMessage ())
100+ .stacktrace (false )
101+ .buildAndSetResponse (exc );
102+ return ABORT ;
103+ }
104+ return createErrorResponse (exc , cause , flow );
90105 } catch (Exception e ) {
91106 log .info ("" , e );
92- return createErrorResponse (exc ,e , flow );
107+ return createErrorResponse (exc , e , flow );
93108 }
94109 return CONTINUE ;
95110 }
96111
97- private @ NotNull Outcome createErrorResponse (Exchange exc , Exception e , Flow flow ) {
112+ private @ NotNull Outcome createErrorResponse (Exchange exc , Throwable e , Flow flow ) {
98113 user (router .getConfiguration ().isProduction (), getDisplayName ())
99114 .detail ("Error transforming message!" )
100115 .exception (e )
@@ -116,8 +131,8 @@ public void init() {
116131 try {
117132 xsltTransformer = new XSLTTransformer (xslt , router , getConcurrency ());
118133 } catch (Exception e ) {
119- log .debug ("" ,e );
120- throw new ConfigurationException ("Could not create XSLT transformer" ,e );
134+ log .debug ("" , e );
135+ throw new ConfigurationException ("Could not create XSLT transformer" , e );
121136
122137 }
123138 }
0 commit comments