use of org.apache.axiom.om.OMException in project webservices-axiom by apache.
the class TestInsertSiblingBeforeOnOrphan method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory fac = metaFactory.getOMFactory();
OMText text1 = fac.createOMText("text1");
OMText text2 = fac.createOMText("text2");
try {
text1.insertSiblingAfter(text2);
fail("Expected OMException because node has no parent");
} catch (OMException ex) {
// Expected
}
}
use of org.apache.axiom.om.OMException in project webservices-axiom by apache.
the class Attachments method getAttachmentSpecType.
/**
* Identify the type of message (MTOM or SOAP with attachments) represented by this object. Note
* that this method is only meaningful if the instance was created from a stream.
*
* @return One of the {@link MTOMConstants#MTOM_TYPE}, {@link MTOMConstants#SWA_TYPE} or
* {@link MTOMConstants#SWA_TYPE_12} constants.
* @throws OMException
* if the message doesn't have one of the supported types (i.e. is neither MTOM nor
* SOAP with attachments) or if the instance was not created from a stream
*/
public String getAttachmentSpecType() {
if (this.applicationType == null) {
ContentType contentType = delegate.getContentType();
if (contentType == null) {
throw new OMException("Unable to determine the attachment spec type because the " + "Attachments object doesn't have a known content type");
}
applicationType = contentType.getParameter("type");
if ((MTOMConstants.MTOM_TYPE).equalsIgnoreCase(applicationType)) {
this.applicationType = MTOMConstants.MTOM_TYPE;
} else if ((MTOMConstants.SWA_TYPE).equalsIgnoreCase(applicationType)) {
this.applicationType = MTOMConstants.SWA_TYPE;
} else if ((MTOMConstants.SWA_TYPE_12).equalsIgnoreCase(applicationType)) {
this.applicationType = MTOMConstants.SWA_TYPE_12;
} else {
throw new OMException("Invalid Application type. Support available for MTOM & SwA only.");
}
}
return this.applicationType;
}
use of org.apache.axiom.om.OMException in project webservices-axiom by apache.
the class DigestGenerator method getDigest.
/**
* This method is an overloaded method for the digest generation for OMProcessingInstruction
*
* @param pi
* @param digestAlgorithm
* @return Returns a byte array representing the calculated digest value
*/
public byte[] getDigest(OMProcessingInstruction pi, String digestAlgorithm) throws OMException {
byte[] digest = new byte[0];
try {
MessageDigest md = MessageDigest.getInstance(digestAlgorithm);
md.update((byte) 0);
md.update((byte) 0);
md.update((byte) 0);
md.update((byte) 7);
md.update(pi.getTarget().getBytes("UnicodeBigUnmarked"));
md.update((byte) 0);
md.update((byte) 0);
md.update(pi.getValue().getBytes("UnicodeBigUnmarked"));
digest = md.digest();
} catch (NoSuchAlgorithmException e) {
throw new OMException(e);
} catch (UnsupportedEncodingException e) {
throw new OMException(e);
}
return digest;
}
use of org.apache.axiom.om.OMException in project webservices-axiom by apache.
the class DigestGenerator method getDigest.
/**
* This method is an overloaded method for the digest generation for OMText
*
* @param text
* @param digestAlgorithm
* @return Returns a byte array representing the calculated digest value
*/
public byte[] getDigest(OMText text, String digestAlgorithm) throws OMException {
byte[] digest = new byte[0];
try {
MessageDigest md = MessageDigest.getInstance(digestAlgorithm);
md.update((byte) 0);
md.update((byte) 0);
md.update((byte) 0);
md.update((byte) 3);
md.update(text.getText().getBytes("UnicodeBigUnmarked"));
digest = md.digest();
} catch (NoSuchAlgorithmException e) {
throw new OMException(e);
} catch (UnsupportedEncodingException e) {
throw new OMException(e);
}
return digest;
}
use of org.apache.axiom.om.OMException in project webservices-axiom by apache.
the class DigestGenerator method getDigest.
/**
* This method is an overloaded method for the digest generation for OMDocument
*
* @param document
* @param digestAlgorithm
* @return Returns a byte array representing the calculated digest
*/
public byte[] getDigest(OMDocument document, String digestAlgorithm) throws OMException {
byte[] digest = new byte[0];
try {
MessageDigest md = MessageDigest.getInstance(digestAlgorithm);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.writeInt(9);
Collection<OMNode> childNodes = getValidElements(document);
dos.writeInt(childNodes.size());
Iterator<OMNode> itr = childNodes.iterator();
while (itr.hasNext()) {
OMNode node = itr.next();
if (node.getType() == OMNode.PI_NODE)
dos.write(getDigest((OMProcessingInstruction) node, digestAlgorithm));
else if (node.getType() == OMNode.ELEMENT_NODE)
dos.write(getDigest((OMElement) node, digestAlgorithm));
}
dos.close();
md.update(baos.toByteArray());
digest = md.digest();
} catch (NoSuchAlgorithmException e) {
throw new OMException(e);
} catch (IOException e) {
throw new OMException(e);
}
return digest;
}
Aggregations