List of usage examples for javax.servlet.http HttpServlet getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.adeptj.runtime.common.Servlets.java
public static ServiceRegistration<Servlet> osgiServlet(BundleContext ctx, HttpServlet servlet) { Class<? extends HttpServlet> cls = servlet.getClass(); WebServlet webServlet = checkWebServletAnnotation(cls); Dictionary<String, Object> properties = new Hashtable<>(); // NOSONAR properties.put(HTTP_WHITEBOARD_SERVLET_PATTERN, ArrayUtils.isEmpty(webServlet.urlPatterns()) ? webServlet.value() : webServlet.urlPatterns()); properties.put(HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED, webServlet.asyncSupported()); handleInitParams(webServlet, properties); String servletName = resolveServletName(cls, webServlet.name(), properties); LOGGER.info("Registering OSGi Servlet: [{}]", servletName); return ctx.registerService(Servlet.class, servlet, properties); }
From source file:io.adeptj.runtime.common.Servlets.java
public static ServiceRegistration<Servlet> osgiServlet(BundleContext ctx, HttpServlet servlet) { Class<? extends HttpServlet> cls = servlet.getClass(); WebServlet webServlet = checkWebServletAnnotation(cls); Dictionary<String, Object> properties = new Hashtable<>(); // NOSONAR properties.put(HTTP_WHITEBOARD_SERVLET_PATTERN, ArrayUtils.isEmpty(webServlet.urlPatterns()) ? webServlet.value() : webServlet.urlPatterns()); properties.put(HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED, webServlet.asyncSupported()); handleInitParams(webServlet, properties); handleName(cls, webServlet.name(), properties); String servletFQCN = cls.getName(); LOGGER.info("Registering OSGi Servlet: [{}]", servletFQCN); return ctx.registerService(Servlet.class, servlet, properties); }
From source file:com.adeptj.runtime.common.Servlets.java
public static ServiceRegistration<Servlet> osgiServlet(BundleContext ctx, HttpServlet errorServlet, List<String> errors) { Class<? extends HttpServlet> cls = errorServlet.getClass(); WebServlet webServlet = checkWebServletAnnotation(cls); Dictionary<String, Object> properties = new Hashtable<>(); // NOSONAR properties.put(HTTP_WHITEBOARD_SERVLET_ERROR_PAGE, errors); // Apply this ErrorServlet to all the ServletContext instances registered with OSGi. properties.put(HTTP_WHITEBOARD_CONTEXT_SELECT, ALL_CONTEXT_SELECT_FILTER); properties.put(HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED, webServlet.asyncSupported()); handleInitParams(webServlet, properties); String servletName = resolveServletName(cls, webServlet.name(), properties); LOGGER.info("Registering OSGi ErrorServlet: [{}]", servletName); return ctx.registerService(Servlet.class, errorServlet, properties); }
From source file:io.adeptj.runtime.common.Servlets.java
public static ServiceRegistration<Servlet> osgiServlet(BundleContext ctx, HttpServlet errorServlet, List<String> errors) { Class<? extends HttpServlet> cls = errorServlet.getClass(); WebServlet webServlet = checkWebServletAnnotation(cls); Dictionary<String, Object> properties = new Hashtable<>(); // NOSONAR properties.put(HTTP_WHITEBOARD_SERVLET_ERROR_PAGE, errors); // Apply this ErrorServlet to all the ServletContext instances registered with OSGi. properties.put(HTTP_WHITEBOARD_CONTEXT_SELECT, ALL_CONTEXT_SELECT_FILTER); properties.put(HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED, webServlet.asyncSupported()); handleInitParams(webServlet, properties); String servletName = handleName(cls, webServlet.name(), properties); LOGGER.info("Registering OSGi ErrorHandler: [{}]", servletName); return ctx.registerService(Servlet.class, errorServlet, properties); }
From source file:com.grantedbyme.example.ServletUtils.java
public static GrantedByMe getSDK(HttpServlet context) throws IOException { // read private key String privateKey = null;//w w w .j av a 2s. co m InputStream privateKeyInputStream = context.getClass().getResourceAsStream("/private_key.pem"); try { privateKey = IOUtils.toString(privateKeyInputStream); } finally { privateKeyInputStream.close(); } // read server key String serverKey = null; InputStream serverKeyInputStream = context.getClass().getResourceAsStream("/server_key.pem"); try { serverKey = IOUtils.toString(serverKeyInputStream); } finally { serverKeyInputStream.close(); } // _log(serverKey); // initialize BouncyCastle security provider Security.insertProviderAt(new org.bouncycastle.jce.provider.BouncyCastleProvider(), 0); // create sdk GrantedByMe sdk = new GrantedByMe(privateKey, serverKey); // Create a trust manager that does not validate certificate chains TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { //No need to implement. } public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { //No need to implement. } } }; // Install the all-trusting trust manager try { SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } catch (Exception e) { e.printStackTrace(); } // set SDK parameters sdk.apiURL = "https://api-dev.grantedby.me/v1/service/"; //sdk.isDebug = true; return sdk; }
From source file:net.arnx.jsonic.web.extension.SpringContainer.java
@Override public void init(HttpServlet servlet) throws ServletException { super.init(servlet); this.log = LogFactory.getLog(servlet.getClass()); appContext = WebApplicationContextUtils.getWebApplicationContext(context); }
From source file:nu.mine.kino.web.JSONICContainer.java
@Override public void init(HttpServlet servlet) throws ServletException { super.init(servlet); this.log = LogFactory.getLog(servlet.getClass()); appContext = WebApplicationContextUtils.getWebApplicationContext(context); }
From source file:org.commoncrawl.server.ServletLauncher.java
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { ServletRegistry theRegistry = null;// w w w. ja va 2 s. co m synchronized (this) { theRegistry = registry; if (theRegistry == null) { LOG.info("Querying for Registry"); String registryClass = getInitParameter(SERVLET_REGISTRY_KEY); LOG.info("Registry Class is:" + registryClass); if (registryClass != null) { try { LOG.info("Loading Registry Class"); Class<ServletRegistry> classObject = (Class<ServletRegistry>) Thread.currentThread() .getContextClassLoader().loadClass(registryClass); LOG.info("Instantiating Registry Class"); registry = classObject.newInstance(); theRegistry = registry; } catch (ClassNotFoundException e) { LOG.error(StringUtils.stringifyException(e)); } catch (InstantiationException e) { LOG.error(StringUtils.stringifyException(e)); } catch (IllegalAccessException e) { LOG.error(StringUtils.stringifyException(e)); } if (registry == null) { LOG.error("Failed to instantiate reigstry!"); } } } } if (theRegistry != null) { HttpServlet servlet = theRegistry.getServletForURI(req.getRequestURI()); if (servlet != null) { LOG.info("Dispatching to servlet:" + servlet.getClass().getCanonicalName()); servlet.service(req, resp); } else { Request baseRequest = (Request) req; baseRequest.setHandled(false); // super.service(req, resp); } } }
From source file:org.openmrs.module.web.WebModuleUtil.java
/** * This method will find and cache this module's servlets (so that it doesn't have to look them * up every time)//from w w w . j a v a2 s. com * * @param mod * @param servletContext the servlet context */ public static void loadServlets(Module mod, ServletContext servletContext) { Element rootNode = mod.getConfig().getDocumentElement(); NodeList servletTags = rootNode.getElementsByTagName("servlet"); for (int i = 0; i < servletTags.getLength(); i++) { Node node = servletTags.item(i); NodeList childNodes = node.getChildNodes(); String name = "", className = ""; for (int j = 0; j < childNodes.getLength(); j++) { Node childNode = childNodes.item(j); if ("servlet-name".equals(childNode.getNodeName())) { if (childNode.getTextContent() != null) { name = childNode.getTextContent().trim(); } } else if ("servlet-class".equals(childNode.getNodeName()) && childNode.getTextContent() != null) { className = childNode.getTextContent().trim(); } } if (name.length() == 0 || className.length() == 0) { log.warn("both 'servlet-name' and 'servlet-class' are required for the 'servlet' tag. Given '" + name + "' and '" + className + "' for module " + mod.getName()); continue; } HttpServlet httpServlet = null; try { httpServlet = (HttpServlet) ModuleFactory.getModuleClassLoader(mod).loadClass(className) .newInstance(); } catch (ClassNotFoundException e) { log.warn("Class not found for servlet " + name + " for module " + mod.getName(), e); continue; } catch (IllegalAccessException e) { log.warn("Class cannot be accessed for servlet " + name + " for module " + mod.getName(), e); continue; } catch (InstantiationException e) { log.warn("Class cannot be instantiated for servlet " + name + " for module " + mod.getName(), e); continue; } try { log.debug("Initializing " + name + " servlet. - " + httpServlet + "."); ServletConfig servletConfig = new ModuleServlet.SimpleServletConfig(name, servletContext); httpServlet.init(servletConfig); } catch (Exception e) { log.warn("Unable to initialize servlet: ", e); throw new ModuleException("Unable to initialize servlet: " + httpServlet, mod.getModuleId(), e); } // don't allow modules to overwrite servlets of other modules. HttpServlet otherServletUsingSameName = moduleServlets.get(name); if (otherServletUsingSameName != null) { //log.debug("A servlet mapping with name " + name + " already exists. " + mod.getModuleId() + "'s servlet is overwriting it"); String otherServletName = otherServletUsingSameName.getClass().getPackage() + "." + otherServletUsingSameName.getClass().getName(); throw new ModuleException("A servlet mapping with name " + name + " is already in use and pointing at: " + otherServletName + " from another installed module and this module is trying" + " to use that same name. Either the module attempting to be installed (" + mod.getModuleId() + ") will not work or the other one will not. Please consult the developers of these two" + " modules to sort this out."); } log.debug("Caching the " + name + " servlet."); moduleServlets.put(name, httpServlet); } }
From source file:org.polymap.core.http.HttpServiceTracker.java
protected void init() { assert httpService != null; // servlet extensions ****** IConfigurationElement[] exts = Platform.getExtensionRegistry() .getConfigurationElementsFor(SERVLETS_EXTENSION_POINT_ID); log.debug("servlet extensions found: " + exts.length); for (IConfigurationElement ext : exts) { try {//from w w w .j a v a2 s . c o m String path = ext.getAttribute("path"); String contextPath = ext.getAttribute("contextPath"); if (contextPath != null && !contextPath.startsWith("/")) { contextPath = "/" + contextPath; } HttpServlet servlet = (HttpServlet) ext.createExecutableExtension("class"); httpService.registerServlet(path, servlet, null, null); log.debug(" context: " + contextPath + " :" + servlet.getClass().getName()); } catch (Exception e) { CorePlugin.logError("Error while starting servlet extension: " + ext.getName(), log, e); } } }