Announcement Announcement Module
Collapse
No announcement yet.
How to throw customized exceptions ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to throw customized exceptions ?

    Hi

    I would like to know if there is any out-of-box component that supports to allow user to throw an explicit customized runtime exception from spring config file ?

    To elaborate, I've a header-value-router.
    What I want is based on a specific header-value, I need to throw a specific customized exception.

    Is this something possible ?

  • #2
    Code:
    <int:service-activator input-channel="input" output-channel="next">
    	<int-groovy:script>
    		if (headers['foo'] == 'bar') {
    			throw new foo.MyException("header foo == bar");
    		}
    		payload
    	</int-groovy:script>
    </int:service-activator>
    Last edited by Gary Russell; Jul 14th, 2013, 11:48 PM.

    Comment


    • #3
      Thanks Gary.

      To be more specific, I want my message to be "routed" first (based on header-value) and then take decision of throwing an exception or not.

      To achieve it, will the below configuration hold good ?

      Code:
      <int:header-value-router input-channel="routingChannel" header-name="testHeader">
          <int:mapping value="someHeaderValue" channel="channelA" />
          <int:mapping value="someOtherHeaderValue" channel="channelB" />
      </int:header-value-router>
      
      <int:service-activator input-channel="channelB">
      	<int-groovy:script>
      			throw new foo.MyException("My customized runtime exception message");
      	</int-groovy:script>
      </int:service-activator>
      Also I've a global "error-channel" defined at my Gateway. Throwing this exception from my groovy-script will land my message (wrapped as MessagingException) on my global error-channel ?

      Best Regards
      LB

      Comment


      • #4
        Yes and yes.

        The ErrorMessage on the error channel will have a MessagingException payload (with failedMessage and cause as usual).

        Comment


        • #5
          What is the namespace support for int-groovy element ? I'm unable to find its namespace definition in Reference Manual.

          Regards
          LB
          Last edited by lbvirgo; Jul 15th, 2013, 06:51 AM.

          Comment


          • #6
            Hi!
            What is the namespace support for int-groovy element ?
            http://static.springsource.org/sprin...single/#groovy
            https://github.com/SpringSource/spri...ion-config.xml
            You have to add to your dependency spring-integration-scripting and spring-integration-groovy jars.

            Take care,
            Artem

            Comment


            • #7
              Many thanks.

              Would have been great if the namespace definition was mentioned in Reference Manual as well.

              Best Regards
              LB

              Comment


              • #8
                if the namespace definition was mentioned in Reference Manual as well
                Sounds good.
                So, feel free to raise a JIRA ticket to address that issue: https://jira.springsource.org/browse/INT
                I see in the RM a lot of adapters' chapters haven't got a note regarding their namespace...

                Comment


                • #9
                  You have to add to your dependency spring-integration-scripting and spring-integration-groovy jars
                  Just adding groovy should be sufficient; scripting will be pulled in transitively.

                  Code:
                  <dependency>
                  	<groupId>org.springframework.integration</groupId>
                  	<artifactId>spring-integration-groovy</artifactId>
                  	<version>${spring.integration.version}</version>
                  </dependency>
                  I agree that the reference manual should include it.

                  That said, they all have the same pattern and, you can always look them up in the jar's META-INF/spring.handlers file, with the schemaLocation being in the META-INF/spring.schemas file.

                  Also, if you use the Spring Tool Suite (STS), once you've added the jar to the classpath, click on the 'Namspaces' tab in the XML editor and it will be available for selection (if the file was already open before you add the new jar to the pom, you might have to close and reopen the file).

                  I am sure IntelliJ has some similar support.

                  I don't think I have ever manually typed in that stuff.

                  Comment


                  • #10
                    I don't think I have ever manually typed in that stuff.
                    Right. The IDE does the stuff .

                    I am sure IntelliJ has some similar support.
                    IntelliJ IDEA has build-in Spring Integration plugin (since version 12). And when I add to the confing some custom tag from SI (e.g. <int-gfe:outbound-channel-adapter>), the IDE suggests me to import concrate namespace.

                    So, LB, try to enjoy your work!

                    Comment


                    • #11
                      So, LB, try to enjoy your work!
                      Indeed, I'm ! The journey has been very exciting so-far with SI !

                      Comment

                      Working...
                      X