The Transport Level
So far this chapter has focused on the distinction, within JAX-WS, between the application and handler levels.
JAX-WS also provides access, on either the client side or the service side, to the transport level, which is
usually HTTP(S). Such access has been used but not studied in earlier examples. This section focuses on
the transport level with the deliberately minimalist Echo
service and a sample EchoClient
.
Access to the transport level will be
especially useful in the next chapter on security.
The Echo
service (see Example 5-13) relies upon dependency injection through the
@Resource
annotation to get a non-null
reference to the WebServiceContext
(line 1). The
WebServiceContext
, in turn, can be used to access the MessageContext
(line 2), which provides
information about the transport level. To illustrate such access, the echo
method gets the
HTTP request headers as a Map
(line 3) and then prints the map’s contents to the
standard output (line 4).
Example 5-13. The Echo service, which accesses the transport level
package
mctx
;
import
java.util.Map
;
import
java.util.Set
;
import
javax.annotation.Resource
;
import
javax.jws.WebService
;
import
javax.jws.WebMethod
;
import
javax.xml.ws.WebServiceContext
;
import
javax.xml.ws.handler.MessageContext
;
@WebService
public
class
Echo
{
@Resource
WebServiceContext
wctx
;
@WebMethod
public
String
echo
(
String
in
)
{
String
out
Get Java Web Services: Up and Running, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.