FileDocCategorySizeDatePackage
Retailer.javaAPI DocExample6469Tue May 29 16:57:48 BST 2007pricequote.retailer.server

Retailer

public class Retailer extends Object implements RetailerPortType
author
Arun Gupta

Fields Summary
WebServiceContext
wsc
private static final Logger
logger
private static final Level
level
private static final String
WQS_NAMESPACE_URI
Constructors Summary
Methods Summary
private java.lang.StringgetMSEndpointAddress(javax.servlet.ServletContext sc)

        String endpoint = sc.getInitParameter("wqs.wcf.endpoint");
        if (endpoint == null || endpoint.equals("")) {
            //endpoint = "http://131.107.72.15/Wholesaler/WholesalerService.svc?wsdl";
            endpoint = "http://localhost:8080/pricequote-wcf/wholesaler?wsdl";
        }

        return endpoint;
    
private java.lang.StringgetMSServiceName(javax.servlet.ServletContext sc)

        String serviceName = sc.getInitParameter("wqs.wcf.serviceName");
        if (serviceName == null || serviceName.equals("")) {
            //serviceName = "WholesalerService";
            serviceName = "WholesaleService";
        }

        return serviceName;
    
public QuotegetPrice(int pid)


        
        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;
    
private java.lang.StringgetSunEndpointAddress(javax.servlet.ServletContext sc)

        String endpoint = sc.getInitParameter("wqs.wsit.endpoint");
        if (endpoint == null || endpoint.equals(""))
            endpoint = "http://localhost:8080/pricequote/wholesaler?wsdl";

        return endpoint;
    
private java.lang.StringgetSunServiceName(javax.servlet.ServletContext sc)

        String serviceName = sc.getInitParameter("wqs.wsit.serviceName");
        if (serviceName == null || serviceName.equals(""))
            serviceName = "WholesalerQuoteService";

        return serviceName;