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


Java ContextResourceLink.setGlobal方法代码示例

本文整理汇总了Java中org.apache.catalina.deploy.ContextResourceLink.setGlobal方法的典型用法代码示例。如果您正苦于以下问题:Java ContextResourceLink.setGlobal方法的具体用法?Java ContextResourceLink.setGlobal怎么用?Java ContextResourceLink.setGlobal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.catalina.deploy.ContextResourceLink的用法示例。


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

示例1: testEnableNamingGlobal

import org.apache.catalina.deploy.ContextResourceLink; //导入方法依赖的package包/类
/**
 * Test for enabling JNDI and using global resources.
 */
@Test
public void testEnableNamingGlobal() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    // You can customise the context by calling its API

    // Enable JNDI - it is disabled by default
    tomcat.enableNaming();

    ContextEnvironment environment = new ContextEnvironment();
    environment.setType("java.lang.String");
    environment.setName("globalTest");
    environment.setValue("Tomcat User");
    tomcat.getServer().getGlobalNamingResources().addEnvironment(environment);

    ContextResourceLink link = new ContextResourceLink();
    link.setGlobal("globalTest");
    link.setName(HelloWorldJndi.JNDI_ENV_NAME);
    link.setType("java.lang.String");
    ctx.getNamingResources().addResourceLink(link);

    Tomcat.addServlet(ctx, "jndiServlet", new HelloWorldJndi());
    ctx.addServletMapping("/", "jndiServlet");

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() + "/");
    assertEquals("Hello, Tomcat User", res.toString());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:36,代码来源:TestTomcat.java

示例2: testEnableNamingGlobal

import org.apache.catalina.deploy.ContextResourceLink; //导入方法依赖的package包/类
/**
 * Test for enabling JNDI and using global resources.
 */
@Test
public void testEnableNamingGlobal() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // Must have a real docBase - just use temp
    org.apache.catalina.Context ctx =
        tomcat.addContext("", System.getProperty("java.io.tmpdir"));

    // You can customise the context by calling its API

    // Enable JNDI - it is disabled by default
    tomcat.enableNaming();

    ContextEnvironment environment = new ContextEnvironment();
    environment.setType("java.lang.String");
    environment.setName("globalTest");
    environment.setValue("Tomcat User");
    tomcat.getServer().getGlobalNamingResources().addEnvironment(environment);

    ContextResourceLink link = new ContextResourceLink();
    link.setGlobal("globalTest");
    link.setName(HelloWorldJndi.JNDI_ENV_NAME);
    ctx.getNamingResources().addResourceLink(link);

    Tomcat.addServlet(ctx, "jndiServlet", new HelloWorldJndi());
    ctx.addServletMapping("/", "jndiServlet");

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() + "/");
    assertEquals("Hello, Tomcat User", res.toString());
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:36,代码来源:TestTomcat.java

示例3: testEnableNamingGlobal

import org.apache.catalina.deploy.ContextResourceLink; //导入方法依赖的package包/类
/** 
 * Test for enabling JNDI and using global resources.
 */
@Test
public void testEnableNamingGlobal() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    
    // Must have a real docBase - just use temp
    org.apache.catalina.Context ctx = 
        tomcat.addContext("", System.getProperty("java.io.tmpdir"));
    
    // You can customise the context by calling its API
    
    // Enable JNDI - it is disabled by default
    tomcat.enableNaming();

    ContextEnvironment environment = new ContextEnvironment();
    environment.setType("java.lang.String");
    environment.setName("globalTest");
    environment.setValue("Tomcat User");
    tomcat.getServer().getGlobalNamingResources().addEnvironment(environment);
    
    ContextResourceLink link = new ContextResourceLink();
    link.setGlobal("globalTest");
    link.setName(HelloWorldJndi.JNDI_ENV_NAME);
    ctx.getNamingResources().addResourceLink(link);
    
    Tomcat.addServlet(ctx, "jndiServlet", new HelloWorldJndi());
    ctx.addServletMapping("/", "jndiServlet");
    
    tomcat.start();
    
    ByteChunk res = getUrl("http://localhost:" + getPort() + "/");
    assertEquals("Hello, Tomcat User", res.toString());
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:36,代码来源:TestTomcat.java

示例4: applyNamingResources

import org.apache.catalina.deploy.ContextResourceLink; //导入方法依赖的package包/类
/**
 * JNDIで取得する名前付きオブジェクトのグローバルリソースへの登録
 *
 * @param namingResources
 * @throws NamingException
 */
protected void applyNamingResources(NamingResources namingResources) throws NamingException {
    // --------------------------------
    // ネーミングリソースにデータソース・環境変数を登録
    // --------------------------------
    // (factoryを指定しない場合、BasicDataSourceFactoryが用いられBasicDataSourceが生成される)
    ContextResource ctxRes = new ContextResource();
    ctxRes.setName("jdbc/ds");
    ctxRes.setAuth("Container");
    ctxRes.setType("javax.sql.DataSource");
    ctxRes.setProperty("factory", DerbyDataSourceFactory.class.getName());

    // JNDIによる環境変数
    ContextEnvironment ctxEnv = new ContextEnvironment();
    ctxEnv.setName("testvalue2");
    ctxEnv.setType("java.lang.Integer");
    ctxEnv.setValue("12345");
    ctxEnv.setOverride(false);

    namingResources.addResource(ctxRes);
    namingResources.addEnvironment(ctxEnv);

    // --------------------------------
    // リソースリンクをアプリケーションのコンテキストに設定する.
    // ここでプログラム的に構成するため、"context.xml"は不要.
    // --------------------------------
    ContextResourceLink resourceLink1 = new ContextResourceLink();
    resourceLink1.setName("jdbc/ds");
    resourceLink1.setGlobal("jdbc/ds");
    resourceLink1.setType("javax.sql.DataSource");
    ctx.getNamingResources().addResourceLink(resourceLink1);

    ContextResourceLink resourceLink2 = new ContextResourceLink();
    resourceLink2.setName("testvalue2");
    resourceLink2.setGlobal("testvalue2");
    resourceLink2.setType("java.lang.Integer");
    ctx.getNamingResources().addResourceLink(resourceLink2);
}
 
开发者ID:seraphy,项目名称:EmbeddedTomcatLauncher,代码行数:44,代码来源:SimpleServerConfigurator3.java

示例5: testGlobalNaming

import org.apache.catalina.deploy.ContextResourceLink; //导入方法依赖的package包/类
@Test
public void testGlobalNaming() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    tomcat.enableNaming();

    org.apache.catalina.Context ctx = tomcat.addContext("", null);

    tomcat.start();

    Context webappInitial = ContextBindings.getContext(ctx);

    // Nothing added at the moment so should be null
    Object obj = doLookup(webappInitial, COMP_ENV + "/" + LOCAL_NAME);
    Assert.assertNull(obj);

    ContextEnvironment ce = new ContextEnvironment();
    ce.setName(GLOBAL_NAME);
    ce.setValue(DATA);
    ce.setType(DATA.getClass().getName());

    tomcat.getServer().getGlobalNamingResources().addEnvironment(ce);

    // No link so still should be null
    obj = doLookup(webappInitial, COMP_ENV + "/" + LOCAL_NAME);
    Assert.assertNull(obj);

    // Now add a resource link to the context
    ContextResourceLink crl = new ContextResourceLink();
    crl.setGlobal(GLOBAL_NAME);
    crl.setName(LOCAL_NAME);
    crl.setType(DATA.getClass().getName());
    ctx.getNamingResources().addResourceLink(crl);

    // Link exists so should be OK now
    obj = doLookup(webappInitial, COMP_ENV + "/" + LOCAL_NAME);
    Assert.assertEquals(DATA, obj);

    // Try shortcut
    ResourceLinkFactory factory = new ResourceLinkFactory();
    ResourceLinkRef rlr = new ResourceLinkRef(DATA.getClass().getName(), GLOBAL_NAME, null, null);
    obj = factory.getObjectInstance(rlr, null, null, null);
    Assert.assertEquals(DATA, obj);

    // Remove the link
    ctx.getNamingResources().removeResourceLink(LOCAL_NAME);

    // No link so should be null
    obj = doLookup(webappInitial, COMP_ENV + "/" + LOCAL_NAME);
    Assert.assertNull(obj);

    // Shortcut should fail too
    obj = factory.getObjectInstance(rlr, null, null, null);
    Assert.assertNull(obj);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:55,代码来源:TestNamingContext.java


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