use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class EIPUtils method enrichEnvelope.
/**
* Merge two SOAP envelopes using the given XPath expression that specifies the
* element that enriches the first envelope from the second
*
* @param envelope SOAPEnvelope to be enriched with the content
* @param enricher SOAPEnvelope from which the enriching element will be extracted
* @param expression SynapseXPath describing the enriching element
* @throws JaxenException on failing of processing the xpath
*/
public static void enrichEnvelope(SOAPEnvelope envelope, SOAPEnvelope enricher, MessageContext synCtxt, SynapseXPath expression) throws JaxenException {
OMElement enrichingElement;
enricher.toString();
List elementList = getMatchingElements(envelope, synCtxt, expression);
List list = getMatchingElements(enricher, synCtxt, expression);
if ((checkNotEmpty(elementList) && checkNotEmpty(list)) || (!checkNotEmpty(elementList) && checkNotEmpty(list))) {
if (checkNotEmpty(elementList)) {
// attach at parent of the first result from the XPath, or to the SOAPBody
Object o = elementList.get(0);
if (o instanceof OMElement && ((OMElement) o).getParent() != null && ((OMElement) o).getParent() instanceof OMElement) {
enrichingElement = (OMElement) ((OMElement) o).getParent();
OMElement body = envelope.getBody();
if (!isBody(body, enrichingElement)) {
OMElement nonBodyElem = enrichingElement;
enrichingElement = envelope.getBody();
addChildren(elementList, enrichingElement);
while (!isBody(body, (OMElement) nonBodyElem.getParent())) {
nonBodyElem = (OMElement) nonBodyElem.getParent();
}
nonBodyElem.detach();
}
}
}
enrichingElement = envelope.getBody();
// validate child element is a SOAPEnvelop
for (Object child : list) {
if (child instanceof SOAPEnvelope) {
throw new SynapseException("Could not add SOAPEnvelope as child element.");
}
}
addChildren(list, enrichingElement);
} else {
throw new SynapseException("Could not find matching elements to aggregate.");
}
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class CallMediator method handleFault.
private void handleFault(MessageContext synCtx, Exception ex) {
synCtx.setProperty(SynapseConstants.SENDING_FAULT, Boolean.TRUE);
if (ex != null && ex instanceof AxisFault) {
AxisFault axisFault = (AxisFault) ex;
int errorCode = SynapseConstants.BLOCKING_CALL_OPERATION_FAILED;
if (axisFault.getFaultCodeElement() != null && !"".equals(axisFault.getFaultCodeElement().getText())) {
try {
errorCode = Integer.parseInt(axisFault.getFaultCodeElement().getText());
} catch (NumberFormatException e) {
errorCode = SynapseConstants.BLOCKING_CALL_OPERATION_FAILED;
}
}
synCtx.setProperty(SynapseConstants.ERROR_CODE, errorCode);
if (axisFault.getMessage() != null) {
synCtx.setProperty(SynapseConstants.ERROR_MESSAGE, axisFault.getMessage());
} else {
synCtx.setProperty(SynapseConstants.ERROR_MESSAGE, "Error while performing " + "the call operation");
}
if (axisFault.getFaultDetailElement() != null) {
if (axisFault.getFaultDetailElement().getFirstElement() != null) {
synCtx.setProperty(SynapseConstants.ERROR_DETAIL, axisFault.getFaultDetailElement().getFirstElement());
} else {
synCtx.setProperty(SynapseConstants.ERROR_DETAIL, axisFault.getFaultDetailElement().getText());
}
}
}
synCtx.setProperty(SynapseConstants.ERROR_EXCEPTION, ex);
throw new SynapseException("Error while performing the call operation", ex);
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class MediatorProperty method evaluate.
/**
* @param synCtx
*/
public void evaluate(MessageContext synCtx) {
String result;
if (value != null) {
result = value;
} else if (expression != null) {
result = expression.stringValueOf(synCtx);
} else {
throw new SynapseException("A value or expression must be specified");
}
if (scope == null || XMLConfigConstants.SCOPE_DEFAULT.equals(scope)) {
synCtx.setProperty(name, result);
} else if (XMLConfigConstants.SCOPE_AXIS2.equals(scope)) {
// Setting property into the Axis2 Message Context
Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
axis2MessageCtx.setProperty(name, result);
MediatorPropertyUtils.handleSpecialProperties(name, result, axis2MessageCtx);
} else if (XMLConfigConstants.SCOPE_CLIENT.equals(scope)) {
// Setting property into the Axis2 Message Context client options
Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
axis2MessageCtx.getOptions().setProperty(name, result);
} else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope)) {
// Setting Transport Headers
Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
Object headers = axis2MessageCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
if (headers != null && headers instanceof Map) {
Map headersMap = (Map) headers;
headersMap.put(name, result);
}
if (headers == null) {
Map headersMap = new HashMap();
headersMap.put(name, result);
axis2MessageCtx.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, headersMap);
}
}
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class PayloadHelper method setMapPayload.
public static void setMapPayload(SOAPEnvelope envelope, SimpleMap map) {
if (map instanceof SimpleMapImpl) {
SimpleMapImpl impl = (SimpleMapImpl) map;
OMElement mapElt = impl.getOMElement(envelope.getOMFactory());
if (mapElt == null) {
log.debug("null map element returned");
return;
}
setXMLPayload(envelope, mapElt);
} else {
throw new SynapseException("cannot handle any other instance of SimpleMap at this point TODO");
}
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class JmsConsumer method cleanup.
public boolean cleanup() throws SynapseException {
if (logger.isDebugEnabled()) {
logger.debug(getId() + " cleaning up...");
}
try {
store.cleanup(connection, session);
return true;
} catch (JMSException e) {
throw new SynapseException("Error while connecting to store to close created connections. JMS provider " + "might not be accessible" + store.getName(), e);
} finally {
connection = null;
session = null;
consumer = null;
}
}
Aggregations