Dec 6, 2010

Implementing a solution by using Camel.

Here we try to implement an integration solution by using Camel. The problem is, to send an e-mail to a central administration. In an organization each client can send an incident to the central administration. Organization use a website to do this process. So the client can visit the website and fill an incident form and send.  Website should pass that details to the relevant place by converting that details in to an E-mail.

To build this system we need Maven, Apache-cxf, Apache-Camel and Spring web framework. So lets try this.
first you need to create a Maven project. To do that you can type,
mvn archetype:create -DgroupId=org.apache.camel -DartifactId=camel-example-reportincident -DarchetypeArtifactId=maven-archetype-webapp

Then you need to add Apach-cxf dependencies to the pom.xml file.

You may need "cxf-rt-core" , "cxf-rt-frontend-jaxws", "cxf-rt-transports-http". After that we need to create a .wsdl file. We should put it in src/main/webapp/WEB-INF/wsdl/report_incident.wsdl .
 (refer this link to get the coding :- http://camel.apache.org/tutorial-example-reportincident-part1.html)

Now we need to add some plugins to generate java classes from the wsdl. To do that we need to integrate the cxf wsdl2java converter plugins and maven-compiler-plugin. After inserting these plugins you should edit the web.xml file.

In that file we must add a listener. Now we will use spring to do that.
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

Then we should specify the cxf servlet, URI and cxf-config,xml path details in the web.xml file.

So the path for cxf-config.xml is src/main/resources and you should place that xml file in that place.

The basic configurations are done for now. Now you need to create a java file and it should like this.

package org.apache.camel.example.reportincident;

/**
 * The webservice we have implemented.
 */
public class ReportIncidentEndpointImpl implements ReportIncidentEndpoint {

    public OutputReportIncident reportIncident(InputReportIncident parameters) {
        System.out.println("Hello ReportIncidentEndpointImpl is called from " + parameters.getGivenName());

        OutputReportIncident out = new OutputReportIncident();
        out.setCode("OK");
        return out;
    }

}

Before that you may need to remove the .jsp page which created by maven initially. Then you can try to compile the project.
Try;
mvn clean compile

If the project compiles without errors you can try to run it on a web container. So you need to edit the pom file again and insert maven-jetty-plugin to the main pom file. using jetty is easy than using any other web container, but camel supports for many finds of web containers too.
Then try;
mvn jetty:run

If you try to visit http://localhost:8080 you will see some details to your web application. Still it is not complete, si you wil not see any UI. You can use SOAPUI to do that thing.

Cont...

No comments:

Post a Comment

Your comments are always welcome ...