[
https://issues.apache.org/jira/browse/SOLR-6542?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Jakob Furrer updated SOLR-6542:
-------------------------------
Description:
I try to get a HttpSolrServer object with the following non-standard
functionalities:
* a proxy is used for the connection
* the connection timeout is set
A HttpClient object is required for setting proxy (see code listing 1).
The timeout can either be defined on the internal httpClient object (see option
a) or later on the created httpSolrServer object (see option b)
Question one:
_Is there a difference in behaviour of the HttpSolrServer instance when I set
the connection timeout directly in my own HttpClient object in comparison to
using the method HttpSolrServer#setConnectionTimeout() ?_
I would expect that there is no difference.
Moving from Solr 4.6 to Solr 4.9, I also upgraded HttpClient to the same
Version Solr is using (httpclient-4.2.6 was used in solr-4.6, now
httpclient-4.3.1 is used in solr-4.9).
The newer version of HttpSolr deprecates a number of methods used in my code,
therefore I was looking for a way to modify it according to the new API (see
code listing 2).
I now get an java.lang.UnsupportedOperationException when using the method
HttpSolrServer#setConnectionTimeout()
{noformat}
java.lang.UnsupportedOperationException
at
org.apache.http.impl.client.InternalHttpClient.getParams(InternalHttpClient.java:204)
at
org.apache.solr.client.solrj.impl.HttpClientUtil.setConnectionTimeout(HttpClientUtil.java:249)
at
org.apache.solr.client.solrj.impl.HttpSolrServer.setConnectionTimeout(HttpSolrServer.java:634)
at
test.HttpSolrServerTest.newStyle_httpclient_4_3_1(HttpSolrServerTest.java:89)
{noformat}
It seems that since the switch of the library HttpClient something internally
clashes in the HttpSolrServer object.
Question two:
_Is this something that has been overlooked when the library within SolrJ was
changed to the newer version, or am trying something that must not be done?_
I would expect that the method HttpSolrServer#setConnectionTimeout() can be
used, independent of the way I chose to create that object.
Bonus question:
_Am I using an acceptable way of accessing Solr over a proxy or are there
better methods?_
{code:title=code listing 1|borderStyle=solid}
/**
* requires the following libraries to run
* httpclient-4.2.6.jar
* httpcore-4.2.5.jar
* solr-solrj-4.6.0.jar
*
* --> shows lots of deprecated methods when using
httpclient-4.3.1.jar
*/
@Test
public void oldStyle_httpclient_4_2_6() throws Exception {
String solrUrlForPing =
"http://localhost:8060/FTS-Index/WebOffice";
String proxyHost = "127.0.0.1";
int proxyPort = 8888; // Using "Fiddler" as dummy proxy
int maxTimeout = 10000; // 10 seconds
final HttpParams httpParams = new BasicHttpParams();
// option a) timeout can be set as a parameter of the httpClient
HttpConnectionParams.setConnectionTimeout(httpParams,
maxTimeout);
HttpConnectionParams.setSoTimeout(httpParams, maxTimeout);
ClientConnectionManager connMgr = new
PoolingClientConnectionManager();
HttpClient httpClient = new DefaultHttpClient(connMgr,
httpParams);
HttpHost httpProxy = new HttpHost(proxyHost, proxyPort);
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, httpProxy);
HttpSolrServer httpSolrServer = new
HttpSolrServer(solrUrlForPing, httpClient);
// option b) timeout can be set on the httpSolrServer object
httpSolrServer.setConnectionTimeout(maxTimeout);
httpSolrServer.setSoTimeout(maxTimeout);
httpSolrServer.ping();
}
{code}
{code:title=code listing 2|borderStyle=solid}
/**
* requires the following libraries to run
* httpclient-4.3.1.jar
* httpcore-4.3.jar
* solr-solrj-4.9.0.jar
*/
@Test
public void newStyle_httpclient_4_3_1() throws Exception {
String solrUrlForPing =
"http://localhost:8060/FTS-Index/WebOffice";
String proxyHost = "127.0.0.1";
int proxyPort = 8888; // Using "Fiddler" as dummy proxy
int maxTimeout = 10000; // 10 seconds
HttpClientBuilder hcBuilder = HttpClients.custom();
// setting the maximum allowed timeout
RequestConfig config = RequestConfig.custom()
.setSocketTimeout(maxTimeout)
.setConnectTimeout(maxTimeout)
.build();
hcBuilder.setDefaultRequestConfig(config);
HttpHost httpProxy = new HttpHost(proxyHost, proxyPort);
DefaultProxyRoutePlanner routePlanner = new
DefaultProxyRoutePlanner(httpProxy);
hcBuilder.setRoutePlanner(routePlanner);
HttpClient httpClient = hcBuilder.build();
HttpSolrServer httpSolrServer = new
HttpSolrServer(solrUrlForPing, httpClient);
// option b) timeout can be set on the httpSolrServer object
httpSolrServer.setConnectionTimeout(maxTimeout); // -->
THROWS java.lang.UnsupportedOperationException
httpSolrServer.setSoTimeout(maxTimeout); // -->
THROWS java.lang.UnsupportedOperationException
httpSolrServer.ping();
}
{code}
was:
I try to get a HttpSolrServer object with the following non-standard
functionalities:
a) a proxy is used for the connection
b) the connection timeout is set
A HttpClient object is required for setting proxy (see code listing [1]).
The timeout can either be defined on the internal httpClient object (see option
[a]) or later on the created httpSolrServer object (see option [b])
Question one:
Is there a difference in behaviour of the HttpSolrServer instance when I set
the connection timeout directly in my own HttpClient object in comparison to
using the method HttpSolrServer#setConnectionTimeout() ?
I would expect that there is no difference.
Moving from Solr 4.6 to Solr 4.9, I also upgraded HttpClient to the same
Version Solr is using (httpclient-4.2.6 was used in solr-4.6, now
httpclient-4.3.1 is used in solr-4.9).
The newer version of HttpSolr deprecates a number of methods used in my code,
therefore I was looking for a way to modify it according to the new API (see
code listing [2]).
I now get an java.lang.UnsupportedOperationException when using the method
HttpSolrServer#setConnectionTimeout()
java.lang.UnsupportedOperationException
at
org.apache.http.impl.client.InternalHttpClient.getParams(InternalHttpClient.java:204)
at
org.apache.solr.client.solrj.impl.HttpClientUtil.setConnectionTimeout(HttpClientUtil.java:249)
at
org.apache.solr.client.solrj.impl.HttpSolrServer.setConnectionTimeout(HttpSolrServer.java:634)
at
test.HttpSolrServerTest.newStyle_httpclient_4_3_1(HttpSolrServerTest.java:89)
It seems that since the switch of the library HttpClient something internally
clashes in the HttpSolrServer object.
Question two:
Is this something that has been overlooked when the library within SolrJ was
changed to the newer version, or am trying something that must not be done?
I would expect that the method HttpSolrServer#setConnectionTimeout() can be
used, independent of the way I chose to create that object.
Bonus question:
Am I using an acceptable way of accessing Solr over a proxy or are there better
methods?
/**
* code listing [1]:
*
* requires the following libraries to run
* httpclient-4.2.6.jar
* httpcore-4.2.5.jar
* solr-solrj-4.6.0.jar
*
* --> shows lots of deprecated methods when using
httpclient-4.3.1.jar
*/
@Test
public void oldStyle_httpclient_4_2_6() throws Exception {
String solrUrlForPing =
"http://localhost:8060/FTS-Index/WebOffice";
String proxyHost = "127.0.0.1";
int proxyPort = 8888; // Using "Fiddler" as dummy proxy
int maxTimeout = 10000; // 10 seconds
final HttpParams httpParams = new BasicHttpParams();
// option a) timeout can be set as a parameter of the httpClient
HttpConnectionParams.setConnectionTimeout(httpParams,
maxTimeout);
HttpConnectionParams.setSoTimeout(httpParams, maxTimeout);
ClientConnectionManager connMgr = new
PoolingClientConnectionManager();
HttpClient httpClient = new DefaultHttpClient(connMgr,
httpParams);
HttpHost httpProxy = new HttpHost(proxyHost, proxyPort);
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, httpProxy);
HttpSolrServer httpSolrServer = new
HttpSolrServer(solrUrlForPing, httpClient);
// option b) timeout can be set on the httpSolrServer object
httpSolrServer.setConnectionTimeout(maxTimeout);
httpSolrServer.setSoTimeout(maxTimeout);
httpSolrServer.ping();
}
/**
* code listing [2]:
*
* requires the following libraries to run
* httpclient-4.3.1.jar
* httpcore-4.3.jar
* solr-solrj-4.9.0.jar
*/
@Test
public void newStyle_httpclient_4_3_1() throws Exception {
String solrUrlForPing =
"http://localhost:8060/FTS-Index/WebOffice";
String proxyHost = "127.0.0.1";
int proxyPort = 8888; // Using "Fiddler" as dummy proxy
int maxTimeout = 10000; // 10 seconds
HttpClientBuilder hcBuilder = HttpClients.custom();
// setting the maximum allowed timeout
RequestConfig config = RequestConfig.custom()
.setSocketTimeout(maxTimeout)
.setConnectTimeout(maxTimeout)
.build();
hcBuilder.setDefaultRequestConfig(config);
HttpHost httpProxy = new HttpHost(proxyHost, proxyPort);
DefaultProxyRoutePlanner routePlanner = new
DefaultProxyRoutePlanner(httpProxy);
hcBuilder.setRoutePlanner(routePlanner);
HttpClient httpClient = hcBuilder.build();
HttpSolrServer httpSolrServer = new
HttpSolrServer(solrUrlForPing, httpClient);
// option b) timeout can be set on the httpSolrServer object
httpSolrServer.setConnectionTimeout(maxTimeout); // -->
THROWS java.lang.UnsupportedOperationException
httpSolrServer.setSoTimeout(maxTimeout); // -->
THROWS java.lang.UnsupportedOperationException
httpSolrServer.ping();
}
> Method setConnectionTimeout throws Exception when using HttpSolrServer with a
> proxy
> -----------------------------------------------------------------------------------
>
> Key: SOLR-6542
> URL: https://issues.apache.org/jira/browse/SOLR-6542
> Project: Solr
> Issue Type: Bug
> Components: clients - java
> Affects Versions: 4.9, 4.10
> Reporter: Jakob Furrer
> Priority: Minor
>
> I try to get a HttpSolrServer object with the following non-standard
> functionalities:
> * a proxy is used for the connection
> * the connection timeout is set
> A HttpClient object is required for setting proxy (see code listing 1).
> The timeout can either be defined on the internal httpClient object (see
> option a) or later on the created httpSolrServer object (see option b)
> Question one:
> _Is there a difference in behaviour of the HttpSolrServer instance when I set
> the connection timeout directly in my own HttpClient object in comparison to
> using the method HttpSolrServer#setConnectionTimeout() ?_
> I would expect that there is no difference.
> Moving from Solr 4.6 to Solr 4.9, I also upgraded HttpClient to the same
> Version Solr is using (httpclient-4.2.6 was used in solr-4.6, now
> httpclient-4.3.1 is used in solr-4.9).
> The newer version of HttpSolr deprecates a number of methods used in my code,
> therefore I was looking for a way to modify it according to the new API (see
> code listing 2).
> I now get an java.lang.UnsupportedOperationException when using the method
> HttpSolrServer#setConnectionTimeout()
> {noformat}
> java.lang.UnsupportedOperationException
> at
> org.apache.http.impl.client.InternalHttpClient.getParams(InternalHttpClient.java:204)
> at
> org.apache.solr.client.solrj.impl.HttpClientUtil.setConnectionTimeout(HttpClientUtil.java:249)
> at
> org.apache.solr.client.solrj.impl.HttpSolrServer.setConnectionTimeout(HttpSolrServer.java:634)
> at
> test.HttpSolrServerTest.newStyle_httpclient_4_3_1(HttpSolrServerTest.java:89)
> {noformat}
> It seems that since the switch of the library HttpClient something internally
> clashes in the HttpSolrServer object.
> Question two:
> _Is this something that has been overlooked when the library within SolrJ was
> changed to the newer version, or am trying something that must not be done?_
> I would expect that the method HttpSolrServer#setConnectionTimeout() can be
> used, independent of the way I chose to create that object.
> Bonus question:
> _Am I using an acceptable way of accessing Solr over a proxy or are there
> better methods?_
> {code:title=code listing 1|borderStyle=solid}
> /**
> * requires the following libraries to run
> * httpclient-4.2.6.jar
> * httpcore-4.2.5.jar
> * solr-solrj-4.6.0.jar
> *
> * --> shows lots of deprecated methods when using
> httpclient-4.3.1.jar
> */
> @Test
> public void oldStyle_httpclient_4_2_6() throws Exception {
> String solrUrlForPing =
> "http://localhost:8060/FTS-Index/WebOffice";
> String proxyHost = "127.0.0.1";
> int proxyPort = 8888; // Using "Fiddler" as dummy proxy
> int maxTimeout = 10000; // 10 seconds
> final HttpParams httpParams = new BasicHttpParams();
> // option a) timeout can be set as a parameter of the httpClient
> HttpConnectionParams.setConnectionTimeout(httpParams,
> maxTimeout);
> HttpConnectionParams.setSoTimeout(httpParams, maxTimeout);
> ClientConnectionManager connMgr = new
> PoolingClientConnectionManager();
> HttpClient httpClient = new DefaultHttpClient(connMgr,
> httpParams);
> HttpHost httpProxy = new HttpHost(proxyHost, proxyPort);
>
> httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, httpProxy);
> HttpSolrServer httpSolrServer = new
> HttpSolrServer(solrUrlForPing, httpClient);
> // option b) timeout can be set on the httpSolrServer object
> httpSolrServer.setConnectionTimeout(maxTimeout);
> httpSolrServer.setSoTimeout(maxTimeout);
> httpSolrServer.ping();
> }
> {code}
> {code:title=code listing 2|borderStyle=solid}
> /**
> * requires the following libraries to run
> * httpclient-4.3.1.jar
> * httpcore-4.3.jar
> * solr-solrj-4.9.0.jar
> */
> @Test
> public void newStyle_httpclient_4_3_1() throws Exception {
> String solrUrlForPing =
> "http://localhost:8060/FTS-Index/WebOffice";
> String proxyHost = "127.0.0.1";
> int proxyPort = 8888; // Using "Fiddler" as dummy proxy
> int maxTimeout = 10000; // 10 seconds
> HttpClientBuilder hcBuilder = HttpClients.custom();
> // setting the maximum allowed timeout
> RequestConfig config = RequestConfig.custom()
> .setSocketTimeout(maxTimeout)
> .setConnectTimeout(maxTimeout)
> .build();
> hcBuilder.setDefaultRequestConfig(config);
> HttpHost httpProxy = new HttpHost(proxyHost, proxyPort);
> DefaultProxyRoutePlanner routePlanner = new
> DefaultProxyRoutePlanner(httpProxy);
> hcBuilder.setRoutePlanner(routePlanner);
> HttpClient httpClient = hcBuilder.build();
> HttpSolrServer httpSolrServer = new
> HttpSolrServer(solrUrlForPing, httpClient);
> // option b) timeout can be set on the httpSolrServer object
> httpSolrServer.setConnectionTimeout(maxTimeout); // -->
> THROWS java.lang.UnsupportedOperationException
> httpSolrServer.setSoTimeout(maxTimeout); // -->
> THROWS java.lang.UnsupportedOperationException
> httpSolrServer.ping();
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]