Camel
  1. Camel
  2. CAMEL-4312

Print reason for XSL stylesheet compile failure

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.6.0
    • Fix Version/s: 2.8.2, 2.9.0
    • Component/s: camel-core
    • Labels:
      None
    • Environment:

      ServiceMix 4.3.1-fuse-01-22

    • Patch Info:
      Patch Available
    • Estimated Complexity:
      Novice

      Description

      Failure to compile a resource in an xslt:// URL leads to this error message:

      org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToCreateRouteException: Failed to create route route39 at: >>> To[xslt://foo.xslt] <<< in route: Route[[From[direct:foo]] -> [To[xslt://foo.xslt... because of Failed to resolve endpoint: xslt://foo.xslt due to:
      Could not compile stylesheet class path resource [foo.xslt]
      ...

      Caused by: javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:877)[:]
      at org.apache.camel.builder.xml.XsltBuilder.setTransformerSource(XsltBuilder.java:252)[68:org.apache.camel.camel-core:2.6.0.fuse-01-22]
      at org.apache.camel.builder.xml.XsltBuilder.setTransformerInputStream(XsltBuilder.java:282)[68:org.apache.camel.camel-core:2.6.0.fuse-01-22]
      at org.apache.camel.component.xslt.XsltComponent.loadResource(XsltComponent.java:156)[75:org.apache.camel.camel-spring:2.6.0.fuse-01-22]
      ... 33 more

      Which is completely correct, but doesn't provide much of a hint as to how to fix my stylesheet

      1. CAMEL-4312-patch.txt
        8 kB
        Ioannis Canellos

        Activity

        Hide
        Michael Smith added a comment -

        The current exception logging was added in CAMEL-457 and CAMEL-3313

        Show
        Michael Smith added a comment - The current exception logging was added in CAMEL-457 and CAMEL-3313
        Hide
        Willem Jiang added a comment -

        I just checked the code of org.apache.camel.builder.xml.XsltBuilder.setTransformerSource,
        the exception is thrown from xalan, I don't think we can add more information about it in Camel.

        Show
        Willem Jiang added a comment - I just checked the code of org.apache.camel.builder.xml.XsltBuilder.setTransformerSource, the exception is thrown from xalan, I don't think we can add more information about it in Camel.
        Hide
        Michael Smith added a comment -

        I had a quick look at the Xalan source in the JDK. Looks like you'd just need to call setErrorListener() on the TransformerFactory and pass in a javax.xml.transform.ErrorListener. Otherwise the errors are only printed to stderr.

            /**
             * javax.xml.transform.sax.TransformerFactory implementation.
             * Set the error event listener for the TransformerFactory, which is used
             * for the processing of transformation instructions, and not for the
             * transformation itself.
             *
             * @param listener The error listener to use with the TransformerFactory
             * @throws IllegalArgumentException
             */
            public void setErrorListener(ErrorListener listener)
        

        http://download.oracle.com/docs/cd/E17802_01/webservices/webservices/docs/1.6/api/javax/xml/transform/ErrorListener.html

        Show
        Michael Smith added a comment - I had a quick look at the Xalan source in the JDK. Looks like you'd just need to call setErrorListener() on the TransformerFactory and pass in a javax.xml.transform.ErrorListener. Otherwise the errors are only printed to stderr. /** * javax.xml.transform.sax.TransformerFactory implementation. * Set the error event listener for the TransformerFactory, which is used * for the processing of transformation instructions, and not for the * transformation itself. * * @param listener The error listener to use with the TransformerFactory * @ throws IllegalArgumentException */ public void setErrorListener(ErrorListener listener) http://download.oracle.com/docs/cd/E17802_01/webservices/webservices/docs/1.6/api/javax/xml/transform/ErrorListener.html
        Hide
        Claus Ibsen added a comment -

        Michael do you want to try an attempt to fix this with a patch? For example you could try if the ErrorListener is invoked with any useable information when a XSL cannot be compiled.

        Show
        Claus Ibsen added a comment - Michael do you want to try an attempt to fix this with a patch? For example you could try if the ErrorListener is invoked with any useable information when a XSL cannot be compiled.
        Hide
        Ioannis Canellos added a comment -

        I tested it and it seems that the ErrorListener is invoked and passed an Exception which contains the line and the error that was found.

        I will work on patch for it.

        Show
        Ioannis Canellos added a comment - I tested it and it seems that the ErrorListener is invoked and passed an Exception which contains the line and the error that was found. I will work on patch for it.
        Hide
        Ioannis Canellos added a comment -

        I am attaching a patch which adds an ErrorListener implementation which logs the line and the error where the line is found. Also adds a unit test which checks the invocation of these methods.

        Show
        Ioannis Canellos added a comment - I am attaching a patch which adds an ErrorListener implementation which logs the line and the error where the line is found. Also adds a unit test which checks the invocation of these methods.
        Hide
        Claus Ibsen added a comment -

        Ioannis thanks for the patch.

        Could you read about building with checkstyle here:
        http://camel.apache.org/building.html

        As the source code in Camel should pass the checkstyle. So I had to refine a bit in your patch.

        Show
        Claus Ibsen added a comment - Ioannis thanks for the patch. Could you read about building with checkstyle here: http://camel.apache.org/building.html As the source code in Camel should pass the checkstyle. So I had to refine a bit in your patch.

          People

          • Assignee:
            Ioannis Canellos
            Reporter:
            Michael Smith
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development