use of org.apache.axiom.om.OMException in project carbon-apimgt by wso2.
the class APIProviderImpl method getCustomApiOutSequences.
/**
* Get the list of Custom out Sequences of API
*
* @return List of available out sequences
* @throws APIManagementException
*/
public List<String> getCustomApiOutSequences(APIIdentifier apiIdentifier) throws APIManagementException {
Set<String> sequenceList = new TreeSet<>();
boolean isTenantFlowStarted = false;
try {
String tenantDomain = null;
if (apiIdentifier.getProviderName().contains("-AT-")) {
String provider = apiIdentifier.getProviderName().replace("-AT-", "@");
tenantDomain = MultitenantUtils.getTenantDomain(provider);
}
PrivilegedCarbonContext.startTenantFlow();
isTenantFlowStarted = true;
if (!StringUtils.isEmpty(tenantDomain)) {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
} else {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
}
UserRegistry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry(tenantId);
String customOutSeqFileLocation = APIUtil.getSequencePath(apiIdentifier, APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT);
if (registry.resourceExists(customOutSeqFileLocation)) {
org.wso2.carbon.registry.api.Collection outSeqCollection = (org.wso2.carbon.registry.api.Collection) registry.get(customOutSeqFileLocation);
if (outSeqCollection != null) {
String[] outSeqChildPaths = outSeqCollection.getChildren();
Arrays.sort(outSeqChildPaths);
for (String outSeqChildPath : outSeqChildPaths) {
Resource outSequence = registry.get(outSeqChildPath);
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 '" + outSeqChildPath + "' 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_OUT + " sequences of " + apiIdentifier + " in the registry";
log.error(msg);
throw new APIManagementException(msg, e);
} catch (Exception e) {
log.error(e.getMessage());
throw new APIManagementException(e.getMessage(), e);
} finally {
if (isTenantFlowStarted) {
PrivilegedCarbonContext.endTenantFlow();
}
}
return new ArrayList<>(sequenceList);
}
use of org.apache.axiom.om.OMException in project carbon-apimgt by wso2.
the class APIProviderImpl method getCustomInSequences.
/**
* Get stored custom inSequences from governanceSystem registry
*
* @throws APIManagementException
*/
public List<String> getCustomInSequences(APIIdentifier apiIdentifier) throws APIManagementException {
List<String> sequenceList = new ArrayList<String>();
boolean isTenantFlowStarted = false;
try {
String tenantDomain = null;
if (apiIdentifier.getProviderName().contains("-AT-")) {
String provider = apiIdentifier.getProviderName().replace("-AT-", "@");
tenantDomain = MultitenantUtils.getTenantDomain(provider);
}
PrivilegedCarbonContext.startTenantFlow();
isTenantFlowStarted = true;
if (!StringUtils.isEmpty(tenantDomain)) {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
} else {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
}
UserRegistry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry(tenantId);
if (registry.resourceExists(APIConstants.API_CUSTOM_INSEQUENCE_LOCATION)) {
org.wso2.carbon.registry.api.Collection inSeqCollection = (org.wso2.carbon.registry.api.Collection) registry.get(APIConstants.API_CUSTOM_INSEQUENCE_LOCATION);
if (inSeqCollection != null) {
String[] inSeqChildPaths = inSeqCollection.getChildren();
Arrays.sort(inSeqChildPaths);
for (String inSeqChildPath : inSeqChildPaths) {
Resource inSequence = registry.get(inSeqChildPath);
try {
OMElement seqElment = APIUtil.buildOMElement(inSequence.getContentStream());
sequenceList.add(seqElment.getAttributeValue(new QName("name")));
} catch (OMException e) {
log.info("Error occurred when reading the sequence '" + inSeqChildPath + "' from the registry.", e);
}
}
}
}
String customInSeqFileLocation = APIUtil.getSequencePath(apiIdentifier, "in");
if (registry.resourceExists(customInSeqFileLocation)) {
org.wso2.carbon.registry.api.Collection inSeqCollection = (org.wso2.carbon.registry.api.Collection) registry.get(customInSeqFileLocation);
if (inSeqCollection != null) {
String[] inSeqChildPaths = inSeqCollection.getChildren();
Arrays.sort(inSeqChildPaths);
for (String inSeqChildPath : inSeqChildPaths) {
Resource inSequence = registry.get(inSeqChildPath);
try {
OMElement seqElment = APIUtil.buildOMElement(inSequence.getContentStream());
sequenceList.add(seqElment.getAttributeValue(new QName("name")));
} catch (OMException e) {
log.info("Error occurred when reading the sequence '" + inSeqChildPath + "' from the registry.", e);
}
}
}
}
} catch (Exception e) {
handleException("Issue is in getting custom InSequences from the Registry", e);
} finally {
if (isTenantFlowStarted) {
PrivilegedCarbonContext.endTenantFlow();
}
}
return sequenceList;
}
use of org.apache.axiom.om.OMException in project wso2-axis2-transports by wso2.
the class XMPPPacketListener method createSOAPEnvelopeForRawMessage.
/**
* Creates a SOAP envelope using details found in chat message.
* @param msgCtx
* @param chatMessage
* @return
*/
private SOAPEnvelope createSOAPEnvelopeForRawMessage(MessageContext msgCtx, String chatMessage) throws AxisFault {
// TODO : need to add error handling logic
String callRemoved = chatMessage.replaceFirst("call", "");
// extract Service name
String serviceName = callRemoved.trim().substring(0, callRemoved.indexOf(":") - 1);
String operationName = callRemoved.trim().substring(callRemoved.indexOf(":"), callRemoved.indexOf("(") - 1);
// Extract parameters from IM message
String parameterList = callRemoved.trim().substring(callRemoved.indexOf("("), callRemoved.trim().length() - 1);
StringTokenizer st = new StringTokenizer(parameterList, ",");
MultipleEntryHashMap parameterMap = new MultipleEntryHashMap();
while (st.hasMoreTokens()) {
String token = st.nextToken();
String name = token.substring(0, token.indexOf("="));
String value = token.substring(token.indexOf("=") + 1);
parameterMap.put(name, value);
}
SOAPEnvelope envelope = null;
try {
msgCtx.setProperty(XMPPConstants.CONTAINS_SOAP_ENVELOPE, new Boolean(true));
if (serviceName != null && serviceName.trim().length() > 0) {
AxisService axisService = msgCtx.getConfigurationContext().getAxisConfiguration().getService(serviceName);
msgCtx.setAxisService(axisService);
AxisOperation axisOperation = axisService.getOperationBySOAPAction("urn:" + operationName);
if (axisOperation != null) {
msgCtx.setAxisOperation(axisOperation);
}
}
if (operationName != null && operationName.trim().length() > 0) {
msgCtx.setSoapAction("urn:" + operationName);
}
XMPPOutTransportInfo xmppOutTransportInfo = (XMPPOutTransportInfo) msgCtx.getProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO);
// This should be only set for messages received via chat.
// TODO : need to read from a constant
xmppOutTransportInfo.setContentType("xmpp/text");
msgCtx.setServerSide(true);
// TODO : need to support SOAP12 as well
SOAPFactory soapFactory = new SOAP11Factory();
envelope = BuilderUtil.buildsoapMessage(msgCtx, parameterMap, soapFactory);
// TODO : improve error handling & messages
} catch (AxisFault e) {
throw new AxisFault(e.getMessage());
} catch (OMException e) {
throw new AxisFault(e.getMessage());
} catch (FactoryConfigurationError e) {
throw new AxisFault(e.getMessage());
}
return envelope;
}
use of org.apache.axiom.om.OMException in project wso2-synapse by wso2.
the class JsonDataSource method serialize.
public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {
try {
if (format != null && format.getContentType() != null) {
if (format.getContentType().contains("xml")) {
// reuse the stream
inputStream.reset();
JsonUtil.toXml(inputStream, false).serialize(output, format);
return;
}
}
inputStream.reset();
IOUtils.copy(inputStream, output);
} catch (IOException e) {
logger.error("#serialize:OutputStream. Could not serialize JSON payload. Error>>> " + e.getLocalizedMessage());
throw new OMException("Could not serialize JSON payload.", e);
}
}
use of org.apache.axiom.om.OMException in project wso2-synapse by wso2.
the class JsonDataSourceImpl method serialize.
public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
XMLStreamReader reader = getReader();
xmlWriter.writeStartDocument();
while (reader.hasNext()) {
int x = reader.next();
switch(x) {
case XMLStreamConstants.START_ELEMENT:
xmlWriter.writeStartElement(reader.getPrefix(), reader.getLocalName(), reader.getNamespaceURI());
int namespaceCount = reader.getNamespaceCount();
for (int i = namespaceCount - 1; i >= 0; i--) {
xmlWriter.writeNamespace(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
}
int attributeCount = reader.getAttributeCount();
for (int i = 0; i < attributeCount; i++) {
xmlWriter.writeAttribute(reader.getAttributePrefix(i), reader.getAttributeNamespace(i), reader.getAttributeLocalName(i), reader.getAttributeValue(i));
}
break;
case XMLStreamConstants.START_DOCUMENT:
break;
case XMLStreamConstants.CHARACTERS:
xmlWriter.writeCharacters(reader.getText());
break;
case XMLStreamConstants.CDATA:
xmlWriter.writeCData(reader.getText());
break;
case XMLStreamConstants.END_ELEMENT:
xmlWriter.writeEndElement();
break;
case XMLStreamConstants.END_DOCUMENT:
xmlWriter.writeEndDocument();
break;
case XMLStreamConstants.SPACE:
break;
case XMLStreamConstants.COMMENT:
xmlWriter.writeComment(reader.getText());
break;
case XMLStreamConstants.DTD:
xmlWriter.writeDTD(reader.getText());
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
xmlWriter.writeProcessingInstruction(reader.getPITarget(), reader.getPIData());
break;
case XMLStreamConstants.ENTITY_REFERENCE:
xmlWriter.writeEntityRef(reader.getLocalName());
break;
default:
throw new OMException();
}
}
xmlWriter.writeEndDocument();
xmlWriter.flush();
xmlWriter.close();
}
Aggregations