@Override public List<ServiceReference> lookupService(ServiceMessage request) { List<ServiceReference> result = referencesByQualifier.get(request.qualifier()); if (result == null || result.isEmpty()) { return Collections.emptyList(); } String contentType = request.dataFormatOrDefault(); return result .stream() .filter(ref -> ref.contentTypes().contains(contentType)) .collect(Collectors.toList()); }
@Override public List<ServiceReference> lookupService(ServiceMessage request) { List<ServiceReference> result = referencesByQualifier.get(request.qualifier()); if (result == null || result.isEmpty()) { return Collections.emptyList(); } String contentType = request.dataFormatOrDefault(); return result .stream() .filter(ref -> ref.contentTypes().contains(contentType)) .collect(Collectors.toList()); }
private Mono<Void> ok(HttpServerResponse httpResponse, ServiceMessage response) { ByteBuf content = response.hasData(ByteBuf.class) ? response.data() : encodeData(response.data(), response.dataFormatOrDefault()); return httpResponse.status(OK).sendObject(content).then(); }
private Mono<Void> error(HttpServerResponse httpResponse, ServiceMessage response) { int code = Integer.parseInt(Qualifier.getQualifierAction(response.qualifier())); HttpResponseStatus status = HttpResponseStatus.valueOf(code); ByteBuf content = response.hasData(ErrorData.class) ? encodeData(response.data(), response.dataFormatOrDefault()) : response.data(); return httpResponse.status(status).sendObject(content).then(); }
private Mono<Void> ok(HttpServerResponse httpResponse, ServiceMessage response) { ByteBuf content = response.hasData(ByteBuf.class) ? response.data() : encodeData(response.data(), response.dataFormatOrDefault()); return httpResponse.status(OK).sendObject(content).then(); }
dataBuffer = ByteBufAllocator.DEFAULT.buffer(); try { DataCodec dataCodec = DataCodec.getInstance(message.dataFormatOrDefault()); dataCodec.encode(new ByteBufOutputStream(dataBuffer), message.data()); } catch (Throwable ex) {
private Mono<Void> error(HttpServerResponse httpResponse, ServiceMessage response) { int code = response.errorType(); HttpResponseStatus status = HttpResponseStatus.valueOf(code); ByteBuf content = response.hasData(ErrorData.class) ? encodeData(response.data(), response.dataFormatOrDefault()) : response.data(); return httpResponse.status(status).sendObject(content).then(); }
/** * Decode message. * * @param message the original message (with {@link ByteBuf} data) * @param dataType the type of the data. * @return a new Service message that upon {@link ServiceMessage#data()} returns the actual data * (of type data type) * @throws MessageCodecException when decode fails */ public static ServiceMessage decodeData(ServiceMessage message, Class<?> dataType) throws MessageCodecException { if (!message.hasData(ByteBuf.class) || dataType == null) { return message; } Object data; Class<?> targetType = message.isError() ? ErrorData.class : dataType; ByteBuf dataBuffer = message.data(); try (ByteBufInputStream inputStream = new ByteBufInputStream(dataBuffer, true)) { DataCodec dataCodec = DataCodec.getInstance(message.dataFormatOrDefault()); data = dataCodec.decode(inputStream, targetType); } catch (Throwable ex) { throw new MessageCodecException( "Failed to decode data on message q=" + message.qualifier(), ex); } return ServiceMessage.from(message).data(data).build(); } }