当前位置: 首页>>代码示例>>Java>>正文


Java XContentType.fromMediaTypeOrFormat方法代码示例

本文整理汇总了Java中org.elasticsearch.common.xcontent.XContentType.fromMediaTypeOrFormat方法的典型用法代码示例。如果您正苦于以下问题:Java XContentType.fromMediaTypeOrFormat方法的具体用法?Java XContentType.fromMediaTypeOrFormat怎么用?Java XContentType.fromMediaTypeOrFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.common.xcontent.XContentType的用法示例。


在下文中一共展示了XContentType.fromMediaTypeOrFormat方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ClientYamlTestResponse

import org.elasticsearch.common.xcontent.XContentType; //导入方法依赖的package包/类
ClientYamlTestResponse(Response response) throws IOException {
    this.response = response;
    if (response.getEntity() != null) {
        String contentType = response.getHeader("Content-Type");
        this.bodyContentType = XContentType.fromMediaTypeOrFormat(contentType);
        try {
            byte[] bytes = EntityUtils.toByteArray(response.getEntity());
            //skip parsing if we got text back (e.g. if we called _cat apis)
            if (bodyContentType != null) {
                this.parsedResponse = ObjectPath.createFromXContent(bodyContentType.xContent(), new BytesArray(bytes));
            }
            this.body = bytes;
        } catch (IOException e) {
            EntityUtils.consumeQuietly(response.getEntity());
            throw e;
        }
    } else {
        this.body = null;
        this.bodyContentType = null;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:ClientYamlTestResponse.java

示例2: parseEntity

import org.elasticsearch.common.xcontent.XContentType; //导入方法依赖的package包/类
<Resp> Resp parseEntity(
        HttpEntity entity, CheckedFunction<XContentParser, Resp, IOException> entityParser) throws IOException {
    if (entity == null) {
        throw new IllegalStateException("Response body expected but not returned");
    }
    if (entity.getContentType() == null) {
        throw new IllegalStateException("Elasticsearch didn't return the [Content-Type] header, unable to parse response body");
    }
    XContentType xContentType = XContentType.fromMediaTypeOrFormat(entity.getContentType().getValue());
    if (xContentType == null) {
        throw new IllegalStateException("Unsupported Content-Type: " + entity.getContentType().getValue());
    }
    try (XContentParser parser = xContentType.xContent().createParser(registry, entity.getContent())) {
        return entityParser.apply(parser);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:RestHighLevelClient.java

示例3: createFromResponse

import org.elasticsearch.common.xcontent.XContentType; //导入方法依赖的package包/类
public static ObjectPath createFromResponse(Response response) throws IOException {
    byte[] bytes = EntityUtils.toByteArray(response.getEntity());
    String contentType = response.getHeader("Content-Type");
    XContentType xContentType = XContentType.fromMediaTypeOrFormat(contentType);
    return ObjectPath.createFromXContent(xContentType.xContent(), new BytesArray(bytes));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:ObjectPath.java

示例4: entityAsMap

import org.elasticsearch.common.xcontent.XContentType; //导入方法依赖的package包/类
/**
 * Convert the entity from a {@link Response} into a map of maps.
 */
public Map<String, Object> entityAsMap(Response response) throws IOException {
    XContentType xContentType = XContentType.fromMediaTypeOrFormat(response.getEntity().getContentType().getValue());
    try (XContentParser parser = createParser(xContentType.xContent(), response.getEntity().getContent())) {
        return parser.map();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:ESRestTestCase.java

示例5: newBuilder

import org.elasticsearch.common.xcontent.XContentType; //导入方法依赖的package包/类
/**
 * Creates a new {@link XContentBuilder} for a response to be sent using this channel. The builder's type is determined by the following
 * logic. If the request has a format parameter that will be used to attempt to map to an {@link XContentType}. If there is no format
 * parameter, the HTTP Accept header is checked to see if it can be matched to a {@link XContentType}. If this first attempt to map
 * fails, the request content type will be used if the value is not {@code null}; if the value is {@code null} the output format falls
 * back to JSON.
 */
@Override
public XContentBuilder newBuilder(@Nullable XContentType requestContentType, boolean useFiltering) throws IOException {
    // try to determine the response content type from the media type or the format query string parameter, with the format parameter
    // taking precedence over the Accept header
    XContentType responseContentType = XContentType.fromMediaTypeOrFormat(format);
    if (responseContentType == null) {
        if (requestContentType != null) {
            // if there was a parsed content-type for the incoming request use that since no format was specified using the query
            // string parameter or the HTTP Accept header
            responseContentType = requestContentType;
        } else {
            // default to JSON output when all else fails
            responseContentType = XContentType.JSON;
        }
    }

    Set<String> includes = Collections.emptySet();
    Set<String> excludes = Collections.emptySet();
    if (useFiltering) {
        Set<String> filters = Strings.splitStringByCommaToSet(filterPath);
        includes = filters.stream().filter(INCLUDE_FILTER).collect(toSet());
        excludes = filters.stream().filter(EXCLUDE_FILTER).map(f -> f.substring(1)).collect(toSet());
    }

    XContentBuilder builder = new XContentBuilder(XContentFactory.xContent(responseContentType), bytesOutput(), includes, excludes);
    if (pretty) {
        builder.prettyPrint().lfAtEnd();
    }

    builder.humanReadable(human);
    return builder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:40,代码来源:AbstractRestChannel.java

示例6: buildResponse

import org.elasticsearch.common.xcontent.XContentType; //导入方法依赖的package包/类
public static RestResponse buildResponse(Table table, RestChannel channel) throws Exception {
    RestRequest request = channel.request();
    XContentType xContentType = XContentType.fromMediaTypeOrFormat(request.param("format", request.header("Accept")));
    if (xContentType != null) {
        return buildXContentBuilder(table, channel);
    }
    return buildTextPlainResponse(table, channel);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:RestTable.java

示例7: entityAsMap

import org.elasticsearch.common.xcontent.XContentType; //导入方法依赖的package包/类
public static Map<String, Object> entityAsMap(Response response) throws UnsupportedOperationException, IOException {
	XContentType xContentType = XContentType
			.fromMediaTypeOrFormat(response.getEntity().getContentType().getValue());
	try (XContentParser parser = createParser(xContentType.xContent(), response.getEntity().getContent())) {
		return parser.map();
	}
}
 
开发者ID:biocaddie,项目名称:elasticsearch-queryexpansion-plugin,代码行数:8,代码来源:AbstractITCase.java


注:本文中的org.elasticsearch.common.xcontent.XContentType.fromMediaTypeOrFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。