Skip to content

Commit a387b19

Browse files
adityamparikhclaude
andcommitted
refactor(config): make JsonResponseParser a Spring Bean
Extract JsonResponseParser instantiation into a dedicated @bean method so it can be injected as a dependency into solrClient(), making the wiring explicit and enabling overriding in tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: adityamparikh <aditya.m.parikh@gmail.com>
1 parent 487f090 commit a387b19

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

src/main/java/org/apache/solr/mcp/server/config/SolrConfig.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,12 @@ public class SolrConfig {
168168
* @see SolrConfigurationProperties#url()
169169
*/
170170
@Bean
171-
SolrClient solrClient(SolrConfigurationProperties properties) {
171+
JsonResponseParser jsonResponseParser() {
172+
return new JsonResponseParser();
173+
}
174+
175+
@Bean
176+
SolrClient solrClient(SolrConfigurationProperties properties, JsonResponseParser jsonResponseParser) {
172177
String url = properties.url();
173178

174179
// Ensure URL is properly formatted for Solr
@@ -188,7 +193,7 @@ SolrClient solrClient(SolrConfigurationProperties properties) {
188193

189194
// Use with explicit base URL; JSON wire format replaces the JavaBin default
190195
return new Http2SolrClient.Builder(url).withConnectionTimeout(CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS)
191-
.withIdleTimeout(SOCKET_TIMEOUT_MS, TimeUnit.MILLISECONDS).withResponseParser(new JsonResponseParser())
196+
.withIdleTimeout(SOCKET_TIMEOUT_MS, TimeUnit.MILLISECONDS).withResponseParser(jsonResponseParser)
192197
.build();
193198
}
194199
}

src/test/java/org/apache/solr/mcp/server/config/SolrConfigTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void testUrlNormalization(String inputUrl, String expectedUrl) {
8181
SolrConfig solrConfig = new SolrConfig();
8282

8383
// Test URL normalization
84-
SolrClient client = solrConfig.solrClient(testProperties);
84+
SolrClient client = solrConfig.solrClient(testProperties, new JsonResponseParser());
8585
assertNotNull(client);
8686

8787
var httpClient = assertInstanceOf(Http2SolrClient.class, client);
@@ -101,7 +101,7 @@ void testUrlWithoutTrailingSlash() {
101101
SolrConfigurationProperties testProperties = new SolrConfigurationProperties("http://localhost:8983");
102102
SolrConfig solrConfig = new SolrConfig();
103103

104-
SolrClient client = solrConfig.solrClient(testProperties);
104+
SolrClient client = solrConfig.solrClient(testProperties, new JsonResponseParser());
105105
Http2SolrClient httpClient = (Http2SolrClient) client;
106106

107107
// Should add trailing slash and solr path
@@ -120,7 +120,7 @@ void testUrlWithTrailingSlashButNoSolrPath() {
120120
SolrConfigurationProperties testProperties = new SolrConfigurationProperties("http://localhost:8983/");
121121
SolrConfig solrConfig = new SolrConfig();
122122

123-
SolrClient client = solrConfig.solrClient(testProperties);
123+
SolrClient client = solrConfig.solrClient(testProperties, new JsonResponseParser());
124124
Http2SolrClient httpClient = (Http2SolrClient) client;
125125

126126
// Should add solr path to existing trailing slash
@@ -139,7 +139,7 @@ void testUrlWithSolrPathButNoTrailingSlash() {
139139
SolrConfigurationProperties testProperties = new SolrConfigurationProperties("http://localhost:8983/solr");
140140
SolrConfig solrConfig = new SolrConfig();
141141

142-
SolrClient client = solrConfig.solrClient(testProperties);
142+
SolrClient client = solrConfig.solrClient(testProperties, new JsonResponseParser());
143143
Http2SolrClient httpClient = (Http2SolrClient) client;
144144

145145
// Should add trailing slash
@@ -158,7 +158,7 @@ void testUrlAlreadyProperlyFormatted() {
158158
SolrConfigurationProperties testProperties = new SolrConfigurationProperties("http://localhost:8983/solr/");
159159
SolrConfig solrConfig = new SolrConfig();
160160

161-
SolrClient client = solrConfig.solrClient(testProperties);
161+
SolrClient client = solrConfig.solrClient(testProperties, new JsonResponseParser());
162162
Http2SolrClient httpClient = (Http2SolrClient) client;
163163

164164
// Should remain unchanged

0 commit comments

Comments
 (0)