You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by th...@apache.org on 2014/10/08 18:25:20 UTC

svn commit: r1630164 - in /lucene/dev/branches/lucene_solr_4_10/solr: ./ core/src/java/org/apache/solr/servlet/ solrj/src/java/org/apache/solr/client/solrj/impl/ solrj/src/java/org/apache/solr/common/

Author: thelabdude
Date: Wed Oct  8 16:25:20 2014
New Revision: 1630164

URL: http://svn.apache.org/r1630164
Log:
SOLR-6550: backport to 4_10 branch so we can backport SOLR-6511

Modified:
    lucene/dev/branches/lucene_solr_4_10/solr/CHANGES.txt
    lucene/dev/branches/lucene_solr_4_10/solr/core/src/java/org/apache/solr/servlet/ResponseUtils.java
    lucene/dev/branches/lucene_solr_4_10/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrServer.java
    lucene/dev/branches/lucene_solr_4_10/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
    lucene/dev/branches/lucene_solr_4_10/solr/solrj/src/java/org/apache/solr/common/SolrException.java

Modified: lucene/dev/branches/lucene_solr_4_10/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/solr/CHANGES.txt?rev=1630164&r1=1630163&r2=1630164&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/solr/CHANGES.txt (original)
+++ lucene/dev/branches/lucene_solr_4_10/solr/CHANGES.txt Wed Oct  8 16:25:20 2014
@@ -19,6 +19,12 @@ See the tutorial at http://lucene.apache
 
 ==================  4.10.2 ==================
 
+Other Changes
+----------------------
+
+* SOLR-6550: Provide simple mechanism for passing additional metadata / context about a server-side
+   SolrException back to the client-side (Timothy Potter)
+
 ==================  4.10.1 ==================
 
 Bug Fixes

Modified: lucene/dev/branches/lucene_solr_4_10/solr/core/src/java/org/apache/solr/servlet/ResponseUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/solr/core/src/java/org/apache/solr/servlet/ResponseUtils.java?rev=1630164&r1=1630163&r2=1630164&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/solr/core/src/java/org/apache/solr/servlet/ResponseUtils.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/solr/core/src/java/org/apache/solr/servlet/ResponseUtils.java Wed Oct  8 16:25:20 2014
@@ -40,7 +40,11 @@ public class ResponseUtils {
   public static int getErrorInfo(Throwable ex, NamedList info, Logger log) {
     int code = 500;
     if (ex instanceof SolrException) {
-      code = ((SolrException)ex).code();
+      SolrException solrExc = (SolrException)ex;
+      code = solrExc.code();
+      NamedList<String> errorMetadata = solrExc.getMetadata();
+      if (errorMetadata != null)
+        info.add("metadata", errorMetadata);
     }
     
     for (Throwable th = ex; th != null; th = th.getCause()) {

Modified: lucene/dev/branches/lucene_solr_4_10/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrServer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrServer.java?rev=1630164&r1=1630163&r2=1630164&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrServer.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrServer.java Wed Oct  8 16:25:20 2014
@@ -237,7 +237,22 @@ public class ConcurrentUpdateSolrServer 
               msg.append(response.getStatusLine().getReasonPhrase());
               msg.append("\n\n\n\n");
               msg.append("request: ").append(method.getURI());
-              handleError(new SolrException(ErrorCode.getErrorCode(statusCode), msg.toString()));
+
+              SolrException solrExc = new SolrException(ErrorCode.getErrorCode(statusCode), msg.toString());
+              // parse out the metadata from the SolrException
+              try {
+                NamedList<Object> resp =
+                    server.parser.processResponse(response.getEntity().getContent(),
+                        response.getEntity().getContentType().getValue());
+                NamedList<Object> error = (NamedList<Object>) resp.get("error");
+                if (error != null)
+                  solrExc.setMetadata((NamedList<String>) error.get("metadata"));
+              } catch (Exception exc) {
+                // don't want to fail to report error if parsing the response fails
+                log.warn("Failed to parse error response from "+server.getBaseURL()+" due to: "+exc);
+              }
+
+              handleError(solrExc);
             } else {
               onSuccess(response);
             }

Modified: lucene/dev/branches/lucene_solr_4_10/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java?rev=1630164&r1=1630163&r2=1630164&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java Wed Oct  8 16:25:20 2014
@@ -530,6 +530,7 @@ public class HttpSolrServer extends Solr
         throw new RemoteSolrException(httpStatus, e.getMessage(), e);
       }
       if (httpStatus != HttpStatus.SC_OK) {
+        NamedList<String> metadata = null;
         String reason = null;
         try {
           NamedList err = (NamedList) rsp.get("error");
@@ -538,6 +539,7 @@ public class HttpSolrServer extends Solr
             if(reason == null) {
               reason = (String) err.get("trace");
             }
+            metadata = (NamedList<String>)err.get("metadata");
           }
         } catch (Exception ex) {}
         if (reason == null) {
@@ -547,7 +549,9 @@ public class HttpSolrServer extends Solr
           msg.append("request: " + method.getURI());
           reason = java.net.URLDecoder.decode(msg.toString(), UTF_8);
         }
-        throw new RemoteSolrException(httpStatus, reason, null);
+        RemoteSolrException rss = new RemoteSolrException(httpStatus, reason, null);
+        if (metadata != null) rss.setMetadata(metadata);
+        throw rss;
       }
       success = true;
       return rsp;

Modified: lucene/dev/branches/lucene_solr_4_10/solr/solrj/src/java/org/apache/solr/common/SolrException.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/solr/solrj/src/java/org/apache/solr/common/SolrException.java?rev=1630164&r1=1630163&r2=1630164&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/solr/solrj/src/java/org/apache/solr/common/SolrException.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/solr/solrj/src/java/org/apache/solr/common/SolrException.java Wed Oct  8 16:25:20 2014
@@ -23,6 +23,7 @@ import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.solr.common.util.NamedList;
 import org.slf4j.Logger;
 
 /**
@@ -85,6 +86,7 @@ public class SolrException extends Runti
   }
   
   int code=0;
+  protected NamedList<String> metadata;
 
   /**
    * The HTTP Status code associated with this Exception.  For SolrExceptions 
@@ -97,6 +99,26 @@ public class SolrException extends Runti
    */
   public int code() { return code; }
 
+  public void setMetadata(NamedList<String> metadata) {
+    this.metadata = metadata;
+  }
+
+  public NamedList<String> getMetadata() {
+    return metadata;
+  }
+
+  public String getMetadata(String key) {
+    return (metadata != null && key != null) ? metadata.get(key) : null;
+  }
+
+  public void setMetadata(String key, String value) {
+    if (key == null || value == null)
+      throw new IllegalArgumentException("Exception metadata cannot be null!");
+
+    if (metadata == null)
+      metadata = new NamedList<String>();
+    metadata.add(key, value);
+  }
 
   public void log(Logger log) { log(log,this); }
   public static void log(Logger log, Throwable e) {