You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Viki Keaton <Vi...@acxiom.com> on 2019/08/04 06:36:37 UTC

Is there a difference between Java DSL and Rest DSL and the way they work?

Hello-
I am having an issue between using jetty in Java DSL and utilizing Rest DSL.  Thank you in advance for your help.
I am using Eclipse, Camel 2.24.0, Spring Boot 2.2.0, Java 1.8, and I can not use any xml.

I have one example that uses Jetty in the from().  Using Spring boot, this means that my project Spring Boot application comes up with using port 8080 via Tomcat.  This forces me to use port 8081 with my Jetty component.  Which also means, that I have Jetty running inside tomcat - unallowed.

If I utilize the Rest DSL version, I get nothing. It's the same route code in both examples - DTRoute.  Is there a difference between using Rest DSL and Java DSL?

--The Rest DSL Version:--
@Component
public class MyRoute extends RouteBuilder {
  @Override
  public void configure() throws Exception {
    restConfiguration()
      .component("servlet")
      .bindingMode(RestBindingMode.json);

    rest()
      .get("/hello").to("direct:hello")
      .get("/data-trans/{dataMartId}").to("direct:dataTrans");
    from("direct:hello")
      .log(LoggingLevel.INFO, "Welcome to Reckon Lineage Adapter")
      .transform().simple("Welcome to Reckon Lineage Adapter");

    from ("direct:dataTrans")
       .log("what is the data mart id? ${header.dataMartId}")
       .to("direct:getDataTrans")
       .log("back here");
   }
}

My DTRoute router class - used in both examples:
@Component
public class DTRoute extends RouteBuilder {

               private static final String DATA_TRANS_URL="http://<MY REST SERVICE>:<PORT>/<SOME CONTEXT>?bridgeEndpoint=true";
               private static final String BASIC_AUTH = "<BASIC AUTH TOKEN>";

               @Override
               public void configure() {

               from("direct:getDataTrans").tracing()
                   .log("at direct:getDataMart")
                   .log("properties: DATA_TRANS_VM is properties:{{data.trans.vm}}")
                   .setBody().constant(null)
                   .setHeader(Exchange.HTTP_METHOD, simple("GET"))
                   .setHeader("Content-Type", constant("application/json"))
                   .setHeader("Accept", constant("application/json"))
                   .setHeader("Accept-Encoding", constant("identity"))
                   .setHeader("Authorization", constant(BASIC_AUTH))
                   .log("call data mart url for id=${header.dataMartId}")
                   .to(DATA_TRANS_URL)
                   .convertBodyTo(String.class)
                              .log("body:${body}");
               }
}

Postman:
http://localhost:8080/camel/data-trans/12345
Results: ""

Console Output:
2019-08-04 01:09:53,100 logLevel=INFO thread="http-nio-8080-exec-2" category=route3 what is the data mart id? 12345
2019-08-04 01:09:53,101 logLevel=INFO thread="http-nio-8080-exec-2" category=route1 at direct:getDataMart
2019-08-04 01:09:53,101 logLevel=INFO thread="http-nio-8080-exec-2" category=route1 properties: DATA_TRANS_VM is properties:{{data.trans.vm}}
2019-08-04 01:09:53,102 logLevel=INFO thread="http-nio-8080-exec-2" category=route1 call data mart url for id=12345
2019-08-04 01:09:53,324 logLevel=INFO thread="http-nio-8080-exec-2" category=route1 body:
2019-08-04 01:09:53,324 logLevel=INFO thread="http-nio-8080-exec-2" category=route3 back here


--The Jetty Version:--
@Component
public class MyRoute extends RouteBuilder {
  @Override
  public void configure() throws Exception {

   from("jetty:http://localhost:8081/foobar").tracing()
                              .log("data mart id is: ${header.dataMartId}")
                              .to("direct:dataTrans");

/*restConfiguration()
      .component("servlet")
      .bindingMode(RestBindingMode.json);

    rest()
      .get("/hello").to("direct:hello")
      //.get("/data-trans").to("direct:hello");
      .get("/data-trans/{dataMartId}").to("direct:dataTrans");
*/

   from("direct:hello")
      .log(LoggingLevel.INFO, "Welcome to Reckon Lineage Adapter")
      .transform().simple("Welcome to Reckon Lineage Adapter");

    from ("direct:dataTrans")
       .log("what is the data mart id? ${header.dataMartId}")
       .to("direct:getDataTrans")
       .log("back here");
   }
}

EXACT SAME ROUTE ABOVE defined in Router DTRoute and I get a response when using jetty, but nothing when I use Rest DSL.  Please, tell me what I'm doing wrong?

Postman:
http://localhost:8081/foobar?dataMartId=12345
Results:
{
  "name": "Source Contribution Metrics for Job: chyatt_source_contrib_tst Datamart Build",
  "jobID": "2569995",
  "records": 1026358,
  "fields": [
    {
      "name": "abilitec_consumer_link",
      "nonNullValues": 1026358,
      "contributions": [
        {
          "id": "2060475",
          "alias": "chyatt_ccalera001_dir_ld",
          "unique": 9976,
          "shared": 0.0
        }...

Console Output:
2019-08-04 01:24:38,405 logLevel=INFO thread="qtp621209929-28" category=route2 data mart id is: 12345
2019-08-04 01:24:38,408 logLevel=INFO thread="qtp621209929-28" category=route4 what is the data mart id? 12345
2019-08-04 01:24:38,408 logLevel=INFO thread="qtp621209929-28" category=route1 at direct:getDataMart
2019-08-04 01:24:38,408 logLevel=INFO thread="qtp621209929-28" category=route1 properties: DATA_TRANS_VM is properties:{{data.trans.vm}}
2019-08-04 01:24:38,409 logLevel=INFO thread="qtp621209929-28" category=route1 call data mart url for id=12345
2019-08-04 01:24:38,651 logLevel=INFO thread="qtp621209929-28" category=route1 body:{
  "name": "Source Contribution Metrics for Job: chyatt_source_contrib_tst Datamart Build",
  "jobID": "2569995",
  "records": 1026358,
  "fields": [
    {
      "name": "abilitec_consumer_link",
      "nonNullValues": 1026358,
      "contributions": [
        {
          "id": "2060475",
          "alias": "chyatt_ccalera001_dir_ld",
          "unique": 9976,
          "shared": 0.0
        }...
***************************************************************************
The information contained in this communication is confidential, is
intended only for the use of the recipient named above, and may be legally
privileged.

If the reader of this message is not the intended recipient, you are
hereby notified that any dissemination, distribution or copying of this
communication is strictly prohibited.

If you have received this communication in error, please resend this
communication to the sender and delete the original message or any copy
of it from your computer system.

Thank You.
****************************************************************************