Author: ningjiang
Date: Tue Oct 23 06:28:03 2012
New Revision: 1401174
URL: http://svn.apache.org/viewvc?rev=1401174&view=rev
Log:
CAMEL-5733 Fixed the NPE with SpringBatchProducer and null header value
Modified:
camel/branches/camel-2.10.x/ (props changed)
camel/branches/camel-2.10.x/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchProducer.java
camel/branches/camel-2.10.x/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchEndpointTest.java
Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Merged /camel/trunk:r1401159-1401166
Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
camel/branches/camel-2.10.x/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchProducer.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchProducer.java?rev=1401174&r1=1401173&r2=1401174&view=diff
==============================================================================
---
camel/branches/camel-2.10.x/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchProducer.java
(original)
+++
camel/branches/camel-2.10.x/components/camel-spring-batch/src/main/java/org/apache/camel/component/spring/batch/SpringBatchProducer.java
Tue Oct 23 06:28:03 2012
@@ -56,8 +56,11 @@ public class SpringBatchProducer extends
parametersBuilder.addLong(headerKey, (Long) headerValue);
} else if (headerValue instanceof Double) {
parametersBuilder.addDouble(headerKey, (Double) headerValue);
- } else {
+ } else if (headerValue != null) {
parametersBuilder.addString(headerKey, headerValue.toString());
+ } else {
+ // if the value is null we just put String with null value
here to avoid the NPE
+ parametersBuilder.addString(headerKey, null);
}
}
return parametersBuilder.toJobParameters();
Modified:
camel/branches/camel-2.10.x/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchEndpointTest.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchEndpointTest.java?rev=1401174&r1=1401173&r2=1401174&view=diff
==============================================================================
---
camel/branches/camel-2.10.x/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchEndpointTest.java
(original)
+++
camel/branches/camel-2.10.x/components/camel-spring-batch/src/test/java/org/apache/camel/component/spring/batch/SpringBatchEndpointTest.java
Tue Oct 23 06:28:03 2012
@@ -117,6 +117,22 @@ public class SpringBatchEndpointTest ext
String parameter = jobParameters.getValue().getString(headerKey);
assertEquals(parameter, headerValue);
}
+
+ @Test
+ public void setNullValueToJobParams() throws Exception {
+ // Given
+ String headerKey = "headerKey";
+ Date headerValue = null;
+
+ // When
+ template.sendBodyAndHeader("direct:start", "Start the job, please.",
headerKey, headerValue);
+
+ // Then
+ ArgumentCaptor<JobParameters> jobParameters =
ArgumentCaptor.forClass(JobParameters.class);
+ verify(jobLauncher).run(any(Job.class), jobParameters.capture());
+ Date parameter = jobParameters.getValue().getDate(headerKey);
+ assertEquals(parameter, headerValue);
+ }
@Test
public void shouldConvertDateHeadersToJobParams() throws Exception {