use of com.couchbase.client.core.deps.com.fasterxml.jackson.core.type.TypeReference in project couchbase-jvm-clients by couchbase.
the class SaslAuthenticationHandler method failConnect.
/**
* Refactored method which is called from many places to fail the connection
* process because of an issue during SASL auth.
*
* <p>Usually errors during auth are very problematic and as a result we cannot continue
* with this channel connect attempt.</p>
*
* @param ctx the channel context.
*/
private void failConnect(final ChannelHandlerContext ctx, final String message, final ByteBuf lastPacket, final Throwable cause, final short status) {
Optional<Duration> latency = ConnectTimings.stop(ctx.channel(), this.getClass(), false);
byte[] packetCopy = Bytes.EMPTY_BYTE_ARRAY;
Map<String, Object> serverContext = null;
if (lastPacket != null) {
if (MemcacheProtocol.verifyResponse(lastPacket)) {
// This is a proper response, try to extract server context
Optional<ByteBuf> body = MemcacheProtocol.body(lastPacket);
if (body.isPresent()) {
byte[] content = ByteBufUtil.getBytes(body.get());
try {
serverContext = Mapper.decodeInto(content, new TypeReference<Map<String, Object>>() {
});
} catch (Exception ex) {
// Ignore, no displayable content
}
}
} else {
// This is not a proper memcache response, store the raw packet for debugging purposes
int ridx = lastPacket.readerIndex();
lastPacket.readerIndex(lastPacket.writerIndex());
packetCopy = new byte[lastPacket.readableBytes()];
lastPacket.readBytes(packetCopy);
lastPacket.readerIndex(ridx);
}
}
KeyValueIoErrorContext errorContext = new KeyValueIoErrorContext(MemcacheProtocol.decodeStatus(status), endpointContext, serverContext);
endpointContext.environment().eventBus().publish(new SaslAuthenticationFailedEvent(latency.orElse(Duration.ZERO), errorContext, message, packetCopy));
interceptedConnectPromise.tryFailure(new AuthenticationFailureException(message, errorContext, cause));
ctx.pipeline().remove(this);
}
use of com.couchbase.client.core.deps.com.fasterxml.jackson.core.type.TypeReference in project couchbase-jvm-clients by couchbase.
the class AsyncSearchIndexManager method analyzeDocument.
/**
* Allows to see how a document is analyzed against a specific index.
*
* @param name the name of the search index.
* @param document the document to analyze.
* @return a {@link CompletableFuture} with analyzed document parts once complete.
*/
public CompletableFuture<List<JsonObject>> analyzeDocument(final String name, final JsonObject document, final AnalyzeDocumentOptions options) {
notNullOrEmpty(name, "Search Index Name");
notNull(document, "Document");
return searchHttpClient.post(path(analyzeDocumentPath(name)), options.build()).trace(TracingIdentifiers.SPAN_REQUEST_MS_ANALYZE_DOCUMENT).json(Mapper.encodeAsBytes(document.toMap())).exec(core).exceptionally(throwable -> {
if (throwable.getMessage().contains("Page not found")) {
throw new FeatureNotAvailableException("Document analysis is not available on this server version!");
} else if (throwable instanceof RuntimeException) {
throw (RuntimeException) throwable;
} else {
throw new CouchbaseException("Failed to analyze search document", throwable);
}
}).thenApply(response -> {
JsonNode rootNode = Mapper.decodeIntoTree(response.content());
List<Map<String, Object>> analyzed = Mapper.convertValue(rootNode.get("analyzed"), new TypeReference<List<Map<String, Object>>>() {
});
return analyzed.stream().filter(Objects::nonNull).map(JsonObject::from).collect(Collectors.toList());
});
}
Aggregations