Search in sources :

Example 1 with ErrorMessage

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();
    }
}
Also used : UaException(org.eclipse.milo.opcua.stack.core.UaException) ErrorMessage(org.eclipse.milo.opcua.stack.core.channel.messages.ErrorMessage) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)

Example 2 with ErrorMessage

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();
    }
}
Also used : UaException(org.eclipse.milo.opcua.stack.core.UaException) ErrorMessage(org.eclipse.milo.opcua.stack.core.channel.messages.ErrorMessage) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)

Example 3 with ErrorMessage

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;
}
Also used : UaRuntimeException(org.eclipse.milo.opcua.stack.core.UaRuntimeException) UaException(org.eclipse.milo.opcua.stack.core.UaException) ErrorMessage(org.eclipse.milo.opcua.stack.core.channel.messages.ErrorMessage) ByteBuf(io.netty.buffer.ByteBuf)

Example 4 with ErrorMessage

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);
        }
    }
}
Also used : UaException(org.eclipse.milo.opcua.stack.core.UaException) IOException(java.io.IOException) ErrorMessage(org.eclipse.milo.opcua.stack.core.channel.messages.ErrorMessage)

Example 5 with ErrorMessage

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);
        }
    }
}
Also used : UaException(org.eclipse.milo.opcua.stack.core.UaException) IOException(java.io.IOException) ErrorMessage(org.eclipse.milo.opcua.stack.core.channel.messages.ErrorMessage) ReferenceCountUtil(io.netty.util.ReferenceCountUtil)

Aggregations

UaException (org.eclipse.milo.opcua.stack.core.UaException)5 ErrorMessage (org.eclipse.milo.opcua.stack.core.channel.messages.ErrorMessage)5 IOException (java.io.IOException)2 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)2 ByteBuf (io.netty.buffer.ByteBuf)1 ReferenceCountUtil (io.netty.util.ReferenceCountUtil)1 UaRuntimeException (org.eclipse.milo.opcua.stack.core.UaRuntimeException)1