View Javadoc
1   /*
2    * Copyright (c) 2012-2014, Dienst Landelijk Gebied - Ministerie van Economische Zaken
3    * 
4    * Gepubliceerd onder de BSD 2-clause licentie, 
5    * zie https://github.com/MinELenI/CBSviewer/blob/master/LICENSE.md voor de volledige licentie.
6    */
7   package nl.mineleni.cbsviewer.servlet;
8   
9   import javax.servlet.ServletConfig;
10  import javax.servlet.ServletException;
11  import javax.servlet.http.HttpServlet;
12  
13  import org.slf4j.Logger;
14  import org.slf4j.LoggerFactory;
15  
16  /**
17   * Gedeelde basis servlet.
18   * 
19   * @author mprins
20   * 
21   */
22  public abstract class AbstractBaseServlet extends HttpServlet {
23  
24  	/** sleutel voor user id. {@value} */
25  	public static final String USER_ID = "user_id";
26  
27  	/** sleutel voor password. {@value} */
28  	public static final String USER_PASSWORD = "user_password";
29  
30  	/** default serialVersionUID. */
31  	private static final long serialVersionUID = 1L;
32  
33  	/** logger. */
34  	private static final Logger LOGGER = LoggerFactory
35  			.getLogger(AbstractBaseServlet.class);
36  	/** proxyserver address for the this service. */
37  	private transient String proxyHost;
38  
39  	/** proxyserver port for the this service. */
40  	private transient int proxyPort = -1;
41  
42  	/** user id voor bijv. authenticatie. @see #USER_ID */
43  	private transient String userID;
44  
45  	/** password voor bijv. authenticatie. @see #USER_PASSWORD */
46  	private transient String passID;
47  
48  	/**
49  	 * Gets the proxy host.
50  	 * 
51  	 * @return the proxyHost
52  	 */
53  	public String getProxyHost() {
54  		return this.proxyHost;
55  	}
56  
57  	/**
58  	 * Gets the proxy port.
59  	 * 
60  	 * @return the proxyPort
61  	 */
62  	public int getProxyPort() {
63  		return this.proxyPort;
64  	}
65  
66  	/**
67  	 * Gets the user id.
68  	 * 
69  	 * @return the userID
70  	 */
71  	public String getUserID() {
72  		return this.userID;
73  	}
74  
75  	/**
76  	 * Gets the pass id.
77  	 * 
78  	 * @return the passID
79  	 */
80  	public String getPassID() {
81  		return this.passID;
82  	}
83  
84  	/**
85  	 * Leest de config opties uit de web.xml in; het gaat om {@link #USER_ID} en
86  	 * {@link #USER_PASSWORD}. Daarnaast wordt expliciet de init van de super
87  	 * klasse aangeroepen.
88  	 * 
89  	 * @param config
90  	 *            the <code>ServletConfig</code> object that contains
91  	 *            configutation information for this servlet
92  	 * @throws ServletException
93  	 *             if an exception occurs that interrupts the servlet's normal
94  	 *             operation
95  	 * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
96  	 */
97  	@Override
98  	public void init(final ServletConfig config) throws ServletException {
99  		super.init(config);
100 
101 		// netwerk data/parameters
102 		this.proxyHost = System.getProperty("http.proxyHost");
103 		try {
104 			this.proxyPort = Integer.valueOf(System
105 					.getProperty("http.proxyPort"));
106 		} catch (final NumberFormatException e) {
107 			LOGGER.debug("Geen proxy poort gedefinieerd.");
108 		}
109 		LOGGER.info("Instellen van proxy config: " + this.proxyHost + ":"
110 				+ this.proxyPort);
111 
112 		// user data/parameters
113 		this.userID = config.getInitParameter(USER_ID);
114 		this.passID = config.getInitParameter(USER_PASSWORD);
115 		if (LOGGER.isDebugEnabled()) {
116 			LOGGER.debug("User ID is: " + this.userID
117 					+ "; User password lengte is: "
118 					+ (null != this.passID ? this.passID.length() : "0"));
119 		}
120 	}
121 }