use of com.sun.messaging.bridge.api.BridgeException in project openmq by eclipse-ee4j.
the class BridgeServiceManagerImpl method init.
/**
* Initialize the bridge service manager
*/
@Override
public synchronized void init(BridgeBaseContext ctx) throws Exception {
com.sun.messaging.jmq.jmsclient.Debug.setUseLogger(true);
FaultInjection.setBridgeBaseContext(ctx);
_bc = ctx;
Properties props = _bc.getBridgeConfig();
String activekey = props.getProperty(BridgeBaseContext.PROP_PREFIX) + ".activelist";
List<String> alist = BridgeUtil.getListProperty(activekey, props);
int size = alist.size();
String name = null;
Iterator<String> itr = alist.iterator();
while (itr.hasNext()) {
name = itr.next();
try {
loadBridge(name);
} catch (BridgeException e) {
if (e.getStatus() == Status.NOT_MODIFIED) {
continue;
}
_bc.logError(_bmr.getKString(_bmr.E_LOAD_BRIDGE_FAILED, name, e.getMessage()), null);
throw e;
}
}
if (_bc.isHAEnabled()) {
JMSBridgeStore store = (JMSBridgeStore) _bc.getJDBCStore();
if (store == null) {
throw new BridgeException("null JDBC store");
}
List jmsbridges = store.getJMSBridges(null);
name = null;
itr = alist.iterator();
while (itr.hasNext()) {
name = itr.next();
String type = props.getProperty(props.getProperty(BridgeBaseContext.PROP_PREFIX) + "." + name + ".type");
if (type == null) {
throw new BridgeException(_bmr.getString(_bmr.X_BRIDGE_NO_TYPE, name));
}
if (!type.trim().toUpperCase(_bmr.getLocale()).equals(Bridge.JMS_TYPE)) {
continue;
}
if (jmsbridges.contains(name)) {
continue;
}
try {
store.addJMSBridge(name, true, null);
} catch (DupKeyException e) {
_bc.logInfo(_bmr.getKString(_bmr.I_JMSBRIDGE_NOT_OWNER, name), null);
itr.remove();
}
}
jmsbridges = store.getJMSBridges(null);
itr = jmsbridges.iterator();
while (itr.hasNext()) {
name = itr.next();
if (alist.contains(name)) {
continue;
}
alist.add(name);
try {
loadBridge(name);
} catch (BridgeException e) {
_bc.logError(_bmr.getKString(_bmr.E_LOAD_BRIDGE_FAILED, name, e.getMessage()), null);
throw e;
}
}
if (alist.size() != size) {
StringBuilder sb = new StringBuilder();
int i = 0;
itr = alist.iterator();
while (itr.hasNext()) {
if (i > 0) {
sb.append(',');
}
sb.append(itr.next());
i++;
}
Properties p = new Properties();
p.setProperty(activekey, sb.toString());
_bc.updateBridgeConfig(p);
}
}
String keyu = props.getProperty(BridgeBaseContext.PROP_PREFIX) + ctx.PROP_ADMIN_USER_SUFFIX;
String keyp = props.getProperty(BridgeBaseContext.PROP_PREFIX) + ctx.PROP_ADMIN_PASSWORD_SUFFIX;
_user = props.getProperty(keyu);
_passwd = props.getProperty(keyp);
if (_user == null || _user.trim().length() == 0) {
throw new JMSException(_bmr.getString(_bmr.X_BRIDGE_NO_ADMIN_USER, keyu));
}
_user = _user.trim();
if (_passwd == null || _passwd.trim().length() == 0) {
throw new JMSException(_bmr.getString(_bmr.X_BRIDGE_NO_ADMIN_PASSWORD, keyp));
}
_passwd = _passwd.trim();
_adminHandler = new AdminMessageHandler(this);
_state = State.STOPPED;
}
use of com.sun.messaging.bridge.api.BridgeException in project openmq by eclipse-ee4j.
the class BridgeServiceManagerImpl method resumeBridge.
public synchronized void resumeBridge(String name, String[] args, String type) throws Exception {
if (type != null && !type.equals(Bridge.JMS_TYPE) && !type.equals(Bridge.STOMP_TYPE)) {
throw new IllegalArgumentException(_bmr.getKString(_bmr.X_BRIDGE_INVALID_TYPE, type));
}
if (name == null && type == null) {
throw new UnsupportedOperationException(_bmr.getKString(_bmr.X_BRIDGE_RESUME_NO_TYPE));
}
Bridge b = null;
if (name != null) {
b = _bridges.get(name);
if (b == null) {
throw new BridgeException(_bmr.getKString(_bmr.X_BRIDGE_NAME_NOT_FOUND, name));
}
if (type != null && !type.equals(b.getType())) {
String[] eparam = new String[] { name, b.getType(), type };
throw new BridgeException(_bmr.getKString(_bmr.X_BRIDGE_TYPE_MISMATCH, eparam));
}
resumeBridge(b, args);
return;
}
for (Map.Entry<String, Bridge> pair : _bridges.entrySet()) {
b = pair.getValue();
if (type != null && !b.getType().equals(type)) {
continue;
}
resumeBridge(b, args);
}
}
use of com.sun.messaging.bridge.api.BridgeException in project openmq by eclipse-ee4j.
the class BridgeServiceManagerImpl method listBridge.
public synchronized ArrayList<BridgeCmdSharedReplyData> listBridge(String name, String[] args, String type, BridgeManagerResources bmr) throws Exception {
if (type != null && !type.equals(Bridge.JMS_TYPE) && !type.equals(Bridge.STOMP_TYPE)) {
throw new IllegalArgumentException(_bmr.getString(_bmr.X_BRIDGE_INVALID_TYPE, type));
}
if (name == null) {
_bc.logDebug("Listing all bridges (type=" + type + ")", null);
BridgeCmdSharedReplyData reply = new BridgeCmdSharedReplyData(3, 4, "-");
String[] oneRow = new String[3];
oneRow[0] = bmr.getString(BridgeCmdSharedResources.I_BGMGR_TITLE_BRIDGE_NAME);
oneRow[1] = bmr.getString(BridgeCmdSharedResources.I_BGMGR_TITLE_BRIDGE_TYPE);
oneRow[2] = bmr.getString(BridgeCmdSharedResources.I_BGMGR_TITLE_BRIDGE_STATE);
reply.addTitle(oneRow);
Bridge b = null;
for (Map.Entry<String, Bridge> pair : _bridges.entrySet()) {
b = pair.getValue();
if (type != null && !b.getType().equals(type)) {
continue;
}
oneRow[0] = b.getName();
oneRow[1] = b.getType();
oneRow[2] = b.getState().toString(bmr);
reply.add(oneRow);
}
_bc.logDebug("Listed all bridges (type=" + type + ")", null);
ArrayList<BridgeCmdSharedReplyData> replys = new ArrayList<>();
replys.add(reply);
return replys;
}
if (args == null) {
_bc.logInfo(_bmr.getString(_bmr.I_LISTING_BRIDGE, name), null);
} else {
_bc.logInfo(_bmr.getString(_bmr.I_LISTING_BRIDGE_WITH, name, BridgeUtil.toString(args)), null);
}
Bridge b = _bridges.get(name);
if (b == null) {
String emsg = _bmr.getKString(_bmr.X_BRIDGE_NAME_NOT_FOUND, name);
_bc.logError(emsg, null);
throw new BridgeException(emsg);
}
BridgeContext bc = new BridgeContextImpl(_bc, b.getName());
return b.list(bc, args, bmr);
}
use of com.sun.messaging.bridge.api.BridgeException in project openmq by eclipse-ee4j.
the class AdminMessageHandler method handle.
public void handle(Session session, ObjectMessage msg) {
BridgeManagerResources bmr = _br;
ObjectMessage reply = null;
int msgType = AdminMessageType.Type.LAST;
try {
reply = session.createObjectMessage();
if (DEBUG) {
_bc.logInfo("BridgeAdminMessageHandler.handle:\n<<<<****" + msg, null);
}
try {
String lang = msg.getStringProperty(AdminMessageType.PropName.LOCALE_LANG);
String country = msg.getStringProperty(AdminMessageType.PropName.LOCALE_COUNTRY);
String variant = msg.getStringProperty(AdminMessageType.PropName.LOCALE_VARIANT);
Locale locale = new Locale(lang, country, variant);
bmr = _bsm.getBridgeManagerResources(locale);
} catch (Exception e) {
bmr = _br;
String emsg = _br.getKString(_br.E_GET_LOCALE_FAILED, e.toString(), msg.toString());
_bc.logWarn(emsg, null);
}
Destination dest = msg.getJMSDestination();
if (!(dest instanceof Queue)) {
throw new BridgeException(_br.getKString(_br.X_ADMIN_MSG_NOT_QUEUE, dest));
}
if (!((Queue) dest).getQueueName().equals(_bsm.getAdminDestinationName())) {
throw new BridgeException(_br.getKString(_br.X_ADMIN_MSG_UNEXPECTED_DEST, dest));
}
try {
msgType = msg.getIntProperty(AdminMessageType.PropName.MESSAGE_TYPE);
} catch (Exception e) {
msgType = AdminMessageType.Type.LAST;
String emsg = _br.getKString(_br.X_EXCEPTION_PROCESSING_ADMIN_MSG, msg.toString());
_bc.logError(emsg, e);
throw new BridgeException(emsg, e);
}
AdminCmdHandler ach = null;
try {
ach = _handlers[msgType];
} catch (IndexOutOfBoundsException e) {
String emsg = _br.getKString(_br.X_UNEXPECTED_ADMIN_MSG_TYPE, AdminMessageType.getString(msgType));
throw new BridgeException(emsg);
}
if (ach == null) {
String emsg = "No bridge admin handler for message type " + AdminMessageType.getString(msgType);
throw new BridgeException(emsg);
}
reply.setIntProperty(AdminMessageType.PropName.MESSAGE_TYPE, ++msgType);
ach.handle(session, msg, reply, bmr);
} catch (Throwable t) {
int status = Status.ERROR;
if (t instanceof BridgeException) {
BridgeException be = (BridgeException) t;
status = be.getStatus();
if (be.getCause() == null) {
// else should already logged
_bc.logError(t.getMessage(), null);
}
} else {
_bc.logError(t.getMessage(), t);
}
if (DEBUG) {
_bc.logInfo("BridgeAdminMessageHandler exception: " + t.getMessage() + (reply == null ? "no reply created" : "sending error reply"), t);
}
if (reply != null) {
sendReply(session, msg, reply, status, AdminCmdHandler.getMessageFromThrowable(t), bmr);
}
}
}
use of com.sun.messaging.bridge.api.BridgeException in project openmq by eclipse-ee4j.
the class DebugHandler method handle.
/**
* When called, parent has set reply message type property
*
* throw exception if let parent handle sendReply
*/
@Override
public void handle(Session session, ObjectMessage msg, ObjectMessage reply, BridgeManagerResources bmr) throws BridgeException, Exception {
int msgtype = msg.getIntProperty(AdminMessageType.PropName.MESSAGE_TYPE);
if (msgtype != AdminMessageType.Type.DEBUG) {
throw new BridgeException("Unexpected bridge admin message type " + AdminMessageType.getString(msgtype));
}
String debugArg = msg.getStringProperty(AdminMessageType.PropName.CMD_ARG);
String target = msg.getStringProperty(AdminMessageType.PropName.TARGET);
if (debugArg == null) {
throw new BridgeException(_bmr.getKString(_bmr.X_ADMIN_DEBUG_NO_ARG));
}
if (!debugArg.trim().equals("fault")) {
throw new BridgeException(_bmr.getKString(_bmr.X_ADMIN_DEBUG_UNSUPPORTED_ARG, debugArg));
}
if (target == null || target.trim().length() == 0) {
throw new BridgeException(_bmr.getKString(_bmr.X_ADMIN_DEBUG_NO_NAME, debugArg));
}
Properties props = (Properties) msg.getObject();
String faultName = target;
String faultSelector = props.getProperty("selector");
FaultInjection fi = FaultInjection.getInjection();
String enabledStr = props.getProperty("enabled");
if (enabledStr != null && enabledStr.equalsIgnoreCase("false")) {
fi.unsetFault(faultName);
} else {
fi.setFaultInjection(true);
try {
fi.setFault(faultName, faultSelector, props);
} catch (Exception e) {
_bc.logError(_bmr.getKString(_bmr.E_ADMIN_SET_FAULT_FAILED, faultName), e);
throw e;
}
}
parent.sendReply(session, msg, reply, Status.OK, (String) null, bmr);
}
Aggregations