working on it ...

Filters

Explore Public Snippets

Sort by

Found 5 snippets matching: "rmi server"

    public by lbottaro  281543  2  6  3

    Simple RMI Java server

    This code shows a basic RMI server example. A "server" is the class which has a main method that creates an instance of the remote object implementation, exports the remote object and then binds that instance to a name in a RMI registry. Here the server implements the remote interface Hello. The class that contains this main method could be the
    package example.hello;
    	
    import java.rmi.registry.Registry;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.RemoteException;
    import java.rmi.server.UnicastRemoteObject;
    	
    public class Server implements Hello {
    	
        public Server() {}
    
        public String sayHello() {
    	return "Hello, world!";
        }
    	
        public static void main(String args[]) {
    	
    	try {
    	    Server obj = new Server();
    	    Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);
    
    	    // Bind the remote object's stub in the registry
    	    Registry registry = LocateRegistry.getRegistry();
    	    registry.bind("Hello", stub);
    
    	    System.err.println("Server ready");
    	} catch (Exception e) {
    	    System.err.println("Server exception: " + e.toString());
    	    e.printStackTrace();
    	}
        }
    }    

    external by hopeful  420  1  3  0

    Run jstatd w/o error 'access denied (java.util.PropertyPermission java.rmi.server.ignoreSubClasses write)'

    Run jstatd w/o error 'access denied (java.util.PropertyPermission java.rmi.server.ignoreSubClasses write)': jstatd.sh
    #!/bin/sh
    policy=${HOME}/.jstatd.all.policy
    [ -r ${policy} ] || cat >${policy} <<'POLICY'
    grant codebase "file:${java.home}/../lib/tools.jar" {
      permission java.security.AllPermission;
    };
    POLICY
    
    jstatd -J-Djava.security.policy=${policy} &
    
    
    

    external by Tom Michaud  196  0  2  0

    OES Security Module configuration/RMI server startup success

    OES Security Module configuration/RMI server startup success: gistfile1.txt
    After logging in:
    [oracle@aus2-fge-dpm01v bin]$ sudo su oracle
    [oracle@aus2-fge-dpm01v bin]$ export JAVA_HOME=/opt/oracle/software/jrockit
    [oracle@aus2-fge-dpm01v bin]$ cd /opt/oracle/software/Middleware/oesclient/oessm/SMConfigTool
    [oracle@aus2-fge-dpm01v bin]$ cp smconfig.rmi.controlled.prp di2.rmi.controlled.prp
    [oracle@aus2-fge-dpm01v bin]$ vim di2.rmi.controlled.prp
    <editted with the following diffs>
    [oracle@aus2-fge-dpm01v bin]$ diff smconfig.rmi.controlled.prp di2.rmi.controlled.prp
    [oracle@aus2-fge-dpm01v SMConfigTool]$ diff smconfig.rmi.controlled.prp di2.rmi.controlled.prp
    20,21c20,21
    < oracle.security.jps.runtime.pd.client.RegistrationServerHost=
    < oracle.security.jps.runtime.pd.client.RegistrationServerPort=
    ---
    > oracle.security.jps.runtime.pd.client.RegistrationServerHost=aus2-fge-dpm01v.dev.drillinginfo.com
    > oracle.security.jps.runtime.pd.client.RegistrationServerPort=7002
    26c26
    < oracle.security.jps.pdp.rmism.RMIRegistryPortNumber=
    ---
    > oracle.security.jps.pdp.rmism.RMIRegistryPortNumber=9405
    30c30
    < oracle.security.jps.runtime.pd.client.sm_name=
    ---
    > oracle.security.jps.runtime.pd.client.sm_name=di2-rmi-sm
    36c36
    < oracle.security.jps.runtime.pd.client.DistributionServicePort=
    ---
    > oracle.security.jps.runtime.pd.client.DistributionServicePort=8000
    38,40d37
    
    [oracle@aus2-fge-dpm01v bin]$ cat ../SMConfigTool/di2.rmi.controlled.prp
    <!--
     Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
    
       NAME
         smconfig.rmi.controlled.prp
    
       DESCRIPTION
         This file specifies parameters used by SM configuration script (config.sh).
         This file is for RMI SM in Controlled Policy Distribution Mode.
    
    -->
    #  Policy dustribution mode. Possible values:
    #   controlled-push - if this mode is set you need to configire Policy Distribution configiration parameters
    
    oracle.security.jps.runtime.pd.client.policyDistributionMode=controlled-push
    
    #  -------- Policy Distributor connectivity information - required for controlled-push distribution mode
    #  Only needed for controlled-push policy distribution mode
    
    oracle.security.jps.runtime.pd.client.RegistrationServerHost=aus2-fge-dpm01v.dev.drillinginfo.com
    oracle.security.jps.runtime.pd.client.RegistrationServerPort=7002
    
    #---------- ONLY for  RMI SM  -----------------------------
    # port number to accept authorization requests
    
    oracle.security.jps.pdp.rmism.RMIRegistryPortNumber=9405
    
    # Only Supply if you do not use -smConfigId at the command line
    # SM name
    oracle.security.jps.runtime.pd.client.sm_name=di2-rmi-sm
    
    # >>>>>>>>>>>>OPTIONAL PARAMETERS<<<<<<<<<<<<<<<<<
    # ------------ Only for Java SM, WS SM, and RMI SM in controlled-push mode --------------------
    #  port to listen for policy distribution. Picked automatically by SM config tool if not specified
    
    oracle.security.jps.runtime.pd.client.DistributionServicePort=8000
    oracle.security.jps.runtime.pd.client.sm_type=rmi
    
    [oracle@aus2-fge-dpm01v bin]$ cd /opt/oracle/software/Middleware/oesclient/oessm/bin
    [oracle@aus2-fge-dpm01v bin]$ ./config.sh -smConfigId di2-rmi-sm -prpFileName ../SMConfigTool/di2.rmi.controlled.prp
    Configuring for Controlled Policy Distribution Mode
    Security Module configuration is created at: /opt/oracle/software/Middleware/oesclient/oes_sm_instances/di2-rmi-sm
    Enter password for key stores:<weblogic user's password found in S106 card>
    Enter password for key stores again:<ditto>
    Passwords are saved in credential store.
    Keystores are initialized successfully.
    Please enter a value for OES Admin Server User name:weblogic
    Please enter a value for OES Admin Server Password:<weblogic user's password found in S106 card>
    Please re-enter a value for OES Admin Server Password:<ditto>
    Enrollment is proceeded successfully.
    
    [oracle@aus2-fge-dpm01v bin]$ cd /opt/oracle/software/Middleware/oesclient/oes_sm_instances/di2-rmi-sm
    [oracle@aus2-fge-dpm01v di2-rmi-sm]$ ls
    bin  config  security  startRMIServer.sh
    [oracle@aus2-fge-dpm01v di2-rmi-sm]$ ./startRMIServer.sh
    Dec 15, 2014 5:31:09 PM oracle.security.jps.internal.audit.dynamic.AuditStoreFactory getInstance
    WARNING: file /opt/oracle/software/Middleware/oesclient/oes_sm_instances/di2-rmi-sm/config/audit-store.xml was not found
    Dec 15, 2014 5:31:21 PM oracle.security.jps.az.internal.runtime.pd.register.PDPRegister run
    INFO: PDP registration succeeded.
    Dec 15, 2014 5:31:24 PM com.bea.security.ssmrmi.services.impl.RMIAuthorizationServiceImpl start
    INFO: RMI Authorization service has started.
    Dec 15, 2014 5:31:24 PM com.bea.security.ssmrmi.services.impl.RMIRoleServiceImpl start
    INFO: RMI Role-Mapping service has started.
    Dec 15, 2014 5:31:24 PM com.bea.security.ssmrmi.services.impl.RMIServiceLocatorImpl start
    INFO: RMI Service Locator has started.
    RMI-SSM has started.
    
    

    external by tanzwud  82  0  1  0

    Open Uni Rmi SERVER

    Open Uni Rmi SERVER: Server.java
    package rmi;
    
    import java.rmi.registry.LocateRegistry;
    import java.rmi.registry.Registry;
    import java.rmi.server.UnicastRemoteObject;
    
    /**
     * Date: 16/06/2015
     *
     * @author ivan Ko
     */
    // skeleton
    public class Server {
    
        public static void main(String[] args) throws Exception {
            // create and export remote object
            RemoteClassNotImplementingSerializable server = new RemoteClassNotImplementingSerializable();
            // and get a stub object on server
            // stub may be passed back to the client
            ClientStub stub = (ClientStub) UnicastRemoteObject.exportObject(server, 0);
    
            // bind the remote object's stub to the registry
            // port number 12345
            Registry registry = LocateRegistry.createRegistry(12346);
            registry.bind("university", stub);
    
            System.out.println("Server Ready!");
        }
    }
    
    
    

    external by mbapna  2  0  2  0

    Hospital Inventory RMI (Server and Client)

    Hospital Inventory RMI (Server and Client): Hospital Inventory RMI (Server and Client)
    
    RMI Client Side
    
    import java.rmi.*;
    import java.rmi.server.*;
    
    public class room0{
    
    public static void main(String[] args){
    			room0 Roomzero=new room0();
    			Roomzero.addtoanotherroom(0,1,"ventilators",2);                           
    /*Any methods that need to be called should be called from here*/
    /*Roomzero.addfrom(…….);
    /*Roomzero.gettable();*/
    }
    
    public String addtoanotherroom(int room1int,int room2int, String item1, int numberofitems){
    try 	{ 
    	if (room1int != 0) {
    		System.out.print("Can only affect your own room!");
    		return "Can only affect your own room!";
    		}
     RemoteInterface service = (RemoteInterface) Naming.lookup("rmi://localhost/Hospitalsys");
     String stringroom0=service.addtoanotherroom(0,  room2int,  item1, numberofitems);
     System.out.print(stringroom0);
    	return stringroom0;
    }
    
    catch(Exception ex){                       
    /*Must throw exception because method can throw RemoteException*/
    return "Could not complete";
    }}
    
    public String addtoownroom(int room1int,int room2int, String item1, int numberofitems){
    try{ 
    	if (room1int != 0) {return "Can only affect your own room!";}
     RemoteInterface service =  (RemoteInterface)Naming.lookup("rmi://127.0.0.1/Hospitalsys");
     String stringroom0=service.addtoownroom(0,  room2int,  item1, numberofitems);
     System.out.print(stringroom0);
    	return stringroom0;
    }
    catch(Exception ex){                       
    return("Could not complete");
    }}
     
    public int[][] totable(){                                                     
    try{
    RemoteInterface service = (RemoteInterface)Naming.lookup("rmi://127.0.0.1/Hospitalsys");
    int[][]table1= service.totable();                                  
    for (int i = 0; i < table1.length; i++) {
        for (int j = 0; j < table1[i].length; j++) {
            System.out.print(table1[i][j] + " ");
        }
        System.out.println();
    }
    return table1;
    }
    
    catch(Exception ex){
    int[][] a=new int[1][1];
    a[0][0]=1;
    return a;
    }}}
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    RMI Server Side
    
    Room: 
    
    public class Room {
    		public int ventilators=5;
    		public int dialysismachines=3;
    		public int heartlungmachines=2;
    }
    
    
    RemoteInterface:
    
    import java.rmi.*;
    public interface RemoteInterface extends Remote{
    	public String addtoanotherroom(int room1int,int room2int, String item, int numberofitems) throws RemoteException;
    	public String addtoownroom(int room1int,int room2int, String item, int numberofitems) throws RemoteException;
    	public int[][] totable() throws RemoteException;
    }
    
    NegativeNumberException:
    
    import java.io.*;
    
    public class negativenumberexception extends Exception{
    public negativenumberexception(){
    super("Can’t be a negative number");
    }}
    
    
    Hospital:
    
    import java.rmi.*;
    import java.rmi.server.*;
    import java.util.*;
    /*Hospital System objects will be remote objects. The methods implement the Remote Interface*/
    
    public class Hospital extends UnicastRemoteObject implements RemoteInterface{
    	static int roomoriginalitem=0;
    	static int numberofrooms=12;
    	static List<Room> hospital1 = new ArrayList<Room>();
    
    public Hospital() throws RemoteException{
    	}
    
    public static void main(String[]args){
    try{
    /*Initialize a hospital with 12 rooms. */
    	for(int i=1;i<numberofrooms;i++) {
    		hospital1.add(new Room());
    		}
    	RemoteInterface service=new Hospital();
    	Naming.rebind("Hospitalsys",service);
    }
    
    catch(Exception e){
    	e.printStackTrace();
    }}
    
    /*Must be synchronized so that negative number exception is only caught when needed. Adding (numberofitems) item to room 2.*/
    
    public synchronized String addtoanotherroom(int room1int,int room2int, String item1, int numberofitems) {
    
    try{
    	Room room1=hospital1.get(room1int);
    	Room room2=hospital1.get(room2int);
    	if (item1.toLowerCase()=="ventilators"||item1.toLowerCase()=="dialysismachines"||item1.toLowerCase()=="heartlungmachines"){
    		if (item1.toLowerCase()=="ventilators") 
    	        roomoriginalitem=room1.ventilators;
    				 room1.ventilators=room1.ventilators-numberofitems;  
    	if (item1.toLowerCase()=="dialysismachines") {
    				 roomoriginalitem=room1.dialysismachines;
    				 room1.dialysismachines=room1.dialysismachines-numberofitems;}
    	if (item1.toLowerCase()=="heartlungmachines") {
    				roomoriginalitem=room1.heartlungmachines;
    				room1.heartlungmachines=room1.heartlungmachines-numberofitems;}   
    	if (roomoriginalitem-numberofitems<0 && item1.toLowerCase()=="ventilators") {
    				room1.ventilators=roomoriginalitem;
    				throw new negativenumberexception();}
    	if (roomoriginalitem-numberofitems<0 && item1.toLowerCase()=="dialysismachines") {
    				room1.dialysismachines=roomoriginalitem;
    				throw new negativenumberexception();}
    	if (roomoriginalitem-numberofitems<0 && item1.toLowerCase()=="heartlungmachines") {
    				room1.heartlungmachines=roomoriginalitem;
    /*Used in case needed to refer to original value if transaction can’t take place*/
    				throw new negativenumberexception();}
    	if (item1.toLowerCase()=="ventilators")
    		 room2.ventilators=room2.ventilators+numberofitems;   
    	if (item1.toLowerCase()=="dialysismachines")
    		room2.dialysismachines=room2.dialysismachines+numberofitems;   
    	if (item1.toLowerCase()=="heartlungmachines") {
    		 room2.heartlungmachines=room2.heartlungmachines+numberofitems; }
    /*The room where the item was originally in loses items. The room where the item was placed gains the same number of items.*/
    /*No negative amount of items. Success!*/
    	return" Success";
    }
    	else{
    		return "Invalid entry entered";
    	}}
    catch(negativenumberexception e){      
    /*No changes are made to table if this exception is called*/
    return "Can’t be negative items in a room";
    }}
    
    
    public synchronized String addtoownroom(int room2int,int room1int, String item1, int numberofitems) {
    
    try{
    	Room room1=hospital1.get(room1int);
    	Room room2=hospital1.get(room2int);
    	if (item1.toLowerCase()=="ventilators"||item1.toLowerCase()=="dialysismachines"||item1.toLowerCase()=="heartlungmachines"){
    		if (item1.toLowerCase()=="ventilators") 
    	        roomoriginalitem=room1.ventilators;
    				 room1.ventilators=room1.ventilators-numberofitems;  
    	if (item1.toLowerCase()=="dialysismachines") {
    				 roomoriginalitem=room1.dialysismachines;
    				 room1.dialysismachines=room1.dialysismachines-numberofitems;}
    	if (item1.toLowerCase()=="heartlungmachines") {
    				roomoriginalitem=room1.heartlungmachines;
    				room1.heartlungmachines=room1.heartlungmachines-numberofitems;}   
    	if (roomoriginalitem-numberofitems<0 && item1.toLowerCase()=="ventilators") {
    				room1.ventilators=roomoriginalitem;
    				throw new negativenumberexception();}
    	if (roomoriginalitem-numberofitems<0 && item1.toLowerCase()=="dialysismachines") {
    				room1.dialysismachines=roomoriginalitem;
    				throw new negativenumberexception();}
    	if (roomoriginalitem-numberofitems<0 && item1.toLowerCase()=="heartlungmachines") {
    				room1.heartlungmachines=roomoriginalitem;
    /*Used in case needed to refer to original value if transaction can’t take place*/
    				throw new negativenumberexception();}
    	if (item1.toLowerCase()=="ventilators")
    		 room2.ventilators=room2.ventilators+numberofitems;   
    	if (item1.toLowerCase()=="dialysismachines")
    		room2.dialysismachines=room2.dialysismachines+numberofitems;   
    	if (item1.toLowerCase()=="heartlungmachines") {
    		 room2.heartlungmachines=room2.heartlungmachines+numberofitems; }
    /*The room where the item was originally in loses items. The room where the item was placed gains the same number of items.*/
    /*No negative amount of items. Success!*/
    	return" Success";
    }
    	else{
    		return "Invalid number entered";
    	}}
    catch(negativenumberexception e){      
    /*No changes are made to table if this exception is called*/
    return "Can’t be negative items in a room";
    }}
    
    
    
    
    
    
    
    /*Displays 3*12 matrix of items in each room*/
    public int[][] totable(){                                               
    	int[][] table=new int[3][];
    	for (int rooms=0; rooms<numberofrooms; rooms++) {
    			for (int itemofintrigue=0; itemofintrigue<3; itemofintrigue++) {
    					if (itemofintrigue==0)
    						table[itemofintrigue][rooms]=hospital1.get(rooms).ventilators;
    					if (itemofintrigue==1)
    						table[itemofintrigue][rooms]=hospital1.get(rooms).dialysismachines;
    					if (itemofintrigue==2)
    						table[itemofintrigue][rooms]=hospital1.get(rooms).heartlungmachines;
    			}}
    	return table;
    
    import java.rmi.*;
    import java.rmi.server.*;
    import java.util.*;
    
     
    
    
    

    List Complete ( 5 snippets total )

    • Public Snippets
    • Channels Snippets