public static void respForbidden(final HttpRequest request, final HttpChannel channel, ESLogger logger) { XContentBuilder builder; try { builder = ContentBuilder.restContentBuilder(request); builder.startObject() .field(new XContentBuilderString("status"), RestStatus.FORBIDDEN) .field(new XContentBuilderString("message"), "You are not login") .endObject(); channel.sendResponse( new BytesRestResponse(RestStatus.FORBIDDEN, builder)); } catch (IOException e) { if (logger != null) { logger.error("Get Exception in checkPermission: " + e.getMessage()); } e.printStackTrace(); } }
public static void respIpForbidden(final HttpRequest request, final HttpChannel channel, ESLogger logger) { XContentBuilder builder; try { builder = ContentBuilder.restContentBuilder(request); builder.startObject() .field(new XContentBuilderString("status"), RestStatus.FORBIDDEN) .field(new XContentBuilderString("message"), "Your ip is not in auth list") .endObject(); channel.sendResponse( new BytesRestResponse(RestStatus.FORBIDDEN, builder)); } catch (IOException e) { if (logger != null) { logger.error("Get Exception in checkIpPermission: " + e.getMessage()); } e.printStackTrace(); } }
@Override public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { builder.startArray(CommonFields.BUCKETS); for (Bucket bucket : buckets) { builder.startObject(); builder.field(CommonFields.KEY, bucket.getKeyAsText()); builder.field(CommonFields.DOC_COUNT, bucket.getDocCount()); Set<String> geohashGridsString = new HashSet<String>(bucket.geohashesList.size()); for (long geohash: bucket.geohashesList) { geohashGridsString.add(GeoHashUtils.toString(geohash)); } builder.array(new XContentBuilderString("geohash_grids"), geohashGridsString); builder.field(new XContentBuilderString("cluster_center")); ShapeBuilder.newPoint(bucket.getClusterCenter().getLon(), bucket.getClusterCenter().getLat()).toXContent(builder,params); ((InternalAggregations) bucket.getAggregations()).toXContentInternal(builder, params); builder.endObject(); } builder.endArray(); return builder; }
@Override protected void handleRequest(final RestRequest request, final RestChannel channel, Client client) throws Exception { // logger.info("Path:" + request.path() + "uri:" + request.uri()); XContentBuilder builder = ContentBuilder.restContentBuilder(request); if (request.path().equals("/_auth/config_reload")) { this.config.reloadConfig(); builder.startObject() .field(new XContentBuilderString("status"), RestStatus.OK) .field(new XContentBuilderString("message"), "config reload success") .endObject(); channel.sendResponse( new BytesRestResponse(RestStatus.OK, builder)); } else if (request.path().equals("/_auth/config_show")) { builder.startObject() .field("open_auth", this.config.getSet().getAsBoolean("open_auth", false)) .field("username", config.getSet().get("username", "").trim()) .field("password", config.getSet().get("password", "").trim()) .field("open_ip_auth", this.config.getSet().getAsBoolean("open_ip_auth", false)) .field("ip_auth_list", this.config.getSet().getAsArray("ip_auth_list", new String[0])) .endObject(); channel.sendResponse( new BytesRestResponse(RestStatus.OK, builder)); } //super.handleRequest(request, channel); }
private void addIntMinMax(XContentBuilderString field, int min, int max, double avg, XContentBuilder builder) throws IOException { builder.startObject(field); builder.field(Fields.MIN, min); builder.field(Fields.MAX, max); builder.field(Fields.AVG, avg); builder.endObject(); }
private void addDoubleMinMax(XContentBuilderString field, double min, double max, double avg, XContentBuilder builder) throws IOException { builder.startObject(field); builder.field(Fields.MIN, min); builder.field(Fields.MAX, max); builder.field(Fields.AVG, avg); builder.endObject(); }
/** * Gets the mappings for the given schema and table as a formatted json string. */ public String mapping(String schema, String table) throws IOException { if(USE_EXTERNAL_ES5){ return ""; } GetMappingsResponse response = getElasticInternalClient().admin().indices().prepareGetMappings(schema).setTypes(table).execute().actionGet(); XContentBuilder builder = XContentFactory.jsonBuilder(); builder.prettyPrint().lfAtEnd(); builder.startObject(); ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappingsByIndex = response.getMappings(); if (mappingsByIndex.isEmpty()) { return ""; } for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexEntry : mappingsByIndex) { if (indexEntry.value.isEmpty()) { continue; } builder.startObject(indexEntry.key, XContentBuilder.FieldCaseConversion.NONE); builder.startObject(new XContentBuilderString("mappings")); for (ObjectObjectCursor<String, MappingMetaData> typeEntry : indexEntry.value) { builder.field(typeEntry.key); builder.map(typeEntry.value.sourceAsMap()); } builder.endObject(); builder.endObject(); } builder.endObject(); return builder.string(); }
public XmlXContentBuilder array(XContentBuilderString name, String... values) throws IOException { startArray(name); for (String value : values) { value(value); } endArray(); return this; }
public XmlXContentBuilder array(XContentBuilderString name, Object... values) throws IOException { startArray(name); for (Object value : values) { value(value); } endArray(); return this; }
public XmlXContentBuilder field(XContentBuilderString name) throws IOException { if (fieldCaseConversion == FieldCaseConversion.UNDERSCORE) { generator.writeFieldName(name.underscore()); } else if (fieldCaseConversion == FieldCaseConversion.CAMELCASE) { generator.writeFieldName(name.camelCase()); } else { generator.writeFieldName(name.underscore()); } return this; }
public XmlXContentBuilder field(XContentBuilderString name, FieldCaseConversion conversion) throws IOException { if (conversion == FieldCaseConversion.UNDERSCORE) { generator.writeFieldName(name.underscore()); } else if (conversion == FieldCaseConversion.CAMELCASE) { generator.writeFieldName(name.camelCase()); } else { generator.writeFieldName(name.underscore()); } return this; }
public XmlXContentBuilder field(XContentBuilderString name, char[] value, int offset, int length) throws IOException { field(name); if (value == null) { generator.writeNull(); } else { generator.writeString(value, offset, length); } return this; }
public XmlXContentBuilder field(XContentBuilderString name, String value) throws IOException { field(name); if (value == null) { generator.writeNull(); } else { generator.writeString(value); } return this; }
public XmlXContentBuilder field(XContentBuilderString name, String value, FieldCaseConversion conversion) throws IOException { field(name, conversion); if (value == null) { generator.writeNull(); } else { generator.writeString(value); } return this; }
public XmlXContentBuilder field(XContentBuilderString name, Integer value) throws IOException { field(name); if (value == null) { generator.writeNull(); } else { generator.writeNumber(value.intValue()); } return this; }
public XmlXContentBuilder field(XContentBuilderString name, Long value) throws IOException { field(name); if (value == null) { generator.writeNull(); } else { generator.writeNumber(value.longValue()); } return this; }
public XmlXContentBuilder field(XContentBuilderString name, Float value) throws IOException { field(name); if (value == null) { generator.writeNull(); } else { generator.writeNumber(value.floatValue()); } return this; }
public XmlXContentBuilder field(XContentBuilderString name, Double value) throws IOException { field(name); if (value == null) { generator.writeNull(); } else { generator.writeNumber(value); } return this; }
public XmlXContentBuilder field(XContentBuilderString name, BigDecimal value, int scale, RoundingMode rounding, boolean toDouble) throws IOException { field(name); if (toDouble) { try { generator.writeNumber(value.setScale(scale, rounding).doubleValue()); } catch (ArithmeticException e) { generator.writeString(value.toEngineeringString()); } } else { generator.writeString(value.toEngineeringString()); } return this; }
public XmlXContentBuilder field(XContentBuilderString name, BytesReference value) throws IOException { field(name); if (!value.hasArray()) { value = value.toBytesArray(); } generator.writeBinary(value.array(), value.arrayOffset(), value.length()); return this; }
public XmlXContentBuilder field(XContentBuilderString name, Text value) throws IOException { field(name); if (value.hasBytes() && value.bytes().hasArray()) { generator.writeUTF8String(value.bytes().array(), value.bytes().arrayOffset(), value.bytes().length()); return this; } if (value.hasString()) { generator.writeString(value.string()); return this; } // TODO: TextBytesOptimization we can use a buffer here to convert it? maybe add a request to jackson to support InputStream as well? BytesArray bytesArray = value.bytes().toBytesArray(); generator.writeUTF8String(bytesArray.array(), bytesArray.arrayOffset(), bytesArray.length()); return this; }
public XmlXContentBuilder field(XContentBuilderString name, Iterable value) throws IOException { startArray(name); for (Object o : value) { value(o); } endArray(); return this; }
public XmlXContentBuilder field(XContentBuilderString name, String... value) throws IOException { startArray(name); for (String o : value) { value(o); } endArray(); return this; }
public XmlXContentBuilder field(XContentBuilderString name, Object... value) throws IOException { startArray(name); for (Object o : value) { value(o); } endArray(); return this; }
public XmlXContentBuilder field(XContentBuilderString name, int offset, int length, int... value) throws IOException { assert ((offset >= 0) && (value.length > length)); startArray(name); for (int i = offset; i < length; i++) { value(value[i]); } endArray(); return this; }
public XmlXContentBuilder field(XContentBuilderString name, int... value) throws IOException { startArray(name); for (Object o : value) { value(o); } endArray(); return this; }
public XmlXContentBuilder field(XContentBuilderString name, long... value) throws IOException { startArray(name); for (Object o : value) { value(o); } endArray(); return this; }
public XmlXContentBuilder field(XContentBuilderString name, float... value) throws IOException { startArray(name); for (Object o : value) { value(o); } endArray(); return this; }
public XmlXContentBuilder field(XContentBuilderString name, double... value) throws IOException { startArray(name); for (Object o : value) { value(o); } endArray(); return this; }
public XmlXContentBuilder timeValueField(XContentBuilderString rawFieldName, XContentBuilderString readableFieldName, TimeValue timeValue) throws IOException { if (humanReadable) { field(readableFieldName, timeValue.toString()); } field(rawFieldName, timeValue.millis()); return this; }
public XmlXContentBuilder timeValueField(XContentBuilderString rawFieldName, XContentBuilderString readableFieldName, long rawTime) throws IOException { if (humanReadable) { field(readableFieldName, new TimeValue(rawTime).toString()); } field(rawFieldName, rawTime); return this; }
public XmlXContentBuilder byteSizeField(XContentBuilderString rawFieldName, XContentBuilderString readableFieldName, ByteSizeValue byteSizeValue) throws IOException { if (humanReadable) { field(readableFieldName, byteSizeValue.toString()); } field(rawFieldName, byteSizeValue.bytes()); return this; }
public XmlXContentBuilder byteSizeField(XContentBuilderString rawFieldName, XContentBuilderString readableFieldName, long rawSize) throws IOException { if (humanReadable) { field(readableFieldName, new ByteSizeValue(rawSize).toString()); } field(rawFieldName, rawSize); return this; }
@Override public void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception{ if (logger.isDebugEnabled()){ logger.debug("REST S3ManageAction called"); } String rivername = request.param("rivername"); String command = request.param("command"); String status = null; if (START_COMMAND.equals(command)){ status = "STARTED"; } else if (STOP_COMMAND.equals(command)){ status = "STOPPED"; } try{ if (status != null){ XContentBuilder xb = jsonBuilder() .startObject() .startObject("amazon-s3") .field("feedname", rivername) .field("status", status) .endObject() .endObject(); client.prepareIndex("_river", rivername, "_s3status").setSource(xb).execute().actionGet(); } XContentBuilder builder = jsonBuilder(); builder .startObject() .field(new XContentBuilderString("ok"), true) .endObject(); channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder)); } catch (IOException e) { onFailure(request, channel, e); } }
@Override public void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception{ if (logger.isDebugEnabled()){ logger.debug("REST DriveManageAction called"); } String rivername = request.param("rivername"); String command = request.param("command"); String status = null; if (START_COMMAND.equals(command)){ status = "STARTED"; } else if (STOP_COMMAND.equals(command)){ status = "STOPPED"; } try{ if (status != null){ XContentBuilder xb = jsonBuilder() .startObject() .startObject("google-drive") .field("feedname", rivername) .field("status", status) .endObject() .endObject(); client.prepareIndex("_river", rivername, "_drivestatus").setSource(xb).execute().actionGet(); } XContentBuilder builder = jsonBuilder(); builder .startObject() .field(new XContentBuilderString("ok"), true) .endObject(); channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder)); } catch (IOException e) { onFailure(request, channel, e); } }
public Suggest(XContentBuilderString name) { this.name = name; }
public Suggest(XContentBuilderString name, List<Suggestion<? extends Entry<? extends Option>>> suggestions) { this.name = name; this.suggestions = suggestions; }
public static Suggest readSuggest(XContentBuilderString name, StreamInput in) throws IOException { Suggest result = new Suggest(name); result.readFrom(in); return result; }
protected XContentBuilderString getScriptFieldName() { return Fields.SCRIPT; }
@Override protected XContentBuilderString getScriptFieldName() { return TEMPLATE; }