当前位置: 首页>>代码示例>>Java>>正文


Java Context类代码示例

本文整理汇总了Java中javax.naming.Context的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Context类属于javax.naming包,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doGet

import javax.naming.Context; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    resp.setContentType("text/plain;UTF-8");
    PrintWriter out = resp.getWriter();

    try {
        Context ctx = new InitialContext();
        Object obj = ctx.lookup("java:comp/env/bug50351");
        TesterObject to = (TesterObject) obj;
        out.print(to.getFoo());
    } catch (NamingException ne) {
        ne.printStackTrace(out);
    }
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:17,代码来源:TestNamingContext.java

示例2: registerDataSource

import javax.naming.Context; //导入依赖的package包/类
/**
 * This method is separated from the rest of the example since you normally
 * would NOT register a JDBC driver in your code. It would likely be
 * configered into your naming and directory service using some GUI.
 * 
 * @throws Exception
 *             if an error occurs
 */
private void registerDataSource() throws Exception {
    this.tempDir = File.createTempFile("jnditest", null);
    this.tempDir.delete();
    this.tempDir.mkdir();
    this.tempDir.deleteOnExit();

    com.mysql.jdbc.jdbc2.optional.MysqlDataSource ds;
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
    env.put(Context.PROVIDER_URL, this.tempDir.toURI().toString());
    this.ctx = new InitialContext(env);
    assertTrue("Naming Context not created", this.ctx != null);
    ds = new com.mysql.jdbc.jdbc2.optional.MysqlDataSource();
    ds.setUrl(dbUrl); // from BaseTestCase
    this.ctx.bind("_test", ds);
}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:25,代码来源:DataSourceTest.java

示例3: createSubcontext

import javax.naming.Context; //导入依赖的package包/类
@Override
public Context createSubcontext(Name name) throws NamingException {
	if (name.isEmpty())
		throw new InvalidNameException("Cannot bind empty name");

	Name nm = getMyComponents(name);
	String atom = nm.get(0);
	Object inter = iBindings.get(atom);

	if (nm.size() == 1) {
		if (inter != null)
			throw new NameAlreadyBoundException("Use rebind to override");

		Context child = createCtx(this, atom, iEnv);

		iBindings.put(atom, child);

		return child;
	} else {
		if (!(inter instanceof Context))
			throw new NotContextException(atom + " does not name a context");

		return ((Context) inter).createSubcontext(nm.getSuffix(1));
	}
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:26,代码来源:LocalContext.java

示例4: getNameParser

import javax.naming.Context; //导入依赖的package包/类
/**
 * Retrieves the parser associated with the named context. In a 
 * federation of namespaces, different naming systems will parse names 
 * differently. This method allows an application to get a parser for 
 * parsing names into their atomic components using the naming convention 
 * of a particular naming system. Within any single naming system, 
 * NameParser objects returned by this method must be equal (using the 
 * equals() test).
 * 
 * @param name the name of the context from which to get the parser
 * @return a name parser that can parse compound names into their atomic 
 * components
 * @exception NamingException if a naming exception is encountered
 */
public NameParser getNameParser(Name name)
    throws NamingException {

    while ((!name.isEmpty()) && (name.get(0).length() == 0))
        name = name.getSuffix(1);
    if (name.isEmpty())
        return nameParser;

    if (name.size() > 1) {
        Object obj = bindings.get(name.get(0));
        if (obj instanceof Context) {
            return ((Context) obj).getNameParser(name.getSuffix(1));
        } else {
            throw new NotContextException
                (sm.getString("namingContext.contextExpected"));
        }
    }

    return nameParser;

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:36,代码来源:NamingContext.java

示例5: main

import javax.naming.Context; //导入依赖的package包/类
public static void main(String[] args) throws NamingException {
	checkArgs(args);
	final Hashtable<String, String> jndiProperties = new Hashtable<>();
	jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
	final Context ic = new InitialContext(jndiProperties);

	Simple proxy = (Simple) ic.lookup("ejb:EAP71-PLAYGROUND-server/ejb/SimpleBean!" + Simple.class.getName());

	HashSet<String> serverList = new HashSet<>();

	for (int i = 0; i < 20; i++) {
		serverList.add(proxy.getJBossServerName());
	}

	if (serverList.size() > 1) {
		log.info("Server should be part of a cluster or multiple URL's as the invocation was executed on the following servers : " + serverList);
	} else if (serverList.size() == 1) {
		log.warning("Server is not part of a cluster with multiple nodes, or did not have multiple PROVIDER URL's, as the invocation was executed on a single server : " + new ArrayList<String>(serverList).get(0));
	} else {
		throw new RuntimeException("Unexpected result, no server list!");
	}
}
 
开发者ID:wfink,项目名称:jboss-eap7.1-playground,代码行数:23,代码来源:LegacyClusterJBossEjbClient.java

示例6: getObjectInstance

import javax.naming.Context; //导入依赖的package包/类
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
        Hashtable<?,?> environment) throws Exception {

    if (obj instanceof Reference) {
        Reference ref = (Reference)obj;
        String className = ref.getClassName();

        if (className == null) {
            throw new RuntimeException();
        }

        if (className.equals("org.apache.naming.resources.TesterObject")) {
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
            Class<?> clazz =
                cl.loadClass("org.apache.naming.resources.TesterObject");
            return clazz.newInstance();
        }
    }
    return null;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:22,代码来源:TesterFactory.java

示例7: connectToEJB

import javax.naming.Context; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <T> T connectToEJB(Class<T> remoteInterface, String userName,
        String password) throws Exception {
    try {
        props.put(Context.SECURITY_PRINCIPAL, userName);
        props.put(Context.SECURITY_CREDENTIALS, password);
        props.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.openejb.client.RemoteInitialContextFactory");
        props.put("java.naming.provider.url", "http://127.0.0.1:8080/tomee/ejb");
        props.put("openejb.authentication.realmName", "bss-realm");

        Context context = new InitialContext(props);
        T service = (T) context.lookup(remoteInterface.getName());
        return service;
    } catch (NamingException e) {
        throw new SaaSSystemException("Service lookup failed!", e);
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:18,代码来源:ServiceFactory.java

示例8: DefaultInstanceManager

import javax.naming.Context; //导入依赖的package包/类
public DefaultInstanceManager(Context context, Map<String, Map<String, String>> injectionMap,
		org.apache.catalina.Context catalinaContext, ClassLoader containerClassLoader) {
	classLoader = catalinaContext.getLoader().getClassLoader();
	privileged = catalinaContext.getPrivileged();
	this.containerClassLoader = containerClassLoader;
	ignoreAnnotations = catalinaContext.getIgnoreAnnotations();
	Log log = catalinaContext.getLogger();
	Set<String> classNames = new HashSet<String>();
	loadProperties(classNames, "org/apache/catalina/core/RestrictedServlets.properties",
			"defaultInstanceManager.restrictedServletsResource", log);
	loadProperties(classNames, "org/apache/catalina/core/RestrictedListeners.properties",
			"defaultInstanceManager.restrictedListenersResource", log);
	loadProperties(classNames, "org/apache/catalina/core/RestrictedFilters.properties",
			"defaultInstanceManager.restrictedFiltersResource", log);
	restrictedClasses = Collections.unmodifiableSet(classNames);
	this.context = context;
	this.injectionMap = injectionMap;
	this.postConstructMethods = catalinaContext.findPostConstructMethods();
	this.preDestroyMethods = catalinaContext.findPreDestroyMethods();
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:21,代码来源:DefaultInstanceManager.java

示例9: init

import javax.naming.Context; //导入依赖的package包/类
private void init() {

        if (!isAlwaysLookup()) {
            Context ctx = null;
            try {
                ctx = (props != null) ? new InitialContext(props) : new InitialContext(); 

                datasource = (DataSource) ctx.lookup(url);
            } catch (Exception e) {
                getLog().error(
                        "Error looking up datasource: " + e.getMessage(), e);
            } finally {
                if (ctx != null) {
                    try { ctx.close(); } catch(Exception ignore) {}
                }
            }
        }
    }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:JNDIConnectionProvider.java

示例10: process

import javax.naming.Context; //导入依赖的package包/类
@Override
public void process(SearchResult result) throws NamingException, ParseException
{
    try
    {
        doProcess(result);
    }
    finally
    {
        Object obj = result.getObject();
        
        if (obj != null && obj instanceof Context)
        {
            try
            {
                ((Context)obj).close();
            }
            catch (NamingException e)
            {
                logger.debug("error when closing result block context", e);
            }
            obj = null;
        }
        result = null;
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:27,代码来源:LDAPUserRegistry.java

示例11: listBindings

import javax.naming.Context; //导入依赖的package包/类
/**
 * Enumerates the names bound in the named context, along with the 
 * objects bound to them. The contents of any subcontexts are not 
 * included.
 * <p>
 * If a binding is added to or removed from this context, its effect on 
 * an enumeration previously returned is undefined.
 * 
 * @param name the name of the context to list
 * @return an enumeration of the bindings in this context. 
 * Each element of the enumeration is of type Binding.
 * @exception NamingException if a naming exception is encountered
 */
@Override
public NamingEnumeration<Binding> listBindings(Name name)
    throws NamingException {
    // Removing empty parts
    while ((!name.isEmpty()) && (name.get(0).length() == 0))
        name = name.getSuffix(1);
    if (name.isEmpty()) {
        return new NamingContextBindingsEnumeration(bindings.values().iterator(), this);
    }
    
    NamingEntry entry = bindings.get(name.get(0));
    
    if (entry == null) {
        throw new NameNotFoundException
            (sm.getString("namingContext.nameNotBound", name, name.get(0)));
    }
    
    if (entry.type != NamingEntry.CONTEXT) {
        throw new NamingException
            (sm.getString("namingContext.contextExpected"));
    }
    return ((Context) entry.value).listBindings(name.getSuffix(1));
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:37,代码来源:NamingContext.java

示例12: testBlockingTimeOut

import javax.naming.Context; //导入依赖的package包/类
@Test
public void testBlockingTimeOut() {
  try {
    Context ctx = cache.getJNDIContext();
    GemFireConnPooledDataSource ds =
        (GemFireConnPooledDataSource) ctx.lookup("java:/PooledDataSource");
    GemFireConnectionPoolManager provider =
        (GemFireConnectionPoolManager) ds.getConnectionProvider();
    ConnectionPoolCacheImpl poolCache =
        (ConnectionPoolCacheImpl) provider.getConnectionPoolCache();
    poolCache.getPooledConnectionFromPool();
    Thread.sleep(40000);
    if (!(poolCache.activeCache.isEmpty())) {
      fail("Clean-up on expiration not done");
    }
  } catch (Exception e) {
    fail("Exception occured in testBlockingTimeOut due to " + e);
    e.printStackTrace();
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:21,代码来源:CleanUpJUnitTest.java

示例13: getObjectInstance

import javax.naming.Context; //导入依赖的package包/类
/**
 * Create a new DataSource instance.
 * 
 * @param obj
 *            The reference object describing the DataSource
 */
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment)
		throws NamingException {
	Object result = super.getObjectInstance(obj, name, nameCtx, environment);
	// Can we process this request?
	if (result != null) {
		Reference ref = (Reference) obj;
		RefAddr userAttr = ref.get("username");
		RefAddr passAttr = ref.get("password");
		if (userAttr.getContent() != null && passAttr.getContent() != null) {
			result = wrapDataSource(result, userAttr.getContent().toString(), passAttr.getContent().toString());
		}
	}
	return result;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:22,代码来源:DataSourceLinkFactory.java

示例14: main

import javax.naming.Context; //导入依赖的package包/类
public static void main(String[] args) throws NamingException {
	checkArgs(args);
	
	Properties p = new Properties();
	
	p.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
	InitialContext ic = new WildFlyInitialContext(p);
	
	Simple proxy = (Simple) ic.lookup("ejb:EAP71-PLAYGROUND-server/ejb/SimpleBean!" + Simple.class.getName());
	
	try {
		proxy.logText("Simple invocation without security at " + new Date());
		log.info("Expected to work with the default configuration, to get a security failure remote the <local> element from the ApplicationRealm!");
	} catch (Exception e) {
		log.severe("Expected to fail if no <local> configuration in ApplicationRealm, unfortunately no good Exception");
		e.printStackTrace();
	}
}
 
开发者ID:wfink,项目名称:jboss-eap7.1-playground,代码行数:19,代码来源:SimpleWildFlyInitialContextClient.java

示例15: getInstance

import javax.naming.Context; //导入依赖的package包/类
/**
 * Retrieves an <code>APPlatformService</code> instance.
 * 
 * @return the service instance
 */
public static APPlatformService getInstance() {
    try {

        Properties p = new Properties();
        p.setProperty (Context.INITIAL_CONTEXT_FACTORY,"org.apache.openejb.client.LocalInitialContextFactory");

        InitialContext context = new InitialContext(p);
        Object lookup = context.lookup(JNDI_NAME);
        if (!APPlatformService.class.isAssignableFrom(lookup.getClass())) {
            throw new IllegalStateException(
                    "Failed to look up APPlatformService. The returned service is not implementing correct interface");
        }
        return (APPlatformService) lookup;
    } catch (NamingException e) {
        logger.error("Service lookup failed: " + JNDI_NAME);
        throw new IllegalStateException(
                "No valid platform service available", e);
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:25,代码来源:APPlatformServiceFactory.java


注:本文中的javax.naming.Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。