use of org.springframework.oxm.MarshallingFailureException in project spring-framework by spring-projects.
the class JibxMarshaller method transformAndMarshal.
private void transformAndMarshal(Object graph, Result result) throws IOException {
try {
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
marshalOutputStream(graph, os);
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
Transformer transformer = this.transformerFactory.newTransformer();
transformer.transform(new StreamSource(is), result);
} catch (TransformerException ex) {
throw new MarshallingFailureException("Could not transform to [" + ClassUtils.getShortName(result.getClass()) + "]", ex);
}
}
use of org.springframework.oxm.MarshallingFailureException in project spring-framework by spring-projects.
the class JibxMarshaller method marshalDomNode.
// Unsupported marshalling
@Override
protected void marshalDomNode(Object graph, Node node) throws XmlMappingException {
try {
// JiBX does not support DOM natively, so we write to a buffer first, and transform that to the Node
Result result = new DOMResult(node);
transformAndMarshal(graph, result);
} catch (IOException ex) {
throw new MarshallingFailureException("JiBX marshalling exception", ex);
}
}
use of org.springframework.oxm.MarshallingFailureException in project spring-framework by spring-projects.
the class JibxMarshaller method transformAndUnmarshal.
private Object transformAndUnmarshal(Source source, String encoding) throws IOException {
try {
Transformer transformer = this.transformerFactory.newTransformer();
if (encoding != null) {
transformer.setOutputProperty(OutputKeys.ENCODING, encoding);
}
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
transformer.transform(source, new StreamResult(os));
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
return unmarshalInputStream(is);
} catch (TransformerException ex) {
throw new MarshallingFailureException("Could not transform from [" + ClassUtils.getShortName(source.getClass()) + "]", ex);
}
}
use of org.springframework.oxm.MarshallingFailureException in project spring-framework by spring-projects.
the class JibxMarshaller method marshalSaxHandlers.
@Override
protected void marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler) throws XmlMappingException {
try {
// JiBX does not support SAX natively, so we write to a buffer first, and transform that to the handlers
SAXResult saxResult = new SAXResult(contentHandler);
saxResult.setLexicalHandler(lexicalHandler);
transformAndMarshal(graph, saxResult);
} catch (IOException ex) {
throw new MarshallingFailureException("JiBX marshalling exception", ex);
}
}
use of org.springframework.oxm.MarshallingFailureException in project spring-integration-samples by spring-projects.
the class WeatherMarshaller method unmarshal.
public Object unmarshal(Source source) throws IOException, XmlMappingException {
// this.writeXml(((DOMSource)source).getNode().getOwnerDocument());
DOMResult result = null;
try {
Transformer transformer = transformerFactory.newTransformer();
result = new DOMResult();
transformer.transform(source, result);
} catch (Exception e) {
throw new MarshallingFailureException("Failed to unmarshal SOAP Response", e);
}
Weather weather = new Weather();
String expression = xpathPrefix + "p:City";
String city = XPathExpressionFactory.createXPathExpression(expression, namespacePrefixes).evaluateAsString(result.getNode());
weather.setCity(city);
expression = xpathPrefix + "p:State";
String state = XPathExpressionFactory.createXPathExpression(expression, namespacePrefixes).evaluateAsString(result.getNode());
weather.setState(state);
expression = xpathPrefix + "p:Temperature";
String temperature = XPathExpressionFactory.createXPathExpression(expression, namespacePrefixes).evaluateAsString(result.getNode());
weather.setTemperature(temperature);
expression = xpathPrefix + "p:Description";
String description = XPathExpressionFactory.createXPathExpression(expression, namespacePrefixes).evaluateAsString(result.getNode());
weather.setDescription(description);
return weather;
}
Aggregations