concept web service in category camel

appears as: web services, web service, web services, web service, The web service
Camel in Action

This is an excerpt from Manning's book Camel in Action.

This kind of consumer is mostly associated with client-server architectures and web services. It’s also referred to as an asynchronous receiver in the EIP world. An event-driven consumer listens on a particular messaging channel, such as a TCP/IP port, JMS queue, Twitter handle, Amazon SQS queue, WebSocket, and so on. It then waits for a client to send messages to it. When a message arrives, the consumer wakes up and takes the message for processing.

Web services are an extremely useful integration technology for distributed applications. They are often associated with service-oriented architecture (SOA), in which each service is defined as a web service.

You can think of a web service as an API on the network. The API itself is defined using the Web Services Description Language (WSDL), specifying the operations you can call on a web service and the input and output types, among other things. Messages are typically XML, formatted to comply with the SOAP schema. In addition, these messages are typically sent over HTTP. Web services allow you to write Java code and make that Java code callable over the internet, which is pretty neat!

For accessing and publishing web services, Camel uses Apache CXF (http://cxf.apache.org). CXF is a popular web services framework that supports many web services standards. We covered Camel’s use of CXF in chapter 10, so you can refer to that chapter for more general usage. Here we focus on CXF’s support of the Web Services Security (WS-Security) standard. The WS-Security support in CXF allows you to do the following:

The callback handler for the client side is a little different in that you’re providing a password to use when calling the web service. The following listing shows such a callback handler.

Listing 14.5 A simple WS-Security callback for a client-side app
package camelinaction.wssecurity; import java.io.IOException; import javax.security.auth.callback.Callback; import javax.security.auth.callback.CallbackHandler; import javax.security.auth.callback.UnsupportedCallbackException; import org.apache.wss4j.common.ext.WSPasswordCallback; public class ClientPasswordCallback implements CallbackHandler { public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { WSPasswordCallback pc = (WSPasswordCallback) callbacks[0]; pc.setPassword("secret"); } } Specifies the password to use when invoking the web service

Figure 15.1 A Rider Auto Parts application accepting incoming inventory updates from either files or a web service

15_01.png
Camel in Action

This is an excerpt from Manning's book Camel in Action.

This kind of consumer is mostly associated with client-server architectures and web services. It’s also referred to as an asynchronous receiver in the EIP world. An event-driven consumer listens on a particular messaging channel, usually a TCP/IP port or a JMS queue, and waits for a client to send messages to it. When a message arrives, the consumer wakes up and takes the message for processing.

JMS messaging applications are typically used within an organization—users outside the corporate firewall rarely send JMS messages to internal systems. For messaging with the external world, web services can be used. We’ll look at how Camel uses Apache CXF to access and serve up web services next.

In this case, to place an order at Rider Auto Parts with a web service, you need a single method call named order. This method will accept part name, amount, and customer name parameters. When the method is complete, it will return a result code to the client. The web service should be exposed on the server’s http://localhost:9000/order address.

Adding a Web Service to Your Route

With all that set up, you’re ready to start using the order web service within a Camel route. Listing 7.6 shows a route using the web service.

Listing 7.6. Web-enabled route configuration

Because you defined your CXF web service as an endpoint bean in listing 7.5, you just had to import the bean configuration and refer to the bean ID to set up the consumer . Recall that setting up a CXF consumer effectively turns the entire route into a web service, so once the order data is sent to an internal queue for processing, the output produced by the route is returned to the caller of the web service .

How does one call this web service? Well, you could use pure CXF or another web services framework compatible with CXF. In this case, you’ll use Camel. You used an endpoint bean to configure CXF earlier, so you can use that to send to the web service as well.

You first need to prepare the parameters to be passed into the web service:

List<Object> params = new ArrayList<Object>();
params.add("motor");
params.add(1);
params.add("honda");

Recall that, in the WSDL, you specified that the web service accepted parameters for part name, number of parts, and customer name.

Next, you can use a ProducerTemplate to send a message to the web service: