lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r1527554 - in /lucene/dev/branches/branch_4x: ./ solr/ solr/core/ solr/core/src/java/org/apache/solr/handler/ solr/core/src/java/org/apache/solr/response/ solr/core/src/test/org/apache/solr/schema/ solr/solrj/ solr/solrj/src/java/org/apache...
Date Mon, 30 Sep 2013 13:34:05 GMT
Author: markrmiller
Date: Mon Sep 30 13:34:04 2013
New Revision: 1527554

URL: http://svn.apache.org/r1527554
Log:
SOLR-5291: Solrj does not propagate the root cause to the user for many errors.
SOLR-3530: Better error messages / Content-Type validation in SolrJ.

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/solr/   (props changed)
    lucene/dev/branches/branch_4x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/solr/core/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/response/SchemaXmlResponseWriter.java
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/response/XMLResponseWriter.java
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/schema/TestCloudManagedSchema.java
    lucene/dev/branches/branch_4x/solr/solrj/   (props changed)
    lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/ResponseParser.java
    lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/BinaryResponseParser.java
    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/java/org/apache/solr/client/solrj/impl/XMLResponseParser.java

Modified: lucene/dev/branches/branch_4x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/CHANGES.txt?rev=1527554&r1=1527553&r2=1527554&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Mon Sep 30 13:34:04 2013
@@ -275,6 +275,9 @@ Bug Fixes
 * SOLR-5279: Implicit properties don't seem to exist on core RELOAD
   (elyograg, hossman, Steve Rowe) 
 
+* SOLR-5291: Solrj does not propagate the root cause to the user for many errors.
+  (Mark Miller)
+
 Optimizations
 ----------------------
 
@@ -289,6 +292,8 @@ Optimizations
 * SOLR-4816: CloudSolrServer now uses multiple threads to send updates by default.  
   (Joel Bernstein via Mark Miller)
 
+* SOLR-3530: Better error messages / Content-Type validation in SolrJ. (Mark Miller, hossman)
+
 Other Changes
 ----------------------
 

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java?rev=1527554&r1=1527553&r2=1527554&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
Mon Sep 30 13:34:04 2013
@@ -49,7 +49,10 @@ import org.apache.lucene.index.IndexWrit
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IOContext;
 import org.apache.lucene.store.IndexInput;
+
 import static org.apache.lucene.util.IOUtils.CHARSET_UTF_8;
+
+import org.apache.solr.client.solrj.impl.BinaryResponseParser;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrException.ErrorCode;
 import org.apache.solr.common.params.CommonParams;
@@ -1002,7 +1005,7 @@ public class ReplicationHandler extends 
 
       @Override
       public String getContentType(SolrQueryRequest request, SolrQueryResponse response)
{
-        return "application/octet-stream";
+        return BinaryResponseParser.BINARY_CONTENT_TYPE;
       }
 
       @Override

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java?rev=1527554&r1=1527553&r2=1527554&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java
Mon Sep 30 13:34:04 2013
@@ -22,6 +22,7 @@ import java.util.*;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.index.IndexableField;
 import org.apache.lucene.util.BytesRef;
+import org.apache.solr.client.solrj.impl.BinaryResponseParser;
 import org.apache.solr.common.SolrDocument;
 import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.util.JavaBinCodec;
@@ -57,7 +58,7 @@ public class BinaryResponseWriter implem
 
   @Override
   public String getContentType(SolrQueryRequest request, SolrQueryResponse response) {
-    return "application/octet-stream";
+    return BinaryResponseParser.BINARY_CONTENT_TYPE;
   }
 
   @Override

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/response/SchemaXmlResponseWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/response/SchemaXmlResponseWriter.java?rev=1527554&r1=1527553&r2=1527554&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/response/SchemaXmlResponseWriter.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/response/SchemaXmlResponseWriter.java
Mon Sep 30 13:34:04 2013
@@ -20,6 +20,7 @@ package org.apache.solr.response;
 import java.io.Writer;
 import java.io.IOException;
 
+import org.apache.solr.client.solrj.impl.XMLResponseParser;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.request.SolrQueryRequest;
 
@@ -44,6 +45,6 @@ public class SchemaXmlResponseWriter imp
 
   @Override
   public String getContentType(SolrQueryRequest request, SolrQueryResponse response) {
-    return CONTENT_TYPE_XML_UTF8;
+    return XMLResponseParser.XML_CONTENT_TYPE;
   }
 }

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/response/XMLResponseWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/response/XMLResponseWriter.java?rev=1527554&r1=1527553&r2=1527554&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/response/XMLResponseWriter.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/response/XMLResponseWriter.java
Mon Sep 30 13:34:04 2013
@@ -20,6 +20,7 @@ package org.apache.solr.response;
 import java.io.Writer;
 import java.io.IOException;
 
+import org.apache.solr.client.solrj.impl.XMLResponseParser;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.request.SolrQueryRequest;
 
@@ -44,6 +45,6 @@ public class XMLResponseWriter implement
 
   @Override
   public String getContentType(SolrQueryRequest request, SolrQueryResponse response) {
-    return CONTENT_TYPE_XML_UTF8;
+    return XMLResponseParser.XML_CONTENT_TYPE;
   }
 }

Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/schema/TestCloudManagedSchema.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/schema/TestCloudManagedSchema.java?rev=1527554&r1=1527553&r2=1527554&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/schema/TestCloudManagedSchema.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/schema/TestCloudManagedSchema.java
Mon Sep 30 13:34:04 2013
@@ -120,7 +120,7 @@ public class TestCloudManagedSchema exte
 
   protected final void assertFileNotInZooKeeper(String fileName) throws Exception {
     // Stolen from AbstractBadConfigTestBase
-    String errString = "returned non ok status:404, message:Not Found";
+    String errString = "Not Found";
     ignoreException(Pattern.quote(errString));
     String rawContent = null;
     try {

Modified: lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/ResponseParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/ResponseParser.java?rev=1527554&r1=1527553&r2=1527554&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/ResponseParser.java
(original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/ResponseParser.java
Mon Sep 30 13:34:04 2013
@@ -35,6 +35,15 @@ public abstract class ResponseParser
   public abstract NamedList<Object> processResponse(Reader reader);
   
   /**
+   * A well behaved ResponseParser will return it's content-type.
+   * 
+   * @return the content-type this parser expects to parse
+   */
+  public String getContentType() {
+    return null;
+  }
+  
+  /**
    * @return the version param passed to solr
    */
   public String getVersion()

Modified: lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/BinaryResponseParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/BinaryResponseParser.java?rev=1527554&r1=1527553&r2=1527554&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/BinaryResponseParser.java
(original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/BinaryResponseParser.java
Mon Sep 30 13:34:04 2013
@@ -30,6 +30,8 @@ import java.io.Reader;
  * @since solr 1.3
  */
 public class BinaryResponseParser extends ResponseParser {
+  public static final String BINARY_CONTENT_TYPE = "application/octet-stream";
+  
   @Override
   public String getWriterType() {
     return "javabin";
@@ -45,6 +47,10 @@ public class BinaryResponseParser extend
     }
   }
 
+  @Override
+  public String getContentType() {
+    return BINARY_CONTENT_TYPE;
+  }
 
   @Override
   public String getVersion() {

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=1527554&r1=1527553&r2=1527554&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
Mon Sep 30 13:34:04 2013
@@ -26,6 +26,7 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.http.Header;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
@@ -265,7 +266,7 @@ public class HttpSolrServer extends Solr
                 for (ContentStream content : streams) {
                   String contentType = content.getContentType();
                   if(contentType==null) {
-                    contentType = "application/octet-stream"; // default
+                    contentType = BinaryResponseParser.BINARY_CONTENT_TYPE; // default
                   }
                   String name = content.getName();
                   if(name==null) {
@@ -367,6 +368,13 @@ public class HttpSolrServer extends Solr
       
       // Read the contents
       respBody = response.getEntity().getContent();
+      Header ctHeader = response.getLastHeader("content-type");
+      String contentType;
+      if (ctHeader != null) {
+        contentType = ctHeader.getValue();
+      } else {
+        contentType = "";
+      }
       
       // handle some http level checks before trying to parse the response
       switch (httpStatus) {
@@ -382,11 +390,15 @@ public class HttpSolrServer extends Solr
           }
           break;
         default:
-          throw new RemoteSolrException(httpStatus, "Server at " + getBaseURL()
-              + " returned non ok status:" + httpStatus + ", message:"
-              + response.getStatusLine().getReasonPhrase(), null);
+          if (processor == null) {
+            throw new RemoteSolrException(httpStatus, "Server at "
+                + getBaseURL() + " returned non ok status:" + httpStatus
+                + ", message:" + response.getStatusLine().getReasonPhrase(),
+                null);
+          }
       }
       if (processor == null) {
+        
         // no processor specified, return raw stream
         NamedList<Object> rsp = new NamedList<Object>();
         rsp.add("stream", respBody);
@@ -395,6 +407,17 @@ public class HttpSolrServer extends Solr
         return rsp;
       }
       
+      String procCt = processor.getContentType();
+      if (procCt != null) {
+        if (!contentType.equals(procCt)) {
+          // unexpected content type
+          String msg = "Expected content type " + procCt + " but got " + contentType + ".";
+          RemoteSolrException e = new RemoteSolrException(httpStatus, msg + " " +
+              IOUtils.toString(respBody), null);
+          throw e;
+        }
+      }
+      
 //      if(true) {
 //        ByteArrayOutputStream copy = new ByteArrayOutputStream();
 //        IOUtils.copy(respBody, copy);
@@ -403,8 +426,13 @@ public class HttpSolrServer extends Solr
 //        respBody = new ByteArrayInputStream(copy.toByteArray());
 //      }
       
+      NamedList<Object> rsp = null;
       String charset = EntityUtils.getContentCharSet(response.getEntity());
-      NamedList<Object> rsp = processor.processResponse(respBody, charset);
+      try {
+        rsp = processor.processResponse(respBody, charset);
+      } catch (Exception e) {
+        throw new RemoteSolrException(httpStatus, e.getMessage(), e);
+      }
       if (httpStatus != HttpStatus.SC_OK) {
         String reason = null;
         try {

Modified: lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/XMLResponseParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/XMLResponseParser.java?rev=1527554&r1=1527553&r2=1527554&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/XMLResponseParser.java
(original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/XMLResponseParser.java
Mon Sep 30 13:34:04 2013
@@ -32,6 +32,7 @@ import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
+
 import java.io.InputStream;
 import java.io.Reader;
 import java.util.ArrayList;
@@ -46,6 +47,7 @@ import java.util.Locale;
  */
 public class XMLResponseParser extends ResponseParser
 {
+  public static final String XML_CONTENT_TYPE = "application/xml; charset=UTF-8";
   public static Logger log = LoggerFactory.getLogger(XMLResponseParser.class);
   private static final XMLErrorLogger xmllog = new XMLErrorLogger(log);
 
@@ -78,6 +80,11 @@ public class XMLResponseParser extends R
   {
     return "xml";
   }
+  
+  @Override
+  public String getContentType() {
+    return XML_CONTENT_TYPE;
+  }
 
   @Override
   public NamedList<Object> processResponse(Reader in) {



Mime
View raw message