[ 
https://issues.apache.org/jira/browse/SOLR-6542?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15981118#comment-15981118
 ] 

Shawn Heisey commented on SOLR-6542:
------------------------------------

Someone mentioned this issue in relation to a more recent problem, which is why 
I am commenting now, over two years after the issue was created.

I believe the reason this problem is encountered is because you have created 
the HttpClient object external to the Solr client, then you are trying to 
modify settings on the HttpClient from within the Solr client.

The methods on the Solr client that set timeouts are designed to work with the 
HttpClient object that the HttpSolrServer object can create internally.  When 
you create the HttpClient object yourself and use it to create HttpSolrServer 
(HttpSolrClient in 5.0 and later), all connection parameters like timeouts 
should be set on the HttpClient before that client is passed to the Solr 
client.  The two methods you are using should NOT be used with an external 
HttpClient.

In the second code example, the timeouts are being set on the HttpClient 
exactly like I described ... so there is no need to call the timeout methods on 
the Solr client.  I am closing this issue as invalid.  If you find that there 
is still a problem even when not setting the timeouts with SolrJ code, then we 
can reopen and investigate.


> 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:8983/solr/collection1";;
>               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:8983/solr/collection1";;
>               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.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org

Reply via email to