Is there any specific Glassfish configuration required to allow remote CORBA lookup across a LAN? Or, does, perhaps, the routers firewall need configuration?
How do I troubleshoot this connection?
The CORBA lookup client just hangs:
BUILD SUCCESSFUL
Total time: 3 seconds
Nov 22, 2014 3:45:26 AM aggregatorclient.AggregatorClient remoteEJB
WARNING: {org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, Context.SECURITY_CREDENTIALS=pass123, org.omg.CORBA.ORBInitialHost=192.168.0.119, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, Context.SECURITY_PRINCIPAL=user1}
When run from localhost (ie, from localhost, connecting to localhost), with everything on the same computer, the connection works fine.
The CORBA connection lookup parameters, in jndi.properties:
java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory
java.naming.factory.url.pkgs=com.sun.enterprise.naming
java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
Context.SECURITY_PRINCIPAL=user1
Context.SECURITY_CREDENTIALS=pass123
org.omg.CORBA.ORBInitialHost=192.168.0.119
org.omg.CORBA.ORBInitialPort=3700
the connecting clients code:
package aggregatorclient;
import dur.ejb.AnswerSessionBeanRemote;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class AggregatorClient {
private static final Logger log = Logger.getLogger(AggregatorClient.class.getName());
public static void main(String[] args) {
try {
new AggregatorClient().remoteEJB();
} catch (NamingException ex) {
Logger.getLogger(AggregatorClient.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void remoteEJB() throws NamingException {
Context ctx = new InitialContext();
log.warning(ctx.getEnvironment().toString());
Object obj = ctx.lookup("dur.ejb.AnswerSessionBeanRemote");
AnswerSessionBeanRemote asbr = (AnswerSessionBeanRemote) obj;
log.info("answer\t" + asbr.lifeTheUniverseAndEverything());
}
}
The client is executed with Glassfish appclient.
Been having the same "hanging forever" lookup behavior with a standalone ejb client running on a remote host. It turned out to be related to the server host's ability to resolve its own hostname into its own non-loopback address. I resolved it by adding / fixing an entry in /etc/hosts:
10.0.10.102 my-server-hostname
I checked that the server could actually resolve the right ip address with hostname -i :
$ hostname -i
10.0.10.102
After restarting GlassFish, remote lookup and call to EJB worked like a charm!
Explanation
I found this solution after sniffing the traffic between my client and server. The underlying protocol is GIOP (had never heard of it).
When executing the remote lookup, my client's request was actually able to reach GlassFish. But the server replied with a misleading "Location Forward" response, indicating 127.0.1.1 as a IIOP:Profile_host. 127.0.1.1 was the loopback ip address that my server's hostname resolved to before I fixed the /etc/hosts.
Related
I am exploring ways to connect to a SQL database using JDBC in Java and interact with it. Problem is no matter how I follow the syntax to make such connection it does not let me to connect to that instance of SQL Server on my laptop. I have seen other people being able to run such instances on their localhost instead and be able to connect to it via JDBS but I could not find any walkthroughs as how I can do the same. Any help with it will be greatly appreciated. Here is the connection I have on my laptop:
And here the JDBC connection URL that I try to make based on this on my code:
package helpers;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DbHandler {
private static final String connectionUrl = "jdbc:sqlserver://LAPTOP-KAQ3H6IG//SQLEXPRESS:1433;database=pub;user=MyUserName;password=MyPassword";
public static void addNewJobWithName(String jobName) {
try (Connection connect = DriverManager.getConnection(connectionUrl)) {
connect.createStatement().execute("INSERT INTO [pub].[dbo].[jobs] (job_id, job_desc, min_lvl, max_lvl) VALUES (2,'QA3', 50, 100);");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
And the error I receive:
The TCP/IP connection to the host LAPTOP-KAQ3H6IG//SQLEXPRESS, port 1433 has failed. Error: "LAPTOP-KAQ3H6IG//SQLEXPRESS. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.". at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:237)
Thanks in advance for your help
Did a combination of things based on the comments made here and some other posts I read on stack overflow regarding other things to do to fully solve this problem here are the things that I did:
Changed my connection URL string to this:
"jdbc:sqlserver://localhost:1433;database=pub;user=MyUserName;password=MyPassword;encrypt=true;trustServerCertificate=true";
On SQL Server configuration manager clicked on 'SQL Server Network Configuration' and enabled 'Named Pipes' and 'TCP/IP' in 'Protocols for SQLEXPRESS' (where my local MSSQL instance is setup).
Clicking on TCP/IP in the same window, switched to the IP Address tab and entered '1433' as the port number for the IPAII section right at the end of the list (Leave the other port sections empty).
Restarted SQL Server (SQLEXPRESS) from the list of services in Windows.
Hope it can help other people having the same problem as well.
I've been having an issue with DNS lookup for IPv6 addresses that I can't seem to find good information about.
I'm trying to lookup an IPv6 address using InetAddress.getByName("ipv6.local.com"). It throws an UnknownHostException error.
The weird part is I know the DNS server can be contacted because this works:
InetAddress.getByName("ipv4.local.com")
I also know the IPv6 record is working because I can run:
nslookup ipv6.local.com
and it properly returns 3ffe:b00:0:1:4678:3eff:fe36:16e8.
Likewise, if I run the following in C++, I get a result with the above address as well:
int errorCode = getaddrinfo("ipv6.local.com", "4242", &hints, &res);
I have also tried Inet6Address.getByName(), but this also throws UnknownHostException. So why do getaddrinfo() and nslookup work and not InetAddress.getByName()?
I am attempting the DNS lookup from an Android device (Galaxy Tab S2 8") running Android 6.0.1 on the same network as the DNS server. The DNS server has a record "ipv4.local.com" pointing to 192.168.0.190, and a record "ipv6.local.com" pointing to 3ffe:b00:0:1:4678:3eff:fe36:16e8.
The DNS server is explicitly set in Wi-Fi settings on the Android device, and is running on 192.168.0.182.
Any ideas?
I am not sure why IPv6 resolution is not working for you. Here is the example of Java code(java version "1.8.0_171") I tested:
package com.myjava.ip;
import java.net.InetAddress;
import java.net.UnknownHostException;
class MyIpByHost {
public static void main(String a[]){
try {
InetAddress host = InetAddress.getByName("ipv6.google.com");
System.out.println(host.getHostAddress());
} catch (UnknownHostException ex) {
ex.printStackTrace();
}
}
}
Output: java com/myjava/ip/MyIpByHost => 2404:6800:4003:c02:0:0:0:8a
This code returns IPv6 for endpoint "ipv6.google.com".
Java run C functions in it's backend to get work done. As you already know getaddrinfo() function of C supports IPv6, but gethostbyname() does not.
You may be running outdated version of java with underlying C function
gethostbyname() which does not support IPv6. I
would suggest you to upgrade Java which will use getaddrinfo().
First for all, i'm sorry for my english.
I have a problem with Java API Transport Client. I have one master node and three data nodes. Version of my Elasticsearch is 5.0.2 and i use 5.0.2 API.
I try to connect to my cluster with Transport Client and then i response
Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{8SAZOxXXTU61DuDDMN-vGw}{XX.XX.X.XXX}{XX.XX.X.XXX:9300}, {#transport#-2}{Fv3729YgTGClRBo5T2mWpA}{XX.XX.X.XXX}{XX.XX.X.XXX:9300}, {#transport#-3}{Fr98ApBbRv29Xv6Mc8L4TQ}{XX.XX.X.XXX}{XX.XX.X.XXX:9300}, {#transport#-4}{JOmpSH4LRzuP_XInxQtD9Q}{XX.XX.X.XXX}{XX.XX.X.XXX:9300}]]
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:328)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:226)
at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:59)
at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:339)
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:403)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:80)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:54)
at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:62)
at nn.Main.main(Main.java:57)
That is my code of client:
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.xpack.client.PreBuiltXPackTransportClient;
public class Main {
private static String[] hosts = new String[] {
"XX.XX.X.XXX"
,"XX.XX.X.XXX"
,"XX.XX.X.XXX"
,"XX.XX.X.XXX"
};
private static final Settings settings = Settings.builder()
.put("cluster.name", "myCluster")
.put("client.transport.sniff", true)
.put("transport.tcp.port", 9300)
.put("xpack.security.user", "transport_client_user:changeme")
.build();
private static final String index = "myIndex";
private static final String type = "myType";
private static TransportClient client;
public static void main(String[] args) throws UnknownHostException {
InetSocketTransportAddress[] ista = new InetSocketTransportAddress[hosts.length];
for (int i = 0; i < hosts.length; i++) {
ista[i] = new InetSocketTransportAddress(InetAddress.getByName(hosts[i]), 9300);
}
client = new PreBuiltXPackTransportClient(settings).addTransportAddresses(ista);
SearchRequestBuilder rb = client
.prepareSearch(index)
.setTypes(type)
.setSearchType(SearchType.DEFAULT)
.setQuery(QueryBuilders.termQuery("_id", 3524598));
SearchResponse sResponse = rb.get();
System.out.println(sResponse.toString());
}
}
Port for transport client - 9300, all my nodes communicate under this port. I saw a lot like my question, and i trying to follow the advice contained in them. But i have the same exception.
If need more information or any files or settings of my Elastic - i'm ready to answer.
If it is important this is content of elasticsearch.yml
cluster.name: myCluster
node.name: elastic-0
path.data: /var/db/elasticsearch
path.logs: /var/log/elasticsearch
path.scripts: /usr/local/libexec/elasticsearch
network.host: _vmx0_
node.master: true
node.data: false
node.ingest: false
node.attr.rack_id: rack_one
cluster.routing.allocation.awareness.attributes: rack_id
discovery.zen.minimum_master_nodes: 3
discovery.zen.ping.unicast.hosts: ["XX.XX.X.XXX","XX.XX.X.XXX","XX.XX.X.XXX","XX.XX.X.XXX","XX.XX.X.XXX"]
bootstrap.memory_lock: false
xpack.monitoring.exporters:
id1:
type: http
host: ["XX.XX.X.XXX:9200"]
auth.username: remote_monitor
auth.password: changeme
I tried to change TransportClient on just Client, and disable client.transport.sniff but without result.
I will be very gratefull for any help or ideas.
I found the reason for which i received "NoNodeAvailableException".
The reason is transport_client's role does not grant permission to view the data in all indices on default.
And i will to built my role for the access to data in indices.
Link: https://www.elastic.co/guide/en/x-pack/5.0/built-in-roles.html
This exception usually occurs when we try to use ES with TranscientClient (9300) and not with an API (9200).
These could be the reasons behind this:
Our IP address or the port that is provided is wrong. By default, the transport communication happens via 9300 until and unless we explicitly change in the elastisearch.yml
The IP address and the port is not reachable from the machine where we are running the Java Application. The ES machine is simply not reachable from Client Machine so we need to open the port and IP to the client.
If we change the 'transport.host' then ES considers as a prod environment and makes bootstrap checks. But in the scenario where the environment is not prod and we are running ES in one machine and trying to hit it from another machine with a transport client (Java app) then we can just add 'discovery.type: single-node'.
Change the Elastic Search yaml as follows:
cluster.name: elasticsearch
node.name: node-1
transport.host: 0.0.0.0
transport.tcp.port: 9300
http.port: 9200
network.host: 0.0.0.0
discovery.type: single-node
I'm stuck with that for at least 5 hours now and have no other resort but to ask here. I'm writing an RMI application. I'd like the server to bind a remote object (NoteBoardImpl here), that will be looked-up by the client. Client passes its listener (NoteBoardListener here) to the server, the listener is also a remote object exported by the client.
I've prepared a simple SSCCE here, so I really hope somebody can look into it. All the classes are in the same folder the default package. I know it's discouraged and I should've split the application in three jars, but I wanted to keep it as simple as possible here.
Remote interfaces:
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface INoteBoard extends Remote {
public void test(INoteBoardListener listener) throws RemoteException;
}
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface INoteBoardListener extends Remote {
public void onNewText(String text) throws RemoteException;
}
Interfaces implementations:
import java.rmi.RemoteException;
public class NoteBoardImpl implements INoteBoard {
#Override
public void test(INoteBoardListener listener) throws RemoteException {
listener.onNewText("server call the listener");
}
}
import java.rmi.RemoteException;
public class NoteBoardListener implements INoteBoardListener {
#Override
public void onNewText(String text) throws RemoteException {
System.out.println(text);
}
}
Client and server:
import java.rmi.Naming;
import java.rmi.server.UnicastRemoteObject;
public class Client {
public static void main(String[] args) {
if (args.length < 2) {
System.out.println("2 arguments required:\nRMI_IP RMI_port");
return;
}
System.setProperty("java.rmi.server.hostname", args[0]);
try {
INoteBoard nb = (INoteBoard) Naming.lookup(String.format("rmi://%s:%s/note", args[0], args[1]));
INoteBoardListener l = (INoteBoardListener) UnicastRemoteObject.exportObject(new NoteBoardListener(), 0);
nb.test(l);
l.onNewText("client invokes listener");
} catch (Exception e) {
e.printStackTrace();
}
}
}
import java.rmi.Naming;
import java.rmi.server.UnicastRemoteObject;
public class Server {
public static void main(String[] args) {
if (args.length < 2) {
System.out.println("2 arguments required:\nRMI_IP RMI_port");
return;
}
System.setProperty("java.rmi.server.hostname", args[0]);
try {
INoteBoard noteBoard = (INoteBoard) UnicastRemoteObject.exportObject(new NoteBoardImpl(), 0);
Naming.rebind(String.format("rmi://%s:%s/note", args[0], args[1]), noteBoard);
} catch (Exception e) {
e.printStackTrace();
}
}
}
I've tried to simulate a distributed system for testing purposes and ran the client on a virtual machine. The host-VM network has the following specs - host IP = 192.168.56.1, VM IP = 192.168.56.101.
First I ran the client and the server locally, using the following commands (having started rmiregistry 1099 beforehand). The working directory is the project's root and the compiled classes are in bin directory:
java -cp bin -Djava.rmi.server.codebase=http://student.agh.edu.pl/~grajewsk/bin/ Server 192.168.56.1 1099
java -cp bin Client 192.168.56.1 1099
And it worked.
Then I ran the client program on the VM using the same command and here's the exception I got:
java.rmi.ConnectException: Connection refused to host: 192.168.56.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.invoke(UnicastRef.java:128)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
at sun.proxy.$Proxy0.test(Unknown Source)
at Client.main(Client.java:14)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:327)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:193)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
at java.net.Socket.connect(Socket.java:546)
at java.net.Socket.connect(Socket.java:495)
at java.net.Socket.<init>(Socket.java:392)
at java.net.Socket.<init>(Socket.java:206)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:146)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 7 more
Notice how the object is successfully looked-up in the server's registry, then the client-side remote object is exported (also with success) and the execution breaks in the 14-th line, where I'm trying to invoke a method on the server-side object passing the client-side object.
I have no firewalls on either of the systems, pings in both directions go flawlessly. I know that there must be some conceptual problem here and certainly I misunderstood something about the RMI. I'd very much appreciate your help.
The binary codebase is on my student's server, as well as the source code. Thank you in advance!
Here's what I'd do to get to the bottom of this.
Run your server app
find out what port it's using for RMI (it's ephemeral, so it should change for each process you create of the server).
find the PID with ps -ef
then netstat -anp|grep This should then give you the port number. And it should be bound to 0.0.0.0
on the client VM, use nc or telnet to verify you can connect to the port. If this fails, you probably have a firewall/iptables issue.
use wireshark to verify your client is actually attempting to connect to the port/ip combo you learned from step #2.
Remember, just because you can ping, doesn't mean you can connect to a given port. Also check "iptables -L".
Also, Naming says not to put the scheme component of the URL. The format should be //host:port/name, so you should check that as well.
Ok, finally solved it. The problem was, that I was passing the same java.rmi.server.hostname argument in both programs, that means that both client and server got the address of the server here. It turned out, that if the client wants to export its own objects, it has to provide its own IP to the java.rmi.server.hostname. This way everything works fine.
So, to sum it up, I had to give 3 arguments to the server:
RMI_IP RMI_port server_hostname
And 3 analogous arguments to the client:
RMI_IP RMI_port client_hostname
I'm having trouble with my e-mail configuration for sending e-mails using lotus notes in a java program. I know this is pretty much straight forward but i guess i'm missing something. My code is as follows;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
public class MailClass {
public void SendMail() {
SimpleEmail email = new SimpleEmail();
try {
email.setHostName("mail.smtp.host");
email.addTo("recipient#company.com");
email.setFrom("sender#agency.com");
email.setSubject("Hello World");
email.setMsg("This is a simple test of commons-email");
email.send();
} catch (EmailException ex) {
Logger.getLogger(MailClass4.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String[] args) {
MailClass main = new MailClass();
main.SendMail();
}
}
I keep on getting this error
SEVERE: null
org.apache.commons.mail.EmailException: Sending the email to the following server failed : mail.smtp.host:25
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
...
Caused by: javax.mail.MessagingException: Unknown SMTP host: mail.smtp.host;
nested exception is:java.net.UnknownHostException: mail.smtp.host at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1970)
I'm guessing it's about my host but not really sure what to do about it. From my understanding your host should be your email client (ex. mail.smtp.google.com). But since this is Lotus Notes (it runs in our intranet btw) the implimentation will be different. I've seen other samples that use the "mail.smtp.host" as host but i can't get this one right....
It's my first time doing an e-mail program so i'm pretty much clueless about this.
You can use your Domino server running on your intranet as SMTP server but first you have to ask your admin if Domino has been set up to allow SMTP - and at the same time ask for the proper host name and port).
setHostName requires the hostname or IP-address of a smtp server. And the exception makes it very clear what the issue is.
Lotus Notes is basicslly just a client and has nothing to do with what you are trying to accomplish.