Results 1 to 3 of 3

Thread: Spring batch with spring integration via http

  1. #1

    Question Spring batch with spring integration via http

    hi ..
    i am trying to configure the http adapters b/w spring batch and integration. my app (spring-batch-admin) exposes a lightweight spring integration context which launches jobs. the configs are as follows

    Code:
    <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
    
    <int-http:inbound-channel-adapter 
    id="batchHttpAdapter" 
    name="/someJobs" 
    message-converters="stringMessageConverter" 
    channel="job-launches"	
    supported-methods="POST" />
    
    <bean id="stringMessageConverter"
    class="org.springframework.http.converter.StringHttpMessageConverter" />	
    
    <int:service-activator 
    input-channel="job-launches" 
    output-channel="batchJobRequests">
    <bean	class="org.springframework.batch.admin.integration.StringToJobLaunchRequestAdapter">
       <property name="jobLocator" ref="jobRegistry" />
    </bean>
    </int:service-activator>
    
    <int:service-activator input-channel="batchJobRequests">
    <bean class="org.springframework.batch.integration.launch.JobLaunchingMessageHandler">			<constructor-arg ref="jobLauncher" /></bean>
    </int:service-activator>
    The job is launched asynchronously
    Code:
    	<task:executor id="asyncExecutor" pool-size="10"/>
    	<bean id="jobLauncher"
    	class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    		<property name="jobRepository" ref="jobRepository" />
    		<property name="taskExecutor" ref="asyncExecutor"></property>
    	</bean>
    On the client side requests are sent as follows (from another app )
    Code:
    <int-http:outbound-gateway url="http://someurl:port/spring-batch-admin/someJobs" request-channel="someChannel" http-method="POST"></int-http:outbound-gateway>
    How do i configure the client to receive the response which is the JobExecution ?

    Thanks

  2. #2
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    Probably all you need to do is use <http:inbound-gateway/> instead of <http:inbound-channel-adapter/> and provide an HttpMessageConverter that can convert the reply on the job-operator channel.

  3. #3

    Question

    yes thanks, i had figured i wud have needed a gateway. however i decided to use the already present json api in spring-batch-admin. Is there a better way of doing this invocation on the client side ?
    Code:
    String launchUrl = "http://url:port/spring-batch-admin/jobs/{jobName}.json?{jobParameters}";
    
    Map<String, String> jobConfiguration = new HashMap<String, String>();
    jobConfiguration.put("jobName", someJobNameAsString);
    String jobParameters = // get a string formatted as jobParameters=param1=val1,param2=val2...
    jobConfiguration.put("jobParameters", jobParameters);
    
    RestTemplate template = new RestTemplate();
    List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
    converters.add(new StringHttpMessageConverter());
    template.setMessageConverters(converters);
    
    String response = template.postForObject(launchURL,null,String.class , jobConfiguration);

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •