use of org.eclipse.persistence.sessions.remote.rmi.RMIConnection in project eclipselink by eclipse-ee4j.
the class EntityManagerSetupImpl method updateRemote.
/**
* Checks for partitioning properties.
*/
protected void updateRemote(Map m, ClassLoader loader) {
String protocol = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.REMOTE_PROTOCOL, m, this.session);
String serverName = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.REMOTE_SERVER_NAME, m, this.session);
if (serverName == null) {
// Configure as client.
if (protocol != null) {
RemoteConnection connection = null;
if (protocol.equalsIgnoreCase(RemoteProtocol.RMI)) {
String url = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.REMOTE_URL, m, this.session);
if (url == null) {
throw EntityManagerSetupException.missingProperty(PersistenceUnitProperties.REMOTE_URL);
}
try {
connection = new RMIConnection(((RMIServerSessionManager) Naming.lookup(url)).createRemoteSessionController());
} catch (Exception exception) {
throw ValidationException.invalidValueForProperty(url, PersistenceUnitProperties.REMOTE_URL, exception);
}
} else {
try {
Class<? extends RemoteConnection> cls = findClassForProperty(protocol, PersistenceUnitProperties.REMOTE_PROTOCOL, loader);
Constructor<? extends RemoteConnection> constructor = cls.getConstructor();
connection = constructor.newInstance();
} catch (Exception exception) {
throw ValidationException.invalidValueForProperty(protocol, PersistenceUnitProperties.REMOTE_PROTOCOL, exception);
}
}
RemoteSession remoteSession = new RemoteSession();
remoteSession.setIsMetadataRemote(false);
remoteSession.setProject(this.session.getProject());
remoteSession.setProfiler(this.session.getProfiler());
remoteSession.setSessionLog(this.session.getSessionLog());
remoteSession.setEventManager(this.session.getEventManager());
remoteSession.setQueries(this.session.getQueries());
remoteSession.setProperties(this.session.getProperties());
remoteSession.setName(this.session.getName());
remoteSession.setRemoteConnection(connection);
this.session = remoteSession;
}
} else {
// Configure as server.
if (protocol.equalsIgnoreCase(RemoteProtocol.RMI)) {
RMIServerSessionManager manager = null;
// Make sure RMI registry is started.
try {
java.rmi.registry.LocateRegistry.createRegistry(1099);
} catch (Exception exception) {
System.out.println("Security violation " + exception.toString());
}
// Create local instance of the factory
try {
manager = new RMIServerSessionManagerDispatcher(session);
} catch (RemoteException exception) {
throw ValidationException.invalidValueForProperty(serverName, PersistenceUnitProperties.REMOTE_SERVER_NAME, exception);
}
// Put the local instance into the Registry
try {
Naming.unbind(serverName);
} catch (Exception exception) {
// Ignore.
}
// Put the local instance into the Registry
try {
Naming.rebind(serverName, manager);
} catch (Exception exception) {
throw ValidationException.invalidValueForProperty(serverName, PersistenceUnitProperties.REMOTE_SERVER_NAME, exception);
}
}
}
}
use of org.eclipse.persistence.sessions.remote.rmi.RMIConnection in project eclipselink by eclipse-ee4j.
the class RMIConnectionExceptionsTest method setup.
@Override
public void setup() throws Exception {
Session session = new org.eclipse.persistence.internal.sessions.DatabaseSessionImpl();
session.setProperty("TransporterGenerator", generator);
RMIServerManagerController.start(session, getNameToBind(), "org.eclipse.persistence.testing.tests.remote.rmi.RMIRemoteSessionControllerDispatcherForTestingExceptions");
RMIServerManager serverManager = (RMIServerManager) Naming.lookup(getNameToBind());
RMIConnection rmiConnection = new RMIConnection(serverManager.createRemoteSessionController());
setRemoteConnection(rmiConnection);
}
use of org.eclipse.persistence.sessions.remote.rmi.RMIConnection in project eclipselink by eclipse-ee4j.
the class RMISessionBrokerRemoteModel method setup.
@Override
public void setup() {
createTables();
oldSession = getSession();
Session broker = buildClientSessionBrokerAndPopulate();
org.eclipse.persistence.testing.tests.remote.RemoteModel.setServerSession(broker);
RMIServerManagerController.start(broker);
RMIConnection connection = createConnection();
Session remoteSession = connection.createRemoteSession();
remoteSession.setLogLevel(oldSession.getLogLevel());
remoteSession.setLog(oldSession.getLog());
getExecutor().setSession(remoteSession);
}
use of org.eclipse.persistence.sessions.remote.rmi.RMIConnection in project eclipselink by eclipse-ee4j.
the class RMISessionBrokerRemoteModel method createConnection.
public static RMIConnection createConnection() {
RMISessionBrokerServerManager serverManager = null;
// Set the client security manager
try {
System.setSecurityManager(new RMISecurityManager());
} catch (Exception exception) {
System.out.println("Security violation " + exception.toString());
}
// Get the remote factory object from the Registry
try {
serverManager = (RMISessionBrokerServerManager) Naming.lookup("SERVER-BROKER-MANAGER");
} catch (Exception exception) {
throw new TestProblemException(exception.toString());
}
RMIConnection rmiConnection = null;
try {
rmiConnection = new RMIConnection(serverManager.createRemoteSessionController());
} catch (RemoteException exception) {
System.out.println("Error in invocation " + exception.toString());
}
return rmiConnection;
}
Aggregations