dsmiley commented on code in PR #3361: URL: https://github.com/apache/solr/pull/3361#discussion_r2127845663
########## solr/modules/tika/src/java/org/apache/solr/handler/tika/TikaServerDocumentLoader.java: ########## @@ -0,0 +1,199 @@ +/* + * 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.tika; + +import java.io.InputStream; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import org.apache.solr.common.SolrException; +import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.common.params.CommonParams; +import org.apache.solr.common.util.ContentStream; +import org.apache.solr.handler.loader.ContentStreamLoader; +import org.apache.solr.request.SolrQueryRequest; +import org.apache.solr.response.SolrQueryResponse; +import org.apache.solr.update.AddUpdateCommand; +import org.apache.solr.update.processor.UpdateRequestProcessor; +import org.eclipse.jetty.client.ContentResponse; +import org.eclipse.jetty.client.HttpClient; +import org.eclipse.jetty.client.InputStreamRequestContent; +import org.eclipse.jetty.client.Request; +import org.eclipse.jetty.http.HttpHeader; +import org.eclipse.jetty.http.MimeTypes; +import org.noggit.JSONParser; +import org.noggit.ObjectBuilder; + +public class TikaServerDocumentLoader extends ContentStreamLoader { + + private final String tikaServerUrl; + private final int connectionTimeout; + private final int socketTimeout; + private final String idField; + private final boolean returnMetadata; + private final String metadataPrefix; + private final String contentField; + private final HttpClient httpClient; // Jetty's HttpClient + private final SolrQueryRequest req; + private final UpdateRequestProcessor processor; + + public TikaServerDocumentLoader( + SolrQueryRequest req, + UpdateRequestProcessor processor, + String tikaServerUrl, + int connectionTimeout, + int socketTimeout, + String idField, + boolean returnMetadata, + String metadataPrefix, + String contentField, + HttpClient jettyClient) { + this.req = req; + this.processor = processor; + this.tikaServerUrl = tikaServerUrl; + this.connectionTimeout = connectionTimeout; + this.socketTimeout = + socketTimeout; // Store it, though specific usage might vary with Jetty client + this.idField = idField; + this.returnMetadata = returnMetadata; + this.metadataPrefix = metadataPrefix; + this.contentField = contentField; + this.httpClient = jettyClient; + } + + @Override + public void load( + SolrQueryRequest req, + SolrQueryResponse rsp, + ContentStream stream, + UpdateRequestProcessor processor) + throws Exception { + String fullTikaServerUrl = this.tikaServerUrl; + if (!fullTikaServerUrl.endsWith("/")) { + fullTikaServerUrl += "/"; + } + // Using /rmeta/text to ensure X-TIKA:content has the main textual content. + fullTikaServerUrl += "rmeta/text"; + + Request jettyRequest = this.httpClient.POST(fullTikaServerUrl); + jettyRequest.accept(MimeTypes.Type.APPLICATION_JSON.asString()); + + String reqContentType = stream.getContentType(); + if (reqContentType != null) { + jettyRequest.headers(headers -> headers.add(HttpHeader.CONTENT_TYPE, reqContentType)); + } else { + jettyRequest.headers( + headers -> headers.add(HttpHeader.CONTENT_TYPE, "application/octet-stream")); + } + + // Apply request-specific timeout using connectionTimeout. + // The HttpClient instance itself is configured with an idleTimeout (derived from + // socketTimeout). + jettyRequest.timeout(this.connectionTimeout, TimeUnit.MILLISECONDS); Review Comment: weird to use the connection timeout as the request timeout. If we want one universal timeout for all the things that timeout, then `this.connectionTimeout` should just be `this.timeout`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
