Search in sources :

Example 21 with OMException

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
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMText(org.apache.axiom.om.OMText) OMException(org.apache.axiom.om.OMException)

Example 22 with OMException

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;
}
Also used : ContentType(org.apache.axiom.mime.ContentType) OMException(org.apache.axiom.om.OMException)

Example 23 with OMException

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;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest) OMException(org.apache.axiom.om.OMException)

Example 24 with OMException

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;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest) OMException(org.apache.axiom.om.OMException)

Example 25 with OMException

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;
}
Also used : OMNode(org.apache.axiom.om.OMNode) DataOutputStream(java.io.DataOutputStream) OMElement(org.apache.axiom.om.OMElement) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) MessageDigest(java.security.MessageDigest) OMException(org.apache.axiom.om.OMException)

Aggregations

OMException (org.apache.axiom.om.OMException)89 OMElement (org.apache.axiom.om.OMElement)35 XMLStreamException (javax.xml.stream.XMLStreamException)31 IOException (java.io.IOException)30 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)21 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)18 InputStream (java.io.InputStream)16 QName (javax.xml.namespace.QName)13 OMFactory (org.apache.axiom.om.OMFactory)12 ArrayList (java.util.ArrayList)11 MalformedURLException (java.net.MalformedURLException)10 Test (org.junit.Test)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)9 ParseException (org.json.simple.parser.ParseException)9 APIMgtResourceAlreadyExistsException (org.wso2.carbon.apimgt.api.APIMgtResourceAlreadyExistsException)9 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)9 FaultGatewaysException (org.wso2.carbon.apimgt.api.FaultGatewaysException)9 MonetizationException (org.wso2.carbon.apimgt.api.MonetizationException)9 UnsupportedPolicyTypeException (org.wso2.carbon.apimgt.api.UnsupportedPolicyTypeException)9