public static XContentBuilder restContentBuilder(RestRequest request, @Nullable BytesReference autoDetectSource) throws IOException { XContentType contentType = XContentType.fromRestContentType(request.param("format", request.header("Content-Type"))); if (contentType == null) { // try and guess it from the auto detect source if (autoDetectSource != null) { contentType = XContentFactory.xContentType(autoDetectSource); } } if (contentType == null) { // default to JSON contentType = XContentType.JSON; } XContentBuilder builder = new XContentBuilder(XContentFactory.xContent(contentType), new BytesStreamOutput()); if (request.paramAsBoolean("pretty", false)) { builder.prettyPrint().lfAtEnd(); } builder.humanReadable(request.paramAsBoolean("human", builder.humanReadable())); String casing = request.param("case"); if (casing != null && "camelCase".equals(casing)) { builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.CAMELCASE); } else { // we expect all REST interfaces to write results in underscore casing, so // no need for double casing builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.NONE); } return builder; }
new XContentBuilder(XContentFactory.xContent(responseContentType), unclosableOutputStream, includes, excludes); if (pretty) { builder.prettyPrint().lfAtEnd();
static BytesRestResponse convertMainResponse(MainResponse response, RestRequest request, XContentBuilder builder) throws IOException { RestStatus status = response.isAvailable() ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE; // Default to pretty printing, but allow ?pretty=false to disable if (request.hasParam("pretty") == false) { builder.prettyPrint().lfAtEnd(); } response.toXContent(builder, request); return new BytesRestResponse(status, builder); }
new XContentBuilder(XContentFactory.xContent(responseContentType), unclosableOutputStream, includes, excludes); if (pretty) { builder.prettyPrint().lfAtEnd();
public static String queryAsJson(QueryBuilder query) throws IOException { XContentBuilder x = XContentFactory.jsonBuilder(); x.prettyPrint().lfAtEnd(); query.toXContent(x, ToXContent.EMPTY_PARAMS); return x.string(); }
new XContentBuilder(XContentFactory.xContent(responseContentType), unclosableOutputStream, includes, excludes); if (pretty) { builder.prettyPrint().lfAtEnd();
new XContentBuilder(XContentFactory.xContent(responseContentType), unclosableOutputStream, includes, excludes); if (pretty) { builder.prettyPrint().lfAtEnd();
private void sendResponse(final RestRequest request, final RestChannel channel, final Map<String, Object> params, final boolean acknowledged) { try { final XContentBuilder builder = JsonXContent.contentBuilder(); if (request.hasParam("pretty")) { builder.prettyPrint().lfAtEnd(); } builder.startObject(); builder.field("acknowledged", acknowledged); if (params != null) { for (final Map.Entry<String, Object> entry : params.entrySet()) { builder.field(entry.getKey(), entry.getValue()); } } builder.endObject(); channel.sendResponse(new BytesRestResponse(OK, builder)); } catch (final Exception e) { sendErrorResponse(channel, e); } }
private void sendResponse(final RestRequest request, final RestChannel channel, final Map<String, Object> params) { try { final XContentBuilder builder = JsonXContent.contentBuilder(); if (request.hasParam("pretty")) { builder.prettyPrint().lfAtEnd(); } builder.startObject(); builder.field("acknowledged", true); if (params != null) { for (final Map.Entry<String, Object> entry : params.entrySet()) { builder.field(entry.getKey(), entry.getValue()); } } builder.endObject(); channel.sendResponse(new BytesRestResponse(OK, builder)); } catch (final Exception e) { sendErrorResponse(channel, e); } }
private void sendResponse(final RestRequest request, final RestChannel channel, final String file) { try { final XContentBuilder builder = JsonXContent.contentBuilder(); final String pretty = request.param("pretty"); if (pretty != null && !"false".equalsIgnoreCase(pretty)) { builder.prettyPrint().lfAtEnd(); } builder.startObject(); builder.field("acknowledged", true); builder.field("file", file); builder.endObject(); channel.sendResponse(new BytesRestResponse(OK, builder)); } catch (final IOException e) { throw new ElasticsearchException("Failed to create a resposne.", e); } }
static BytesRestResponse convertMainResponse(MainResponse response, RestRequest request, XContentBuilder builder) throws IOException { RestStatus status = response.isAvailable() ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE; // Default to pretty printing, but allow ?pretty=false to disable if (request.hasParam("pretty") == false) { builder.prettyPrint().lfAtEnd(); } response.toXContent(builder, request); return new BytesRestResponse(status, builder); } }
static BytesRestResponse convertMainResponse(MainResponse response, RestRequest request, XContentBuilder builder) throws IOException { RestStatus status = response.isAvailable() ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE; // Default to pretty printing, but allow ?pretty=false to disable if (request.hasParam("pretty") == false) { builder.prettyPrint().lfAtEnd(); } response.toXContent(builder, request); return new BytesRestResponse(status, builder); }
static BytesRestResponse convertMainResponse(MainResponse response, RestRequest request, XContentBuilder builder) throws IOException { RestStatus status = response.isAvailable() ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE; // Default to pretty printing, but allow ?pretty=false to disable if (request.hasParam("pretty") == false) { builder.prettyPrint().lfAtEnd(); } response.toXContent(builder, request); return new BytesRestResponse(status, builder); } }
final String pretty = request.param("pretty"); if (pretty != null && !"false".equalsIgnoreCase(pretty)) { builder.prettyPrint().lfAtEnd();
public static XContentBuilder restContentBuilder(RestRequest request) throws IOException { XContentType contentType = XContentType .fromRestContentType(request.param("format", request.header("Content-Type"))); if (contentType == null) { // default to JSON contentType = XContentType.JSON; } XContentBuilder builder = new XContentBuilder(XContentFactory.xContent(contentType), new BytesStreamOutput()); if (request.paramAsBoolean("pretty", false)) { builder.prettyPrint().lfAtEnd(); } String casing = request.param("case"); if (casing != null && "camelCase".equals(casing)) { builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.CAMELCASE); } else { // we expect all REST interfaces to write results in underscore casing, so // no need for double casing builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.NONE); } return builder; }
public static XContentBuilder restContentBuilder(RestRequest request) throws IOException { XContentType contentType = XContentType.fromRestContentType(request.param("format", request.header("Content-Type"))); if (contentType == null) { // default to JSON contentType = XContentType.JSON; } XContentBuilder builder = new XContentBuilder(XContentFactory.xContent(contentType), new BytesStreamOutput()); if (request.paramAsBoolean("pretty", false)) { builder.prettyPrint().lfAtEnd(); } String casing = request.param("case"); if (casing != null && "camelCase".equals(casing)) { builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.CAMELCASE); } else { // we expect all REST interfaces to write results in underscore casing, so // no need for double casing builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.NONE); } return builder; }
final String pretty = request.param("pretty"); if (pretty != null && !"false".equalsIgnoreCase(pretty)) { builder.prettyPrint().lfAtEnd();
builder.prettyPrint().lfAtEnd();
XContentBuilder builder = new XContentBuilder(XContentFactory.xContent(contentType), bytesOutput(), filters); if (request.paramAsBoolean("pretty", false)) { builder.prettyPrint().lfAtEnd();