i'm trying to use Jsoup to connect to a site but i keep on getting the following error, i have configured everything well inside the following xmls,"setting.xlm" and "pom.xml". can anyone help me to find out what is the main cause of all this. Than you so much.
here is the error that im getting:
Exception in thread "main" java.net.SocketTimeoutException: connect timed out
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:75)
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 sun.net.NetworkClient.doConnect(NetworkClient.java:175)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:378)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:473)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:203)
at sun.net.www.http.HttpClient.New(HttpClient.java:290)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:995)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:931)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:849)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:425)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:410)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:164)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:153)
at com.mycompany.mavenproject1.Facebook.main(Facebook.java:23)
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 16.904s
Finished at: Mon May 20 14:00:03 CAT 2013
Final Memory: 19M/47M
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project mavenproject1: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]
A possible solution for this problem within the Tomcat web application is to modify the CONTEXT. XML file, and modify the CONNECTOR definition that governs the workstation browser connectivity to the Tomcat server. Specifically, modify the connectionTimeout value. Increase this value to suppress the error condition.
Your Java socket is timing out means that it takes too long to get respond from other device and your request expires before getting response. This exception is occurring on following condition. Server is slow and default timeout is less, so just put timeout value according to you.
Using try/catch/finally If you are a developer, so you can surround the socket connection part of your code in a try/catch/finally and handle the error in the catch. You might try connecting a second time, or try connecting to another possible socket, or simply exit the program cleanly.
As a result, a “connection timed out” error can occur when a client is trying to establish a connection to a server. Therefore, we should check the firewall settings to see if it's blocking a port before binding it to a service.
You are probably unable to reach the internet due to being behind a proxy.
Setting up a proxy for Jsoup is the same as for ordinary URL
connections on Java.
Considering your proxy is at 127.0.0.1
and its port is 8182
, you can set it as:
System.setProperty("http.proxyHost", "127.0.0.1");
System.setProperty("http.proxyPort", "8182");
If you are trying to access through HTTPS, the properties are https.proxyHost
and https.proxyPort
.
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class ExampleJSoupProxy {
public static void main(String[] args) throws Exception {
System.setProperty("http.proxyHost", "127.0.0.1");
System.setProperty("http.proxyPort", "8182");
Document doc = Jsoup.connect("http://stackoverflow.com").get();
System.out.println("Obtained Title: " + doc.title());
}
}
Obtained Title: Stack Overflow
This does not seem to be a problem in your application. It should be a network problem.
Check if you can open the page you're trying to parse in your browser. If you're using a proxy, try to run your application without proxy and see if it solves the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With