cExchangePattern
cExchangePattern Standard properties
These properties are used to configure cExchangePattern running in the Standard Job framework.
The Standard
cExchangePattern component belongs to the Core family.
Basic settings
Exchange Patterns |
Select the message exchange mode from InOnly or InOptionalOut, InOut, OutIn, |
Usage
Usage rule |
As a middle component in a Route, cExchangePattern allows you to set the message |
Limitation |
|
Scenario: Enabling the InOut exchange pattern to get replies
This scenario applies only to a Talend solution with ESB.
In this scenario, a cExchangePattern component is
used to enable the request/reply exchange pattern in the Route, so that the client can
get a reply from the server.
To send requests to the server side, a soapUI is needed and its configuration will be
briefed in the following contents.
To build the Route, do the following.
Dropping and linking the components
-
From the Palette, drag and
drop a cSOAP, a cExchangePattern and a cProcessor onto the workspace, and label them WebService_producer, Set_exchange_mode and Build_reply_message respectively to better identify their
roles in the Route. -
Link cSOAP to cExchangePattern using a Row > Route
connection. -
Link cExchangePattern to cProcessor using a Row > Route
connection.
Configuring the components
-
Double-click cSOAP to open
its Basic settings view in the Component tab. -
In the Address field, leave
the default setting unchanged. -
In the Type list, select
wsdlURL. -
In the WSDL File field,
enter the URL of the wsdl file. You can also click the three-dot button to
browse for it. -
Click […] next to Service
Configuration to open the service configuration wizard. The
WSDL field has been filled in with the selected WSDL
file. Click to show the available port in the Port
Name box. Select theairportSoap
port and click
Finish to close the wizard. The Service
Name and Port Name fields in the
Basic settings view are filled in
automatically. -
In the Dataformat list,
select PAYLOAD. -
Double-click cExchangePattern to open its Basic
settings view in the Component tab. -
In the Exchange Patterns
list, select InOut to enable the
request/reply message exchange mode. -
Double-click cProcessor to
open its Basic settings view in the
Component tab. -
In the Code box, enter the
code below.12345StringBuilder sb = new StringBuilder();sb.append("<tns:getAirportInformationByISOCountryCodeResponse xmlns:tns="http://airportsoap.sopera.de">");sb.append("<tns:getAirportInformationByISOCountryCodeResult>This is a response</tns:getAirportInformationByISOCountryCodeResult>");sb.append("</tns:getAirportInformationByISOCountryCodeResponse>");exchange.getOut().setBody(sb.toString());As shown above, a string is built here and is used as a reply
message of the route. It is in line with the message definition of the above
wsdl file. -
Press Ctrl+S to save your
Route.
Viewing code and executing the Route
-
Click the Code tab at the bottom of the
design workspace to check the generated code.As shown above, the route has its message exchange pattern set as
InOut
using the method
.setExchangePattern(org.apache.camel.ExchangePattern.InOut)
.
In the meantime, a string is created usingStringBuilder sb = new
at
StringBuilder()cProcessor_1
and is used as the
reply message via the methodexchange.getOut().setBody(
.
sb.toString()) -
Press F6 to execute the Route.
The server Route gets started.
Creating and sending a request to the server Route and getting a reply
-
In the soapUI, create a Test project and edit a request, as illustrated
below:Note that the wsdl file must be same as that configured for
cSOAP, so that the request can be in line
with the definition of the web service. -
Send the request to the server Route and you can get the reply, as
illustrated below: