Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Before we started our routing using the Direct endpoint with "direct:start". We should replace this with the CXF endpoint.

But before going to far we have to make a few adjustments to the .wsdl file and it's location in our project folder. We move report_incident.wsdl from src/main/webapp/WEB-INF/wsdl* to src/main/resources as we want to be able to refer to it from within our route builder from Java code and thus it should be on the classpath for easy access. Secondly we have upgrade the CXF to a newer version and it identified a minor issue with the .wsdl file itself. We have to give the complexType a name otherwise we get some JAXB error.

So the .wsdl should be changed from:

Code Block
xml
xml

    <xs:element name="inputReportIncident">
        <xs:complexType>

To include a name attribute of the complex types:

Code Block
xml
xml

    <xs:element name="inputReportIncident">
        <xs:complexType name="inputReportIncident">

Using CXF endpoint

Okay now we are ready to turn our attention to using CXF directly in Camel routing. So we zap ReportIncidentEndpointImpl as we no longer need this code. So what's left is:

  • FilenameGenerator.java
  • ReportIncidentRoutes.java
    And that is all what's needed, well for now... (wink)

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

CXF endpoint can be configured in either or both CXF spring configuration file or/and in the route directly. It accepts one parameter and others are optional. The parameter it must have is the service class. The service class is the interface for the WSDL operation's. As we have the wsdl2java goal to generate this class for us, we have it already as org.apache.camel.example.reportincident.ReportIncidentEndpoint.

The other parameter we will provide is the url to the .wsdl file. And finally we must provide the http address we expose the webservice at. The URI is therefore:

Code Block
java
java

        // endpoint to our CXF webservice
        String cxfEndpoint = "cxf://http://localhost:8080/part-five/webservices/incident"
                + "?serviceClass=org.apache.camel.example.reportincident.ReportIncidentEndpoint"
                + "&wsdlURL=report_incident.wsdl";

Then we can replace "direct:start" with our endpoint instead:

Code Block
java
java

        from(cxfEndpoint)