ARTEMIS-4174 fix style & rat
This commit is contained in:
parent
791fb7fd7b
commit
691771c766
|
@ -36,6 +36,7 @@ public class RmiRegistryFactory {
|
|||
private Registry registry;
|
||||
private String host;
|
||||
private HostLimitedServerSocketFactory socketFactory;
|
||||
|
||||
/**
|
||||
* @return the port
|
||||
*/
|
||||
|
@ -62,7 +63,7 @@ public class RmiRegistryFactory {
|
|||
* Create a server socket for testing purposes.
|
||||
*/
|
||||
ServerSocket createTestSocket() throws IOException {
|
||||
return socketFactory.createServerSocket(1100);
|
||||
return socketFactory.createServerSocket(1100);
|
||||
}
|
||||
|
||||
public Object getObject() throws Exception {
|
||||
|
@ -72,13 +73,13 @@ public class RmiRegistryFactory {
|
|||
class HostLimitedServerSocketFactory implements RMIServerSocketFactory {
|
||||
@Override
|
||||
public ServerSocket createServerSocket(int port) throws IOException {
|
||||
InetAddress hostAddress;
|
||||
if (host != null) {
|
||||
hostAddress = InetAddress.getByName(host);
|
||||
} else {
|
||||
hostAddress = null; // accept connections on all local addresses
|
||||
}
|
||||
return ServerSocketFactory.getDefault().createServerSocket(port, 0, hostAddress);
|
||||
InetAddress hostAddress;
|
||||
if (host != null) {
|
||||
hostAddress = InetAddress.getByName(host);
|
||||
} else {
|
||||
hostAddress = null; // accept connections on all local addresses
|
||||
}
|
||||
return ServerSocketFactory.getDefault().createServerSocket(port, 0, hostAddress);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,9 +92,7 @@ public class RmiRegistryFactory {
|
|||
|
||||
public void init() throws RemoteException, UnknownHostException {
|
||||
socketFactory = new HostLimitedServerSocketFactory();
|
||||
registry = LocateRegistry.createRegistry(port,
|
||||
new PassThroughToDefaultSocketFactory(),
|
||||
socketFactory);
|
||||
registry = LocateRegistry.createRegistry(port, new PassThroughToDefaultSocketFactory(), socketFactory);
|
||||
}
|
||||
|
||||
public void destroy() throws RemoteException {
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.artemis.core.server.management;
|
||||
|
||||
import org.apache.activemq.artemis.core.config.JMXConnectorConfiguration;
|
||||
|
@ -10,43 +26,40 @@ import java.net.ServerSocket;
|
|||
|
||||
public class JMXRMIRegistryPortTest {
|
||||
|
||||
@Test
|
||||
public void explicitLocalhostRegistry() throws IOException {
|
||||
RmiRegistryFactory registryFactory = new RmiRegistryFactory();
|
||||
registryFactory.setHost("localhost");
|
||||
registryFactory.setPort(1099);
|
||||
registryFactory.init();
|
||||
try (ServerSocket testSocket = registryFactory.createTestSocket()) {
|
||||
Assert.assertEquals(InetAddress.getByName("localhost"),
|
||||
testSocket.getInetAddress());
|
||||
}
|
||||
registryFactory.destroy();
|
||||
}
|
||||
@Test
|
||||
public void explicitLocalhostRegistry() throws IOException {
|
||||
RmiRegistryFactory registryFactory = new RmiRegistryFactory();
|
||||
registryFactory.setHost("localhost");
|
||||
registryFactory.setPort(1099);
|
||||
registryFactory.init();
|
||||
try (ServerSocket testSocket = registryFactory.createTestSocket()) {
|
||||
Assert.assertEquals(InetAddress.getByName("localhost"), testSocket.getInetAddress());
|
||||
}
|
||||
registryFactory.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unlimitedHostRegistry() throws IOException {
|
||||
RmiRegistryFactory registryFactory = new RmiRegistryFactory();
|
||||
registryFactory.setHost(null);
|
||||
registryFactory.setPort(1099);
|
||||
registryFactory.init();
|
||||
try (ServerSocket testSocket = registryFactory.createTestSocket()) {
|
||||
Assert.assertEquals(InetAddress.getByAddress(new byte[] { 0, 0, 0, 0 }),
|
||||
testSocket.getInetAddress());
|
||||
}
|
||||
registryFactory.destroy();
|
||||
}
|
||||
@Test
|
||||
public void unlimitedHostRegistry() throws IOException {
|
||||
RmiRegistryFactory registryFactory = new RmiRegistryFactory();
|
||||
registryFactory.setHost(null);
|
||||
registryFactory.setPort(1099);
|
||||
registryFactory.init();
|
||||
try (ServerSocket testSocket = registryFactory.createTestSocket()) {
|
||||
Assert.assertEquals(InetAddress.getByAddress(new byte[]{0, 0, 0, 0}), testSocket.getInetAddress());
|
||||
}
|
||||
registryFactory.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultRegistry() throws IOException {
|
||||
RmiRegistryFactory registryFactory = new RmiRegistryFactory();
|
||||
JMXConnectorConfiguration configuration = new JMXConnectorConfiguration();
|
||||
registryFactory.setHost(configuration.getConnectorHost());
|
||||
registryFactory.setPort(configuration.getConnectorPort());
|
||||
registryFactory.init();
|
||||
try (ServerSocket testSocket = registryFactory.createTestSocket()) {
|
||||
Assert.assertEquals(InetAddress.getByName("localhost"),
|
||||
testSocket.getInetAddress());
|
||||
}
|
||||
registryFactory.destroy();
|
||||
}
|
||||
@Test
|
||||
public void defaultRegistry() throws IOException {
|
||||
RmiRegistryFactory registryFactory = new RmiRegistryFactory();
|
||||
JMXConnectorConfiguration configuration = new JMXConnectorConfiguration();
|
||||
registryFactory.setHost(configuration.getConnectorHost());
|
||||
registryFactory.setPort(configuration.getConnectorPort());
|
||||
registryFactory.init();
|
||||
try (ServerSocket testSocket = registryFactory.createTestSocket()) {
|
||||
Assert.assertEquals(InetAddress.getByName("localhost"), testSocket.getInetAddress());
|
||||
}
|
||||
registryFactory.destroy();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue