use of javax.xml.stream.XMLStreamException in project midpoint by Evolveum.
the class CustomDataWriter method write.
@Override
public void write(Object obj, MessagePartInfo part, XMLStreamWriter output) {
QName rootElement = part.getElementQName();
Element serialized;
try {
serialized = prismContex.domSerializer().serializeAnyData(obj, rootElement);
StaxUtils.copy(serialized, output);
// output.writeCharacters(serialized);
} catch (SchemaException | XMLStreamException e) {
// TODO Auto-generated catch block
throw new Fault(e);
}
}
use of javax.xml.stream.XMLStreamException in project webservices-axiom by apache.
the class ByteArrayCustomBuilder method create.
@Override
public OMDataSource create(OMElement element) throws OMException {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
element.serializeAndConsume(baos);
byte[] bytes = baos.toByteArray();
return new ByteArrayDataSource(bytes, encoding);
} catch (XMLStreamException e) {
throw new OMException(e);
} catch (OMException e) {
throw e;
} catch (Throwable t) {
throw new OMException(t);
}
}
use of javax.xml.stream.XMLStreamException in project webservices-axiom by apache.
the class InputStreamDataSource method serialize.
@Override
public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {
if (data == null) {
throw new OMException("The InputStreamDataSource does not have a backing object");
}
String encoding = format.getCharSetEncoding();
try {
if (!data.encoding.equalsIgnoreCase(encoding)) {
byte[] bytes = getXMLBytes(encoding);
output.write(bytes);
} else {
// Write the input stream to the output stream
inputStream2OutputStream(data.is, output);
}
} catch (UnsupportedEncodingException e) {
throw new XMLStreamException(e);
} catch (IOException e) {
throw new XMLStreamException(e);
}
}
use of javax.xml.stream.XMLStreamException in project webservices-axiom by apache.
the class TestNextAfterEndDocument method runTest.
protected void runTest() throws Throwable {
XMLInputFactory factory = staxImpl.newNormalizedXMLInputFactory();
XMLStreamReader reader = factory.createXMLStreamReader(new StringReader("<root/>"));
while (reader.next() != XMLStreamReader.END_DOCUMENT) {
// Just loop
}
try {
reader.next();
fail("Expected exception");
} catch (IllegalStateException ex) {
// Expected
} catch (NoSuchElementException ex) {
// This is also OK
} catch (XMLStreamException ex) {
fail("Expected IllegalStateException or NoSuchElementException");
}
}
use of javax.xml.stream.XMLStreamException in project webservices-axiom by apache.
the class ParserInputStreamDataSource method getXMLBytes.
@Override
public byte[] getXMLBytes(String encoding) {
if (log.isDebugEnabled()) {
log.debug("Entry ParserInputStreamDataSource.getXMLBytes(encoding)");
}
try {
InputStream is = data.readParserInputStream();
if (is != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OMOutputFormat format = new OMOutputFormat();
format.setCharSetEncoding(encoding);
try {
BufferUtils.inputStream2OutputStream(is, baos);
if (log.isDebugEnabled()) {
log.debug("Exit ParserInputStreamDataSource.getXMLBytes(encoding)");
}
return baos.toByteArray();
} catch (IOException e) {
throw new OMException(e);
}
} else {
//via SerializeAndConsume call
if (log.isDebugEnabled()) {
log.warn("Parser was already read, recovering by just returning new byte[0]");
log.debug("Exit ParserInputStreamDataSource.getXMLBytes(encoding)");
}
return new byte[0];
}
} catch (XMLStreamException e) {
throw new OMException(e);
}
}
Aggregations