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 18:35:26 UTC

svn commit: r1469946 - in /lucene/dev/trunk/solr/solrj/src: java/org/apache/solr/client/solrj/impl/HttpSolrServer.java test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java test/org/apache/solr/client/solrj/SolrExampleXMLTest.java

Author: ryan
Date: Fri Apr 19 16:35:26 2013
New Revision: 1469946

URL: http://svn.apache.org/r1469946
Log:
SOLR-4358: HttpSolrServer now supports forcing multipart requests

Modified:
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
    lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java
    lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java?rev=1469946&r1=1469945&r2=1469946&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java Fri Apr 19 16:35:26 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/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java?rev=1469946&r1=1469945&r2=1469946&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java (original)
+++ lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java Fri Apr 19 16:35:26 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/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java?rev=1469946&r1=1469945&r2=1469946&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java (original)
+++ lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java Fri Apr 19 16:35:26 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);



RE: svn commit: r1469946 - in /lucene/dev/trunk/solr/solrj/src: java/org/apache/solr/client/solrj/impl/HttpSolrServer.java test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java test/org/apache/solr/client/solrj/SolrExampleXMLTest.java

Posted by Uwe Schindler <uw...@thetaphi.de>.
Hi Ryan,

can you remove the code commented out? It was there for your debugging but should not stay alive. Especially as it uses forbidden-apis (byte<->String without charset).

Uwe

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de


> -----Original Message-----
> From: ryan@apache.org [mailto:ryan@apache.org]
> Sent: Friday, April 19, 2013 6:35 PM
> To: commits@lucene.apache.org
> Subject: svn commit: r1469946 - in /lucene/dev/trunk/solr/solrj/src:
> java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
> test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java
> test/org/apache/solr/client/solrj/SolrExampleXMLTest.java
> 
> Author: ryan
> Date: Fri Apr 19 16:35:26 2013
> New Revision: 1469946
> 
> URL: http://svn.apache.org/r1469946
> Log:
> SOLR-4358: HttpSolrServer now supports forcing multipart requests
> 
> Modified:
> 
> lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpS
> olrServer.java
> 
> lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampl
> eBinaryTest.java
> 
> lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampl
> eXMLTest.java
> 
> Modified:
> lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpS
> olrServer.java
> URL:
> http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apa
> che/solr/client/solrj/impl/HttpSolrServer.java?rev=1469946&r1=1469945&r2
> =1469946&view=diff
> ==========================================================
> ====================
> ---
> lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpS
> olrServer.java (original)
> +++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/im
> +++ pl/HttpSolrServer.java Fri Apr 19 16:35:26 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/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampl
> eBinaryTest.java
> URL:
> http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/test/org/apa
> che/solr/client/solrj/SolrExampleBinaryTest.java?rev=1469946&r1=1469945&
> r2=1469946&view=diff
> ==========================================================
> ====================
> ---
> lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampl
> eBinaryTest.java (original)
> +++ lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/So
> +++ lrExampleBinaryTest.java Fri Apr 19 16:35:26 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/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampl
> eXMLTest.java
> URL:
> http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/test/org/apa
> che/solr/client/solrj/SolrExampleXMLTest.java?rev=1469946&r1=1469945&r2
> =1469946&view=diff
> ==========================================================
> ====================
> ---
> lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampl
> eXMLTest.java (original)
> +++ lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/So
> +++ lrExampleXMLTest.java Fri Apr 19 16:35:26 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);



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org