manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1673580 - in /manifoldcf/branches/dev_1x: ./ connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/
Date Tue, 14 Apr 2015 23:10:26 GMT
Author: kwright
Date: Tue Apr 14 23:10:25 2015
New Revision: 1673580

URL: http://svn.apache.org/r1673580
Log:
Pull up build fix from trunk.

Modified:
    manifoldcf/branches/dev_1x/   (props changed)
    manifoldcf/branches/dev_1x/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/HttpPoster.java
    manifoldcf/branches/dev_1x/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/ModifiedHttpSolrClient.java

Propchange: manifoldcf/branches/dev_1x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Apr 14 23:10:25 2015
@@ -123,4 +123,4 @@
 /manifoldcf/branches/CONNECTORS-981:1605049-1605773
 /manifoldcf/branches/CONNECTORS-989:1611600-1612101
 /manifoldcf/branches/CONNECTORS-990:1610284-1610707
-/manifoldcf/trunk:1620703,1620748,1620812,1620862,1621449,1621613,1621855,1622213,1622740,1622850,1622853-1622854,1623249,1623251,1623314,1623599,1623951,1623953-1623954,1623956,1623972,1624058,1624085,1624174,1624236,1624377,1624384,1624399,1624449,1624464,1624504,1624729-1624731,1624906,1624909-1624910,1624982,1625023,1625095,1625103,1625108,1625264,1625270,1625394,1625400,1625910,1626090,1626097,1626102,1626638-1626639,1626973,1627687,1627690,1627959,1628046,1628066,1628106,1628168,1628188,1628699,1628798,1628808,1628845,1628905,1629122,1629374-1629375,1629379,1629541,1629994,1630188,1630535,1630623,1630671,1630812,1630885,1631039,1631162,1631164,1631252,1631750,1631953,1632013,1632225,1632289,1632562,1632844,1632847,1632854,1633062-1633063,1633108,1633193,1633202,1633282,1633284,1633295,1633336,1633339,1633345,1633348,1633364,1633378,1633383,1633432,1633546,1633590,1633634,1633668,1633727,1633760,1633764,1633786,1633910,1633923,1634021,1634028,1634067,1634132,1634145,1634148,163
 4155,1634188,1634202,1634264,1634373,1634530,1634688,1634850,1634857,1635103,1635116,1635421,1635438,1635478,1635481,1635484,1635490,1635809,1635939,1636146,1636167,1636180,1636207,1636215,1636232,1636334,1636519,1636570,1636684,1636940,1637011,1637310,1637350,1637364,1637373,1637378,1639259,1639593,1639600,1640018,1640101,1640199,1640204,1640208,1640314,1640319,1640749,1640772,1640805,1640888,1640925,1640941-1640942,1641222,1641328,1641557,1641559,1641629,1641633,1641724,1641754,1641911,1642163,1642255,1642318,1642531,1642650,1642658,1642673,1642716,1644197,1644399,1644538,1644920,1644931,1646317,1646397,1646403,1646408,1646640,1646947,1647574,1647585,1647608,1648686,1648976,1649201,1649203,1649529,1649605,1649628,1649794,1650351,1650722,1650741-1650742,1650745,1650747,1650911,1650954,1651332,1651539,1651907,1651921,1652071,1652974,1653175,1653899,1654651,1655205,1655261,1655264,1655377,1655411,1655618,1655914,1657346,1657443,1658004,1658036,1658121,1658155,1658188,1658463,1658476,
 1660258,1660276,1661454,1665848,1666160,1666781,1666820,1668312,1669100,1669238,1669487,1669523,1669586,1669660,1670614,1670625,1670715,1671496,1672169,1672301,1672616,1672737,1673559,1673573
+/manifoldcf/trunk:1620703,1620748,1620812,1620862,1621449,1621613,1621855,1622213,1622740,1622850,1622853-1622854,1623249,1623251,1623314,1623599,1623951,1623953-1623954,1623956,1623972,1624058,1624085,1624174,1624236,1624377,1624384,1624399,1624449,1624464,1624504,1624729-1624731,1624906,1624909-1624910,1624982,1625023,1625095,1625103,1625108,1625264,1625270,1625394,1625400,1625910,1626090,1626097,1626102,1626638-1626639,1626973,1627687,1627690,1627959,1628046,1628066,1628106,1628168,1628188,1628699,1628798,1628808,1628845,1628905,1629122,1629374-1629375,1629379,1629541,1629994,1630188,1630535,1630623,1630671,1630812,1630885,1631039,1631162,1631164,1631252,1631750,1631953,1632013,1632225,1632289,1632562,1632844,1632847,1632854,1633062-1633063,1633108,1633193,1633202,1633282,1633284,1633295,1633336,1633339,1633345,1633348,1633364,1633378,1633383,1633432,1633546,1633590,1633634,1633668,1633727,1633760,1633764,1633786,1633910,1633923,1634021,1634028,1634067,1634132,1634145,1634148,163
 4155,1634188,1634202,1634264,1634373,1634530,1634688,1634850,1634857,1635103,1635116,1635421,1635438,1635478,1635481,1635484,1635490,1635809,1635939,1636146,1636167,1636180,1636207,1636215,1636232,1636334,1636519,1636570,1636684,1636940,1637011,1637310,1637350,1637364,1637373,1637378,1639259,1639593,1639600,1640018,1640101,1640199,1640204,1640208,1640314,1640319,1640749,1640772,1640805,1640888,1640925,1640941-1640942,1641222,1641328,1641557,1641559,1641629,1641633,1641724,1641754,1641911,1642163,1642255,1642318,1642531,1642650,1642658,1642673,1642716,1644197,1644399,1644538,1644920,1644931,1646317,1646397,1646403,1646408,1646640,1646947,1647574,1647585,1647608,1648686,1648976,1649201,1649203,1649529,1649605,1649628,1649794,1650351,1650722,1650741-1650742,1650745,1650747,1650911,1650954,1651332,1651539,1651907,1651921,1652071,1652974,1653175,1653899,1654651,1655205,1655261,1655264,1655377,1655411,1655618,1655914,1657346,1657443,1658004,1658036,1658121,1658155,1658188,1658463,1658476,
 1660258,1660276,1661454,1665848,1666160,1666781,1666820,1668312,1669100,1669238,1669487,1669523,1669586,1669660,1670614,1670625,1670715,1671496,1672169,1672301,1672616,1672737,1673559,1673573,1673579

Modified: manifoldcf/branches/dev_1x/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/HttpPoster.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/dev_1x/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/HttpPoster.java?rev=1673580&r1=1673579&r2=1673580&view=diff
==============================================================================
--- manifoldcf/branches/dev_1x/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/HttpPoster.java
(original)
+++ manifoldcf/branches/dev_1x/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/HttpPoster.java
Tue Apr 14 23:10:25 2015
@@ -53,9 +53,11 @@ import org.apache.solr.client.solrj.requ
 import org.apache.solr.client.solrj.request.UpdateRequest;
 import org.apache.solr.client.solrj.impl.XMLResponseParser;
 import org.apache.solr.common.util.ContentStreamBase;
+import org.apache.solr.client.solrj.SolrResponse;
 import org.apache.solr.client.solrj.response.SolrPingResponse;
 import org.apache.solr.client.solrj.response.UpdateResponse;
 import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.params.ModifiableSolrParams;
 import org.apache.solr.common.util.ContentStream;
 import org.apache.solr.common.SolrException;
@@ -1502,7 +1504,7 @@ public class HttpPoster
         // Do the operation!
         try
         {
-          SolrPingResponse response = new SolrPing(postStatusAction).process(solrServer);
+          SolrResponse response = new SolrPing(postStatusAction).process(solrServer);
         }
         catch (InterruptedIOException ioe)
         {
@@ -1597,14 +1599,17 @@ public class HttpPoster
   */
   protected static class SolrPing extends SolrRequest
   {
+    /** Request parameters. */
     private ModifiableSolrParams params;
     
-    public SolrPing()
-    {
-      super( METHOD.GET, "/admin/ping" );
+    /**
+     * Create a new SolrPing object.
+     */
+    public SolrPing() {
+      super(METHOD.GET, "/admin/ping");
       params = new ModifiableSolrParams();
     }
-
+    
     public SolrPing(String url)
     {
       super( METHOD.GET, url );
@@ -1617,19 +1622,60 @@ public class HttpPoster
     }
 
     @Override
-    public ModifiableSolrParams getParams() {
-      return params;
+    protected SolrPingResponse createResponse(SolrClient client) {
+      return new SolrPingResponse();
     }
 
     @Override
-    public SolrPingResponse process( SolrClient server ) throws SolrServerException, IOException

-    {
-      long startTime = System.currentTimeMillis();
-      SolrPingResponse res = new SolrPingResponse();
-      res.setResponse( server.request( this ) );
-      res.setElapsedTime( System.currentTimeMillis()-startTime );
-      return res;
+    public ModifiableSolrParams getParams() {
+      return params;
+    }
+    
+    /**
+     * Remove the action parameter from this request. This will result in the same
+     * behavior as {@code SolrPing#setActionPing()}. For Solr server version 4.0
+     * and later.
+     * 
+     * @return this
+     */
+    public SolrPing removeAction() {
+      params.remove(CommonParams.ACTION);
+      return this;
+    }
+    
+    /**
+     * Set the action parameter on this request to enable. This will delete the
+     * health-check file for the Solr core. For Solr server version 4.0 and later.
+     * 
+     * @return this
+     */
+    public SolrPing setActionDisable() {
+      params.set(CommonParams.ACTION, CommonParams.DISABLE);
+      return this;
     }
+    
+    /**
+     * Set the action parameter on this request to enable. This will create the
+     * health-check file for the Solr core. For Solr server version 4.0 and later.
+     * 
+     * @return this
+     */
+    public SolrPing setActionEnable() {
+      params.set(CommonParams.ACTION, CommonParams.ENABLE);
+      return this;
+    }
+    
+    /**
+     * Set the action parameter on this request to ping. This is the same as not
+     * including the action at all. For Solr server version 4.0 and later.
+     * 
+     * @return this
+     */
+    public SolrPing setActionPing() {
+      params.set(CommonParams.ACTION, CommonParams.PING);
+      return this;
+    }
+
   }
 
   /** See CONNECTORS-956.  Make a safe lucene field name from a possibly

Modified: manifoldcf/branches/dev_1x/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/ModifiedHttpSolrClient.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/dev_1x/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/ModifiedHttpSolrClient.java?rev=1673580&r1=1673579&r2=1673580&view=diff
==============================================================================
--- manifoldcf/branches/dev_1x/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/ModifiedHttpSolrClient.java
(original)
+++ manifoldcf/branches/dev_1x/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/ModifiedHttpSolrClient.java
Tue Apr 14 23:10:25 2015
@@ -95,7 +95,6 @@ public class ModifiedHttpSolrClient exte
 
   
   private final HttpClient httpClient;
-  private int maxRetries = 0;
   private boolean useMultiPartPost = true;
 
   public ModifiedHttpSolrClient(String baseURL, HttpClient client, ResponseParser parser)
{
@@ -104,9 +103,8 @@ public class ModifiedHttpSolrClient exte
   }
   
   @Override
-  protected HttpRequestBase createMethod(final SolrRequest request) throws IOException, SolrServerException
{
-    HttpRequestBase method = null;
-    InputStream is = null;
+  protected HttpRequestBase createMethod(final SolrRequest request, String collection) throws
IOException, SolrServerException {
+    
     SolrParams params = request.getParams();
     Collection<ContentStream> streams = requestWriter.getContentStreams(request);
     String path = requestWriter.getPath(request);
@@ -129,165 +127,139 @@ public class ModifiedHttpSolrClient exte
     if (invariantParams != null) {
       wparams.add(invariantParams);
     }
-    
-    int tries = maxRetries + 1;
-    try {
-      while( tries-- > 0 ) {
-        // Note: since we aren't do intermittent time keeping
-        // ourselves, the potential non-timeout latency could be as
-        // much as tries-times (plus scheduling effects) the given
-        // timeAllowed.
-        try {
-          if( SolrRequest.METHOD.GET == request.getMethod() ) {
-            if( streams != null ) {
-              throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "GET can't send
streams!" );
-            }
-            method = new HttpGet( baseUrl + path + toQueryString( wparams, false ) );
-          }
-          else if( SolrRequest.METHOD.POST == request.getMethod() || SolrRequest.METHOD.PUT
== request.getMethod() ) {
 
-            String url = baseUrl + path;
-            boolean hasNullStreamName = false;
-            if (streams != null) {
-              for (ContentStream cs : streams) {
-                if (cs.getName() == null) {
-                  hasNullStreamName = true;
-                  break;
-                }
-              }
-            }
-            boolean isMultipart = ((this.useMultiPartPost && SolrRequest.METHOD.POST
== request.getMethod())
-              || ( streams != null && streams.size() > 1 )) && !hasNullStreamName;
-            
-            LinkedList<NameValuePair> postOrPutParams = new LinkedList<>();
-            if (streams == null || isMultipart) {
-              // send server list and request list as query string params
-              ModifiableSolrParams queryParams = calculateQueryParams(getQueryParams(), wparams);
-              queryParams.add(calculateQueryParams(request.getQueryParams(), wparams));
-              String fullQueryUrl = url + toQueryString( queryParams, false );
-              HttpEntityEnclosingRequestBase postOrPut = SolrRequest.METHOD.POST == request.getMethod()
?
-                new HttpPost(fullQueryUrl) : new HttpPut(fullQueryUrl);
-              if (!isMultipart) {
-                postOrPut.addHeader("Content-Type",
-                    "application/x-www-form-urlencoded; charset=UTF-8");
-              }
+    String basePath = baseUrl;
+    if (collection != null)
+      basePath += "/" + collection;
+
+    if (SolrRequest.METHOD.GET == request.getMethod()) {
+      if (streams != null) {
+        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "GET can't send streams!");
+      }
+      return new HttpGet(basePath + path + toQueryString(wparams, false));
+    }
 
-              List<FormBodyPart> parts = new LinkedList<>();
-              Iterator<String> iter = wparams.getParameterNamesIterator();
-              while (iter.hasNext()) {
-                String p = iter.next();
-                String[] vals = wparams.getParams(p);
-                if (vals != null) {
-                  for (String v : vals) {
-                    if (isMultipart) {
-                      parts.add(new FormBodyPart(p, new StringBody(v, StandardCharsets.UTF_8)));
-                    } else {
-                      postOrPutParams.add(new BasicNameValuePair(p, v));
-                    }
-                  }
-                }
-              }
+    if (SolrRequest.METHOD.POST == request.getMethod() || SolrRequest.METHOD.PUT == request.getMethod())
{
 
-              if (isMultipart && streams != null) {
-                for (ContentStream content : streams) {
-                  String contentType = content.getContentType();
-                  if(contentType==null) {
-                    contentType = BinaryResponseParser.BINARY_CONTENT_TYPE; // default
-                  }
-                  String name = content.getName();
-                  if(name==null) {
-                    name = "";
-                  }
-                  parts.add(new FormBodyPart(name, 
-                       new InputStreamBody(
-                           content.getStream(), 
-                           contentType, 
-                           content.getName())));
-                }
-              }
-              
-              if (parts.size() > 0) {
-                ModifiedMultipartEntity entity = new ModifiedMultipartEntity(HttpMultipartMode.STRICT,
null, StandardCharsets.UTF_8);
-                //MultipartEntity entity = new MultipartEntity(HttpMultipartMode.STRICT);
-                for(FormBodyPart p: parts) {
-                  entity.addPart(p);
-                }
-                postOrPut.setEntity(entity);
-              } else {
-                //not using multipart
-                postOrPut.setEntity(new UrlEncodedFormEntity(postOrPutParams, StandardCharsets.UTF_8));
-              }
+      String url = basePath + path;
+      boolean hasNullStreamName = false;
+      if (streams != null) {
+        for (ContentStream cs : streams) {
+          if (cs.getName() == null) {
+            hasNullStreamName = true;
+            break;
+          }
+        }
+      }
+      boolean isMultipart = ((this.useMultiPartPost && SolrRequest.METHOD.POST ==
request.getMethod())
+          || (streams != null && streams.size() > 1)) && !hasNullStreamName;
 
-              method = postOrPut;
-            }
-            // It is has one stream, it is the post body, put the params in the URL
-            else {
-              String pstr = toQueryString(wparams, false);
-              HttpEntityEnclosingRequestBase postOrPut = SolrRequest.METHOD.POST == request.getMethod()
?
-                new HttpPost(url + pstr) : new HttpPut(url + pstr);
-
-              // Single stream as body
-              // Using a loop just to get the first one
-              final ContentStream[] contentStream = new ContentStream[1];
-              for (ContentStream content : streams) {
-                contentStream[0] = content;
-                break;
-              }
-              if (contentStream[0] instanceof RequestWriter.LazyContentStream) {
-                postOrPut.setEntity(new InputStreamEntity(contentStream[0].getStream(), -1)
{
-                  @Override
-                  public Header getContentType() {
-                    return new BasicHeader("Content-Type", contentStream[0].getContentType());
-                  }
-                  
-                  @Override
-                  public boolean isRepeatable() {
-                    return false;
-                  }
-                  
-                });
+      LinkedList<NameValuePair> postOrPutParams = new LinkedList<>();
+      if (streams == null || isMultipart) {
+        // send server list and request list as query string params
+        ModifiableSolrParams queryParams = calculateQueryParams(getQueryParams(), wparams);
+        queryParams.add(calculateQueryParams(request.getQueryParams(), wparams));
+        String fullQueryUrl = url + toQueryString(queryParams, false);
+        HttpEntityEnclosingRequestBase postOrPut = SolrRequest.METHOD.POST == request.getMethod()
?
+            new HttpPost(fullQueryUrl) : new HttpPut(fullQueryUrl);
+        if (!isMultipart) {
+          postOrPut.addHeader("Content-Type",
+              "application/x-www-form-urlencoded; charset=UTF-8");
+        }
+
+        List<FormBodyPart> parts = new LinkedList<>();
+        Iterator<String> iter = wparams.getParameterNamesIterator();
+        while (iter.hasNext()) {
+          String p = iter.next();
+          String[] vals = wparams.getParams(p);
+          if (vals != null) {
+            for (String v : vals) {
+              if (isMultipart) {
+                parts.add(new FormBodyPart(p, new StringBody(v, StandardCharsets.UTF_8)));
               } else {
-                postOrPut.setEntity(new InputStreamEntity(contentStream[0].getStream(), -1)
{
-                  @Override
-                  public Header getContentType() {
-                    return new BasicHeader("Content-Type", contentStream[0].getContentType());
-                  }
-                  
-                  @Override
-                  public boolean isRepeatable() {
-                    return false;
-                  }
-                });
+                postOrPutParams.add(new BasicNameValuePair(p, v));
               }
-              method = postOrPut;
             }
           }
-          else {
-            throw new SolrServerException("Unsupported method: "+request.getMethod() );
-          }
         }
-        catch( NoHttpResponseException r ) {
-          method = null;
-          if(is != null) {
-            is.close();
+
+        if (isMultipart && streams != null) {
+          for (ContentStream content : streams) {
+            String contentType = content.getContentType();
+            if (contentType == null) {
+              contentType = BinaryResponseParser.BINARY_CONTENT_TYPE; // default
+            }
+            String name = content.getName();
+            if (name == null) {
+              name = "";
+            }
+            parts.add(new FormBodyPart(name,
+                new InputStreamBody(
+                    content.getStream(),
+                    contentType,
+                    content.getName())));
           }
-          // If out of tries then just rethrow (as normal error).
-          if (tries < 1) {
-            throw r;
+        }
+
+        if (parts.size() > 0) {
+          ModifiedMultipartEntity entity = new ModifiedMultipartEntity(HttpMultipartMode.STRICT,
null, StandardCharsets.UTF_8);
+          //MultipartEntity entity = new MultipartEntity(HttpMultipartMode.STRICT);
+          for (FormBodyPart p : parts) {
+            entity.addPart(p);
           }
+          postOrPut.setEntity(entity);
+        } else {
+          //not using multipart
+          postOrPut.setEntity(new UrlEncodedFormEntity(postOrPutParams, StandardCharsets.UTF_8));
+        }
+
+        return postOrPut;
+      }
+      // It is has one stream, it is the post body, put the params in the URL
+      else {
+        String pstr = toQueryString(wparams, false);
+        HttpEntityEnclosingRequestBase postOrPut = SolrRequest.METHOD.POST == request.getMethod()
?
+            new HttpPost(url + pstr) : new HttpPut(url + pstr);
+
+        // Single stream as body
+        // Using a loop just to get the first one
+        final ContentStream[] contentStream = new ContentStream[1];
+        for (ContentStream content : streams) {
+          contentStream[0] = content;
+          break;
+        }
+        if (contentStream[0] instanceof RequestWriter.LazyContentStream) {
+          postOrPut.setEntity(new InputStreamEntity(contentStream[0].getStream(), -1) {
+            @Override
+            public Header getContentType() {
+              return new BasicHeader("Content-Type", contentStream[0].getContentType());
+            }
+
+            @Override
+            public boolean isRepeatable() {
+              return false;
+            }
+
+          });
+        } else {
+          postOrPut.setEntity(new InputStreamEntity(contentStream[0].getStream(), -1) {
+            @Override
+            public Header getContentType() {
+              return new BasicHeader("Content-Type", contentStream[0].getContentType());
+            }
+
+            @Override
+            public boolean isRepeatable() {
+              return false;
+            }
+          });
         }
+        return postOrPut;
       }
-    } catch (IOException ex) {
-      throw new SolrServerException("error reading streams", ex);
     }
-    
-    return method;
-  }
 
-  @Override
-  public void setMaxRetries(int maxRetries) {
-    super.setMaxRetries(maxRetries);
-    this.maxRetries = maxRetries;
+    throw new SolrServerException("Unsupported method: " + request.getMethod());
+
   }
 
   public static String toQueryString( SolrParams params, boolean xml ) {



Mime
View raw message