Java Reference
In-Depth Information
Listing 11-24 demonstrates this interplay by providing an alternate version of the
doGet() method that appears in Listing 11-14 's LibraryClient application. In-
steadofworkingwith HttpURLConnection ,thealternate doGet() methodworks
with Service and Dispatch .
Listing 11-24. Revised LibraryClient application's doGet() method as a dispatch client
static void doGet(String isbn) throws Exception
{
Service service = Service.create(new QName(""));
String endpoint = "http://localhost:9902/library";
service.addPort(new
QName(""),
HTTPBind-
ing.HTTP_BINDING, endpoint);
Dispatch<Source> dispatch;
dispatch
=
service.createDispatch(new
QName(""),
Source.class,
Ser-
vice.Mode.MESSAGE);
Map<String,
Object>
reqContext
=
dis-
patch.getRequestContext();
reqContext.put(MessageContext.HTTP_REQUEST_METHOD,
"get");
if (isbn != null)
reqContext.put(MessageContext.QUERY_STRING,
"isb-
n="+isbn);
Source result;
try
{
result = dispatch.invoke(null);
}
catch (Exception e)
{
System.err.println(e);
return;
}
try
{
Search WWH ::




Custom Search