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
packagemctx;importjava.util.Map;importjava.util.Set;importjavax.annotation.Resource;importjavax.jws.WebService;importjavax.jws.WebMethod;importjavax.xml.ws.WebServiceContext;importjavax.xml.ws.handler.MessageContext;@WebServicepublicclassEcho{@ResourceWebServiceContextwctx;![]()
@WebMethodpublicStringecho(Stringin){Stringout
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access