Author: yonik
Date: Thu Jan 24 21:18:16 2008
New Revision: 615112

URL: http://svn.apache.org/viewvc?rev=615112&view=rev
Log:
SOLR-457: SolrJ updates - allow client to pass HttpClient, change interfaces to 
classes, use InputStream for XML parser, make XML factory static

Added:
    
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/DirectXMLRequest.java
      - copied, changed from r615015, 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/DirectXmlRequest.java
    
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/LukeRequest.java
    
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/MultiCoreRequest.java
    
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/QueryRequest.java
    
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/UpdateRequest.java
Removed:
    
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/RequestBase.java
Modified:
    
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/ResponseParser.java
    
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/SolrRequest.java
    
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/SolrResponse.java
    
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java
    
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java
    
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/impl/XMLResponseParser.java
    
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/DirectXmlRequest.java
    
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/SolrPing.java
    
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/response/SolrResponseBase.java

Modified: 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/ResponseParser.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/ResponseParser.java?rev=615112&r1=615111&r2=615112&view=diff
==============================================================================
--- 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/ResponseParser.java
 (original)
+++ 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/ResponseParser.java
 Thu Jan 24 21:18:16 2008
@@ -18,6 +18,8 @@
 package org.apache.solr.client.solrj;
 
 import java.io.Reader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 
 import org.apache.solr.common.util.NamedList;
 
@@ -26,8 +28,11 @@
  * @version $Id$
  * @since solr 1.3
  */
-public interface ResponseParser 
+public abstract class ResponseParser
 {
-  String getWriterType(); // for example: wt=XML, JSON, etc
-  NamedList<Object> processResponse( Reader body );
+  public abstract String getWriterType(); // for example: wt=XML, JSON, etc
+
+  public abstract NamedList<Object> processResponse(InputStream body, String 
encoding);
+
+  public abstract NamedList<Object> processResponse(Reader reader);
 }

Modified: 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/SolrRequest.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/SolrRequest.java?rev=615112&r1=615111&r2=615112&view=diff
==============================================================================
--- 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/SolrRequest.java
 (original)
+++ 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/SolrRequest.java
 Thu Jan 24 21:18:16 2008
@@ -29,17 +29,53 @@
  * @version $Id$
  * @since solr 1.3
  */
-public interface SolrRequest extends Serializable
+public abstract class SolrRequest implements Serializable
 {
   public enum METHOD {
     GET,
     POST
   };
-  
-  public String getPath();
-  public String getCore();  // the name of requested core
-  public METHOD getMethod();
-  public SolrParams getParams();
-  public Collection<ContentStream> getContentStreams() throws IOException;
-  public SolrResponse process( SolrServer server ) throws SolrServerException, 
IOException;
+
+  private METHOD method = METHOD.GET;
+  private String path = null;
+  private String core = null;
+
+  //---------------------------------------------------------
+  //---------------------------------------------------------
+
+  public SolrRequest( METHOD m, String path )
+  {
+    this.method = m;
+    this.path = path;
+  }
+
+  //---------------------------------------------------------
+  //---------------------------------------------------------
+
+  public METHOD getMethod() {
+    return method;
+  }
+  public void setMethod(METHOD method) {
+    this.method = method;
+  }
+
+  public String getPath() {
+    return path;
+  }
+  public void setPath(String path) {
+    this.path = path;
+  }
+
+  public String getCore() {
+    return core;
+  }
+
+  public void setCore(String core) {
+    this.core = core;
+  }
+
+
+  public abstract SolrParams getParams();
+  public abstract Collection<ContentStream> getContentStreams() throws 
IOException;
+  public abstract SolrResponse process( SolrServer server ) throws 
SolrServerException, IOException;
 }

Modified: 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/SolrResponse.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/SolrResponse.java?rev=615112&r1=615111&r2=615112&view=diff
==============================================================================
--- 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/SolrResponse.java
 (original)
+++ 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/SolrResponse.java
 Thu Jan 24 21:18:16 2008
@@ -27,8 +27,8 @@
  * @version $Id$
  * @since solr 1.3
  */
-public interface SolrResponse extends Serializable
+public abstract class SolrResponse implements Serializable
 {
-  long getElapsedTime();
-  NamedList<Object> getResponse();
+  public abstract long getElapsedTime();
+  public abstract NamedList<Object> getResponse();
 }

Modified: 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java?rev=615112&r1=615111&r2=615112&view=diff
==============================================================================
--- 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java
 (original)
+++ 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java
 Thu Jan 24 21:18:16 2008
@@ -165,6 +165,7 @@
       QueryResponseWriter responseWriter = core.getQueryResponseWriter(req);
       StringWriter out = new StringWriter();
       responseWriter.write(out, req, rsp);
+      // TODO: writers might be able to output binary someday
       
       req.close();
       return _processor.processResponse( new StringReader( out.toString() ) );

Modified: 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java?rev=615112&r1=615111&r2=615112&view=diff
==============================================================================
--- 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java
 (original)
+++ 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java
 Thu Jan 24 21:18:16 2008
@@ -29,14 +29,7 @@
 import java.util.zip.GZIPInputStream;
 import java.util.zip.InflaterInputStream;
 
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.HttpMethodBase;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
-import org.apache.commons.httpclient.NoHttpResponseException;
+import org.apache.commons.httpclient.*;
 import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
 import org.apache.commons.httpclient.methods.PostMethod;
@@ -88,6 +81,15 @@
     this(new URL(solrServerUrl));
   }
 
+  /** Talk to the Solr server via the given HttpClient.  The connection manager
+   * for the client should be a MultiThreadedHttpConnectionManager if this
+   * client is being reused across SolrServer instances, or of multiple threads
+   * will use this SolrServer.
+   */
+  public CommonsHttpSolrServer(String solrServerUrl, HttpClient httpClient) 
throws MalformedURLException {
+    this(new URL(solrServerUrl), httpClient);
+  }
+
   /**
    * @param baseURL The URL of the Solr server.  For 
    * example, "<code>http://localhost:8983/solr/</code>"
@@ -96,17 +98,26 @@
    */
   public CommonsHttpSolrServer(URL baseURL) 
   {
+    this(baseURL, null);
+  }
+
+
+  private CommonsHttpSolrServer(URL baseURL, HttpClient client) {
     this._baseURL = baseURL.toExternalForm();
     if( this._baseURL.endsWith( "/" ) ) {
       this._baseURL = this._baseURL.substring( 0, this._baseURL.length()-1 );
     }
-    
-    this._httpClient = createHttpClient();
-    
-    // increase the default connections
-    this.setDefaultMaxConnectionsPerHost( 32 );  // 2
-    this.setMaxTotalConnections( 128 ); // 20
-    
+
+    _httpClient = (client == null) ? new HttpClient(new 
MultiThreadedHttpConnectionManager()) : client;
+
+    if (client == null) {
+      // set some better defaults if we created a new connection manager and 
client
+      
+      // increase the default connections
+      this.setDefaultMaxConnectionsPerHost( 32 );  // 2
+      this.setMaxTotalConnections( 128 ); // 20
+    }
+
     // by default use the XML one
     _processor = new XMLResponseParser();
 
@@ -115,14 +126,7 @@
     _invariantParams.set( CommonParams.WT, _processor.getWriterType() );
     _invariantParams.set( CommonParams.VERSION, "2.2" );
   }
-  
-  /**
-   * This can be overridden to add certificates etc
-   */
-  protected HttpClient createHttpClient()
-  {
-    return new HttpClient( new MultiThreadedHttpConnectionManager() );
-  }
+
 
   //------------------------------------------------------------------------
   //------------------------------------------------------------------------
@@ -320,8 +324,7 @@
           }
         }
       }
-      Reader reader = new InputStreamReader( respBody, charset ); 
-      return _processor.processResponse( reader );
+      return _processor.processResponse(respBody, charset);
     } 
     catch (HttpException e) {
       throw new SolrServerException( e );
@@ -362,11 +365,15 @@
     _processor = processor;
   }
 
-  public MultiThreadedHttpConnectionManager getConnectionManager() {
-    return 
(MultiThreadedHttpConnectionManager)_httpClient.getHttpConnectionManager();
+  public HttpClient getHttpClient() {
+    return _httpClient;
+  }
+
+  private HttpConnectionManager getConnectionManager() {
+    return _httpClient.getHttpConnectionManager();
   }
   
-  /** set connectionTimeout on the underlying 
MultiThreadedHttpConnectionManager */
+  /** set connectionTimeout on the underlying HttpConnectionManager */
   public void setConnectionTimeout(int timeout) {
     getConnectionManager().getParams().setConnectionTimeout(timeout);
   }
@@ -376,17 +383,17 @@
     _httpClient.getParams().setConnectionManagerTimeout(timeout);
   }
   
-  /** set soTimeout (read timeout) on the underlying 
MultiThreadedHttpConnectionManager.  This is desirable for queries, but 
probably not for indexing. */
+  /** set soTimeout (read timeout) on the underlying HttpConnectionManager.  
This is desirable for queries, but probably not for indexing. */
   public void setSoTimeout(int timeout) {
     getConnectionManager().getParams().setSoTimeout(timeout);
   }
   
-  /** set maxConnectionsPerHost on the underlying 
MultiThreadedHttpConnectionManager */
+  /** set maxConnectionsPerHost on the underlying HttpConnectionManager */
   public void setDefaultMaxConnectionsPerHost(int connections) {
     
getConnectionManager().getParams().setDefaultMaxConnectionsPerHost(connections);
   }
   
-  /** set maxTotalConnection on the underlying 
MultiThreadedHttpConnectionManager */
+  /** set maxTotalConnection on the underlying HttpConnectionManager */
   public void setMaxTotalConnections(int connections) {
     getConnectionManager().getParams().setMaxTotalConnections(connections);
   }

Modified: 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/impl/XMLResponseParser.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/impl/XMLResponseParser.java?rev=615112&r1=615111&r2=615112&view=diff
==============================================================================
--- 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/impl/XMLResponseParser.java
 (original)
+++ 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/impl/XMLResponseParser.java
 Thu Jan 24 21:18:16 2008
@@ -18,6 +18,7 @@
 package org.apache.solr.client.solrj.impl;
 
 import java.io.Reader;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -40,14 +41,14 @@
  * @version $Id$
  * @since solr 1.3
  */
-public class XMLResponseParser implements ResponseParser
+public class XMLResponseParser extends ResponseParser
 {
   public static Logger log = 
Logger.getLogger(XMLResponseParser.class.getName());
-  
-  XMLInputFactory factory;
-  
-  public XMLResponseParser()
-  {
+
+  // reuse the factory among all parser instances so things like string caches
+  // won't be duplicated
+  static final XMLInputFactory factory;
+  static {
     factory = XMLInputFactory.newInstance();
     try {
       // The java 1.6 bundled stax parser (sjsxp) does not currently have a 
thread-safe
@@ -64,25 +65,43 @@
       log.fine( "Unable to set the 'reuse-instance' property for the input 
factory: "+factory );
     }
   }
+
+  public XMLResponseParser() {}
   
   public String getWriterType()
   {
     return "xml";
   }
 
+  public NamedList<Object> processResponse(Reader in) {
+    XMLStreamReader parser = null;
+    try {
+      parser = factory.createXMLStreamReader(in);
+    } catch (XMLStreamException e) {
+      throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "parsing 
error", e);
+    }
+
+    return processResponse(parser);    
+  }
+
+  public NamedList<Object> processResponse(InputStream in, String encoding)
+  {
+     XMLStreamReader parser = null;
+    try {
+      parser = factory.createXMLStreamReader(in, encoding);
+    } catch (XMLStreamException e) {
+      throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "parsing 
error", e);
+    }
+
+    return processResponse(parser);
+  }
+
   /**
    * parse the text into a named list...
    */
-  public NamedList<Object> processResponse( Reader in )
+  private NamedList<Object> processResponse(XMLStreamReader parser)
   {
-    XMLStreamReader parser = null;
-    try { 
-//      String txt = IOUtils.toString( in );
-//      in = new StringReader( txt );
-//      System.out.println( "TEXT:"+txt );
-      
-      parser = factory.createXMLStreamReader(in);
-      
+    try {
       NamedList<Object> response = null;
       for (int event = parser.next();  
        event != XMLStreamConstants.END_DOCUMENT;

Copied: 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/DirectXMLRequest.java
 (from r615015, 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/DirectXmlRequest.java)
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/DirectXMLRequest.java?p2=lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/DirectXMLRequest.java&p1=lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/DirectXmlRequest.java&r1=615015&r2=615112&rev=615112&view=diff
==============================================================================
--- 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/DirectXmlRequest.java
 (original)
+++ 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/DirectXMLRequest.java
 Thu Jan 24 21:18:16 2008
@@ -22,6 +22,7 @@
 
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.SolrRequest;
 import org.apache.solr.client.solrj.response.UpdateResponse;
 import org.apache.solr.client.solrj.util.ClientUtils;
 import org.apache.solr.common.params.SolrParams;
@@ -33,7 +34,7 @@
  * @version $Id$
  * @since solr 1.3
  */
-public class DirectXmlRequest extends RequestBase
+public class DirectXmlRequest extends SolrRequest
 {
   final String xml;
   

Modified: 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/DirectXmlRequest.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/DirectXmlRequest.java?rev=615112&r1=615111&r2=615112&view=diff
==============================================================================
--- 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/DirectXmlRequest.java
 (original)
+++ 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/DirectXmlRequest.java
 Thu Jan 24 21:18:16 2008
@@ -22,6 +22,7 @@
 
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.SolrRequest;
 import org.apache.solr.client.solrj.response.UpdateResponse;
 import org.apache.solr.client.solrj.util.ClientUtils;
 import org.apache.solr.common.params.SolrParams;
@@ -33,7 +34,7 @@
  * @version $Id$
  * @since solr 1.3
  */
-public class DirectXmlRequest extends RequestBase
+public class DirectXmlRequest extends SolrRequest
 {
   final String xml;
   

Added: 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/LukeRequest.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/LukeRequest.java?rev=615112&view=auto
==============================================================================
--- 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/LukeRequest.java
 (added)
+++ 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/LukeRequest.java
 Thu Jan 24 21:18:16 2008
@@ -0,0 +1,103 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.client.solrj.request;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.solr.client.solrj.SolrServer;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.response.LukeResponse;
+import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.ContentStream;
+
+/**
+ * 
+ * @version $Id$
+ * @since solr 1.3
+ */
+public class LukeRequest extends SolrRequest
+{
+  private List<String> fields;
+  private int count = -1;
+  private boolean showSchema = false;
+  
+  public LukeRequest()
+  {
+    super( METHOD.GET, "/admin/luke" );
+  }
+
+  public LukeRequest( String path )
+  {
+    super( METHOD.GET, path );
+  }
+
+  
//---------------------------------------------------------------------------------
+  
//---------------------------------------------------------------------------------
+  
+  public void addField( String f )
+  {
+    if( fields == null ) {
+      fields = new ArrayList<String>();
+    }
+    fields.add( f );
+  }
+  
+  
//---------------------------------------------------------------------------------
+  
//---------------------------------------------------------------------------------
+  
+  public boolean isShowSchema() {
+    return showSchema;
+  }
+
+  public void setShowSchema(boolean showSchema) {
+    this.showSchema = showSchema;
+  }
+
+  public Collection<ContentStream> getContentStreams() {
+    return null;
+  }
+
+  public SolrParams getParams() {
+    ModifiableSolrParams params = new ModifiableSolrParams();
+    if( fields != null && fields.size() > 0 ) {
+      params.add( CommonParams.FL, fields.toArray( new String[fields.size()] ) 
);
+    }
+    if( count >= 0 ) {
+      params.add( "count", count+"" );
+    }
+    if (showSchema) {
+       params.add("show", "schema");
+    }
+    return params;
+  }
+
+  public LukeResponse process( SolrServer server ) throws SolrServerException, 
IOException 
+  {
+    long startTime = System.currentTimeMillis();
+    LukeResponse res = new LukeResponse( server.request( this ) );
+    res.setElapsedTime( System.currentTimeMillis()-startTime );
+    return res;
+  }
+}
+

Added: 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/MultiCoreRequest.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/MultiCoreRequest.java?rev=615112&view=auto
==============================================================================
--- 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/MultiCoreRequest.java
 (added)
+++ 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/MultiCoreRequest.java
 Thu Jan 24 21:18:16 2008
@@ -0,0 +1,130 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.client.solrj.request;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import org.apache.solr.client.solrj.SolrServer;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.response.MultiCoreResponse;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.MultiCoreParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.params.MultiCoreParams.MultiCoreAction;
+import org.apache.solr.common.util.ContentStream;
+
+/**
+ * 
+ * @version $Id$
+ * @since solr 1.3
+ */
+public class MultiCoreRequest extends SolrRequest
+{
+  private MultiCoreParams.MultiCoreAction action = null;
+  private String core = null;
+  
+  public MultiCoreRequest()
+  {
+    super( METHOD.GET, "/admin/multicore" );
+  }
+
+  public MultiCoreRequest( String path )
+  {
+    super( METHOD.GET, path );
+  }
+
+  public final void setCoreParam( String v )
+  {
+    this.core = v;
+  }
+
+  @Override
+  public final void setCore( String v )
+  {
+    throw new UnsupportedOperationException( "MultiCoreRequest does not use a 
core.");
+  }
+  
+  @Override
+  public final String getCore()
+  {
+    return ""; // force it to invalid core
+  }
+  
+  
//---------------------------------------------------------------------------------------
+  //
+  
//---------------------------------------------------------------------------------------
+
+  public void setAction( MultiCoreAction action )
+  {
+    this.action = action;
+  }
+
+  
//---------------------------------------------------------------------------------------
+  //
+  
//---------------------------------------------------------------------------------------
+
+  public SolrParams getParams() 
+  {
+    if( action == null ) {
+      throw new RuntimeException( "no action specified!" );
+    }
+    ModifiableSolrParams params = new ModifiableSolrParams();
+    params.set( MultiCoreParams.ACTION, action.toString() );
+    params.set( MultiCoreParams.CORE, core );
+    return params;
+  }
+
+  
//---------------------------------------------------------------------------------------
+  //
+  
//---------------------------------------------------------------------------------------
+
+  public Collection<ContentStream> getContentStreams() throws IOException {
+    return null;
+  }
+  
+  public MultiCoreResponse process(SolrServer server) throws 
SolrServerException, IOException 
+  {
+    long startTime = System.currentTimeMillis();
+    MultiCoreResponse res = new MultiCoreResponse( server.request( this ) );
+    res.setElapsedTime( System.currentTimeMillis()-startTime );
+    return res;
+  }
+
+  
//---------------------------------------------------------------------------------------
+  //
+  
//---------------------------------------------------------------------------------------
+
+  public static MultiCoreResponse reloadCore( String name, SolrServer server ) 
throws SolrServerException, IOException
+  {
+    MultiCoreRequest req = new MultiCoreRequest();
+    req.setCoreParam( name );
+    req.setAction( MultiCoreAction.RELOAD );
+    return req.process( server );
+  }
+
+  public static MultiCoreResponse getStatus( String name, SolrServer server ) 
throws SolrServerException, IOException
+  {
+    MultiCoreRequest req = new MultiCoreRequest();
+    req.setCoreParam( name );
+    req.setAction( MultiCoreAction.STATUS );
+    return req.process( server );
+  }
+}
+

Added: 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/QueryRequest.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/QueryRequest.java?rev=615112&view=auto
==============================================================================
--- 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/QueryRequest.java
 (added)
+++ 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/QueryRequest.java
 Thu Jan 24 21:18:16 2008
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.client.solrj.request;
+
+import java.util.Collection;
+
+import org.apache.solr.client.solrj.SolrServer;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.ContentStream;
+
+/**
+ * 
+ * @version $Id$
+ * @since solr 1.3
+ */
+public class QueryRequest extends SolrRequest
+{
+  private SolrParams query;
+  
+  public QueryRequest()
+  {
+    super( METHOD.GET, null );
+  }
+
+  public QueryRequest( SolrParams q )
+  {
+    super( METHOD.GET, null );
+    query = q;
+  }
+
+  /**
+   * Use the params 'QT' parameter if it exists
+   */
+  @Override
+  public String getPath() {
+    String qt = query.get( CommonParams.QT );
+    if( qt == null ) {
+      qt = super.getPath();
+    }
+    if( qt != null && qt.startsWith( "/" ) ) {
+      return qt;
+    }
+    return "/select";
+  }
+  
+  
//---------------------------------------------------------------------------------
+  
//---------------------------------------------------------------------------------
+  
+  public Collection<ContentStream> getContentStreams() {
+    return null;
+  }
+
+  public SolrParams getParams() {
+    return query;
+  }
+
+  public QueryResponse process( SolrServer server ) throws SolrServerException 
+  {
+    try 
+    {
+      long startTime = System.currentTimeMillis();
+      QueryResponse res = new QueryResponse( server.request( this ) );
+      res.setElapsedTime( System.currentTimeMillis()-startTime );
+      return res;
+    } 
+    catch (Exception e) 
+    {
+      throw new SolrServerException("Error executing query", e);
+    }
+  }
+}
+

Modified: 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/SolrPing.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/SolrPing.java?rev=615112&r1=615111&r2=615112&view=diff
==============================================================================
--- 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/SolrPing.java
 (original)
+++ 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/SolrPing.java
 Thu Jan 24 21:18:16 2008
@@ -22,9 +22,9 @@
 
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.SolrRequest;
 import org.apache.solr.client.solrj.response.SolrPingResponse;
 import org.apache.solr.common.params.ModifiableSolrParams;
-import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.util.ContentStream;
 
 /**
@@ -32,7 +32,7 @@
  * @version $Id$
  * @since solr 1.3
  */
-public class SolrPing extends RequestBase
+public class SolrPing extends SolrRequest
 {
   private ModifiableSolrParams params;
   

Added: 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/UpdateRequest.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/UpdateRequest.java?rev=615112&view=auto
==============================================================================
--- 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/UpdateRequest.java
 (added)
+++ 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/UpdateRequest.java
 Thu Jan 24 21:18:16 2008
@@ -0,0 +1,281 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.client.solrj.request;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.solr.client.solrj.SolrServer;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.response.UpdateResponse;
+import org.apache.solr.client.solrj.util.ClientUtils;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.params.UpdateParams;
+import org.apache.solr.common.util.ContentStream;
+import org.apache.solr.common.util.XML;
+
+/**
+ * 
+ * @version $Id$
+ * @since solr 1.3
+ */
+public class UpdateRequest extends SolrRequest
+{
+  public enum ACTION {
+    COMMIT,
+    OPTIMIZE
+  };
+  
+  private boolean waitFlush = true;
+  private boolean waitSearcher = true;
+  private boolean allowDups = false;
+  private boolean overwriteCommitted = true;
+  private boolean overwritePending = true;
+  private ACTION action = null;
+  
+  private List<SolrInputDocument> documents = null;
+  private List<String> deleteById = null;
+  private List<String> deleteQuery = null;
+  
+  public UpdateRequest()
+  {
+    super( METHOD.POST, "/update" );
+  }
+
+  //---------------------------------------------------------------------------
+  //---------------------------------------------------------------------------
+  
+  /**
+   * clear the pending documents and delete commands
+   */
+  public void clear()
+  {
+    if( documents != null ) {
+      documents.clear();
+    }
+    if( deleteById != null ) {
+      deleteById.clear();
+    }
+    if( deleteQuery != null ) {
+      deleteQuery.clear();
+    }
+  }
+  
+  //---------------------------------------------------------------------------
+  //---------------------------------------------------------------------------
+  
+  public UpdateRequest add( final SolrInputDocument doc )
+  {
+    if( documents == null ) {
+      documents = new ArrayList<SolrInputDocument>( 2 );
+    }
+    documents.add( doc );
+    return this;
+  }
+  
+  public UpdateRequest add( final Collection<SolrInputDocument> docs )
+  {
+    if( documents == null ) {
+      documents = new ArrayList<SolrInputDocument>( docs.size()+1 );
+    }
+    documents.addAll( docs );
+    return this;
+  }
+  
+  public UpdateRequest deleteById( String id )
+  {
+    if( deleteById == null ) {
+      deleteById = new ArrayList<String>();
+    }
+    deleteById.add( id );
+    return this;
+  }
+  
+  public UpdateRequest deleteByQuery( String q )
+  {
+    if( deleteQuery == null ) {
+      deleteQuery = new ArrayList<String>();
+    }
+    deleteQuery.add( q );
+    return this;
+  }
+
+  public UpdateRequest setAction(ACTION action, boolean waitFlush, boolean 
waitSearcher ) {
+    this.action = action;
+    this.waitFlush = waitFlush;
+    this.waitSearcher = waitSearcher;
+    return this;
+  }
+
+  //--------------------------------------------------------------------------
+  //--------------------------------------------------------------------------
+
+  public Collection<ContentStream> getContentStreams() throws IOException {
+    return ClientUtils.toContentStreams( getXML(), ClientUtils.TEXT_XML );
+  }
+  
+  public String getXML() throws IOException {
+    StringWriter writer = new StringWriter();
+    if( documents != null && documents.size() > 0 ) {
+      writer.write("<add ");
+      writer.write("allowDups=\"" + allowDups + "\" ");
+      // TODO: remove these when deprecations are removed
+      writer.write("overwriteCommitted=\"" + overwriteCommitted + "\" ");
+      writer.write("overwritePending=\"" + overwritePending + "\">");
+      for (SolrInputDocument doc : documents ) {
+        if( doc != null ) {
+          ClientUtils.writeXML( doc, writer );
+        }
+      }
+      writer.write("</add>");
+    }
+    
+    // Add the delete commands
+    boolean deleteI = deleteById != null && deleteById.size() > 0;
+    boolean deleteQ = deleteQuery != null && deleteQuery.size() > 0;
+    if( deleteI || deleteQ ) {
+      writer.append( "<delete>" );
+      if( deleteI ) {
+        for( String id : deleteById ) {
+          writer.append( "<id>" );
+          XML.escapeCharData( id, writer );
+          writer.append( "</id>" );
+        }
+      }
+      if( deleteQ ) {
+        for( String q : deleteQuery ) {
+          writer.append( "<query>" );
+          XML.escapeCharData( q, writer );
+          writer.append( "</query>" );
+        }
+      }
+      writer.append( "</delete>" );
+    }
+    
+    // If action is COMMIT or OPTIMIZE, it is sent with params
+    String xml = writer.toString();
+    //System.out.println( "SEND:"+xml );
+    return (xml.length() > 0) ? xml : null;
+  }
+
+  //--------------------------------------------------------------------------
+  //--------------------------------------------------------------------------
+
+  public SolrParams getParams() {
+    if( action != null ) {
+      ModifiableSolrParams params = new ModifiableSolrParams();
+      if( action == ACTION.OPTIMIZE ) {
+        params.set( UpdateParams.OPTIMIZE, "true" );
+      }
+      else if( action == ACTION.COMMIT ) {
+        params.set( UpdateParams.COMMIT, "true" );
+      }
+      params.set( UpdateParams.WAIT_FLUSH, waitFlush+"" );
+      params.set( UpdateParams.WAIT_SEARCHER, waitSearcher+"" );
+      return params;
+    }
+    return null; 
+  }
+  
+  public UpdateResponse process( SolrServer server ) throws 
SolrServerException, IOException
+  {
+    long startTime = System.currentTimeMillis();
+    UpdateResponse res = new UpdateResponse( server.request( this ) );
+    res.setElapsedTime( System.currentTimeMillis()-startTime );
+    return res;
+  }
+
+  //--------------------------------------------------------------------------
+  // 
+  //--------------------------------------------------------------------------
+
+  public void setOverwrite( boolean v )
+  {
+    allowDups = !v;
+    overwriteCommitted = v;
+    overwritePending = v;
+  }
+  
+  //--------------------------------------------------------------------------
+  // 
+  //--------------------------------------------------------------------------
+
+  public boolean isWaitFlush() {
+    return waitFlush;
+  }
+
+  public boolean isWaitSearcher() {
+    return waitSearcher;
+  }
+
+  public ACTION getAction() {
+    return action;
+  }
+
+  public boolean isAllowDups() {
+    return allowDups;
+  }
+
+  /**
+   * Use setOverwrite()
+   */
+  @Deprecated
+  public void setAllowDups(boolean allowDups) {
+    this.allowDups = allowDups;
+  }
+
+  @Deprecated
+  public boolean isOverwriteCommitted() {
+    return overwriteCommitted;
+  }
+
+  /**
+   * Use setOverwrite()
+   */
+  @Deprecated
+  public void setOverwriteCommitted(boolean overwriteCommitted) {
+    this.overwriteCommitted = overwriteCommitted;
+  }
+
+  @Deprecated
+  public boolean isOverwritePending() {
+    return overwritePending;
+  }
+
+  /**
+   * Use setOverwrite()
+   */
+  @Deprecated
+  public void setOverwritePending(boolean overwritePending) {
+    this.overwritePending = overwritePending;
+  }
+
+  public void setWaitFlush(boolean waitFlush) {
+    this.waitFlush = waitFlush;
+  }
+
+  public void setWaitSearcher(boolean waitSearcher) {
+    this.waitSearcher = waitSearcher;
+  }
+}

Modified: 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/response/SolrResponseBase.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/response/SolrResponseBase.java?rev=615112&r1=615111&r2=615112&view=diff
==============================================================================
--- 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/response/SolrResponseBase.java
 (original)
+++ 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/response/SolrResponseBase.java
 Thu Jan 24 21:18:16 2008
@@ -25,7 +25,7 @@
  * @version $Id$
  * @since solr 1.3
  */
-public abstract class SolrResponseBase implements SolrResponse
+public abstract class SolrResponseBase extends SolrResponse
 {
   private long elapsedTime = -1;
   private NamedList<Object> response = null;


Reply via email to