Monday, May 5, 2014

Nullpointer exception in OpenSAML

This is a common exception to beginners in using OpenSAML. A common mistake when starting to use the OpenSAML library is to not initialise the library.
OpenSAML needs a couple of configuration files in order to work. The library is provided with a default set of these files that is sufficient for mot uses. Before starting the use the library the configurations must be loaded. This is done using the bootstrap function.

try {
   DefaultBootstrap.bootstrap();
} catch (ConfigurationException e) {
   throw new RuntimeException("Bootstrapping failed");
}      

If you do not do this before you start using the library, you might run into exceptions like.

Exception in thread "main" java.lang.NullPointerException
 at no.steras.opensaml.Main.main(Main.java:25)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:601)
 at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

3 comments:

  1. What to do if DefaultBootstrap gives an InputStream cannot be null?
    Exception in thread "main" java.lang.IllegalArgumentException: InputStream cannot be null
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:117)
    at org.opensaml.xml.parse.BasicParserPool$DocumentBuilderProxy.parse(BasicParserPool.java:671)
    at org.opensaml.xml.parse.BasicParserPool.parse(BasicParserPool.java:215)
    at org.opensaml.xml.XMLConfigurator.load(XMLConfigurator.java:141)
    at org.opensaml.DefaultBootstrap.initializeXMLTooling(DefaultBootstrap.java:199)
    at org.opensaml.DefaultBootstrap.bootstrap(DefaultBootstrap.java:91)
    at com.ccs.saml.metadata.SamlMetadataGenerator.main(SamlMetadataGenerator.java:34)

    Do I need to put a config-file somewhere specific?
    If so, which file and where should I put it?

    ReplyDelete
    Replies
    1. Try this
      http://stackoverflow.com/questions/4956087/opensaml-bootstrap-nets-me-inputstream-cannot-be-null

      Delete
  2. Thanks, after adding openws.jar and creating a good X509 certificate, I now got it working.

    ReplyDelete