This is an automated email from the ASF dual-hosted git repository.
dsmiley pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new 0c8dcb806d6 New SolrJ CollectionScopedSolrClient (#4418)
0c8dcb806d6 is described below
commit 0c8dcb806d6b4c1b590d04cb8e3b5cea3f5edba7
Author: David Smiley <[email protected]>
AuthorDate: Sun May 17 11:27:51 2026 -0400
New SolrJ CollectionScopedSolrClient (#4418)
---
.../unreleased/CollectionScopedSolrClient.yml | 7 +++
.../solrj/impl/CollectionScopedSolrClient.java | 61 ++++++++++++++++++++++
2 files changed, 68 insertions(+)
diff --git a/changelog/unreleased/CollectionScopedSolrClient.yml
b/changelog/unreleased/CollectionScopedSolrClient.yml
new file mode 100644
index 00000000000..9bd6b677d82
--- /dev/null
+++ b/changelog/unreleased/CollectionScopedSolrClient.yml
@@ -0,0 +1,7 @@
+title: New SolrJ CollectionScopedSolrClient
+type: added
+authors:
+ - name: David Smiley
+links:
+ - name: PR#4418
+ url: https://github.com/apache/solr/pull/4418
diff --git
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CollectionScopedSolrClient.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CollectionScopedSolrClient.java
new file mode 100644
index 00000000000..5b0b4ee86ce
--- /dev/null
+++
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CollectionScopedSolrClient.java
@@ -0,0 +1,61 @@
+/*
+ * 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.impl;
+
+import java.io.IOException;
+import java.util.Objects;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.common.util.NamedList;
+
+/**
+ * This SolrClient delegates to a backing client with a specified collection.
Simple attempts to
+ * refer to another collection will fail. DISCLAIMER: this isn't a security
mechanism.
+ */
+public class CollectionScopedSolrClient extends SolrClient {
+
+ private final SolrClient delegate;
+
+ public CollectionScopedSolrClient(SolrClient delegate, String
defaultCollection) {
+ this.delegate = Objects.requireNonNull(delegate);
+ this.defaultCollection = Objects.requireNonNull(defaultCollection);
+ }
+
+ @Override
+ public NamedList<Object> request(SolrRequest<?> request, String collection)
+ throws SolrServerException, IOException {
+ if (collection == null) {
+ collection = defaultCollection;
+ } else if (!collection.equals(defaultCollection)) {
+ throw new IllegalArgumentException(
+ "Restricted to default collection " + defaultCollection + " but was
given " + collection);
+ }
+ return delegate.request(request, collection);
+ }
+
+ @Override
+ public String toString() {
+ return delegate + "/" + defaultCollection;
+ }
+
+ @Override
+ public void close() throws IOException {
+ delegate.close();
+ }
+}