Search in sources :

Example 71 with OMException

use of org.apache.axiom.om.OMException in project carbon-apimgt by wso2.

the class APIProviderImpl method getCustomFaultSequences.

/**
 * Get stored custom fault sequences from governanceSystem registry
 *
 * @throws APIManagementException
 */
@Deprecated
public List<String> getCustomFaultSequences() throws APIManagementException {
    Set<String> sequenceList = new TreeSet<>();
    try {
        UserRegistry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry(tenantId);
        if (registry.resourceExists(APIConstants.API_CUSTOM_FAULTSEQUENCE_LOCATION)) {
            org.wso2.carbon.registry.api.Collection faultSeqCollection = (org.wso2.carbon.registry.api.Collection) registry.get(APIConstants.API_CUSTOM_FAULTSEQUENCE_LOCATION);
            if (faultSeqCollection != null) {
                String[] faultSeqChildPaths = faultSeqCollection.getChildren();
                Arrays.sort(faultSeqChildPaths);
                for (String faultSeqChildPath : faultSeqChildPaths) {
                    Resource outSequence = registry.get(faultSeqChildPath);
                    try {
                        OMElement seqElment = APIUtil.buildOMElement(outSequence.getContentStream());
                        sequenceList.add(seqElment.getAttributeValue(new QName("name")));
                    } catch (OMException e) {
                        log.info("Error occurred when reading the sequence '" + faultSeqChildPath + "' from the registry.", e);
                    }
                }
            }
        }
    } catch (RegistryException e) {
        String msg = "Error while retrieving registry for tenant " + tenantId;
        log.error(msg);
        throw new APIManagementException(msg, e);
    } catch (org.wso2.carbon.registry.api.RegistryException e) {
        String msg = "Error while processing the " + APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT + " in the registry";
        log.error(msg);
        throw new APIManagementException(msg, e);
    } catch (Exception e) {
        log.error(e.getMessage());
        throw new APIManagementException(e.getMessage(), e);
    }
    return new ArrayList<>(sequenceList);
}
Also used : QName(javax.xml.namespace.QName) Resource(org.wso2.carbon.registry.core.Resource) APIProductResource(org.wso2.carbon.apimgt.api.model.APIProductResource) APIResource(org.wso2.carbon.apimgt.api.doc.model.APIResource) ArrayList(java.util.ArrayList) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) OMElement(org.apache.axiom.om.OMElement) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) XMLStreamException(javax.xml.stream.XMLStreamException) GraphQLPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.GraphQLPersistenceException) APIImportExportException(org.wso2.carbon.apimgt.impl.importexport.APIImportExportException) IOException(java.io.IOException) MediationPolicyPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.MediationPolicyPersistenceException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ArtifactSynchronizerException(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException) WSDLPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.WSDLPersistenceException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) GovernanceException(org.wso2.carbon.governance.api.exception.GovernanceException) DocumentationPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) PersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.PersistenceException) UnsupportedPolicyTypeException(org.wso2.carbon.apimgt.api.UnsupportedPolicyTypeException) FaultGatewaysException(org.wso2.carbon.apimgt.api.FaultGatewaysException) NotificationException(org.wso2.carbon.apimgt.impl.notification.exception.NotificationException) APIMgtResourceAlreadyExistsException(org.wso2.carbon.apimgt.api.APIMgtResourceAlreadyExistsException) MonetizationException(org.wso2.carbon.apimgt.api.MonetizationException) ThumbnailPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.ThumbnailPersistenceException) OASPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.OASPersistenceException) WorkflowException(org.wso2.carbon.apimgt.impl.workflow.WorkflowException) AsyncSpecPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.AsyncSpecPersistenceException) ParseException(org.json.simple.parser.ParseException) MalformedURLException(java.net.MalformedURLException) OMException(org.apache.axiom.om.OMException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) TreeSet(java.util.TreeSet) OMException(org.apache.axiom.om.OMException)

Example 72 with OMException

use of org.apache.axiom.om.OMException in project carbon-apimgt by wso2.

the class APIManagerConfiguration method load.

/**
 * Populate this configuration by reading an XML file at the given location. This method
 * can be executed only once on a given APIManagerConfiguration instance. Once invoked and
 * successfully populated, it will ignore all subsequent invocations.
 *
 * @param filePath Path of the XML descriptor file
 * @throws APIManagementException If an error occurs while reading the XML descriptor
 */
public void load(String filePath) throws APIManagementException {
    if (initialized) {
        return;
    }
    InputStream in = null;
    int offset = APIUtil.getPortOffset();
    int receiverPort = 9611 + offset;
    int authUrlPort = 9711 + offset;
    int jmsPort = 5672 + offset;
    System.setProperty(RECEIVER_URL_PORT, "" + receiverPort);
    System.setProperty(AUTH_URL_PORT, "" + authUrlPort);
    System.setProperty(JMS_PORT, "" + jmsPort);
    try {
        in = FileUtils.openInputStream(new File(filePath));
        StAXOMBuilder builder = new StAXOMBuilder(in);
        secretResolver = SecretResolverFactory.create(builder.getDocumentElement(), true);
        readChildElements(builder.getDocumentElement(), new Stack<String>());
        initialized = true;
        String url = getFirstProperty(APIConstants.API_KEY_VALIDATOR_URL);
        if (url == null) {
            log.error("API_KEY_VALIDATOR_URL is null");
        }
    } catch (IOException e) {
        log.error(e.getMessage());
        throw new APIManagementException("I/O error while reading the API manager " + "configuration: " + filePath, e);
    } catch (XMLStreamException e) {
        log.error(e.getMessage());
        throw new APIManagementException("Error while parsing the API manager " + "configuration: " + filePath, e);
    } catch (OMException e) {
        log.error(e.getMessage());
        throw new APIManagementException("Error while parsing API Manager configuration: " + filePath, e);
    } catch (Exception e) {
        log.error(e.getMessage());
        throw new APIManagementException("Unexpected error occurred while parsing configuration: " + filePath, e);
    } finally {
        IOUtils.closeQuietly(in);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) StAXOMBuilder(org.apache.axiom.om.impl.builder.StAXOMBuilder) IOException(java.io.IOException) File(java.io.File) OMException(org.apache.axiom.om.OMException) XMLStreamException(javax.xml.stream.XMLStreamException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) OMException(org.apache.axiom.om.OMException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException)

Example 73 with OMException

use of org.apache.axiom.om.OMException in project wso2-axis2-transports by wso2.

the class XMPPPacketListener method buildSOAPEnvelope.

/**
 * builds SOAP envelop using message contained in packet
 * @param packet
 * @param msgContext
 * @throws AxisFault
 */
private void buildSOAPEnvelope(Packet packet, MessageContext msgContext) throws AxisFault {
    Message message = (Message) packet;
    String logMsg = "Trying to create " + "message content using XMPP message received :" + packet.toXML();
    String messageBody = StringEscapeUtils.unescapeXml(message.getBody());
    if (msgContext.isServerSide()) {
        log.debug("Received Envelope : " + messageBody);
    }
    InputStream inputStream = new ByteArrayInputStream(messageBody.getBytes());
    SOAPEnvelope envelope = null;
    try {
        Object obj = message.getProperty(XMPPConstants.CONTAINS_SOAP_ENVELOPE);
        if (obj != null && ((Boolean) obj).booleanValue()) {
            String contentType = (String) message.getProperty(XMPPConstants.CONTENT_TYPE);
            if (contentType == null) {
                throw new AxisFault("Can not Find Content type Property in the XMPP Message");
            }
            envelope = TransportUtils.createSOAPMessage(msgContext, inputStream, contentType);
            msgContext.setProperty(XMPPConstants.CONTAINS_SOAP_ENVELOPE, new Boolean(true));
        } else {
            // This message could either be a service call or a help command
            if (!(messageContainsCommandsFromChat(messageBody, msgContext))) {
                envelope = createSOAPEnvelopeForRawMessage(msgContext, messageBody);
            }
        }
        if (envelope != null) {
            msgContext.setEnvelope(envelope);
        }
    } catch (OMException e) {
        log.error(logMsg, e);
        throw new AxisFault(logMsg);
    } catch (XMLStreamException e) {
        log.error(logMsg, e);
        throw new AxisFault(logMsg);
    } catch (FactoryConfigurationError e) {
        log.error(logMsg, e);
        throw new AxisFault(logMsg);
    } catch (AxisFault e) {
        log.error(logMsg, e);
        throw new AxisFault(logMsg);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) Message(org.jivesoftware.smack.packet.Message) XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMException(org.apache.axiom.om.OMException) FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError)

Example 74 with OMException

use of org.apache.axiom.om.OMException in project ballerina by ballerina-lang.

the class XMLUtils method parse.

/**
 * Create a XML item from string literal.
 *
 * @param xmlStr String representation of the XML
 * @return XML sequence
 */
@SuppressWarnings("unchecked")
public static BXML<?> parse(String xmlStr) {
    try {
        if (xmlStr.isEmpty()) {
            return new BXMLItem(new TextImpl());
        }
        // If this is an XML document, parse it and return an element type XML.
        if (xmlStr.trim().startsWith(XML_DCLR_START)) {
            return new BXMLItem(xmlStr);
        }
        // Here we add a dummy enclosing tag, and send to AXIOM to parse the XML.
        // This is to overcome the issue of axiom not allowing to parse xml-comments,
        // xml-text nodes, and pi nodes, without having an enclosing xml-element node.
        OMElement omElement = AXIOMUtil.stringToOM("<root>" + xmlStr + "</root>");
        Iterator<OMNode> children = omElement.getChildren();
        OMNode omNode = null;
        if (children.hasNext()) {
            omNode = children.next();
        }
        if (children.hasNext()) {
            throw new BallerinaException("xml item must be one of the types: 'element', 'comment', 'text', 'pi'");
        }
        // Here the node is detached from the dummy root, and added to a
        // document element. This is to get the xpath working correctly
        omNode = omNode.detach();
        OMDocument doc = OM_FACTORY.createOMDocument();
        doc.addChild(omNode);
        return new BXMLItem(omNode);
    } catch (BallerinaException e) {
        throw e;
    } catch (OMException | XMLStreamException e) {
        Throwable cause = e.getCause() == null ? e : e.getCause();
        throw new BallerinaException(cause.getMessage());
    } catch (Throwable e) {
        throw new BallerinaException("failed to parse xml: " + e.getMessage());
    }
}
Also used : BXMLItem(org.ballerinalang.model.values.BXMLItem) OMNode(org.apache.axiom.om.OMNode) XMLStreamException(javax.xml.stream.XMLStreamException) OMElement(org.apache.axiom.om.OMElement) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException) OMException(org.apache.axiom.om.OMException) TextImpl(org.apache.axiom.om.impl.dom.TextImpl) OMDocument(org.apache.axiom.om.OMDocument)

Example 75 with OMException

use of org.apache.axiom.om.OMException in project webservices-axiom by apache.

the class InputStreamDataSource method copy.

/**
 * Return a InputStreamDataSource backed by a ByteArrayInputStream
 */
@Override
public OMDataSourceExt copy() {
    byte[] bytes;
    try {
        bytes = getXMLBytes(data.encoding);
    } catch (UnsupportedEncodingException e) {
        throw new OMException(e);
    }
    InputStream is1 = new ByteArrayInputStream(bytes);
    InputStream is2 = new ByteArrayInputStream(bytes);
    data.is = is1;
    return new InputStreamDataSource(is2, data.encoding);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) 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