ContentStreamUpdateRequest error de escritura del socket al enviar cadenas grandes

I get the following exception when sending data to solr using the ContentStreamUpdateRequest of SolrJ

Exception in thread "main" org.apache.solr.client.solrj.SolrServerException: java.net.SocketException: Software caused connection abort: socket write error
    at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:478)
    at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:244)
    at com.atosworldline.documentarchiver.core.solr.SolrIndexer.addDocument(SolrIndexer.java:48)
    at com.atosworldline.documentarchiver.core.solr.SolrIndexerTest.main(SolrIndexerTest.java:14)
Caused by: java.net.SocketException: Software caused connection abort: socket write error
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
    at java.io.BufferedOutputStream.write(BufferedOutputStream.java:105)
    at org.apache.commons.httpclient.HttpConnection.write(HttpConnection.java:975)
    at org.apache.commons.httpclient.HttpConnection.write(HttpConnection.java:943)
    at org.apache.commons.httpclient.HttpConnection.print(HttpConnection.java:1033)
    at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.print(MultiThreadedHttpConnectionManager.java:1644)
    at org.apache.commons.httpclient.HttpMethodBase.writeRequestLine(HttpMethodBase.java:2218)
    at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2059)
    at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
    at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
    at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
    at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:422)
    ... 3 more

The reason for that exception is, that I'm sending the binary data of the document to solr. If I remove this, the application runs successfull. I'm using the following code to send the request

SolrServer solrServer = new CommonsHttpSolrServer(url);
ContentStreamUpdateRequest request = new ContentStreamUpdateRequest(EXTRACT);
request.addFile(document);

//request.setParam("literal.id", documentName);
request.setAction(ACTION.COMMIT, true, true);
byte[] byteContent = FileUtils.readFileToByteArray(document);
String base64encodedFile = Base64.byteArrayToBase64(byteContent, 0, byteContent.length);
request.setParam(SolrDBSchema.DOCUMENT.toString(), base64encodedFile);
request.setParam("literal." + SolrDBSchema.OWNER.toString(), owner);
request.setParam("literal." + SolrDBSchema.VALID.toString(), Boolean.toString(valid));
request.setParam("literal." + SolrDBSchema.DATE.toString(), validFor.toString());
request.setParam("literal." + SolrDBSchema.DOCUMENT_TYPE.toString(), documentType);
solrServer.request(request);

I think the String base64encodedFile is to long for a HTTP request, but I don't know a solution for that problem. As far as I know Solr is not able to store the document by configuration.

preguntado el 08 de noviembre de 11 a las 09:11

1 Respuestas

Since you are using SolrJ, consider setting the RequestWriter to use the BinaryRequestWriter, like this:

   solrServer.setRequestWriter(new BinaryRequestWriter());

This will allow you to write your data to Solr in the binary format and may bypass the issue you are experiencing sending the large data stream as XML.

Note that you will need to ensure you have the BinaryUpdateRequestHandler enabled in your solrconfig.xml settings.

  <requestHandler name="/update/javabin" class="solr.BinaryUpdateRequestHandler" /> 

respondido 08 nov., 11:17

I still get the same exception. I dived into the code. The problem is, that it's hardcoded in the CommonsHttpSolrServer to send the parameters as a HTTP GET request. If I'd able to send them as POST request it wouldn't be a problem. So I should request that as a new feature. - itsme

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.