Java Reference
In-Depth Information
lower overhead as compared to SOAP-based web services. But if the services are to be ex-
posed to applications written in other languages, Java RMI isn't a suitable solution because
it isn't cross-platform. SOAP is a cross-platform solution that can be easily used from C#
and C++ environments to COBOL, Python, and so on.
Another avenue for exposing services is via JMS. Although many developers probably
wouldn't associate JMS and SOAP, both technologies fundamentally focus on message ex-
change. Messaging middleware has a long history that predates web services. The JMS ap-
proach to messaging is asynchronous message passing using store-and-forward, whereas
SOAP is focused on synchronous message invocations. SOAP provides a well-documented
interface in which tools can then be used to automatically generate client code. This isn't
possible with JMS. JMS is a better solution when integrating two systems, not providing
an external interface to one system.
We should also point out that SOAP-based web services, unlike either Java RMI or JMS,
could easily work with corporate firewalls. SOAP messages are usually delivered using the
pervasive HTTP/HTTPS. Let's next look at when you'd use EJBs with SOAP.
8.2.3. When to expose EJBs as SOAP web services
JAX-WS allows both regular Java classes (POJOs) and stateless or singleton EJBs to be
exposed as web services. If you examine the source code for a POJO-based web service
versus an EJB web service, there isn't a big difference. The EJB web service will have
an additional @Stateless / @Singleton annotation and maybe an annotation or two
for other EJB features that we've covered thus far, such as the timer service or transaction
management. Both a POJO web service and an EJB web service support dependency injec-
tion and lifecycle methods such as @PostConstruct and @PreDestroy , but you gain
several important benefits from exposing EJB as web services.
First, with EJB web services you automatically gain the benefits of declarative transaction
and security management available only to EJB components. These are both big features
that drive the use of EJBs over POJOs. You can use interceptors and a timer service if your
application needs them, without any additional work.
Second, and most importantly, exposing an EJB via web services enables business logic to
be exposed without any additional effort or code duplication. An EJB web service is no dif-
Search WWH ::




Custom Search