Search code examples
javaopensaml

Unable to invoke DefaultBootstrap.bootstrap(); method in own opensaml unmarshalling method


I have written the following unmarshalling method to process my xml file but am faced with the following error during execution.

The following snippet is my code:

private Response a(String text) throws ConfigurationException, SAXException  {

        try {
             DefaultBootstrap.bootstrap();   <= ERROR HERE
        }
        catch(ConfigurationException e) {
             log.error("Error Encountered", e);
        }

        Schema s = SAMLSchemaBuilder.getSAML11Schema();

        BasicParserPool bpp = new BasicParserPool();
        bpp.setNamespaceAware(true);
        bpp.setIgnoreElementContentWhitespace(true);
        bpp.setSchema(schema);

        InputStream is= new ByteArrayInputStream(Base64.decode(samlContent).getBytes());
        Response res= null;

        try {
            Document doc = bpp.parse(is);
            Element elmt= doc.getDocumentElement();
            try {

                QName qn = new QName(elmt.getNamespaceURI(), elmt.getLocalName(), elmt.getPrefix());
                Unmarshaller um = Configuration.getUnmarshallerFactory().getUnmarshaller(qn);
                samlResponse = (Response) unmarshaller.unmarshall(elmt);
            } catch (XMLParserException e) {
                  logger.debug(e.getMessage());
        } catch (UnmarshallingException e) {
            logger.debug(e.getMessage());
        }

        return res;
    }

The following is the error messaged return in the IDE:

java.lang.IllegalArgumentException: Error create SSL context

    at org.opensaml.ws.soap.client.http.TLSProtocolSocketFactory.init(TLSProtocolSocketFactory.java:151)
    at org.opensaml.ws.soap.client.http.TLSProtocolSocketFactory.<init>(TLSProtocolSocketFactory.java:111)
    at org.opensaml.DefaultBootstrap.initializeHttpClient(DefaultBootstrap.java:118)
    at org.opensaml.DefaultBootstrap.bootstrap(DefaultBootstrap.java:110)

I would greatly appreciate any form of help or sharing of knowledge if you have encountered the following issue previously. Thank you!


Solution

  • If it is just a test code, that runs without any https communtication, you should set system property org.opensaml.httpclient.https.disableHostnameVerification=true in jvm, or include the following code snippet before DefaultBootstrap.bootstrap() method:

    System.setProperty("org.opensaml.httpclient.https.disableHostnameVerification", "true");