Camel
  1. Camel
  2. CAMEL-4576

Make exception throwing as flexible in XML as in Java DSL

    Details

    • Estimated Complexity:
      Unknown

      Description

      When throwing exceptions there are more options in the java DSL (one has full control) than in the XML where you can only reference an exception instance.

      It would be useful to be able to construct the exception and throw it, so that one could add messages to it - preferably like:

      throwException class="someEx" message="someProblem ${body} ${in.header.someHeader}
      

      Reference: http://camel.apache.org/exception-clause.html

        Activity

        Hide
        David J. M. Karlsen added a comment -

        Yes - I've checked - it's actually what I'm referring to in the issue.
        But it's not possible to "You can initialize your exception as you " - because it refers to one pre-instanciated instance - which is not flexible - hence the expression $

        {body}

        in my suggestion for improvement.

        Show
        David J. M. Karlsen added a comment - Yes - I've checked - it's actually what I'm referring to in the issue. But it's not possible to "You can initialize your exception as you " - because it refers to one pre-instanciated instance - which is not flexible - hence the expression $ {body} in my suggestion for improvement.
        Hide
        Claus Ibsen added a comment -

        You wanna create a new exception instance on the fly and provide a String for its constructor. And that String parameter is constructed using the Simple language.

        Which use-case do you need this for? Eg to use <throwException> in a Camel route?

        Show
        Claus Ibsen added a comment - You wanna create a new exception instance on the fly and provide a String for its constructor. And that String parameter is constructed using the Simple language. Which use-case do you need this for? Eg to use <throwException> in a Camel route?
        Hide
        David J. M. Karlsen added a comment - - edited

        Yes - I want to do a conditional check in a step - and given that it evaluates throw an arbitrary exception with arbitrary parameters (using for instance the bean binding stuff for the params).

        Something like

        <camel:when>
        	<camel:setBody>{in.body.args[0].myGet}</camel:setBody>
        	<camel:simple>bean:mySpringbean?method=isOffline( ${in.header.name} )</camel:simple>
                <camel:throwException expression="com.company.SomeException( ${in.header.someHeader} is offline) ">
        </camel:when>
        

        really looking forward to the 2.9.x beanBinding stuff - it looks very powerful.

        Show
        David J. M. Karlsen added a comment - - edited Yes - I want to do a conditional check in a step - and given that it evaluates throw an arbitrary exception with arbitrary parameters (using for instance the bean binding stuff for the params). Something like <camel:when> <camel:setBody>{in.body.args[0].myGet}</camel:setBody> <camel:simple>bean:mySpringbean?method=isOffline( ${in.header.name} )</camel:simple> <camel:throwException expression="com.company.SomeException( ${in.header.someHeader} is offline) "> </camel:when> really looking forward to the 2.9.x beanBinding stuff - it looks very powerful.
        Hide
        John Mark added a comment -

        I am also looking for the same feature. I am doing some conditional routing in Java DSL and would like to throw an informative exception for unexpected conditions. I don't see any way to do this in Java DSL either. The .throwException() method just takes an exception. I did not see any way to use Simple to build the exception message.

        Show
        John Mark added a comment - I am also looking for the same feature. I am doing some conditional routing in Java DSL and would like to throw an informative exception for unexpected conditions. I don't see any way to do this in Java DSL either. The .throwException() method just takes an exception. I did not see any way to use Simple to build the exception message.

          People

          • Assignee:
            Unassigned
            Reporter:
            David J. M. Karlsen
          • Votes:
            3 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:

              Development