use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class ForwardingService method tryToDispatchToEndpoint.
/**
* Try to dispatch message to the given endpoint
*
* @param messageToDispatch MessageContext containing message to forward
* @param endpoint endpoint to forward message to
*/
private void tryToDispatchToEndpoint(MessageContext messageToDispatch, Endpoint endpoint) {
isSuccessful = false;
MessageContext outCtx = null;
try {
// For each retry we need to have a fresh copy of the original message
messageToDispatch.setEnvelope(MessageHelper.cloneSOAPEnvelope(messageToDispatch.getEnvelope()));
setSoapHeaderBlock(messageToDispatch);
updateAxis2MessageContext(messageToDispatch);
if (messageConsumer != null && messageConsumer.isAlive()) {
outCtx = sender.send(endpoint, messageToDispatch);
}
// For Protocols like JMS etc no need of validating response
if (isResponseValidationNotRequired) {
isSuccessful = true;
onForwardSuccess(endpoint);
}
// there is no response
if (!isResponseValidationNotRequired && outCtx == null) {
isSuccessful = true;
onForwardSuccess(endpoint);
}
// there is a response (In message context) but failed to send with no exception thrown
if (!isResponseValidationNotRequired && outCtx != null && "true".equals(outCtx.getProperty(SynapseConstants.BLOCKING_SENDER_ERROR))) {
log.error("Blocking Sender Error " + outCtx.getProperty(SynapseConstants.ERROR_EXCEPTION));
isSuccessful = false;
onForwardFailure();
// invoke fault sequence of MP
sendThroughFaultSeq(outCtx);
return;
}
// there is a response so check on status codes
if (!isResponseValidationNotRequired && outCtx != null && validateResponse(outCtx)) {
isSuccessful = true;
sendThroughReplySeq(outCtx);
onForwardSuccess(endpoint);
}
} catch (Exception e) {
log.error("[ " + messageProcessor.getName() + " ] Error while forwarding message to endpoint " + targetEndpoint + ".", e);
if (!isResponseValidationNotRequired && outCtx != null && e instanceof SynapseException && validateResponse(outCtx)) {
isSuccessful = true;
onForwardSuccess(endpoint);
}
if (!isResponseValidationNotRequired && outCtx != null && "true".equals(outCtx.getProperty(ForwardingProcessorConstants.BLOCKING_SENDER_ERROR))) {
log.error("Blocking Sender Error " + outCtx.getProperty(SynapseConstants.ERROR_EXCEPTION));
isSuccessful = false;
onForwardFailure();
// invoke fault sequence of MP
sendThroughFaultSeq(outCtx);
}
if (!isResponseValidationNotRequired && outCtx != null && validateResponse(outCtx)) {
isSuccessful = false;
onForwardFailure();
// invoke fault sequence of MP
sendThroughFaultSeq(outCtx);
}
}
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class ForwardingService method init.
public void init(SynapseEnvironment se) throws SynapseException {
// Setting up the JMS consumer here.
try {
setMessageConsumer();
} catch (StoreForwardException e) {
throw new SynapseException("Error while initializing consumer " + messageProcessor.getName(), e);
}
// Defaults to -1.
Map<String, Object> parametersMap = messageProcessor.getParameters();
if (parametersMap.get(MessageProcessorConstants.MAX_DELIVER_ATTEMPTS) != null) {
maxDeliverAttempts = Integer.parseInt((String) parametersMap.get(MessageProcessorConstants.MAX_DELIVER_ATTEMPTS));
}
if (parametersMap.get(MessageProcessorConstants.RETRY_INTERVAL) != null) {
retryInterval = Integer.parseInt((String) parametersMap.get(MessageProcessorConstants.RETRY_INTERVAL));
}
String maxConnectionAttemptsToStore = (String) parametersMap.get(MessageProcessorConstants.MAX_STORE_CONNECT_ATTEMPTS);
String storeConnectionAttemptDelay = (String) parametersMap.get(MessageProcessorConstants.STORE_CONNECTION_RETRY_INTERVAL);
if (null != maxConnectionAttemptsToStore) {
this.maxConnectionAttemptsToStore = Integer.parseInt(maxConnectionAttemptsToStore);
}
if (null != storeConnectionAttemptDelay) {
this.storeConnectionAttemptDelay = Integer.parseInt(storeConnectionAttemptDelay);
}
replySeq = (String) parametersMap.get(ForwardingProcessorConstants.REPLY_SEQUENCE);
faultSeq = (String) parametersMap.get(ForwardingProcessorConstants.FAULT_SEQUENCE);
deactivateSeq = (String) parametersMap.get(ForwardingProcessorConstants.DEACTIVATE_SEQUENCE);
targetEndpoint = (String) parametersMap.get(ForwardingProcessorConstants.TARGET_ENDPOINT);
String failMessageStoreName = (String) parametersMap.get(ForwardingProcessorConstants.FAIL_MESSAGES_STORE);
if (null != failMessageStoreName && !failMessageStoreName.isEmpty()) {
failMessageStore = se.createMessageContext().getConfiguration().getMessageStore(failMessageStoreName);
}
// Default value should be true.
if (parametersMap.get(ForwardingProcessorConstants.THROTTLE) != null) {
isThrottling = Boolean.parseBoolean((String) parametersMap.get(ForwardingProcessorConstants.THROTTLE));
}
if (parametersMap.get(ForwardingProcessorConstants.CRON_EXPRESSION) != null) {
cronExpression = String.valueOf(parametersMap.get(ForwardingProcessorConstants.CRON_EXPRESSION));
}
// Default Value should be -1.
if (cronExpression != null && parametersMap.get(ForwardingProcessorConstants.THROTTLE_INTERVAL) != null) {
throttlingInterval = Long.parseLong((String) parametersMap.get(ForwardingProcessorConstants.THROTTLE_INTERVAL));
}
nonRetryStatusCodes = (String[]) parametersMap.get(ForwardingProcessorConstants.NON_RETRY_STATUS_CODES);
// Default to FALSE.
if (parametersMap.get(ForwardingProcessorConstants.MAX_DELIVERY_DROP) != null && parametersMap.get(ForwardingProcessorConstants.MAX_DELIVERY_DROP).toString().equals("Enabled") && maxDeliverAttempts > 0) {
isMaxDeliveryAttemptDropEnabled = true;
}
// Setting the interval value.
interval = Long.parseLong((String) parametersMap.get(MessageProcessorConstants.INTERVAL));
/*
* Make sure to set the isInitialized flag to TRUE in order to avoid
* re-initialization.
*/
initialized = true;
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class TransactionMediator method mediate.
public boolean mediate(MessageContext synCtx) {
if (synCtx.getEnvironment().isDebuggerEnabled()) {
if (super.divertMediationRoute(synCtx)) {
return true;
}
}
// UserTransaction tx = null;
final SynapseLog synLog = getLog(synCtx);
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Start : Transaction mediator (" + action + ")");
if (synLog.isTraceTraceEnabled()) {
synLog.traceTrace("Message : " + synCtx.getEnvelope());
}
}
initContext(synCtx);
try {
// tx = (UserTransaction) txContext.lookup(USER_TX_LOOKUP_STR);
TranscationManger.lookUp(txContext);
} catch (Exception e) {
handleException("Cloud not get the context name " + USER_TX_LOOKUP_STR, e, synCtx);
}
if (action.equals(ACTION_COMMIT)) {
try {
// tx.commit();
long key = Thread.currentThread().getId();
TranscationManger.endTransaction(true, key);
} catch (Exception e) {
handleException("Unable to commit transaction", e, synCtx);
}
} else if (action.equals(ACTION_ROLLBACK)) {
try {
// tx.rollback();
long key = Thread.currentThread().getId();
TranscationManger.rollbackTransaction(true, key);
} catch (Exception e) {
handleException("Unable to rollback transaction", e, synCtx);
}
} else if (action.equals(ACTION_NEW)) {
int status = Status.STATUS_UNKNOWN;
try {
// status = tx.getStatus();
status = TranscationManger.getStatus();
} catch (Exception e) {
handleException("Unable to query transaction status", e, synCtx);
}
if (!(status == Status.STATUS_NO_TRANSACTION || status == Status.STATUS_UNKNOWN)) {
throw new SynapseException("Require to begin a new transaction, " + "but a transaction already exist");
}
beginNewTransaction(synCtx);
} else if (action.equals(ACTION_USE_EXISTING_OR_NEW)) {
int status = Status.STATUS_UNKNOWN;
try {
// status = tx.getStatus();
status = TranscationManger.getStatus();
} catch (Exception e) {
handleException("Unable to query transaction status", e, synCtx);
}
if (status == Status.STATUS_NO_TRANSACTION) {
beginNewTransaction(synCtx);
}
} else if (action.equals(ACTION_FAULT_IF_NO_TX)) {
int status = Status.STATUS_UNKNOWN;
try {
// status = tx.getStatus();
status = TranscationManger.getStatus();
} catch (Exception e) {
handleException("Unable to query transaction status", e, synCtx);
}
if (status != Status.STATUS_ACTIVE)
throw new SynapseException("No active transaction. Require an active transaction");
} else {
handleException("Invalid transaction mediator action : " + action, synCtx);
}
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("End : Transaction mediator");
}
return true;
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class SamplingService method dispatch.
/**
* Sends the message to a given sequence.
*
* @param messageContext
* message to be injected.
*/
public void dispatch(final MessageContext messageContext) {
setSoapHeaderBlock(messageContext);
final ExecutorService executor = messageContext.getEnvironment().getExecutorService();
executor.submit(new Runnable() {
public void run() {
try {
Mediator processingSequence = messageContext.getSequence(sequence);
if (processingSequence != null) {
processingSequence.mediate(messageContext);
}
} catch (SynapseException syne) {
if (!messageContext.getFaultStack().isEmpty()) {
(messageContext.getFaultStack().pop()).handleFault(messageContext, syne);
}
log.error("Error occurred while executing the message", syne);
} catch (Throwable t) {
log.error("Error occurred while executing the message", t);
}
}
});
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class RegistryResourceFetcher method init.
public void init(SynapseEnvironment se) {
if (items == null) {
String msg = "resources configuration is required";
log.error(msg);
throw new SynapseException(msg);
}
Iterator it = items.getChildrenWithName(new QName("resource"));
while (it.hasNext()) {
OMElement resourceElement = (OMElement) it.next();
String path = resourceElement.getText();
String type = "xml";
OMAttribute typeAttribute = resourceElement.getAttribute(new QName("type"));
if (typeAttribute != null) {
type = typeAttribute.getAttributeValue();
}
registryResources.add(new RegistryResourceEntry(path, type));
}
this.synapseConfiguration = se.getSynapseConfiguration();
this.registry = (AbstractRegistry) se.getSynapseConfiguration().getRegistry();
this.synapseEnvironment = se;
this.view = new RegistryResourceFetcherView(this);
MBeanRegistrar.getInstance().registerMBean(view, "ESB-Registry", "RegistryResourceFetcher");
this.state = State.ACTIVE;
}
Aggregations