use of com.sun.messaging.bridge.api.StompFrameParseException 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.StompFrameParseException in project openmq by eclipse-ee4j.
the class STOMPWebSocket method processData.
private void processData(Buffer buf) throws Exception {
if (DEBUG) {
logger.log(Logger.INFO, Thread.currentThread() + " processData:buf.remaining=" + buf.remaining());
}
if (parseState.buf != null) {
parseState.buf.shrink();
}
parseState.buf = Buffers.appendBuffers(memManager, parseState.buf, buf);
Buffer input = parseState.buf;
if (parseState.message == null) {
if (input.remaining() >= StompFrameMessage.MIN_COMMAND_LEN) {
parseState.message = StompFrameMessageImpl.parseCommand(input);
if (DEBUG) {
logger.log(logger.INFO, "returned from parseCommand with " + parseState.message);
}
}
}
if (parseState.message == null) {
return;
}
StompFrameMessageImpl message = parseState.message;
if (message.getNextParseStage() == StompFrameMessage.ParseStage.HEADER) {
message.parseHeader(input);
if (DEBUG) {
logger.log(logger.INFO, "returned from parseHeader");
}
}
if (message.getNextParseStage() == StompFrameMessage.ParseStage.BODY) {
message.readBody(input);
}
if (message.getNextParseStage() == StompFrameMessage.ParseStage.NULL) {
message.readNULL(input);
}
if (DEBUG) {
logger.log(logger.INFO, "position=" + buf.position() + ", input=" + input + ", nextParseState=" + message.getNextParseStage());
}
if (message.getNextParseStage() != StompFrameMessage.ParseStage.DONE) {
if (DEBUG) {
logger.log(logger.INFO, "parseData with position=" + input.position() + ", hasRemaining=" + input.hasRemaining());
}
return;
}
Exception ex = message.getParseException();
if (ex != null) {
if (ex instanceof StompFrameParseException) {
message = (StompFrameMessageImpl) ((StompFrameParseException) ex).getStompMessageERROR(StompFrameMessageImpl.getFactory(), logger);
} else {
message = (StompFrameMessageImpl) (new StompFrameParseException(ex.getMessage(), ex)).getStompMessageERROR(StompFrameMessageImpl.getFactory(), logger);
}
message.setFatalERROR();
parseState.reset();
sendToClient(message, stompProtocolHandler, null);
return;
}
final Buffer remainder = input.split(input.position());
parseState.reset();
parseState.buf = remainder;
dispatchMessage(message);
}
Aggregations