Search in sources :

Example 6 with ServiceFault

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);
}
Also used : ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) ServiceFault(org.eclipse.milo.opcua.stack.core.types.structured.ServiceFault) UaException(org.eclipse.milo.opcua.stack.core.UaException)

Example 7 with ServiceFault

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);
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) ServiceFault(org.eclipse.milo.opcua.stack.core.types.structured.ServiceFault) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) ByteBuf(io.netty.buffer.ByteBuf) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) OpcUaBinaryStreamEncoder(org.eclipse.milo.opcua.stack.core.serialization.OpcUaBinaryStreamEncoder)

Aggregations

ServiceFault (org.eclipse.milo.opcua.stack.core.types.structured.ServiceFault)7 UaException (org.eclipse.milo.opcua.stack.core.UaException)4 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)4 ResponseHeader (org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader)4 ByteBuf (io.netty.buffer.ByteBuf)3 UaServiceFaultException (org.eclipse.milo.opcua.stack.core.UaServiceFaultException)3 SecurityPolicy (org.eclipse.milo.opcua.stack.core.security.SecurityPolicy)3 ByteString (org.eclipse.milo.opcua.stack.core.types.builtin.ByteString)3 UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)3 X509Certificate (java.security.cert.X509Certificate)2 Arrays (java.util.Arrays)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Predicate (java.util.function.Predicate)2 ServiceFaultListener (org.eclipse.milo.opcua.sdk.client.api.ServiceFaultListener)2 OpcUaClientConfig (org.eclipse.milo.opcua.sdk.client.api.config.OpcUaClientConfig)2 OpcUaSubscriptionManager (org.eclipse.milo.opcua.sdk.client.subscriptions.OpcUaSubscriptionManager)2 UaStackClient (org.eclipse.milo.opcua.stack.client.UaStackClient)2 AttributeId (org.eclipse.milo.opcua.stack.core.AttributeId)2 Identifiers (org.eclipse.milo.opcua.stack.core.Identifiers)2