Announcement Announcement Module
Collapse
No announcement yet.
Using header-enricher for priority with spring-integration 2.1.0 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using header-enricher for priority with spring-integration 2.1.0

    Hello,

    I'm using spring-integration 2.1.0.

    The workflow I want to achieve is:
    1. use a header-enricher in spring xml context config to set a value for the pre-defined PRIORITY header
    2. read this value back out in downstream code using the MessageHeaders.getPriority() method.

    However, the HTML reference docs suggest using a MessagePriority enum ; the MessageHeaders.getPriority() returns an Integer; and if I try to set an integer value in XML config e.g.

    <int:header-enricher>
    <int:header name="priority" value="7" />
    </int:header-enricher>


    it seems to set it as a String value. (I've also tried name="PRIORITY" just in case it's case-sensitive. in that case MessageHeaders.getPriority() returns null.)

    Could you please let me know what the recommended approach is for setting the predefined PRIORITY Header in xml config and then reading it back downstream using MessageHeaders.getPriority().

    (I had read in other forums that it had flipped back and forth between using enums and using integer values. Not sure what the current state is).

    Thank you.

  • #2
    I looked at the XSD, and saw the header-enricher leads to the "priority" field, which leads to what I think is your answer:
    Code:
    	<xsd:simpleType name="priorityEnumeration">
    		<xsd:restriction base="xsd:token">
    			<xsd:enumeration value="HIGHEST" />
    			<xsd:enumeration value="HIGH" />
    			<xsd:enumeration value="NORMAL" />
    			<xsd:enumeration value="LOW" />
    			<xsd:enumeration value="LOWEST" />
    		</xsd:restriction>
    	</xsd:simpleType>

    Comment


    • #3
      If you want your custom priority field than name it as something different than 'priority'. For example "PRIORITY" (as you already tried) and than you can retrieve it as headers.getHeader("PRIORITY")

      Comment


      • #4
        Also, based on what was posted by @Wrangler I've raised a JIRA issue: https://jira.springsource.org/browse/INT-2412

        Comment


        • #5
          As a work-around, you can use an expression...

          Code:
          <header-enricher input-channel="in" output-channel="out">
          	<header name="priority" expression="7"/>
          </header-enricher>
          And it will be assigned as an Integer.

          Comment


          • #6
            Originally posted by Wrangler View Post
            I looked at the XSD, and saw the header-enricher leads to the "priority" field, which leads to what I think is your answer:
            Code:
            	<xsd:simpleType name="priorityEnumeration">
            		<xsd:restriction base="xsd:token">
            			<xsd:enumeration value="HIGHEST" />
            			<xsd:enumeration value="HIGH" />
            			<xsd:enumeration value="NORMAL" />
            			<xsd:enumeration value="LOW" />
            			<xsd:enumeration value="LOWEST" />
            		</xsd:restriction>
            	</xsd:simpleType>
            Hi Wrangler,

            I have tried that. Referencing version 2.1 in my xsi:schemaLocation list at the top of my spring context file. i.e.:

            http://www.springframework.org/schema/integration
            http://www.springframework.org/schem...ration-2.1.xsd


            I've tried :


            <int:header-enricher input-channel="myInputChannel" output-channel="myOutputChannel">
            <int:header name="priority" value="HIGH" />
            </int:header-enricher>


            The error I get when running my integration test is :

            Incorrect type specified for header 'priority'. Expected [class java.lang.Integer] but actual type is [class java.lang.String]


            I'm going to try Gary Russell's suggestion. Else I'll create a custom priority field as suggested by Oleg Zhurakousky.

            Thanks.

            Comment


            • #7
              Thanks Gary. Yes, using your suggestion worked. i.e.

              <header-enricher input-channel="in" output-channel="out">
              <header name="priority" expression="7"/>
              </header-enricher>
              Last edited by utcs; Jan 23rd, 2012, 05:03 AM. Reason: referencing Gary's suggestion, as otherwise hard to tell what I'm referring to.

              Comment


              • #8
                Just to put a finishing touch on this one priority is set to Integer regardless if 'expression' or 'value' is used. In fact the exception that was mentioned earlier proves the fact that it is set as Integer. And we actually have tests (e.g., HeaderEnricherOverwriteTests.java) where it is validated.
                So the real confusion is the schema which I am about to fix

                Comment


                • #9
                  could related documentation be updated too?

                  Originally posted by oleg.zhurakousky View Post
                  Just to put a finishing touch on this one priority is set to Integer regardless if 'expression' or 'value' is used. In fact the exception that was mentioned earlier proves the fact that it is set as Integer. And we actually have tests (e.g., HeaderEnricherOverwriteTests.java) where it is validated.
                  So the real confusion is the schema which I am about to fix
                  Hi Oleg,

                  Thanks for your help. Also just to point out what initially led to my confusion - the following sections of the online documentation, which refer to the enum values for the default priority header.

                  4.1.2
                  http://static.springsource.org/sprin...essage-headers

                  4.1.4
                  http://static.springsource.org/sprin...essage-builder

                  6.2.2
                  http://static.springsource.org/sprin...eader-enricher

                  If these could be updated too, that will help others who intend to use the default priority header.

                  Thanks!
                  Last edited by utcs; Feb 1st, 2012, 09:47 AM. Reason: typos

                  Comment


                  • #10
                    Good point!
                    I'll fix the docs as well

                    Comment


                    • #11
                      Yes; if you use
                      Code:
                      <header-enricher input-channel="replyChannelInput" output-channel="echoInput">
                      	<priority value="2"/>
                      </header-enricher>
                      You get an Integer. But if you do what the OP did

                      Code:
                      <header-enricher input-channel="in" output-channel="out">
                      	<header name="priority" value="7"/>
                      </header-enricher>
                      You get a String (you can fix this with an expression).

                      Given that we have a well-known header <priority/>, that works correctly (aside from the schema issue), that is a better way to solve the issue than using an expression.

                      Comment


                      • #12
                        By the way, another solution is to explicitly type the header...

                        Code:
                        	<header name="priority" value="7" type="java.lang.Integer" />

                        Comment


                        • #13
                          Good catch Gary, but we can actually fix that as well. Look at MessageBuilder.verifyType(..). So I'll fix it and will add a test to MessageBuilderTests

                          Comment

                          Working...
                          X