Camel
  1. Camel
  2. CAMEL-797

camel-example-reportincident tutorial - ideas for new parts to add

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.4.0
    • Fix Version/s: 2.0-M2
    • Component/s: documentation, examples
    • Labels:
      None

      Description

      Hi,

      First of all, I would like to thanks Claus for the quality of its tutorial. This is a great job for the camel community to have now a second tutorial showing the magic of Camel.

      What I would like to propose is to add a fourth part to this tutorial to show :

      • How to turn on the code to DSL language and/or spring xml configuration file ?
      • How the architecture can be adapted to use Camel as the entry point of the web service instead of the CxFServlet ?

      Task to do

      1) Adapt the architecture to allow Camel to become the entry point of the web services
      2) Transpose the code to routes the messages between the endpoints using DSL language through a java class
      3) Idem bu using a spring configuration file

      1. part-four.zip
        10 kB
        Hadrian Zbarcea

        Activity

        Hide
        Claus Ibsen added a comment -

        Closing all 2.0M2 tickets

        Show
        Claus Ibsen added a comment - Closing all 2.0M2 tickets
        Hide
        Claus Ibsen added a comment -

        The tutorial is finished. No time to write more on it.

        Show
        Claus Ibsen added a comment - The tutorial is finished. No time to write more on it.
        Hide
        Claus Ibsen added a comment -

        I need to write part 6 that is the XML based router.

        The code is now provided in camel 2.0 as an example (based on part-5)

        Show
        Claus Ibsen added a comment - I need to write part 6 that is the XML based router. The code is now provided in camel 2.0 as an example (based on part-5)
        Hide
        Willem Jiang added a comment -

        @Charles

        Could you check my latest changes on CAMEL-1254 ?
        I introduce a new operation serviceClassInstance in URI for looking up the service class from camel context registry.

        Show
        Willem Jiang added a comment - @Charles Could you check my latest changes on CAMEL-1254 ? I introduce a new operation serviceClassInstance in URI for looking up the service class from camel context registry.
        Hide
        Charles Moulliard added a comment -

        @Willem,

        Great. When the patch will be available, I will use it for the second part of my tutorial.

        Show
        Charles Moulliard added a comment - @Willem, Great. When the patch will be available, I will use it for the second part of my tutorial.
        Hide
        Willem Jiang added a comment -

        @ Charles,

        You are right , here is the [mail thread|http://www.nabble.com/org.apache.cxf.interceptor.Fault%3A-Message-part-%7Bhttp%3A-reportincident.example.camel.apache.org%7DinputReportIncident-was-not-recognized.(Does-it-exist-in-service-WSDL)-td20937098s22882.html#a20950634} that we were discussing.

        I just checked the CXF code of dealing #reportIncidentEndpoint, I don't think it is difficult to support it in camel-cxf

        Show
        Willem Jiang added a comment - @ Charles, You are right , here is the [mail thread|http://www.nabble.com/org.apache.cxf.interceptor.Fault%3A-Message-part-%7Bhttp%3A- reportincident.example.camel.apache.org%7DinputReportIncident-was-not-recognized. (Does-it-exist-in-service-WSDL )-td20937098s22882.html#a20950634} that we were discussing. I just checked the CXF code of dealing #reportIncidentEndpoint, I don't think it is difficult to support it in camel-cxf
        Hide
        Charles Moulliard added a comment -

        I must revert my code to test it again. But if my memory is correct, when I try to do the following , exception was raised because it is not possible to pass the bean reference as an interface to the serviceclass.

        <!-- implementation of the webservice -->
        <osgi:reference id="reportIncidentEndpoint" interface="org.apache.camel.example.reportincident.ReportIncidentService"/>

        <!-- webservice endpoint -->
        <cxf:cxfEndpoint id="reportIncident"
        address="/incident" wsdlURL="/WEB-INF/wsdl/report_incident.xml"
        serviceClass="org.apache.camel.example.reportincident.service.ReportIncidentImpl"
        endpointName="s:ReportIncidentPort"
        serviceName="s:ReportIncidentService"
        xmlns:s="http://reportincident.example.camel.apache.org"/>

        With a jaxws endpoint, it is possible to provide the bean reference

        <!-- export the webservice using jaxws -->
        <jaxws:endpoint id="reportIncident"
        implementor="#reportIncidentEndpoint"
        address="/incident"
        wsdlLocation="/wsdl/report_incident.wsdl"
        endpointName="s:ReportIncidentPort"
        serviceName="s:ReportIncidentService"
        xmlns:s="http://reportincident.example.camel.apache.org"/>

        Show
        Charles Moulliard added a comment - I must revert my code to test it again. But if my memory is correct, when I try to do the following , exception was raised because it is not possible to pass the bean reference as an interface to the serviceclass. <!-- implementation of the webservice --> <osgi:reference id="reportIncidentEndpoint" interface="org.apache.camel.example.reportincident.ReportIncidentService"/> <!-- webservice endpoint --> <cxf:cxfEndpoint id="reportIncident" address="/incident" wsdlURL="/WEB-INF/wsdl/report_incident.xml" serviceClass="org.apache.camel.example.reportincident.service.ReportIncidentImpl" endpointName="s:ReportIncidentPort" serviceName="s:ReportIncidentService" xmlns:s="http://reportincident.example.camel.apache.org"/> With a jaxws endpoint, it is possible to provide the bean reference <!-- export the webservice using jaxws --> <jaxws:endpoint id="reportIncident" implementor="#reportIncidentEndpoint" address="/incident" wsdlLocation="/wsdl/report_incident.wsdl" endpointName="s:ReportIncidentPort" serviceName="s:ReportIncidentService" xmlns:s="http://reportincident.example.camel.apache.org"/>
        Hide
        Claus Ibsen added a comment -

        I created the ticket CAMEL-1254

        Show
        Claus Ibsen added a comment - I created the ticket CAMEL-1254
        Hide
        Claus Ibsen added a comment -

        @Charles

        Could you log the issue with the missing possibility to refer to a spring bean for the serviceClass? That would be a nice option to have.
        I think it should support the # notation so you can refer to it just as:

        cxf://localhost:8080/myapp/myserver?serviceClass=#myCoolService
        

        And the spring XML

        <bean id=myCoolService class="..."/>
        

        The # notation is now possible in Camel 2.0 for all setter properties on a given Endpoint.

        Show
        Claus Ibsen added a comment - @Charles Could you log the issue with the missing possibility to refer to a spring bean for the serviceClass? That would be a nice option to have. I think it should support the # notation so you can refer to it just as: cxf: //localhost:8080/myapp/myserver?serviceClass=#myCoolService And the spring XML <bean id=myCoolService class= "..." /> The # notation is now possible in Camel 2.0 for all setter properties on a given Endpoint.
        Hide
        Charles Moulliard added a comment -

        Additional remark

        I know that this tutorial does not explain in detail How CXF works and is integrated but it should be interesting for the users that you explain why you have switched the endpoint from jaxws to cxf and what are the difference between the two endpoints (ex : it is not possible to pass a spring reference into cxf endpoint for the service class, ...) ?

        Show
        Charles Moulliard added a comment - Additional remark I know that this tutorial does not explain in detail How CXF works and is integrated but it should be interesting for the users that you explain why you have switched the endpoint from jaxws to cxf and what are the difference between the two endpoints (ex : it is not possible to pass a spring reference into cxf endpoint for the service class, ...) ?
        Hide
        Claus Ibsen added a comment -

        Charles I have also upload a new zip file with the missing cxf file remove (not needed)

        Please check if that works for you

        Show
        Claus Ibsen added a comment - Charles I have also upload a new zip file with the missing cxf file remove (not needed) Please check if that works for you
        Hide
        Claus Ibsen added a comment -

        Thanks Charles for review. I have fixed it.

        Show
        Claus Ibsen added a comment - Thanks Charles for review. I have fixed it.
        Hide
        Charles Moulliard added a comment -

        Is the following sentence of the part 5 correct ?

        " The idea now is to replace the endpoint the starts the ball going from "direct:start" to the CXF endpoint."

        or 'the starts' should be 'TO starts'

        Show
        Charles Moulliard added a comment - Is the following sentence of the part 5 correct ? " The idea now is to replace the endpoint the starts the ball going from "direct:start" to the CXF endpoint." or 'the starts' should be 'TO starts'
        Hide
        Claus Ibsen added a comment -

        Okay I have added a part 5 to demonstrate how to embed Camel with Spring so it's started and stopped by Spring
        And finally I also added how to use camel-cxf endpoints directly in the routing so it's nice.

        I plan to do a part 6 to introduce the equal Spring DSL version

        Any feedback and review is of course welcome

        Show
        Claus Ibsen added a comment - Okay I have added a part 5 to demonstrate how to embed Camel with Spring so it's started and stopped by Spring And finally I also added how to use camel-cxf endpoints directly in the routing so it's nice. I plan to do a part 6 to introduce the equal Spring DSL version Any feedback and review is of course welcome
        Hide
        Claus Ibsen added a comment -

        After messing with letting camel handle the entry point with cxf I am not happy with it. It will require quite a context change for end-users to let it handle it properly, and I feel as a developer I lose a little control.

        Also I had to use cxf:endpoint to configure it using spring xml and not jaxws (I got a ClassCastException). Will report it later.

        And frankly to handle any exceptions during the routing requires to use a more powerful DSL style and I frankly don't think we are there yet int the tutorial. (Maybe for part 7+).

            private static OutputReportIncident OK = new OutputReportIncident();
            private static OutputReportIncident VALIDATION = new OutputReportIncident();
            private static OutputReportIncident ERROR = new OutputReportIncident();
        
            public void configure() throws Exception {
                OK.setCode("0");
                VALIDATION.setCode("1");
                ERROR.setCode("9");
        
                // first part from the webservice -> file backup
                from("cxf:bean:reportIncident")
                        .tryBlock()
                            .convertBodyTo(InputReportIncident.class)
                            .bean(ValidateIncidentService.class)
                            .setHeader(FileComponent.HEADER_FILE_NAME, bean(FilenameGenerator.class, "generateFilename"))
                            .to("velocity:MailBody.vm")
                            .transform(constant(OK))
                        .handle(IncidentValidationException.class)
                            .transform(constant(VALIDATION))
                        .handle(Exception.class)
                            .transform(constant(ERROR))
                        .end();
            }
        

        So part 5 will be a gentle introduction to let Spring create the camel context and we will take it from there in baby steps.

        Show
        Claus Ibsen added a comment - After messing with letting camel handle the entry point with cxf I am not happy with it. It will require quite a context change for end-users to let it handle it properly, and I feel as a developer I lose a little control. Also I had to use cxf:endpoint to configure it using spring xml and not jaxws (I got a ClassCastException). Will report it later. And frankly to handle any exceptions during the routing requires to use a more powerful DSL style and I frankly don't think we are there yet int the tutorial. (Maybe for part 7+). private static OutputReportIncident OK = new OutputReportIncident(); private static OutputReportIncident VALIDATION = new OutputReportIncident(); private static OutputReportIncident ERROR = new OutputReportIncident(); public void configure() throws Exception { OK.setCode( "0" ); VALIDATION.setCode( "1" ); ERROR.setCode( "9" ); // first part from the webservice -> file backup from( "cxf:bean:reportIncident" ) .tryBlock() .convertBodyTo(InputReportIncident.class) .bean(ValidateIncidentService.class) .setHeader(FileComponent.HEADER_FILE_NAME, bean(FilenameGenerator.class, "generateFilename" )) .to( "velocity:MailBody.vm" ) .transform(constant(OK)) .handle(IncidentValidationException.class) .transform(constant(VALIDATION)) .handle(Exception.class) .transform(constant(ERROR)) .end(); } So part 5 will be a gentle introduction to let Spring create the camel context and we will take it from there in baby steps.
        Hide
        Claus Ibsen added a comment -

        From James in another ticket. A good idea. So I comment it here to not forget to write something about this in the tutorial.

        BTW I wonder if we should encourage the use of

        when().xpath("/foo")
        

        rather than

        when(header....)
        

        as the when(). is typically more feature rich and has better IDE smart completion

        Show
        Claus Ibsen added a comment - From James in another ticket. A good idea. So I comment it here to not forget to write something about this in the tutorial. BTW I wonder if we should encourage the use of when().xpath( "/foo" ) rather than when(header....) as the when(). is typically more feature rich and has better IDE smart completion
        Hide
        Claus Ibsen added a comment -

        @Hadrian

        I agree but I wanted to introduce the "Camel calls CXF entry automatically" when Willem have improve the CXF so I dont have to go through hoops to get the input object. And as I understand it he has fixed/improved this recently. But the very reasons for not doing this from the start is the fact that I wanted to demo that Camel doens't take the power from the ordinary developer. The cursor is blinking in his code editor and he is in control and can write the code to start the show Camel is all about this also, just being there when you need it and it can be a very powerful helper/friend.

        Show
        Claus Ibsen added a comment - @Hadrian I agree but I wanted to introduce the "Camel calls CXF entry automatically" when Willem have improve the CXF so I dont have to go through hoops to get the input object. And as I understand it he has fixed/improved this recently. But the very reasons for not doing this from the start is the fact that I wanted to demo that Camel doens't take the power from the ordinary developer. The cursor is blinking in his code editor and he is in control and can write the code to start the show Camel is all about this also, just being there when you need it and it can be a very powerful helper/friend.
        Hide
        Hadrian Zbarcea added a comment -

        The attached code does not include a solution for the first bullet in the original description of this task:
        1) Adapt the architecture to allow Camel to become the entry point of the web services

        I think this is an important aspect to demonstrate.

        Show
        Hadrian Zbarcea added a comment - The attached code does not include a solution for the first bullet in the original description of this task: 1) Adapt the architecture to allow Camel to become the entry point of the web services I think this is an important aspect to demonstrate.
        Hide
        Claus Ibsen added a comment -

        Part 4 now done. Will add a part 5 later. Should be either more about unit testing with Camel test kit (such as mocks) or to introduce spring.

        Show
        Claus Ibsen added a comment - Part 4 now done. Will add a part 5 later. Should be either more about unit testing with Camel test kit (such as mocks) or to introduce spring.
        Hide
        Hadrian Zbarcea added a comment -

        Ah, there was an issue for this. I presented camel @trijug yesterday and I used the attached version for step 4. It does 1. and 2, and I sent it to Claus if he wants to add more of his magic before attaching it to the wiki. Sometimes mail client are smart enough to send my messages to trash, so I'll attach it here too if anybody wants to improve on it.

        Show
        Hadrian Zbarcea added a comment - Ah, there was an issue for this. I presented camel @trijug yesterday and I used the attached version for step 4. It does 1. and 2, and I sent it to Claus if he wants to add more of his magic before attaching it to the wiki. Sometimes mail client are smart enough to send my messages to trash, so I'll attach it here too if anybody wants to improve on it.
        Hide
        Willem Jiang added a comment -

        I think we could put these codes into the svn example directory, in this way we could make the tutorial codes sync with the latest Camel.

        Show
        Willem Jiang added a comment - I think we could put these codes into the svn example directory, in this way we could make the tutorial codes sync with the latest Camel.
        Hide
        Claus Ibsen added a comment -

        Each part has a file attached with the source code.

        At the end I will add a new example to camel 1.5 that is based on the tutorial with a finished integration on this use-case. However this example will be more like the last parts with spring, routes, and everything.
        Currently that code is not in SVN (yet)

        Show
        Claus Ibsen added a comment - Each part has a file attached with the source code. At the end I will add a new example to camel 1.5 that is based on the tutorial with a finished integration on this use-case. However this example will be more like the last parts with spring, routes, and everything. Currently that code is not in SVN (yet)
        Hide
        Charles Moulliard added a comment -

        Is the code of the tutorial available under SVN ?

        Show
        Charles Moulliard added a comment - Is the code of the tutorial available under SVN ?
        Hide
        Charles Moulliard added a comment -

        New ideas

        Part 7 : Add transaction support
        Part 8 : Deploy Camel in an application server (JBOSS, Tomcat), WebSphere, BEA, ...), OSGI server (Spring Application Platform suite, Equinox, Felix, ...) or JBI ESB (ServiceMix, Petals, ...)

        The next step will be the redaction of a book

        Show
        Charles Moulliard added a comment - New ideas Part 7 : Add transaction support Part 8 : Deploy Camel in an application server (JBOSS, Tomcat), WebSphere, BEA, ...), OSGI server (Spring Application Platform suite, Equinox, Felix, ...) or JBI ESB (ServiceMix, Petals, ...) The next step will be the redaction of a book
        Hide
        Charles Moulliard added a comment -

        I will sign the Apache SLA and send it back in order for me to have access to the wiki.

        Show
        Charles Moulliard added a comment - I will sign the Apache SLA and send it back in order for me to have access to the wiki.
        Hide
        Claus Ibsen added a comment -

        Charles do you have edit rights to the wiki? If not then you can get it but you need to have signed the Apache CLA so Apache have the rights to whatever you write on the wiki.

        If so then you can also write / edit the tutorial.

        I will take a look at a part 4 this weekend. I think I will keep it basic at first to introduce the routing in only Java.
        And then part 5 can be more about spring how to setup Camel using spring xml files.
        And then a part 6 about the camel-cxf integration as its a bit not easy.

        Oh and then definitely a part about unit testing with the camel test kit as its very important as well.

        Show
        Claus Ibsen added a comment - Charles do you have edit rights to the wiki? If not then you can get it but you need to have signed the Apache CLA so Apache have the rights to whatever you write on the wiki. If so then you can also write / edit the tutorial. I will take a look at a part 4 this weekend. I think I will keep it basic at first to introduce the routing in only Java. And then part 5 can be more about spring how to setup Camel using spring xml files. And then a part 6 about the camel-cxf integration as its a bit not easy . Oh and then definitely a part about unit testing with the camel test kit as its very important as well.
        Hide
        Charles Moulliard added a comment -

        How can I help you ?

        Show
        Charles Moulliard added a comment - How can I help you ?
        Hide
        Claus Ibsen added a comment -

        Yes after some of the heat settled I will sit down with a few beers and craft some more parts. However any contribution is of course much appreciated.

        Show
        Claus Ibsen added a comment - Yes after some of the heat settled I will sit down with a few beers and craft some more parts. However any contribution is of course much appreciated.

          People

          • Assignee:
            Claus Ibsen
            Reporter:
            Charles Moulliard
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development