use of org.eclipse.milo.opcua.stack.client.transport.UaTransportRequest in project milo by eclipse.
the class UascClientMessageHandler method onSecureMessage.
private void onSecureMessage(ChannelHandlerContext ctx, ByteBuf buffer) throws UaException {
// skip messageType, chunkType, messageSize
buffer.skipBytes(3 + 1 + 4);
long secureChannelId = buffer.readUnsignedIntLE();
if (secureChannelId != secureChannel.getChannelId()) {
throw new UaException(StatusCodes.Bad_SecureChannelIdInvalid, "invalid secure channel id: " + secureChannelId);
}
if (accumulateChunk(buffer)) {
final List<ByteBuf> buffersToDecode = chunkBuffers;
chunkBuffers = new ArrayList<>(maxChunkCount);
serializationQueue.decode((binaryDecoder, chunkDecoder) -> {
ByteBuf message;
long requestId;
try {
ChunkDecoder.DecodedMessage decodedMessage = chunkDecoder.decodeSymmetric(secureChannel, buffersToDecode);
message = decodedMessage.getMessage();
requestId = decodedMessage.getRequestId();
} catch (MessageAbortException e) {
logger.warn("Received message abort chunk; error={}, reason={}", e.getStatusCode(), e.getMessage());
UaTransportRequest request = pending.remove(e.getRequestId());
if (request != null) {
request.getFuture().completeExceptionally(e);
} else {
logger.warn("No pending request for requestId={}", e.getRequestId());
}
return;
} catch (MessageDecodeException e) {
logger.error("Error decoding symmetric message", e);
ctx.close();
return;
}
UaTransportRequest request = pending.remove(requestId);
try {
UaResponseMessage response = (UaResponseMessage) binaryDecoder.setBuffer(message).readMessage(null);
if (request != null) {
request.getFuture().complete(response);
} else {
logger.warn("No pending request with requestId={} for {}", requestId, response.getClass().getSimpleName());
}
} catch (Throwable t) {
logger.error("Error decoding UaResponseMessage", t);
if (request != null) {
request.getFuture().completeExceptionally(t);
}
} finally {
message.release();
}
});
}
}
use of org.eclipse.milo.opcua.stack.client.transport.UaTransportRequest in project milo by eclipse.
the class OpcClientHttpCodec method decode.
@Override
protected void decode(ChannelHandlerContext ctx, HttpResponse httpResponse, List<Object> out) throws Exception {
logger.trace("channelRead0: " + httpResponse);
UaTransportRequest transportRequest = ctx.channel().attr(KEY_PENDING_REQUEST).getAndSet(null);
if (httpResponse instanceof FullHttpResponse) {
String contentType = httpResponse.headers().get(HttpHeaderNames.CONTENT_TYPE);
FullHttpResponse fullHttpResponse = (FullHttpResponse) httpResponse;
ByteBuf content = fullHttpResponse.content();
UaResponseMessage responseMessage;
switch(transportProfile) {
case HTTPS_UABINARY:
{
if (!UABINARY_CONTENT_TYPE.equalsIgnoreCase(contentType)) {
throw new UaException(StatusCodes.Bad_DecodingError, "unexpected content-type: " + contentType);
}
OpcUaBinaryStreamDecoder decoder = new OpcUaBinaryStreamDecoder(client.getStaticSerializationContext());
decoder.setBuffer(content);
responseMessage = (UaResponseMessage) decoder.readMessage(null);
break;
}
case HTTPS_UAXML:
{
// TODO extract document from SOAP message body
throw new UaException(StatusCodes.Bad_InternalError, "no decoder for transport: " + transportProfile);
}
default:
throw new UaException(StatusCodes.Bad_InternalError, "no decoder for transport: " + transportProfile);
}
transportRequest.getFuture().complete(responseMessage);
} else {
HttpResponseStatus status = httpResponse.status();
if (status.equals(HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE)) {
transportRequest.getFuture().completeExceptionally(new UaException(StatusCodes.Bad_ResponseTooLarge));
} else {
transportRequest.getFuture().completeExceptionally(new UaException(StatusCodes.Bad_UnexpectedError, String.format("%s: %s", status.code(), status.reasonPhrase())));
}
}
}
Aggregations