use of org.eclipse.milo.opcua.stack.core.types.structured.ServiceFault in project milo by eclipse.
the class ServiceRequest method createServiceFault.
public ServiceFault createServiceFault(Throwable throwable) {
UaException exception = (throwable instanceof UaException) ? (UaException) throwable : new UaException(throwable);
ResponseHeader responseHeader = new ResponseHeader(DateTime.now(), request.getRequestHeader().getRequestHandle(), exception.getStatusCode(), null, null, null);
return new ServiceFault(responseHeader);
}
use of org.eclipse.milo.opcua.stack.core.types.structured.ServiceFault in project milo by eclipse.
the class OpcServerHttpRequestHandler method sendServiceFault.
private void sendServiceFault(ChannelHandlerContext ctx, UInteger requestHandle, Throwable fault) {
StatusCode statusCode = UaException.extract(fault).map(UaException::getStatusCode).orElse(StatusCode.BAD);
ServiceFault serviceFault = new ServiceFault(new ResponseHeader(DateTime.now(), requestHandle, statusCode, null, null, null));
ByteBuf contentBuffer = BufferUtil.pooledBuffer();
// TODO switch on transport profile for binary vs xml encoding
OpcUaBinaryStreamEncoder binaryEncoder = new OpcUaBinaryStreamEncoder(stackServer.getSerializationContext());
binaryEncoder.setBuffer(contentBuffer);
binaryEncoder.writeMessage(null, serviceFault);
FullHttpResponse httpResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, contentBuffer);
httpResponse.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
httpResponse.headers().set(HttpHeaderNames.CONTENT_TYPE, UABINARY_CONTENT_TYPE);
httpResponse.headers().set(HttpHeaderNames.CONTENT_LENGTH, contentBuffer.readableBytes());
ctx.writeAndFlush(httpResponse);
}
Aggregations