Stack Exchange
How to make post request in apache camel rest
I am new apache rest dsl with spring boot, have made following changes
Main Class
package com.javaoutofbounds.pojo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(scanBasePackages = {"com.ccs.batchfile"})
public class BatchFileApplication {

    public static void main(String[] args) {
        SpringApplication.run(BatchFileApplication.class, args);
    }
}

Service class
package com.ccs.batchfile.service;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.rest.RestBindingMode;
import org.springframework.stereotype.Component;

@Component
public class BatchFileService extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        restConfiguration().component("servlet").bindingMode(RestBindingMode.json);
        rest("/batchFile").consumes("application/json").produces("application/json").get("/routeStart").to("direct:startRoute");
    }

}

Route class
package com.ccs.batchfile.routes;

import org.apache.camel.builder.RouteBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ccs.batchfile.processor.StartRouteProcessor;

@Component
public class StartRoute  extends RouteBuilder{

     @Autowired
     private StartRouteProcessor startRouteProcessor;

    @Override
    public void configure() throws Exception {
        from("direct:startRoute").log("Inside StartRoute")
        .process(startRouteProcessor);
    }

}

Processor class
package com.ccs.batchfile.processor;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.springframework.stereotype.Component;

@Component("startRouteProcessor")
public class StartRouteProcessor implements Processor{

    public void process(Exchange exchange) throws Exception {
        String message = exchange.getIn().getBody(String.class);
        System.out.println(message);
    }

}

I am not getting control to StartRouteProcessor, when i make below post request in postman
http://localhost:8080/batchFile/routeStart/
I have used below test payload to check if works.
{
 "title" : "test title",
 "singer" : "some singer"
}

When i post the above request i am getting 404 error. Kindly help on this please

I tried your example and you need to add two changes.
In your "main" class, the 'component scan' annotation is right, but you have to add a 'ServletRegistrationBean' with name 'CamelServlet':
package org.funcode.app.main;

import org.apache.camel.component.servlet.CamelHttpTransportServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;

@SpringBootApplication(scanBasePackages = {"org.funcode.app"})
public class BatchFileApplication {

    private static final String CAMEL_URL_MAPPING = "/api/*";
    private static final String CAMEL_SERVLET_NAME = "CamelServlet";

    public static void main(String[] args) {
        SpringApplication.run(BatchFileApplication.class, args);
    }

    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        ServletRegistrationBean registration =
                new ServletRegistrationBean(new CamelHttpTransportServlet(), CAMEL_URL_MAPPING);
        registration.setName(CAMEL_SERVLET_NAME);
        return registration;
    }
}

And if you want view on the log the content you posted on the request, you need to change the method of the request to "post":
package org.funcode.app.main;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.rest.RestBindingMode;
import org.springframework.stereotype.Component;

@Component
public class BatchFileService extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        restConfiguration().component("servlet").bindingMode(RestBindingMode.json);

        rest("/batchFile")
            .consumes("application/json")
            .produces("application/json")
            .post("/routeStart")
            .to("direct:startRoute");
    }
}

I hope it helps.
