use of org.apache.axiom.om.OMException in project webservices-axiom by apache.
the class TestAddHeaderBlockFromQNameWithoutNamespace method runTest.
@Override
protected void runTest() throws Throwable {
SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
SOAPHeader header = soapFactory.createSOAPHeader(envelope);
try {
header.addHeaderBlock(new QName("test"));
fail("Expected OMException");
} catch (OMException ex) {
// Expected
}
}
use of org.apache.axiom.om.OMException 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 org.apache.axiom.om.OMException 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 org.apache.axiom.om.OMException in project webservices-axiom by apache.
the class SAXResultContentHandler method processAttribute.
@Override
public void processAttribute(String namespaceURI, String localName, String prefix, String value, String type, boolean specified) {
OMElement element = (OMElement) target;
OMNamespace ns;
if (namespaceURI.length() > 0) {
ns = element.findNamespace(namespaceURI, prefix);
if (ns == null) {
throw new OMException("Unbound namespace " + namespaceURI);
}
} else {
ns = null;
}
OMAttribute attr = element.addAttribute(localName, value, ns);
attr.setAttributeType(type);
}
use of org.apache.axiom.om.OMException in project webservices-axiom by apache.
the class BuilderSpec method create.
private static BuilderSpec create(StAXParserConfiguration configuration, InputSource is, boolean makeDetachable) {
XMLStreamReader reader;
Detachable detachable;
Closeable closeable;
try {
if (is.getByteStream() != null) {
String systemId = is.getSystemId();
String encoding = is.getEncoding();
InputStream in = is.getByteStream();
if (makeDetachable) {
DetachableInputStream detachableInputStream = new DetachableInputStream(in, false);
in = detachableInputStream;
detachable = detachableInputStream;
} else {
detachable = null;
}
if (systemId != null) {
if (encoding == null) {
reader = StAXUtils.createXMLStreamReader(configuration, systemId, in);
} else {
throw new UnsupportedOperationException();
}
} else {
if (encoding == null) {
reader = StAXUtils.createXMLStreamReader(configuration, in);
} else {
reader = StAXUtils.createXMLStreamReader(configuration, in, encoding);
}
}
closeable = null;
} else if (is.getCharacterStream() != null) {
Reader in = is.getCharacterStream();
if (makeDetachable) {
DetachableReader detachableReader = new DetachableReader(in);
in = detachableReader;
detachable = detachableReader;
} else {
detachable = null;
}
reader = StAXUtils.createXMLStreamReader(configuration, in);
closeable = null;
} else {
String systemId = is.getSystemId();
InputStream in = new URL(systemId).openConnection().getInputStream();
if (makeDetachable) {
DetachableInputStream detachableInputStream = new DetachableInputStream(in, true);
in = detachableInputStream;
detachable = detachableInputStream;
} else {
detachable = null;
}
reader = StAXUtils.createXMLStreamReader(configuration, systemId, in);
closeable = in;
}
} catch (XMLStreamException ex) {
throw new OMException(ex);
} catch (IOException ex) {
throw new OMException(ex);
}
return new BuilderSpec(new StAXPullInput(reader, true, closeable), detachable);
}
Aggregations