1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.search.solr.business;
35
36 import fr.paris.lutece.portal.service.util.AppPropertiesService;
37 import org.apache.solr.client.solrj.SolrClient;
38 import org.apache.solr.client.solrj.impl.Http2SolrClient;
39
40
41
42
43
44 public final class SolrServerService
45 {
46 private static final String PROPERTY_SOLR_SERVER_URL = "solr.server.address";
47 private static final String PROPERTY_SOLR_TIMEOUT = "solr.server.timeout";
48 private static final String PROPERTY_SOLR_IDLE_TIMEOUT = "solr.idle.timeout";
49 private static final String PROPERTY_SOLR_HTTP_BASIC_AUTH_USER = "solr.httpBasicAuthUser";
50 private static final String PROPERTY_SOLR_HTTP_BASIC_AUTH_PASSWORD = "solr.httpBasicAuthPassword";
51
52 private static final String SOLR_SERVER_URL = AppPropertiesService.getProperty( PROPERTY_SOLR_SERVER_URL );
53 private static final int SOLR_CONNECTION_TIMEOUT = AppPropertiesService.getPropertyInt( PROPERTY_SOLR_TIMEOUT, 60000 );
54 private static final int SOLR_IDLE_TIMEOUT = AppPropertiesService.getPropertyInt( PROPERTY_SOLR_IDLE_TIMEOUT, 600000 );
55
56 private static final String SOLR_HTTP_BASIC_AUTH_USER = AppPropertiesService.getProperty( PROPERTY_SOLR_HTTP_BASIC_AUTH_USER );
57 private static final String SOLR_HTTP_BASIC_AUTH_PASSWORD = AppPropertiesService.getProperty( PROPERTY_SOLR_HTTP_BASIC_AUTH_PASSWORD );
58 private static SolrServerService _instance;
59 private SolrClient _solrServer;
60
61
62
63
64 private SolrServerService( )
65 {
66 _solrServer = createSolrServer( SOLR_SERVER_URL );
67 }
68
69
70
71
72
73
74 public static SolrServerService getInstance( )
75 {
76 if ( _instance == null )
77 {
78 _instance = new SolrServerService( );
79 }
80
81 return _instance;
82 }
83
84
85
86
87
88
89 public SolrClient getSolrServer( )
90 {
91 if ( _solrServer == null )
92 {
93 _solrServer = createSolrServer( SOLR_SERVER_URL );
94 }
95
96 return _solrServer;
97 }
98
99
100
101
102
103
104
105
106 private SolrClient createSolrServer( String strServerUrl )
107 {
108 return new Http2SolrClient.Builder(strServerUrl).connectionTimeout(SOLR_CONNECTION_TIMEOUT).idleTimeout(SOLR_IDLE_TIMEOUT).withBasicAuthCredentials(SOLR_HTTP_BASIC_AUTH_USER, SOLR_HTTP_BASIC_AUTH_PASSWORD).build();
109 }
110 }