FileDocCategorySizeDatePackage
RetailerClient.javaAPI DocExample5032Tue May 29 16:57:48 BST 2007pricequote.retailer.client

RetailerClient

public class RetailerClient extends Object
author
Arun Gupta

Fields Summary
private static final String
ENDPOINT
private static final String
WSDL_LOCATION
private static final QName
SERVICE
private static int
pid
Constructors Summary
Methods Summary
private static final java.lang.Stringcarname(int pid)

        switch (pid % 4) {
            case 1:
                return "AM-Vantage-2k6";
            case 2:
                return "BMW-M3-2k6";
            case 3:
                return "MB-SLR-2k6";
            case 0:
            default:
                return "Porsche-911-2k6";
        }
    
private static final voiddisplayPhotoAndPrice(Quote quote)

        if (quote.getPhoto() != null) {
            try {
                String carName = carname(pid);
                File file = new File(carName + ".jpeg");
                ImageIO.write((BufferedImage)quote.getPhoto(), "jpeg", file);
                String imageLocation = file.getAbsolutePath();
                System.out.printf("Photo is copied to \"%s\" file.\n", imageLocation);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            System.out.println("No photo received.");
        }
        System.out.println("Quoted price: " + quote.getPrice());
        System.out.println("Success!");
    
public static QuotegetQuote(java.lang.String endpoint, java.lang.String spid)
Invokes the web service.

        RetailerQuoteService service;
        try {
            service = new RetailerQuoteService(new URL(WSDL_LOCATION), SERVICE);
        } catch (MalformedURLException e) {
            throw new WebServiceException(e);
        }
        if (endpoint == null || endpoint.equals("")) {
            endpoint = ENDPOINT;
        }

        if (spid != null && spid != "")
            pid = Integer.valueOf(spid);

        RetailerPortType port = service.getRetailerPort();
        System.out.printf("Invoking endpoint address \"%s\" for product id \"%s\".\n", endpoint, spid);
        ((BindingProvider)port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);

        Quote quote = port.getPrice(pid);
        return quote;
    
public static voidmain(java.lang.String[] args)


         
        String endpoint = System.getProperty("endpoint");
        String pid = System.getProperty("pid");
        Quote quote = getQuote(endpoint, pid);
        displayPhotoAndPrice(quote);