Ejemplo n.º 1
0
  /**
   * Bind an object both in standard JNDI (to expose via HA-JNDI) and in our injected NamingServer
   *
   * @throws Exception
   */
  public void start() throws Exception {
    // Standard JNDI
    Context ctx = new InitialContext();
    ctx.bind(NAME, VALUE);
    log.info("Bound " + VALUE + " to " + ctx + " under " + NAME);
    ctx.bind(BAD_BINDING, new NonDeserializable());
    log.info("Bound a NonDeserializable to " + ctx + " under " + BAD_BINDING);

    // For some reason creating a context for our own JNDI doesn't work
    // inside the server, so as a hack we directly deal with the NamingServer
    // to bind the object

    //    Properties env = new Properties();
    //    env.setProperty("java.naming.provider.url", providerURL);
    //    log.info("Env = " + env);
    //    Context ctx = new InitialContext(env);
    //    ctx.bind(NAME, VALUE);

    Naming namingServer = naming.getNamingInstance();
    namingServer.bind(
        parser.parse(NAME), new MarshalledValuePair(VALUE), VALUE.getClass().getName());
    log.info("Bound " + VALUE + " to " + namingServer + " under " + NAME);
    Context sub = namingServer.createSubcontext(parser.parse(SUBCONTEXT_NAME));
    sub.bind(parser.parse(NAME), VALUE);
    log.info("Bound " + VALUE + " to " + sub + " under " + NAME);

    // NOTE: we must bind the NonDeserializable directly, or else the
    // NamingContext will wrap it in a MarshalledValuePair, which will
    // defeat the test by triggering deserialization too late
    namingServer.bind(
        parser.parse(BAD_BINDING), new NonDeserializable(), NonDeserializable.class.getName());

    log.info("Bound a NonDeserializable to " + namingServer + " under " + BAD_BINDING);
  }
Ejemplo n.º 2
0
  /**
   * Undoes the bindings done in start().
   *
   * @throws Exception
   */
  public void stop() throws Exception {
    // Standard JNDI
    Context ctx = new InitialContext();
    ctx.unbind(NAME);
    log.info("Unbound " + NAME + " from " + ctx);
    ctx.unbind(BAD_BINDING);
    log.info("Unbound " + BAD_BINDING + " from " + ctx);

    // For some reason creating a context for our own JNDI doesn't work
    // inside the server, so as a hack we directly deal with the NamingServer
    // to bind the object

    //    Properties env = new Properties();
    //    env.setProperty("java.naming.provider.url", providerURL);
    //
    //    Context ctx = new InitialContext(env);
    //      ctx.unbind(NAME);

    Naming namingServer = naming.getNamingInstance();
    try {
      namingServer.unbind(parser.parse(SUBCONTEXT_NAME + "/" + NAME));
      log.info("Unbound " + SUBCONTEXT_NAME + "/" + NAME + " from " + namingServer);
    } catch (NameNotFoundException ignored) {
      // already unbound by test
    }
    try {
      namingServer.unbind(parser.parse(SUBCONTEXT_NAME));
      log.info("Unbound " + SUBCONTEXT_NAME + " from " + namingServer);
    } catch (NameNotFoundException ignored) {
      // already unbound by test
    }
    try {
      namingServer.unbind(parser.parse(NAME));
      log.info("Unbound " + NAME + " from " + namingServer);
    } catch (NameNotFoundException ignored) {
      // already unbound by test
    }
    try {
      namingServer.unbind(parser.parse(BAD_BINDING));
      log.info("Unbound " + BAD_BINDING + " from " + namingServer);
    } catch (NameNotFoundException ignored) {
      // already unbound by test
    }
  }