use of org.apache.axiom.om.OMException in project webservices-axiom by apache.
the class BuilderSpec method from.
static BuilderSpec from(StAXParserConfiguration configuration, Source source) {
if (source instanceof SAXSource) {
return from((SAXSource) source, true);
} else if (source instanceof DOMSource) {
return from(((DOMSource) source).getNode(), true);
} else if (source instanceof StreamSource) {
StreamSource streamSource = (StreamSource) source;
InputSource is = new InputSource();
is.setByteStream(streamSource.getInputStream());
is.setCharacterStream(streamSource.getReader());
is.setPublicId(streamSource.getPublicId());
is.setSystemId(streamSource.getSystemId());
return from(configuration, is);
} else if (source instanceof StAXSource) {
return from(((StAXSource) source).getXMLStreamReader());
} else {
try {
return new BuilderSpec(new FilteredXmlInput(new StAXPullInput(StAXUtils.getXMLInputFactory().createXMLStreamReader(source), true, null), NamespaceRepairingFilter.DEFAULT), null);
} catch (XMLStreamException ex) {
throw new OMException(ex);
}
}
}
use of org.apache.axiom.om.OMException in project webservices-axiom by apache.
the class DetachableInputStream method detach.
@Override
public void detach() throws OMException {
MemoryBlob blob = Blobs.createMemoryBlob();
try {
blob.readFrom(target);
} catch (StreamCopyException ex) {
throw new OMException(ex.getCause());
}
if (closeOnDetach) {
try {
target.close();
} catch (IOException ex) {
throw new OMException(ex);
}
}
target = blob.readOnce();
}
use of org.apache.axiom.om.OMException in project webservices-axiom by apache.
the class UUIDGenerator method getInitialUUID.
protected static String getInitialUUID() {
if (myRand == null) {
myRand = new Random();
}
long rand = myRand.nextLong();
String sid;
try {
sid = InetAddress.getLocalHost().toString();
} catch (UnknownHostException e) {
sid = Thread.currentThread().getName();
}
StringBuffer sb = new StringBuffer();
sb.append(sid);
sb.append(":");
sb.append(Long.toString(rand));
MessageDigest md5 = null;
try {
md5 = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
throw new OMException(e);
}
md5.update(sb.toString().getBytes());
byte[] array = md5.digest();
StringBuffer sb2 = new StringBuffer();
for (int j = 0; j < array.length; ++j) {
int b = array[j] & 0xFF;
sb2.append(Integer.toHexString(b));
}
int begin = myRand.nextInt();
if (begin < 0)
begin = begin * -1;
begin = begin % 8;
return sb2.toString().substring(begin, begin + 18).toUpperCase();
}
use of org.apache.axiom.om.OMException in project webservices-axiom by apache.
the class TestSetOMDocumentElementNonSOAPEnvelope method runTest.
@Override
protected void runTest() throws Throwable {
SOAPMessage message = soapFactory.createSOAPMessage();
OMElement element = soapFactory.createOMElement(new QName("test"));
try {
message.setOMDocumentElement(element);
fail("Expected OMException");
} catch (OMException ex) {
// Expected
}
}
use of org.apache.axiom.om.OMException in project webservices-axiom by apache.
the class TestCreateStAXOMBuilderIncorrectState method runTest.
@Override
protected void runTest() throws Throwable {
XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader("<root>text</root>"));
// Position the reader on a CHARACTERS event
while (reader.getEventType() != XMLStreamReader.CHARACTERS) {
reader.next();
}
try {
OMXMLBuilderFactory.createStAXOMBuilder(metaFactory.getOMFactory(), reader);
fail("Expected OMException");
} catch (OMException ex) {
// Expected
}
}
Aggregations