Author: kwright
Date: Tue Sep 25 11:50:19 2018
New Revision: 1841919
URL: http://svn.apache.org/viewvc?rev=1841919&view=rev
Log:
Pull up yet another attempt to fix CONNECTORS-1533 from trunk.
Modified:
manifoldcf/branches/release-2.11-branch/ (props changed)
manifoldcf/branches/release-2.11-branch/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/ModifiedHttpSolrClient.java
Propchange: manifoldcf/branches/release-2.11-branch/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Sep 25 11:50:19 2018
@@ -152,4 +152,4 @@
/manifoldcf/branches/CONNECTORS-981:1605049-1605773
/manifoldcf/branches/CONNECTORS-989:1611600-1612101
/manifoldcf/branches/CONNECTORS-990:1610284-1610707
-/manifoldcf/trunk:1841397,1841587,1841596,1841598,1841618,1841840,1841853
+/manifoldcf/trunk:1841397,1841587,1841596,1841598,1841618,1841840,1841853,1841918
Modified:
manifoldcf/branches/release-2.11-branch/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/ModifiedHttpSolrClient.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/release-2.11-branch/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/ModifiedHttpSolrClient.java?rev=1841919&r1=1841918&r2=1841919&view=diff
==============================================================================
---
manifoldcf/branches/release-2.11-branch/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/ModifiedHttpSolrClient.java
(original)
+++
manifoldcf/branches/release-2.11-branch/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/ModifiedHttpSolrClient.java
Tue Sep 25 11:50:19 2018
@@ -166,35 +166,61 @@ public class ModifiedHttpSolrClient exte
}
if (SolrRequest.METHOD.POST == request.getMethod() ||
SolrRequest.METHOD.PUT == request.getMethod()) {
-
- // Hack to allow short queries to go one way, and long queries to go
another.
- final Collection<ContentStream> requestStreams = (requestWriter
instanceof
org.apache.solr.client.solrj.impl.BinaryRequestWriter)?null:requestWriter.getContentStreams(request);
- final boolean mustUseMultipart = this.useMultiPartPost && requestStreams
!= null && requestStreams.size() > 0; //request instanceof
org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;
- if (mustUseMultipart) {
- //System.out.println("Overriding with streams");
- streams = requestStreams;
- }
//System.out.println("Post or put");
String url = basePath + path;
- boolean hasNullStreamName = false;
- if (streams != null) {
- for (ContentStream cs : streams) {
- if (cs.getName() == null) {
- hasNullStreamName = true;
- break;
+
+ // UpdateRequest uses PUT now, and ContentStreamUpdateHandler uses POST.
+ // We must override PUT with POST if multipart is required.
+ // If useMultipart is on, we fall back to getting streams directly from
the request, for now.
+ final String contentWriterUrl = url + toQueryString(wparams, false);
+
+ final boolean isMultipart;
+ if (this.useMultiPartPost) {
+ final Collection<ContentStream> requestStreams =
request.getContentStreams();
+ // Do we have streams?
+ if (requestStreams != null && requestStreams.size() > 0) {
+
+ // Need to know if we have a stream name
+ boolean hasNullStreamName = false;
+ if (requestStreams != null) {
+ for (ContentStream cs : requestStreams) {
+ if (cs.getName() == null) {
+ hasNullStreamName = true;
+ break;
+ }
+ }
+ }
+
+ // Also, is the contentWriter URL too big?
+ final boolean urlTooBig = contentWriterUrl.length() > 4000;
+ //System.out.println("RequestStreams present? "+(requestStreams !=
null && requestStreams.size() > 0)+"; hasNullStreamName? "+hasNullStreamName+";
url length = "+contentWriterUrl.length());
+ isMultipart = requestStreams != null && requestStreams.size() > 0 &&
((request.getMethod() == SolrRequest.METHOD.POST && !hasNullStreamName) ||
urlTooBig);
+ if (isMultipart) {
+ //System.out.println("Overriding with multipart post");
+ streams = requestStreams;
}
+ } else {
+ isMultipart = false;
}
+ } else {
+ isMultipart = false;
}
- boolean isMultipart = ((this.useMultiPartPost && SolrRequest.METHOD.POST
== request.getMethod())
- || (streams != null && streams.size() > 1)) && !hasNullStreamName;
+ final SolrRequest.METHOD methodToUse =
isMultipart?SolrRequest.METHOD.POST:request.getMethod();
+
+ /*
+ final boolean isMultipart = ((this.useMultiPartPost &&
SolrRequest.METHOD.POST == methodToUse)
+ || (streams != null && streams.size() > 1)) && !hasNullStreamName;
+ */
+ //System.out.println("isMultipart = "+isMultipart);
+
LinkedList<NameValuePair> postOrPutParams = new LinkedList<>();
- if(contentWriter != null && !mustUseMultipart) {
+ if(contentWriter != null && !isMultipart) {
//System.out.println(" using contentwriter");
- String fullQueryUrl = url + toQueryString(wparams, false);
- HttpEntityEnclosingRequestBase postOrPut = SolrRequest.METHOD.POST ==
request.getMethod() ?
+ String fullQueryUrl = contentWriterUrl;
+ HttpEntityEnclosingRequestBase postOrPut = SolrRequest.METHOD.POST ==
methodToUse ?
new HttpPost(fullQueryUrl) : new HttpPut(fullQueryUrl);
postOrPut.addHeader("Content-Type",
contentWriter.getContentType());
@@ -216,13 +242,13 @@ public class ModifiedHttpSolrClient exte
ModifiableSolrParams queryParams =
calculateQueryParams(getQueryParams(), wparams);
queryParams.add(calculateQueryParams(request.getQueryParams(),
wparams));
String fullQueryUrl = url + toQueryString(queryParams, false);
- HttpEntityEnclosingRequestBase postOrPut = fillContentStream(request,
streams, wparams, isMultipart, postOrPutParams, fullQueryUrl);
+ HttpEntityEnclosingRequestBase postOrPut =
fillContentStream(methodToUse, streams, wparams, isMultipart, postOrPutParams,
fullQueryUrl);
return postOrPut;
}
// It is has one stream, it is the post body, put the params in the URL
else {
String fullQueryUrl = url + toQueryString(wparams, false);
- HttpEntityEnclosingRequestBase postOrPut = SolrRequest.METHOD.POST ==
request.getMethod() ?
+ HttpEntityEnclosingRequestBase postOrPut = SolrRequest.METHOD.POST ==
methodToUse ?
new HttpPost(fullQueryUrl) : new HttpPut(fullQueryUrl);
fillSingleContentStream(streams, postOrPut);
@@ -257,8 +283,8 @@ public class ModifiedHttpSolrClient exte
}
- private HttpEntityEnclosingRequestBase fillContentStream(SolrRequest
request, Collection<ContentStream> streams, ModifiableSolrParams wparams,
boolean isMultipart, LinkedList<NameValuePair> postOrPutParams, String
fullQueryUrl) throws IOException {
- HttpEntityEnclosingRequestBase postOrPut = SolrRequest.METHOD.POST ==
request.getMethod() ?
+ private HttpEntityEnclosingRequestBase fillContentStream(SolrRequest.METHOD
methodToUse, Collection<ContentStream> streams, ModifiableSolrParams wparams,
boolean isMultipart, LinkedList<NameValuePair> postOrPutParams, String
fullQueryUrl) throws IOException {
+ HttpEntityEnclosingRequestBase postOrPut = SolrRequest.METHOD.POST ==
methodToUse ?
new HttpPost(fullQueryUrl) : new HttpPut(fullQueryUrl);
if (!isMultipart) {