use of javax.ejb.TransactionAttribute in project wildfly by wildfly.
the class TransactedQueueMessageSender method sendToQueueAndRollback.
@TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
public void sendToQueueAndRollback() throws JMSException {
Connection connection = null;
Session session = null;
try {
logger.trace("Creating a Connection");
connection = factory.createConnection();
logger.trace("Creating a Session");
session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
Message message = session.createTextMessage("Hello world 2!");
logger.trace("Sending message");
producer.send(message);
// ROLLBACK
ctx.setRollbackOnly();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (session != null) {
session.close();
}
if (connection != null) {
connection.close();
}
}
}
use of javax.ejb.TransactionAttribute in project wildfly by wildfly.
the class TransactedTopicMessageSender method sendToTopicAndRollback.
@TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
public void sendToTopicAndRollback() throws JMSException {
Connection connection = null;
Session session = null;
try {
logger.trace("Creating a Connection");
connection = factory.createConnection();
logger.trace("Creating a Session");
session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(topic);
Message message = session.createTextMessage("Hello world 2!");
logger.trace("Sending message");
producer.send(message);
// ROLLBACK
ctx.setRollbackOnly();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (session != null) {
session.close();
}
if (connection != null) {
connection.close();
}
}
}
use of javax.ejb.TransactionAttribute in project tomee by apache.
the class TransactionRule method apply.
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
final TransactionAttribute annotation = description.getAnnotation(TransactionAttribute.class);
final Transactional annotation2 = description.getAnnotation(Transactional.class);
if (annotation == null && annotation2 == null) {
base.evaluate();
return;
}
final BeanContext beanContext = getBeanContext();
final Method method = beanContext.getManagedClass().getMethod(description.getMethodName());
final TransactionType transactionType = TransactionType.get(annotation == null ? TransactionAttributeType.valueOf(annotation2.value().name()) : annotation.value());
beanContext.getMethodContext(method).setTransactionType(transactionType);
ThreadContext tc = ThreadContext.getThreadContext();
final boolean tcCreated;
if (tc == null) {
tcCreated = true;
tc = ThreadContext.enter(new ThreadContext(beanContext, null));
} else {
tcCreated = false;
}
final TransactionPolicy policy = EjbTransactionUtil.createTransactionPolicy(transactionType, tc);
try {
base.evaluate();
} finally {
if (rollback) {
policy.setRollbackOnly();
}
EjbTransactionUtil.afterInvoke(policy, tc);
if (tcCreated) {
ThreadContext.exit(tc);
}
}
}
};
}
use of javax.ejb.TransactionAttribute in project ART-TIME by Artezio.
the class ReportEngine method generate.
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public byte[] generate(String templateName, OutputFormat outputFormat, Map<String, Object> params) {
IReportEngine engine = null;
IRunAndRenderTask task = null;
try (ByteArrayOutputStream reportOutput = new ByteArrayOutputStream()) {
engine = createReportEngine();
task = createEngineTask(engine, templateName);
setTaskParams(task, params);
setTaskRenderOptions(task, outputFormat, reportOutput);
task.run();
return reportOutput.toByteArray();
} catch (IOException | BirtException e) {
throw new RuntimeException("Can't generate a report: ", e);
} finally {
if (task != null)
task.close();
if (engine != null)
engine.destroy();
}
}
use of javax.ejb.TransactionAttribute in project UVMS-ExchangeModule-APP by UnionVMS.
the class ExchangeMessageConsumerBean method onMessage.
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void onMessage(Message message) {
TextMessage textMessage = (TextMessage) message;
ExchangeBaseRequest request = tryConsumeExchangeBaseRequest(textMessage);
LOG.info("Message received in Exchange Message MDB");
LOG.debug("Request body : ", request);
if (request == null) {
LOG.error("[ERROR] ExchangeBaseRequest is null!! Check the message sent...");
try {
// Handle PingResponse from plugin
JAXBMarshaller.unmarshallTextMessage(textMessage, PingResponse.class);
updatePingStateEvent.fire(new ExchangeMessageEvent(textMessage));
} catch (ExchangeModelMarshallException e) {
AcknowledgeResponse type = tryConsumeAcknowledgeResponse(textMessage);
if (type == null) {
LOG.error("[ Error when receiving message in exchange: {}]", message);
errorEvent.fire(new ExchangeMessageEvent(textMessage, ExchangeModuleResponseMapper.createFaultMessage(FaultCode.EXCHANGE_MESSAGE, "Error when receiving message in exchange")));
} else {
updateStateEvent.fire(new ExchangeMessageEvent(textMessage));
}
}
} else if (!checkUsernameShouldBeProvided(request)) {
LOG.error("[ Error when receiving message in exchange, username must be set in the request: ]");
errorEvent.fire(new ExchangeMessageEvent(textMessage, ExchangeModuleResponseMapper.createFaultMessage(FaultCode.EXCHANGE_MESSAGE, "Username in the request must be set")));
} else {
LOG.info("[INFO] Going to process following message type (aka Exchange Method) : " + request.getMethod());
switch(request.getMethod()) {
case LIST_SERVICES:
pluginConfigEvent.fire(new ExchangeMessageEvent(textMessage));
break;
case SET_COMMAND:
sendCommandToPluginEvent.fire(new ExchangeMessageEvent(textMessage));
break;
case SEND_REPORT_TO_PLUGIN:
sendMessageToPluginEvent.fire(new ExchangeMessageEvent(textMessage));
break;
case SET_MOVEMENT_REPORT:
processMovementEvent.fire(new ExchangeMessageEvent(textMessage));
break;
case RECEIVE_SALES_REPORT:
receiveSalesReportEvent.fire(new ExchangeMessageEvent(textMessage));
break;
case RECEIVE_SALES_QUERY:
receiveSalesQueryEvent.fire(new ExchangeMessageEvent(textMessage));
break;
case RECEIVE_SALES_RESPONSE:
receiveSalesResponseEvent.fire(new ExchangeMessageEvent(textMessage));
break;
case RECEIVE_INVALID_SALES_MESSAGE:
receiveInvalidSalesMessageEvent.fire(new ExchangeMessageEvent(textMessage));
break;
case SEND_SALES_RESPONSE:
sendSalesResponseEvent.fire(new ExchangeMessageEvent(textMessage));
break;
case SEND_SALES_REPORT:
sendSalesReportEvent.fire(new ExchangeMessageEvent(textMessage));
break;
case UPDATE_PLUGIN_SETTING:
updatePluginSettingEvent.fire(new ExchangeMessageEvent(textMessage));
break;
case PING:
pingEvent.fire(new ExchangeMessageEvent(textMessage));
break;
case PROCESSED_MOVEMENT:
processedMovementEvent.fire(new ExchangeMessageEvent(textMessage));
break;
case SET_MDR_SYNC_MESSAGE_REQUEST:
mdrSyncRequestMessageEvent.fire(new ExchangeMessageEvent(textMessage));
break;
case SET_MDR_SYNC_MESSAGE_RESPONSE:
mdrSyncResponseMessageEvent.fire(new ExchangeMessageEvent(textMessage));
break;
case SET_FLUX_FA_REPORT_MESSAGE:
processFLUXFAReportMessageEvent.fire(new ExchangeMessageEvent(textMessage));
break;
case SET_FA_QUERY_MESSAGE:
receivedFaQueryFromFlux.fire(new ExchangeMessageEvent(textMessage));
break;
case SET_FLUX_FA_RESPONSE_MESSAGE:
processFLUXFAResponseMessageEvent.fire(new ExchangeMessageEvent(textMessage));
break;
case UPDATE_LOG_STATUS:
updateLogStatusEvent.fire(new ExchangeMessageEvent(textMessage));
break;
case LOG_REF_ID_BY_TYPE_EXISTS:
logRefIdByTyeExists.fire(new ExchangeMessageEvent(textMessage));
break;
case LOG_ID_BY_TYPE_EXISTS:
logIdByTyeExists.fire(new ExchangeMessageEvent(textMessage));
break;
default:
LOG.error("[ Not implemented method consumed: {} ] ", request.getMethod());
errorEvent.fire(new ExchangeMessageEvent(textMessage, ExchangeModuleResponseMapper.createFaultMessage(FaultCode.EXCHANGE_MESSAGE, "Method not implemented")));
}
}
}
Aggregations