當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。