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);
}
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);
}
}
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);
}
}
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());
}
}
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);
}
Aggregations