You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ry...@apache.org on 2013/04/19 22:28:22 UTC

svn commit: r1470023 - in /lucene/dev/branches/branch_4x: ./ solr/ solr/solrj/ solr/solrj/src/java/org/apache/solr/client/solrj/impl/ solr/solrj/src/test/org/apache/solr/client/solrj/

Author: ryan
Date: Fri Apr 19 20:28:22 2013
New Revision: 1470023

URL: http://svn.apache.org/r1470023
Log:
SOLR-4358: HttpSolrServer now supports forcing multipart requests
........
Merged revision(s) 1469946 from lucene/dev/trunk:

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/solr/   (props changed)
    lucene/dev/branches/branch_4x/solr/solrj/   (props changed)
    lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
    lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java
    lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java

Modified: lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java?rev=1470023&r1=1470022&r2=1470023&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java Fri Apr 19 20:28:22 2013
@@ -225,13 +225,22 @@ public class HttpSolrServer extends Solr
           else if( SolrRequest.METHOD.POST == request.getMethod() ) {
 
             String url = baseUrl + path;
-            boolean isMultipart = ( streams != null && streams.size() > 1 );
+            boolean hasNullStreamName = false;
+            if (streams != null) {
+              for (ContentStream cs : streams) {
+                if (cs.getName() == null) {
+                  hasNullStreamName = true;
+                  break;
+                }
+              }
+            }
+            boolean isMultipart = (this.useMultiPartPost || ( streams != null && streams.size() > 1 )) && !hasNullStreamName;
 
             LinkedList<NameValuePair> postParams = new LinkedList<NameValuePair>();
             if (streams == null || isMultipart) {
               HttpPost post = new HttpPost(url);
               post.setHeader("Content-Charset", "UTF-8");
-              if (!this.useMultiPartPost && !isMultipart) {
+              if (!isMultipart) {
                 post.addHeader("Content-Type",
                     "application/x-www-form-urlencoded; charset=UTF-8");
               }
@@ -243,7 +252,7 @@ public class HttpSolrServer extends Solr
                 String[] vals = params.getParams(p);
                 if (vals != null) {
                   for (String v : vals) {
-                    if (this.useMultiPartPost || isMultipart) {
+                    if (isMultipart) {
                       parts.add(new FormBodyPart(p, new StringBody(v, Charset.forName("UTF-8"))));
                     } else {
                       postParams.add(new BasicNameValuePair(p, v));
@@ -252,13 +261,17 @@ public class HttpSolrServer extends Solr
                 }
               }
 
-              if (isMultipart) {
+              if (isMultipart && streams != null) {
                 for (ContentStream content : streams) {
                   String contentType = content.getContentType();
                   if(contentType==null) {
                     contentType = "application/octet-stream"; // default
                   }
-                  parts.add(new FormBodyPart(content.getName(), 
+                  String name = content.getName();
+                  if(name==null) {
+                    name = "";
+                  }
+                  parts.add(new FormBodyPart(name, 
                        new InputStreamBody(
                            content.getStream(), 
                            contentType, 
@@ -381,6 +394,15 @@ public class HttpSolrServer extends Solr
         shouldClose = false;
         return rsp;
       }
+      
+//      if(true) {
+//        ByteArrayOutputStream copy = new ByteArrayOutputStream();
+//        IOUtils.copy(respBody, copy);
+//        String val = new String(copy.toByteArray());
+//        System.out.println(">RESPONSE>"+val+"<"+val.length());
+//        respBody = new ByteArrayInputStream(copy.toByteArray());
+//      }
+      
       String charset = EntityUtils.getContentCharSet(response.getEntity());
       NamedList<Object> rsp = processor.processResponse(respBody, charset);
       if (httpStatus != HttpStatus.SC_OK) {

Modified: lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java?rev=1470023&r1=1470022&r2=1470023&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java Fri Apr 19 20:28:22 2013
@@ -46,6 +46,7 @@ public class SolrExampleBinaryTest exten
       s.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
       s.setDefaultMaxConnectionsPerHost(100);
       s.setMaxTotalConnections(100);
+      s.setUseMultiPartPost(random().nextBoolean());
 
       // where the magic happens
       s.setParser(new BinaryResponseParser());

Modified: lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java?rev=1470023&r1=1470022&r2=1470023&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java Fri Apr 19 20:28:22 2013
@@ -38,6 +38,7 @@ public class SolrExampleXMLTest extends 
     try {
       String url = jetty.getBaseUrl().toString();
       HttpSolrServer s = new HttpSolrServer(url);
+      s.setUseMultiPartPost(random().nextBoolean());
       s.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
       s.setDefaultMaxConnectionsPerHost(100);
       s.setMaxTotalConnections(100);