You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by "James Mello (JIRA)" <ji...@apache.org> on 2008/09/05 20:23:52 UTC

[jira] Created: (CAMEL-880) Headers lost when using scriptBuilder to set headers dynamically

Headers lost when using scriptBuilder to set headers dynamically
----------------------------------------------------------------

                 Key: CAMEL-880
                 URL: https://issues.apache.org/activemq/browse/CAMEL-880
             Project: Apache Camel
          Issue Type: Bug
          Components: camel-script
    Affects Versions: 1.4.0
            Reporter: James Mello


When running a dynamic script evaluation in a setHeader, the header is lost as the Pipeline chain uses the data from the out body as the source of headers. 

So trying to figure this out, I looked into the source, and found that if the getOut is not null, the out message is used to set the header in the setHeader processor. Unfortunately in the script engine this block of code always ensures that it's NOT null. 

script builder class line 520 of Camel 1.4 

        ScriptContext context = engine.getContext(); 
        int scope = ScriptContext.ENGINE_SCOPE; 
        context.setAttribute("context", exchange.getContext(), scope); 
        context.setAttribute("exchange", exchange, scope); 
        context.setAttribute("request", exchange.getIn(), scope); 
        context.setAttribute("response", exchange.getOut(), scope); 

The place were the out message is used is here in the Pipeline class at line 79 

            if (first) { 
                first = false; 
            } else { 
                nextExchange = createNextExchange(processor, nextExchange); 
            } 

The specifics of my setup were:

Used spring with the following configuration:

	<camel:camelContext>
		<camel:route>
			<camel:from uri="jms://LLAQueue?disableReplyTo=true" />
			<camel:setHeader headerName="activity.type">
				<camel:jxpath>exchange.getIn().getBody().getExerciseHighLevelActivity().getActivityType()</camel:jxpath>
			</camel:setHeader>
			<camel:choice>
				<camel:when>
					<camel:javaScript>
						exchange.getIn().getHeader('activity.type') == 3
					</camel:javaScript>
					<camel:transform>
						<camel:javaScript>
							exchange.getIn().getBody().getData() !=
							undefined ?
							exchange.getIn().getBody().getData() : ""
						</camel:javaScript>
					</camel:transform>
					<camel:to uri="log:info?showAll=true" />
				</camel:when>
			</camel:choice>
		</camel:route>
	</camel:camelContext>

I did not test this problem with other exchange types, just the JMS type.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (CAMEL-880) Headers lost when using scriptBuilder to set headers dynamically

Posted by "Willem Jiang (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-880?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Willem Jiang resolved CAMEL-880.
--------------------------------

    Fix Version/s: 1.5.0
       Resolution: Fixed

Just committed a quick fix for it.

> Headers lost when using scriptBuilder to set headers dynamically
> ----------------------------------------------------------------
>
>                 Key: CAMEL-880
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-880
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-script
>    Affects Versions: 1.4.0
>            Reporter: James Mello
>            Assignee: Willem Jiang
>             Fix For: 1.5.0
>
>
> When running a dynamic script evaluation in a setHeader, the header is lost as the Pipeline chain uses the data from the out body as the source of headers. 
> So trying to figure this out, I looked into the source, and found that if the getOut is not null, the out message is used to set the header in the setHeader processor. Unfortunately in the script engine this block of code always ensures that it's NOT null. 
> script builder class line 520 of Camel 1.4 
>         ScriptContext context = engine.getContext(); 
>         int scope = ScriptContext.ENGINE_SCOPE; 
>         context.setAttribute("context", exchange.getContext(), scope); 
>         context.setAttribute("exchange", exchange, scope); 
>         context.setAttribute("request", exchange.getIn(), scope); 
>         context.setAttribute("response", exchange.getOut(), scope); 
> The place were the out message is used is here in the Pipeline class at line 79 
>             if (first) { 
>                 first = false; 
>             } else { 
>                 nextExchange = createNextExchange(processor, nextExchange); 
>             } 
> The specifics of my setup were:
> Used spring with the following configuration:
> 	<camel:camelContext>
> 		<camel:route>
> 			<camel:from uri="jms://LLAQueue?disableReplyTo=true" />
> 			<camel:setHeader headerName="activity.type">
> 				<camel:jxpath>exchange.getIn().getBody().getExerciseHighLevelActivity().getActivityType()</camel:jxpath>
> 			</camel:setHeader>
> 			<camel:choice>
> 				<camel:when>
> 					<camel:javaScript>
> 						exchange.getIn().getHeader('activity.type') == 3
> 					</camel:javaScript>
> 					<camel:transform>
> 						<camel:javaScript>
> 							exchange.getIn().getBody().getData() !=
> 							undefined ?
> 							exchange.getIn().getBody().getData() : ""
> 						</camel:javaScript>
> 					</camel:transform>
> 					<camel:to uri="log:info?showAll=true" />
> 				</camel:when>
> 			</camel:choice>
> 		</camel:route>
> 	</camel:camelContext>
> I did not test this problem with other exchange types, just the JMS type.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (CAMEL-880) Headers lost when using scriptBuilder to set headers dynamically

Posted by "Willem Jiang (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-880?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45486#action_45486 ] 

njiang edited comment on CAMEL-880 at 9/5/08 8:18 PM:
------------------------------------------------------------

This issue is easy to fix. 
{code}
 // change 
 context.setAttribute("response", exchange.getOut(), scope); 
  // to 
 context.setAttribute("response", exchange.getOut(false), scope); 
{code}
In this way a new out message will not be create if the exchange's out message is not be set.

I will add new test to verify my change.

      was (Author: njiang):
    This issue is easy to fix. 
{code}
  context.setAttribute("response", exchange.getOut(), scope); 
  // to 
 context.setAttribute("response", exchange.getOut(false), scope); 
{code}
In this way a new out message will not be create if the exchange's out message is not be set.

I will add new test to verify my change.
  
> Headers lost when using scriptBuilder to set headers dynamically
> ----------------------------------------------------------------
>
>                 Key: CAMEL-880
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-880
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-script
>    Affects Versions: 1.4.0
>            Reporter: James Mello
>            Assignee: Willem Jiang
>             Fix For: 1.5.0
>
>
> When running a dynamic script evaluation in a setHeader, the header is lost as the Pipeline chain uses the data from the out body as the source of headers. 
> So trying to figure this out, I looked into the source, and found that if the getOut is not null, the out message is used to set the header in the setHeader processor. Unfortunately in the script engine this block of code always ensures that it's NOT null. 
> script builder class line 520 of Camel 1.4 
>         ScriptContext context = engine.getContext(); 
>         int scope = ScriptContext.ENGINE_SCOPE; 
>         context.setAttribute("context", exchange.getContext(), scope); 
>         context.setAttribute("exchange", exchange, scope); 
>         context.setAttribute("request", exchange.getIn(), scope); 
>         context.setAttribute("response", exchange.getOut(), scope); 
> The place were the out message is used is here in the Pipeline class at line 79 
>             if (first) { 
>                 first = false; 
>             } else { 
>                 nextExchange = createNextExchange(processor, nextExchange); 
>             } 
> The specifics of my setup were:
> Used spring with the following configuration:
> 	<camel:camelContext>
> 		<camel:route>
> 			<camel:from uri="jms://LLAQueue?disableReplyTo=true" />
> 			<camel:setHeader headerName="activity.type">
> 				<camel:jxpath>exchange.getIn().getBody().getExerciseHighLevelActivity().getActivityType()</camel:jxpath>
> 			</camel:setHeader>
> 			<camel:choice>
> 				<camel:when>
> 					<camel:javaScript>
> 						exchange.getIn().getHeader('activity.type') == 3
> 					</camel:javaScript>
> 					<camel:transform>
> 						<camel:javaScript>
> 							exchange.getIn().getBody().getData() !=
> 							undefined ?
> 							exchange.getIn().getBody().getData() : ""
> 						</camel:javaScript>
> 					</camel:transform>
> 					<camel:to uri="log:info?showAll=true" />
> 				</camel:when>
> 			</camel:choice>
> 		</camel:route>
> 	</camel:camelContext>
> I did not test this problem with other exchange types, just the JMS type.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (CAMEL-880) Headers lost when using scriptBuilder to set headers dynamically

Posted by "Willem Jiang (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-880?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Willem Jiang reassigned CAMEL-880:
----------------------------------

    Assignee: Willem Jiang

> Headers lost when using scriptBuilder to set headers dynamically
> ----------------------------------------------------------------
>
>                 Key: CAMEL-880
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-880
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-script
>    Affects Versions: 1.4.0
>            Reporter: James Mello
>            Assignee: Willem Jiang
>
> When running a dynamic script evaluation in a setHeader, the header is lost as the Pipeline chain uses the data from the out body as the source of headers. 
> So trying to figure this out, I looked into the source, and found that if the getOut is not null, the out message is used to set the header in the setHeader processor. Unfortunately in the script engine this block of code always ensures that it's NOT null. 
> script builder class line 520 of Camel 1.4 
>         ScriptContext context = engine.getContext(); 
>         int scope = ScriptContext.ENGINE_SCOPE; 
>         context.setAttribute("context", exchange.getContext(), scope); 
>         context.setAttribute("exchange", exchange, scope); 
>         context.setAttribute("request", exchange.getIn(), scope); 
>         context.setAttribute("response", exchange.getOut(), scope); 
> The place were the out message is used is here in the Pipeline class at line 79 
>             if (first) { 
>                 first = false; 
>             } else { 
>                 nextExchange = createNextExchange(processor, nextExchange); 
>             } 
> The specifics of my setup were:
> Used spring with the following configuration:
> 	<camel:camelContext>
> 		<camel:route>
> 			<camel:from uri="jms://LLAQueue?disableReplyTo=true" />
> 			<camel:setHeader headerName="activity.type">
> 				<camel:jxpath>exchange.getIn().getBody().getExerciseHighLevelActivity().getActivityType()</camel:jxpath>
> 			</camel:setHeader>
> 			<camel:choice>
> 				<camel:when>
> 					<camel:javaScript>
> 						exchange.getIn().getHeader('activity.type') == 3
> 					</camel:javaScript>
> 					<camel:transform>
> 						<camel:javaScript>
> 							exchange.getIn().getBody().getData() !=
> 							undefined ?
> 							exchange.getIn().getBody().getData() : ""
> 						</camel:javaScript>
> 					</camel:transform>
> 					<camel:to uri="log:info?showAll=true" />
> 				</camel:when>
> 			</camel:choice>
> 		</camel:route>
> 	</camel:camelContext>
> I did not test this problem with other exchange types, just the JMS type.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-880) Headers lost when using scriptBuilder to set headers dynamically

Posted by "Willem Jiang (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-880?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45486#action_45486 ] 

Willem Jiang commented on CAMEL-880:
------------------------------------

This issue is easy to fix. 
{code|language=java}
  context.setAttribute("response", exchange.getOut(), scope); 
  // to 
 context.setAttribute("response", exchange.getOut(false), scope); 
{code}
In this way a new out message will not be create if the exchange's out message is not be set.

I will add new test to verify my change.

> Headers lost when using scriptBuilder to set headers dynamically
> ----------------------------------------------------------------
>
>                 Key: CAMEL-880
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-880
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-script
>    Affects Versions: 1.4.0
>            Reporter: James Mello
>
> When running a dynamic script evaluation in a setHeader, the header is lost as the Pipeline chain uses the data from the out body as the source of headers. 
> So trying to figure this out, I looked into the source, and found that if the getOut is not null, the out message is used to set the header in the setHeader processor. Unfortunately in the script engine this block of code always ensures that it's NOT null. 
> script builder class line 520 of Camel 1.4 
>         ScriptContext context = engine.getContext(); 
>         int scope = ScriptContext.ENGINE_SCOPE; 
>         context.setAttribute("context", exchange.getContext(), scope); 
>         context.setAttribute("exchange", exchange, scope); 
>         context.setAttribute("request", exchange.getIn(), scope); 
>         context.setAttribute("response", exchange.getOut(), scope); 
> The place were the out message is used is here in the Pipeline class at line 79 
>             if (first) { 
>                 first = false; 
>             } else { 
>                 nextExchange = createNextExchange(processor, nextExchange); 
>             } 
> The specifics of my setup were:
> Used spring with the following configuration:
> 	<camel:camelContext>
> 		<camel:route>
> 			<camel:from uri="jms://LLAQueue?disableReplyTo=true" />
> 			<camel:setHeader headerName="activity.type">
> 				<camel:jxpath>exchange.getIn().getBody().getExerciseHighLevelActivity().getActivityType()</camel:jxpath>
> 			</camel:setHeader>
> 			<camel:choice>
> 				<camel:when>
> 					<camel:javaScript>
> 						exchange.getIn().getHeader('activity.type') == 3
> 					</camel:javaScript>
> 					<camel:transform>
> 						<camel:javaScript>
> 							exchange.getIn().getBody().getData() !=
> 							undefined ?
> 							exchange.getIn().getBody().getData() : ""
> 						</camel:javaScript>
> 					</camel:transform>
> 					<camel:to uri="log:info?showAll=true" />
> 				</camel:when>
> 			</camel:choice>
> 		</camel:route>
> 	</camel:camelContext>
> I did not test this problem with other exchange types, just the JMS type.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (CAMEL-880) Headers lost when using scriptBuilder to set headers dynamically

Posted by "Willem Jiang (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-880?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45486#action_45486 ] 

njiang edited comment on CAMEL-880 at 9/5/08 8:17 PM:
------------------------------------------------------------

This issue is easy to fix. 
{code}
  context.setAttribute("response", exchange.getOut(), scope); 
  // to 
 context.setAttribute("response", exchange.getOut(false), scope); 
{code}
In this way a new out message will not be create if the exchange's out message is not be set.

I will add new test to verify my change.

      was (Author: njiang):
    This issue is easy to fix. 
{code|language=java}
  context.setAttribute("response", exchange.getOut(), scope); 
  // to 
 context.setAttribute("response", exchange.getOut(false), scope); 
{code}
In this way a new out message will not be create if the exchange's out message is not be set.

I will add new test to verify my change.
  
> Headers lost when using scriptBuilder to set headers dynamically
> ----------------------------------------------------------------
>
>                 Key: CAMEL-880
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-880
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-script
>    Affects Versions: 1.4.0
>            Reporter: James Mello
>            Assignee: Willem Jiang
>
> When running a dynamic script evaluation in a setHeader, the header is lost as the Pipeline chain uses the data from the out body as the source of headers. 
> So trying to figure this out, I looked into the source, and found that if the getOut is not null, the out message is used to set the header in the setHeader processor. Unfortunately in the script engine this block of code always ensures that it's NOT null. 
> script builder class line 520 of Camel 1.4 
>         ScriptContext context = engine.getContext(); 
>         int scope = ScriptContext.ENGINE_SCOPE; 
>         context.setAttribute("context", exchange.getContext(), scope); 
>         context.setAttribute("exchange", exchange, scope); 
>         context.setAttribute("request", exchange.getIn(), scope); 
>         context.setAttribute("response", exchange.getOut(), scope); 
> The place were the out message is used is here in the Pipeline class at line 79 
>             if (first) { 
>                 first = false; 
>             } else { 
>                 nextExchange = createNextExchange(processor, nextExchange); 
>             } 
> The specifics of my setup were:
> Used spring with the following configuration:
> 	<camel:camelContext>
> 		<camel:route>
> 			<camel:from uri="jms://LLAQueue?disableReplyTo=true" />
> 			<camel:setHeader headerName="activity.type">
> 				<camel:jxpath>exchange.getIn().getBody().getExerciseHighLevelActivity().getActivityType()</camel:jxpath>
> 			</camel:setHeader>
> 			<camel:choice>
> 				<camel:when>
> 					<camel:javaScript>
> 						exchange.getIn().getHeader('activity.type') == 3
> 					</camel:javaScript>
> 					<camel:transform>
> 						<camel:javaScript>
> 							exchange.getIn().getBody().getData() !=
> 							undefined ?
> 							exchange.getIn().getBody().getData() : ""
> 						</camel:javaScript>
> 					</camel:transform>
> 					<camel:to uri="log:info?showAll=true" />
> 				</camel:when>
> 			</camel:choice>
> 		</camel:route>
> 	</camel:camelContext>
> I did not test this problem with other exchange types, just the JMS type.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.