logger.log(level, "Retailer.getListPrice invoked");
ServletContext sc = (ServletContext)wsc.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
logger.log(level, "Configuring WSIT client ...");
WholesalerClient sunClient = new WholesalerClient(getSunEndpointAddress(sc), new QName(WQS_NAMESPACE_URI, getSunServiceName(sc)));
logger.log(level, "Invoking WSIT's Wholesaler ...");
pricequote.wholesaler.client.Quote sunQuote = sunClient.getQuote(pid);
float sunPrice = sunQuote.getPrice();
ClientSession session = ClientSession.getSession((BindingProvider)sunClient.getBindingProvider());
if (session != null)
session.close();
logger.log(level, "Sun's wholesaler response received.");
logger.log(level, "Configuring WSIT#2 client ...");
WholesalerClient msClient = new WholesalerClient(getMSEndpointAddress(sc), new QName(WQS_NAMESPACE_URI, getMSServiceName(sc)));
logger.log(level, "Invoking WSIT#2's Wholesaler ...");
pricequote.wholesaler.client.Quote msQuote = msClient.getQuote(pid);
session = ClientSession.getSession((BindingProvider)msClient.getBindingProvider());
if (session != null)
session.close();
float msPrice = msQuote.getPrice();
logger.log(level, "WSIT#2's wholesaler response received.");
pricequote.wholesaler.client.Quote quote = sunPrice <= msPrice ? sunQuote : msQuote;
logger.log(level, "Got a better price from \"{0}\" Wholesaler ...",
(sunPrice <= msPrice ? "WSIT" : "WSIT#2"));
// TODO: Calculate the price to be returned back
// TODO: based upon user's identity and gross margin
// TODO: For now, the best price from wholesaler is
// TODO: returned to the consumer
Quote response = new Quote();
response.setPrice(quote.getPrice());
response.setPhoto(quote.getPhoto());
logger.log(level, "Returning the response.");
return response;