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

The following examples show how to use javax.naming.Context#rebind() . These examples are extracted from open source projects. 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 Project: tomee   File: Assembler.java    License: 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 2
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 3
Source Project: oodt   File: ExecServer.java    License: 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 4
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 5
/**
 * 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 6
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 7
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
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
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
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
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
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 Project: hibersap   File: JndiUtil.java    License: 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
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 Project: hottub   File: HelloServer.java    License: 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
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
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
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 Project: oodt   File: AvroExecServer.java    License: 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
private CamelContext createCamelContext(StorageCredentials creds) throws Exception {
    WildFlyCamelContext camelctx = new WildFlyCamelContext();
    Context jndictx = camelctx.getNamingContext();
    jndictx.rebind("creds", creds);
    return camelctx;
}