Search in sources :

Example 6 with OMException

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);
        }
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) InputSource(org.xml.sax.InputSource) SAXSource(javax.xml.transform.sax.SAXSource) XMLStreamException(javax.xml.stream.XMLStreamException) StAXPullInput(org.apache.axiom.om.impl.stream.stax.pull.StAXPullInput) StreamSource(javax.xml.transform.stream.StreamSource) StAXSource(javax.xml.transform.stax.StAXSource) FilteredXmlInput(org.apache.axiom.core.stream.FilteredXmlInput) OMException(org.apache.axiom.om.OMException)

Example 7 with OMException

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();
}
Also used : MemoryBlob(org.apache.axiom.blob.MemoryBlob) StreamCopyException(org.apache.axiom.ext.io.StreamCopyException) IOException(java.io.IOException) OMException(org.apache.axiom.om.OMException)

Example 8 with OMException

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

Example 9 with OMException

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
    }
}
Also used : QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) SOAPMessage(org.apache.axiom.soap.SOAPMessage) OMException(org.apache.axiom.om.OMException)

Example 10 with OMException

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
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) StringReader(java.io.StringReader) 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