@@ -37,17 +37,17 @@ public class RestClientConfiguration {
3737
3838 private static final Log log = LogFactory .getLog (RestClientConfiguration .class );
3939 private static final Pattern URL_PATTERN = Pattern .compile ("\\ b(https?)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]" );
40+ private static final Pattern VERSION_PATTERN = Pattern .compile ("^[v]\\ d[_]\\ d[_]\\ d$" );
4041
4142 private String jasperReportsServerUrl ;
4243 private MimeType contentMimeType = MimeType .JSON ;
4344 private MimeType acceptMimeType = MimeType .JSON ;
4445 private JRSVersion jrsVersion = JRSVersion .v5_5_0 ;
46+
4547 private AuthenticationType authenticationType = AuthenticationType .REST ;
4648 private Boolean restrictedHttpMethods = false ;
47-
48- private Boolean isJerseyRequestLogged = false ;
49-
50- private Boolean isJSonEntitieLogged = false ;
49+ private Boolean logHttpEntity = false ;
50+ private Boolean logHttp = false ;
5151
5252 private TrustManager [] trustManagers ;
5353 private Integer connectionTimeout ;
@@ -90,10 +90,35 @@ public void setJasperReportsServerUrl(String jasperReportsServerUrl) {
9090 public AuthenticationType getAuthenticationType () {
9191 return authenticationType ;
9292 }
93+
9394 public void setAuthenticationType (AuthenticationType authenticationType ) {
9495 this .authenticationType = authenticationType ;
9596 }
9697
98+ public Boolean getRestrictedHttpMethods () {
99+ return restrictedHttpMethods ;
100+ }
101+
102+ public void setRestrictedHttpMethods (Boolean restrictedHttpMethods ) {
103+ this .restrictedHttpMethods = restrictedHttpMethods ;
104+ }
105+
106+ public Boolean getLogHttp () {
107+ return logHttp ;
108+ }
109+
110+ public void setLogHttp (Boolean logHttp ) {
111+ this .logHttp = logHttp ;
112+ }
113+
114+ public Boolean getLogHttpEntity () {
115+ return logHttpEntity ;
116+ }
117+
118+ public void setLogHttpEntity (Boolean logHttpEntity ) {
119+ this .logHttpEntity = logHttpEntity ;
120+ }
121+
97122 public MimeType getContentMimeType () {
98123 return contentMimeType ;
99124 }
@@ -118,7 +143,7 @@ public void setJrsVersion(JRSVersion jrsVersion) {
118143 this .jrsVersion = jrsVersion ;
119144 }
120145
121- public TrustManager [] getTrustManagers () {
146+ public TrustManager [] getTrustManagers () {
122147 return trustManagers ;
123148 }
124149
@@ -142,43 +167,63 @@ public void setReadTimeout(Integer readTimeout) {
142167 this .readTimeout = readTimeout ;
143168 }
144169
145- public Boolean getRestrictedHttpMethods () {
146- return restrictedHttpMethods ;
147- }
148-
149- public void setRestrictedHttpMethods (Boolean restrictedHttpMethods ) {
150- this .restrictedHttpMethods = restrictedHttpMethods ;
151- }
152-
153- public Boolean getIsJerseyRequestLogged () {
154- return isJerseyRequestLogged ;
155- }
156-
157- public void setIsJerseyRequestLogged (Boolean isJerseyRequestLogged ) {
158- this .isJerseyRequestLogged = isJerseyRequestLogged ;
159- }
160-
161- public Boolean getIsJSonEntitieLogged () {
162- return isJSonEntitieLogged ;
163- }
164-
165- public void setIsJSonEntitieLogged (Boolean isJSonEntitieLogged ) {
166- this .isJSonEntitieLogged = isJSonEntitieLogged ;
167- }
168-
169170 public static RestClientConfiguration loadConfiguration (String path ) {
170- Properties properties = loadProperties (path );
171+ Properties properties = null ;
172+ if (path != null ) {
173+ properties = loadProperties (path );
174+ }
175+ if (properties == null ) {
176+ log .info ("The properties file was not loaded" );
177+ return null ;
178+ }
171179
172180 RestClientConfiguration configuration = new RestClientConfiguration ();
173- configuration .setJasperReportsServerUrl (properties .getProperty ("url" ));
181+ String url = properties .getProperty ("url" );
182+ if (url != null && !url .equals ("" ) && URL_PATTERN .matcher (url ).matches ()) {
183+ configuration .setJasperReportsServerUrl (url );
184+ }
174185
175186 String connectionTimeout = properties .getProperty ("connectionTimeout" );
176- if (connectionTimeout != null && !connectionTimeout .equals ("" ))
187+ if (connectionTimeout != null && !connectionTimeout .equals ("" )) {
177188 configuration .setConnectionTimeout (Integer .valueOf (connectionTimeout ));
189+ }
178190
179191 String readTimeout = properties .getProperty ("readTimeout" );
180- if (readTimeout != null && !readTimeout .equals ("" ))
181- configuration .setConnectionTimeout (Integer .valueOf (readTimeout ));
192+ if (readTimeout != null && !readTimeout .equals ("" )) {
193+ configuration .setReadTimeout (Integer .valueOf (readTimeout ));
194+ }
195+ String jrsVersion = properties .getProperty ("jasperserverVersion" );
196+ if (jrsVersion != null && !jrsVersion .equals ("" ) && VERSION_PATTERN .matcher (jrsVersion ).matches ()) {
197+ try {
198+ configuration .setJrsVersion (JRSVersion .valueOf (jrsVersion ));
199+ } catch (Exception e ) {
200+ log .info ("There is no version for JasperReportsServer or it isn't supported." , e );
201+ }
202+ }
203+
204+ String authenticationType = properties .getProperty ("authenticationType" );
205+ if (authenticationType != null && !authenticationType .equals ("" )) {
206+ try {
207+ configuration .setAuthenticationType (AuthenticationType .valueOf (authenticationType .toUpperCase ()));
208+ } catch (Exception e ) {
209+ log .info ("There is no authentication type or it isn't supported." , e );
210+ }
211+ }
212+
213+ String logHttp = properties .getProperty ("logHttp" );
214+ if (logHttp != null && !logHttp .equals ("" )) {
215+ configuration .setLogHttp (Boolean .valueOf (logHttp ));
216+ }
217+
218+ String logHttpEntity = properties .getProperty ("logHttpEntity" );
219+ if (logHttpEntity != null && !logHttpEntity .equals ("" )) {
220+ configuration .setLogHttpEntity (Boolean .valueOf (logHttpEntity ));
221+ }
222+
223+ String restrictedHttpMethods = properties .getProperty ("restrictedHttpMethods" );
224+ if (restrictedHttpMethods != null && !restrictedHttpMethods .equals ("" )) {
225+ configuration .setRestrictedHttpMethods (Boolean .valueOf (restrictedHttpMethods ));
226+ }
182227
183228 try {
184229 configuration .setContentMimeType (MimeType .valueOf (properties .getProperty ("contentMimeType" )));
@@ -202,9 +247,8 @@ private static Properties loadProperties(String path) {
202247 properties .load (is );
203248 } catch (Exception e ) {
204249 log .info ("Error when loading properties file" , e );
250+ return null ;
205251 }
206252 return properties ;
207253 }
208-
209-
210254}
0 commit comments