use of com.sun.messaging.bridge.api.BridgeContext in project openmq by eclipse-ee4j.
the class StompMessageFilter method handleRead.
/**
* @param ctx Context of {@link FilterChainContext} processing
* @return the next action
*/
@Override
public NextAction handleRead(final FilterChainContext ctx) throws IOException {
BridgeContext bc = null;
synchronized (this) {
if (_bc == null || _jmsprop == null || logger == null) {
if (logger != null) {
logger.logWarn("Stomp Service not ready yet", null);
}
throw new IOException("Stomp service not ready yet");
}
bc = _bc;
}
final Connection c = ctx.getConnection();
StompProtocolHandler sph = sphAttr.get(c);
if (logger.isFinestLoggable()) {
logger.logFinest(this + ", conn=@" + c.hashCode() + ", sph=@" + (sph == null ? "null" : sph.hashCode()), null);
}
AttributeHolder ah = ctx.getAttributes();
ah.setAttribute(STOMP_PROTOCOL_HANDLER, sph);
final Buffer input = ctx.getMessage();
final PacketParseState parsestate = parsestateAttr.get(c);
int pos = input.position();
StompFrameMessageImpl _message = null;
try {
if (logger.isFinestLoggable()) {
logger.logFinest(this + ", position=" + pos + ", input=" + input, null);
}
if (parsestate.message == null) {
if (input.remaining() >= StompFrameMessage.MIN_COMMAND_LEN) {
parsestate.message = StompFrameMessageImpl.parseCommand(input, logger);
if (logger.isFinestLoggable()) {
logger.logFinest("returned from parseCommand with " + parsestate.message, null);
}
}
if (parsestate.message == null) {
input.position(pos);
return ctx.getStopAction(input);
}
}
_message = parsestate.message;
if (_message.getNextParseStage() == StompFrameMessage.ParseStage.HEADER) {
_message.parseHeader(input);
if (logger.isFinestLoggable()) {
logger.logFinest("returned from parseHeader", null);
}
}
if (_message.getNextParseStage() == StompFrameMessage.ParseStage.BODY) {
_message.readBody(input);
}
if (_message.getNextParseStage() == StompFrameMessage.ParseStage.NULL) {
_message.readNULL(input);
}
if (logger.isFinestLoggable()) {
logger.logFinest("position=" + input.position() + ", input=" + input + ", nextParseState=" + _message.getNextParseStage(), null);
}
if (_message.getNextParseStage() != StompFrameMessage.ParseStage.DONE) {
if (logger.isFinestLoggable()) {
logger.logFinest("StopAction with position=" + input.position() + ", hasRemaining=" + input.hasRemaining(), null);
}
return ctx.getStopAction((input.hasRemaining() ? input : null));
}
ctx.setMessage(_message);
Exception pex = _message.getParseException();
if (pex != null) {
if (pex instanceof StompFrameParseException) {
_message = (StompFrameMessageImpl) ((StompFrameParseException) pex).getStompMessageERROR(StompFrameMessageImpl.getFactory(), logger);
} else {
_message = (StompFrameMessageImpl) (new StompFrameParseException(pex.getMessage(), pex)).getStompMessageERROR(StompFrameMessageImpl.getFactory(), logger);
}
ctx.setMessage(_message);
parsestate.reset();
return ctx.getInvokeAction();
}
final Buffer remainder = input.split(input.position());
parsestate.reset();
return ctx.getInvokeAction(remainder.hasRemaining() ? remainder : null);
} catch (Throwable t) {
if (t instanceof OutOfMemoryError) {
logger.logSevere(_OOMMSG, null);
bc.handleGlobalError(t, _OOMMSG);
} else {
logger.logSevere(StompServer.getStompBridgeResources().getKString(StompBridgeResources.E_PARSE_INCOMING_DATA_FAILED, t.getMessage()), t);
}
try {
if (t instanceof StompFrameParseException) {
_message = (StompFrameMessageImpl) ((StompFrameParseException) t).getStompMessageERROR(StompFrameMessageImpl.getFactory(), logger);
_message.setFatalERROR();
} else {
_message = (StompFrameMessageImpl) (new StompFrameParseException(t.getMessage(), t, true)).getStompMessageERROR(StompFrameMessageImpl.getFactory(), logger);
}
} catch (Throwable tt) {
if (t instanceof OutOfMemoryError) {
_message = (StompFrameMessageImpl) StompFrameParseException.OOMMSG;
} else {
logger.logSevere(StompServer.getStompBridgeResources().getKString(StompBridgeResources.E_UNABLE_CREATE_ERROR_MSG, t.getMessage()), tt);
RuntimeException re = new RuntimeException(tt.getMessage());
re.initCause(tt);
throw re;
}
}
ctx.setMessage(_message);
parsestate.reset();
return ctx.getInvokeAction();
}
}
use of com.sun.messaging.bridge.api.BridgeContext 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.BridgeContext in project openmq by eclipse-ee4j.
the class BridgeServiceManagerImpl method startBridge.
/**
* @return true if started successful, false if asynchronously started
*
* @throws Exception if start failed
*/
private boolean startBridge(Bridge b, String[] args) throws Exception {
if (args == null) {
_bc.logInfo(_bmr.getString(_bmr.I_STARTING_BRIDGE, b.getName()), null);
}
if (b.getState() == Bridge.State.STARTED && args == null) {
_bc.logInfo(_bmr.getString(_bmr.I_BRIDGE_ALREADY_STARTED, b.getName()), null);
return true;
}
BridgeContext ctx = new BridgeContextImpl(_bc, b.getName());
StringBuilder sf = new StringBuilder();
sf.append(_bmr.getString(_bmr.I_STARTING_BRIDGE_WITH_PROPS, b.getName()));
String key = null;
Enumeration e = ctx.getConfig().propertyNames();
while (e.hasMoreElements()) {
key = (String) e.nextElement();
sf.append("\t" + key + "=" + ctx.getConfig().getProperty(key) + "\n");
}
if (args == null) {
_bc.logInfo(sf.toString(), null);
}
try {
boolean ret = b.start(ctx, args);
if (args == null) {
_bc.logInfo(_bmr.getString(_bmr.I_STARTED_BRIDGE, b.getName()), null);
}
return ret;
} catch (Exception e1) {
_bc.logError(_bmr.getKString(_bmr.E_START_BRIDGE_FAILED, b.getName(), e1.getMessage()), null);
throw e1;
}
}
Aggregations