You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsif-dev@ws.apache.org by ow...@apache.org on 2003/02/09 17:08:08 UTC

cvs commit: xml-axis-wsif/java/src/org/apache/wsif/wsdl AuthenticatingProxyWSDLLocatorImpl.java WSIFWSDLLocatorImpl.java

owenb       2003/02/09 08:08:08

  Modified:    java/src/org/apache/wsif/wsdl
                        AuthenticatingProxyWSDLLocatorImpl.java
                        WSIFWSDLLocatorImpl.java
  Log:
  Updated to work with the latest wsdl4j:
  Implement getBaseInputSource and getImportInputSource as required by the latest version of the javax.wsdl.xml.WSDLLocator interface.
  getBaseReader and getImportReader are no longer required by the interface.
  
  Revision  Changes    Path
  1.5       +12 -8     xml-axis-wsif/java/src/org/apache/wsif/wsdl/AuthenticatingProxyWSDLLocatorImpl.java
  
  Index: AuthenticatingProxyWSDLLocatorImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/wsdl/AuthenticatingProxyWSDLLocatorImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AuthenticatingProxyWSDLLocatorImpl.java	8 Jan 2003 15:54:44 -0000	1.4
  +++ AuthenticatingProxyWSDLLocatorImpl.java	9 Feb 2003 16:08:08 -0000	1.5
  @@ -67,6 +67,8 @@
   
   import javax.wsdl.WSDLException;
   
  +import org.xml.sax.InputSource;
  +
   /**
    * Implementation of javax.wsdl.xml.WSDLLocator. This class can be used to
    * locate a wsdl document behind an authenticating proxy. Only http and ftp
  @@ -120,11 +122,11 @@
       }
   
       /**
  -     * Get a reader for the base wsdl document. Returns null if the document
  +     * Get a InputSource for the base wsdl document. Returns null if the document
        * cannot be located.
  -     * @return The reader or null if the import cannot be resolved
  +     * @return The InputSource or null if the import cannot be resolved
        */
  -    public Reader getBaseReader() {
  +    public InputSource getBaseInputSource() {
           if (baseReader == null) {
               try {
   				URL url = new URL(wsdlLocation);
  @@ -143,17 +145,18 @@
                   documentBase = wsdlLocation;
               }
           }
  -        return baseReader;
  +        if (baseReader == null) return null;
  +        return new InputSource(baseReader);
       }
   
       /**
  -     * Get a reader for an imported wsdl document. Returns null if the import document
  +     * Get a InputSource for an imported wsdl document. Returns null if the import document
        * cannot be located.
        * @param base The document base uri for the parent wsdl document
        * @param relativeLocation The relative uri of the import wsdl document
  -     * @return The reader or null if the import cannot be resolved
  +     * @return The InputSource or null if the import cannot be resolved
        */
  -    public Reader getImportReader(String base, String relativeLocation) {
  +    public InputSource getImportInputSource(String base, String relativeLocation) {
           try {
   			URL contextURL = (base != null) ? new URL(base) : null;            
               URL url = new URL(contextURL, relativeLocation);
  @@ -172,7 +175,8 @@
           	// necessary to avoid a NullPointerException in WSDLReaderImpl
           	importBase = "unknownImportURI";
           }
  -        return importReader;
  +        if (importReader == null) return null;
  +        return new InputSource(importReader);
       }
   
       /**
  
  
  
  1.13      +68 -28    xml-axis-wsif/java/src/org/apache/wsif/wsdl/WSIFWSDLLocatorImpl.java
  
  Index: WSIFWSDLLocatorImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/wsdl/WSIFWSDLLocatorImpl.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- WSIFWSDLLocatorImpl.java	7 Dec 2002 12:34:04 -0000	1.12
  +++ WSIFWSDLLocatorImpl.java	9 Feb 2003 16:08:08 -0000	1.13
  @@ -64,6 +64,7 @@
   import java.net.URL;
   
   import org.apache.wsif.logging.Trc;
  +import org.xml.sax.InputSource;
   
   import com.ibm.wsdl.util.StringUtils;
   
  @@ -77,7 +78,8 @@
   public class WSIFWSDLLocatorImpl implements javax.wsdl.xml.WSDLLocator { 
    
       Reader baseReader = null; 
  -    Reader importReader = null; 
  +    InputStream baseInputStream = null;
  +    InputStream importInputStream = null;     
       String contextURI = null; 
       String wsdlLocation = null; 
       String documentBase = null; 
  @@ -113,19 +115,22 @@
       } 
   
   	/**
  -	 * Get a reader for the base wsdl document. Returns null if the document
  +	 * Get a InputSource for the base wsdl document. Returns null if the document
   	 * cannot be located.
  -	 * @return The reader or null if the import cannot be resolved
  +	 * @return The InputSource or null if the import cannot be resolved
   	 */  
  -    public Reader getBaseReader() { 
  +    public InputSource getBaseInputSource() { 
       	Trc.entry(this);
  -        if (baseReader == null) { 
  +    	if (baseReader != null) {
  +    		return new InputSource(baseReader);
  +    	}
  +    	Reader reader = null;
  +        if (baseInputStream == null) { 
               try { 
                   URL url = null; 
                   URL contextURL = 
                       (contextURI != null) ? StringUtils.getURL(null, contextURI) : null; 
  -                if (loader != null) { 
  -                    InputStream in = null; 
  +                if (loader != null) {  
                       try { 
                           if (contextURL != null) 
                               url = new URL(contextURL, wsdlLocation); 
  @@ -138,15 +143,15 @@
                           String wsdlRelativeLocation = url.getPath(); 
                           if (wsdlRelativeLocation.startsWith("/")) 
                               wsdlRelativeLocation = wsdlRelativeLocation.substring(1); 
  -                        in = loader.getResourceAsStream(wsdlRelativeLocation); 
  -                        baseReader = new InputStreamReader(in); 
  +                        baseInputStream = loader.getResourceAsStream(wsdlRelativeLocation); 
  +//                        baseReader = new InputStreamReader(in);
                       } catch (Exception exc) { 
   			        	Trc.ignoredException(exc);
                       } 
                   } 
  -                if (baseReader == null) { 
  +                if (baseInputStream == null) { 
                       url = StringUtils.getURL(contextURL, wsdlLocation); 
  -                    baseReader = StringUtils.getContentAsReader(url); 
  +                    reader = StringUtils.getContentAsReader(url);                    
                   } 
                   if (url != null) 
                       documentBase = url.toString(); 
  @@ -156,21 +161,26 @@
               } 
           } 
           Trc.exit();
  -        return baseReader; 
  +        if (baseInputStream == null) {
  +        	if (reader != null) return new InputSource(reader);
  +        	return null;
  +        }
  +        return new InputSource(baseInputStream); 
       } 
   
   	/**
  -	 * Get a reader for an imported wsdl document. Returns null if the import document
  +	 * Get a InputSource for an imported wsdl document. Returns null if the import document
   	 * cannot be located.
   	 * @param base The document base uri for the parent wsdl document
   	 * @param relativeLocation The relative uri of the import wsdl document
  -	 * @return The reader or null if the import cannot be resolved
  +	 * @return The InputSource or null if the import cannot be resolved
   	 */
  -    public Reader getImportReader(String base, String relativeLocation) {
  +    public InputSource getImportInputSource(String base, String relativeLocation) {
       	Trc.entry(this,base,relativeLocation);
       	
  -    	// Reset importReader if finding import within import
  -    	importReader = null;
  +    	// Reset importInputStream if finding import within import
  +    	importInputStream = null;
  +    	Reader reader = null;
       	boolean triedSU = false; 
           try { 
               // If a ClassLoader was used to load the base document, chances 
  @@ -181,14 +191,13 @@
                       // Relative location has been specified from a root dir. However, 
                       // using a ClassLoader, root dirs don't mean anything. 
                       relativeLocation = relativeLocation.substring(1, relativeLocation.length()); 
  -                    InputStream in = loader.getResourceAsStream(relativeLocation); 
  -                    importReader = new InputStreamReader(in); 
  +                    importInputStream = loader.getResourceAsStream(relativeLocation); 
                   } else if (relativeLocation.indexOf("://") != -1) { 
                       // This is a fully specified URL of some kind so don't use the 
                       // ClassLoader to find the import.
                       triedSU = true; 
                       url = StringUtils.getURL(null, relativeLocation); 
  -                    importReader = StringUtils.getContentAsReader(url); 
  +                    reader = StringUtils.getContentAsReader(url);                    
                   } else { 
                       // Import location has been specified relative to the base document 
                       // and so we can to try to form the complete path to it. 						 
  @@ -215,19 +224,17 @@
                           } else { 
                               url = new URL(null, "file:" + relativeLocation); 
                           }  
  -                        InputStream in = loader.getResourceAsStream(url.getPath()); 
  -                        importReader = new InputStreamReader(in); 
  +                        importInputStream = loader.getResourceAsStream(url.getPath());  
                       } else {                    	
                       	url = new URL(null, "file:" + relativeLocation);
  -                    	InputStream in = loader.getResourceAsStream(url.getPath()); 
  -                        importReader = new InputStreamReader(in); 
  +                    	importInputStream = loader.getResourceAsStream(url.getPath());  
                       }
                   } 
               } else {
               	triedSU = true; 
                   URL contextURL = (base != null) ? StringUtils.getURL(null, base) : null; 
                   url = StringUtils.getURL(contextURL, relativeLocation); 
  -                importReader = StringUtils.getContentAsReader(url); 
  +                reader = StringUtils.getContentAsReader(url);                
               } 
               importBase = (url == null) ? relativeLocation : url.toString(); 
           } catch (Exception e) {
  @@ -238,7 +245,7 @@
           		try {        		
                  	    URL contextURL = (base != null) ? StringUtils.getURL(null, base) : null; 
                       URL url = StringUtils.getURL(contextURL, relativeLocation); 
  -                    importReader = StringUtils.getContentAsReader(url);
  +                    reader = StringUtils.getContentAsReader(url);
                       importBase = (url == null) ? relativeLocation : url.toString();         		
           		} catch (Exception e2) {
           			Trc.exception(e2);
  @@ -253,10 +260,42 @@
           	}
           } 
           Trc.exit();
  -        return importReader; 
  +        if (importInputStream == null) {
  +        	if (reader != null) return new InputSource(reader); 
  +            return null;
  +        }
  +        return new InputSource(importInputStream); 
       } 
   
   	/**
  +	 * @deprecated Old WSDLLocator method, no longer on the interface
  +	 */
  +    public Reader getBaseReader() {
  +    	InputSource is = getBaseInputSource();
  +    	if (is == null) return null;
  +    	if (is.getCharacterStream() != null) {
  +    		return is.getCharacterStream();
  +    	} else if (is.getByteStream() != null) {
  +    		return new InputStreamReader(is.getByteStream());
  +    	}    	
  +    	return null;
  +    }
  +
  +	/**
  +	 * @deprecated Old WSDLLocator method, no longer on the interface
  +	 */
  +    public Reader getImportReader(String base, String relativeLocation) {    	    	
  +    	InputSource is = getImportInputSource(base, relativeLocation);
  +    	if (is == null) return null;
  +    	if (is.getCharacterStream() != null) {
  +    		return is.getCharacterStream();
  +    	} else if (is.getByteStream() != null) {
  +    		return new InputStreamReader(is.getByteStream());
  +    	}    	
  +    	return null;
  +    }
  +    
  +	/**
   	 * Get the document base uri for the base wsdl document
   	 * @return The document base uri
   	 */ 
  @@ -315,7 +354,8 @@
        */
       public void close() throws IOException {
      		if (baseReader != null) baseReader.close();
  -  		if (importReader != null) importReader.close();
  +  		if (importInputStream != null) importInputStream.close();
  +  		if (baseInputStream != null) baseInputStream.close();
       }    
   }