Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.此内容没有您所选择的语言版本。
Deploying into a Web Server
Deploying Apache CXF and Apache Camel applications into a JBoss Web Server or a JBoss Enterprise Application Platform container
Copyright © 2011-2020 Red Hat, Inc. and/or its affiliates.
Abstract
Chapter 1. Overview of JBoss Fuse Deployment 复制链接链接已复制到粘贴板!
Abstract
1.1. Supported Web Server Platforms 复制链接链接已复制到粘贴板!
Overview 复制链接链接已复制到粘贴板!
- JBoss Web Server (JBoss WS)
- JBoss Enterprise Application Platform (JBoss EAP)
Supported product versions 复制链接链接已复制到粘贴板!
1.2. Camel on EAP Subsystem 复制链接链接已复制到粘贴板!
Overview 复制链接链接已复制到粘贴板!
1.3. WAR Build and Deployment Model 复制链接链接已复制到粘贴板!
How to install Fuse libraries 复制链接链接已复制到粘贴板!
Build model 复制链接链接已复制到粘贴板!
Figure 1.1. Building the WAR with Maven
Maven POM file 复制链接链接已复制到粘贴板!
pom.xml, which is typically used to configure the following aspects of the build:
- The packaging type to be
war(which instructs Maven to build a WAR file). - Dependent JAR files, which will be bundled with the WAR (including the requisite JBoss Fuse libraries).
- The name of the WAR file.
Build process 复制链接链接已复制到粘贴板!
Deployment 复制链接链接已复制到粘贴板!
Chapter 2. Apache Camel on JBoss EAP 复制链接链接已复制到粘贴板!
Abstract
2.1. Overview of Using JBoss Fuse on JBoss EAP 复制链接链接已复制到粘贴板!
- Less bloated war deployments by using the EAP Camel Subsystem instead of packaging Fuse libraries in a WAR file.
- Patch the application server instead of individual deployments
- No need to ship camel dependencies with applications
- Use supported versions of component libraries
2.2. Install JBoss Fuse on JBoss EAP 复制链接链接已复制到粘贴板!
Procedure 2.1. Downlad and Install JBoss Fuse
- Download the Red Hat JBoss Fuse 6.3.0 on EAP Installer:
- Browse to the JBoss Fuse Software Downloads page on the Red Hat Customer Portal and, when prompted, login to your customer account.
- Select version
6.3.0from the Version dropdown menu and click theDownloadlink for the Red Hat JBoss Fuse 6.3.0 on EAP Installer package. Download the installer package to a temporary location.
- Navigate to EAP_HOME of a clean instance of JBoss EAP.
- Run the downloaded installer with the following command:
java -jar TEMP_LOCATION/fuse-eap-installer-6.3.0.redhat-xxx.jar
java -jar TEMP_LOCATION/fuse-eap-installer-6.3.0.redhat-xxx.jarCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.3. Working with Camel on JBoss EAP 复制链接链接已复制到粘贴板!
2.3.1. Using a Camel Context 复制链接链接已复制到粘贴板!
camelContext represents a single Camel routing rulebase. It contains all the routes of your application. You can have as many camelContexts as necessary, provided they have different names.
- define a
camelContextas a part of the subsystem definition in thestandalone.xmlanddomain.xmlfiles - deploy them in a supported deployment artifact that includes the
-camel-context.xmlsuffixed file - provide camelContexts along with their routes via a RouteBuilder and the CDI integration
camelContext as a part of the subsystem definition this way:
camelContext two ways:
- using annotation
@Injectviacamel-cdi - via JNDI treeImportantTo inject by CDI a deployed
camelContextdefined in Spring XML, you need to use the Java@Resourceannotation, instead of the@Inject @ContextNameannotations in the Camel CDI extension. Using the@Inject @ContextNameannotations can result in the creation of a newcamelContextinstead of injecting the named context, which later causes endpoint lookups to fail.
2.3.1.1. Example of a Context and a Route 复制链接链接已复制到粘贴板!
@ContextName annotation provides a specific name to the CamelContext.
2.3.1.2. Configuring Camel Context using CDI Mechanism 复制链接链接已复制到粘贴板!
CamelContext bean. After you initialise the CDI container, a CamelContext bean starts and instantiates automatically.
CamelContext bean into the application as:
@Inject
@ContextName("cdi-context")
private CamelContext context;
@Inject
@ContextName("cdi-context")
private CamelContext context;
2.3.1.3. Configuring Camel Routes using CDI Mechanism 复制链接链接已复制到粘贴板!
2.3.1.4. Customizing Camel Context 复制链接链接已复制到粘贴板!
@ContextName qualifier that allows you to change the name of the default CamelContext bean. For example:
CamelContext class to declare a custom camel context bean.
2.3.1.5. Supporting Multiple CamelContexts 复制链接链接已复制到粘贴板!
2.3.2. Camel Context Deployment 复制链接链接已复制到粘贴板!
- Use the
-camel-context.xmlsuffix as a part of another supported deployment, such as a JAR, WAR, or EAR deploymentThis deployment may contain multiple-camel-context.xmlfiles. - Use the
-camel-context.xmlsuffix in a standaloneXMLfile deployment by dropping the file into the EAP deployment directory
@Resource(name = "java:jboss/camel/context/mycontext") CamelContext camelContext;
@Resource(name = "java:jboss/camel/context/mycontext")
CamelContext camelContext;
java:jboss/camel/context/mycontext is the name assigned the deployed camel context in the JNDI registry. mycontext is the xml:id of the camelContext element in the Camel context XML file.
2.3.3. Hawtio Web Console 复制链接链接已复制到粘贴板!
- deploy HawtIO as a WAR file
- add some users to your management and application realms by using the following command: $ bin/add-user.sh
- navigate to the
http://localhost:8080/hawtio, the HawtIO login page appears - Click in the top navigation bar to view all the running Camel Contexts
- list of all the running camel applications
- detail information of each CamelContext such as Camel version number, runtime statics
- list of all the routes and their runtime statistics in each camel application
- manage the lifecycle of all camel applications and their routes
- graphical representation of the running routes along with real time metrics
- live tracing and debugging of running routes
- profile the running routes with real time runtime statics
- browse and send messages to camel endpoint
2.3.4. Selecting Components 复制链接链接已复制到粘贴板!
2.3.5. Configuring Camel Subsystem 复制链接链接已复制到粘贴板!
2.3.6. Configuring Camel Deployment 复制链接链接已复制到粘贴板!
WEB-INF/jboss-all.xml or META-INF/jboss-all.xml configuration file.
jboss-all.xml file, to control the camel configuration.
2.4. Integration with JMS 复制链接链接已复制到粘贴板!
camel-jms component provides messaging support. It integrates with the EAP Messaging (HornetQ) subsystem. Integration with other JMS implementations is possible by using the JBoss generic JMS Resource Adapter.
2.4.1. Configuring EAP JMS 复制链接链接已复制到粘贴板!
jms-destinations section.
<jms-queue name="WildFlyCamelQueue"> <entry name="java:/jms/queue/WildFlyCamelQueue"/> </jms-queue>
<jms-queue name="WildFlyCamelQueue">
<entry name="java:/jms/queue/WildFlyCamelQueue"/>
</jms-queue>
jms-queue add --queue-address=WildFlyCamelQueue --entries=queue/WildFlyCamelQueue,java:/jms/queue/WildFlyCamelQueue
jms-queue add --queue-address=WildFlyCamelQueue --entries=queue/WildFlyCamelQueue,java:/jms/queue/WildFlyCamelQueue
2.4.2. Configuring Camel Route 复制链接链接已复制到粘贴板!
camel-cdi component. You can inject the JMS ConnectionFactory instances into the Camel RouteBuilder via JNDI lookups.
2.4.2.1. JMS Producer 复制链接链接已复制到粘贴板!
RouteBuilder by injecting the DefaultJMSConnectionFactory connection factory from JNDI. However, the connection factory is defined within the messaging subsystem. Also, a timer endpoint runs after every 10 seconds to share an XML payload to the EAPCamelQueue destination.
EAPCamelQueue destination, a log message appears. Use the EAP Administration console to verify that the messages are placed onto the queue.
2.4.2.2. JMS Consumer 复制链接链接已复制到粘贴板!
2.4.2.3. JMS Transactions 复制链接链接已复制到粘贴板!
camel-jms component requires a transaction manager of type org.springframework.transaction.PlatformTransactionManager. Therefore, you can create a bean extending JtaTransactionManager.
@Named to make the bean available to Camel. It enables you to register the bean within the camel bean registry. Also, inject the EAP transaction manager and user transaction instances by using CDI.
TransactionalTemplate using the desired transaction policy. For example, PROPAGATION_REQUIRED in this instance.
2.4.2.4. Remote JMS destinations 复制链接链接已复制到粘贴板!
java:jboss/export namespace are appropriate for remote clients.
<jms-queue name="RemoteQueue"> <entry name="java:jboss/exported/jms/queues/RemoteQueue"/> </jms-queue>
<jms-queue name="RemoteQueue">
<entry name="java:jboss/exported/jms/queues/RemoteQueue"/>
</jms-queue>
Chapter 3. Building a WAR 复制链接链接已复制到粘贴板!
Abstract
3.1. Preparing to use Maven 复制链接链接已复制到粘贴板!
Overview 复制链接链接已复制到粘贴板!
Prerequisites 复制链接链接已复制到粘贴板!
- Maven installation—Maven is a free, open source build tool from Apache. You can download the latest version from the Maven download page.
- Network connection—whilst performing a build, Maven dynamically searches external repositories and downloads the required artifacts on the fly. By default, Maven looks for repositories that are accessed over the Internet. You can change this behavior so that Maven will prefer searching repositories that are on a local network.NoteMaven can run in an offline mode. In offline mode Maven will only look for artifacts in its local repository.
Adding the Red Hat JBoss Fuse repository 复制链接链接已复制到粘贴板!
settings.xml file. Maven looks for your settings.xml file in the .m2 directory of the user's home directory. If there is not a user specified settings.xml file, Maven will use the system-level settings.xml file at M2_HOME/conf/settings.xml.
.m2/settings.xml file or modify the system-level settings. In the settings.xml file, add the repository element for the JBoss Fuse repository as shown in bold text in Example 3.1, “Adding the Red Hat JBoss Fuse Repositories to Maven”.
Example 3.1. Adding the Red Hat JBoss Fuse Repositories to Maven
Artifacts 复制链接链接已复制到粘贴板!
Maven coordinates 复制链接链接已复制到粘贴板!
{groupId, artifactId, version}. Sometimes Maven augments the basic set of coordinates with the additional coordinates, packaging and classifier. A tuple can be written with the basic coordinates, or with the additional packaging coordinate, or with the addition of both the packaging and classifier coordinates, as follows:
groupdId:artifactId:version groupdId:artifactId:packaging:version groupdId:artifactId:packaging:classifier:version
groupdId:artifactId:version
groupdId:artifactId:packaging:version
groupdId:artifactId:packaging:classifier:version
- groupdId
- Defines a scope for the name of the artifact. You would typically use all or part of a package name as a group ID—for example,
org.fusesource.example. - artifactId
- Defines the artifact name (relative to the group ID).
- version
- Specifies the artifact's version. A version number can have up to four parts:
n.n.n.n, where the last part of the version number can contain non-numeric characters (for example, the last part of1.0-SNAPSHOTis the alphanumeric substring,0-SNAPSHOT). - packaging
- Defines the packaged entity that is produced when you build the project. For OSGi projects, the packaging is
bundle. The default value isjar. - classifier
- Enables you to distinguish between artifacts that were built from the same POM, but have different content.
dependency element to a POM:
bundle package type in the preceding dependency, because a bundle is just a particular kind of JAR file and jar is the default Maven package type. If you do need to specify the packaging type explicitly in a dependency, however, you can use the type element.
3.2. Modifying an Existing Maven Project 复制链接链接已复制到粘贴板!
Overview 复制链接链接已复制到粘贴板!
Change the package type to WAR 复制链接链接已复制到粘贴板!
war in your project's pom.xml file. Change the contents of the packaging element to war, as shown in the following example:
<project ... > ... <packaging>war</packaging> ... </project>
<project ... >
...
<packaging>war</packaging>
...
</project>
maven-war-plugin, to perform packaging for this project.
Customize the JDK compiler version 复制链接链接已复制到粘贴板!
JAVA_HOME and the PATH environment variables to the correct values for your JDK, you must also modify the POM file.
maven-compiler-plugin plug-in settings to your POM (if they are not already present):
Store resources under webapp/WEB-INF 复制链接链接已复制到粘贴板!
/WEB-INF directory in the standard WAR directory layout. In order to ensure that these resources are copied into the root of the generated WAR package, store the WEB-INF directory under ProjectDir/src/main/webapp in the Maven directory tree, as follows:
web.xml file is stored at ProjectDir/src/main/webapp/WEB-INF/web.xml.
Customize the Maven WAR plug-in 复制链接链接已复制到粘贴板!
plugins section of the pom.xml file. Most of the configuration options are concerned with adding additonal resources to the WAR package. For example, to include all of the resources under the src/main/resources directory (specified relative to the location of pom.xml) in the WAR package, you could add the following WAR plug-in configuration to your POM:
webXml- Specifies where to find the
web.xmlfile in the current Maven project, relative to the location ofpom.xml. The default issrc/main/webapp/WEB-INF/web.xml. webResources- Specifies additional resource files that are to be included in the generated WAR package. It can contain the following sub-elements:
webResources/resource—each resource elements specifies a set of resource files to include in the WAR.webResources/resource/directory—specifies the base directory from which to copy resource files, where this directory is specified relative to the location ofpom.xml.webResources/resource/targetPath—specifies where to put the resource files in the generated WAR package.webResources/resource/includes—uses an Ant-style wildcard pattern to specify explicitly which resources should be included in the WAR.webResources/resource/excludes—uses an Ant-style wildcard pattern to specify explicitly which resources should be excluded from the WAR (exclusions have priority over inclusions).
maven-war-plugin plug-in, which has a bug that causes two copies of the web.xml file to be inserted into the generated .war file.
Building the WAR 复制链接链接已复制到粘贴板!
pom.xml file), and enter the following Maven command:
mvn install
mvn install
ProjectDir/target directory, and then to install the generated WAR in the local Maven repository.
3.3. Bootstrapping a CXF Servlet in a WAR 复制链接链接已复制到粘贴板!
Overview 复制链接链接已复制到粘贴板!
web.xml to use the standard CXF servlet, org.apache.cxf.transport.servlet.CXFServlet.
Example 复制链接链接已复制到粘贴板!
web.xml file shows how to configure the CXF servlet, where all Web service addresses accessed through this servlet would be prefixed by /services/ (as specified by the value of servlet-mapping/url-pattern):
cxf-servlet.xml file 复制链接链接已复制到粘贴板!
web.xml file, it is also necessary to configure your Web services by defining a cxf-servlet.xml file, which must be copied into the root of the generated WAR.
cxf-servlet.xml in the default location, you can customize its name and location, by setting the contextConfigLocation context parameter in the web.xml file. For example, to specify that Apache CXF configuration is located in WEB-INF/cxf-servlet.xml, set the following context parameter in web.xml:
3.4. Bootstrapping a Spring Context in a WAR 复制链接链接已复制到粘贴板!
Overview 复制链接链接已复制到粘贴板!
Bootstrapping a Spring context in a WAR 复制链接链接已复制到粘贴板!
web.xml file shows how to boot up a Spring application context that is initialized by the XML file, /WEB-INF/applicationContext.xml (which is the location of the context file in the generated WAR package):
Maven dependency 复制链接链接已复制到粘贴板!
ContextLoaderListener class from the Spring framework, you must add the following dependency to your project's pom.xml file:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring-version}</version>
</dependency>
spring-version property specifies the version of the Spring framework you are using.
Chapter 4. Deploying an Apache CXF Web Service 复制链接链接已复制到粘贴板!
Abstract
4.1. Apache CXF Example 复制链接链接已复制到粘贴板!
Overview 复制链接链接已复制到粘贴板!
url-pattern setting from web.xml, and the address attribute of the Web services endpoint are combined to give the URL, http://localhost:8080/wsdl_first/services/CustomerServicePort.
Figure 4.1. Example Web Service Deployed in a Web Server
wsdl_first sample 复制链接链接已复制到粘贴板!
samples/wsdl_first directory. For details of how to install the Apache CXF distribution, see the section called “Install Apache CXF”.
web.xml file 复制链接链接已复制到粘贴板!
web.xml file. In the wsdl_first project, the web.xml file is stored at the following location:
wsdl_first/src/main/webapp/WEB-INF/web.xml
wsdl_first/src/main/webapp/WEB-INF/web.xml
web.xml file.
Example 4.1. web.xml File for the wsdl_first Example
web.xml file are:
- Servlet class—specifies the
org.apache.cxf.transport.servlet.CXFServletclass, which implements a special servlet that integrates with Web services. - 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, thewsdl_firstexample servlet will match URLs of the following form:http://localhost:8080/wsdl_first/services/*
http://localhost:8080/wsdl_first/services/*Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Implied Spring container 复制链接链接已复制到粘贴板!
CXFServlet automatically creates and starts up a Spring container, which you can then use for defining Web service endpoints. By default, this Spring container automatically loads the following XML file in the WAR:
WEB-INF/cxf-servlet.xml
WEB-INF/cxf-servlet.xml
wsdl_first example project, this file is stored at the following location:
wsdl_first/src/main/webapp/WEB-INF/cxf-servlet.xml
wsdl_first/src/main/webapp/WEB-INF/cxf-servlet.xml
cxf-servlet.xml file 复制链接链接已复制到粘贴板!
cxf-servlet.xml file is primarily used to create Web service endpoints, which represent the Web services exposed through the Web server. Apache CXF provides a convenient and flexible syntax for defining Web service endpoints in XML and you can use this flexible syntax to define endpoints in cxf-servlet.xml.
cxf-servlet.xml file, which creates a single CustomerService endpoint, using the jaxws:endpoint element.
Example 4.2. Spring Configuration for the wsdl_first Example
address attribute of the jaxws:endpoint specifies the final segment of the Web service's URL. When you put together all of the settings from the Web server, the web.xml file, and the cxf-server.xml file, you obtain the following URL for this Web service endpoint:
http://localhost:8080/wsdl_first/services/CustomerServicePort
http://localhost:8080/wsdl_first/services/CustomerServicePort
WSDL address configuration 复制链接链接已复制到粘贴板!
web.xml, and the Spring configuration, cxf-servlet.xml, it is also necessary to ensure that the SOAP address in the WSDL contract is correctly specified, so that it matches the URL for this Web service.
wsdl_first example, the WSDL contract is located in the following file:
wsdl_first/src/main/resources/CustomerService.wsdl
wsdl_first/src/main/resources/CustomerService.wsdl
location attribute of the soap:address element must be set to the correct Web service URL, as shown in Example 4.3, “Address in the WSDL CustomerService Contract”.
Example 4.3. Address in the WSDL CustomerService Contract
4.2. Deploy the Apache CXF Example 复制链接链接已复制到粘贴板!
Overview 复制链接链接已复制到粘贴板!
wsdl_first example) and shows you how to deploy it into a Web server, by packaging the application as a WAR. In this example, the Web service is implemented by binding the service to a Java class with the JAX-WS mapping.
Prerequisites 复制链接链接已复制到粘贴板!
- Either of the following Web servers are installed:
- JBoss Web Server, or
- JBoss Enterprise Application Platform
- Java version 1.7 or later is installed.
- Apache Maven 3.0.0 or later is installed.
- Maven is configured to access the JBoss Fuse repositories, as described in Section 3.1, “Preparing to use Maven”.
- You have access to the Internet, so that Maven can download dependencies from remote repositories.
Install Apache CXF 复制链接链接已复制到粘贴板!
wsdl_first example, you need to install the Apache CXF kit, apache-cxf-3.1.5.redhat-630xxx.zip, provided in the extras/ directory of the JBoss Fuse installation.
- Find the Apache CXF kit at the following location:
InstallDir/extras/apache-cxf-3.1.5.redhat-630xxx.zip
InstallDir/extras/apache-cxf-3.1.5.redhat-630xxx.zipCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Using a suitable archive utility on your platform, unzip the
apache-cxf-3.1.5.redhat-630xxx.zipfile and extract it to a convenient location,CXFInstallDir.
The wsdl_first example 复制链接链接已复制到粘贴板!
wsdl_first example is located under the following sub-directory of the Apache CXF installation:
CXFInstallDir/samples/wsdl_first/
CXFInstallDir/samples/wsdl_first/
Build and run the example 复制链接链接已复制到粘贴板!
wsdl_first example, perform the following steps:
- Using your favorite text editor, open the
CustomerService.wsdlfile, which can be found in the following location in thewsdl_firstproject:wsdl_first/src/main/resources/CustomerService.wsdl
wsdl_first/src/main/resources/CustomerService.wsdlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Edit thesoap:addresselement in the WSDL contract, removing comments around the element labeledstandalone Tomcat deploymentand inserting comments around the element labeledembedded deployment. When you are finished editing, thesoap:addresselement should be look as follows:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Build the
wsdl_firstexample using Maven. Change directory to theCXFInstallDir/samples/wsdl_firstdirectory, open a command prompt, and enter the following command at the command line:mvn clean package
mvn clean packageCopy to Clipboard Copied! Toggle word wrap Toggle overflow If this command executes successfully, you should be able to find the WAR file,wsdl_first.war, under thewsdl_first/targetsub-directory. - Make sure that the Web server is already running (a simple way to test this is to enter the URL,
http://localhost:8080, into your browser). If you need to start the Web server, you can typically do this from the command line. The command to start the Web server depends on the particular product you are using, as follows:- JBoss Web Server (WS)—open a new command prompt and execute the
startup.shscript from thetomcat8/bin/directory (or thetomcat7/bin/directory, as appropriate). For more details about how to configure and launch the Web server, see the Installation Guide from the JBoss Web Server library. - JBoss Enterprise Application Platform (EAP)—for a standalone instance, open a new command prompt and execute the
bin/standalone.shscript. For more details about how to configure and launch the EAP, see the Administration and Configuration Guide from the JBoss Enterprise Application Platform library.
- Deploy the
wsdl_firstexample to the running Web server. Manually copy thewsdl_first.warWAR file from thewsdl_first/targetdirectory to the Web server's deployment directory, as follows:- JBoss Web Server (WS)—copy the
wsdl_first.warWAR file to thetomcat8/webappsdirectory (ortomcat7/webappsdirectory, as appropriate). - JBoss Enterprise Application Platform (EAP)—copy the
wsdl_first.warWAR file to thestandalone/deploymentsdirectory.
- Use a Web browser to query the WSDL contract from the newly deployed Web service. Navigate to the following URL in your browser:
http://localhost:8080/wsdl_first/services/CustomerServicePort?wsdl
http://localhost:8080/wsdl_first/services/CustomerServicePort?wsdlCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThis step might not work in the Safari browser. - Run the test client against the deployed Web service. Change directory to the
CXFInstallDir/samples/wsdl_firstdirectory, open a command prompt, and enter the following command at the command line:mvn -Pclient
mvn -PclientCopy to Clipboard Copied! Toggle word wrap Toggle overflow If the client runs successfully, you should see some output like the following in your command window:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Chapter 5. Deploying an Apache Camel Servlet Endpoint 复制链接链接已复制到粘贴板!
Abstract
5.1. Apache Camel Servlet Example 复制链接链接已复制到粘贴板!
Overview 复制链接链接已复制到粘贴板!
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.17.0.redhat-630xxx/camel/hello.
Figure 5.1. Camel Servlet Example Deployed in a Web Server
camel-example-servlet-tomcat example 复制链接链接已复制到粘贴板!
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 复制链接链接已复制到粘贴板!
org.apache.camel.component.servlet.CamelHttpTransportServlet
org.apache.camel.component.servlet.CamelHttpTransportServlet
servlet://RelativePath[?Options]
servlet://RelativePath[?Options]
RelativePath specifies the tail segment of the HTTP URL path for this servlet.
web.xml file 复制链接链接已复制到粘贴板!
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
web.xml file.
Example 5.1. web.xml File for the camel-example-servlet-tomcat Example
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.17.0.redhat-630xxx/camel/*
http://localhost:8080/camel-example-servlet-tomcat-2.17.0.redhat-630xxx/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 复制链接链接已复制到粘贴板!
Example 5.2. Route Definition for the Camel Servlet Example
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.17.0.redhat-630xxx/camel/hello
http://localhost:8080/camel-example-servlet-tomcat-2.17.0.redhat-630xxx/camel/hello
5.2. Deploy the Apache Camel Servlet 复制链接链接已复制到粘贴板!
Overview 复制链接链接已复制到粘贴板!
camel-example-servlet-tomcat example) and shows you how to deploy it into a Web server, by packaging the application as a WAR.
Prerequisites 复制链接链接已复制到粘贴板!
- Either of the following Web servers are installed:
- JBoss Web Server, or
- JBoss Enterprise Application Platform
- Java version 1.7 or later is installed.
- Apache Maven 3.0.0 or later is installed.
- Maven is configured to access the JBoss Fuse repositories, as described in Section 3.1, “Preparing to use Maven”.
- You have access to the Internet, so that Maven can download dependencies from remote repositories.
Install Apache Camel 复制链接链接已复制到粘贴板!
camel-example-servlet-tomcat example, you need to install the Apache Camel kit, apache-camel-2.17.0.redhat-630xxx.zip, provided in the extras/ directory of the JBoss Fuse installation.
- Find the Apache Camel kit at the following location:
InstallDir/extras/apache-camel-2.17.0.redhat-630xxx.zip
InstallDir/extras/apache-camel-2.17.0.redhat-630xxx.zipCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Using a suitable archive utility on your platform, unzip the
apache-camel-2.17.0.redhat-630xxx.zipfile and extract it to a convenient location,CamelInstallDir.
The camel-example-servlet-tomcat example 复制链接链接已复制到粘贴板!
camel-example-servlet-tomcat example is located under the following sub-directory of the Apache Camel installation:
CamelInstallDir/examples/camel-example-servlet-tomcat/
CamelInstallDir/examples/camel-example-servlet-tomcat/
Build and run the example 复制链接链接已复制到粘贴板!
camel-example-servlet-tomcat example, perform the following steps:
- Build the
camel-example-servlet-tomcatexample using Maven. Change directory to theCamelInstallDir/examples/camel-example-servlet-tomcat/directory, open a command prompt, and enter the following command at the command line:mvn package
mvn packageCopy to Clipboard Copied! Toggle word wrap Toggle overflow If this command executes successfully, you should be able to find the WAR file,camel-example-servlet-tomcat-2.17.0.redhat-630xxx.war, under thecamel-example-servlet-tomcat/targetsub-directory. - Make sure that the Web server is already running (a simple way to test this is to enter the URL,
http://localhost:8080, into your browser). If you need to start the Web server, you can typically do this from the command line. The command to start the Web server depends on the particular product you are using, as follows:- JBoss Web Server (WS)—open a new command prompt and execute the
startup.shscript from thetomcat8/bin/directory (or thetomcat7/bin/directory, as appropriate). For more details about how to configure and launch the WS, see the Installation Guide from the JBoss Web Server library. - JBoss Enterprise Application Platform (EAP)—for a standalone instance, open a new command prompt and execute the
bin/standalone.shscript. For more details about how to configure and launch the EAP, see the Administration and Configuration Guide from the JBoss Enterprise Application Platform library.
- Deploy the
camel-example-servlet-tomcatexample to the running Web server. Manually copy thecamel-example-servlet-tomcat-2.17.0.redhat-630xxx.warWAR file from thecamel-example-servlet-tomcat/targetdirectory to the Web server's deployment directory, as follows:- JBoss Web Server (WS)—copy the
camel-example-servlet-tomcat-2.17.0.redhat-630xxx.warWAR file to thetomcat8/webappsdirectory (ortomcat7/webappsdirectory, as appropriate). - JBoss Enterprise Application Platform (EAP)—copy the
camel-example-servlet-tomcat-2.17.0.redhat-630xxx.warWAR file to thestandalone/deploymentsdirectory.
- Navigate to the following URL in your browser:
http://localhost:8080/camel-example-servlet-tomcat-2.17.0.redhat-630xxx/
http://localhost:8080/camel-example-servlet-tomcat-2.17.0.redhat-630xxx/Copy to Clipboard Copied! Toggle word wrap Toggle overflow When the page loads, you should see the following text in your browser window: - Click the highlighted link in the line
To get started click this link.and follow the on-screen instructions to test the servlet.
Legal Notice 复制链接链接已复制到粘贴板!
Trademark Disclaimer