use of javax.servlet.ServletConfig in project opennms by OpenNMS.
the class PollerConfigServlet method init.
/**
* <p>init</p>
*
* @throws javax.servlet.ServletException if any.
*/
@Override
public void init() throws ServletException {
ServletConfig config = this.getServletConfig();
try {
PollerConfigFactory.init();
pollerFactory = PollerConfigFactory.getInstance();
pollerConfig = pollerFactory.getConfiguration();
if (pollerConfig == null) {
throw new ServletException("Poller Configuration file is empty");
}
} catch (Throwable e) {
throw new ServletException(e.getMessage());
}
initPollerServices();
this.redirectSuccess = config.getInitParameter("redirect.success");
if (this.redirectSuccess == null) {
throw new ServletException("Missing required init parameter: redirect.success");
}
}
use of javax.servlet.ServletConfig in project hudson-2.x by hudson.
the class AccessDeniedHandlerImpl method handle.
public void handle(ServletRequest request, ServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse rsp = (HttpServletResponse) response;
rsp.setStatus(HttpServletResponse.SC_FORBIDDEN);
req.setAttribute("exception", accessDeniedException);
Stapler stapler = new Stapler();
stapler.init(new ServletConfig() {
public String getServletName() {
return "Stapler";
}
public ServletContext getServletContext() {
return Hudson.getInstance().servletContext;
}
public String getInitParameter(String name) {
return null;
}
public Enumeration getInitParameterNames() {
return new Vector().elements();
}
});
stapler.invoke(req, rsp, Hudson.getInstance(), "/accessDenied");
}
use of javax.servlet.ServletConfig in project jetty.project by eclipse.
the class FastCGIProxyServlet method newHttpClient.
@Override
protected HttpClient newHttpClient() {
ServletConfig config = getServletConfig();
String scriptRoot = config.getInitParameter(SCRIPT_ROOT_INIT_PARAM);
if (scriptRoot == null)
throw new IllegalArgumentException("Mandatory parameter '" + SCRIPT_ROOT_INIT_PARAM + "' not configured");
return new HttpClient(new ProxyHttpClientTransportOverFCGI(scriptRoot), null);
}
use of javax.servlet.ServletConfig in project jetty.project by eclipse.
the class AbstractProxyServlet method createHttpClient.
/**
* <p>Creates a {@link HttpClient} instance, configured with init parameters of this servlet.</p>
* <p>The init parameters used to configure the {@link HttpClient} instance are:</p>
* <table>
* <caption>Init Parameters</caption>
* <thead>
* <tr>
* <th>init-param</th>
* <th>default</th>
* <th>description</th>
* </tr>
* </thead>
* <tbody>
* <tr>
* <td>maxThreads</td>
* <td>256</td>
* <td>The max number of threads of HttpClient's Executor. If not set, or set to the value of "-", then the
* Jetty server thread pool will be used.</td>
* </tr>
* <tr>
* <td>maxConnections</td>
* <td>32768</td>
* <td>The max number of connections per destination, see {@link HttpClient#setMaxConnectionsPerDestination(int)}</td>
* </tr>
* <tr>
* <td>idleTimeout</td>
* <td>30000</td>
* <td>The idle timeout in milliseconds, see {@link HttpClient#setIdleTimeout(long)}</td>
* </tr>
* <tr>
* <td>timeout</td>
* <td>60000</td>
* <td>The total timeout in milliseconds, see {@link Request#timeout(long, java.util.concurrent.TimeUnit)}</td>
* </tr>
* <tr>
* <td>requestBufferSize</td>
* <td>HttpClient's default</td>
* <td>The request buffer size, see {@link HttpClient#setRequestBufferSize(int)}</td>
* </tr>
* <tr>
* <td>responseBufferSize</td>
* <td>HttpClient's default</td>
* <td>The response buffer size, see {@link HttpClient#setResponseBufferSize(int)}</td>
* </tr>
* </tbody>
* </table>
*
* @return a {@link HttpClient} configured from the {@link #getServletConfig() servlet configuration}
* @throws ServletException if the {@link HttpClient} cannot be created
*/
protected HttpClient createHttpClient() throws ServletException {
ServletConfig config = getServletConfig();
HttpClient client = newHttpClient();
// Redirects must be proxied as is, not followed.
client.setFollowRedirects(false);
// Must not store cookies, otherwise cookies of different clients will mix.
client.setCookieStore(new HttpCookieStore.Empty());
Executor executor;
String value = config.getInitParameter("maxThreads");
if (value == null || "-".equals(value)) {
executor = (Executor) getServletContext().getAttribute("org.eclipse.jetty.server.Executor");
if (executor == null)
throw new IllegalStateException("No server executor for proxy");
} else {
QueuedThreadPool qtp = new QueuedThreadPool(Integer.parseInt(value));
String servletName = config.getServletName();
int dot = servletName.lastIndexOf('.');
if (dot >= 0)
servletName = servletName.substring(dot + 1);
qtp.setName(servletName);
executor = qtp;
}
client.setExecutor(executor);
value = config.getInitParameter("maxConnections");
if (value == null)
value = "256";
client.setMaxConnectionsPerDestination(Integer.parseInt(value));
value = config.getInitParameter("idleTimeout");
if (value == null)
value = "30000";
client.setIdleTimeout(Long.parseLong(value));
value = config.getInitParameter("timeout");
if (value == null)
value = "60000";
_timeout = Long.parseLong(value);
value = config.getInitParameter("requestBufferSize");
if (value != null)
client.setRequestBufferSize(Integer.parseInt(value));
value = config.getInitParameter("responseBufferSize");
if (value != null)
client.setResponseBufferSize(Integer.parseInt(value));
try {
client.start();
// Content must not be decoded, otherwise the client gets confused.
client.getContentDecoderFactories().clear();
// Pass traffic to the client, only intercept what's necessary.
ProtocolHandlers protocolHandlers = client.getProtocolHandlers();
protocolHandlers.clear();
protocolHandlers.put(new ProxyContinueProtocolHandler());
return client;
} catch (Exception x) {
throw new ServletException(x);
}
}
use of javax.servlet.ServletConfig in project guice by google.
the class ServletDefinition method init.
public void init(final ServletContext servletContext, Injector injector, Set<HttpServlet> initializedSoFar) throws ServletException {
// This absolutely must be a singleton, and so is only initialized once.
if (!Scopes.isSingleton(injector.getBinding(servletKey))) {
throw new ServletException("Servlets must be bound as singletons. " + servletKey + " was not bound in singleton scope.");
}
HttpServlet httpServlet = injector.getInstance(servletKey);
this.httpServlet.set(httpServlet);
// Only fire init() if we have not appeared before in the filter chain.
if (initializedSoFar.contains(httpServlet)) {
return;
}
//initialize our servlet with the configured context params and servlet context
httpServlet.init(new ServletConfig() {
@Override
public String getServletName() {
return servletKey.toString();
}
@Override
public ServletContext getServletContext() {
return servletContext;
}
@Override
public String getInitParameter(String s) {
return initParams.get(s);
}
@Override
public Enumeration getInitParameterNames() {
return Iterators.asEnumeration(initParams.keySet().iterator());
}
});
// Mark as initialized.
initializedSoFar.add(httpServlet);
}
Aggregations