Cover | Table of Contents | Colophon
http://www.w3.org/TR/ws-arch:A web service is a software system identified by a URI, whose public interfaces and bindings are defined and described using XML. Its definition can be discovered by other software systems. These systems may then interact with the Web service in a manner prescribed by its definition, using XML-based messages conveyed by Internet protocols.
http://www.w3.org/TR/ws-arch:A web service is a software system identified by a URI, whose public interfaces and bindings are defined and described using XML. Its definition can be discovered by other software systems. These systems may then interact with the Web service in a manner prescribed by its definition, using XML-based messages conveyed by Internet protocols.
http://www.w3c.org/TR/SOAP) prevents the use of other transport
mechanisms, such as FTP, SMTP or even JMS; in fact, both
Apache SOAP and
its successor, Axis,
support the use of SMTP as the carrier for SOAP messages.Envelope,
Header, and Body, which belong
to a namespace defined by the SOAP specification. Although the
specification defines rules that implementations must follow when
creating the structure of a SOAP message, it says nothing about the
application-dependent information that the message may contain, apart
from the fact that any content conveyed within the envelope must be
valid XML. Example 1-1 shows a typical SOAP message.<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns0=
"urn:jwsnut.chapter6.headerbookservice/types/HeaderBookQuery"
xmlns:ns1=
"urn:jwsnut.chapter6.headerbookservice/wsdl/HeaderBookQuery"
env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<env:Header>
<ns1:auth xsi:type="ns0:Authentication">
<UserName xsi:type="xsd:string">JWSUserName</UserName>
<Password xsi:type="xsd:string">JWSPassword</Password>
</ns1:auth>
</env:Header>
<env:Body>
<ns1:getBookAuthor>
<String_1 xsi:type="xsd:string">Java in a Nutshell</String_1>
<String_2 xsi:type="xsd:string" xsi:nil="1"/>
</ns1:getBookAuthor>
</env:Body>
</env:Envelope>http://www.w3c.org. At the time of this
writing, however, most existing WSDL-aware software (including that
provided by Sun Microsystems) is based on WSDL Version 1.1.
http://jcp.org/jsr/detail/110.jsp
for details. WSDL is discussed in Chapter 5.
http://jcp.org/jsr/detail/101.jsp.java.rmi.Remote.javax.ejb.EJBObject.javax.ejb.EJBLocalObject.javax.ejb.EJBHome and is required to
exist if the session bean provides a remote interface.javax.ejb.EJBLocalHome. The local home interface
is required only if the bean provides a local interface.javax.ejb.SessionBean interface.BookQuery
interface defined for the book web service described in this chapter.
This interface must, of course, satisfy the usual JAX-RPC
requirements described in Section 2.1.2.1, earlier in this chapter,
and will ultimately be published to clients in the form of a WSDL
definition. The session bean may also have remote and/or local
interfaces and the corresponding home and local home interfaces.
However, a bean that is implemented simply in order to host a web
service is not required to be accessible to either local or remote
clients as an EJB and therefore is not required to provide the local
and remote interfaces (or their home interface counterparts). Thus,
although it is possible to extend an existing session bean so that it
can be exposed as a web service by defining a service endpoint
interface that advertises some or all of its existing business
methods, it is not necessary to invent a local or remote interface or
home interfaces for a new bean that is only intended to be used as a
web service.http://jcp.org/jsr/detail/67.jsp.
This chapter looks only at SAAJ and uses it as a convenient means of
introducing SOAP messages; the more advanced messaging facilities
provided by JAXM are covered in Chapter 4.http://www.w3.org/TR/SOAP, is not a formally
adopted W3C specification but it is, nevertheless, the specification
on which all existing SOAP implementations, including SAAJ, are
based. The W3C is working on a formal definition of the next revision
of SOAP, to be called Version 1.2. At the time of this writing, the
SOAP 1.2 specification is available for public review, and Sun plans
to include support for SOAP 1.2 in SAAJ (and JAX-RPC) when the
specification is finalized.
SOAPFault interface that, since it must
be a top-level element in the SOAP body, is derived from
SOAPBodyElement (see Figure 3-4). The SOAP specification requires that there
be no more than one SOAP fault in the message body. Faults can be
mixed with other top-level elements if necessary.SOAPFault
interface to allow its value to be set or retrieved:|
Attribute
|
SOAPFault methods
|
Description
|
|---|---|---|
|
Fault code
|
getFaultCode( )
setFaultCode( )
|
A code that indicates the reason for reporting the fault.
Applications may define their own private fault codes or use the set
of standard values defined by the SOAP 1.1 specification (described
later). All fault codes must be namespace-qualified.
|
|
Fault string
|
getFaultString(
)
setFaultString(
)
|
A human-readable description of the reason for the fault. The value
of this attribute typically is written to a log file or displayed in
a user interface.
|
|
Fault actor
|
getFaultActor( ) |
Content-Type
and Content-Length
headers along with the
SOAPAction
header that was described in Section 3.3.2, earlier in this chapter.
Similarly, when a message is received, any MIME headers that
accompany it must be extracted from the protocol-specific wrapper and
be made part of the created SOAPMessage. The MIME
headers associated with a SOAPMessage are held in
an object of type
javax.xml.soap.MimeHeaders
.MimeHeader and MimeHeaders are
two of four concrete classes in the java.xml.soap
package. The MimeHeader class represents a single
MIME header and contains the header name and its associated value,
which are set at construction time and cannot subsequently be
changed.MimeHeaders is a collection of
MimeHeader objects. When it is created, a
MimeHeaders object is empty; headers can be added
using one of the following methods:public void addHeader(String headerName, String headerValue)
MimeHeader object with the given header
name and value, and adds it to the collection of headers.public void setHeader(String headerName, String headerValue)
ant run-client-debug
BookImageRequest that
represents an array of strings, where each string is the title of a
book. Here is what the body of the SOAP request looks like when
requesting the cover images for three books:http://jcp.org/jsr/detail/105.jsp) and
JSR 106 (XML Digital Encryption APIs; see
http://jcp.org/jsr/detail/106.jsp). Until
these JSRs are completed and their implementations become part of the
Java platform, you can still make use of the authentication
mechanisms already provided for HTTP to add a level of security to
your service. In this section, you'll see how to
configure the client and server parts of the service to use both HTTP
basic authentication, which is relatively weak, and HTTPS, which is
much more robust but is slightly more difficult to set up.MessageFactory consist of an empty body and an
empty header. However, there are established uses of SOAP that make
use of message headers to convey information from the message sender
to the receiver, or to intermediate nodes that the message might
traverse along its delivery path. JAXM provides the concept of
messaging
profiles
,
where a profile represents a specific and standardized way of
constructing a SOAP message, such as the ebXML Message Service. A
JAXM messaging profile is represented by a profile-specific
MessageFactory that can build SOAP messages
according to the rules applicable to the profile.MessageFactory consist of an empty body and an
empty header. However, there are established uses of SOAP that make
use of message headers to convey information from the message sender
to the receiver, or to intermediate nodes that the message might
traverse along its delivery path. JAXM provides the concept of
messaging
profiles
,
where a profile represents a specific and standardized way of
constructing a SOAP message, such as the ebXML Message Service. A
JAXM messaging profile is represented by a profile-specific
MessageFactory that can build SOAP messages
according to the rules applicable to the profile.
MessageFactory for that profile. Each
message is then handled as follows:MessageFactory for the selected messaging profile.SAAJServlet as the base class for our example web
service, but in this chapter, we are going to use the class
javax.xml.messaging.JAXMServlet instead. These two
servlets are virtually identical — the only real difference
between them is that JAXMServlet is included as
part of the JAXM API and should therefore be available in all JAXM
implementations, whereas SAAJServlet is a private
class developed from example code in the JWSDP distribution. We
could, of course, have used JAXMServlet in Chapter 3 instead of creating
SAAJServlet, but to do so would have introduced a
dependency on JAXM, which we wanted to avoid. Like
SAAJServlet, JAXMServlet
delivers received SOAP messages via the onMessage(
) method, where the application will implement its message
handling.doGet( ) method so that it sends a message to the
receiver whenever it is invoked. This allows us to run the example by
pointing a web browser at the appropriate URL; this also gives us
somewhere to display the message that the receiver returns to us. We
don't have a similar issue with the message
receiver, which is also deployed as a servlet derived from
ProviderConnectionFactory
createConnection( ) method, but we
didn't see how the provider itself is located. This
information is held in a file called client.xml,
which must be located in the CLASSPATH of the JAXM
client. Since both the sender and the receiver servlets in this
example are deployed as web applications, their
client.xml files should be placed in the
WEB-INF/classes directory of their WAR files, as
shown in the following listing of the files that make up the web
archive for the SOAPRPSender servlet: META-INF/MANIFEST.MF
WEB-INF/classes/ora/jwsnut/chapter4/soaprpsender/SOAPRPSenderServlet.class
WEB-INF/classes/client.xml
WEB-INF/web.xml
SOAPRPSender servlet is shown in Example 4-6, in which the line numbers on the left have
been added for ease of reference only.http://msdn.microsoft.com/ws/2001/10/Routing.
Although a full discussion of the specification is outside the scope
of this book, this section contains a brief overview and a
description of the API that JAXM provides to allow the construction
of messages that conform to the specification.path, contains child elements from the set listed
in Table 4-4.|
Element
|
Description
|
|---|---|
to
|
Contains the URI of the ultimate destination of the message. This
element is added by the sender and cannot be changed as the message
passes through intermediate systems.
|
from
|
Contains a URI that identifies the sender of the message.
|
fwd
|
If present, this tag contains zero or more URIs that define a list of
intermediate systems that must be visited before the message is
delivered to its final recipient. All of the systems in this list
must be visited in the order in which they appear. If this is not
possible, the message is discarded and a fault is returned (see the
fault element). |
http://www.ebxml.org/specs/ebMS.pdf) defines
the packaging model for ebXML messages, which is based on SOAP with
attachments and is therefore compatible with both SAAJ and JAXM. This
section briefly describes the ebXML packaging model and looks at how
it is supported by the JAXM ebXML profile. The ebXML profile
implements Version 1.0 of the ebXML-TRP specification.