use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class JDBCMessageStore method deserializeMessage.
/**
* Will convert the byte[] message to store-able message.
*
* @param msgObj serialized message read from the database.
* @return converted message context.
*/
protected MessageContext deserializeMessage(byte[] msgObj) {
MessageContext messageContext = null;
if (msgObj != null) {
ObjectInputStream ios = null;
try {
// Convert back to MessageContext and add to list
ios = new ObjectInputStream(new ByteArrayInputStream(msgObj));
Object msg = ios.readObject();
if (msg instanceof StorableMessage) {
StorableMessage jdbcMsg = (StorableMessage) msg;
org.apache.axis2.context.MessageContext axis2Mc = this.newAxis2Mc();
MessageContext synapseMc = this.newSynapseMc(axis2Mc);
messageContext = MessageConverter.toMessageContext(jdbcMsg, axis2Mc, synapseMc);
}
} catch (IOException e) {
throw new SynapseException("Error reading object input stream", e);
} catch (ClassNotFoundException e) {
throw new SynapseException("Could not find the class", e);
} finally {
closeStream(ios);
}
} else {
throw new SynapseException("Retrieved Object is null");
}
return messageContext;
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class ResequenceMessageStore method getNextMessage.
/**
* Will get the next message belonging to a sequence.
*
* @return the next message in the sequence.
*/
private MessageContext getNextMessage() {
MessageContext msg = null;
final int firstRowIndex = 0;
try {
String tableName = getJdbcConfiguration().getTableName();
String selectMessageStatement = "SELECT message FROM " + tableName + " WHERE " + ResequenceMessageStoreConstants.SEQ_ID + "= ?";
Statement statement = new Statement(selectMessageStatement) {
@Override
public List<Map> getResult(ResultSet resultSet) throws SQLException {
return messageContentResultSet(resultSet, this.getStatement());
}
};
statement.addParameter(nextSequenceId);
List<Map> processedRows = getProcessedRows(statement);
if (!processedRows.isEmpty()) {
msg = getMessageContext(processedRows, firstRowIndex);
nextSequenceId++;
if (log.isTraceEnabled()) {
log.trace("Message with id " + msg.getMessageID() + " returned for sequence " + nextSequenceId);
}
} else {
if (log.isTraceEnabled()) {
log.trace("Sequences not returned from DB, next sequence will be:" + nextSequenceId);
}
}
} catch (SynapseException ex) {
throw new SynapseException("Error while peek the message", ex);
}
return msg;
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class ResequenceMessageStore method getMessageWithMinimumSequence.
/**
* <p>
* Retrieve the minimum sequence number of the available sequence ids in the DB
* </p>
* <p>
* This operation should call when there's a gap and a timeout occurs.
* </p>
* <p>
* <b>Note : </b> This operation would reset the "nextSequenceId" to the minimum sequence id generated from the
* DB.
* </p>
*
* @return the message context of the next sequence
*/
private MessageContext getMessageWithMinimumSequence() {
String tableName = getJdbcConfiguration().getTableName();
String selectMinimumSequenceIdStatement = "SELECT message,seq_id FROM " + tableName + " WHERE " + ResequenceMessageStoreConstants.SEQ_ID + "=(SELECT min(" + ResequenceMessageStoreConstants.SEQ_ID + ")" + " from " + tableName + ")";
Statement stmt = new Statement(selectMinimumSequenceIdStatement) {
@Override
public List<Map> getResult(ResultSet resultSet) throws SQLException {
return getMessageWithMinimumId(resultSet, this.getStatement());
}
};
MessageContext msg = null;
final int firstRowIndex = 0;
try {
List<Map> processedRows = getProcessedRows(stmt);
if (!processedRows.isEmpty()) {
msg = getMessageContext(processedRows, firstRowIndex);
long sequenceId = getSequenceId(processedRows, firstRowIndex);
nextSequenceId = sequenceId + 1;
if (log.isTraceEnabled()) {
log.trace("Message with id " + msg.getMessageID() + " returned as the minimum, the minimum " + "sequence " + "will be marked as " + nextSequenceId);
}
}
} catch (SynapseException ex) {
throw new SynapseException("Error while peek the message", ex);
}
return msg;
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class ResequenceMessageStore method peek.
/**
* {@inheritDoc}
*/
@Override
public MessageContext peek() throws SynapseException {
MessageContext msg;
if (!hasStarted) {
nextSequenceId = readStartId() + 1;
hasStarted = true;
}
msg = getNextMessage();
if (null == msg && !shouldWait()) {
msg = getMessageWithMinimumSequence();
}
if (null != msg) {
long currentSequenceId = nextSequenceId - 1;
String messageId = msg.getMessageID();
sequenceIdMapper.put(messageId, currentSequenceId);
if (nextElapsedTime > 0) {
nextElapsedTime = System.currentTimeMillis() + gapTimeoutInterval;
}
if (log.isDebugEnabled()) {
log.debug("Message with sequence " + currentSequenceId + " and message id " + messageId + " will be returned to the processor.");
log.debug("Next elapsed time would be marked as:" + nextElapsedTime);
}
}
return msg;
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class TemplateMessageExecutor method execute.
public void execute() {
// Inject the message into SynapseEnvironment
MessageContext mc = synapseEnvironment.createMessageContext();
mc.pushFaultHandler(new MediatorFaultHandler(mc.getFaultSequence()));
synapseEnvironment.injectAsync(mc, seqMed);
}
Aggregations