DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • The Importance of Code Profiling in Performance Engineering
  • Unleash Peak Performance in Java Applications: Overview of Profile-Guided Optimization (PGO)
  • Integrating Salesforce With Google BigQuery for Cortex Framework Deployment
  • Stop Using Spring Profiles Per Environment

Trending

  • Create Your Own AI-Powered Virtual Tutor: An Easy Tutorial
  • AI Meets Vector Databases: Redefining Data Retrieval in the Age of Intelligence
  • While Performing Dependency Selection, I Avoid the Loss Of Sleep From Node.js Libraries' Dangers
  • Fixing Common Oracle Database Problems

Apache Camel: Jetty Component: IN PROGRESS -- NEEDS PROFILE PIC

By 
Ashish Mishra user avatar
Ashish Mishra
·
Jun. 24, 15 · Interview
Likes (0)
Comment
Save
Tweet
Share
2.4K Views

Join the DZone community and get the full member experience.

Join For Free

Apache Camel: Jetty Component

Today, I'm going to explain about the Camel's Jetty component and how to configure to the jetty component. Here, I used Spring DSL to configure the jetty component. So, let's start the camel riding.

Camel's jetty component is used for HTTP/S based request/response as like classical Servlet. Jetty component consumes and produces the http request/response and support GET, POST, DELTE, PUT methods of forms. It act as a servlet as we define J2EE web  project. It receive the request from the client, process it and create the response accordingly. With Jetty component we can create the HTTP based endpoints which consumes/produces http request.

Now, Let's start the programming. I assume that you have created your project by using Maven. I also assume that you have added all the dependency required for camel in your project.

Add the below dependency in your project's pom.xml

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-jetty</artifactId>
    <version>X.X.X</version> <!-- Here, the version must be same as your project's camel version -->
</dependency>
After adding jetty dependency please do clean and build your project.

Now, I'm going to add the endpoints which receive the incoming request and respond it accordingly. Below is the configuration based on Spring DSL.

The  Spring-DSL for camel-jetty component,

<!-- Jetty Component -->
<camel:route id="httpComponent" startupOrder="1">
<camel:from uri="jetty:http://URL:PORT/makhir?continuationTimeout=100000" />
<camel:setExchangePattern pattern="InOut" />
<camel:convertBodyTo type="java.lang.String" charset="UTF-8"/>
<camel:to uri="log:Recived Input in httpComponent?showAll=true" />
<camel:choice>
<camel:when>
<camel:simple>${header.CamelHttpMethod} == "GET"</camel:simple>
<camel:to uri="direct:testGetRoute" />
</camel:when>
<camel:when>
<camel:simple>${header.CamelHttpMethod} == "POST"</camel:simple>
<camel:to uri="direct:splitterRoute" />
</camel:when>
</camel:choice>
</camel:route>

We can have same component using Java DSL also. I've created the jetty component which receives the incoming http request and serve accordingly as per below.



/**
 * This is the jetty component which creates the http endpoint which
 * consumes the http request and respond accordingly.
 * @author Ashish Mishra
 * @since 22-06-2015 15:02:05
 * */
public class JettyCommponent extends RouteBuilder{
@Override
public void configure() throws Exception {
from("jetty:http://localhost:8080/makhir?continuationTimeout=100000").process(
new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
String message = exchange.getIn().getBody(String.class);
System.out.println("Request Body Message : " + message);
String httpMethod = (String) exchange.getProperty("CamelHttpMethod");
System.out.println("Http Method : " + httpMethod);
if(httpMethod.equalsIgnoreCase("GET")){
System.out.println("Add implementation for GET method and route accordingly");
} else if(httpMethod.equalsIgnoreCase("POST")){
System.out.println("Add implementation for POST method and route accordingly");
} else
System.out.println("Default Implementation " + message);
exchange.getOut().setBody("Response: " + message);
}
});
}
}

Now, you should add this routes in your main class which have CamelContext object. About how to add the routes in camelcontext I've explained in my first blog related to camel.

That's it. Now build your project and deployed it in your ESB and try to call that endpoint by creating some java test class using http client.

You can use the Jetty component as per your need in your application. It gives web servlet like features in camel routing.

You can read more about camel:jetty component Apache Camel.

Hope, you have enjoyed this camel ride.
Jetty (web server) Profile (engineering) PIC (markup language)

Opinions expressed by DZone contributors are their own.

Related

  • The Importance of Code Profiling in Performance Engineering
  • Unleash Peak Performance in Java Applications: Overview of Profile-Guided Optimization (PGO)
  • Integrating Salesforce With Google BigQuery for Cortex Framework Deployment
  • Stop Using Spring Profiles Per Environment

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!