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 Registry registry;
|
||||||
private String host;
|
private String host;
|
||||||
private HostLimitedServerSocketFactory socketFactory;
|
private HostLimitedServerSocketFactory socketFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the port
|
* @return the port
|
||||||
*/
|
*/
|
||||||
|
@ -62,7 +63,7 @@ public class RmiRegistryFactory {
|
||||||
* Create a server socket for testing purposes.
|
* Create a server socket for testing purposes.
|
||||||
*/
|
*/
|
||||||
ServerSocket createTestSocket() throws IOException {
|
ServerSocket createTestSocket() throws IOException {
|
||||||
return socketFactory.createServerSocket(1100);
|
return socketFactory.createServerSocket(1100);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getObject() throws Exception {
|
public Object getObject() throws Exception {
|
||||||
|
@ -72,13 +73,13 @@ public class RmiRegistryFactory {
|
||||||
class HostLimitedServerSocketFactory implements RMIServerSocketFactory {
|
class HostLimitedServerSocketFactory implements RMIServerSocketFactory {
|
||||||
@Override
|
@Override
|
||||||
public ServerSocket createServerSocket(int port) throws IOException {
|
public ServerSocket createServerSocket(int port) throws IOException {
|
||||||
InetAddress hostAddress;
|
InetAddress hostAddress;
|
||||||
if (host != null) {
|
if (host != null) {
|
||||||
hostAddress = InetAddress.getByName(host);
|
hostAddress = InetAddress.getByName(host);
|
||||||
} else {
|
} else {
|
||||||
hostAddress = null; // accept connections on all local addresses
|
hostAddress = null; // accept connections on all local addresses
|
||||||
}
|
}
|
||||||
return ServerSocketFactory.getDefault().createServerSocket(port, 0, hostAddress);
|
return ServerSocketFactory.getDefault().createServerSocket(port, 0, hostAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,9 +92,7 @@ public class RmiRegistryFactory {
|
||||||
|
|
||||||
public void init() throws RemoteException, UnknownHostException {
|
public void init() throws RemoteException, UnknownHostException {
|
||||||
socketFactory = new HostLimitedServerSocketFactory();
|
socketFactory = new HostLimitedServerSocketFactory();
|
||||||
registry = LocateRegistry.createRegistry(port,
|
registry = LocateRegistry.createRegistry(port, new PassThroughToDefaultSocketFactory(), socketFactory);
|
||||||
new PassThroughToDefaultSocketFactory(),
|
|
||||||
socketFactory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy() throws RemoteException {
|
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;
|
package org.apache.activemq.artemis.core.server.management;
|
||||||
|
|
||||||
import org.apache.activemq.artemis.core.config.JMXConnectorConfiguration;
|
import org.apache.activemq.artemis.core.config.JMXConnectorConfiguration;
|
||||||
|
@ -10,43 +26,40 @@ import java.net.ServerSocket;
|
||||||
|
|
||||||
public class JMXRMIRegistryPortTest {
|
public class JMXRMIRegistryPortTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void explicitLocalhostRegistry() throws IOException {
|
public void explicitLocalhostRegistry() throws IOException {
|
||||||
RmiRegistryFactory registryFactory = new RmiRegistryFactory();
|
RmiRegistryFactory registryFactory = new RmiRegistryFactory();
|
||||||
registryFactory.setHost("localhost");
|
registryFactory.setHost("localhost");
|
||||||
registryFactory.setPort(1099);
|
registryFactory.setPort(1099);
|
||||||
registryFactory.init();
|
registryFactory.init();
|
||||||
try (ServerSocket testSocket = registryFactory.createTestSocket()) {
|
try (ServerSocket testSocket = registryFactory.createTestSocket()) {
|
||||||
Assert.assertEquals(InetAddress.getByName("localhost"),
|
Assert.assertEquals(InetAddress.getByName("localhost"), testSocket.getInetAddress());
|
||||||
testSocket.getInetAddress());
|
}
|
||||||
}
|
registryFactory.destroy();
|
||||||
registryFactory.destroy();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unlimitedHostRegistry() throws IOException {
|
public void unlimitedHostRegistry() throws IOException {
|
||||||
RmiRegistryFactory registryFactory = new RmiRegistryFactory();
|
RmiRegistryFactory registryFactory = new RmiRegistryFactory();
|
||||||
registryFactory.setHost(null);
|
registryFactory.setHost(null);
|
||||||
registryFactory.setPort(1099);
|
registryFactory.setPort(1099);
|
||||||
registryFactory.init();
|
registryFactory.init();
|
||||||
try (ServerSocket testSocket = registryFactory.createTestSocket()) {
|
try (ServerSocket testSocket = registryFactory.createTestSocket()) {
|
||||||
Assert.assertEquals(InetAddress.getByAddress(new byte[] { 0, 0, 0, 0 }),
|
Assert.assertEquals(InetAddress.getByAddress(new byte[]{0, 0, 0, 0}), testSocket.getInetAddress());
|
||||||
testSocket.getInetAddress());
|
}
|
||||||
}
|
registryFactory.destroy();
|
||||||
registryFactory.destroy();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultRegistry() throws IOException {
|
public void defaultRegistry() throws IOException {
|
||||||
RmiRegistryFactory registryFactory = new RmiRegistryFactory();
|
RmiRegistryFactory registryFactory = new RmiRegistryFactory();
|
||||||
JMXConnectorConfiguration configuration = new JMXConnectorConfiguration();
|
JMXConnectorConfiguration configuration = new JMXConnectorConfiguration();
|
||||||
registryFactory.setHost(configuration.getConnectorHost());
|
registryFactory.setHost(configuration.getConnectorHost());
|
||||||
registryFactory.setPort(configuration.getConnectorPort());
|
registryFactory.setPort(configuration.getConnectorPort());
|
||||||
registryFactory.init();
|
registryFactory.init();
|
||||||
try (ServerSocket testSocket = registryFactory.createTestSocket()) {
|
try (ServerSocket testSocket = registryFactory.createTestSocket()) {
|
||||||
Assert.assertEquals(InetAddress.getByName("localhost"),
|
Assert.assertEquals(InetAddress.getByName("localhost"), testSocket.getInetAddress());
|
||||||
testSocket.getInetAddress());
|
}
|
||||||
}
|
registryFactory.destroy();
|
||||||
registryFactory.destroy();
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue