Java Code Examples for javax.naming.Context#rebind()

The following examples show how to use javax.naming.Context#rebind() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HelloServer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    int retryCount = 0;
    while (retryCount < MAX_RETRY) {
        try {
            // Step 1: Instantiate the Hello servant
            HelloImpl helloRef = new HelloImpl();

            // Step 2: Publish the reference in the Naming Service
            // using JNDI API
            Context initialNamingContext = new InitialContext();
            initialNamingContext.rebind("HelloService", helloRef);

            System.out.println("Hello Server: Ready...");
            break;
        } catch (Exception e) {
            System.out.println("Server initialization problem: " + e);
            e.printStackTrace();
            retryCount++;
            try {
                Thread.sleep(ONE_SECOND);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
        }
    }
}
 
Example 2
Source File: JndiBindingRegistry.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private boolean bindToJndi(final String jndiName, final Object objectToBind) throws NamingException {
   if (context != null) {
      String parentContext;
      String jndiNameInContext;
      int sepIndex = jndiName.lastIndexOf('/');
      if (sepIndex == -1) {
         parentContext = "";
      } else {
         parentContext = jndiName.substring(0, sepIndex);
      }
      jndiNameInContext = jndiName.substring(sepIndex + 1);
      try {
         context.lookup(jndiName);

         //JMSServerManagerImpl.log.warn("Binding for " + jndiName + " already exists");
         return false;
      } catch (Throwable e) {
         // OK
      }

      Context c = JNDIUtil.createContext(context, parentContext);

      c.rebind(jndiNameInContext, objectToBind);
   }
   return true;
}
 
Example 3
Source File: JVoiceXmlJndiSupport.java    From JVoiceXML with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Binds the given stub and skeleton.
 *
 * <p>
 * Both have to be exported. The skeleton has to be accessed from the
 * stub via RMI and the stub has to be exported to be accessible via
 * JNDI.
 * </p>
 *
 * @param context The context to bind skeleton and stub.
 * @param skeleton The skeleton to bind.
 * @param stub The stub to bind.
 */
static void bind(final Context context, final Skeleton skeleton,
                 final Stub stub) {
    final String skeletonName;
    try {
        skeletonName = skeleton.getSkeletonName();
    } catch (RemoteException re) {
        LOGGER.error("error retrieving the skeleton name", re);
        return;
    }

    final String stubName = stub.getStubName();
    try {
        context.rebind(skeletonName, skeleton);
        context.rebind(stubName, stub);
    } catch (javax.naming.NamingException ne) {
        LOGGER.error("naming exception while exporting '" + skeletonName
                     + "'", ne);
        return;
    }

    LOGGER.info("bound '" + stubName + "' to '"
            + stub.getClass().getName() + "'");
}
 
Example 4
Source File: ExecServer.java    From oodt with Apache License 2.0 6 votes vote down vote up
public void run() {
	while (shouldKeepBinding()) {
	  try {
		Context objectContext = configuration.getObjectContext();
		objectContext.rebind(name, server.getServant());
		objectContext.close();
	  } catch (Exception ex) {
		System.err.println("Exception binding at " + new Date() + "; will keep trying...");
		ex.printStackTrace();
	  } finally {
		try {
		  Thread.sleep(REBIND_PERIOD);
		} catch (InterruptedException ignore) {
		}
	  }
	}
}
 
Example 5
Source File: DatabaseViaDataSourceTest.java    From rxjava-jdbc with Apache License 2.0 6 votes vote down vote up
private static DataSource initDataSource() {
    JdbcDataSource dataSource = new JdbcDataSource();
    String dbUrl = DatabaseCreator.nextUrl();
    dataSource.setURL(dbUrl);

    String jndiName = "jdbc/RxDS";

    try {
        Context context = new InitialContext();
        context.rebind(jndiName, dataSource);
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }

    return dataSource;
}
 
Example 6
Source File: Assembler.java    From tomee with Apache License 2.0 6 votes vote down vote up
public void bindGlobals(final Map<String, Object> bindings) throws NamingException {
    final Context containerSystemContext = containerSystem.getJNDIContext();
    for (final Entry<String, Object> value : bindings.entrySet()) {
        final String path = value.getKey();
        // keep only global bindings
        if (path.startsWith("module/") || path.startsWith("app/") || path.startsWith("comp/") || path.equalsIgnoreCase("global/dummy")) {
            continue;
        }

        // a bit weird but just to be consistent if user doesn't lookup directly the resource
        final Context lastContext = Contexts.createSubcontexts(containerSystemContext, path);
        try {
            lastContext.rebind(path.substring(path.lastIndexOf('/') + 1, path.length()), value.getValue());
        } catch (final NameAlreadyBoundException nabe) {
            nabe.printStackTrace();
        }
        containerSystemContext.rebind(path, value.getValue());
    }
}
 
Example 7
Source File: HelloServer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    int retryCount = 0;
    while (retryCount < MAX_RETRY) {
        try {
            //HelloServer.set("SETTING TEST ITL");
            // Step 1: Instantiate the Hello servant
            HelloImpl helloRef = new HelloImpl();

            // Step 2: Publish the reference in the Naming Service
            // using JNDI API
            Context initialNamingContext = new InitialContext();
            initialNamingContext.rebind("HelloService", helloRef);

            System.out.println("Hello Server: Ready...");
            break;
        } catch (Exception e) {
            System.out.println("Server initialization problem: " + e);
            e.printStackTrace();
            retryCount++;
            try {
                Thread.sleep(ONE_SECOND);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
        }
    }
}
 
Example 8
Source File: HelloServer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    int retryCount = 0;
    while (retryCount < MAX_RETRY) {
        try {
            //HelloServer.set("SETTING TEST ITL");
            // Step 1: Instantiate the Hello servant
            HelloImpl helloRef = new HelloImpl();

            // Step 2: Publish the reference in the Naming Service
            // using JNDI API
            Context initialNamingContext = new InitialContext();
            initialNamingContext.rebind("HelloService", helloRef);

            System.out.println("Hello Server: Ready...");
            break;
        } catch (Exception e) {
            System.out.println("Server initialization problem: " + e);
            e.printStackTrace();
            retryCount++;
            try {
                Thread.sleep(ONE_SECOND);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
        }
    }
}
 
Example 9
Source File: HelloServer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    int retryCount = 0;
    while (retryCount < MAX_RETRY) {
        try {
            //HelloServer.set("SETTING TEST ITL");
            // Step 1: Instantiate the Hello servant
            HelloImpl helloRef = new HelloImpl();

            // Step 2: Publish the reference in the Naming Service
            // using JNDI API
            Context initialNamingContext = new InitialContext();
            initialNamingContext.rebind("HelloService", helloRef);

            System.out.println("Hello Server: Ready...");
            break;
        } catch (Exception e) {
            System.out.println("Server initialization problem: " + e);
            e.printStackTrace();
            retryCount++;
            try {
                Thread.sleep(ONE_SECOND);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
        }
    }
}
 
Example 10
Source File: HelloServer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    int retryCount = 0;
    while (retryCount < MAX_RETRY) {
        try {
            //HelloServer.set("SETTING TEST ITL");
            // Step 1: Instantiate the Hello servant
            HelloImpl helloRef = new HelloImpl();

            // Step 2: Publish the reference in the Naming Service
            // using JNDI API
            Context initialNamingContext = new InitialContext();
            initialNamingContext.rebind("HelloService", helloRef);

            System.out.println("Hello Server: Ready...");
            break;
        } catch (Exception e) {
            System.out.println("Server initialization problem: " + e);
            e.printStackTrace();
            retryCount++;
            try {
                Thread.sleep(ONE_SECOND);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
        }
    }
}
 
Example 11
Source File: HelloServer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    int retryCount = 0;
    while (retryCount < MAX_RETRY) {
        try {
            //HelloServer.set("SETTING TEST ITL");
            // Step 1: Instantiate the Hello servant
            HelloImpl helloRef = new HelloImpl();

            // Step 2: Publish the reference in the Naming Service
            // using JNDI API
            Context initialNamingContext = new InitialContext();
            initialNamingContext.rebind("HelloService", helloRef);

            System.out.println("Hello Server: Ready...");
            break;
        } catch (Exception e) {
            System.out.println("Server initialization problem: " + e);
            e.printStackTrace();
            retryCount++;
            try {
                Thread.sleep(ONE_SECOND);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
        }
    }
}
 
Example 12
Source File: HelloServer.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    int retryCount = 0;
    while (retryCount < MAX_RETRY) {
        try {
            //HelloServer.set("SETTING TEST ITL");
            // Step 1: Instantiate the Hello servant
            HelloImpl helloRef = new HelloImpl();

            // Step 2: Publish the reference in the Naming Service
            // using JNDI API
            Context initialNamingContext = new InitialContext();
            initialNamingContext.rebind("HelloService", helloRef);

            System.out.println("Hello Server: Ready...");
            break;
        } catch (Exception e) {
            System.out.println("Server initialization problem: " + e);
            e.printStackTrace();
            retryCount++;
            try {
                Thread.sleep(ONE_SECOND);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
        }
    }
}
 
Example 13
Source File: JndiUtil.java    From hibersap with Apache License 2.0 5 votes vote down vote up
public static void rebindSessionManager(final SessionManager sessionManager, final String jndiName) {
    LOG.info("Binding Hibersap SessionManager '" + sessionManager.getConfig().getName()
            + "' to JNDI name '" + jndiName + "'");

    try {
        Context ctx = new InitialContext();
        ctx.rebind(jndiName, sessionManager);
    } catch (NamingException e) {
        throw new HibersapException("Failed binding Hibersap SessionManager to JNDI name [" + jndiName + "]", e);
    }
}
 
Example 14
Source File: HelloServer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    int retryCount = 0;
    while (retryCount < MAX_RETRY) {
        try {
            //HelloServer.set("SETTING TEST ITL");
            // Step 1: Instantiate the Hello servant
            HelloImpl helloRef = new HelloImpl();

            // Step 2: Publish the reference in the Naming Service
            // using JNDI API
            Context initialNamingContext = new InitialContext();
            initialNamingContext.rebind("HelloService", helloRef);

            System.out.println("Hello Server: Ready...");
            break;
        } catch (Exception e) {
            System.out.println("Server initialization problem: " + e);
            e.printStackTrace();
            retryCount++;
            try {
                Thread.sleep(ONE_SECOND);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
        }
    }
}
 
Example 15
Source File: HelloServer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    int retryCount = 0;
    while (retryCount < MAX_RETRY) {
        try {
            //HelloServer.set("SETTING TEST ITL");
            // Step 1: Instantiate the Hello servant
            HelloImpl helloRef = new HelloImpl();

            // Step 2: Publish the reference in the Naming Service
            // using JNDI API
            Context initialNamingContext = new InitialContext();
            initialNamingContext.rebind("HelloService", helloRef);

            System.out.println("Hello Server: Ready...");
            break;
        } catch (Exception e) {
            System.out.println("Server initialization problem: " + e);
            e.printStackTrace();
            retryCount++;
            try {
                Thread.sleep(ONE_SECOND);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
        }
    }
}
 
Example 16
Source File: HelloServer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    int retryCount = 0;
    while (retryCount < MAX_RETRY) {
        try {
            //HelloServer.set("SETTING TEST ITL");
            // Step 1: Instantiate the Hello servant
            HelloImpl helloRef = new HelloImpl();

            // Step 2: Publish the reference in the Naming Service
            // using JNDI API
            Context initialNamingContext = new InitialContext();
            initialNamingContext.rebind("HelloService", helloRef);

            System.out.println("Hello Server: Ready...");
            break;
        } catch (Exception e) {
            System.out.println("Server initialization problem: " + e);
            e.printStackTrace();
            retryCount++;
            try {
                Thread.sleep(ONE_SECOND);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
        }
    }
}
 
Example 17
Source File: HelloServer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    int retryCount = 0;
    while (retryCount < MAX_RETRY) {
        try {
            //HelloServer.set("SETTING TEST ITL");
            // Step 1: Instantiate the Hello servant
            HelloImpl helloRef = new HelloImpl();

            // Step 2: Publish the reference in the Naming Service
            // using JNDI API
            Context initialNamingContext = new InitialContext();
            initialNamingContext.rebind("HelloService", helloRef);

            System.out.println("Hello Server: Ready...");
            break;
        } catch (Exception e) {
            System.out.println("Server initialization problem: " + e);
            e.printStackTrace();
            retryCount++;
            try {
                Thread.sleep(ONE_SECOND);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
        }
    }
}
 
Example 18
Source File: HelloImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void start() throws Exception
{
   if (!m_isRunning)
   {
      // export the remote object
      PortableRemoteObject.exportObject(this);
      // set up the initialContext
      Context ctx = new InitialContext();
      ctx.rebind(IIOP_JNDI_NAME, this);
      System.out.println("My Service servant started successfully");
      m_isRunning = true;
   }
}
 
Example 19
Source File: AvroExecServer.java    From oodt with Apache License 2.0 5 votes vote down vote up
public void run() {
    while (shouldKeepBinding()) try {
        Context objectContext = configuration.getObjectContext();
        objectContext.rebind(name, server.getServant());
        objectContext.close();
    } catch (Throwable ex) {
        System.err.println("Exception binding at " + new Date() + "; will keep trying...");
        ex.printStackTrace();
    } finally {
        try {
            Thread.sleep(REBIND_PERIOD);
        } catch (InterruptedException ignore) {}
    }
}
 
Example 20
Source File: AzureIntegrationTest.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
private CamelContext createCamelContext(StorageCredentials creds) throws Exception {
    WildFlyCamelContext camelctx = new WildFlyCamelContext();
    Context jndictx = camelctx.getNamingContext();
    jndictx.rebind("creds", creds);
    return camelctx;
}