Search in sources :

Example 1 with OMException

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

Example 2 with OMException

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);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayDataSource(org.apache.axiom.om.ds.ByteArrayDataSource) OMException(org.apache.axiom.om.OMException)

Example 3 with OMException

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);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) OMException(org.apache.axiom.om.OMException)

Example 4 with OMException

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

Example 5 with OMException

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);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStream(java.io.InputStream) Closeable(java.io.Closeable) XMLStreamReader(javax.xml.stream.XMLStreamReader) Reader(java.io.Reader) XMLFragmentStreamReader(org.apache.axiom.util.stax.XMLFragmentStreamReader) IOException(java.io.IOException) URL(java.net.URL) Detachable(org.apache.axiom.om.impl.common.builder.Detachable) XMLStreamException(javax.xml.stream.XMLStreamException) StAXPullInput(org.apache.axiom.om.impl.stream.stax.pull.StAXPullInput) OMException(org.apache.axiom.om.OMException)

Aggregations

OMException (org.apache.axiom.om.OMException)85 OMElement (org.apache.axiom.om.OMElement)33 XMLStreamException (javax.xml.stream.XMLStreamException)28 IOException (java.io.IOException)26 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)12 OMFactory (org.apache.axiom.om.OMFactory)12 MalformedURLException (java.net.MalformedURLException)10 ArrayList (java.util.ArrayList)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