I have created two Web Projects in java.
One of the project was running inside the Tomcat docker container:
192.160.1.5:8080/SocketServer
Another project was running in local machine using eclipse
localhost:8081/SocketClient
I am trying to connect the SocketServer project running inside docker container from the SocketClient using HttpURLConnection in java. But it gives some errors like below:
java.net.ConnectException: Connection refused
at java.base/sun.nio.ch.Net.connect0(Native Method)
at java.base/sun.nio.ch.Net.connect(Net.java:574)
at java.base/sun.nio.ch.Net.connect(Net.java:563)
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:588)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:333)
at java.base/java.net.Socket.connect(Socket.java:648)
at java.base/java.net.Socket.connect(Socket.java:597)
at java.base/java.net.Socket.<init>(Socket.java:520)
at java.base/java.net.Socket.<init>(Socket.java:370)
at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:122)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
at com.dump.LogAction.startSocket(LogAction.java:61)
at com.dump.LogAction.execute(LogAction.java:37)
How can I resolve this?
This is normal behavior, you should read the docs.
https://docs.docker.com/network/network-tutorial-host/
Quick answer: run the docker image with --network host argument OR you need to expose a port publicly https://www.whitesourcesoftware.com/free-developer-tools/blog/docker-expose-port/ --expose 8080
Related
I have a client-server Java project, from which I have generated a JAR file for the client execution.
When the JAR file is not running on Vmware, it easily connects to the server (which is running in IntelliJ).
However, it cannot connect to the server when it is on the virtual machine.
It gives me this error:
java.net.ConnectException: Connection refused (Connection refused)
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
Has anyone had any similar experience?
I want to run my app on my real device Android but I receive this error:
Running command: D:\WebStorm\Path\platforms\android\cordova\run.bat ANDROID_HOME=C:\Program Files (x86)\Android\android-sdk JAVA_HOME=C:\Program Files\Java\jdk1.8.0_40 WARNING : No target specified, deploying to device '02c5cabed02456d5'. Running: D:\WebStorm\Path\platforms\android\gradlew cdvBuildDebug -b D: \WebStorm\Path\platforms\android\build.gradle
-PcdvBuildArch=arm -Dorg. gradle.daemon=true Downloading http://services.gradle.org/distributions/gradle-2.2.1-all.zip
Exception in thread "main" java.lang.RuntimeException: java.net.ConnectException : Connection refused: connect
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAcc essManager.java:78)
at org.gradle.wrapper.Install.createDist(Install.java:47)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48) Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketI mpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.ja va:345)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocket Impl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java :188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
at sun.net.www.http.HttpClient.New(HttpClient.java:308)
at sun.net.www.http.HttpClient.New(HttpClient.java:326)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLC onnection.java:1168)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConn ection.java:1104)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConne ction.java:998)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection .java:932)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLCo nnection.java:1512)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon nection.java:1440)
at org.gradle.wrapper.Download.downloadInternal(Download.java:59)
at org.gradle.wrapper.Download.download(Download.java:45)
at org.gradle.wrapper.Install$1.call(Install.java:60)
at org.gradle.wrapper.Install$1.call(Install.java:47)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAcc essManager.java:65)
... 3 more
D:\WebStorm\Path\platforms\android\cordova\node_modules\q\q.js:126
throw e;
^ Error code 1 for command: cmd with args: /s /c "D:\WebStorm\Path\platfo rms\android\gradlew cdvBuildDebug -b D:\WebStorm\Path\platforms\android \build.gradle -PcdvBuildArch=arm -Dorg.gradle.daemon=true" ERROR running one or more of the platforms: Error: D:\WebStorm\Path\pla tforms\android\cordova\run.bat: Command failed with exit code 8 You may not have the required environment or OS to run this project
I installed the Android sdk and I added to my Path in Windows7 this:
C:\Development\android-sdk\platform-tools;
C:\Development\android-sdk\tools;
C:\Development\android-sdk\android-sdk
Where is the problem???
It is seems be issue with proxy only.
You can set proxy in two ways.
Create/Edit gradle.properties # c:\Users\<username>\.gradle\
OR
Goto your project location and do the same as above
Example : platforms/android/gradle.properities
Write below content in file
systemProp.http.proxyHost=proxyhost
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=username
systemProp.http.proxyPassword=pwd
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost
systemProp.https.proxyHost=proxyhost
systemProp.https.proxyPort=8080
systemProp.https.proxyUser=username
systemProp.https.proxyPassword=pwd
systemProp.https.nonProxyHosts=*.nonproxyrepos.com|localhost
This link helped me: http://forum.ionicframework.com/t/proxy-error-when-downloading-gradle-zip-during-ionic-emulate-android/31701
To find .gradle, go to your user folder (default is c:\Users\<your login>). In case gradle.properties is not existing, simply create one
Looking at your stacktrace it seems to be some kind of connectivity problem. Is your computer is using any proxy to connect to network? if yes then that have to be configured for your build tool as well. As i can see it is just trying to download gradle-2.2.1-all.zip and it is failing due to connection problem.
Solution: Steps to configure proxy in nodejs
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
Hope that information helps you.
Regards
Himanshu
When executing
java -jar jenkins-cli.jar -s https://jenkins_url help
I'm getting connection refused for some reason. Jenkins version is 1580.3, user has the permissions on Jenkins server, cli jar is up-to-date and ssh public key is configured properly. Any idea what might be causing this? Here's the stack trace if it will help:
Exception in thread "main" java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at hudson.cli.CLI.connectViaCliPort(CLI.java:203)
at hudson.cli.CLI.<init>(CLI.java:126)
at hudson.cli.CLIConnectionFactory.connect(CLIConnectionFactory.java:72)
at hudson.cli.CLI._main(CLI.java:466)
at hudson.cli.CLI.main(CLI.java:382)
Suppressed: java.io.EOFException: unexpected stream termination
at hudson.remoting.ChannelBuilder.negotiate(ChannelBuilder.java:331)
at hudson.remoting.Channel.<init>(Channel.java:421)
at hudson.remoting.Channel.<init>(Channel.java:400)
at hudson.remoting.Channel.<init>(Channel.java:396)
at hudson.remoting.Channel.<init>(Channel.java:385)
at hudson.remoting.Channel.<init>(Channel.java:377)
at hudson.remoting.Channel.<init>(Channel.java:353)
at hudson.cli.CLI.connectViaHttp(CLI.java:157)
at hudson.cli.CLI.<init>(CLI.java:130)
... 3 more
If the connection is refused, perhaps the CLI is disabled, but more likely there's a firewall or network issue.
Each successful HTTP request to Jenkins responds with the CLI port as an HTTP header, so you can quickly check whether it's enabled:
curl -sI http://jenkins/ | grep CLI
Alternatively, as documented on the wiki, you can check whether the TCP port is enabled. Look for "TCP port for JNLP slave agents" at http://jenkins/configureSecurity/
However, since your stacktrace indicates that the CLI client is trying to establish a connection to a particular port, it suggests that the CLI is enabled, and Jenkins is advertising that port number in its HTTP responses.
So you could try to connect to that port manually, to check whether it's open:
telnet jenkins <cli-port>
If you also see "Connection refused" here, then you know that your Jenkins and CLI client setup seem to be ok, but you have a network issue. In which case, check that the firewall on the Jenkins server allows incoming connections on that CLI port.
To make firewall configuration easier, you can switch from a random port to a fixed port in the "configure security" page mentioned above.
I had this issue on Ubuntu 16.04.
Note: this error happened to me well after setting up and having ran successful build jobs before. This happened to me after running a particularly heavy build job. So my fix might work assuming that the error isn't a firewall issue.
First, I tried to do a safe restart through the commandline using the jenkins-cli.jar tool:
java -jar jenkins-cli.jar -s http://localhost:8080 -auth <username>:<password> safe-restart
but also got the same Connection refused error message.
So as a last resort I tried restarting the Jenkins service on the server like so:
sudo systemctl restart jenkins
and that fixed it.
I'm trying to implement the RMI Compute PI tutorial found on the Sun/Oracle website here. The server is located on an Amazon windows EC2 Server. The client is located on my personal computer at home. Just to keep things simple, I have disabled the firewall on the server and open all the port on the EC2 security group. I can ping the machine, have access to files, etc... My aim is just to have a basic RMI program worked on AWS. I will oversee security issues later.
Lauching the server is not a problem. And it's correctly bound to the RMI Registry. I'm using the following command to launch it :
java -Djava.security.manager -Djava.security.policy=C:\AWSTest\security.policy -Djava.rmi.server.codebase=file:/C:/AWS/Sources/sun-rmi-tutorial-server/bin/ file:/C:/AWS/Sources/sun-rmi-tutorial-common/bin/ -classpath C:\AWS\Sources\sun-rmi-tutorial-server\bin;C:\AWS\Sources\sun-rmi-tutorial-common\bin engine.ComputeEngine ec2-XX-XX-XX-XXX.ap-southeast-1.compute.amazonaws.com
The RMI registry is started on the server side.
I have declared a new security manager on the server side System.setSecurityManager(new RMISecurityManager())
I'm using a security.policy file where I'm granted all permission.
When I'm launching the client side, on my local computer, I'm ending with an UnmarshalException:
ComputePi exception: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: engine.ComputeEngine_Stub
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: engine.ComputeEngine_Stub
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:101)
at client.ComputePi.main(ComputePi.java:14)
Caused by: java.lang.ClassNotFoundException: engine.ComputeEngine_Stub
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:453)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:184)
at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:637)
at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:264)
at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:216)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1593)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
... 3 more
Do you have any suggestions of what is wrong ? Why can't the client find the correct Stub ? I'm using Eclipse Juno, Genady RMI Plugin and Java 1.7.0_07.
Thanks for your help
EDIT 1 :
The Java workspace is organized around 3 projects : the Client side, the Server Side and a Common project where both the server and the client share classes.
I can read the remote registry from my local computer. The RMI plugin can connect remotely to the server and inspect the registry.
If instead of making 3 projects I put all the classes under the same project, everything is working fine... But I notice that no stubs where generated (or needed).
If, on the client side, I'm putting a reference in the classpath to the server classes (everything being build locally), i have a connection timeout error instead of the unmarshalling error.
ComputePi exception: Connection refused to host: XX.XXX.XX.XX; nested exception is:
java.net.ConnectException: Connection timed out: connect
java.rmi.ConnectException: Connection refused to host: XX.XXX.XXX; nested exception is:
java.net.ConnectException: Connection timed out: connect
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 engine.ComputeEngine_Stub.executeTask(ComputeEngine_Stub.java:35)
at client.ComputePi.main(ComputePi.java:19)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.(Socket.java:425)
at java.net.Socket.(Socket.java:208)
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)
... 5 more
You haven't deployed the stub class to the client.
I've configured a slave to run on my machine, the slave is connected and recognized by Jenkins.
I've configured my project to use that specific slave and I can see that it kicks into action when a job needs to be done.
After a while I receive the following error:
[Android Tunneling] $ /opt/jdk/jdk1.7.0/bin/java -cp maven3-agent.jar:/opt/maven/apache- maven-3.0.4/boot/plexus-classworlds-2.4.jar org.jvnet.hudson.maven3.agent.Maven3Main /opt/maven/apache-maven-3.0.4 /home/efi/Documents/jenkins/jenkins-cli.jar maven3-interceptor.jar 34176
Error: Could not find or load main class org.jvnet.hudson.maven3.agent.Maven3Main
ERROR: Failed to launch Maven. Exit code = 1
When running this command locally via terminal I get
Exception in thread "main" java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:337)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:198)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:208)
at org.jvnet.hudson.maven3.agent.Maven3Main.main(Maven3Main.java:128)
at org.jvnet.hudson.maven3.agent.Maven3Main.main(Maven3Main.java:63)
Any idea what might be the problem ?
Command line is looking for maven to be installed on /opt/maven/apache-maven-3.0.4 (default location for cloudbees slaves). If your local setup don't match this, you need to override tools location for this custom slave