Java Code Examples for org.opensaml.xml.parse.ParserPool#parse()

The following examples show how to use org.opensaml.xml.parse.ParserPool#parse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLObjectHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Unmarshall a Document from an InputSteam.
 * 
 * @param parserPool the ParserPool instance to use
 * @param inputStream the InputStream to unmarshall
 * @return the unmarshalled XMLObject
 * @throws XMLParserException if there is a problem parsing the input data
 * @throws UnmarshallingException if there is a problem unmarshalling the parsed DOM
 */
public static XMLObject unmarshallFromInputStream(ParserPool parserPool, InputStream inputStream)
        throws XMLParserException, UnmarshallingException {
    Logger log = getLogger();
    log.debug("Parsing InputStream into DOM document");

    Document messageDoc = parserPool.parse(inputStream);
    Element messageElem = messageDoc.getDocumentElement();

    if (log.isTraceEnabled()) {
        log.trace("Resultant DOM message was:");
        log.trace(XMLHelper.nodeToString(messageElem));
    }

    log.debug("Unmarshalling DOM parsed from InputStream");
    Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(messageElem);
    if (unmarshaller == null) {
        log.error("Unable to unmarshall InputStream, no unmarshaller registered for element "
                + XMLHelper.getNodeQName(messageElem));
        throw new UnmarshallingException(
                "Unable to unmarshall InputStream, no unmarshaller registered for element "
                        + XMLHelper.getNodeQName(messageElem));
    }

    XMLObject message = unmarshaller.unmarshall(messageElem);

    log.debug("InputStream succesfully unmarshalled");
    return message;
}
 
Example 2
Source File: XMLObjectHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Unmarshall a Document from a Reader.
 * 
 * @param parserPool the ParserPool instance to use
 * @param reader the Reader to unmarshall
 * @return the unmarshalled XMLObject
 * @throws XMLParserException if there is a problem parsing the input data
 * @throws UnmarshallingException if there is a problem unmarshalling the parsed DOM
 */
public static XMLObject unmarshallFromReader(ParserPool parserPool, Reader reader)
        throws XMLParserException, UnmarshallingException {
    Logger log = getLogger();
    log.debug("Parsing Reader into DOM document");
    

    Document messageDoc = parserPool.parse(reader);
    Element messageElem = messageDoc.getDocumentElement();

    if (log.isTraceEnabled()) {
        log.trace("Resultant DOM message was:");
        log.trace(XMLHelper.nodeToString(messageElem));
    }

    log.debug("Unmarshalling DOM parsed from Reader");
    Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(messageElem);
    if (unmarshaller == null) {
        log.error("Unable to unmarshall Reader, no unmarshaller registered for element "
                + XMLHelper.getNodeQName(messageElem));
        throw new UnmarshallingException(
                "Unable to unmarshall Reader, no unmarshaller registered for element "
                        + XMLHelper.getNodeQName(messageElem));
    }

    XMLObject message = unmarshaller.unmarshall(messageElem);

    log.debug("Reader succesfully unmarshalled");
    return message;
}
 
Example 3
Source File: WebSecurityConfig.java    From spring-tsers-auth with Apache License 2.0 5 votes vote down vote up
@Bean
@Qualifier("idp-ssocircle")
public ExtendedMetadataDelegate ssoCircleExtendedMetadataProvider()
        throws MetadataProviderException {


    AbstractMetadataProvider provider = new AbstractMetadataProvider() {
        @Override
        protected XMLObject doGetMetadata() throws MetadataProviderException {
            DefaultResourceLoader loader = new DefaultResourceLoader();
            Resource storeFile = loader.getResource("classPath:/saml/idp-metadata.xml");

            ParserPool parser = parserPool();
            try {
                Document mdDocument = parser.parse(storeFile.getInputStream());
                Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(mdDocument.getDocumentElement());
                return unmarshaller.unmarshall(mdDocument.getDocumentElement());
            } catch (Exception e) {
                e.printStackTrace();
                throw new MetadataProviderException();
            }


        }
    };
    ExtendedMetadataDelegate extendedMetadataDelegate =
            new ExtendedMetadataDelegate(provider, extendedMetadata());
    extendedMetadataDelegate.setMetadataTrustCheck(false);
    extendedMetadataDelegate.setMetadataRequireSignature(false);
    return extendedMetadataDelegate;
}