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

📄 bookpriceproxy.java

📁 java web services how to program
💻 JAVA
字号:
// BookPriceProxy.java
// BookPriceProxy is a service proxy for each book store抯 
// Book Price Web service.
package jws1casestudy.pricefinder;

// Java core packages
import java.net.URL;

// Java XML packages
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;

// Axis packages
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.encoding.ser.BeanSerializerFactory;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;

// Deitel packages
import jws1casestudy.pricefinder.common.PriceQuote;

public class BookPriceProxy
{
   // Web service invocation object
   private Call call;
   
   // constructor
   public BookPriceProxy( URL serviceWSDL, 
      QName serviceNamespace, QName priceQuoteNamespace,
      String portName ) throws ServiceException
   {    
      // construct a service object bases on WSDL
      Service service = 
         new Service( serviceWSDL, serviceNamespace );
      
      // create getPrice identifier
      QName getPriceNamespace = 
         new QName( null, portName );
      
      // create a Call that specifies the service port and
      // method to call
      call = ( Call )service.createCall(
         getPriceNamespace, "getPrice" );
      
      // create serializer and deserializer
      BeanSerializerFactory serializerFactory =
         new BeanSerializerFactory( PriceQuote.class, 
            priceQuoteNamespace );
      
      BeanDeserializerFactory deserializerFactory =
         new BeanDeserializerFactory( PriceQuote.class,
            priceQuoteNamespace );
      
      // register type mapping for PriceQuote's serializer
      // and deserializer
      call.registerTypeMapping( PriceQuote.class,
         priceQuoteNamespace, serializerFactory, 
         deserializerFactory );

   } // end constructor
   
   // get price from one book store using DII
   public PriceQuote getPrice( String isbn )
   {
      // response object
      PriceQuote response = null;
      
      // invoke Book Price Web service
      try {

         // invoke Web service method
         Object responseObj = call.invoke( 
            new Object[] { isbn } );

         // cast return object to PriceQuote
         response = ( PriceQuote ) responseObj;

      } // end try

      // handle exception in accessing Web service
      catch ( Exception exception){
         exception.printStackTrace();
      }

      return response;

   } // end method getPrice
   
} // end class BookPriceProxy

⌨️ 快捷键说明

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