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)

7 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. Hi, I am using above code { DefaultBootstrap.bootstrap();} but when I deployed to server this exception is throwing:

      Exception in thread "main" java.lang.ClassCastException: org.opensaml.core.xml.schema.impl.XSAnyBuilder cannot be cast to org.opensaml.xml.XMLObjectBuilder

      inside lib. location is :

      at org.opensaml.xml.XMLConfigurator.load(XMLConfigurator.java:182)
      at org.opensaml.xml.XMLConfigurator.load(XMLConfigurator.java:166)
      at org.opensaml.xml.XMLConfigurator.load(XMLConfigurator.java:143)
      at org.opensaml.DefaultBootstrap.initializeXMLTooling(DefaultBootstrap.java:224)
      at org.opensaml.DefaultBootstrap.initializeXMLTooling(DefaultBootstrap.java:207)
      at org.opensaml.DefaultBootstrap.bootstrap(DefaultBootstrap.java:100)

      Couldn't identify the reason, can you guys help on this. please.



      Delete
    3. According to this, https://issues.shibboleth.net/jira/browse/OSJ-152, it sound like it might be a problem where you have some packages from OpenSAML 2 and some from OpenSAML 3

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

    ReplyDelete
  3. when I used above code for the initialization of SAML, it is throwing below exception, any idea or help:

    Exception in thread "main" java.lang.ClassCastException: org.opensaml.core.xml.schema.impl.XSAnyBuilder cannot be cast to org.opensaml.xml.XMLObjectBuilder
    at org.opensaml.xml.XMLConfigurator.initializeObjectProviders(XMLConfigurator.java:236)
    at org.opensaml.xml.XMLConfigurator.load(XMLConfigurator.java:182)
    at org.opensaml.xml.XMLConfigurator.load(XMLConfigurator.java:166)
    at org.opensaml.xml.XMLConfigurator.load(XMLConfigurator.java:143)
    at org.opensaml.DefaultBootstrap.initializeXMLTooling(DefaultBootstrap.java:224)
    at org.opensaml.DefaultBootstrap.initializeXMLTooling(DefaultBootstrap.java:207)
    at org.opensaml.DefaultBootstrap.bootstrap(DefaultBootstrap.java:100)
    at se.cambio.platform.auth.metadata.util.SAMLUtil.createSAMLObject(SAMLUtil.java:14)

    ReplyDelete
    Replies
    1. According to this, https://issues.shibboleth.net/jira/browse/OSJ-152, it sound like it might be a problem where you have some packages from OpenSAML 2 and some from OpenSAML 3

      Delete