I've tried axiom-1.2.8 and OMSource, and works fine. (Andreas alternative #2).
Unless I misunderstood something, this alternative does not
need a copy of the XML text in memory for the SAML assertion in
addition of the DOM tree, only the DOM tree for it (else I wouldn't
be able to use OpenSAML, I think). Not sure if the TransformerFactory
is heavier enough to warrant a ThreadLocal, though. I think the transformer
should go in the ThreadLocal ,not only the factory.
new imports:
import org.w3c.dom.Document;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import org.apache.axiom.om.impl.jaxp.OMSource;
new code:
private static final ThreadLocal<TransformerFactory> transFac = new
ThreadLocal<TransformerFactory>() {
@Override
protected TransformerFactory initialValue() {
return TransformerFactory.newInstance();
}
};
public boolean assercioValida(OMElement assercio) {
OMSource source = new OMSource(assercio);
Element assercioSAMLDOM = null;
Transformer transformer;
try {
transformer = transFac.get().newTransformer();
DOMResult result = new DOMResult();
transformer.transform(source, result);
assercioSAMLDOM =
((Document)result.getNode()).getDocumentElement();
logger.debug("obteained assertion DOM \"on the fly\"");
} catch (TransformerConfigurationException e2) {
logger.error(e2,e2);
} catch (TransformerException e) {
logger.error(e,e);
}
try {
if (assercioSAMLDOM==null) {
// worse solution, generates and parses XML (bytearray) but works
with axiom-1.2.7
assercioSAMLDOM = XMLUtils.toDOM(assercio);
logger.debug("obtained assertion DOM through XML (overhead)");
[...] Unmarshalling unchanged, as before
}
[...]
}
--
Xavi Drudis Ferran
[email protected]