manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1673579 - in /manifoldcf/trunk/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr: HttpPoster.java ModifiedHttpSolrClient.java
Date Tue, 14 Apr 2015 23:09:46 GMT
Author: kwright
Date: Tue Apr 14 23:09:45 2015
New Revision: 1673579

URL: http://svn.apache.org/r1673579
Log:
Get things to build again due to Solr 5.1.0

Modified:
    manifoldcf/trunk/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/HttpPoster.java
    manifoldcf/trunk/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/ModifiedHttpSolrClient.java

Modified: manifoldcf/trunk/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/HttpPoster.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/HttpPoster.java?rev=1673579&r1=1673578&r2=1673579&view=diff
==============================================================================
--- manifoldcf/trunk/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/HttpPoster.java
(original)
+++ manifoldcf/trunk/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/HttpPoster.java
Tue Apr 14 23:09:45 2015
@@ -54,9 +54,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;
@@ -1441,7 +1443,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)
         {
@@ -1536,14 +1538,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 );
@@ -1556,19 +1561,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/trunk/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/ModifiedHttpSolrClient.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/ModifiedHttpSolrClient.java?rev=1673579&r1=1673578&r2=1673579&view=diff
==============================================================================
--- manifoldcf/trunk/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/ModifiedHttpSolrClient.java
(original)
+++ manifoldcf/trunk/connectors/solr/connector/src/main/java/org/apache/manifoldcf/agents/output/solr/ModifiedHttpSolrClient.java
Tue Apr 14 23:09:45 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