portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/webservices/util SoapAccessBean.java UDDIAccessBean.java
Date Mon, 29 Oct 2001 08:53:51 GMT
taylor      01/10/29 00:53:51

  Added:       src/java/org/apache/jetspeed/webservices/util
                        SoapAccessBean.java UDDIAccessBean.java
  Log:
  Added Soap and UDDI beans contributed by Scott Roehrig.
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/webservices/util/SoapAccessBean.java
  
  Index: SoapAccessBean.java
  ===================================================================
  /*
   * SoapAccessBean.java
   *
   * Created on August 6, 2001, 3:59 PM
   */
  package org.apache.jetspeed.webservices.util;
  // import beans packages
  import java.beans.*;
  // import soap packages
  import org.apache.soap.SOAPException;
  import org.apache.soap.Constants;
  import org.apache.soap.rpc.Call;
  import org.apache.soap.rpc.Parameter;
  import org.apache.soap.rpc.Response;
  // import utility classes
  import java.util.Vector;
  // used to implement logging services
  import org.apache.turbine.util.Log;
  
  /** SoapAccessBean provides a Soap WebServices Client command bean pattern.
    *
    * This bean can be used to interact with webservices via soap. The WSDL
    * file for the target web service is required since it contains the
    * parameters required to interact with the service.
    *
    * @author Scott A. Roehrig
    * @version 1.0
    */
  public class SoapAccessBean implements java.io.Serializable {
      // declare member variables
      private transient Call request;
      private Vector parameters; 
      private transient Log  log;
      private boolean loggingEnabled;
          
      // declare methods
      /** Default constructor required to support Serialization. */
      public SoapAccessBean() {
          request = new Call();
          setLogging(false);
                   
      }
  
      /** Creates new SoapAccessBean with parameters specified.
      *
      * @param targetURI type: java.lang.String - 
      * desc: targetURI for the services
      *
      * @param method type: java.lang.String - 
      * desc: service method
      */
      public SoapAccessBean(String targetURI, String method) {
          // create call object
          request = new Call();
          // set targetObjectURI, method, and encoding style
          request.setTargetObjectURI(targetURI);
          request.setMethodName(method);
          request.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
          // create Vector to store service parameters
          parameters = new java.util.Vector();
              
      }
      
      /** Setter method for parameters property.
      *
      * The parameters property is used to set
      * the various parameters required to interact
      * with the service.
      *
      * @param parameters
      * type: java.util.Vector - 
      * desc: stores service parameters
      */
      public void setParameters(Vector parameters) {
          this.parameters = parameters;
          
      }
      
      /** Parameters property getter method.
      *
      * @return java.util.Vector - 
      * desc: stores service parameters
      */
      public java.util.Vector getParameters() {
          return parameters;
          
      }
      
      /** Enables or disables logging.
      *
      * @param loggingEnabled
      * type: java.lang.boolean - 
      * desc: indicates whether logging is enabled
      */
      public void setLogging(boolean loggingEnabled) {
          this.loggingEnabled = loggingEnabled;
          // if logging is enabled, output log message
          if (loggingEnabled == true) {
              log = new Log();
              log.debug("debug", "logging has been enabled");
          }
          else {
              log = null;
          }
          
      }
      
      /** Adds the needed parameter to the request.
      *
      * The parameters required by the service are defined within
      * its WSDL descriptor file
      *
      * @param paramName
      * type: java.lang.String - 
      * desc: the parameter name
      *
      * @param paramClass 
      * type: java.lang.Class - 
      * desc: the class of the parameter
      *
      * @param paramValue 
      * type:java.lang.Object - 
      * desc: the parameter
      *
      * @param encoding 
      * type:java.lang.String - 
      * desc: the parameter encoding
      */
      public void addParameter(String paramName, Class  paramClass, Object paramValue, String
encoding) {
          parameters.addElement(new Parameter(paramName, paramClass, paramValue, encoding));
          
      }
      
      /** Processes client service requests.
      *
      * @param url
      * type: java.lang.String - 
      * desc: the service endpoint url
      *       defined in the WSDL file
      *
      * @throws SOAPException 
      * type: org.apache.soap.SOAPException - 
      * desc: thrown if an exception occurs
      *       contains details of the exception
      *
      * @return java.lang.Object - 
      * desc: the results of the service request
      *       must be cast by caller
      */
      public Object processRequest(String url) throws SOAPException {
          // create soap response
          Response response = null;
          Object result = null;
          try {
              request.setParams(parameters);
              response = request.invoke(new java.net.URL(url), "");
              // verify result
              if (response.generatedFault() == true && loggingEnabled == true) {
                      log.warn("system", response.getFault().getFaultString());
              }
              else {
              /* get result as object
                * caller must cast result to proper type
                */
                  result = response.getReturnValue().getValue();
                  // if logging enabled, output response
                  if (loggingEnabled == true) {
                      log.debug("debug", response.getReturnValue().toString());
                  }
              }
          }
          catch (java.net.MalformedURLException exception) {
              // if logging enabled output exception
              if (loggingEnabled == true) {
                  log.error("system", exception.getMessage(), exception);
              }
          }
          return result;
      }
      
  }
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/webservices/util/UDDIAccessBean.java
  
  Index: UDDIAccessBean.java
  ===================================================================
  /*
   * UDDIAccessBean.java
   *
   * Created on October 23, 2001, 7:39 PM
   */
  
  package org.apache.jetspeed.webservices.util;
  // import javabeans packages
  import java.io.Serializable;
  import java.beans.*;
  // import uddi packages
  import com.ibm.uddi.UDDIException;
  import com.ibm.uddi.client.UDDIProxy;
  import com.ibm.uddi.response.*;
  // import soap packages
  import org.apache.soap.SOAPException;
  // import logging framework
  import org.apache.turbine.util.Log;
  
  /**
   * UDDIAccessBean provides a command bean interface
   * to UDDI registry services.
   * Please note that  currently only inquiry tasks are supported. I
   * hope to add other task types soon.
   * @author  Scott A. Roehrig@IBM Corporation
   * @version 1.0
   */
  public class UDDIAccessBean extends Object implements Serializable {
      // declare member variables
      private transient UDDIProxy proxy;
      private String queryURL;
      private transient Log log;
      private boolean loggingEnabled;
      
      /** setter method for queryURL */
      public void setQueryURL(String queryURL) {
          this.queryURL = queryURL;
      }
      
      /** getter method for queryURL */
      public String getQueryURL() {
          return queryURL;
      }
      
      /** enables or disables logging services */
      public void setLogging(boolean loggingEnabled) {
          this.loggingEnabled = loggingEnabled;
          // if logging is enabled, output log message
          if (loggingEnabled == true) {
              log = new Log();
              log.debug("debug", "logging has been enabled");
          }
          else {
              log = null;
          }
      }
      
      /** creates new UDDIAccessBean */
      public UDDIAccessBean() {
          proxy = new UDDIProxy();
          queryURL = "http://www-3.ibm.com/services/uddi/testregistry/inquiryapi";
          setLogging(false);
      }
      
      /** creates new UDDIAccessBean with provided queryURL */
      public UDDIAccessBean(String queryURL) {
          proxy = new UDDIProxy();
          this.queryURL = queryURL;
          setLogging(false);
      }
      
      /** performs business lookup against registry */
      public java.util.List queryBusiness(String name) {
          // create list to store results
          java.util.List businessList = new java.util.Vector();
          // perform query
          try {
              proxy.setInquiryURL(queryURL);
              BusinessList results = proxy.find_business(name, null, 0);
              businessList = results.getBusinessInfos().getBusinessInfoVector();
              if (loggingEnabled == true) {
                  java.util.ListIterator iterator = businessList.listIterator();
                  while (iterator.hasNext() == true) {
                      com.ibm.uddi.response.BusinessInfo business = (com.ibm.uddi.response.BusinessInfo)iterator.next();
                      log.debug("debug", business.getDefaultDescriptionString());
                  }
              }
          }
          catch (java.net.MalformedURLException exception) {
              exception.printStackTrace();
              if (loggingEnabled == true) {
                  log.error("error", exception.getMessage(), exception);
              }
          }
          catch (UDDIException exception) {
              exception.printStackTrace();
              if (loggingEnabled == true) {
                  log.error("error", exception.getMessage(), exception);
              }
          }
          catch (SOAPException exception) {
              exception.printStackTrace();
              if (loggingEnabled == true) {
                  log.error("error", exception.getMessage(), exception);
              }
          }
          // return results
          return businessList;
      }
      
      /** returns businessKey object associated with provided business */
     public String getBusinessKey(String businessName) {
         String businessKey = null;
         // create List to store results
         java.util.List businessList = new java.util.Vector();
         // perform query
         try {
              proxy.setInquiryURL(queryURL);
              BusinessList results = proxy.find_business(businessName, null, 0);
              businessList = results.getBusinessInfos().getBusinessInfoVector();
              // create iterator to search for match
              java.util.ListIterator iterator = businessList.listIterator();
              while (iterator.hasNext() == true) {
                  BusinessInfo business  = (BusinessInfo)iterator.next();
                  if (business.getNameString().equals(businessName)) {
                      businessKey = business.getBusinessKey();
                      if (loggingEnabled == true) {
                          log.debug("debug", business.getNameString()+" has associated key
"+businessKey);
                      }
                  }
              }
         }
         catch (java.net.MalformedURLException exception) {
              exception.printStackTrace();
              if (loggingEnabled == true) {
                  log.error("error", exception.getMessage(), exception);
              }
         }
         catch (UDDIException exception) {
              exception.printStackTrace();
             if (loggingEnabled == true) {
                  log.error("error", exception.getMessage(), exception);
              } 
         }
         catch (SOAPException exception) {
              exception.printStackTrace();
              if (loggingEnabled == true) {
                  log.error("error", exception.getMessage(), exception);
              }
         }
         // return result
         return businessKey;
     }
     
      /** performs service lookup against registry */
      public java.util.List queryService(String businessKey, String description) {
          // create List to store results
          java.util.List serviceList = new java.util.Vector();
          // perform query
          try {
              proxy.setInquiryURL(queryURL);
              ServiceList results = proxy.find_service(businessKey, description, null, 0);
              serviceList = results.getServiceInfos().getServiceInfoVector();
              if (loggingEnabled == true) {
                  java.util.ListIterator iterator = serviceList.listIterator();
                  while (iterator.hasNext() == true) {
                      com.ibm.uddi.response.ServiceInfo service = (com.ibm.uddi.response.ServiceInfo)iterator.next();
                      log.debug("debug", service.getNameString());
                  }
              }
          }
          catch (java.net.MalformedURLException exception) {
              exception.printStackTrace();
              if (loggingEnabled == true) {
                  log.error("error", exception.getMessage(), exception);
              }
          }
          catch (UDDIException exception) {
              exception.printStackTrace();
              if (loggingEnabled == true) {
                  log.error("error", exception.getMessage(), exception);
              }
          }
          catch (SOAPException exception) {
              exception.printStackTrace();
              if (loggingEnabled == true) {
                  log.error("error", exception.getMessage(), exception);
              }
          }
          // return results
          return serviceList;
      }
      
      /** returns serviceKey associated with provided service */
      public String getServiceKey(String businessKey, String serviceName) {
          String serviceKey = null;
         // create List to store results
         java.util.List serviceList = new java.util.Vector();
         // perform query
         try {
              proxy.setInquiryURL(queryURL);
              ServiceList results = proxy.find_service(businessKey, serviceName, null, 0);
              serviceList = results.getServiceInfos().getServiceInfoVector();
              // create iterator to search for match
              java.util.ListIterator iterator = serviceList.listIterator();
              while (iterator.hasNext() == true) {
                  ServiceInfo service  = (ServiceInfo)iterator.next();
                  if (service.getNameString().equals(serviceName)) {
                      serviceKey = service.getServiceKey();
                      if (loggingEnabled == true) {
                          log.debug("debug", service.getNameString()+" has associated key
"+serviceKey);
                      }
                  }
              }
         }
         catch (java.net.MalformedURLException exception) {
              exception.printStackTrace();
              if (loggingEnabled == true) {
                  log.error("error", exception.getMessage(), exception);
              }
         }
         catch (UDDIException exception) {
              exception.printStackTrace();
              if (loggingEnabled == true) {
                  log.error("error", exception.getMessage(), exception);
              }
         }
         catch (SOAPException exception) {
              exception.printStackTrace();
              if (loggingEnabled == true) {
                  log.error("error", exception.getMessage(), exception);
              }
         }
         // return result
         return serviceKey;
      }
      
      /** called before object is garbage collected */
      public void finalize() {
          setLogging(false);
          proxy = null;
          log = null;
          queryURL = null;
      }
      
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:jetspeed-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:jetspeed-dev-help@jakarta.apache.org>


Mime
View raw message