use of com.sun.messaging.jmq.jmsservice.JMSServiceException in project openmq by eclipse-ee4j.
the class DirectXAResource method prepare.
/**
* Ask the resource manager to prepare for a transaction commit of the transaction specified in xid.
*
* @param foreignXid A global transaction identifier.
*
* @return A value indicating the resource manager's vote on the outcome of the transaction. The possible values are:
* XA_RDONLY or XA_OK. If the resource manager wants to roll back the transaction, it should do so by raising an
* appropriate XAException in the prepare method.
*
* @throws XAException If an error has occurred. Possible exception values are: XA_RB*, XAER_RMERR, XAER_RMFAIL,
* XAER_NOTA, XAER_INVAL, or XAER_PROTO.
*/
@Override
public synchronized int prepare(Xid foreignXid) throws XAException {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine(_lgrMID_INF + "DirectXAResource (" + this.hashCode() + ") Prepare " + printXid(foreignXid) + ", connectionId=" + connectionId);
}
// convert to XidImpl
// XidImpl mqxid = new XidImpl(foreignXid);
String methodName = "prepare()";
if (_logFINE) {
// +
_loggerJX.fine(// +
_lgrMID_INF + methodName + ":transactionId=" + this.mTransactionId);
}
// JMS does not do RDONLY transactions
int result = XA_OK;
// JMSServiceReply reply = null;
JMSServiceReply.Status status;
try {
// reply = jmsservice.prepareTransaction(this.connectionId,
jmsservice.prepareTransaction(this.connectionId, this.mTransactionId, foreignXid);
if (_logFINE) {
_loggerJX.fine(_lgrMID_INF + methodName + ":connectionId=" + this.connectionId + ":prepared transactionId=" + this.mTransactionId);
}
} catch (JMSServiceException jse) {
status = jse.getJMSServiceReply().getStatus();
String failure_cause = getFailureCauseAsString(status, jse);
// XXX:tharakan:This message should be in the JMSServiceException
String exerrmsg = "prepareTransaction (XA) on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + // "and Xid:" + mqxid.toString() +
" due to " + failure_cause;
_loggerOC.severe(exerrmsg);
XAException xae = new XAException(XAException.XAER_RMERR);
xae.initCause(jse);
throw xae;
}
// update the resource state
resourceState = PREPARED;
return result;
}
use of com.sun.messaging.jmq.jmsservice.JMSServiceException in project openmq by eclipse-ee4j.
the class StompTransactedSession method createSubscriber.
public StompSubscriber createSubscriber(String subid, StompDestination d, String selector, String duraname, boolean nolocal, StompOutputHandler out) throws Exception {
checkSession();
synchronized (this) {
if (subscribers.get(subid) != null) {
throw new StompProtocolException("Subscriber " + subid + " already exist in transacted session " + this);
}
String stompdest = stompconn.getProtocolHandler().toStompFrameDestination(d, false);
Destination dest = ((StompDestinationImpl) d).getDestination();
JMSServiceReply reply = null;
try {
reply = jmsservice.createDestination(connectionId, dest);
} catch (JMSServiceException jmsse) {
JMSServiceReply.Status status = jmsse.getJMSServiceReply().getStatus();
if (status == JMSServiceReply.Status.CONFLICT) {
if (getDEBUG()) {
logger.log(logger.INFO, "Destination " + stompdest + " already exist");
}
} else {
throw jmsse;
}
}
reply = jmsservice.startConnection(connectionId);
reply = jmsservice.addConsumer(connectionId, sessionId, dest, selector, duraname, (duraname != null), false, false, stompconn.getClientID(), nolocal);
long consumerId = reply.getJMQConsumerID();
TransactedSubscriber sub = new TransactedSubscriber(subid, consumerId, duraname, stompdest, out);
subscribers.put(subid, sub);
return sub;
}
}
use of com.sun.messaging.jmq.jmsservice.JMSServiceException in project openmq by eclipse-ee4j.
the class StompSenderSession method sendStompMessage.
public void sendStompMessage(StompFrameMessage message) throws Exception {
checkSession();
Packet pkt = new Packet();
pkt.setPersistent(jmsservice.DEFAULT_MessageDeliveryMode == MessageDeliveryMode.PERSISTENT);
pkt.setPriority(jmsservice.DEFAULT_MessagePriority.priority());
pkt.setExpiration(jmsservice.DEFAULT_TIME_TO_LIVE);
pkt.setDeliveryTime(jmsservice.DEFAULT_DELIVERY_DELAY);
stompconn.fillRemoteIPAndPort(pkt);
StompDestinationImpl d = fromStompFrameMessage(message, pkt);
String stompdest = d.getStompDestinationString();
try {
jmsservice.createDestination(connectionId, d.getDestination());
} catch (JMSServiceException jmsse) {
JMSServiceReply.Status status = jmsse.getJMSServiceReply().getStatus();
if (status == JMSServiceReply.Status.CONFLICT) {
if (logger.isFineLoggable() || stompconn.getProtocolHandler().getDEBUG()) {
logger.log(logger.INFO, "Destination " + stompdest + " already exist");
}
} else {
throw jmsse;
}
}
synchronized (this) {
Long prodid = producers.get(stompdest);
if (prodid == null) {
JMSServiceReply reply = jmsservice.addProducer(connectionId, sessionId, d.getDestination());
prodid = Long.valueOf(reply.getJMQProducerID());
producers.put(stompdest, prodid);
}
pkt.setProducerID(prodid.longValue());
}
pkt.prepareToSend();
synchronized (this) {
if (isTransacted()) {
pkt.setTransactionID(getTransactionId());
} else {
pkt.setTransactionID(0L);
}
final Packet p = pkt;
jmsservice.sendMessage(connectionId, new JMSPacket() {
@Override
public Packet getPacket() {
return p;
}
});
}
if (logger.isFineLoggable() || stompconn.getProtocolHandler().getDEBUG()) {
logger.log(logger.INFO, "Sent message " + pkt.getSysMessageID());
}
}
use of com.sun.messaging.jmq.jmsservice.JMSServiceException in project openmq by eclipse-ee4j.
the class StompSubscriberSession method createSubscriber.
public StompSubscriber createSubscriber(StompDestination d, String selector, String duraname, boolean nolocal, StompOutputHandler out) throws Exception {
if (consumerId != 0L) {
throw new IllegalStateException("Subscriber already exists on this Session");
}
this.out = out;
this.stompdest = stompconn.getProtocolHandler().toStompFrameDestination(d, false);
this.duraname = duraname;
Destination dest = ((StompDestinationImpl) d).getDestination();
JMSServiceReply reply = null;
try {
reply = jmsservice.createDestination(connectionId, dest);
} catch (JMSServiceException jmsse) {
JMSServiceReply.Status status = jmsse.getJMSServiceReply().getStatus();
if (status == JMSServiceReply.Status.CONFLICT) {
if (logger.isFineLoggable() || stompconn.getProtocolHandler().getDEBUG()) {
logger.log(logger.INFO, "Destination " + stompdest + " already exist");
}
} else {
throw jmsse;
}
}
reply = jmsservice.startConnection(connectionId);
reply = jmsservice.addConsumer(connectionId, sessionId, dest, selector, duraname, (duraname != null), false, false, stompconn.getClientID(), nolocal);
consumerId = reply.getJMQConsumerID();
if (getDEBUG()) {
logger.log(logger.INFO, "Created " + this);
}
return this;
}
use of com.sun.messaging.jmq.jmsservice.JMSServiceException in project openmq by eclipse-ee4j.
the class DirectSession method _createAndAddBrowser.
/**
* Create a Browser with the jmsservice and return a consumerId. Used by the methods implementing jakarta.jms.Session,
* jakarta.jms.QueueSession, and jakarta.jms.TopicSession
*
* @param methodName The JMS API method that was called.
* @param destination The JMS Destination object identifying the destination on which the browser is to be created.
* @param selector The JMS Message selector to be used.
*
* @return The DirectQueueBrowser object to be returned by the JMS API method.
*
* @throws JMSException if any JMS error occurred.
*/
private DirectQueueBrowser _createAndAddBrowser(String methodName, Queue destination, String selector) throws JMSException {
JMSServiceReply reply;
long consumerId = 0L;
DirectQueueBrowser browser = null;
com.sun.messaging.jmq.jmsservice.Destination jmsservice_dest;
if (_logFINE) {
_loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName + ":Destination=" + destination + ":selector=" + selector);
}
this._checkIfClosed(methodName);
jmsservice_dest = this._checkDestinationForConsumer(destination);
try {
reply = jmsservice.addBrowser(connectionId, sessionId, jmsservice_dest, selector);
try {
// Must get a consumerId from the addBrowser method
consumerId = reply.getJMQConsumerID();
} catch (NoSuchFieldException nsfe) {
String exerrmsg = _lgrMID_EXC + methodName + "JMSServiceException:Missing JMQConsumerID";
JMSException jmse = new JMSException(exerrmsg);
jmse.initCause(nsfe);
_loggerJS.severe(exerrmsg);
throw jmse;
}
browser = new DirectQueueBrowser(this, jmsservice, consumerId, destination, jmsservice_dest, selector);
} catch (JMSServiceException jse) {
JMSServiceReply.Status status = jse.getJMSServiceReply().getStatus();
String failure_cause;
JMSException jmsse = null;
String exerrmsg = "createBrowser on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + " and sessionId:" + sessionId + " due to ";
switch(status) {
case FORBIDDEN:
failure_cause = "client forbidden to browse messages from this destination.";
exerrmsg = exerrmsg + failure_cause;
jmsse = new JMSSecurityException(exerrmsg, jse.getJMSServiceReply().getErrorCode());
break;
case NOT_FOUND:
failure_cause = "destination not found and cannot be auto-created.";
break;
case CONFLICT:
failure_cause = "destination limit for number of consumers exceeded.";
break;
case BAD_REQUEST:
failure_cause = "invalid selector=" + selector;
exerrmsg = exerrmsg + failure_cause;
jmsse = new InvalidSelectorException(exerrmsg);
break;
default:
failure_cause = "unkown JMSService server error.";
}
_loggerJS.severe(exerrmsg);
if (jmsse == null) {
exerrmsg = exerrmsg + failure_cause;
jmsse = new JMSException(exerrmsg);
}
jmsse.initCause(jse);
throw jmsse;
}
this.addBrowser(browser);
return browser;
}
Aggregations