use of org.eclipse.milo.opcua.stack.core.channel.messages.ErrorMessage in project milo by eclipse.
the class UascClientMessageHandler method onError.
private void onError(ChannelHandlerContext ctx, ByteBuf buffer) {
try {
ErrorMessage errorMessage = TcpMessageDecoder.decodeError(buffer);
StatusCode statusCode = errorMessage.getError();
logger.error("[remote={}] errorMessage={}", ctx.channel().remoteAddress(), errorMessage);
handshakeFuture.completeExceptionally(new UaException(statusCode, errorMessage.getReason()));
} catch (UaException e) {
logger.error("[remote={}] An exception occurred while decoding an error message: {}", ctx.channel().remoteAddress(), e.getMessage(), e);
handshakeFuture.completeExceptionally(e);
} finally {
ctx.close();
}
}
use of org.eclipse.milo.opcua.stack.core.channel.messages.ErrorMessage in project milo by eclipse.
the class UascClientAcknowledgeHandler method onError.
private void onError(ChannelHandlerContext ctx, ByteBuf buffer) {
try {
ErrorMessage errorMessage = TcpMessageDecoder.decodeError(buffer);
StatusCode statusCode = errorMessage.getError();
logger.error("[remote={}] Received error message: {}", ctx.channel().remoteAddress(), errorMessage);
handshakeFuture.completeExceptionally(new UaException(statusCode, errorMessage.getReason()));
} catch (UaException e) {
logger.error("[remote={}] An exception occurred while decoding an error message: {}", ctx.channel().remoteAddress(), e.getMessage(), e);
handshakeFuture.completeExceptionally(e);
} finally {
ctx.close();
}
}
use of org.eclipse.milo.opcua.stack.core.channel.messages.ErrorMessage in project milo by eclipse.
the class ExceptionHandler method sendErrorMessage.
public static ErrorMessage sendErrorMessage(ChannelHandlerContext ctx, Throwable cause) throws Exception {
String message = cause.getMessage();
long statusCode = StatusCodes.Bad_UnexpectedError;
if (cause instanceof UaException) {
UaException ex = (UaException) cause;
message = ex.getMessage();
statusCode = ex.getStatusCode().getValue();
} else {
Throwable innerCause = cause.getCause();
if (innerCause instanceof UaException) {
UaException ex = (UaException) innerCause;
message = ex.getMessage();
statusCode = ex.getStatusCode().getValue();
} else if (innerCause instanceof UaRuntimeException) {
UaRuntimeException ex = (UaRuntimeException) innerCause;
message = ex.getMessage();
statusCode = ex.getStatusCode().getValue();
}
}
ErrorMessage error = new ErrorMessage(statusCode, message);
ByteBuf messageBuffer = TcpMessageEncoder.encode(error);
ctx.writeAndFlush(messageBuffer).addListener(future -> ctx.close());
return error;
}
use of org.eclipse.milo.opcua.stack.core.channel.messages.ErrorMessage in project milo by eclipse.
the class UascServerHelloHandler method exceptionCaught.
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (cause instanceof IOException) {
ctx.close();
logger.debug("[remote={}] IOException caught; channel closed", ctx.channel().remoteAddress(), cause);
} else {
ErrorMessage errorMessage = ExceptionHandler.sendErrorMessage(ctx, cause);
if (cause instanceof UaException) {
logger.debug("[remote={}] UaException caught; sent {}", ctx.channel().remoteAddress(), errorMessage, cause);
} else {
logger.error("[remote={}] Exception caught; sent {}", ctx.channel().remoteAddress(), errorMessage, cause);
}
}
}
use of org.eclipse.milo.opcua.stack.core.channel.messages.ErrorMessage in project milo by eclipse.
the class UascServerAsymmetricHandler method exceptionCaught.
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
chunkBuffers.forEach(ReferenceCountUtil::safeRelease);
chunkBuffers.clear();
if (cause instanceof IOException) {
ctx.close();
logger.debug("[remote={}] IOException caught; channel closed", ctx.channel().remoteAddress(), cause);
} else {
ErrorMessage errorMessage = ExceptionHandler.sendErrorMessage(ctx, cause);
if (cause instanceof UaException) {
logger.debug("[remote={}] UaException caught; sent {}", ctx.channel().remoteAddress(), errorMessage, cause);
} else {
logger.error("[remote={}] Exception caught; sent {}", ctx.channel().remoteAddress(), errorMessage, cause);
}
}
}
Aggregations