Java: Duplicated port bind by jetty7 under jdk7 - java

I have met an issue that the jetty7 server didn't throw 'Address already in use' exception when the port was occupied by other application. But it had worked well on jdk6.
Environment:
Server: windows 2008 server
Java: 7.0.20.13
Jetty: 7.6.0.RC4
Below is my demo code:
public class Jetty7OnJdk7 {
public static void main(String[] args) throws Exception {
Server server = new Server();
SelectChannelConnector connector = new SelectChannelConnector(); //this is the default connect in jetty7
connector.setReuseAddress(false); //prevent the jetty reusing the occupied port
connector.setPort(80);
server.setConnectors(new Connector[]{connector});
server.start();
System.out.println("=========:" + server);
}
}

Related

Java RMI from external IP

I used java RMI to connect two java applications. if i run them both locally (and change ip to localhost) it works, if i run them both on my server it works. but if i run Client.java locally and ApplicationServer.java on my server it throws this on the client side:
Exception in thread "main" java.rmi.ConnectException: Connection refused to host: my.servers.private.ip; nested exception is:
java.net.ConnectException: Connection timed out: connect ...
Client:
public class Client {
public static void main(String[] args) throws RemoteException, MalformedURLException NotBoundException {
System.out.println("attempting connection");
System.setProperty("java.security.policy","test.policy");
HelloService service =(HelloService) Naming.lookup("rmi://my.servers.private.ip:1001/hello");
System.out.println("connected");
if(service.isConnected()) {
System.out.println("success.");
}
}
}
Server:
public class ApplicationServer {
public static void main(String[] args) throws RemoteException, AlreadyBoundException {
System.setProperty("java.security.policy","test.policy");
System.setProperty("java.rmi.server.hostname","my.servers.private.ip");
Registry registry = LocateRegistry.createRegistry(1001);
registry.rebind("hello", new HelloServant());
System.out.println("ready");
}
}
If i change the code from my.servers.private.ip to my.servers.public.ip and run both on my server it doesn't work either.
Changing my.servers.private.ip to my.servers.public.ip does not work.
I have a feeling it has to do something with the public and private IP.

Why I'm not able to connect to HBase running as Docker container?

I have my Java Spring app that deals with HBase.
Here is my configuration:
#Configuration
public class HbaseConfiguration {
#Bean
public HbaseTemplate hbaseTemplate(#Value("${hadoop.home.dir}") final String hadoopHome,
#Value("${hbase.zookeeper.quorum}") final String quorum,
#Value("${hbase.zookeeper.property.clientPort}") final String port)
throws IOException, ServiceException {
System.setProperty("hadoop.home.dir", hadoopHome);
org.apache.hadoop.conf.Configuration configuration = HBaseConfiguration.create();
configuration.set("hbase.zookeeper.quorum", quorum);
configuration.set("hbase.zookeeper.property.clientPort", port);
HBaseAdmin.checkHBaseAvailable(configuration);
return new HbaseTemplate(configuration);
}
}
#HBASE
hbase.zookeeper.quorum = localhost
hbase.zookeeper.property.clientPort = 2181
hadoop.home.dir = C:/hadoop
Before asking the question I tried to figure out the problem on my own and found this link https://github.com/sel-fish/hbase.docker
But still, I get an error
org.apache.hadoop.net.ConnectTimeoutException: 10000 millis timeout while waiting for channel to be ready for connect. ch : java.nio.channels.SocketChannel[connection-pending remote=myhbase/192.168.99.100:60000]
Could I ask you to help me and clarify how can I connect my local Java app with HBase running in Docker?

SSHJ is not able to connect remote Linux server throws UserAuthException: Exhausted available authentication methods

I am trying to run the following Java code using sshj :-
public static void main(String[] args) throws IOException {
SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();
ssh.connect("host", port);
try {
ssh.authPassword("user", "passwd");
ssh.useCompression();
final String src = System.getProperty("user.home") + File.separator + "test_file";
ssh.newSCPFileTransfer().upload(new FileSystemFile(src), "/tmp/");
} finally {
ssh.disconnect();
ssh.close();
}
}
But it is throwing exception -
Exception in thread "main" net.schmizz.sshj.userauth.UserAuthException: Exhausted available authentication methods
at net.schmizz.sshj.SSHClient.auth(SSHClient.java:231)
at net.schmizz.sshj.SSHClient.auth(SSHClient.java:206)
at net.schmizz.sshj.SSHClient.authPassword(SSHClient.java:292)
at net.schmizz.sshj.SSHClient.authPassword(SSHClient.java:262)
at net.schmizz.sshj.SSHClient.authPassword(SSHClient.java:246)
at sample.SCPUpload.main(SCPUpload.java:17)
I can connect the host using same credentials via Putty. I am using JDK "1.8.0_151". What is wrong here?
Typically it means that either your password is wrong, or you're not allowed to connect using the 'password' authentication method.

How to make a connection to the mysql database in openshift 3.0

I'm testing openshift 3.0 and I cannot figure out how to make a simple connection in java. I've done port forwarding: local port 3306 for remote port 3306 and I'm using the following code:
public class testDAO {
public static void main(String[] args) throws SQLException {
Connection conexao = DriverManager.getConnection(
"jdbc:mysql://127.0.0.1:3306/sampledb","userFGF","eA3Rwe4OgSiWGeK2");
System.out.println("Conectado!");
conexao.close();
}
}

UnsupportedOperationException on Endpoint.publish() with Jetty

I am getting the following error:
com.sun.xml.internal.ws.server.ServerRtException: Server Runtime Error: java.lang.UnsupportedOperationException: !DelegatingThreadPool
With this code:
ServerStart
Server server = new Server(4433); //Jetty
System.setProperty(
"com.sun.net.httpserver.HttpServerProvider",
"org.eclipse.jetty.http.spi.JettyHttpServerProvider");
JettyHttpServerProvider.setServer(server);
//error occurs here
Endpoint.publish("http://localhost:" + 4433 + "/buecherservice", new BuecherServiceImpl());
//not reached code
server.start();
server.stop();
WebService with Interface:
#WebService
public interface BuecherServiceIntf //Interface
#WebService
public class BuecherServiceImpl implements BuecherServiceIntf
Can someone help?
Change
Server server = new Server(4433);
to the following which is required for http-spi
Server server = new Server(new DelegatingThreadPool());
ServerConnector connector = new ServerConnector(server);
connector.setPort(4433);
server.addConnector(connector);

Categories

Resources