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 Thilo Frotscher <th...@web.de> on 2003/12/27 13:55:17 UTC

Bug? FileProvider causes NullPointerException - Please clarify

Hi!

Please clarify if this is a bug. I think it is, but I didn't want
to add a bug report in Bugzilla before this is clarified. Maybe
the current behaviour has a certain intention I didn't discover
so far.

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");
     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. Why is this?
Let's 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 deployment
for a null value the same way.

Thanks,
Thilo