List of usage examples for java.lang Class isInterface
@HotSpotIntrinsicCandidate public native boolean isInterface();
From source file:com.web.server.JarDeployer.java
/** * This method implements the jar deployer which configures the executor services. * Frequently monitors the deploy directory and configures the executor services map * once the jar is deployed in deploy directory and reconfigures if the jar is modified and * placed in the deploy directory./*from www . j a v a 2s . c o m*/ */ public void run() { StandardFileSystemManager fsManager = new StandardFileSystemManager(); try { fsManager.init(); DefaultFileReplicator replicator = new DefaultFileReplicator(new File(cacheDir)); //fsManager.setReplicator(new PrivilegedFileReplicator(replicator)); fsManager.setTemporaryFileStore(replicator); } catch (FileSystemException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } File file = new File(scanDirectory.split(";")[0]); File[] files = file.listFiles(); CopyOnWriteArrayList<String> classList = new CopyOnWriteArrayList<String>(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) continue; //Long lastModified=(Long) fileMap.get(files[i].getName()); if (files[i].getName().endsWith(".jar")) { String filePath = files[i].getAbsolutePath(); FileObject jarFile = null; try { jarFile = fsManager.resolveFile("jar:" + filePath); } catch (FileSystemException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //logger.info("filePath"+filePath); filePath = filePath.substring(0, filePath.toLowerCase().lastIndexOf(".jar")); WebClassLoader customClassLoader = null; try { URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader(); URL[] urls = loader.getURLs(); try { customClassLoader = new WebClassLoader(urls); System.out.println(customClassLoader.geturlS()); new WebServer().addURL(new URL("file:/" + files[i].getAbsolutePath()), customClassLoader); CopyOnWriteArrayList<String> jarList = new CopyOnWriteArrayList(); getUsersJars(new File(libDir), jarList); for (String jarFilePath : jarList) new WebServer().addURL(new URL("file:/" + jarFilePath.replace("\\", "/")), customClassLoader); System.out.println("deploy=" + customClassLoader.geturlS()); this.urlClassLoaderMap.put(scanDirectory + "/" + files[i].getName(), customClassLoader); jarsDeployed.add(files[i].getName()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(urlClassLoaderMap); getChildren(jarFile, classList); } catch (FileSystemException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } for (int classCount = 0; classCount < classList.size(); classCount++) { String classwithpackage = classList.get(classCount).substring(0, classList.get(classCount).indexOf(".class")); classwithpackage = classwithpackage.replace("/", "."); System.out.println("classList:" + classwithpackage.replace("/", ".")); try { if (!classwithpackage.contains("$")) { Class executorServiceClass = customClassLoader.loadClass(classwithpackage); //System.out.println("executor class in ExecutorServicesConstruct"+executorServiceClass); //System.out.println(); if (!executorServiceClass.isInterface()) { Annotation[] classServicesAnnot = executorServiceClass.getDeclaredAnnotations(); if (classServicesAnnot != null) { for (int annotcount = 0; annotcount < classServicesAnnot.length; annotcount++) { if (classServicesAnnot[annotcount] instanceof RemoteCall) { RemoteCall remoteCall = (RemoteCall) classServicesAnnot[annotcount]; //registry.unbind(remoteCall.servicename()); System.out.println(remoteCall.servicename().trim()); try { //for(int count=0;count<500;count++){ RemoteInterface reminterface = (RemoteInterface) UnicastRemoteObject .exportObject((Remote) executorServiceClass.newInstance(), 2004); registry.rebind(remoteCall.servicename().trim(), reminterface); //} } catch (Exception ex) { ex.printStackTrace(); } } } } } Method[] methods = executorServiceClass.getDeclaredMethods(); for (Method method : methods) { Annotation[] annotations = method.getDeclaredAnnotations(); for (Annotation annotation : annotations) { if (annotation instanceof ExecutorServiceAnnot) { ExecutorServiceAnnot executorServiceAnnot = (ExecutorServiceAnnot) annotation; ExecutorServiceInfo executorServiceInfo = new ExecutorServiceInfo(); executorServiceInfo.setExecutorServicesClass(executorServiceClass); executorServiceInfo.setMethod(method); executorServiceInfo.setMethodParams(method.getParameterTypes()); //System.out.println("method="+executorServiceAnnot.servicename()); //System.out.println("method info="+executorServiceInfo); //if(servicesMap.get(executorServiceAnnot.servicename())==null)throw new Exception(); executorServiceMap.put(executorServiceAnnot.servicename(), executorServiceInfo); } } } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } ClassLoaderUtil.closeClassLoader(customClassLoader); try { jarFile.close(); } catch (FileSystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } fsManager.closeFileSystem(jarFile.getFileSystem()); } } fsManager.close(); fsManager = new StandardFileSystemManager(); try { DefaultFileReplicator replicator = new DefaultFileReplicator(new File(cacheDir)); //fsManager.setReplicator(new PrivilegedFileReplicator(replicator)); fsManager.setTemporaryFileStore(replicator); } catch (FileSystemException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } JarFileListener jarFileListener = new JarFileListener(executorServiceMap, libDir, urlClassLoaderMap, jarsDeployed); DefaultFileMonitor fm = new DefaultFileMonitor(jarFileListener); jarFileListener.setFm(fm); FileObject listendir = null; String[] dirsToScan = scanDirectory.split(";"); try { FileSystemOptions opts = new FileSystemOptions(); FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true); fsManager.init(); for (String dir : dirsToScan) { if (dir.startsWith("ftp://")) { listendir = fsManager.resolveFile(dir, opts); } else { listendir = fsManager.resolveFile(dir); } fm.addFile(listendir); } } catch (FileSystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } fm.setRecursive(true); fm.setDelay(3000); fm.start(); //fsManager.close(); }
From source file:org.apache.bval.jsr.ApacheValidatorFactory.java
/** * Return an object of the specified type to allow access to the * provider-specific API. If the Bean Validation provider implementation * does not support the specified class, the ValidationException is thrown. * * @param type the class of the object to be returned. * @return an instance of the specified class * @throws ValidationException if the provider does not support the call. *///from w w w. j av a 2 s.c o m public <T> T unwrap(final Class<T> type) { if (type.isInstance(this)) { @SuppressWarnings("unchecked") final T result = (T) this; return result; } // FIXME 2011-03-27 jw: // This code is unsecure. // It should allow only a fixed set of classes. // Can't fix this because don't know which classes this method should support. if (!(type.isInterface() || Modifier.isAbstract(type.getModifiers()))) { return newInstance(type); } try { final Class<?> cls = ClassUtils.getClass(type.getName() + "Impl"); if (type.isAssignableFrom(cls)) { @SuppressWarnings("unchecked") T result = (T) newInstance(cls); return result; } } catch (ClassNotFoundException e) { // do nothing } throw new ValidationException("Type " + type + " not supported"); }
From source file:org.apache.openjpa.persistence.PersistenceMetaDataDefaults.java
/** * Determines the access type for the given class by placement of * annotations on field or getter method. Does not consult the * super class./*from w ww .j ava 2 s . c om*/ * * Annotation can be placed on either fields or getters but not on both. * If no field or getter is annotated then UNKNOWN access code is returned. */ private int determineImplicitAccessType(Class<?> cls, OpenJPAConfiguration conf) { if (cls.isInterface()) // Managed interfaces return AccessCode.PROPERTY; Field[] allFields = AccessController.doPrivileged(J2DoPrivHelper.getDeclaredFieldsAction(cls)); Method[] methods = AccessController.doPrivileged(J2DoPrivHelper.getDeclaredMethodsAction(cls)); List<Field> fields = filter(allFields, new TransientFilter(true)); /* * OpenJPA 1.x permitted private properties to be persistent. This is * contrary to the JPA 1.0 specification, which states that persistent * properties must be public or protected. OpenJPA 2.0+ will adhere * to the specification by default, but provides a compatibility * option to provide pre-2.0 behavior. */ getterFilter.setIncludePrivate(conf.getCompatibilityInstance().getPrivatePersistentProperties()); List<Method> getters = filter(methods, getterFilter); if (fields.isEmpty() && getters.isEmpty()) return AccessCode.EMPTY; fields = filter(fields, annotatedFilter); getters = filter(getters, annotatedFilter); List<Method> setters = filter(methods, setterFilter); getters = matchGetterAndSetter(getters, setters); boolean mixed = !fields.isEmpty() && !getters.isEmpty(); if (mixed) throw new UserException(_loc.get("access-mixed", cls, toFieldNames(fields), toMethodNames(getters))); if (!fields.isEmpty()) { return AccessCode.FIELD; } if (!getters.isEmpty()) { return AccessCode.PROPERTY; } return AccessCode.UNKNOWN; }
From source file:org.amplafi.flow.flowproperty.FlowPropertyDefinitionImpl.java
/** * @return//from w w w . j a v a 2 s . co m */ private boolean isDefaultByClassAvailable() { if (this.autoCreate != null) { return getBoolean(this.autoCreate); } if (!getDataClassDefinition().isCollection()) { Class<?> dataClass = getDataClassDefinition().getDataClass(); if (dataClass.isPrimitive()) { return true; } else if (dataClass.isInterface() || dataClass.isEnum()) { return false; } } return false; }
From source file:com.google.dexmaker.ProxyBuilder.java
public ProxyBuilder<T> implementing(Class<?>... interfaces) { if (interfaces == null || interfaces.length == 0) { return this; }/*from w w w . jav a 2 s.co m*/ Class[] face = baseClass.getInterfaces(); List<Class> classes = Arrays.asList(face); for (Class<?> i : interfaces) { if (i == null || classes.contains(i)) { continue; } if (!i.isInterface()) { throw new IllegalArgumentException("Not an interface: " + i.getName()); } this.interfaces.add(i); } return this; }
From source file:org.evosuite.setup.TestClusterGenerator.java
public static Set<Class<?>> getConcreteClasses(Class<?> clazz, InheritanceTree inheritanceTree) { // Some special cases if (clazz.equals(java.util.Map.class)) return getConcreteClassesMap(); else if (clazz.equals(java.util.List.class)) return getConcreteClassesList(); else if (clazz.equals(java.util.Set.class)) return getConcreteClassesSet(); else if (clazz.equals(java.util.Collection.class)) return getConcreteClassesList(); else if (clazz.equals(java.util.Iterator.class)) // We don't want to explicitly create iterators // This would only pull in java.util.Scanner, the only // concrete subclass return new LinkedHashSet<Class<?>>(); else if (clazz.equals(java.util.ListIterator.class)) // We don't want to explicitly create iterators return new LinkedHashSet<Class<?>>(); else if (clazz.equals(java.io.Serializable.class)) return new LinkedHashSet<Class<?>>(); else if (clazz.equals(java.lang.Comparable.class)) return getConcreteClassesComparable(); else if (clazz.equals(java.util.Comparator.class)) return new LinkedHashSet<Class<?>>(); Set<Class<?>> actualClasses = new LinkedHashSet<Class<?>>(); if (Modifier.isAbstract(clazz.getModifiers()) || Modifier.isInterface(clazz.getModifiers()) || clazz.equals(Enum.class)) { Set<String> subClasses = inheritanceTree.getSubclasses(clazz.getName()); logger.debug("Subclasses of {}: {}", clazz.getName(), subClasses); Map<String, Integer> classDistance = new HashMap<String, Integer>(); int maxDistance = -1; String name = clazz.getName(); if (clazz.equals(Enum.class)) { name = Properties.TARGET_CLASS; }/* ww w . jav a2 s. c o m*/ for (String subClass : subClasses) { int distance = getPackageDistance(subClass, name); classDistance.put(subClass, distance); maxDistance = Math.max(distance, maxDistance); } int distance = 0; while (actualClasses.isEmpty() && distance <= maxDistance) { logger.debug(" Current distance: {}", distance); for (String subClass : subClasses) { if (classDistance.get(subClass) == distance) { try { Class<?> subClazz = Class.forName(subClass, false, TestGenerationContext.getInstance().getClassLoaderForSUT()); if (!canUse(subClazz)) continue; if (subClazz.isInterface()) continue; if (Modifier.isAbstract(subClazz.getModifiers())) { if (!hasStaticGenerator(subClazz)) continue; } Class<?> mock = MockList.getMockClass(subClazz.getCanonicalName()); if (mock != null) { /* * If we are mocking this class, then such class should not be used * in the generated JUnit test cases, but rather its mock. */ logger.debug("Adding mock {} instead of {}", mock, clazz); subClazz = mock; } else { if (!checkIfCanUse(subClazz.getCanonicalName())) { continue; } } actualClasses.add(subClazz); } catch (ClassNotFoundException e) { logger.error("Problem for {}. Class not found: {}", Properties.TARGET_CLASS, subClass, e); logger.error("Removing class from inheritance tree"); inheritanceTree.removeClass(subClass); } } } distance++; } if (hasStaticGenerator(clazz)) { actualClasses.add(clazz); } if (actualClasses.isEmpty()) { logger.info("Don't know how to instantiate abstract class {}", clazz.getName()); } } else { actualClasses.add(clazz); } logger.debug("Subclasses of {}: {}", clazz.getName(), actualClasses); return actualClasses; }
From source file:net.firejack.platform.core.utils.Factory.java
public Class getGenericParameterClass(Class actualClass, Class genericClass, int parameterIndex) { if (!genericClass.isAssignableFrom(actualClass) || genericClass.equals(actualClass)) { throw new IllegalArgumentException( "Class " + genericClass.getName() + " is not a superclass of " + actualClass.getName() + "."); }//from www. jav a 2s . co m Stack<ParameterizedType> types = new Stack<ParameterizedType>(); Class clazz = actualClass; while (true) { Type currentType = genericClass.isInterface() ? getGenericInterface(clazz, genericClass) : clazz.getGenericSuperclass(); Type rawType; if (currentType instanceof ParameterizedType) { ParameterizedType type = (ParameterizedType) currentType; types.push(type); rawType = type.getRawType(); } else { types.clear(); rawType = currentType; } if (!rawType.equals(genericClass)) { clazz = (Class) rawType; } else { break; } } if (types.isEmpty()) { return (Class) genericClass.getTypeParameters()[parameterIndex].getGenericDeclaration(); } Type result = types.pop().getActualTypeArguments()[parameterIndex]; while (result instanceof TypeVariable && !types.empty()) { int actualArgumentIndex = getParameterTypeDeclarationIndex((TypeVariable) result); ParameterizedType type = types.pop(); result = type.getActualTypeArguments()[actualArgumentIndex]; } if (result instanceof TypeVariable) { throw new IllegalStateException("Unable to resolve type variable " + result + "." + " Try to replace instances of parametrized class with its non-parameterized subtype."); } if (result instanceof ParameterizedType) { result = ((ParameterizedType) result).getRawType(); } if (result == null) { throw new IllegalStateException( "Unable to determine actual parameter type for " + actualClass.getName() + "."); } if (!(result instanceof Class)) { throw new IllegalStateException( "Actual parameter type for " + actualClass.getName() + " is not a Class."); } return (Class) result; }
From source file:org.interreg.docexplore.GeneralConfigPanel.java
String browseClasses(File file) { try {/* w ww. j av a 2 s . c o m*/ List<Class<?>> metaDataPlugins = new LinkedList<Class<?>>(); List<Class<?>> analysisPlugins = new LinkedList<Class<?>>(); List<Class<?>> clientPlugins = new LinkedList<Class<?>>(); List<Class<?>> serverPlugins = new LinkedList<Class<?>>(); List<Class<?>> inputPlugins = new LinkedList<Class<?>>(); List<URL> urls = Startup.extractDependencies(file.getName().substring(0, file.getName().length() - 4), file.getName()); urls.add(file.toURI().toURL()); URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[] {}), this.getClass().getClassLoader()); JarFile jarFile = new JarFile(file); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (!entry.getName().endsWith(".class") || entry.getName().indexOf('$') > 0) continue; String className = entry.getName().substring(0, entry.getName().length() - 6).replace('/', '.'); Class<?> clazz = null; try { clazz = loader.loadClass(className); System.out.println("Reading " + className); } catch (NoClassDefFoundError e) { System.out.println("Couldn't read " + className); } if (clazz == null) continue; if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) continue; if (MetaDataPlugin.class.isAssignableFrom(clazz)) metaDataPlugins.add(clazz); if (AnalysisPlugin.class.isAssignableFrom(clazz)) analysisPlugins.add(clazz); if (ClientPlugin.class.isAssignableFrom(clazz)) clientPlugins.add(clazz); if (ServerPlugin.class.isAssignableFrom(clazz)) serverPlugins.add(clazz); if (InputPlugin.class.isAssignableFrom(clazz)) inputPlugins.add(clazz); } jarFile.close(); @SuppressWarnings("unchecked") Pair<String, String>[] classes = new Pair[metaDataPlugins.size() + analysisPlugins.size() + clientPlugins.size() + serverPlugins.size() + inputPlugins.size()]; if (classes.length == 0) throw new Exception("Invalid plugin (no entry points were found)."); int cnt = 0; for (Class<?> clazz : metaDataPlugins) classes[cnt++] = new Pair<String, String>(clazz.getName(), "MetaData plugin") { public String toString() { return first + " (" + second + ")"; } }; for (Class<?> clazz : analysisPlugins) classes[cnt++] = new Pair<String, String>(clazz.getName(), "Analysis plugin") { public String toString() { return first + " (" + second + ")"; } }; for (Class<?> clazz : clientPlugins) classes[cnt++] = new Pair<String, String>(clazz.getName(), "Reader client plugin") { public String toString() { return first + " (" + second + ")"; } }; for (Class<?> clazz : serverPlugins) classes[cnt++] = new Pair<String, String>(clazz.getName(), "Reader server plugin") { public String toString() { return first + " (" + second + ")"; } }; for (Class<?> clazz : inputPlugins) classes[cnt++] = new Pair<String, String>(clazz.getName(), "Reader input plugin") { public String toString() { return first + " (" + second + ")"; } }; @SuppressWarnings("unchecked") Pair<String, String> res = (Pair<String, String>) JOptionPane.showInputDialog(this, "Please select an entry point for the plugin:", "Plugin entry point", JOptionPane.QUESTION_MESSAGE, null, classes, classes[0]); if (res != null) return res.first; } catch (Throwable e) { ErrorHandler.defaultHandler.submit(e); } return null; }
From source file:org.eclipse.wb.internal.core.model.property.event.ListenerMethodProperty.java
/** * @return the new inner {@link TypeDeclaration} for event listener. *//*from w ww . j a va 2 s . c o m*/ private TypeDeclaration addListenerInnerClassDeclaration() throws Exception { // prepare target BodyDeclarationTarget target = getListenerInnerClassTarget(); // prepare header String headerSource; if (m_listener.hasAdapter()) { headerSource = " extends " + m_listener.getAdapter().getCanonicalName(); } else { Class<?> listenerType = m_listener.getInterface(); if (listenerType.isInterface()) { headerSource = " implements " + getListenerTypeNameSource(); } else { headerSource = " extends " + getListenerTypeNameSource(); } } // add inner class List<String> lines = ImmutableList.of("private class " + createInnerClassName() + headerSource + " {", "}"); return m_javaInfo.getEditor().addTypeDeclaration(lines, target); }
From source file:org.ops4j.pax.web.service.jetty.internal.JettyServerWrapper.java
@SuppressWarnings("unchecked") private HttpServiceContext addContext(final ContextModel model) { Bundle bundle = model.getBundle();// ww w.jav a2s. c o m BundleContext bundleContext = BundleUtils.getBundleContext(bundle); // scan for ServletContainerInitializers Set<Bundle> bundlesInClassSpace = ClassPathUtil.getBundlesInClassSpace(bundle, new HashSet<Bundle>()); if (jettyBundle != null) { ClassPathUtil.getBundlesInClassSpace(jettyBundle, bundlesInClassSpace); } for (URL u : ClassPathUtil.findResources(bundlesInClassSpace, "/META-INF/services", "javax.servlet.ServletContainerInitializer", true)) { try { InputStream is = u.openStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); // only the first line is read, it contains the name of the // class. String className = reader.readLine(); LOG.info("will add {} to ServletContainerInitializers", className); if (className.endsWith("JasperInitializer")) { LOG.info("Skipt {}, because specialized handler will be present", className); continue; } Class<?> initializerClass; try { initializerClass = bundle.loadClass(className); } catch (ClassNotFoundException ignore) { initializerClass = jettyBundle.loadClass(className); } // add those to the model contained ones Map<ServletContainerInitializer, Set<Class<?>>> containerInitializers = model .getContainerInitializers(); ServletContainerInitializer initializer = (ServletContainerInitializer) initializerClass .newInstance(); if (containerInitializers == null) { containerInitializers = new HashMap<ServletContainerInitializer, Set<Class<?>>>(); model.setContainerInitializers(containerInitializers); } Set<Class<?>> setOfClasses = new HashSet<Class<?>>(); // scan for @HandlesTypes HandlesTypes handlesTypes = initializerClass.getAnnotation(HandlesTypes.class); if (handlesTypes != null) { Class<?>[] classes = handlesTypes.value(); for (Class<?> klass : classes) { boolean isAnnotation = klass.isAnnotation(); boolean isInteraface = klass.isInterface(); if (isAnnotation) { try { BundleAnnotationFinder baf = new BundleAnnotationFinder( packageAdminTracker.getService(), bundle); List<Class<?>> annotatedClasses = baf .findAnnotatedClasses((Class<? extends Annotation>) klass); setOfClasses.addAll(annotatedClasses); } catch (Exception e) { LOG.warn("Failed to find annotated classes for ServletContainerInitializer", e); } } else if (isInteraface) { BundleAssignableClassFinder basf = new BundleAssignableClassFinder( packageAdminTracker.getService(), new Class[] { klass }, bundle); Set<String> interfaces = basf.find(); for (String interfaceName : interfaces) { setOfClasses.add(bundle.loadClass(interfaceName)); } } else { // class BundleAssignableClassFinder basf = new BundleAssignableClassFinder( packageAdminTracker.getService(), new Class[] { klass }, bundle); Set<String> classNames = basf.find(); for (String klassName : classNames) { setOfClasses.add(bundle.loadClass(klassName)); } } } } containerInitializers.put(initializer, setOfClasses); LOG.info("added ServletContainerInitializer: {}", className); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IOException e) { LOG.warn( "failed to parse and instantiate of javax.servlet.ServletContainerInitializer in classpath"); } } HttpServiceContext context = new HttpServiceContext((HandlerContainer) getHandler(), model.getContextParams(), getContextAttributes(bundleContext), model.getContextName(), model.getHttpContext(), model.getAccessControllerContext(), model.getContainerInitializers(), model.getJettyWebXmlURL(), model.getVirtualHosts()); context.setClassLoader(model.getClassLoader()); Integer modelSessionTimeout = model.getSessionTimeout(); if (modelSessionTimeout == null) { modelSessionTimeout = sessionTimeout; } String modelSessionCookie = model.getSessionCookie(); if (modelSessionCookie == null) { modelSessionCookie = sessionCookie; } String modelSessionDomain = model.getSessionDomain(); if (modelSessionDomain == null) { modelSessionDomain = sessionDomain; } String modelSessionPath = model.getSessionPath(); if (modelSessionPath == null) { modelSessionPath = sessionPath; } String modelSessionUrl = model.getSessionUrl(); if (modelSessionUrl == null) { modelSessionUrl = sessionUrl; } Boolean modelSessionCookieHttpOnly = model.getSessionCookieHttpOnly(); if (modelSessionCookieHttpOnly == null) { modelSessionCookieHttpOnly = sessionCookieHttpOnly; } Boolean modelSessionSecure = model.getSessionCookieSecure(); if (modelSessionSecure == null) { modelSessionSecure = sessionCookieSecure; } String workerName = model.getSessionWorkerName(); if (workerName == null) { workerName = sessionWorkerName; } configureSessionManager(context, modelSessionTimeout, modelSessionCookie, modelSessionDomain, modelSessionPath, modelSessionUrl, modelSessionCookieHttpOnly, modelSessionSecure, workerName, lazyLoad, storeDirectory); if (model.getRealmName() != null && model.getAuthMethod() != null) { configureSecurity(context, model.getRealmName(), model.getAuthMethod(), model.getFormLoginPage(), model.getFormErrorPage()); } configureJspConfigDescriptor(context, model); LOG.debug("Added servlet context: " + context); if (isStarted()) { try { LOG.debug("(Re)starting servlet contexts..."); // start the server handler if not already started Handler serverHandler = getHandler(); if (!serverHandler.isStarted() && !serverHandler.isStarting()) { serverHandler.start(); } // if the server handler is a handler collection, seems like // jetty will not automatically // start inner handlers. So, force the start of the created // context if (!context.isStarted() && !context.isStarting()) { LOG.debug("Registering ServletContext as service. "); Dictionary<String, String> properties = new Hashtable<String, String>(); properties.put("osgi.web.symbolicname", bundle.getSymbolicName()); Dictionary<?, ?> headers = bundle.getHeaders(); String version = (String) headers.get(Constants.BUNDLE_VERSION); if (version != null && version.length() > 0) { properties.put("osgi.web.version", version); } // Context servletContext = context.getServletContext(); String webContextPath = context.getContextPath(); properties.put("osgi.web.contextpath", webContextPath); context.registerService(bundleContext, properties); LOG.debug("ServletContext registered as service. "); } // CHECKSTYLE:OFF } catch (Exception ignore) { LOG.error("Could not start the servlet context for http context [" + model.getHttpContext() + "]", ignore); if (ignore instanceof MultiException) { LOG.error("MultiException found: "); MultiException mex = (MultiException) ignore; List<Throwable> throwables = mex.getThrowables(); for (Throwable throwable : throwables) { LOG.error(throwable.getMessage()); } } } // CHECKSTYLE:ON } return context; }