use of java.rmi.server.RemoteObject in project jdk8u_jdk by JetBrains.
the class UnrecognizedRefType method test.
private static void test(RemoteObject obj) throws Exception {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bout);
out.writeObject(obj);
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
ObjectInputStream in = new ObjectInputStream(bin);
try {
Object obj2 = in.readObject();
System.err.println("Object unexpectedly deserialized successfully: " + obj2);
throw new RuntimeException("TEST FAILED: object successfully deserialized");
} catch (ClassNotFoundException e) {
System.err.println("ClassNotFoundException as expected:");
e.printStackTrace();
}
// other exceptions cause test failure
}
use of java.rmi.server.RemoteObject in project jmeter by apache.
the class ClientJMeterEngine method getEngine.
private static RemoteJMeterEngine getEngine(String h) throws MalformedURLException, RemoteException, NotBoundException {
// $NON-NLS-1$ $NON-NLS-2$
final String name = "//" + h + "/" + RemoteJMeterEngineImpl.JMETER_ENGINE_RMI_NAME;
Remote remobj = Naming.lookup(name);
if (remobj instanceof RemoteJMeterEngine) {
final RemoteJMeterEngine rje = (RemoteJMeterEngine) remobj;
if (remobj instanceof RemoteObject) {
RemoteObject robj = (RemoteObject) remobj;
System.out.println("Using remote object: " + robj.getRef().remoteToString());
}
return rje;
}
throw new RemoteException("Could not find " + name);
}
use of java.rmi.server.RemoteObject in project jdk8u_jdk by JetBrains.
the class RMIConnector method checkStub.
//--------------------------------------------------------------------
// Private stuff - Check if stub can be trusted.
//--------------------------------------------------------------------
private static void checkStub(Remote stub, Class<?> stubClass) {
//
if (stub.getClass() != stubClass) {
if (!Proxy.isProxyClass(stub.getClass())) {
throw new SecurityException("Expecting a " + stubClass.getName() + " stub!");
} else {
InvocationHandler handler = Proxy.getInvocationHandler(stub);
if (handler.getClass() != RemoteObjectInvocationHandler.class)
throw new SecurityException("Expecting a dynamic proxy instance with a " + RemoteObjectInvocationHandler.class.getName() + " invocation handler!");
else
stub = (Remote) handler;
}
}
// Check RemoteRef in stub is from the expected class
// "sun.rmi.server.UnicastRef2".
//
RemoteRef ref = ((RemoteObject) stub).getRef();
if (ref.getClass() != UnicastRef2.class)
throw new SecurityException("Expecting a " + UnicastRef2.class.getName() + " remote reference in stub!");
// Check RMIClientSocketFactory in stub is from the expected class
// "javax.rmi.ssl.SslRMIClientSocketFactory".
//
LiveRef liveRef = ((UnicastRef2) ref).getLiveRef();
RMIClientSocketFactory csf = liveRef.getClientSocketFactory();
if (csf == null || csf.getClass() != SslRMIClientSocketFactory.class)
throw new SecurityException("Expecting a " + SslRMIClientSocketFactory.class.getName() + " RMI client socket factory in stub!");
}
use of java.rmi.server.RemoteObject in project jdk8u_jdk by JetBrains.
the class ActivationID method writeObject.
/**
* <code>writeObject</code> for custom serialization.
*
* <p>This method writes this object's serialized form for
* this class as follows:
*
* <p>The <code>writeObject</code> method is invoked on
* <code>out</code> passing this object's unique identifier
* (a {@link java.rmi.server.UID UID} instance) as the argument.
*
* <p>Next, the {@link
* java.rmi.server.RemoteRef#getRefClass(java.io.ObjectOutput)
* getRefClass} method is invoked on the activator's
* <code>RemoteRef</code> instance to obtain its external ref
* type name. Next, the <code>writeUTF</code> method is
* invoked on <code>out</code> with the value returned by
* <code>getRefClass</code>, and then the
* <code>writeExternal</code> method is invoked on the
* <code>RemoteRef</code> instance passing <code>out</code>
* as the argument.
*
* @serialData The serialized data for this class comprises a
* <code>java.rmi.server.UID</code> (written with
* <code>ObjectOutput.writeObject</code>) followed by the
* external ref type name of the activator's
* <code>RemoteRef</code> instance (a string written with
* <code>ObjectOutput.writeUTF</code>), followed by the
* external form of the <code>RemoteRef</code> instance as
* written by its <code>writeExternal</code> method.
*
* <p>The external ref type name of the
* <code>RemoteRef</Code> instance is
* determined using the definitions of external ref type
* names specified in the {@link java.rmi.server.RemoteObject
* RemoteObject} <code>writeObject</code> method
* <b>serialData</b> specification. Similarly, the data
* written by the <code>writeExternal</code> method and read
* by the <code>readExternal</code> method of
* <code>RemoteRef</code> implementation classes
* corresponding to each of the defined external ref type
* names is specified in the {@link
* java.rmi.server.RemoteObject RemoteObject}
* <code>writeObject</code> method <b>serialData</b>
* specification.
**/
private void writeObject(ObjectOutputStream out) throws IOException, ClassNotFoundException {
out.writeObject(uid);
RemoteRef ref;
if (activator instanceof RemoteObject) {
ref = ((RemoteObject) activator).getRef();
} else if (Proxy.isProxyClass(activator.getClass())) {
InvocationHandler handler = Proxy.getInvocationHandler(activator);
if (!(handler instanceof RemoteObjectInvocationHandler)) {
throw new InvalidObjectException("unexpected invocation handler");
}
ref = ((RemoteObjectInvocationHandler) handler).getRef();
} else {
throw new InvalidObjectException("unexpected activator type");
}
out.writeUTF(ref.getRefClass(out));
ref.writeExternal(out);
}
use of java.rmi.server.RemoteObject in project jdk8u_jdk by JetBrains.
the class RMIConnector method shadowJrmpStub.
private static RMIConnection shadowJrmpStub(RemoteObject stub) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, NoSuchMethodException {
RemoteRef ref = stub.getRef();
RemoteRef proxyRef = (RemoteRef) proxyRefConstructor.newInstance(new Object[] { ref });
final Constructor<?> rmiConnectionImplStubConstructor = rmiConnectionImplStubClass.getConstructor(RemoteRef.class);
Object[] args = { proxyRef };
RMIConnection proxyStub = (RMIConnection) rmiConnectionImplStubConstructor.newInstance(args);
return proxyStub;
}
Aggregations