当前位置: 首页>>代码示例>>Java>>正文


Java Marshaller.marshall方法代码示例

本文整理汇总了Java中org.opensaml.xml.io.Marshaller.marshall方法的典型用法代码示例。如果您正苦于以下问题:Java Marshaller.marshall方法的具体用法?Java Marshaller.marshall怎么用?Java Marshaller.marshall使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.opensaml.xml.io.Marshaller的用法示例。


在下文中一共展示了Marshaller.marshall方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setSignature

import org.opensaml.xml.io.Marshaller; //导入方法依赖的package包/类
/**
 * Sign the SAML AuthnRequest message
 *
 * @param logoutRequest
 * @param signatureAlgorithm
 * @param cred
 * @return
 * @throws SSOAgentException
 */
public static LogoutRequest setSignature(LogoutRequest logoutRequest, String signatureAlgorithm,
                                         X509Credential cred) throws SSOAgentException {
    try {
        Signature signature = setSignatureRaw(signatureAlgorithm,cred);

        logoutRequest.setSignature(signature);

        List<Signature> signatureList = new ArrayList<Signature>();
        signatureList.add(signature);

        // Marshall and Sign
        MarshallerFactory marshallerFactory =
                org.opensaml.xml.Configuration.getMarshallerFactory();
        Marshaller marshaller = marshallerFactory.getMarshaller(logoutRequest);

        marshaller.marshall(logoutRequest);

        org.apache.xml.security.Init.init();
        Signer.signObjects(signatureList);
        return logoutRequest;

    } catch (Exception e) {
        throw new SSOAgentException("Error while signing the Logout Request message", e);
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:35,代码来源:SSOAgentUtils.java

示例2: marshallMessage

import org.opensaml.xml.io.Marshaller; //导入方法依赖的package包/类
/**
 * Helper method that marshalls the given message.
 * 
 * @param message message the marshall and serialize
 * 
 * @return marshalled message
 * 
 * @throws MessageEncodingException thrown if the give message can not be marshalled into its DOM representation
 */
protected Element marshallMessage(XMLObject message) throws MessageEncodingException {
    log.debug("Marshalling message");

    try {
        Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(message);
        if (marshaller == null) {
            log.error("Unable to marshall message, no marshaller registered for message object: "
                    + message.getElementQName());
            throw new MessageEncodingException(
                    "Unable to marshall message, no marshaller registered for message object: "
                    + message.getElementQName());
        }
        Element messageElem = marshaller.marshall(message);
        if (log.isTraceEnabled()) {
            log.trace("Marshalled message into DOM:\n{}", XMLHelper.nodeToString(messageElem));
        }
        return messageElem;
    } catch (MarshallingException e) {
        log.error("Encountered error marshalling message to its DOM representation", e);
        throw new MessageEncodingException("Encountered error marshalling message into its DOM representation", e);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:32,代码来源:BaseMessageEncoder.java

示例3: logDecodedMessage

import org.opensaml.xml.io.Marshaller; //导入方法依赖的package包/类
/**
 * Log the decoded message to the protocol message logger.
 * 
 * @param messageContext the message context to process
 */
protected void logDecodedMessage(MessageContext messageContext) {
    if(protocolMessageLog.isDebugEnabled() && messageContext.getInboundMessage() != null){
        if (messageContext.getInboundMessage().getDOM() == null) {
            XMLObject message = messageContext.getInboundMessage();
            Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(message);
            if (marshaller != null) {
                try {
                    marshaller.marshall(message);
                } catch (MarshallingException e) {
                    log.error("Unable to marshall message for logging purposes: " + e.getMessage());
                }
            }
            else {
                log.error("Unable to marshall message for logging purposes, no marshaller registered for message object: "
                        + message.getElementQName());
            }
            if (message.getDOM() == null) {
                return;
            }
        }
        protocolMessageLog.debug("\n" + XMLHelper.prettyPrintXML(messageContext.getInboundMessage().getDOM()));
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:BaseMessageDecoder.java

示例4: checkAndMarshall

import org.opensaml.xml.io.Marshaller; //导入方法依赖的package包/类
/**
 * Ensure that the XMLObject is marshalled.
 * 
 * @param xmlObject the object to check and marshall
 * @throws DecryptionException thrown if there is an error when marshalling the XMLObject
 */
protected void checkAndMarshall(XMLObject xmlObject) throws DecryptionException {
    Element targetElement = xmlObject.getDOM();
    if (targetElement == null) {
        Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(xmlObject);
        if (marshaller == null) {
            marshaller =
                    Configuration.getMarshallerFactory().getMarshaller(Configuration.getDefaultProviderQName());
            if (marshaller == null) {
                String errorMsg = "No marshaller available for " + xmlObject.getElementQName();
                log.error(errorMsg);
                throw new DecryptionException(errorMsg);
            }
        }
        try {
            targetElement = marshaller.marshall(xmlObject);
        } catch (MarshallingException e) {
            log.error("Error marshalling target XMLObject", e);
            throw new DecryptionException("Error marshalling target XMLObject", e);
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:Decrypter.java

示例5: marshall

import org.opensaml.xml.io.Marshaller; //导入方法依赖的package包/类
/**
 * Marshall an XMLObject.  If the XMLObject already has a cached DOM via {@link XMLObject#getDOM()},
 * that Element will be returned.  Otherwise the object will be fully marshalled and that Element returned.
 * 
 * @param xmlObject the XMLObject to marshall
 * @return the marshalled Element
 * @throws MarshallingException if there is a problem marshalling the XMLObject
 */
public static Element marshall(XMLObject xmlObject) throws MarshallingException {
    Logger log = getLogger();
    log.debug("Marshalling XMLObject");
    
    if (xmlObject.getDOM() != null) {
        log.debug("XMLObject already had cached DOM, returning that element");
        return xmlObject.getDOM();
    }

    Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(xmlObject);
    if (marshaller == null) {
        log.error("Unable to marshall XMLOBject, no marshaller registered for object: "
                + xmlObject.getElementQName());
    }
    
    Element messageElem = marshaller.marshall(xmlObject);
    
    if (log.isTraceEnabled()) {
        log.trace("Marshalled XMLObject into DOM:");
        log.trace(XMLHelper.nodeToString(messageElem));
    }
    
    return messageElem;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:XMLObjectHelper.java

示例6: marshall

import org.opensaml.xml.io.Marshaller; //导入方法依赖的package包/类
/**
 * `
 * Serialize XML objects
 *
 * @param xmlObject : XACML or SAML objects to be serialized
 * @return serialized XACML or SAML objects
 * @throws EntitlementException
 */
private String marshall(XMLObject xmlObject) throws EntitlementException {

    try {
        doBootstrap();
        System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
                "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");

        MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory();
        Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject);
        Element element = marshaller.marshall(xmlObject);

        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        DOMImplementationLS impl =
                (DOMImplementationLS) registry.getDOMImplementation("LS");
        LSSerializer writer = impl.createLSSerializer();
        LSOutput output = impl.createLSOutput();
        output.setByteStream(byteArrayOutputStream);
        writer.write(element, output);
        return byteArrayOutputStream.toString();
    } catch (Exception e) {
        log.error("Error Serializing the SAML Response");
        throw new EntitlementException("Error Serializing the SAML Response", e);
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:34,代码来源:WSXACMLMessageReceiver.java

示例7: setSignatureValue

import org.opensaml.xml.io.Marshaller; //导入方法依赖的package包/类
/**
 * Add signature to any singable XML object.
 * @param xmlObject Singable xml object.
 * @param signatureAlgorithm Signature algorithm to be used.
 * @param cred X509 Credentials.
 * @param <T> Singable XML object with signature.
 * @return Singable XML object with signature.
 * @throws SSOAgentException If error occurred.
 */
public static <T extends SignableXMLObject> T setSignatureValue(T xmlObject, String signatureAlgorithm,
                                                                X509Credential cred)
        throws SSOAgentException {

    try {
        Signature signature = setSignatureRaw(signatureAlgorithm, cred);
        xmlObject.setSignature(signature);

        List<Signature> signatureList = new ArrayList<>();
        signatureList.add(signature);

        // Marshall and Sign
        MarshallerFactory marshallerFactory =
                org.opensaml.xml.Configuration.getMarshallerFactory();
        Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject);

        marshaller.marshall(xmlObject);

        org.apache.xml.security.Init.init();
        Signer.signObjects(signatureList);
        return xmlObject;
    } catch (Exception e) {
        throw new SSOAgentException("Error while signing the SAML Request message", e);
    }
}
 
开发者ID:wso2-extensions,项目名称:identity-agent-sso,代码行数:35,代码来源:SSOAgentUtils.java

示例8: failOnWrongType

import org.opensaml.xml.io.Marshaller; //导入方法依赖的package包/类
@Test
public void failOnWrongType() throws Exception {
	Marshaller m = (Marshaller) Configuration.getMarshallerFactory().getMarshaller(assertion);
	m.marshall(assertion);
	String messageXML = XMLHelper.nodeToString(assertion.getDOM());
	final String encodedMessage = Base64.encodeBytes(messageXML.getBytes(), Base64.DONT_BREAK_LINES);
	
	context.checking(new Expectations() {{
		atLeast(1).of(req).getParameter("SAMLResponse"); will(returnValue(encodedMessage));
	}});
	
	try {
		extractor.extract(req);
		fail("Wrong response type, should fail");
	} catch (RuntimeException e) {}
}
 
开发者ID:amagdenko,项目名称:oiosaml.java,代码行数:17,代码来源:PostResponseExtractorTest.java

示例9: marshall

import org.opensaml.xml.io.Marshaller; //导入方法依赖的package包/类
/**
 * Marshall a SAML XML object into a W3C DOM and then into a String
 *
 * @param pXMLObject SAML Object to marshall
 * @return XML version of the SAML Object in string form
 */
private String marshall(XMLObject pXMLObject) {
  try {
    MarshallerFactory lMarshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory();
    Marshaller lMarshaller = lMarshallerFactory.getMarshaller(pXMLObject);
    Element lElement = lMarshaller.marshall(pXMLObject);

    DOMImplementationLS lDOMImplementationLS = (DOMImplementationLS) DOMImplementationRegistry.newInstance().getDOMImplementation("LS");
    LSSerializer lSerializer = lDOMImplementationLS.createLSSerializer();
    LSOutput lOutput =  lDOMImplementationLS.createLSOutput();
    lOutput.setEncoding("UTF-8");
    Writer lStringWriter = new StringWriter();
    lOutput.setCharacterStream(lStringWriter);
    lSerializer.write(lElement, lOutput);
    return lStringWriter.toString();
  }
  catch (Exception e) {
    throw new ExInternal("Error Serializing the SAML Response", e);
  }
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:26,代码来源:SAMLResponseCommand.java

示例10: marshall

import org.opensaml.xml.io.Marshaller; //导入方法依赖的package包/类
/**
 * Serializing a SAML2 object into a String
 *
 * @param xmlObject object that needs to serialized.
 * @return serialized object
 * @throws SAMLSSOException
 */
public static String marshall(XMLObject xmlObject) throws SAMLSSOException {
    try {

        System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
                "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");

        MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration
                .getMarshallerFactory();
        Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject);
        Element element = marshaller.marshall(xmlObject);

        ByteArrayOutputStream byteArrayOutputStrm = new ByteArrayOutputStream();
        DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
        LSSerializer writer = impl.createLSSerializer();
        LSOutput output = impl.createLSOutput();
        output.setByteStream(byteArrayOutputStrm);
        writer.write(element, output);
        return byteArrayOutputStrm.toString();
    } catch (Exception e) {
        log.error("Error Serializing the SAML Response");
        throw new SAMLSSOException("Error Serializing the SAML Response", e);
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:32,代码来源:SSOUtils.java

示例11: marshall

import org.opensaml.xml.io.Marshaller; //导入方法依赖的package包/类
/**
 * Serializing a SAML2 object into a String
 *
 * @param xmlObject object that needs to serialized.
 * @return serialized object
 * @throws SAML2SSOUIAuthenticatorException
 */
public static String marshall(XMLObject xmlObject) throws SAML2SSOUIAuthenticatorException {

    try {
        doBootstrap();
        System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
                "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");

        MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration
                .getMarshallerFactory();
        Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject);
        Element element = marshaller.marshall(xmlObject);

        ByteArrayOutputStream byteArrayOutputStrm = new ByteArrayOutputStream();
        DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
        LSSerializer writer = impl.createLSSerializer();
        LSOutput output = impl.createLSOutput();
        output.setByteStream(byteArrayOutputStrm);
        writer.write(element, output);
        return byteArrayOutputStrm.toString();
    } catch (Exception e) {
        log.error("Error Serializing the SAML Response");
        throw new SAML2SSOUIAuthenticatorException("Error Serializing the SAML Response", e);
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:33,代码来源:Util.java

示例12: marshall

import org.opensaml.xml.io.Marshaller; //导入方法依赖的package包/类
private static String marshall(XMLObject xmlObject) throws org.wso2.carbon.identity.base.IdentityException {
    try {
        System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
                "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");

        MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory();
        Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject);
        Element element = marshaller.marshall(xmlObject);

        ByteArrayOutputStream byteArrayOutputStrm = new ByteArrayOutputStream();
        DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        DOMImplementationLS impl =
                (DOMImplementationLS) registry.getDOMImplementation("LS");
        LSSerializer writer = impl.createLSSerializer();
        LSOutput output = impl.createLSOutput();
        output.setByteStream(byteArrayOutputStrm);
        writer.write(element, output);
        return byteArrayOutputStrm.toString("UTF-8");
    } catch (Exception e) {
        log.error("Error Serializing the SAML Response");
        throw IdentityException.error("Error Serializing the SAML Response", e);
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:24,代码来源:ErrorResponseBuilder.java

示例13: assertEquals

import org.opensaml.xml.io.Marshaller; //导入方法依赖的package包/类
/**
 * Asserts a given XMLObject is equal to an expected DOM. The XMLObject is marshalled and the resulting DOM object
 * is compared against the expected DOM object for equality.
 * 
 * @param failMessage the message to display if the DOMs are not equal
 * @param expectedDOM the expected DOM
 * @param xmlObject the XMLObject to be marshalled and compared against the expected DOM
 */
public void assertEquals(String failMessage, Document expectedDOM, XMLObject xmlObject) {
    Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject);
    if(marshaller == null){
        fail("Unable to locate marshaller for " + xmlObject.getElementQName() + " can not perform equality check assertion");
    }
    
    try {
        Element generatedDOM = marshaller.marshall(xmlObject, parser.newDocument());
        if(log.isDebugEnabled()) {
            log.debug("Marshalled DOM was " + XMLHelper.nodeToString(generatedDOM));
        }
        assertXMLEqual(failMessage, expectedDOM, generatedDOM.getOwnerDocument());
    } catch (Exception e) {
        log.error("Marshalling failed with the following error:", e);
        fail("Marshalling failed with the following error: " + e);
    }
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:26,代码来源:BaseTestCase.java

示例14: marshall

import org.opensaml.xml.io.Marshaller; //导入方法依赖的package包/类
/**
 * Serializing a SAML2 object into a String
 *
 * @param xmlObject object that needs to serialized.
 * @return serialized object
 * @throws Exception
 */
public static String marshall(XMLObject xmlObject) throws Exception {
    try {
        doBootstrap();
        System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
                           "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");

        MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory();
        Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject);
        Element element = marshaller.marshall(xmlObject);

        ByteArrayOutputStream byteArrayOutputStrm = new ByteArrayOutputStream();
        DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        DOMImplementationLS impl =
                (DOMImplementationLS) registry.getDOMImplementation("LS");
        LSSerializer writer = impl.createLSSerializer();
        LSOutput output = impl.createLSOutput();
        output.setByteStream(byteArrayOutputStrm);
        writer.write(element, output);
        return byteArrayOutputStrm.toString();
    } catch (Exception e) {
        throw new Exception("Error Serializing the SAML Response", e);
    }
}
 
开发者ID:wso2,项目名称:carbon-commons,代码行数:31,代码来源:Util.java

示例15: encodeSAMLRequest

import org.opensaml.xml.io.Marshaller; //导入方法依赖的package包/类
public static String encodeSAMLRequest(XMLObject authnRequest)
        throws MarshallingException, IOException {
    Marshaller marshaller = Configuration.getMarshallerFactory()
            .getMarshaller(authnRequest);
    Element authDOM = marshaller.marshall(authnRequest);
    StringWriter requestWriter = new StringWriter();
    XMLHelper.writeNode(authDOM, requestWriter);
    String requestMessage = requestWriter.toString();
    Deflater deflater = new Deflater(Deflater.DEFLATED, true);
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream, deflater);
    deflaterOutputStream.write(requestMessage.getBytes(Charset.forName("UTF-8")));
    deflaterOutputStream.close();
    String encodedRequestMessage = Base64.encodeBytes(byteArrayOutputStream.toByteArray(), Base64.DONT_BREAK_LINES);
    encodedRequestMessage = URLEncoder.encode(encodedRequestMessage, HttpUtils.UTF_8).trim();
    return encodedRequestMessage;
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:18,代码来源:SAMLUtils.java


注:本文中的org.opensaml.xml.io.Marshaller.marshall方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。