⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serviceaccess.java

📁 java web services how to program
💻 JAVA
字号:
// ServiceAccess.java
// ServiceAccess provides access to the PriceFinder Web service
// for a Swing-based GUI.
package jws1casestudy.clients.swing;

// JAX-RPC packages
import javax.xml.rpc.*;

// Packages for xrpcc-generated classes
import jws1casestudy.clients.stubs.deitelbookinformation.*;
import jws1casestudy.clients.stubs.bestbookprice.*;
import jws1casestudy.clients.stubs.bookpurchase.*;

public class ServiceAccess {   
   
   // Stubs for invoking Web services
   BookInformation_Stub bookInformationService;
   BestBookPrice_Stub bestBookPriceService;
   BookPurchase_Stub bookPurchaseService;   

   // ServiceAccess constructor
   public ServiceAccess()
   {      
      // create Stub for BookInformation Web service
      bookInformationService = ( BookInformation_Stub )
         new BookInformationService_Impl().getBookInformation();
      
      // create Stub for BestBookPrice Web service
      bestBookPriceService = ( BestBookPrice_Stub )
         new BestBookPriceService_Impl().getBestBookPrice();
      
      // create Stub for BookPurchase Web service
      bookPurchaseService = ( BookPurchase_Stub )
         new BookPurchaseService_Impl().getBookPurchase();
      
   } // end ServiceAccess constructor
   
   // retrieve the best price for the given ISBN from the
   // BestBookPrice Web service
   public jws1casestudy.pricefinder.common.PriceQuote 
      getBestPrice( String ISBN ) throws Exception
   {
      try {
         jws1casestudy.clients.stubs.bestbookprice.PriceQuote 
            quote = bestBookPriceService.getBestPrice( ISBN );

         jws1casestudy.pricefinder.common.PriceQuote returnQuote = 
            new jws1casestudy.pricefinder.common.PriceQuote();

         returnQuote.setIsbn( quote.getIsbn() );
         returnQuote.setPrice( quote.getPrice() );
         returnQuote.setStoreDescription( 
            quote.getStoreDescription() );
         returnQuote.setStoreID( quote.getStoreID() );
      
         return returnQuote;
      }
      
      // handle exception retrieving PriceQuote from Web service
      catch ( Exception exception ) {
         exception.printStackTrace();
         
         throw new Exception( "Error getting price quote." );
      }
   } // end method getBestPrice
   
   // order the book in the give PriceQuote for the given
   // Customer using the BookPurchase Web service
   public void orderBook( 
      jws1casestudy.pricefinder.common.PriceQuote quote, 
      jws1casestudy.pricefinder.common.Customer customer )
      throws Exception
   {
      try {
         jws1casestudy.clients.stubs.bookpurchase.PriceQuote 
            priceQuote = new 
            jws1casestudy.clients.stubs.bookpurchase.PriceQuote();

         priceQuote.setIsbn( quote.getIsbn() );
         priceQuote.setPrice( quote.getPrice() );
         priceQuote.setStoreID( quote.getStoreID() );
         priceQuote.setStoreDescription( 
            quote.getStoreDescription() );

         jws1casestudy.clients.stubs.bookpurchase.Customer 
            remoteCustomer = 
            new jws1casestudy.clients.stubs.bookpurchase.Customer();

         remoteCustomer.setFirstName( customer.getFirstName() );
         remoteCustomer.setLastName( customer.getLastName() );
         remoteCustomer.setStreetAddress( 
            customer.getStreetAddress() );
         remoteCustomer.setCity( customer.getCity() );
         remoteCustomer.setState( customer.getState() );
         remoteCustomer.setZipCode( customer.getZipCode() );
         remoteCustomer.setCountry( customer.getCountry() );
         remoteCustomer.setEmailAddress( 
            customer.getEmailAddress() );
         remoteCustomer.setCreditCardNumber( 
            customer.getCreditCardNumber() );

         bookPurchaseService.orderBook( priceQuote, remoteCustomer );   
      }
     
      // handle exception placing order through Web service
      catch ( Exception exception ) {
         exception.printStackTrace();
         
         throw new Exception( "Error ordering book." );
      }
      
   } // end method orderBook
   
   // retrieve information about the give ISBN from the
   // BookInformation Web service
   public jws1casestudy.pricefinder.common.BookDetails 
      getBookDetails( String ISBN ) throws Exception
   {
      try {
         
         // retreive the BookDetails object
         jws1casestudy.clients.stubs.deitelbookinformation.BookDetails 
            details = bookInformationService.getBookDetails( 
               ISBN );
         
         // package BookDetails information in a common
         // BookDetails object for returning to the caller
         jws1casestudy.pricefinder.common.BookDetails 
            returnDetails =
            new jws1casestudy.pricefinder.common.BookDetails();
         
         returnDetails.setAuthors( details.getAuthors() );
         returnDetails.setCoverImageURL( 
            details.getCoverImageURL() );
         
         returnDetails.setDescription( 
            details.getDescription() );
         
         returnDetails.setIsbn( details.getIsbn() );
         returnDetails.setTitle( details.getTitle() );
         
         return returnDetails;
      }
      
      // handle exception communicating with Web service
      catch ( Exception exception ) {
         exception.printStackTrace();
         
         throw new Exception( "Could not locate information." );
      }
      
   } // end method getBookDetails

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -