owenb       2003/03/04 08:25:20

  Modified:    java/src/org/apache/wsif/util WSIFUtils.java
  Log:
  Add new utility method to read wsdl through an authenticating proxy
  Improve javadoc comments for the readWSDL methods
  Tidy up imports
  
  Revision  Changes    Path
  1.31      +126 -42   xml-axis-wsif/java/src/org/apache/wsif/util/WSIFUtils.java
  
  Index: WSIFUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/util/WSIFUtils.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- WSIFUtils.java    27 Feb 2003 15:46:30 -0000      1.30
  +++ WSIFUtils.java    4 Mar 2003 16:25:19 -0000       1.31
  @@ -87,6 +87,7 @@
   import javax.wsdl.extensions.ExtensibilityElement;
   import javax.wsdl.extensions.ExtensionRegistry;
   import javax.wsdl.factory.WSDLFactory;
  +import javax.wsdl.xml.WSDLLocator;
   import javax.wsdl.xml.WSDLReader;
   import javax.wsdl.xml.WSDLWriter;
   import javax.xml.namespace.QName;
  @@ -95,16 +96,13 @@
   import org.apache.wsif.WSIFException;
   import org.apache.wsif.WSIFService;
   import org.apache.wsif.base.WSIFServiceImpl;
  -import org.apache.wsif.compiler.schema.tools.Schema2Java;
   import org.apache.wsif.format.WSIFFormatHandler;
   import org.apache.wsif.logging.MessageLogger;
   import org.apache.wsif.logging.Trc;
   import org.apache.wsif.mapping.WSIFDefaultMapper;
   import org.apache.wsif.providers.ProviderUtils;
  -import org.apache.wsif.schema.ComplexType;
  -import org.apache.wsif.schema.ElementType;
  -import org.apache.wsif.schema.Parser;
  -import org.apache.wsif.schema.SequenceElement;
  +import org.apache.wsif.wsdl.AuthenticatingProxyWSDLLocatorImpl;
  +import org.apache.wsif.wsdl.ClosableLocator;
   import org.apache.wsif.wsdl.WSIFWSDLLocatorImpl;
   import org.apache.wsif.wsdl.extensions.format.TypeMapping;
   import org.w3c.dom.Document;
  @@ -112,7 +110,6 @@
   import org.xml.sax.InputSource;
   
   import com.ibm.wsdl.Constants;
  -import com.ibm.wsdl.PartImpl;
   
   /**
    * This class provides utilities for WSIF runtime and generated stubs.
  @@ -437,9 +434,14 @@
       }
   
       /**
  -     * Read WSDL - it is different from standard readWSDL method as it is
  -     * using extensibility elements that were registered for dynamic port
  -     * factory.
  +     * Read WSDL - it is different from a WSDLReader readWSDL method in that it
  +     * specifies the use of the WSIF WSDLFactory implementation which registers
  +     * the extensiblity elements used by the WSIF providers.
  +     * @param contextURL The context in which to resolve the wsdlLoc, if the 
wsdlLoc is 
  +     * relative. Can be null, in which case it will be ignored.
  +     * @param wsdlLoc a URI (can be a filename or URL) pointing to a WSDL XML 
definition.
  +     * @return Defintion object representing the definition in the wsdl
  +     * @throws WSDLException Exception thrown if wsdl cannot be read
        */
       public static Definition readWSDL(String contextURL, String wsdlLoc)
           throws WSDLException {
  @@ -463,10 +465,58 @@
       }
   
       /**
  -     * Read WSDL - it is different from standard readWSDL method as it is
  -     * using extensibility elements that were registered for dynamic port
  -     * factory.  It also uses the accompanying class loader to load imported WSDL
  -     * resources.
  +     * Read WSDL through an authenticating proxy. It is different from a WSDLReader 
  +     * readWSDL method in that it
  +     * specifies the use of the WSIF WSDLFactory implementation which registers
  +     * the extensiblity elements used by the WSIF providers.
  +     * @param wsdlLoc a URI (must be an http or ftp URL) pointing to a WSDL file
  +     * @param proxyUsername proxy authentication username
  +     * @param proxyPassword proxy authentication password
  +     * @return Defintion object representing the definition in the wsdl
  +     * @throws WSDLException Exception thrown if wsdl cannot be read
  +     */
  +    public static Definition readWSDLThroughAuthProxy(String wsdlLoc, String 
proxyUsername, String proxyPassword)
  +        throws WSDLException {
  +        Trc.entry(null, wsdlLoc, proxyUsername, "********");
  +
  +        initializeProviders();
  +
  +        WSDLFactory factory = WSDLFactory.newInstance(
  +            WSIFConstants.WSIF_WSDLFACTORY);
  +        WSDLReader wsdlReader = factory.newWSDLReader();
  +        wsdlReader.setFeature(Constants.FEATURE_VERBOSE, false);
  +        WSDLLocator lo = null;
  +        try {
  +            lo = new AuthenticatingProxyWSDLLocatorImpl(wsdlLoc, proxyUsername, 
proxyPassword);
  +            Definition def = wsdlReader.readWSDL(lo);
  +            Trc.exitExpandWsdl(def);
  +            return def;
  +        } catch (WSDLException e) {
  +            Trc.exception(e);
  +            MessageLogger.log("WSIF.0002E", wsdlLoc);
  +            throw e;
  +        } finally {
  +             try {
  +                     if (lo != null && lo instanceof ClosableLocator) {
  +                         ((ClosableLocator) lo).close();
  +                     }
  +             } catch (IOException ioe) {
  +                     //ignore
  +                     Trc.ignoredException(ioe);
  +             }
  +        }
  +    }
  +
  +    /**
  +     * Read WSDL - it is different from a WSDLReader readWSDL method in that it
  +     * specifies the use of the WSIF WSDLFactory implementation which registers
  +     * the extensiblity elements used by the WSIF providers.
  +     * @param documentBase A URL for the document base URI for the wsdl
  +     * @param reader A Reader "pointing at" the wsdl file
  +     * @param cl A ClassLoader used to resolve relative imports when files are in
  +     * in the classpath
  +     * @return Defintion object representing the definition in the wsdl
  +     * @throws WSDLException Exception thrown if wsdl cannot be read
        */
       public static Definition readWSDL(
           URL documentBase,
  @@ -478,10 +528,15 @@
       }
   
       /**
  -     * Read WSDL - it is different from standard readWSDL method as it is
  -     * using extensibility elements that were registered for dynamic port
  -     * factory.  It also uses the accompanying class loader to load imported WSDL
  -     * resources.
  +     * Read WSDL - it is different from a WSDLReader readWSDL method in that it
  +     * specifies the use of the WSIF WSDLFactory implementation which registers
  +     * the extensiblity elements used by the WSIF providers.
  +     * @param documentBase The document base URI for the wsdl
  +     * @param reader A Reader "pointing at" the wsdl file
  +     * @param cl A ClassLoader used to resolve relative imports when files are in
  +     * in the classpath
  +     * @return Defintion object representing the definition in the wsdl
  +     * @throws WSDLException Exception thrown if wsdl cannot be read
        */
       public static Definition readWSDL(
           String documentBase,
  @@ -517,10 +572,16 @@
       }
   
       /**
  -     * Read WSDL - it is different from standard readWSDL method as it is
  -     * using extensibility elements that were registered for dynamic port
  -     * factory.  It also uses the accompanying class loader to load imported WSDL
  -     * resources.
  +     * Read WSDL - it is different from a WSDLReader readWSDL method in that it
  +     * specifies the use of the WSIF WSDLFactory implementation which registers
  +     * the extensiblity elements used by the WSIF providers.
  +     * @param contextURL The context in which to resolve the wsdlLoc, if the 
wsdlLoc is 
  +     * relative. Can be null, in which case it will be ignored.
  +     * @param wsdlLoc a URI (can be a filename or URL) pointing to a WSDL XML 
definition.
  +     * @param cl A ClassLoader used to resolve relative imports when files are in
  +     * in the classpath
  +     * @return Defintion object representing the definition in the wsdl
  +     * @throws WSDLException Exception thrown if wsdl cannot be read
        */
       public static Definition readWSDL(
           URL contextURL,
  @@ -558,13 +619,20 @@
       }
   
       /**
  -     * Read WSDL - it is different from standard readWSDL method as it is
  -     * using extensibility elements that were registered for dynamic port
  -     * factory.
  +     * Read WSDL - it is different from a WSDLReader readWSDL method in that it
  +     * specifies the use of the WSIF WSDLFactory implementation which registers
  +     * the extensiblity elements used by the WSIF providers.
  +     * @param documentBaseURI the document base URI of the WSDL definition
  +     * described by the element. Will be set as the documentBaseURI
  +     * of the returned Definition. Can be null, in which case it
  +     * will be ignored.
  +     * @param reader A Reader "pointing at" the wsdl file
  +     * @return Defintion object representing the definition in the wsdl
  +     * @throws WSDLException Exception thrown if wsdl cannot be read
        */
  -    public static Definition readWSDL(String contextURL, Reader reader)
  +    public static Definition readWSDL(String documentBaseURI, Reader reader)
           throws WSDLException {
  -        Trc.entry(null, contextURL, reader);
  +        Trc.entry(null, documentBaseURI, reader);
   
           initializeProviders();
   
  @@ -573,19 +641,26 @@
           WSDLReader wsdlReader = factory.newWSDLReader();
           wsdlReader.setFeature(Constants.FEATURE_VERBOSE, false);
           Definition def =
  -            wsdlReader.readWSDL(contextURL, new InputSource(reader));
  +            wsdlReader.readWSDL(documentBaseURI, new InputSource(reader));
           Trc.exitExpandWsdl(def);
           return def;
       }
   
       /**
  -     * Read WSDL - it is different from standard readWSDL method as it is
  -     * using extensibility elements that were registered for dynamic port
  -     * factory.
  +     * Read WSDL - it is different from a WSDLReader readWSDL method in that it
  +     * specifies the use of the WSIF WSDLFactory implementation which registers
  +     * the extensiblity elements used by the WSIF providers.
  +     * @param documentBaseURI the document base URI of the WSDL definition
  +     * described by the element. Will be set as the documentBaseURI
  +     * of the returned Definition. Can be null, in which case it
  +     * will be ignored.
  +     * @param wsdlDocument The base wsdl document
  +     * @return Defintion object representing the definition in the wsdl
  +     * @throws WSDLException Exception thrown if wsdl cannot be read
        */
  -    public static Definition readWSDL(String contextURL, Document wsdlDocument)
  +    public static Definition readWSDL(String documentBaseURI, Document wsdlDocument)
           throws WSDLException {
  -        Trc.entry(null, contextURL, wsdlDocument);
  +        Trc.entry(null, documentBaseURI, wsdlDocument);
   
           initializeProviders();
   
  @@ -593,22 +668,29 @@
               WSIFConstants.WSIF_WSDLFACTORY);
           WSDLReader wsdlReader = factory.newWSDLReader();
           wsdlReader.setFeature(Constants.FEATURE_VERBOSE, false);
  -        Definition def = wsdlReader.readWSDL(contextURL, wsdlDocument);
  +        Definition def = wsdlReader.readWSDL(documentBaseURI, wsdlDocument);
   
           Trc.exitExpandWsdl(def);
           return def;
       }
   
       /**
  -     * Read WSDL - it is different from standard readWSDL method as it is
  -     * using extensibility elements that were registered for dynamic port
  -     * factory.
  +     * Read WSDL - it is different from a WSDLReader readWSDL method in that it
  +     * specifies the use of the WSIF WSDLFactory implementation which registers
  +     * the extensiblity elements used by the WSIF providers.
  +     * @param documentBaseURI the document base URI of the WSDL definition
  +     * described by the element. Will be set as the documentBaseURI
  +     * of the returned Definition. Can be null, in which case it
  +     * will be ignored.
  +     * @param definitionsElement the <wsdl:definitions> element
  +     * @return Defintion object representing the definition in the wsdl
  +     * @throws WSDLException Exception thrown if wsdl cannot be read
        */
       public static Definition readWSDL(
  -        String contextURL,
  +        String documentBaseURI,
           Element wsdlServicesElement)
           throws WSDLException {
  -        Trc.entry(null, contextURL, wsdlServicesElement);
  +        Trc.entry(null, documentBaseURI, wsdlServicesElement);
   
           initializeProviders();
   
  @@ -616,16 +698,18 @@
               WSIFConstants.WSIF_WSDLFACTORY);
           WSDLReader wsdlReader = factory.newWSDLReader();
           wsdlReader.setFeature(Constants.FEATURE_VERBOSE, false);
  -        Definition def = wsdlReader.readWSDL(contextURL, wsdlServicesElement);
  +        Definition def = wsdlReader.readWSDL(documentBaseURI, wsdlServicesElement);
   
           Trc.exitExpandWsdl(def);
           return def;
       }
   
       /**
  -     * Write WSDL - it is different from standard writeWSDL method as it is
  -     * using extensibility elements that were registered for dynamic port
  -     * factory.
  +     * Write WSDL. This method will use the WSIF WSDLFactory implementation to
  +     * create a WSDLWriter.
  +     * @param wsdlDef the WSDL definition to be written.
  +     * @param sink the Writer to write the xml to.
  +     * @throws WSDLException Exception thrown if wsdl cannot be written
        */
       public static void writeWSDL(Definition def, Writer sink)
           throws WSDLException {
  
  
  

Reply via email to