You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by bu...@apache.org on 2004/01/16 04:58:26 UTC

DO NOT REPLY [Bug 26182] New: - FileProvider causes NullPointerException

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26182>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26182

FileProvider causes NullPointerException

           Summary: FileProvider causes NullPointerException
           Product: Axis
           Version: current (nightly)
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Critical
          Priority: Other
         Component: Basic Architecture
        AssignedTo: axis-dev@ws.apache.org
        ReportedBy: thilo.frotscher@web.de


If you want to configure the Axis Engine on the client dynamically, the 
following code is supposed to work:

     EngineConfiguration myConfig = new FileProvider("my-client-config.wsdd");
     // next line causes NullPointerException
     Chain globalReqChain = (Chain) myConfig.getGlobalRequest();
     MyHandler h = new MyHandler();
     globalReqChain.addHandler(h);
     Service service = new Service(myConfig);
     Call     call    = (Call) service.createCall();

The second line causes a NullPointerException. 
Even the follwing code causes this exception:

         EngineConfigurationFactory f =
               EngineConfigurationFactoryDefault.newFactory(null);
         EngineConfiguration defaultConfig = f.getClientEngineConfig();
         SimpleProvider myConfig = new SimpleProvider(defaultConfig);
         Chain globalReqChain = (Chain) myConfig.getGlobalRequest();

Why is this? Look at FileProvider's method getGlobalRequest():

     public Handler getGlobalRequest() throws ConfigurationException {
         return deployment.getGlobalRequest();
     }


The variable deployment is null, because it is initialized only if
configureEngine() is called. Only then the WSDD document is loaded!
In my opinion, the loading of the WSDD should be moved to a separate
method like this:

private void loadDeployment() {
    if (getInputStream() == null) {
       try {
          setInputStream(new FileInputStream(configFile));
       } catch (Exception e) {
          if (searchClasspath)
             setInputStream(ClassUtils.getResourceAsStream(engine.getClass(), 
filename));
       }
    }

    if (getInputStream() == null) {
       throw new ConfigurationException(
         Messages.getMessage("noConfigFile"));
    }

    WSDDDocument doc = new WSDDDocument(XMLUtils.
                                  newDocument(getInputStream()));
    deployment = doc.getDeployment();
}



Then, configureEngine looks like this:

     public void configureEngine(AxisEngine engine)
         throws ConfigurationException {
             loadDeployment();
             deployment.configureEngine(engine);
             engine.refreshGlobalOptions();

             setInputStream(null);
         } catch (Exception e) {
             throw new ConfigurationException(e);
         }
     }



And, to fix the NullPointerException, getGlobalRequest() looks like this:

     public Handler getGlobalRequest() throws ConfigurationException {
         if (deployment==null)
             loadDeployment();

         return deployment.getGlobalRequest();
     }


All other methods, where deployment is referenced, should test the variabe
deployment for a null value the same way.