Este conteúdo não está disponível no idioma selecionado.
Chapter 4. Deploying an Apache Camel Servlet Endpoint
Abstract
This tutorial describes how to deploy a Camel application, which is implemented using the Camel servlet component. The Camel application gets installed into the Web server as a servlet, receiving messages through the servlet endpoint which are then processed in a Camel route.
4.1. Apache Camel Servlet Example Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
Overview Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
Figure 4.1, “Camel Servlet Example Deployed in a Web Server” gives an overview of the Camel servlet example deployed in a Web server, which lets you see how the servlet's URL is constructed from settings at different configuration layers. The Web server's host and port, the WAR file name, the
url-pattern setting from web.xml, and the endpoint URI of the Camel servlet endpoint are combined to give the URL, http://localhost:8080/camel-example-servlet-tomcat-2.15.1.redhat-620133/camel/hello.
Figure 4.1. Camel Servlet Example Deployed in a Web Server
camel-example-servlet-tomcat example Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
The code for this example is available from the standard Apache Camel distribution, under the
examples/camel-example-servlet-tomcat directory. For details of how to install the Apache Camel distribution, see the section called “Install Apache Camel”.
Camel servlet component Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
The Camel servlet component is used to process incoming HTTP requests, where the HTTP endpoint is bound to a published servlet. The servlet component is implemented by the following servlet class:
org.apache.camel.component.servlet.CamelHttpTransportServlet
org.apache.camel.component.servlet.CamelHttpTransportServlet
To create a Camel servlet endpoint in a Camel route, define a servlet endpoint URI with the following syntax:
servlet://RelativePath[?Options]
servlet://RelativePath[?Options]
Where
RelativePath specifies the tail segment of the HTTP URL path for this servlet.
web.xml file Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
To deploy the Apache Camel servlet example, you must provide a properly configured
web.xml file. In the camel-example-servlet-tomcat project, the web.xml file is stored at the following location:
camel-example-servlet-tomcat/src/main/webapp/WEB-INF/web.xml
camel-example-servlet-tomcat/src/main/webapp/WEB-INF/web.xml
Example 4.1, “web.xml File for the camel-example-servlet-tomcat Example” shows the contents of the
web.xml file.
Example 4.1. web.xml File for the camel-example-servlet-tomcat Example
The key settings in the preceding
web.xml file are:
servlet/servlet-class- Specifies the
org.apache.camel.component.servlet.CamelHttpTransportServletclass, which implements the Camel servlet component. servlet-mapping/url-pattern- Determines which URLs are routed to this servlet. In general, the servlet URL has the following form:
http://Host:Port/WARFileName/URLPattern
http://Host:Port/WARFileName/URLPatternCopy to Clipboard Copied! Toggle word wrap Toggle overflow Where the base URL,http://Host:Port, is determined by the configuration of the Web server, theWARFileNameis the root of theWARFileName.warWAR file, and theURLPatternis specified by the contents of theurl-patternelement.Assuming that the Web server port is set to 8080, thecamel-example-servlet-tomcatexample servlet will match URLs of the following form:http://localhost:8080/camel-example-servlet-tomcat-2.15.1.redhat-620133/camel/*
http://localhost:8080/camel-example-servlet-tomcat-2.15.1.redhat-620133/camel/*Copy to Clipboard Copied! Toggle word wrap Toggle overflow listener/listener-class- This element launches the Spring container.
context-param- This element specifies the location of the Spring XML file,
camel-config.xml, in the WAR. The Spring container will read this parameter and load the specified Spring XML file, which contains the definition of the Camel route.
Example Camel route Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
Example 4.2, “Route Definition for the Camel Servlet Example” shows the Camel route for this example, defined in a Spring XML file, using Camel's XML DSL syntax.
Example 4.2. Route Definition for the Camel Servlet Example
Because the servlet URL,
servlet:///hello, specifies the relative path, /hello, the complete URL to access this servlet is the following:
http://localhost:8080/camel-example-servlet-tomcat-2.15.1.redhat-620133/camel/hello
http://localhost:8080/camel-example-servlet-tomcat-2.15.1.redhat-620133/camel/hello