Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions changelog/unreleased/SOLR-7498-extract-null-stream-size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: >
The extracting request handler no longer indexes the text "null" as stream_size when the size of
the uploaded content stream is unknown, which failed on numeric stream_size fields.
type: fixed
authors:
- name: Nick Shanin
links:
- name: SOLR-7498
url: https://issues.apache.org/jira/browse/SOLR-7498
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ default ExtractionMetadata buildMetadataFromRequest(ExtractionRequest request) {
md.add(ExtractingMetadataConstants.HTTP_HEADER_CONTENT_TYPE, request.contentType);
md.add(ExtractingMetadataConstants.STREAM_NAME, request.streamName);
md.add(ExtractingMetadataConstants.STREAM_SOURCE_INFO, request.streamSourceInfo);
md.add(ExtractingMetadataConstants.STREAM_SIZE, String.valueOf(request.streamSize));
// the size is unknown (null) for streams that do not report one; do not add the text "null"
if (request.streamSize != null) {
md.add(ExtractingMetadataConstants.STREAM_SIZE, String.valueOf(request.streamSize));
}
md.add(ExtractingMetadataConstants.STREAM_CONTENT_TYPE, request.contentType);
md.add(ExtractingMetadataConstants.HTTP_HEADER_CONTENT_ENCODING, request.charset);
return md;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.handler.extraction;

import java.io.InputStream;
import org.apache.solr.SolrTestCase;
import org.junit.Test;
import org.xml.sax.helpers.DefaultHandler;

/** SOLR-7498: an unknown stream size must not be reported as the text "null". */
public class ExtractionBackendMetadataTest extends SolrTestCase {

private static final ExtractionBackend BACKEND =
new ExtractionBackend() {
@Override
public ExtractionResult extract(InputStream inputStream, ExtractionRequest request) {
throw new UnsupportedOperationException();
}

@Override
public void extractWithSaxHandler(
InputStream inputStream,
ExtractionRequest request,
ExtractionMetadata md,
DefaultHandler saxContentHandler) {
throw new UnsupportedOperationException();
}

@Override
public String name() {
return "test";
}
};

@Test
public void testUnknownStreamSizeIsNotAdded() {
ExtractionRequest request = ExtractionRequest.builder().streamName("doc.pdf").build();
ExtractionMetadata md = BACKEND.buildMetadataFromRequest(request);
assertNull(md.getFirst(ExtractingMetadataConstants.STREAM_SIZE));
assertEquals("doc.pdf", md.getFirst(ExtractingMetadataConstants.STREAM_NAME));
}

@Test
public void testKnownStreamSizeIsAdded() {
ExtractionRequest request = ExtractionRequest.builder().streamSize(1234L).build();
ExtractionMetadata md = BACKEND.buildMetadataFromRequest(request);
assertEquals("1234", md.getFirst(ExtractingMetadataConstants.STREAM_SIZE));
}
}