mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-10 06:59:05 +00:00
Merge
This commit is contained in:
commit
a3b4abc14b
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2002, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -33,15 +33,47 @@ import java.net.*;
|
||||
* in order to obtain client and server sockets for RMI calls. An
|
||||
* application may use the <code>setSocketFactory</code> method to
|
||||
* request that the RMI runtime use its socket factory instance
|
||||
* instead of the default implementation.<p>
|
||||
* instead of the default implementation.
|
||||
*
|
||||
* The default socket factory implementation used goes through a
|
||||
* <p>The default socket factory implementation performs a
|
||||
* three-tiered approach to creating client sockets. First, a direct
|
||||
* socket connection to the remote VM is attempted. If that fails
|
||||
* (due to a firewall), the runtime uses HTTP with the explicit port
|
||||
* number of the server. If the firewall does not allow this type of
|
||||
* communication, then HTTP to a cgi-bin script on the server is used
|
||||
* to POST the RMI call.<p>
|
||||
* to POST the RMI call.
|
||||
*
|
||||
* <p>The default socket factory implementation creates server sockets that
|
||||
* are bound to the wildcard address, which accepts requests from all network
|
||||
* interfaces.
|
||||
*
|
||||
* @implNote
|
||||
* <p>You can use the {@code RMISocketFactory} class to create a server socket that
|
||||
* is bound to a specific address, restricting the origin of requests. For example,
|
||||
* the following code implements a socket factory that binds server sockets to the
|
||||
* loopback address. This restricts RMI to processing requests only from the local host.
|
||||
*
|
||||
* <pre>{@code
|
||||
* class LoopbackSocketFactory extends RMISocketFactory {
|
||||
* public ServerSocket createServerSocket(int port) throws IOException {
|
||||
* return new ServerSocket(port, 5, InetAddress.getLoopbackAddress());
|
||||
* }
|
||||
*
|
||||
* public Socket createSocket(String host, int port) throws IOException {
|
||||
* // just call the default client socket factory
|
||||
* return RMISocketFactory.getDefaultSocketFactory()
|
||||
* .createSocket(host, port);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* // ...
|
||||
*
|
||||
* RMISocketFactory.setSocketFactory(new LoopbackSocketFactory());
|
||||
* }</pre>
|
||||
*
|
||||
* Set the {@code java.rmi.server.hostname} system property
|
||||
* to a host name (typically {@code localhost}) that resolves to the loopback
|
||||
* interface to ensure that the generated stubs use the right network interface.
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @author Peter Jones
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -100,6 +100,26 @@ import sun.rmi.server.UnicastServerRef2;
|
||||
* </ul>
|
||||
* </ul>
|
||||
*
|
||||
* <p>If an object is exported with the
|
||||
* {@link #exportObject(Remote) exportObject(Remote)}
|
||||
* or
|
||||
* {@link #exportObject(Remote, int) exportObject(Remote, port)}
|
||||
* methods, or if a subclass constructor invokes one of the
|
||||
* {@link #UnicastRemoteObject()}
|
||||
* or
|
||||
* {@link #UnicastRemoteObject(int) UnicastRemoteObject(port)}
|
||||
* constructors, the object is exported with a server socket created using the
|
||||
* {@link RMISocketFactory}
|
||||
* class.
|
||||
*
|
||||
* @implNote
|
||||
* <p>By default, server sockets created by the {@link RMISocketFactory} class
|
||||
* listen on all network interfaces. See the
|
||||
* {@link RMISocketFactory} class and the section
|
||||
* <a href="{@docRoot}/../platform/rmi/spec/rmi-server29.html">RMI Socket Factories</a>
|
||||
* in the
|
||||
* <a href="{@docRoot}/../platform/rmi/spec/rmiTOC.html">Java RMI Specification</a>.
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @author Peter Jones
|
||||
* @since JDK1.1
|
||||
|
||||
@ -260,7 +260,7 @@ public class RelationNotification extends Notification {
|
||||
|
||||
super(notifType, sourceObj, sequence, timeStamp, message);
|
||||
|
||||
if (!isValidBasic(notifType,sourceObj,id,typeName) || !isValidCreate(notifType)) {
|
||||
if (!isValidBasicStrict(notifType,sourceObj,id,typeName) || !isValidCreate(notifType)) {
|
||||
throw new IllegalArgumentException("Invalid parameter.");
|
||||
}
|
||||
|
||||
@ -310,7 +310,7 @@ public class RelationNotification extends Notification {
|
||||
|
||||
super(notifType, sourceObj, sequence, timeStamp, message);
|
||||
|
||||
if (!isValidBasic(notifType,sourceObj,id,typeName) || !isValidUpdate(notifType,name,newValue,oldValue)) {
|
||||
if (!isValidBasicStrict(notifType,sourceObj,id,typeName) || !isValidUpdate(notifType,name,newValue,oldValue)) {
|
||||
throw new IllegalArgumentException("Invalid parameter.");
|
||||
}
|
||||
|
||||
@ -457,14 +457,26 @@ public class RelationNotification extends Notification {
|
||||
// - no role old value (for role update)
|
||||
// - no role new value (for role update)
|
||||
|
||||
// Despite the fact, that validation in constructor of RelationNotification prohibit
|
||||
// creation of the class instance with null sourceObj its possible to set it to null later
|
||||
// by public setSource() method.
|
||||
// So we should relax validation rules to preserve serialization behavior compatibility.
|
||||
|
||||
private boolean isValidBasicStrict(String notifType, Object sourceObj, String id, String typeName){
|
||||
if (sourceObj == null) {
|
||||
return false;
|
||||
}
|
||||
return isValidBasic(notifType,sourceObj,id,typeName);
|
||||
}
|
||||
|
||||
private boolean isValidBasic(String notifType, Object sourceObj, String id, String typeName){
|
||||
if (notifType == null || sourceObj == null ||
|
||||
id == null || typeName == null) {
|
||||
if (notifType == null || id == null || typeName == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(sourceObj instanceof RelationService) &&
|
||||
!(sourceObj instanceof ObjectName)) {
|
||||
if (sourceObj != null && (
|
||||
!(sourceObj instanceof RelationService) &&
|
||||
!(sourceObj instanceof ObjectName))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -27,7 +27,10 @@
|
||||
*/
|
||||
|
||||
import java.net.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import static java.lang.System.out;
|
||||
|
||||
public class IndexTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
@ -39,12 +42,17 @@ public class IndexTest {
|
||||
if (index >= 0) {
|
||||
NetworkInterface nif2 = NetworkInterface.getByIndex(index);
|
||||
if (! nif.equals(nif2)) {
|
||||
out.printf("%nExpected interfaces to be the same, but got:%n");
|
||||
displayInterfaceInformation(nif);
|
||||
displayInterfaceInformation(nif2);
|
||||
throw new RuntimeException("both interfaces should be equal");
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
nif = NetworkInterface.getByIndex(-1);
|
||||
out.printf("%ngetByIndex(-1) should have thrown, but instead returned:%n");
|
||||
displayInterfaceInformation(nif);
|
||||
throw new RuntimeException("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// OK
|
||||
@ -52,7 +60,29 @@ public class IndexTest {
|
||||
// In all likelyhood, this interface should not exist.
|
||||
nif = NetworkInterface.getByIndex(Integer.MAX_VALUE - 1);
|
||||
if (nif != null) {
|
||||
out.printf("%ngetByIndex(MAX_VALUE - 1), expected null, got:%n");
|
||||
displayInterfaceInformation(nif);
|
||||
throw new RuntimeException("getByIndex() should have returned null");
|
||||
}
|
||||
}
|
||||
|
||||
static void displayInterfaceInformation(NetworkInterface netint) throws SocketException {
|
||||
out.printf("Display name: %s%n", netint.getDisplayName());
|
||||
out.printf("Name: %s%n", netint.getName());
|
||||
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
|
||||
|
||||
for (InetAddress inetAddress : Collections.list(inetAddresses))
|
||||
out.printf("InetAddress: %s%n", inetAddress);
|
||||
|
||||
out.printf("Up? %s%n", netint.isUp());
|
||||
out.printf("Loopback? %s%n", netint.isLoopback());
|
||||
out.printf("PointToPoint? %s%n", netint.isPointToPoint());
|
||||
out.printf("Supports multicast? %s%n", netint.supportsMulticast());
|
||||
out.printf("Virtual? %s%n", netint.isVirtual());
|
||||
out.printf("Hardware address: %s%n",
|
||||
Arrays.toString(netint.getHardwareAddress()));
|
||||
out.printf("MTU: %s%n", netint.getMTU());
|
||||
out.printf("Index: %s%n", netint.getIndex());
|
||||
out.printf("%n");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user