View Javadoc
1   /******************************************************************************
2    * ClientFactory.java - Create web client objects
3    * $Id: ClientFactory.java,v 1.4 2014/10/08 04:37:20 dick Exp $
4    * 
5    * BuckoVidLib - The BuckoSoft Video Library
6    * Copyright(c) 2014 - Dick Balaska
7    * 
8    * $Log: ClientFactory.java,v $
9    * Revision 1.4  2014/10/08 04:37:20  dick
10   * debug.
11   *
12   * Revision 1.3  2014/10/07 04:28:13  dick
13   * Use Apache logging.
14   *
15   * Revision 1.2  2014/10/07 02:49:47  dick
16   * ConfigManager moves to util, a more public place than the web client.
17   *
18   * Revision 1.1  2014/10/04 16:17:40  dick
19   * Define a web client that can talk to the plex server.
20   *
21   */
22  package com.buckosoft.BuckoVidLib.web.plex.client;
23  
24  import static com.buckosoft.BuckoVidLib.web.plex.client.RestClientConstants.CXF_CLIENT_CONNECTION_TIMEOUT_PROP_KEY;
25  import static com.buckosoft.BuckoVidLib.web.plex.client.RestClientConstants.CXF_CLIENT_LOGGING_IN_INTERCEPTOR_PROP_KEY;
26  import static com.buckosoft.BuckoVidLib.web.plex.client.RestClientConstants.CXF_CLIENT_LOGGING_OUT_INTERCEPTOR_PROP_KEY;
27  import static com.buckosoft.BuckoVidLib.web.plex.client.RestClientConstants.CXF_CLIENT_RECEIVE_TIMEOUT_PROP_KEY;
28  import static com.buckosoft.BuckoVidLib.web.plex.client.RestClientConstants.DEFAULT_CXF_CLIENT_CONNECTION_TIMEOUT;
29  import static com.buckosoft.BuckoVidLib.web.plex.client.RestClientConstants.DEFAULT_CXF_CLIENT_RECEIVE_TIMEOUT;
30  import static com.buckosoft.BuckoVidLib.web.plex.client.RestClientConstants.REST_SERVER_URL_PROP_KEY;
31  import static com.buckosoft.BuckoVidLib.web.plex.client.RestClientConstants.DEFAULT_REST_SERVER_LOCATION;
32  
33  import org.apache.commons.logging.Log;
34  import org.apache.commons.logging.LogFactory;
35  
36  import com.buckosoft.BuckoVidLib.util.ConfigManager;
37  
38  public class ClientFactory {
39  	private	static	LibraryClient libraryClient;
40  	
41  	private final Log log = LogFactory.getLog(getClass());
42  	public static String SERVER_ENDPOINT_URL = null;
43  
44  	static {
45  		new ClientFactory();
46  	}
47  	private	ClientFactory() {
48  		SERVER_ENDPOINT_URL = ConfigManager.getString(REST_SERVER_URL_PROP_KEY, null);
49  
50  		//this bit of code will allow the posrest url to be specified as an environment variable as well.
51  		if (SERVER_ENDPOINT_URL == null)
52  			SERVER_ENDPOINT_URL = System.getProperty(REST_SERVER_URL_PROP_KEY, DEFAULT_REST_SERVER_LOCATION);
53  
54  		log.info("Rest server location: " + SERVER_ENDPOINT_URL);
55  
56  		int connectionTimeout = ConfigManager.getInt(CXF_CLIENT_CONNECTION_TIMEOUT_PROP_KEY, DEFAULT_CXF_CLIENT_CONNECTION_TIMEOUT);
57  		log.info("CXF Client connection  timeout set to: " + connectionTimeout);
58  
59  		int receiveTimeout = ConfigManager.getInt(CXF_CLIENT_RECEIVE_TIMEOUT_PROP_KEY, DEFAULT_CXF_CLIENT_RECEIVE_TIMEOUT);
60  		log.info("CXF Client receive time out set to: " + receiveTimeout);
61  
62  		log.info("CXF Client Logging-In Interceptor enabled: " + ConfigManager.isEnabled(CXF_CLIENT_LOGGING_IN_INTERCEPTOR_PROP_KEY));
63  		log.info("CXF Client Logging-Out Interceptor enabled: " + ConfigManager.isEnabled(CXF_CLIENT_LOGGING_OUT_INTERCEPTOR_PROP_KEY));
64  		
65  	}
66  	
67  	public static LibraryClient getLibraryClient() {
68  		if (libraryClient == null)
69  			libraryClient = new LibraryClient(SERVER_ENDPOINT_URL);
70  		return(libraryClient);
71  	}
72  }