首页 > 解决方案 > 无法调用 DefaultBootstrap.bootstrap();自己的opensaml解组方法中的方法

问题描述

我编写了以下解组方法来处理我的 xml 文件,但在执行过程中遇到以下错误。

以下代码段是我的代码:

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;
    }

以下是 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)

如果您以前遇到以下问题,我将非常感谢任何形式的帮助或知识共享。谢谢!

标签: javaopensaml

解决方案


如果它只是一个测试代码,在没有任何 https 通信的情况下运行,你应该在 jvm 中设置系统属性 org.opensaml.httpclient.https.disableHostnameVerification=true,或者在 DefaultBootstrap.bootstrap() 方法之前包含以下代码片段:

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

推荐阅读