@Override public void configure() throws Exception { from("restlet:http://0.0.0.0:8080/orders?restletMethods=POST") .bean("orderService", "createOrder"); from("restlet:http://0.0.0.0:8080/orders/{id}?restletMethods=GET") .bean("orderService", "getOrder(${header.id})"); from("restlet:http://0.0.0.0:8080/orders?restletMethods=PUT") .bean("orderService", "updateOrder"); from("restlet:http://0.0.0.0:8080/orders/{id}?restletMethods=DELETE") .bean("orderService", "cancelOrder(${header.id})"); } }
public static void main(String[] args) throws Exception { Main main = new Main(); // setup a dummy order service main.bind("orderService", new DummyOrderService()); // add the order route with the Rest services main.addRouteBuilder(new OrderRoute()); System.out.println("***************************************************"); System.out.println(""); System.out.println(" Rider Auto Parts REST order service"); System.out.println(""); System.out.println(" You can try calling this service using:"); System.out.println(" http://localhost:8080/orders/1"); System.out.println(" http://localhost:8080/orders/2"); System.out.println(""); System.out.println(" The Swagger API:"); System.out.println(" http://localhost:8080/api-doc/swagger.json"); System.out.println(" http://localhost:8080/api-doc/swagger.yaml"); System.out.println("***************************************************"); // run the application main.run(); } }
@Override public void configure() throws Exception { // enable Jackson json type converter getContext().getProperties().put("CamelJacksonEnableTypeConverter", "true"); // allow Jackson json to convert to pojo types also getContext().getProperties().put("CamelJacksonTypeConverterToPojo", "true"); from("restlet:http://0.0.0.0:8080/orders?restletMethods=POST") .bean("orderService", "createOrder"); from("restlet:http://0.0.0.0:8080/orders/{id}?restletMethods=GET") .bean("orderService", "getOrder(${header.id})"); from("restlet:http://0.0.0.0:8080/orders?restletMethods=PUT") .bean("orderService", "updateOrder"); from("restlet:http://0.0.0.0:8080/orders/{id}?restletMethods=DELETE") .bean("orderService", "cancelOrder(${header.id})"); } }
restConfiguration() onException(OrderInvalidException.class) .handled(true) .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(400)) .setBody(constant("")); onException(OrderNotFoundException.class) .handled(true) .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(404)) .setBody(constant("")); onException(Exception.class) .handled(true) .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500)) .setBody(simple("${exception.message}\n")); rest("/orders")
@Override public void configure() throws Exception { // configure rest-dsl restConfiguration() // to use spark-rest component and run on port 8080 .component("spark-rest").port(8080); // rest services under the orders context-path rest("/orders") .get("{id}") .to("bean:orderService?method=getOrder(${header.id})") .post() .to("bean:orderService?method=createOrder") .put() .to("bean:orderService?method=updateOrder") .delete("{id}") .to("bean:orderService?method=cancelOrder(${header.id})"); } }
@Override public void configure() throws Exception { // see the application.properties file for setup of the rest configuration // rest services under the orders context-path rest("/orders") // need to specify the POJO types the binding is using (otherwise json binding defaults to Map based) .get("{id}").outType(Order.class) .to("bean:orderService?method=getOrder(${header.id})") // need to specify the POJO types the binding is using (otherwise json binding defaults to Map based) .post().type(Order.class) .to("bean:orderService?method=createOrder") // need to specify the POJO types the binding is using (otherwise json binding defaults to Map based) .put().type(Order.class) .to("bean:orderService?method=updateOrder") .delete("{id}") .to("bean:orderService?method=cancelOrder(${header.id})"); } }
restConfiguration() onException(OrderInvalidException.class) .handled(true) .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(400)) .setBody(constant("")); onException(OrderNotFoundException.class) .handled(true) .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(404)) .setBody(constant("")); onException(Exception.class) .handled(true) .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500)) .setBody(simple("${exception.message}\n")); rest("/orders").description("Order services")
@Override public void configure() throws Exception { // configure rest-dsl restConfiguration() // to use jetty component and run on port 8080 .component("jetty").port(8080) // use a smaller thread pool in jetty as we do not have so high demand yet .componentProperty("minThreads", "1") .componentProperty("maxThreads", "16") // to setup jetty to use the security handler .endpointProperty("handlers", "#securityHandler"); // rest services under the orders context-path rest("/orders") .get("{id}") .to("bean:orderService?method=getOrder(${header.id})") .post() .to("bean:orderService?method=createOrder") .put() .to("bean:orderService?method=updateOrder") .delete("{id}") .to("bean:orderService?method=cancelOrder(${header.id})"); } }
@Override public void configure() throws Exception { // configure rest-dsl restConfiguration() // to use jetty component and run on port 8080 .component("jetty").port(8080) // use a smaller thread pool in jetty as we do not have so high demand yet .componentProperty("minThreads", "1") .componentProperty("maxThreads", "16") // to setup jetty to use the security handler .endpointProperty("handlers", "#securityHandler"); // rest services under the orders context-path rest("/orders") .get("{id}") .to("bean:orderService?method=getOrder(${header.id})") .post() .to("bean:orderService?method=createOrder") .put() .to("bean:orderService?method=updateOrder") .delete("{id}") .to("bean:orderService?method=cancelOrder(${header.id})"); } }
@Override public void configure() throws Exception { // use CXF-RS to setup the REST web service using the resource class // and use the simple binding style which is recommended to use from("cxfrs:http://localhost:8080?resourceClasses=camelinaction.RestOrderService&bindingStyle=SimpleConsumer&providers=#jsonProvider") // call the route based on the operation invoked on the REST web service .toD("direct:${header.operationName}"); // routes that implement the REST services from("direct:createOrder") .bean("orderService", "createOrder"); from("direct:getOrder") .bean("orderService", "getOrder(${header.id})"); from("direct:updateOrder") .bean("orderService", "updateOrder"); from("direct:cancelOrder") .bean("orderService", "cancelOrder(${header.id})"); } }
public static void main(String[] args) throws Exception { Main main = new Main(); // setup a dummy order service main.bind("orderService", new DummyOrderService()); // add the order route with the Rest services main.addRouteBuilder(new OrderRoute()); System.out.println("***************************************************"); System.out.println(""); System.out.println(" Rider Auto Parts REST order service"); System.out.println(""); System.out.println(" You can try calling this service using http://localhost:8080/orders/1"); System.out.println("***************************************************"); // run the application main.run(); } }
@Override public void configure() throws Exception { // configure rest-dsl restConfiguration() // to use spark-rest component and run on port 8080 .component("spark-rest").port(8080) // and enable json binding mode .bindingMode(RestBindingMode.json) // lets enable pretty printing json responses .dataFormatProperty("prettyPrint", "true"); // rest services under the orders context-path rest("/orders") // need to specify the POJO types the binding is using (otherwise json binding defaults to Map based) .get("{id}").outType(Order.class) .to("bean:orderService?method=getOrder(${header.id})") // need to specify the POJO types the binding is using (otherwise json binding defaults to Map based) .post().type(Order.class) .to("bean:orderService?method=createOrder") // need to specify the POJO types the binding is using (otherwise json binding defaults to Map based) .put().type(Order.class) .to("bean:orderService?method=updateOrder") .delete("{id}") .to("bean:orderService?method=cancelOrder(${header.id})"); } }
@Override public void configure() throws Exception { // use CXF-RS to setup the REST web service using the resource class // and use the simple binding style which is recommended to use from("cxfrs:http://localhost:8080?resourceClasses=camelinaction.RestOrderService&bindingStyle=SimpleConsumer") // call the route based on the operation invoked on the REST web service .toD("direct:${header.operationName}"); // routes that implement the REST services from("direct:createOrder") .bean("orderService", "createOrder"); from("direct:getOrder") .bean("orderService", "getOrder(${header.id})"); from("direct:updateOrder") .bean("orderService", "updateOrder"); from("direct:cancelOrder") .bean("orderService", "cancelOrder(${header.id})"); } }
public static void main(String[] args) throws Exception { Main main = new Main(); // setup a dummy order service main.bind("orderService", new DummyOrderService()); // create Jetty Basic Auth security handler main.bind("securityHandler", JettySecurity.createSecurityHandler()); // add the order route with the Rest services main.addRouteBuilder(new OrderRoute()); System.out.println("***************************************************"); System.out.println(""); System.out.println(" Rider Auto Parts REST order service"); System.out.println(""); System.out.println(" You can try calling this service using http://localhost:8080/orders/1"); System.out.println(""); System.out.println(" and use jack/123 as username/password"); System.out.println("***************************************************"); // run the application main.run(); } }
@Override public void configure() throws Exception { // use CXF-RS to setup the REST web service using the resource class // and use the simple binding style which is recommended to use from("cxfrs:http://localhost:8080?resourceClasses=camelinaction.RestOrderService&bindingStyle=SimpleConsumer&providers=#jsonProvider") // call the route based on the operation invoked on the REST web service .toD("direct:${header.operationName}"); // routes that implement the REST services from("direct:createOrder") .bean("orderService", "createOrder"); from("direct:getOrder") .bean("orderService", "getOrder(${header.id})"); from("direct:updateOrder") .bean("orderService", "updateOrder"); from("direct:cancelOrder") .bean("orderService", "cancelOrder(${header.id})"); } }
@Override public void configure() throws Exception { // use CXF-RS to setup the REST web service using the resource class // and use the simple binding style which is recommended to use from("cxfrs:http://localhost:8080?resourceClasses=camelinaction.RestOrderService&bindingStyle=SimpleConsumer") // call the route based on the operation invoked on the REST web service .toD("direct:${header.operationName}"); // routes that implement the REST services from("direct:createOrder") .bean("orderService", "createOrder"); from("direct:getOrder") .bean("orderService", "getOrder(${header.id})"); from("direct:updateOrder") .bean("orderService", "updateOrder"); from("direct:cancelOrder") .bean("orderService", "cancelOrder(${header.id})"); } }