use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class Axis2LoadBalanceMembershipHandler method setConfigurationContext.
public void setConfigurationContext(ConfigurationContext configCtx) {
this.configCtx = configCtx;
// The following code does the bridging between Axis2 and Synapse load balancing
ClusteringAgent clusteringAgent = configCtx.getAxisConfiguration().getClusteringAgent();
if (clusteringAgent == null) {
String msg = "In order to enable load balancing across an Axis2 cluster, " + "the cluster entry should be enabled in the axis2.xml file";
log.error(msg);
throw new SynapseException(msg);
}
groupMgtAgent = clusteringAgent.getGroupManagementAgent(lbDomain);
if (groupMgtAgent == null) {
String msg = "A LoadBalanceEventHandler has not been specified in the axis2.xml " + "file for the domain " + lbDomain;
log.error(msg);
throw new SynapseException(msg);
}
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class InboundEndpointSerializer method serializeInboundEndpoint.
public static OMElement serializeInboundEndpoint(InboundEndpoint inboundEndpoint) {
OMElement inboundEndpointElt = fac.createOMElement(InboundEndpointConstants.INBOUND_ENDPOINT, SynapseConstants.SYNAPSE_OMNAMESPACE);
inboundEndpointElt.addAttribute(InboundEndpointConstants.INBOUND_ENDPOINT_NAME, inboundEndpoint.getName(), null);
if (inboundEndpoint.getInjectingSeq() != null) {
inboundEndpointElt.addAttribute(InboundEndpointConstants.INBOUND_ENDPOINT_SEQUENCE, inboundEndpoint.getInjectingSeq(), null);
}
if (inboundEndpoint.getOnErrorSeq() != null) {
inboundEndpointElt.addAttribute(InboundEndpointConstants.INBOUND_ENDPOINT_ERROR_SEQUENCE, inboundEndpoint.getOnErrorSeq(), null);
}
if (inboundEndpoint.getProtocol() != null) {
inboundEndpointElt.addAttribute(InboundEndpointConstants.INBOUND_ENDPOINT_PROTOCOL, inboundEndpoint.getProtocol(), null);
} else {
inboundEndpointElt.addAttribute(InboundEndpointConstants.INBOUND_ENDPOINT_CLASS, inboundEndpoint.getClassImpl(), null);
}
StatisticsConfigurable statisticsConfigurable = inboundEndpoint.getAspectConfiguration();
if (statisticsConfigurable != null && statisticsConfigurable.isStatisticsEnable()) {
inboundEndpointElt.addAttribute(XMLConfigConstants.STATISTICS_ATTRIB_NAME, XMLConfigConstants.STATISTICS_ENABLE, null);
}
if (statisticsConfigurable != null && statisticsConfigurable.isTracingEnabled()) {
inboundEndpointElt.addAttribute(XMLConfigConstants.TRACE_ATTRIB_NAME, XMLConfigConstants.TRACE_ENABLE, null);
}
inboundEndpointElt.addAttribute(InboundEndpointConstants.INBOUND_ENDPOINT_SUSPEND, Boolean.toString(inboundEndpoint.isSuspend()), null);
OMElement parametersElt = fac.createOMElement(InboundEndpointConstants.INBOUND_ENDPOINT_PARAMETERS, SynapseConstants.SYNAPSE_OMNAMESPACE);
for (Map.Entry<String, String> paramEntry : inboundEndpoint.getParametersMap().entrySet()) {
String strKey = paramEntry.getKey();
OMElement parameter = fac.createOMElement(InboundEndpointConstants.INBOUND_ENDPOINT_PARAMETER, SynapseConstants.SYNAPSE_OMNAMESPACE);
parameter.addAttribute(InboundEndpointConstants.INBOUND_ENDPOINT_PARAMETER_NAME, strKey, null);
if (inboundEndpoint.getParameterKey(strKey) != null) {
parameter.addAttribute(InboundEndpointConstants.INBOUND_ENDPOINT_PARAMETER_KEY, inboundEndpoint.getParameterKey(strKey), null);
} else if (isWellFormedXML(paramEntry.getValue())) {
try {
OMElement omElement = AXIOMUtil.stringToOM(paramEntry.getValue());
parameter.addChild(omElement);
} catch (XMLStreamException e) {
String msg = "Error Parsing OMElement for value of " + paramEntry.getKey();
throw new SynapseException(msg, e);
}
} else {
parameter.setText(paramEntry.getValue());
}
parametersElt.addChild(parameter);
}
inboundEndpointElt.addChild(parametersElt);
return inboundEndpointElt;
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class MessageStoreFactory method getParameters.
private static Map<String, Object> getParameters(OMElement elem) {
Map<String, Object> parameters = null;
try {
Iterator params = elem.getChildrenWithName(PARAMETER_Q);
parameters = new HashMap<>();
while (params.hasNext()) {
Object o = params.next();
if (o instanceof OMElement) {
OMElement prop = (OMElement) o;
OMAttribute paramName = prop.getAttribute(NAME_Q);
OMAttribute expression = prop.getAttribute(EXPRESSION_Q);
String paramValue = prop.getText();
if (expression != null) {
SynapsePath xPathExpression = SynapsePathFactory.getSynapsePath(prop, EXPRESSION_Q);
registerParameter(parameters, paramName, xPathExpression);
} else {
registerParameter(parameters, paramName, paramValue);
}
}
}
} catch (JaxenException e) {
throw new SynapseException("Error occurred while extracting the parameters", e);
}
return parameters;
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class MessageStoreMediatorFactory method createSpecificMediator.
@Override
protected Mediator createSpecificMediator(OMElement elem, Properties properties) {
MessageStoreMediator messageStoreMediator = new MessageStoreMediator();
processAuditStatus(messageStoreMediator, elem);
OMAttribute nameAtt = elem.getAttribute(ATT_NAME);
if (nameAtt != null) {
messageStoreMediator.setName(nameAtt.getAttributeValue());
}
OMAttribute messageStoreNameAtt = elem.getAttribute(ATT_MESSAGE_STORE);
if (messageStoreNameAtt != null) {
if (checkForExpression(messageStoreNameAtt)) {
String path = messageStoreNameAtt.getAttributeValue().substring(1, messageStoreNameAtt.getAttributeValue().length() - 1);
try {
messageStoreMediator.setMessageStoreExp(SynapsePathFactory.getSynapsePath(elem, path));
} catch (JaxenException e) {
String msg = "Invalid XPath expression for attribute 'messageStore' : " + messageStoreNameAtt.getAttributeValue();
throw new SynapseException(msg, e);
}
} else {
messageStoreMediator.setMessageStoreName(messageStoreNameAtt.getAttributeValue());
}
} else {
throw new SynapseException("Message Store mediator must have a Message store defined");
}
OMAttribute sequenceAtt = elem.getAttribute(ATT_SEQUENCE);
if (sequenceAtt != null) {
messageStoreMediator.setOnStoreSequence(sequenceAtt.getAttributeValue());
}
return messageStoreMediator;
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class OMElementUtils method addNameSpaces.
/**
* Add the namespace declarations of a given {@link OMElement} to the namespace
* context of an XPath expression. Typically this method is used with an XPath
* expression appearing in an attribute of the given element.
* <p>
* Note that the default namespace is explicitly excluded and not added to the
* namespace context. This implies that XPath expressions
* appearing in Synapse configuration files follow the same rule as in XSL
* stylesheets. Indeed, the XSLT specification defines the namespace context of
* an XPath expression as follows:
* <blockquote>
* the set of namespace declarations are those in scope on the element which has the
* attribute in which the expression occurs; [...] the default namespace
* (as declared by xmlns) is not part of this set
* </blockquote>
*
* @param xpath
* @param elem
* @param log
*/
public static void addNameSpaces(XPath xpath, OMElement elem, Log log) {
OMElement currentElem = elem;
while (currentElem != null) {
Iterator it = currentElem.getAllDeclaredNamespaces();
while (it.hasNext()) {
OMNamespace n = (OMNamespace) it.next();
// Exclude the default namespace as explained in the Javadoc above
if (n != null && !"".equals(n.getPrefix())) {
try {
xpath.addNamespace(n.getPrefix(), n.getNamespaceURI());
} catch (JaxenException je) {
String msg = "Error adding declared name space with prefix : " + n.getPrefix() + "and uri : " + n.getNamespaceURI() + " to the XPath : " + xpath;
log.error(msg);
throw new SynapseException(msg, je);
}
}
}
OMContainer parent = currentElem.getParent();
// if the parent is a document element or parent is null ,then return
if (parent == null || parent instanceof OMDocument) {
return;
}
if (parent instanceof OMElement) {
currentElem = (OMElement) parent;
}
}
}
Aggregations