I'm building this software for a school assignment. A server (regulator) controls interactions between shops (distributors) and clients. I have three entities:
Regulator. It binds two services: authentication (user control) and listing (lists distributors and their offers) to the registry.
Distributor. Deploys a user interface that allows registering and deleting offers and binds a service (ServiceSales) to the registry.
Client. Deploys a user interface and allows the user to ask the regulator which distributor has the offer they are interested in.
The regulator binds both the services fine, and the other entities interact ok with it. When I'm trying to bind ServiceSales I get an error as if the registry wasn't up.
This is the relevant code in the class Regulator:
Registry registry = LocateRegistry.getRegistry();
Utils.setCodeBase(ServiceSalesInterface.class);
ServiceSalesInterface sales = new ServiceSalesImpl(servicio);
ServicioVentaInterface sales_remote =
(ServiceSalesInterface) UnicastRemoteObject.exportObject(sales, 8888);
registry.rebind(sales.name(), sales_remote);
sales.name() returns service's name.
This is Utils source:
public class Utils {
public static final String CODEBASE = "java.rmi.server.codebase";
public static void setCodeBase(Class<?> c){
String path = c.getProtectionDomain().getCodeSource()
.getLocation().toString();
String cbase = System.getProperty(CODEBASE);
if (path != null && !path.isEmpty()){
path = path + " " + cbase;
}
System.setProperty(CODEBASE, path);
}
}
I've tried using different ports but it doesn't seem to be that what it is causing the error. This is the error message that pops when I'm trying to bind ServiceSales to the registry ( registry.rebind(sales.name(), sales_remote); ):
java.rmi.ConnectException: Connection refused to host: 127.0.1.1; nested exception is:
java.net.ConnectException: Connection refused
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:342)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
In case it is needed, this is the relevant code within the Regulator class (that works fine).
System.setProperty("java.rmi.server.hostname","127.0.0.1");
registry = LocateRegistry.createRegistry(8888);
Utils.setCodeBase(ServiceGoods.class);
ServiceGoodsInterface goods = new ServiceGoodsImpl();
ServiceGoodsInterface goods_remote =
(ServiceGoodsInterface)UnicastRemoteObject.exportObject(goods, 8888);
registry.rebind("ServiceGoods", goods_remote);
Utils.setCodeBase(ServiceAuth.class);
ServiceAuthInterface auth = new ServiceAuthImpl();
ServiceAuthInterface auth_remote =
(ServiceAuthInterface)UnicastRemoteObject.exportObject(auth, 8888);
registry.rebind("ServiceAuth", auth_remote);
System.out.println("Server is running.");
Related
I'm trying to connect to an SMB server using com.hierynomus.smbj v0.10.0. Connection is ok but as soon as I try to authenticate I'm getting this exception:
com.hierynomus.mssmb2.SMBApiException: STATUS_ACCESS_DENIED (0xc0000022): Authentication failed for 'USERNAME' using com.hierynomus.smbj.auth.NtlmAuthenticator#4152d38d
at com.hierynomus.smbj.connection.Connection.authenticate(Connection.java:194)
at MyTest.smbj(MyTest.java:...)
Here is the test code to see what I'm doing:
#Test
void smbj() throws Exception {
SMBClient client = new SMBClient();
try (Connection connection = client.connect("my-smb-server.de")) {
AuthenticationContext ac = new AuthenticationContext("USERNAME", "PASSWORD".toCharArray(), "DOMAIN");
Session session = connection.authenticate(ac);
// ... do more here ...
}
}
The SMB server and connection is perfectly fine since I'm able to connect from the same machine the test is running using multiple GUI tools (e.g. ForkLift) without any customized settings.
connection.getConnectionInfo() returns this before doing the authentication:
Successfully connected to: my-smb-server.de
ConnectionInfo{
serverGuid=975b39d3-55c0-4490-84e7-80371b734ce7,
serverName='my-smb-server.de',
negotiatedProtocol=NegotiatedProtocol{dialect=SMB_2_1, maxTransactSize=8388608, maxReadSize=8388608, maxWriteSize=8388608},
clientGuid=85863c1f-0328-4c21-9a72-b3d907b23a1d,
clientCapabilities=[SMB2_GLOBAL_CAP_DFS],
serverCapabilities=[SMB2_GLOBAL_CAP_DFS, SMB2_GLOBAL_CAP_LEASING, SMB2_GLOBAL_CAP_LARGE_MTU], > clientSecurityMode=0,
serverSecurityMode=3,
server='null' }
Any help is highly appreciated.
In a Java client app we are connecting to a multi-instance MQ Manager as follows:
java.net.URL ccdt = new URL("file:./config/qmgrs/MQMGR/AMQCLCHL.TAB");
MQQueueManager mqQueueManager = new MQQueueManager("*MQMGR", ccdt);
We can then for example enquire about the current depth of a queue as follows:
int openOptions = CMQC.MQOO_INQUIRE;
MQQueue mqQueue = mqQueueManager.accessQueue("A.QUEUE.NAME", openOptions);
System.out.println("queue depth:" + mqQueue.getCurrentDepth());
Question is, using the same MQQueueManager object, how can we get the list of multi-instance MQ Managers' addresses and ports. Or any other info about the manager itself...
We can see there is the following sort of thing available:
String nameList = mqQueueManager.getAttributeString(MQConstants.MQCA_NAMELIST_NAME, MQConstants.MQ_NAMELIST_NAME_LENGTH);
But when we call the above command, we get:
com.ibm.mq.MQException: MQJE001: Completion Code '2', Reason '2067'.
We are not sure if this is because the client code is not configured correctly or, if it is because the connection that we are using does not have sufficient permissions to get information about the manager?
You will have to use MQ PCF classes to query queue manager attributes. There is sample PCF_WalkThroughQueueManagerAttributes.java shipped with MQ that displays all attributes of queue manager. Here is small sample that lists local queues of a queue manager.
private void runPCFTest() {
try {
PCFAgent agent = new PCFAgent(connect());
PCFParameter[] parameters = { new MQCFST (MQConstants.MQCA_Q_NAME, "*"),
new MQCFIN (MQConstants.MQIA_Q_TYPE, MQConstants.MQQT_LOCAL)};
MQMessage[] responses = agent.send(CMQCFC.MQCMD_INQUIRE_Q_NAMES, parameters);
MQCFH cfh = new MQCFH(responses[0]);
for (int i = 0; i < cfh.getParameterCount(); i++) {
System.out.println (PCFParameter.nextParameter (responses [0]));
}
}catch(Exception ex) {
System.out.println(ex);
}
}
#SuppressWarnings({ "unchecked", "rawtypes" })
private MQQueueManager connect() throws MQException {
Hashtable props = new Hashtable();
props.put(MQConstants.HOST_NAME_PROPERTY, "localhost");
props.put(MQConstants.PORT_PROPERTY, 1414);
props.put(MQConstants.CHANNEL_PROPERTY, "MFT_CHN");
props.put(MQConstants.USER_ID_PROPERTY, "user1");
props.put(MQConstants.PASSWORD_PROPERTY, "passw0rd");
props.put(MQConstants.USE_MQCSP_AUTHENTICATION_PROPERTY, true);
return new MQQueueManager("MQM", props);
}
But why do you want to query connection information, host, port etc?
If I understand your question correctly, you want to know all of the hostnames (or IP addresses) and Port numbers of the servers where the MI queue manager may reside. Correct?
This information is in your CCDT file. When you (or MQAdmin) created your CCDT entry for the CLNTCONN (client-side channel), you would have issued a like:
DEFINE CHANNEL(TEST.CHL) CHLTYPE(CLNTCONN) TRPTYPE(TCP) CONNAME('ipaddr1(1414), ipaddr2(1414)') QMNAME(QM1)
Hence, the CONNAME parameter has the information and that is what the MQ client library uses to connect to the remote queue manager. First it will try 'ipaddr1(1414)' and if it fails then it will try 'ipaddr2(1414)'.
I am learning Akka remoting, referring to the book Learning Akka.
Using a limited network, I can't use sbt (can't config the proxy well).
First, I create a project for an Akka server with the application.conf
akka {
actor {
provider = remote
}
remote {
emabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
hostname = "127.0.0.1"
port = 2552
}
}
}
and the console shows
Remoting now listens on addresses: [akka.tcp://akkademy#127.0.0.1:2552]
The second project is the client having a JClient class:
public class JClient {
private static final int TIMEOUT = 2000;
private final ActorSystem system = ActorSystem.create("LocalSystem");
private final ActorSelection remoteDb;
public JClient(String remoteAddress) {
remoteDb = system.actorSelection("akka.tcp://LocalSystem#" + remoteAddress + "/user/akkademy-db");
}
public CompletionStage set(String key, Object value) {
return toJava(ask(remoteDb, new SetRequest(key, value), TIMEOUT));
}
public CompletionStage<Object> get(String key) {
return toJava(ask(remoteDb, new GetRequest(key), TIMEOUT));
}
}
I pass the value "127.0.0.1:2552" to remoteAddress, calling the set/get methods, and encounter the error:
java.util.concurrent.ExecutionException: akka.pattern.AskTimeoutException: Ask timed out on [ActorSelection[Anchor(akka://akkademy/deadLetters), Path(/user/.*)]] after [2000 ms]. Sender[null] sent message of type "javah.GetRequest".
Your client code to obtain an ActorSelection to the remote actor is incorrect. Instead of "LocalSystem", which is the name of the client's actor system, use "akkademy", the name of the server's actor system. Change the JClient constructor to the following:
public JClient(String remoteAddress) {
remoteDb = system.actorSelection("akka.tcp://akkademy#" + remoteAddress + "/user/akkademy-db");
}
In actorSelection the selector should be string of format akka.tcp://${remoteActorSystemName}#${remoteAddress}/user/$actorPath. In the snippet you've posted, looks like you were using LocalSystem as ${remoteActorSystemName} instead of the remote actor system name.
Let me know if switching it to remote works, if not, can you post the full code you are using or a link to it ?
I'm trying to get remote objects from a server hosted on different network. I'm able to connect on same machine and on same network, but when I try to get it from different network I get:
Connection refused to host: 192.168.1.131; nested exception is: java.net.ConnectException: Connection timed out: connect
It seems that lookup function is searching at wrong network. I tried to use System.setProperty but it doesn't work. Here the code:
Server
public class Main {
public static void main(String[] args) {
try{
System.out.println("Init server...\n");
TestInterface test = new TestImplement();
System.setProperty("java.rmi.server.hostname", "95.247.x.x");
System.out.println("Reg RMI...\n");
Registry rmiRegistry = LocateRegistry.createRegistry(5555);
rmiRegistry.rebind("Test" , test);
System.out.println("Reg completed!\n");
}catch(Exception e){
e.printStackTrace();
}
}
}
Client
...
registryRMI = LocateRegistry.getRegistry("95.247.x.x",5555);
TestInterface testClient = (TestInterface)registryRMI.lookup("Test");
...
Do I need to set java.rmi.server.hostname in client jar as well?
TestInterface test = new TestImplement();
System.setProperty("java.rmi.server.hostname", "95.247.x.x");
You need to set java.rmi.server.hostname before exporting any remote objects. Doing it afterwards is too late.
System.setProperty("java.rmi.server.hostname", "95.247.x.x");
TestInterface test = new TestImplement();
I am sure that I am using the correct connection information:
import com.bmc.arsys.api.ARException;
import com.bmc.arsys.api.ARServerUser;
/**
*
* A class to automate deletion of BMC Remedy incidents after deploying or decommissioning servers
*
*/
#SuppressWarnings("unused")
public class BMCIncidentDelete {
public static void main(String[] args) {
/*
* Authentication information
*/
String host = "";
String server = "";
String user = "";
String pass = "";
ARServerUser ctx = new ARServerUser();
ctx.setServer(host);
// ctx.setServer(server);
ctx.setUser(user);
ctx.setPassword(pass);
ctx.setPort(8080);
/*
* Verify user or print stack trace if not possible
*/
try {
ctx.verifyUser();
System.out.println("Connection verified!");
} catch (ARException e) {
System.out.println(e.getMessage().toString());
}
}
}
Unfortunately, I get the following error:
ERROR (90): Cannot establish a network connection to the AR System server; Connection refused: connect
Anyone with experience with the AR System API see this issue before? https://communities.bmc.com/docs/DOC-17514
This error (Connection refused) indicates that the Remedy server is not reachable from your server on the host and port provided. You can validate by using telnet, substituting the hostname for $host:
$ telnet $host 8080
A successful connection should say "Connected to host.", but based on your question you will likely see "Connection refused". Double check the hostname and port number of the Remedy server, and if necessary check that there are no firewalls, etc. between you and the server.